feat:增加运动健康模块
This commit is contained in:
84
src/views/health/calendar.vue
Normal file
84
src/views/health/calendar.vue
Normal file
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<div class="mobile-health-view common-mobile-view">
|
||||
<v-calendar ref="calendarRef" :attributes='dailyInfo.attrs'
|
||||
@dayclick="dateClick" @did-move="changeMonthClick"
|
||||
:is-dark="appStore.isDark"
|
||||
class="health-calendar card-item"/>
|
||||
<health-legend />
|
||||
|
||||
<health-form />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import HealthLegend from '@/components/Health/HealthLegend.vue'
|
||||
import HealthForm from '@/components/Health/HealthForm.vue'
|
||||
import { CalendarDay } from 'v-calendar/dist/types/src/utils/page'
|
||||
import { formatDate, getStartEndDate } from 'vue3-common/utils/dateUtil'
|
||||
import { onMounted, reactive } from 'vue'
|
||||
import { useHealthStore } from '@/store/health'
|
||||
import { useAppStore } from '@/store/app.ts'
|
||||
import { IExercise, IWeight } from '@/types/health'
|
||||
|
||||
const healthStore = useHealthStore()
|
||||
const appStore = useAppStore()
|
||||
|
||||
const dailyInfo = reactive({
|
||||
calendarDate: '',
|
||||
attrs: [] as any[]
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
const result = getStartEndDate(formatDate(new Date()), 'month')
|
||||
healthStore.queryInfo = { startDate: result[0], endDate: result[1] }
|
||||
|
||||
await healthStore.refreshInfo()
|
||||
updateRecordList()
|
||||
healthStore.getHealthDay(formatDate(new Date()))
|
||||
})
|
||||
|
||||
const updateRecordList = () => {
|
||||
healthStore.weightRecordList.forEach((item: IWeight) => {
|
||||
dailyInfo.attrs.push({
|
||||
dot: 'red',
|
||||
dates: item.date
|
||||
})
|
||||
})
|
||||
|
||||
healthStore.exerciseRecordList.forEach((item: IExercise) => {
|
||||
dailyInfo.attrs.push({
|
||||
dot: 'green',
|
||||
dates: item.date
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const dateClick = (day: CalendarDay) => {
|
||||
healthStore.selectDate = formatDate(day.date)
|
||||
healthStore.getHealthDay(formatDate(day.date))
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择月份事件
|
||||
*/
|
||||
const changeMonthClick = async (value) => {
|
||||
const result = getStartEndDate(value[0].id, 'month')
|
||||
healthStore.queryInfo = { startDate: result[0], endDate: result[1] }
|
||||
|
||||
await healthStore.refreshInfo()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.mobile-health-view {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1vh;
|
||||
|
||||
.health-calendar {
|
||||
justify-self: center;
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user