diff --git a/src/apis/exercise.ts b/src/apis/exercise.ts deleted file mode 100644 index 5e5f10c..0000000 --- a/src/apis/exercise.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { cloudService } from './index' -import { IExercise } from '@/types/health' - -export const addExerciseApi = (exercise: IExercise): Promise => - cloudService({ - url: '/home-api/exercise', - method: 'post', - data: exercise - }) - -export const updateExerciseApi = (id: number, exercise: IExercise): Promise => - cloudService({ - url: `/home-api/exercise/${id}`, - method: 'put', - data: exercise - }) - -export const deleteExerciseApi = (id: number): Promise => - cloudService({ - url: `/home-api/exercise/${id}`, - method: 'delete' - }) - -export const queryExerciseApi = (query: IExerciseQuery): Promise => - cloudService({ - url: '/home-api/exercise', - method: 'get', - params: query - }) diff --git a/src/apis/health.ts b/src/apis/health.ts new file mode 100644 index 0000000..f2e9228 --- /dev/null +++ b/src/apis/health.ts @@ -0,0 +1,16 @@ +import { cloudService } from './index' +import { IHealth, IHealthQuery } from '@/types/health' + +export const updateHealthApi = (id: number, health: IHealth): Promise => + cloudService({ + url: `/home-api/health/${id}`, + method: 'put', + data: health + }) + +export const queryHealthApi = (query: IHealthQuery): Promise => + cloudService({ + url: '/home-api/health', + method: 'get', + params: query + }) diff --git a/src/apis/weight.ts b/src/apis/weight.ts deleted file mode 100644 index 00b7f99..0000000 --- a/src/apis/weight.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { cloudService } from './index' -import { IWeight } from '@/types/health' - -export const addWeightApi = (weight: IWeight): Promise => - cloudService({ - url: '/home-api/weight', - method: 'post', - data: weight - }) - -export const updateWeightApi = (id: number, weight: IWeight): Promise => - cloudService({ - url: `/home-api/weight/${id}`, - method: 'put', - data: weight - }) - -export const deleteWeightApi = (id: number): Promise => - cloudService({ - url: `/home-api/weight/${id}`, - method: 'delete' - }) - -export const queryWeightApi = (query: IWeightQuery): Promise => - cloudService({ - url: '/home-api/weight', - method: 'get', - params: query - }) diff --git a/src/components/Bill/BillChart.vue b/src/components/Bill/BillChart.vue index 4a8e353..94e8cc4 100644 --- a/src/components/Bill/BillChart.vue +++ b/src/components/Bill/BillChart.vue @@ -1,5 +1,5 @@ @@ -44,7 +41,6 @@ import * as echarts from 'echarts' import { lineChartOptions, barChartOptions, pieChartOptions } from 'vue3-common/utils/eChartsUtil' import { useBillStore } from '@/store/bill.ts' import { useAppStore } from '@/store/app.ts' -import type { IStatsChart } from 'vue3-common/types' import { isMobile } from 'vue3-common/utils/layoutUtil' const billStore = useBillStore() @@ -53,12 +49,10 @@ const appStore = useAppStore() const billDailyChartRef = ref() const billBookChartRef = ref() const billCategoryChartRef = ref() -const billRankChartRef = ref() let billDailyChart: echarts.ECharts let billBookChart: echarts.ECharts let billCategoryChart: echarts.ECharts -let billRankChart: echarts.ECharts watch(() => billStore.isRefresh, () => { updateChart() @@ -68,15 +62,10 @@ onMounted(() => { billDailyChart = echarts.init(billDailyChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) billBookChart = echarts.init(billBookChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) billCategoryChart = echarts.init(billCategoryChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) - - if (!isMobile()) { - billRankChart = echarts.init(billRankChartRef.value as HTMLElement, appStore.isDark ? 'dark' : null) - } }) const updateChart = () => { const MAX_CATEGORY_COUNT = 5 - const MAX_RANK_COUNT = 10 // 收支统计图 const dailyXAxis = billStore.billDateStatsList.map((item) => item.name) @@ -129,19 +118,5 @@ const updateChart = () => { }] }) } - - // 排行榜统计图 - const billRankList: IStatsChart[] = [] - const resultList = billStore.billRecordList.filter((item) => item.type === billStore.billType) - resultList.sort((a, b) => b.amount - a.amount).forEach((item) => { - billRankList.push({ - name: item.content, - value: item.amount - }) - }) - - if (!isMobile()) { - billRankChart.setOption(pieChartOptions('rank', '元', billRankList.slice(0, MAX_RANK_COUNT))) - } } diff --git a/src/components/Bill/BillRank.vue b/src/components/Bill/BillRank.vue index 4d65c19..86ed5cf 100644 --- a/src/components/Bill/BillRank.vue +++ b/src/components/Bill/BillRank.vue @@ -3,7 +3,7 @@ :key="index" class="rank-item"> {{ index+1 }}. {{ item.content }} - ¥{{ item.amount }} + ¥{{ formatAmount(item.amount) }} @@ -11,6 +11,7 @@ import { useBillStore } from '@/store/bill.ts' import { getBillSortByAmount } from '@/utils/home/billUtil.ts' import { computed } from 'vue' +import { formatAmount } from 'vue3-common/utils/numberUtil' const billStore = useBillStore() diff --git a/src/components/Health/HealthForm.vue b/src/components/Health/HealthForm.vue index a92199f..7764a75 100644 --- a/src/components/Health/HealthForm.vue +++ b/src/components/Health/HealthForm.vue @@ -16,8 +16,8 @@ 运动项目 - + @@ -29,7 +29,8 @@ 运动时长 - 分钟 @@ -41,7 +42,8 @@ 体重 - 千克 @@ -59,14 +61,27 @@ diff --git a/src/components/Health/HealthLegend.vue b/src/components/Health/HealthLegend.vue deleted file mode 100644 index fd7a4d0..0000000 --- a/src/components/Health/HealthLegend.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - - - diff --git a/src/components/Ledger/LedgerRank.vue b/src/components/Ledger/LedgerRank.vue new file mode 100644 index 0000000..c10f3d9 --- /dev/null +++ b/src/components/Ledger/LedgerRank.vue @@ -0,0 +1,23 @@ + + + diff --git a/src/store/health.ts b/src/store/health.ts index ae3e19f..65838d5 100644 --- a/src/store/health.ts +++ b/src/store/health.ts @@ -1,129 +1,56 @@ import { defineStore } from 'pinia' import type { IHandleApi } from 'vue3-common/types' +import { queryHealthApi, updateHealthApi } from '@/apis/health.ts' +import { IHealth, IHealthQuery } from '@/types/health' import { ElMessage } from 'element-plus' -import { - addExerciseApi, - deleteExerciseApi, - queryExerciseApi, - updateExerciseApi -} from '@/apis/exercise' -import { addWeightApi, deleteWeightApi, queryWeightApi, updateWeightApi } from '@/apis/weight' -import { IExercise, IExerciseQuery, IHealth, IWeight } from '@/types/health' export const useHealthStore = defineStore('health', { state: () => ({ - weightRecordList: [] as IWeight[], - exerciseRecordList: [] as IExercise[], + healthRecordList: [] as IHealth[], queryInfo: { startDate: '', endDate: '' - } as IExerciseQuery, - weightApiType: 'ADD' as IHandleApi, - exerciseApiType: 'ADD' as IHandleApi, - currentExercise: { - project: '', - duration: 0, - date: '' - } as IExercise, + } as IHealthQuery, + healthApiType: 'ADD' as IHandleApi, currentHealth: { - project: '', - duration: 0, - value: 0, + sportProject: '', + sportDuration: 0, + weight: 0, date: '' } as IHealth, - currentWeight: { - value: '', - date: '' - } as IWeight, selectDate: '', isScrollEnd: false, isRefresh: false }), actions: { - async queryExerciseRecordList() { - this.exerciseRecordList = await queryExerciseApi(this.queryInfo) + async queryHealthRecordList() { + this.healthRecordList = await queryHealthApi(this.queryInfo) }, - async queryWeightRecordList() { - this.weightRecordList = await queryWeightApi(this.queryInfo) - }, - async handleExerciseApi(exercise: IExercise) { - switch (this.exerciseApiType) { - case 'ADD': - await addExerciseApi(exercise) - ElMessage.success('新增锻炼记录成功') - break - case 'UPDATE': - await updateExerciseApi(exercise.id as number, exercise) - ElMessage.success('更新锻炼记录成功') - break - case 'DELETE': - await deleteExerciseApi(exercise.id as number) - ElMessage.success('删除锻炼记录成功') - break - default: - break - } - await this.refreshInfo() - }, - async handleWeightApi(weight: IWeight) { - switch (this.weightApiType) { - case 'ADD': - await addWeightApi(weight) - ElMessage.success('新增体重记录成功') - break - case 'UPDATE': - await updateWeightApi(weight.id as number, weight) - ElMessage.success('更新体重记录成功') - break - case 'DELETE': - await deleteWeightApi(weight.id as number) - ElMessage.success('删除体重记录成功') - break - default: - break - } + async updateHealthDay() { + await updateHealthApi(this.currentHealth.id as number, this.currentHealth) await this.refreshInfo() + ElMessage.success('更新记录成功') }, getHealthDay(date: string): IHealth { - const exercise = this.exerciseRecordList.find((item) => item.date === date) - const weight = this.weightRecordList.find((item) => item.date === date) - this.currentHealth = this.getEmptyHealth() + const result = this.healthRecordList.find((item) => item.date === date) - if (exercise) { - this.currentHealth.project = exercise.project - this.currentHealth.duration = exercise.duration + if (result) { + return result + } else { + return this.getEmptyHealth(date) } - - if (weight) { - this.currentHealth.value = weight.value - } - - this.currentHealth.date = date }, async refreshInfo() { - await this.queryExerciseRecordList() - await this.queryWeightRecordList() + await this.queryHealthRecordList() this.isRefresh = !this.isRefresh }, - getEmptyExercise(): IExercise { + getEmptyHealth(date: string): IHealth { return { - project: '', - duration: 0, - date: '' - } - }, - getEmptyWeight(): IWeight { - return { - value: 0, - date: '' - } - }, - getEmptyHealth(): IHealth { - return { - date: '', - duration: 0, - project: '', - value: 0 + id: 0, + date, + sportDuration: 0, + sportProject: '', + weight: 0 } } } diff --git a/src/store/period.ts b/src/store/period.ts index 134f033..4319d63 100644 --- a/src/store/period.ts +++ b/src/store/period.ts @@ -10,6 +10,7 @@ import { updatePeriodSettingApi } from '@/apis/period.ts' import { getCurrentMonth } from 'vue3-common/utils/dateUtil' +import { ElMessage } from 'element-plus' export const usePeriodStore = defineStore('period', { state: () => ({ @@ -43,6 +44,7 @@ export const usePeriodStore = defineStore('period', { async updatePeriodDay() { await updatePeriodDayApi(this.currentPeriodDay.id as number, this.currentPeriodDay) await this.refreshInfo() + ElMessage.success('更新记录成功') }, async queryPeriodSetting() { this.periodSetting = await queryPeriodSettingApi() diff --git a/src/styles/home/bill.mobile.module.scss b/src/styles/home/bill.mobile.module.scss index 6aad67e..150b1bd 100644 --- a/src/styles/home/bill.mobile.module.scss +++ b/src/styles/home/bill.mobile.module.scss @@ -7,66 +7,6 @@ align-self: center; } - .bill-chart { - display: grid; - grid-template-rows: repeat(4, 1fr); - gap: 10px; - - .chart-container { - display: grid; - grid-template-rows: 40px 1fr; - - .content { - padding: 0 5px; - display: flex; - justify-content: space-between; - align-items: center; - border-bottom: 1px solid #009FA8; - - .title { - font-size: 1em; - font-weight: bold; - } - } - - .chart { - height: 300px; - width: 100%; - } - - .rank-chart { - overflow: auto; - display: flex; - flex-direction: column; - gap: 5px; - - .rank-item { - padding: 10px; - display: grid; - grid-template-columns: 20px 1fr 80px; - align-items: center; - - .rank-amount { - justify-self: flex-end; - } - } - - .rank-item:nth-child(1) { - color: #d4af37; - font-weight: bold; - } - - .rank-item:nth-child(2) { - color: #a8a8a8; - } - - .rank-item:nth-child(3) { - color: #b87333; - } - } - } - } - .el-switch { .el-switch__core { height: 32px; diff --git a/src/styles/home/bill.module.scss b/src/styles/home/bill.module.scss deleted file mode 100644 index 1f439a4..0000000 --- a/src/styles/home/bill.module.scss +++ /dev/null @@ -1,48 +0,0 @@ -.bill-view { - .bill-chart { - flex-grow: 1; - - display: grid; - grid-template-columns: 1fr 1fr; - grid-template-rows: 1fr 1fr; - gap: 2vh; - - .chart-container { - display: grid; - grid-template-rows: 40px 1fr; - - .content { - padding: 0 5px; - display: flex; - justify-content: space-between; - align-items: center; - border-bottom: 1px solid #009FA8; - - .title { - font-size: 1em; - font-weight: bold; - } - } - } - } - - @media (max-width: 1200px) { - .bill-chart { - display: grid; - grid-template-columns: 1fr; - grid-template-rows: 1fr; - gap: 2vh; - - .chart-container { - .chart { - min-width: 300px; - min-height: 250px; - } - } - } - } - - .bill-dialog { - width: 950px; - } -} diff --git a/src/styles/mobile.home.layout.module.scss b/src/styles/mobile.home.layout.module.scss index 1e917bf..357d534 100644 --- a/src/styles/mobile.home.layout.module.scss +++ b/src/styles/mobile.home.layout.module.scss @@ -52,6 +52,67 @@ $tabBar-height: 70px; gap: 10px; } + .common-chart { + display: grid; + grid-template-columns: 1fr; + grid-template-rows: 1fr; + gap: 10px; + + .chart-container { + display: grid; + grid-template-rows: 40px 1fr; + + .content { + padding: 0 5px; + display: flex; + justify-content: space-between; + align-items: center; + border-bottom: 1px solid #009FA8; + + .title { + font-size: 1em; + font-weight: bold; + } + } + + .chart { + height: 300px; + width: 100%; + } + } + } + + .rank-chart { + overflow: auto; + display: flex; + flex-direction: column; + gap: 5px; + + .rank-item { + padding: 10px; + display: grid; + grid-template-columns: 20px 1fr 80px; + align-items: center; + + .rank-amount { + justify-self: flex-end; + } + } + + .rank-item:nth-child(1) { + color: #d4af37; + font-weight: bold; + } + + .rank-item:nth-child(2) { + color: #a8a8a8; + } + + .rank-item:nth-child(3) { + color: #b87333; + } + } + .title-bar { background-color: var(--el-color-primary); height: $titleBar-height; diff --git a/src/utils/home/ledgerUtil.ts b/src/utils/home/ledgerUtil.ts index d39c27d..fbbf95c 100644 --- a/src/utils/home/ledgerUtil.ts +++ b/src/utils/home/ledgerUtil.ts @@ -22,3 +22,7 @@ export const statsByField = (records: ILedgerRecord[], .sort((a, b) => b.value - a.value) .slice(0, 5) } + +export const getLedgerSortByPrice = (records: ILedgerRecord[]) => { + return records.sort((a, b) => b?.totalPrice - a?.totalPrice) +} diff --git a/src/views/health/calendar.vue b/src/views/health/calendar.vue index cdbd3c1..9096f54 100644 --- a/src/views/health/calendar.vue +++ b/src/views/health/calendar.vue @@ -4,21 +4,19 @@ @dayclick="dateClick" @did-move="changeMonthClick" :is-dark="appStore.isDark" class="health-calendar card-item"/> - - -