feat:增加美食朋友圈接口
This commit is contained in:
@@ -1,31 +1,32 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type {
|
||||
IFoodRecipe, IFoodMaterial, IFoodStep,
|
||||
IFoodStats, IFoodRecord
|
||||
IRecipe, IMaterial, IStep,
|
||||
IStats, IRecord, IMoment
|
||||
} from '@/types/food'
|
||||
import {
|
||||
addFoodRecipeApi,
|
||||
addFoodRecordApi,
|
||||
deleteFoodRecipeApi,
|
||||
deleteFoodRecordApi,
|
||||
addRecipeApi,
|
||||
addRecordApi,
|
||||
deleteRecipeApi,
|
||||
deleteRecordApi,
|
||||
queryFoodNameListApi,
|
||||
queryFoodRecipeByIdApi,
|
||||
queryFoodRecordApi,
|
||||
queryFoodStatsApi,
|
||||
updateFoodRecipeApi,
|
||||
updateFoodRecordApi,
|
||||
queryFoodCategoryApi,
|
||||
queryFoodRecordStatsApi,
|
||||
queryFoodCategoryStatsApi, queryFoodRankStatsApi, queryFoodRecipeApi
|
||||
queryRecipeByIdApi,
|
||||
queryRecordApi,
|
||||
queryStatsApi,
|
||||
updateRecipeApi,
|
||||
updateRecordApi,
|
||||
queryCategoryApi,
|
||||
queryRecordStatsApi,
|
||||
queryCategoryStatsApi, queryRankStatsApi, queryRecipeApi
|
||||
} from '@/apis/food.ts'
|
||||
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'
|
||||
|
||||
export const useFoodStore = defineStore('food', {
|
||||
state: () => ({
|
||||
foodRecipeList: [] as IFoodRecipe[],
|
||||
currentFoodRecipe: {
|
||||
recipeList: [] as IRecipe[],
|
||||
currentRecipe: {
|
||||
id: 0,
|
||||
name: '',
|
||||
category: '',
|
||||
@@ -34,18 +35,19 @@ export const useFoodStore = defineStore('food', {
|
||||
materialList: [],
|
||||
stepList: [],
|
||||
recordList: []
|
||||
} as IFoodRecipe,
|
||||
foodRecordList: [] as IFoodRecord[],
|
||||
currentFoodRecord: {
|
||||
} as IRecipe,
|
||||
recordList: [] as IRecord[],
|
||||
currentRecord: {
|
||||
id: 0,
|
||||
name: '',
|
||||
category: '',
|
||||
date: '',
|
||||
person: '',
|
||||
imageUrl: ''
|
||||
} as IFoodRecord,
|
||||
} as IRecord,
|
||||
momentList: [] as IMoment[],
|
||||
foodNameList: [] as string[],
|
||||
queryRecipe: {
|
||||
queryRecipeSegment: {
|
||||
category: ''
|
||||
},
|
||||
queryRecord: {
|
||||
@@ -54,24 +56,24 @@ export const useFoodStore = defineStore('food', {
|
||||
},
|
||||
queryDateType: 'month' as 'month' | 'year',
|
||||
queryDateList: [] as string[],
|
||||
foodRecipeApiType: 'ADD' as IHandleApi,
|
||||
foodMaterialApiType: 'ADD' as IHandleApi,
|
||||
foodMaterialDialog: {
|
||||
recipeApiType: 'ADD' as IHandleApi,
|
||||
materialApiType: 'ADD' as IHandleApi,
|
||||
materialDialog: {
|
||||
visible: false,
|
||||
title: '',
|
||||
data: {}
|
||||
} as IDialog<IFoodMaterial>,
|
||||
editFoodMaterialIndex: 0,
|
||||
foodStepApiType: 'ADD' as IHandleApi,
|
||||
foodStepDialog: {
|
||||
} as IDialog<IMaterial>,
|
||||
editMaterialIndex: 0,
|
||||
stepApiType: 'ADD' as IHandleApi,
|
||||
stepDialog: {
|
||||
visible: false,
|
||||
title: '',
|
||||
data: {}
|
||||
} as IDialog<IFoodStep>,
|
||||
editFoodStepIndex: 0,
|
||||
foodRecordApiType: 'ADD' as IHandleApi,
|
||||
editFoodRecordIndex: 0,
|
||||
foodImagePath: 'food',
|
||||
} as IDialog<IStep>,
|
||||
editStepIndex: 0,
|
||||
recordApiType: 'ADD' as IHandleApi,
|
||||
editRecordIndex: 0,
|
||||
imagePath: 'food',
|
||||
rateColorList: ['#E2DEDC', '#F7BA2A', '#009FA8'],
|
||||
pageInfo: {
|
||||
currentPage: 1,
|
||||
@@ -79,59 +81,62 @@ export const useFoodStore = defineStore('food', {
|
||||
totalSize: 1
|
||||
},
|
||||
isScrollEnd: false,
|
||||
foodCategoryList: [] as string[],
|
||||
foodStats: {
|
||||
categoryList: [] as string[],
|
||||
stats: {
|
||||
recipeCount: 0,
|
||||
categoryCount: 0,
|
||||
workCount: 0
|
||||
} as IFoodStats,
|
||||
foodRecordStats: [] as IStatsChart[],
|
||||
foodCategoryStats: [] as IStatsChart[],
|
||||
foodRankStats: [] as IStatsChart[],
|
||||
} as IStats,
|
||||
recordStats: [] as IStatsChart[],
|
||||
categoryStats: [] as IStatsChart[],
|
||||
rankStats: [] as IStatsChart[],
|
||||
isRefresh: false
|
||||
}),
|
||||
actions: {
|
||||
async queryFoodRecipeList() {
|
||||
async queryRecipeList() {
|
||||
// const { currentPage, pageSize } = this.pageInfo
|
||||
// const result = await queryFoodRecipeByPageApi(currentPage, pageSize, this.queryRecipe)
|
||||
// this.foodRecipeList.push(...result.records)
|
||||
// this.pageInfo.totalSize = result.total
|
||||
this.foodRecipeList = await queryFoodRecipeApi(this.queryRecipe)
|
||||
this.recipeList = await queryRecipeApi(this.queryRecipe)
|
||||
},
|
||||
async queryFoodRecordList() {
|
||||
async queryRecordList() {
|
||||
const { year, month } = this.queryRecord
|
||||
const date = this.queryDateType === 'year' ? year : month
|
||||
this.queryDateList = getStartEndDate(date, this.queryDateType)
|
||||
this.foodRecordList = await queryFoodRecordApi(this.queryDateList[0], this.queryDateList[1])
|
||||
this.recordList = await queryRecordApi(this.queryDateList[0], this.queryDateList[1])
|
||||
},
|
||||
async queryMomentList() {
|
||||
this.momentList = await queryMomentApi()
|
||||
},
|
||||
async queryFoodNameList() {
|
||||
this.foodNameList = await queryFoodNameListApi()
|
||||
},
|
||||
async queryFoodRecipe(id: number) {
|
||||
this.currentFoodRecipe = await queryFoodRecipeByIdApi(id)
|
||||
async queryRecipe(id: number) {
|
||||
this.currentRecipe = await queryRecipeByIdApi(id)
|
||||
},
|
||||
async queryFoodStats() {
|
||||
this.foodStats = await queryFoodStatsApi()
|
||||
this.foodRecordStats = await queryFoodRecordStatsApi()
|
||||
this.foodCategoryStats = await queryFoodCategoryStatsApi()
|
||||
this.foodRankStats = await queryFoodRankStatsApi()
|
||||
async queryStats() {
|
||||
this.stats = await queryStatsApi()
|
||||
this.recordStats = await queryRecordStatsApi()
|
||||
this.categoryStats = await queryCategoryStatsApi()
|
||||
this.rankStats = await queryRankStatsApi()
|
||||
this.isRefresh = !this.isRefresh
|
||||
},
|
||||
async queryFoodCategory() {
|
||||
this.foodCategoryList = await queryFoodCategoryApi()
|
||||
async queryCategory() {
|
||||
this.categoryList = await queryCategoryApi()
|
||||
},
|
||||
async handleFoodRecipeApi(foodRecipe: IFoodRecipe) {
|
||||
switch (this.foodRecipeApiType) {
|
||||
async handleRecipeApi(recipe: IRecipe) {
|
||||
switch (this.recipeApiType) {
|
||||
case 'ADD':
|
||||
await addFoodRecipeApi(foodRecipe)
|
||||
await addRecipeApi(recipe)
|
||||
ElMessage.success('新增菜谱成功')
|
||||
break
|
||||
case 'UPDATE':
|
||||
await updateFoodRecipeApi(foodRecipe.id as number, foodRecipe)
|
||||
await updateRecipeApi(recipe.id as number, recipe)
|
||||
ElMessage.success('更新菜谱成功')
|
||||
break
|
||||
case 'DELETE':
|
||||
await deleteFoodRecipeApi(foodRecipe.id as number)
|
||||
await deleteRecipeApi(recipe.id as number)
|
||||
ElMessage.success('删除菜谱成功')
|
||||
break
|
||||
default:
|
||||
@@ -139,18 +144,18 @@ export const useFoodStore = defineStore('food', {
|
||||
}
|
||||
await this.refreshInfo()
|
||||
},
|
||||
async handleFoodRecordApi(foodRecord: IFoodRecord) {
|
||||
switch (this.foodRecordApiType) {
|
||||
async handleRecordApi(record: IRecord) {
|
||||
switch (this.recordApiType) {
|
||||
case 'ADD':
|
||||
await addFoodRecordApi(foodRecord)
|
||||
await addRecordApi(record)
|
||||
ElMessage.success('新增成果成功')
|
||||
break
|
||||
case 'UPDATE':
|
||||
await updateFoodRecordApi(foodRecord.id as number, foodRecord)
|
||||
await updateRecordApi(record.id as number, record)
|
||||
ElMessage.success('更新成果成功')
|
||||
break
|
||||
case 'DELETE':
|
||||
await deleteFoodRecordApi(foodRecord.id as number)
|
||||
await deleteRecordApi(record.id as number)
|
||||
ElMessage.success('删除成果成功')
|
||||
break
|
||||
default:
|
||||
@@ -159,11 +164,11 @@ export const useFoodStore = defineStore('food', {
|
||||
await this.refreshInfo()
|
||||
},
|
||||
async refreshInfo() {
|
||||
await this.queryFoodRecipeList()
|
||||
await this.queryFoodRecordList()
|
||||
await this.queryRecipeList()
|
||||
await this.queryRecordList()
|
||||
this.isRefresh = !this.isRefresh
|
||||
},
|
||||
getEmptyFoodRecipe(): IFoodRecipe {
|
||||
getEmptyRecipe(): IRecipe {
|
||||
return {
|
||||
category: '',
|
||||
materialList: [],
|
||||
@@ -174,22 +179,23 @@ export const useFoodStore = defineStore('food', {
|
||||
recordList: []
|
||||
}
|
||||
},
|
||||
getEmptyFoodMaterial(): IFoodMaterial {
|
||||
getEmptyMaterial(): IMaterial {
|
||||
return {
|
||||
amount: '',
|
||||
name: '',
|
||||
type: ''
|
||||
}
|
||||
},
|
||||
getEmptyFoodStep(): IFoodStep {
|
||||
getEmptyStep(): IStep {
|
||||
return {
|
||||
content: '',
|
||||
imageUrl: '',
|
||||
sort: 0
|
||||
}
|
||||
},
|
||||
getEmptyFoodRecord(): IFoodRecord {
|
||||
getEmptyRecord(): IRecord {
|
||||
return {
|
||||
person: 0,
|
||||
category: '',
|
||||
date: '',
|
||||
id: 0,
|
||||
|
||||
Reference in New Issue
Block a user