diff --git a/src/model/product.ts b/src/model/product.ts index de19b4f..ae0e658 100644 --- a/src/model/product.ts +++ b/src/model/product.ts @@ -7,11 +7,15 @@ export interface Product extends BaseModel{ category: ProductCategory photo: string; tags: string[]; - totalCalories: number; totalWeight: number; + protein: number; + fat: number; + fiber: number; + ash: number; + moisture: number; } -export interface CreateProductRequest extends Pick {} +export interface CreateProductRequest extends Pick {} export interface SearchProductFilter extends BaseFilterRequest{ } diff --git a/src/pages/product/components/ProductDialog.vue b/src/pages/product/components/ProductDialog.vue index c46331a..69480a5 100644 --- a/src/pages/product/components/ProductDialog.vue +++ b/src/pages/product/components/ProductDialog.vue @@ -14,7 +14,11 @@ const defaultData: CreateProductRequest = { category: ProductCategory.DRY_FOOD, tags: [], totalWeight: 0, - totalCalories: 0 + protein: 0, + fat: 0, + fiber: 0, + ash: 0, + moisture: 0 } const formData = ref(defaultData) @@ -23,13 +27,19 @@ watch( () => props.data, (newData) => { if (newData) { + // @ts-ignore + const existCategory = productCategoryOptions.find((item) => item.label === newData.category) formData.value = { name: newData.name, - category: newData.category, + category: existCategory ? existCategory.value : ProductCategory.DRY_FOOD, photo: newData.photo, tags: newData.tags, + protein: newData.protein, + fat: newData.fat, + fiber: newData.fiber, + ash: newData.ash, + moisture: newData.moisture, totalWeight: newData.totalWeight, - totalCalories: newData.totalCalories } } else { formData.value = defaultData @@ -56,10 +66,34 @@ const rules: FormRules = { message: '净重量不能为空' } ], - totalCalories: [ + protein: [ { required: true, - message: '总热量不能为空' + message: '蛋白质不能为空' + } + ], + fat: [ + { + required: true, + message: '脂肪不能为空' + } + ], + fiber: [ + { + required: true, + message: '纤维不能为空' + } + ], + ash: [ + { + required: true, + message: '粗灰分不能为空' + } + ], + moisture: [ + { + required: true, + message: '水分不能为空' } ] } @@ -112,14 +146,54 @@ const handleSave = async () => { suffix="g" > - + + + + + + + + + + + + + diff --git a/src/pages/product/index.vue b/src/pages/product/index.vue index 6bc6c9a..e38bd19 100644 --- a/src/pages/product/index.vue +++ b/src/pages/product/index.vue @@ -35,8 +35,24 @@ const columns: BaseTableColumns = [ colKey: 'totalWeight', }, { - title: '总热量', - colKey: 'totalCalories' + title: '蛋白质', + colKey: 'protein', + }, + { + title: '脂肪', + colKey: 'fat', + }, + { + title: '纤维', + colKey: 'fiber', + }, + { + title: '粗灰分', + colKey: 'ash', + }, + { + title: '水分', + colKey: 'moisture', }, { title: '创建时间',