diff --git a/src/apis/food.ts b/src/apis/food.ts index b608e98..70318bd 100644 --- a/src/apis/food.ts +++ b/src/apis/food.ts @@ -1,41 +1,41 @@ import { cloudService } from './index' -import type { IFoodQuery, IFoodRecipe, IFoodRecord, IFoodStats } from '@/types/food' +import type { IFoodQuery, IRecipe, IRecord, IStats } from '@/types/food' import type { IStatsChart } from 'vue3-common/types' -export const addFoodRecipeApi = (foodRecipe: IFoodRecipe): Promise => +export const addRecipeApi = (recipe: IRecipe): Promise => cloudService({ url: '/food-service/food/recipe', method: 'post', - data: foodRecipe + data: recipe }) -export const updateFoodRecipeApi = (id: number, foodRecipe: IFoodRecipe): Promise => +export const updateRecipeApi = (id: number, recipe: IRecipe): Promise => cloudService({ url: `/food-service/food/recipe/${id}`, method: 'put', - data: foodRecipe + data: recipe }) -export const deleteFoodRecipeApi = (id: number): Promise => +export const deleteRecipeApi = (id: number): Promise => cloudService({ url: `/food-service/food/recipe/${id}`, method: 'DELETE' }) -export const queryFoodRecipeByIdApi = (id: number): Promise => +export const queryRecipeByIdApi = (id: number): Promise => cloudService({ url: `/food-service/food/recipe/${id}`, method: 'get' }) -export const queryFoodRecipeApi = (query: IFoodQuery): Promise => +export const queryRecipeApi = (query: IFoodQuery): Promise => cloudService({ url: '/food-service/food/recipe', method: 'get', params: { ...query } }) -export const queryFoodRecipeByPageApi = (currentPage: number, pageSize: number, +export const queryRecipeByPageApi = (currentPage: number, pageSize: number, query: IFoodQuery): Promise => cloudService({ url: '/food-service/food/recipe/page', @@ -49,58 +49,58 @@ export const queryFoodNameListApi = (): Promise => method: 'get' }) -export const addFoodRecordApi = (foodRecord: IFoodRecord): Promise => +export const addRecordApi = (record: IRecord): Promise => cloudService({ url: '/food-service/food/record', method: 'post', - data: foodRecord + data: record }) -export const updateFoodRecordApi = (id: number, foodRecord: IFoodRecord): Promise => +export const updateRecordApi = (id: number, record: IRecord): Promise => cloudService({ url: `/food-service/food/record/${id}`, method: 'put', - data: foodRecord + data: record }) -export const deleteFoodRecordApi = (id: number): Promise => +export const deleteRecordApi = (id: number): Promise => cloudService({ url: `/food-service/food/record/${id}`, method: 'DELETE' }) -export const queryFoodRecordApi = (startDate: string, endDate: string): Promise => +export const queryRecordApi = (startDate: string, endDate: string): Promise => cloudService({ url: '/food-service/food/record', method: 'get', params: { startDate, endDate } }) -export const queryFoodCategoryApi = (): Promise => +export const queryCategoryApi = (): Promise => cloudService({ url: '/food-service/food/category', method: 'get' }) -export const queryFoodStatsApi = (): Promise => +export const queryStatsApi = (): Promise => cloudService({ url: '/food-service/food/stats', method: 'get' }) -export const queryFoodRecordStatsApi = (): Promise => +export const queryRecordStatsApi = (): Promise => cloudService({ url: '/food-service/food/stats/record', method: 'get' }) -export const queryFoodCategoryStatsApi = (): Promise => +export const queryCategoryStatsApi = (): Promise => cloudService({ url: '/food-service/food/stats/category', method: 'get' }) -export const queryFoodRankStatsApi = (): Promise => +export const queryRankStatsApi = (): Promise => cloudService({ url: '/food-service/food/stats/rank', method: 'get' diff --git a/src/apis/moment.ts b/src/apis/moment.ts new file mode 100644 index 0000000..5666026 --- /dev/null +++ b/src/apis/moment.ts @@ -0,0 +1,23 @@ +import { cloudService } from './index' +import type { IComment, IMoment } from '@/types/food' + +export const addCommentApi = (id: number, comment: IComment): Promise => + cloudService({ + url: `/food-service/moment/${id}/comment`, + method: 'post', + data: comment + }) + +export const addMomentApi = (moment: IMoment): Promise => + cloudService({ + url: '/food-service/moment', + method: 'post', + data: moment + }) + +export const queryMomentApi = (): Promise => + cloudService({ + url: '/food-service/moment', + method: 'get' + }) + diff --git a/src/components/Food/FoodCard.vue b/src/components/Food/FoodCard.vue index 977833b..ccb8b13 100644 --- a/src/components/Food/FoodCard.vue +++ b/src/components/Food/FoodCard.vue @@ -2,7 +2,7 @@
- @@ -27,11 +27,11 @@
+ @click="editClick"/> + @click="viewClick()" /> + @click="deleteClick()" />
@@ -63,7 +63,7 @@ import { Edit, MoreFilled, DeleteFilled } from '@element-plus/icons-vue' import { useFoodStore } from '@/store/food' import { defineProps, onMounted, reactive } from 'vue' import type { PropType } from 'vue' -import type { IFoodRecipe, IFoodRecord } from '@/types/food.ts' +import type { IRecipe, IRecord } from '@/types/food.ts' import { useRouter } from 'vue-router' import { formatDate } from 'vue3-common/utils/dateUtil' import { deepCopyObject } from 'vue3-common/utils/dataUtil' @@ -81,7 +81,7 @@ const foodCardInfo = reactive({ const props = defineProps({ foodItem: { required: true, - type: Object as PropType + type: Object as PropType } }) @@ -89,14 +89,14 @@ onMounted(() => { foodCardInfo.recommendRate = props.foodItem?.recommendRate as number }) -const getFoodRecord = (recordList: IFoodRecord[]) => { +const getRecord = (recordList: IRecord[]) => { return recordList.filter((item) => item.imageUrl) } -const editFoodRecipeClick = async () => { +const editClick = async () => { const id = props.foodItem?.id - foodStore.foodRecipeApiType = 'UPDATE' - await foodStore.queryFoodRecipe(id as number) + foodStore.recipeApiType = 'UPDATE' + await foodStore.queryRecipe(id as number) // foodStore.foodRecipeDialog = { // title: '编辑菜谱', // visible: true, @@ -104,14 +104,14 @@ const editFoodRecipeClick = async () => { // } } -const viewFoodRecipeClick = async () => { +const viewClick = async () => { await router.push({ name: 'MobileHomeFoodDetailId', params: { id: props.foodItem?.id } }) } -const deleteFoodRecipeClick = () => { - foodStore.foodRecipeApiType = 'DELETE' +const deleteClick = () => { + foodStore.recipeApiType = 'DELETE' commonElMessageBox(`请确认是否删除该菜谱: ${props.foodItem?.name}?`).then(() => { - foodStore.handleFoodRecipeApi(props.foodItem) + foodStore.handleRecipeApi(props.foodItem) }) } diff --git a/src/components/Food/FoodDaily.vue b/src/components/Food/FoodDaily.vue index 692efe6..7522545 100644 --- a/src/components/Food/FoodDaily.vue +++ b/src/components/Food/FoodDaily.vue @@ -45,13 +45,13 @@ const updateInfo = () => { const getCalendarMoveDate = () => { dailyInfo.calendarDate = formatDate(new Date()) - const foodLength = foodStore.foodRecordList.length + const foodLength = foodStore.recordList.length if (foodLength > 0) { const today = formatDate(new Date()) - if (foodStore.foodRecordList.some((item) => item.date === today)) { + if (foodStore.recordList.some((item) => item.date === today)) { dailyInfo.calendarDate = today } else { - dailyInfo.calendarDate = formatDate(foodStore.foodRecordList[foodLength - 1].date) + dailyInfo.calendarDate = formatDate(foodStore.recordList[foodLength - 1].date) } } else { dailyInfo.calendarDate = '' @@ -66,7 +66,7 @@ const getCalendarAttrDates = () => { dates: new Date() }) - const dateList = foodStore.foodRecordList.map((item) => item.date) + const dateList = foodStore.recordList.map((item) => item.date) dailyInfo.attrs.push({ dot: 'red', dates: [...new Set(dateList)] diff --git a/src/components/Food/FoodDailyItem.vue b/src/components/Food/FoodDailyItem.vue index 69bd171..69aef6f 100644 --- a/src/components/Food/FoodDailyItem.vue +++ b/src/components/Food/FoodDailyItem.vue @@ -28,7 +28,7 @@ import { useFoodStore } from '@/store/food.ts' import { useRouter } from 'vue-router' import { useAppStore } from '@/store/app.ts' import { formatChineseDate } from 'vue3-common/utils/dateUtil' -import type { IFoodRecord } from '@/types/food.ts' +import type { IRecord } from '@/types/food.ts' const foodStore = useFoodStore() const appStore = useAppStore() @@ -55,7 +55,7 @@ onMounted(() => { const dailyItemInfo = reactive({ date: '', - itemList: [] as IFoodRecord[] + itemList: [] as IRecord[] }) /** @@ -67,7 +67,7 @@ const getFoodDailyByDate = (date: string) => { dailyItemInfo.date = formatChineseDate(date, 'MM月DD日 dddd') dailyItemInfo.itemList = [] - foodStore.foodRecordList.forEach((item) => { + foodStore.recordList.forEach((item) => { if (item.date === date) { dailyItemInfo.itemList.push(item) } @@ -79,9 +79,9 @@ const getFoodDailyByDate = (date: string) => { /** * 点击美食记录按钮 - * @param foodRecord 美食记录 + * @param record 美食记录 */ -const selectFoodRecordClick = async (foodRecord: IFoodRecord) => { +const selectFoodRecordClick = async (record: IRecord) => { // foodStore.foodRecordApiType = 'UPDATE' // appStore.isShowMobileBack = true diff --git a/src/components/Food/FoodMaterialForm.vue b/src/components/Food/FoodMaterialForm.vue index fd1ca38..b9a55f3 100644 --- a/src/components/Food/FoodMaterialForm.vue +++ b/src/components/Food/FoodMaterialForm.vue @@ -3,7 +3,7 @@
新增
- @@ -15,35 +15,35 @@ diff --git a/src/components/Food/FoodRecipe.vue b/src/components/Food/FoodRecipe.vue index adb4f7b..032c5b0 100644 --- a/src/components/Food/FoodRecipe.vue +++ b/src/components/Food/FoodRecipe.vue @@ -2,16 +2,16 @@
分类: -
- +
-
@@ -33,7 +33,7 @@ const foodStore = useFoodStore() const queryCategoryList = ref([] as ICategory[]) onMounted(async () => { - await foodStore.queryFoodCategory() + await foodStore.queryCategory() initCategoryList() // foodStore.foodRecipeList = [] await foodStore.refreshInfo() @@ -50,7 +50,7 @@ const initCategoryList = () => { label: '全部', value: '' }) - foodStore.foodCategoryList.forEach((item) => { + foodStore.categoryList.forEach((item) => { queryCategoryList.value.push({ label: item, value: item @@ -60,8 +60,8 @@ const initCategoryList = () => { const queryFoodSegmented = async () => { // foodStore.pageInfo.currentPage = 1 - foodStore.foodRecipeList = [] - await foodStore.queryFoodRecipeList() + foodStore.recipeList = [] + await foodStore.queryRecipeList() } const handleScroll = () => { @@ -71,7 +71,7 @@ const handleScroll = () => { foodStore.isScrollEnd = pageSize * currentPage > totalSize if (!foodStore.isScrollEnd) { foodStore.pageInfo.currentPage++ - foodStore.queryFoodRecipeList() + foodStore.queryRecipeList() } } } diff --git a/src/components/Food/FoodStepForm.vue b/src/components/Food/FoodStepForm.vue index 424eabf..d19f1c9 100644 --- a/src/components/Food/FoodStepForm.vue +++ b/src/components/Food/FoodStepForm.vue @@ -4,7 +4,7 @@ 新增
- @@ -20,7 +20,7 @@ diff --git a/src/components/Stats/FoodRank.vue b/src/components/Stats/FoodRank.vue index 2e57bdb..6da8d1d 100644 --- a/src/components/Stats/FoodRank.vue +++ b/src/components/Stats/FoodRank.vue @@ -15,5 +15,5 @@ const foodStore = useFoodStore() const MAX_RANK_COUNT = 10 -const foodRankList = computed(() => foodStore.foodRankStats) +const foodRankList = computed(() => foodStore.rankStats) diff --git a/src/components/Stats/FoodStats.vue b/src/components/Stats/FoodStats.vue index 33b4f83..f5f260f 100644 --- a/src/components/Stats/FoodStats.vue +++ b/src/components/Stats/FoodStats.vue @@ -2,15 +2,15 @@
+ :value="foodStore.stats.recipeCount"/> + :value="foodStore.stats.categoryCount"/> + :value="foodStore.stats.workCount"/> { - await foodStore.queryFoodStats() + await foodStore.queryStats() }) const getAverageCount = () => { if (foodStore.queryDateType === 'month') { - return foodStore.foodRecordList.length + return foodStore.recordList.length } else { const result = {} // 遍历数据,按月统计出现次数 - foodStore.foodRecordList.forEach((item) => { + foodStore.recordList.forEach((item) => { const date = new Date(item.date) const month = String(date.getMonth() + 1) @@ -47,7 +47,7 @@ const getAverageCount = () => { } }) - return foodStore.foodRecordList.length / Object.keys(result).length + return foodStore.recordList.length / Object.keys(result).length } } diff --git a/src/store/food.ts b/src/store/food.ts index 3e19e61..cacea1a 100644 --- a/src/store/food.ts +++ b/src/store/food.ts @@ -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, - editFoodMaterialIndex: 0, - foodStepApiType: 'ADD' as IHandleApi, - foodStepDialog: { + } as IDialog, + editMaterialIndex: 0, + stepApiType: 'ADD' as IHandleApi, + stepDialog: { visible: false, title: '', data: {} - } as IDialog, - editFoodStepIndex: 0, - foodRecordApiType: 'ADD' as IHandleApi, - editFoodRecordIndex: 0, - foodImagePath: 'food', + } as IDialog, + 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, diff --git a/src/types/food.ts b/src/types/food.ts index 72dc468..fc86e6b 100644 --- a/src/types/food.ts +++ b/src/types/food.ts @@ -3,7 +3,7 @@ export type IFoodSegment = 'recipe' | 'daily' | 'timeline' /** * 食材信息 */ -export interface IFoodMaterial { +export interface IMaterial { type: string; name: string; amount: string; @@ -12,7 +12,7 @@ export interface IFoodMaterial { /** * 步骤信息 */ -export interface IFoodStep { +export interface IStep { sort: number; content: string; imageUrl: string; @@ -21,7 +21,7 @@ export interface IFoodStep { /** * 成果信息 */ -export interface IFoodRecord { +export interface IRecord { id: number; name: string; category: string; @@ -33,7 +33,7 @@ export interface IFoodRecord { /** * 菜谱信息 */ -export interface IFoodRecipe { +export interface IRecipe { id?: number; /** * 美食名称 @@ -54,21 +54,21 @@ export interface IFoodRecipe { /** * 食材 */ - materialList: IFoodMaterial[]; + materialList: IMaterial[]; /** * 步骤 */ - stepList: IFoodStep[]; + stepList: IStep[]; /** * 成果 */ - recordList: IFoodRecord[]; + recordList: IRecord[]; } /** * 统计信息 */ -export interface IFoodStats { +export interface IStats { recipeCount: number; categoryCount: number; workCount: number; @@ -77,3 +77,20 @@ export interface IFoodStats { export interface IFoodQuery { category: string; } + +export interface IComment { + id: number; + username: string; + avatar: string; + content: string; + date: string; +} + +export interface IMoment { + id: number; + username: string; + avatar: string; + content: string; + date: string; + commentList: IComment[]; +} diff --git a/src/views/moment/index.vue b/src/views/moment/index.vue index 0214113..b2f6661 100644 --- a/src/views/moment/index.vue +++ b/src/views/moment/index.vue @@ -1,11 +1,20 @@