feat:增加菜谱显示模块

This commit is contained in:
2025-06-25 19:55:23 +08:00
parent eff6078a98
commit 37b2e588db
22 changed files with 673 additions and 92 deletions

View File

@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import type {
IRecipe, IMaterial, IStep,
IStats, IRecord, IMoment
IStats, IRecord, IMoment, IFoodSegment, IComment
} from '@/types/food'
import {
addRecipeApi,
@@ -21,7 +21,7 @@ import {
import type { IDialog, IHandleApi, IStatsChart } from 'vue3-common/types'
import { ElMessage } from 'element-plus'
import { getCurrentMonth, getCurrentYear, getStartEndDate } from 'vue3-common/utils/dateUtil'
import { queryMomentApi } from '@/apis/moment'
import { addCommentApi, addMomentApi, queryMomentApi, updateMomentApi } from '@/apis/moment'
export const useFoodStore = defineStore('food', {
state: () => ({
@@ -45,6 +45,7 @@ export const useFoodStore = defineStore('food', {
person: '',
imageUrl: ''
} as IRecord,
recordSegment: 'recipe' as IFoodSegment,
momentList: [] as IMoment[],
foodNameList: [] as string[],
queryRecipeSegment: {
@@ -73,6 +74,10 @@ export const useFoodStore = defineStore('food', {
editStepIndex: 0,
recordApiType: 'ADD' as IHandleApi,
editRecordIndex: 0,
currentMoment: {
content: ''
} as IMoment,
momentApiType: 'ADD' as IHandleApi,
imagePath: 'food',
rateColorList: ['#E2DEDC', '#F7BA2A', '#009FA8'],
pageInfo: {
@@ -98,7 +103,7 @@ export const useFoodStore = defineStore('food', {
// const result = await queryFoodRecipeByPageApi(currentPage, pageSize, this.queryRecipe)
// this.foodRecipeList.push(...result.records)
// this.pageInfo.totalSize = result.total
this.recipeList = await queryRecipeApi(this.queryRecipe)
this.recipeList = await queryRecipeApi(this.queryRecipeSegment)
},
async queryRecordList() {
const { year, month } = this.queryRecord
@@ -163,6 +168,29 @@ export const useFoodStore = defineStore('food', {
}
await this.refreshInfo()
},
async handleMomentApi(moment: IMoment) {
switch (this.momentApiType) {
case 'ADD':
await addMomentApi(moment)
ElMessage.success('发布朋友圈成功')
break
case 'UPDATE':
await updateMomentApi(moment.id as number, moment)
ElMessage.success('更新朋友圈成功')
break
case 'DELETE':
// await deleteRecordApi(record.id as number)
ElMessage.success('删除朋友圈成功')
break
default:
break
}
await queryMomentApi()
},
async addComment(id: number, content: string) {
await addCommentApi(id, content)
await this.queryMomentList()
},
async refreshInfo() {
await this.queryRecipeList()
await this.queryRecordList()
@@ -202,6 +230,11 @@ export const useFoodStore = defineStore('food', {
imageUrl: '',
name: ''
}
},
getEmptyMoment(): IMoment {
return {
content: ''
}
}
}
})