diff --git a/src/components/Bill/BillChart.vue b/src/components/Bill/BillChart.vue index 94e8cc4..b88eb9a 100644 --- a/src/components/Bill/BillChart.vue +++ b/src/components/Bill/BillChart.vue @@ -42,6 +42,7 @@ import { lineChartOptions, barChartOptions, pieChartOptions } from 'vue3-common/ import { useBillStore } from '@/store/bill.ts' import { useAppStore } from '@/store/app.ts' import { isMobile } from 'vue3-common/utils/layoutUtil' +import { formatDate } from 'vue3-common/utils/dateUtil' const billStore = useBillStore() const appStore = useAppStore() @@ -68,7 +69,9 @@ const updateChart = () => { const MAX_CATEGORY_COUNT = 5 // 收支统计图 - const dailyXAxis = billStore.billDateStatsList.map((item) => item.name) + const dailyXAxis = billStore.billDateStatsList.map((item) => { + return formatDate(item.name, 'MM-DD') + }) const dailyYAxis = billStore.billDateStatsList.map((item) => item.value) billDailyChart.setOption(lineChartOptions('日期', dailyXAxis, '金额(元)', dailyYAxis)) billDailyChart.setOption({ diff --git a/src/components/Health/HealthChart.vue b/src/components/Health/HealthChart.vue index 2b06183..a4b039d 100644 --- a/src/components/Health/HealthChart.vue +++ b/src/components/Health/HealthChart.vue @@ -9,6 +9,13 @@
+
+
+ 📊睡眠时长统计图 +
+
+
+
📊运动时长统计 @@ -31,15 +38,18 @@ import * as echarts from 'echarts' import { lineChartOptions, barChartOptions, pieChartOptions } from 'vue3-common/utils/eChartsUtil' import { useHealthStore } from '@/store/health' import { useAppStore } from '@/store/app.ts' +import { formatDate } from 'vue3-common/utils/dateUtil' const healthStore = useHealthStore() const appStore = useAppStore() const weightDailyChartRef = ref() +const sleepDailyChartRef = ref() const healthDurationChartRef = ref() const healthCategoryChartRef = ref() let weightDailyChart: echarts.ECharts +let sleepDailyChart: echarts.ECharts let healthDurationChart: echarts.ECharts let healthCategoryChart: echarts.ECharts @@ -49,6 +59,7 @@ watch(() => healthStore.isRefresh, () => { onMounted(() => { weightDailyChart = echarts.init(weightDailyChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) + sleepDailyChart = echarts.init(sleepDailyChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) healthDurationChart = echarts.init(healthDurationChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) healthCategoryChart = echarts.init(healthCategoryChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) }) @@ -57,9 +68,15 @@ const updateChart = () => { const MAX_CATEGORY_COUNT = 5 // 体重趋势统计图 - const weightXAxis = healthStore.healthRecordList.map((item) => item.date).reverse() - const weightYAxis = healthStore.healthRecordList.map((item) => item.weight).reverse() - const sortedRecordList = healthStore.healthRecordList.sort((a, b) => a.weight - b.weight) + const weightRecordList = healthStore.healthRecordList + .filter((item) => item.weight !== 0) + + const weightXAxis = weightRecordList.map((item) => { + return formatDate(item.date, 'MM-DD') + }).reverse() + const weightYAxis = weightRecordList.map((item) => item.weight).reverse() + const sortedRecordList = weightRecordList.sort((a, b) => a.weight - b.weight) + weightDailyChart.setOption(lineChartOptions('日期', weightXAxis, '体重(千克)', weightYAxis)) weightDailyChart.setOption({ yAxis: { @@ -68,10 +85,28 @@ const updateChart = () => { } }) + // 睡眠时长统计图 + const sleepRecordList = healthStore.healthRecordList + .filter((item) => item.sleepDuration !== null) + .sort((a, b) => (a.date > b.date ? -1 : 1)) + + const sleepXAxis = sleepRecordList.map((item) => { + return formatDate(item.date, 'MM-DD') + }).reverse() + const sleepYAxis = sleepRecordList.map((item) => item.sleepDuration).reverse() as number[] + + sleepDailyChart.setOption(barChartOptions('日期', sleepXAxis, '时间(小时)', sleepYAxis)) + // 运动量统计图 - const sportRecordList = healthStore.healthRecordList.filter((item) => item.sportProject !== '') - const durationXAxis = sportRecordList.map((item) => item.date).reverse() + const sportRecordList = healthStore.healthRecordList + .filter((item) => item.sportProject !== '') + .sort((a, b) => (a.date > b.date ? -1 : 1)) + + const durationXAxis = sportRecordList.map((item) => { + return formatDate(item.date, 'MM-DD') + }).reverse() const durationYAxis = sportRecordList.map((item) => item.sportDuration).reverse() + healthDurationChart.setOption(barChartOptions('日期', durationXAxis, '时间(分钟)', durationYAxis)) // 类别统计图 diff --git a/src/components/Health/HealthForm.vue b/src/components/Health/HealthForm.vue index 7764a75..2d43987 100644 --- a/src/components/Health/HealthForm.vue +++ b/src/components/Health/HealthForm.vue @@ -49,6 +49,40 @@ 千克 + + + + + + + + + + + + @@ -68,8 +102,10 @@ const healthStore = useHealthStore() const projectList = ['羽毛球', '乒乓球', '跑步', '其他'] const onSubmit = async () => { - const { sportProject, sportDuration, weight } = healthStore.currentHealth - if (sportProject === '' && sportDuration === 0 && weight === 0) { + const { sportProject, sportDuration, weight, + sleepStartTime, sleepEndTime } = healthStore.currentHealth + if (sportProject === '' && sportDuration === 0 && weight === 0 + && sleepStartTime === '' && sleepEndTime === '') { return } @@ -80,6 +116,11 @@ const onSubmit = async () => { } } + if (sleepStartTime && sleepEndTime && !sleepStartTime && sleepEndTime) { + ElMessage.error('睡眠结束时间应大于睡眠开始时间') + return + } + await healthStore.updateHealthDay() healthStore.currentHealth = healthStore.getHealthDay(healthStore.selectDate) } diff --git a/src/store/health.ts b/src/store/health.ts index 63a8e3a..5b3f148 100644 --- a/src/store/health.ts +++ b/src/store/health.ts @@ -17,6 +17,9 @@ export const useHealthStore = defineStore('health', { currentHealth: { sportProject: '', sportDuration: 0, + sleepStartTime: '', + sleepEndTime: '', + sleepDuration: 0, weight: 0, date: '' } as IHealth, @@ -55,6 +58,9 @@ export const useHealthStore = defineStore('health', { return { id: 0, date, + sleepStartTime: '', + sleepEndTime: '', + sleepDuration: 0, sportDuration: 0, sportProject: '', weight: 0 diff --git a/src/types/health.ts b/src/types/health.ts index 1c4429f..cc0671a 100644 --- a/src/types/health.ts +++ b/src/types/health.ts @@ -3,6 +3,9 @@ export interface IHealth { sportProject: string; sportDuration: number; weight: number; + sleepStartTime: string | null; + sleepEndTime: string | null; + sleepDuration: number | null; date: string; } diff --git a/src/views/blog/archive.vue b/src/views/blog/archive.vue deleted file mode 100644 index 6318568..0000000 --- a/src/views/blog/archive.vue +++ /dev/null @@ -1,60 +0,0 @@ - - - - - diff --git a/src/views/blog/category.vue b/src/views/blog/category.vue deleted file mode 100644 index b95a43f..0000000 --- a/src/views/blog/category.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - - diff --git a/src/views/blog/category[name].vue b/src/views/blog/category[name].vue deleted file mode 100644 index 2918d49..0000000 --- a/src/views/blog/category[name].vue +++ /dev/null @@ -1,41 +0,0 @@ - - - - - diff --git a/src/views/blog/detail[id].vue b/src/views/blog/detail[id].vue deleted file mode 100644 index 1b4c793..0000000 --- a/src/views/blog/detail[id].vue +++ /dev/null @@ -1,55 +0,0 @@ - - - - - diff --git a/src/views/blog/overview.vue b/src/views/blog/overview.vue deleted file mode 100644 index 97ecd9c..0000000 --- a/src/views/blog/overview.vue +++ /dev/null @@ -1,76 +0,0 @@ - - - - - diff --git a/src/views/home/index.vue b/src/views/home/index.vue index ab878a4..5cfcb4e 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -14,10 +14,6 @@
- - @@ -34,10 +30,6 @@ title="运动健康" sub-title="乐享健康生活" router="/health/calendar"/> - - diff --git a/src/views/meta.ts b/src/views/meta.ts index b5ad653..fd687ba 100644 --- a/src/views/meta.ts +++ b/src/views/meta.ts @@ -1,36 +1,10 @@ import type { IRouteMetaConfig } from 'vue3-common/types' export const mobileHomeMeta: IRouteMetaConfig = { - '/blog': { - title: '博客记录', - icon: '', - order: 1, - redirect: '/blog/overview' - }, - '/blog/overview': { - title: '博客列表', - icon: '' - }, - '/blog/category': { - title: '博客分类', - icon: '' - }, - '/blog/category/:name': { - title: '博客分类', - icon: '' - }, - '/blog/archive': { - title: '博客归档', - icon: '' - }, - '/blog/detail/:id': { - title: '博客内容', - icon: '' - }, '/bill': { title: '收支记录', icon: '', - order: 2, + order: 1, redirect: '/bill/data' }, '/bill/data': { @@ -56,7 +30,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/travel': { title: '旅行记录', icon: '', - order: 4, + order: 2, redirect: '/travel/spot' }, '/travel/spot': { @@ -82,7 +56,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/health': { title: '运动健康', icon: '', - order: 4, + order: 3, redirect: '/health/calendar' }, '/health/calendar': { @@ -93,28 +67,10 @@ export const mobileHomeMeta: IRouteMetaConfig = { title: '统计', icon: '' }, - '/plan': { - title: '时光日程', - icon: 'home-calendar', - order: 5, - redirect: '/plan/calendar' - }, - '/plan/calendar': { - title: '日程安排', - icon: '' - }, - '/plan/list': { - title: '日程清单', - icon: '' - }, - '/plan/detail/id': { - title: '日程内容', - icon: '' - }, '/anniversary': { title: '纪念日', icon: 'home-anniversary', - order: 6, + order: 4, redirect: '/anniversary/list' }, '/anniversary/list': { @@ -132,7 +88,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/period': { title: '月经记录', icon: 'home-period', - order: 7, + order: 5, redirect: '/period/calendar' }, '/period/calendar': { @@ -150,7 +106,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/product': { title: '物品记录', icon: 'home-product', - order: 8, + order: 6, redirect: '/product/list' }, '/product/list': { @@ -164,7 +120,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/journal': { title: '日记', icon: 'home-product', - order: 9, + order: 7, redirect: '/journal/record' }, '/journal/record': { @@ -182,7 +138,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/kpi': { title: '绩效', icon: 'home-kpi', - order: 10, + order: 8, redirect: '/kpi/record' }, '/kpi/record': { @@ -196,7 +152,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/asset': { title: '资产', icon: 'home-asset', - order: 12, + order: 9, redirect: '/asset/list' }, '/asset/list': { @@ -210,7 +166,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/ledger': { title: '账本', icon: 'home-ledger', - order: 13, + order: 10, redirect: '/ledger/list' }, '/ledger/list': { @@ -228,7 +184,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/password': { title: '密码', icon: 'home-password', - order: 14, + order: 11, redirect: '/password/list' }, '/password/list': { @@ -238,7 +194,7 @@ export const mobileHomeMeta: IRouteMetaConfig = { '/profile': { title: '个人信息', icon: '', - order: 15, + order: 12, hidden: true, redirect: '/profile/index' }, diff --git a/src/views/plan/calendar.vue b/src/views/plan/calendar.vue deleted file mode 100644 index d96cdf5..0000000 --- a/src/views/plan/calendar.vue +++ /dev/null @@ -1,23 +0,0 @@ - - - - - diff --git a/src/views/plan/detail[id].vue b/src/views/plan/detail[id].vue deleted file mode 100644 index ee63db2..0000000 --- a/src/views/plan/detail[id].vue +++ /dev/null @@ -1,210 +0,0 @@ - - - - - diff --git a/src/views/plan/list.vue b/src/views/plan/list.vue deleted file mode 100644 index 0a61c53..0000000 --- a/src/views/plan/list.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - -