236 lines
6.7 KiB
TypeScript
236 lines
6.7 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import type {
|
|
IFoodRecipe, IFoodMaterial, IFoodStep,
|
|
IFoodStats, IFoodRecord
|
|
} from '@/types/food'
|
|
// import {
|
|
// addFoodRecipeApi, addFoodRecordApi, deleteFoodRecipeApi, deleteFoodRecordApi,
|
|
// queryFoodNameListApi, queryFoodRecipeByIdApi, queryFoodRecipeApi, queryFoodRecordApi,
|
|
// queryFoodStatsApi, updateFoodRecipeApi, updateFoodRecordApi, queryFoodCategoryApi
|
|
// } from '@/apis/food.ts'
|
|
// import { IDateType, ImagePathEnum } from '@/types'
|
|
import type { IDialog, IHandleApi } from 'vue3-common/types'
|
|
import { ElMessage } from 'element-plus'
|
|
import { getCurrentMonth, getCurrentYear, getStartEndDate } from 'vue3-common/utils/dateUtil'
|
|
import { isMobile } from 'vue3-common/utils/layoutUtil'
|
|
|
|
export const useFoodStore = defineStore('food', {
|
|
state: () => ({
|
|
foodRecipeList: [] as IFoodRecipe[],
|
|
currentFoodRecipe: {
|
|
id: 0,
|
|
name: '',
|
|
category: '',
|
|
recommendRate: 0,
|
|
remark: '',
|
|
materialList: [],
|
|
stepList: [],
|
|
recordList: []
|
|
} as IFoodRecipe,
|
|
foodRecordList: [] as IFoodRecord[],
|
|
currentFoodRecord: {
|
|
id: 0,
|
|
name: '',
|
|
category: '',
|
|
date: '',
|
|
person: '',
|
|
imageUrl: ''
|
|
} as IFoodRecord,
|
|
foodNameList: [] as string[],
|
|
queryRecipe: {
|
|
category: ''
|
|
},
|
|
queryRecord: {
|
|
year: getCurrentYear(),
|
|
month: getCurrentMonth()
|
|
},
|
|
queryDateType: 'month',
|
|
queryDateList: [] as string[],
|
|
foodRecipeApiType: 'ADD' as IHandleApi,
|
|
foodRecipeDialog: {
|
|
visible: false,
|
|
title: '',
|
|
data: {}
|
|
} as IDialog<IFoodRecipe>,
|
|
foodMaterialApiType: 'ADD' as IHandleApi,
|
|
foodMaterialDialog: {
|
|
visible: false,
|
|
title: '',
|
|
data: {}
|
|
} as IDialog<IFoodMaterial>,
|
|
editFoodMaterialIndex: 0,
|
|
foodStepApiType: 'ADD' as IHandleApi,
|
|
foodStepDialog: {
|
|
visible: false,
|
|
title: '',
|
|
data: {}
|
|
} as IDialog<IFoodStep>,
|
|
editFoodStepIndex: 0,
|
|
foodRecordApiType: 'ADD' as IHandleApi,
|
|
foodRecordDialog: {
|
|
visible: false,
|
|
title: '',
|
|
data: {}
|
|
} as IDialog<IFoodRecord>,
|
|
editFoodRecordIndex: 0,
|
|
foodImagePath: 'food',
|
|
rateColorList: ['#E2DEDC', '#F7BA2A', '#009FA8'],
|
|
pageInfo: {
|
|
currentPage: 1,
|
|
pageSize: 3,
|
|
totalSize: 1
|
|
},
|
|
isScrollEnd: false,
|
|
foodCategoryList: [] as string[],
|
|
foodStats: {
|
|
recipeCount: 0,
|
|
categoryCount: 0,
|
|
workCount: 0
|
|
} as IFoodStats,
|
|
isRefresh: false
|
|
}),
|
|
actions: {
|
|
async queryFoodRecipeList() {
|
|
const { currentPage, pageSize } = this.pageInfo
|
|
// const result = await queryFoodRecipeApi(currentPage, pageSize, this.queryRecipe)
|
|
const foodRecord: IFoodRecipe = {
|
|
category: '家常菜',
|
|
materialList: [],
|
|
name: '红烧鱼',
|
|
recommendRate: 4,
|
|
recordList: [],
|
|
remark: '',
|
|
stepList: []
|
|
}
|
|
this.foodRecipeList = []
|
|
this.foodRecipeList.push(foodRecord)
|
|
this.foodRecipeList.push(foodRecord)
|
|
// this.foodRecipeList.push(...result.records)
|
|
// this.pageInfo.totalSize = result.total
|
|
},
|
|
async queryFoodRecordList() {
|
|
const { year, month } = this.queryRecord
|
|
const date = this.queryDateType === 'year' ? year : month
|
|
this.queryDateList = getStartEndDate(date, this.queryDateType)
|
|
|
|
const foodRecord: IFoodRecord = {
|
|
category: '家常菜',
|
|
date: '2025-06-23',
|
|
id: 0,
|
|
imageUrl: 'https://ts2.tc.mm.bing.net/th/id/OSK.277ab994364a7e09543c78379bab1d05?w=612&h=408&c=7&rs=1&qlt=80&o=6&cdv=1&cb=ircwebp1&pid=16.1',
|
|
name: '红烧鱼',
|
|
person: '哥哥'
|
|
}
|
|
const foodRecord2: IFoodRecord = {
|
|
category: '家常菜',
|
|
date: '2025-06-22',
|
|
id: 0,
|
|
imageUrl: 'https://ts2.tc.mm.bing.net/th/id/OSK.277ab994364a7e09543c78379bab1d05?w=612&h=408&c=7&rs=1&qlt=80&o=6&cdv=1&cb=ircwebp1&pid=16.1',
|
|
name: '红烧鱼',
|
|
person: '哥哥'
|
|
}
|
|
this.foodRecordList = []
|
|
this.foodRecordList.push(foodRecord)
|
|
this.foodRecordList.push(foodRecord2)
|
|
// this.foodRecordList = await queryFoodRecordApi(this.queryDateList[0], this.queryDateList[1])
|
|
},
|
|
async queryFoodNameList() {
|
|
// this.foodNameList = await queryFoodNameListApi()
|
|
},
|
|
async queryFoodRecipe(id: number) {
|
|
// this.currentFoodRecipe = await queryFoodRecipeByIdApi(id)
|
|
},
|
|
async queryFoodStats() {
|
|
// this.foodStats = await queryFoodStatsApi()
|
|
this.isRefresh = !this.isRefresh
|
|
},
|
|
async queryFoodCategory() {
|
|
// this.foodCategoryList = await queryFoodCategoryApi()
|
|
},
|
|
async handleFoodRecipeApi(id?: number) {
|
|
const { data } = this.foodRecipeDialog
|
|
switch (this.foodRecipeApiType) {
|
|
case 'ADD':
|
|
// await addFoodRecipeApi(data)
|
|
ElMessage.success('新增菜谱成功')
|
|
break
|
|
case 'UPDATE':
|
|
// await updateFoodRecipeApi(data.id as number, data)
|
|
ElMessage.success('更新菜谱成功')
|
|
break
|
|
case 'DELETE':
|
|
// await deleteFoodRecipeApi(id as number)
|
|
ElMessage.success('删除菜谱成功')
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
this.foodRecipeDialog.visible = false
|
|
await this.refreshInfo()
|
|
},
|
|
async handleFoodRecordApi(foodRecord: IFoodRecord) {
|
|
switch (this.foodRecordApiType) {
|
|
case 'ADD':
|
|
// await addFoodRecordApi(foodRecord)
|
|
ElMessage.success('新增成果成功')
|
|
break
|
|
case 'UPDATE':
|
|
// await updateFoodRecordApi(foodRecord.id as number, foodRecord)
|
|
ElMessage.success('更新成果成功')
|
|
break
|
|
case 'DELETE':
|
|
// await deleteFoodRecordApi(foodRecord.id as number)
|
|
ElMessage.success('删除成果成功')
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
this.foodRecordDialog.visible = false
|
|
|
|
if (!isMobile()) {
|
|
await this.refreshInfo()
|
|
}
|
|
},
|
|
async refreshInfo() {
|
|
await this.queryFoodRecipeList()
|
|
await this.queryFoodRecordList()
|
|
this.isRefresh = !this.isRefresh
|
|
},
|
|
getEmptyFoodRecipe(): IFoodRecipe {
|
|
return {
|
|
category: '',
|
|
materialList: [],
|
|
name: '',
|
|
recommendRate: 0,
|
|
remark: '',
|
|
stepList: [],
|
|
recordList: []
|
|
}
|
|
},
|
|
getEmptyFoodMaterial(): IFoodMaterial {
|
|
return {
|
|
amount: '',
|
|
name: '',
|
|
type: ''
|
|
}
|
|
},
|
|
getEmptyFoodStep(): IFoodStep {
|
|
return {
|
|
content: '',
|
|
imageUrl: '',
|
|
sort: 0
|
|
}
|
|
},
|
|
getEmptyFoodRecord(): IFoodRecord {
|
|
return {
|
|
category: '',
|
|
person: '',
|
|
date: '',
|
|
id: 0,
|
|
imageUrl: '',
|
|
name: ''
|
|
}
|
|
}
|
|
}
|
|
})
|