Explorar o código

feat: 添加产品营养成分字段

IlhamTahir hai 11 meses
pai
achega
b17d62fbed

+ 6 - 2
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<Product, "name" | 'photo' | 'tags' | 'totalCalories' | 'totalWeight' | 'category'> {}
+export interface CreateProductRequest extends Pick<Product, "name" | 'photo' | 'tags' | 'totalWeight' | 'category' | 'protein' | 'fat' | 'fiber' | 'ash' | 'moisture'> {}
 
 export interface SearchProductFilter extends BaseFilterRequest{
 }

+ 83 - 9
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<CreateProductRequest>(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<CreateProductRequest> = {
       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"
         ></TInputNumber>
       </TFormItem>
-      <TFormItem label="总热量" name="totalCalories">
+      <TFormItem label="蛋白质" name="protein">
+        <TInputNumber
+          v-model="formData.protein"
+          clearable
+          placeholder="请输入蛋白质含比"
+          theme="normal"
+          align="right"
+          suffix="%"
+        ></TInputNumber>
+      </TFormItem>
+      <TFormItem label="脂肪" name="fat">
+        <TInputNumber
+          v-model="formData.fat"
+          clearable
+          placeholder="请输入脂肪含比"
+          theme="normal"
+          align="right"
+          suffix="%"
+        ></TInputNumber>
+      </TFormItem>
+      <TFormItem label="纤维" name="fiber">
+        <TInputNumber
+          v-model="formData.fiber"
+          clearable
+          placeholder="请输入纤维含比"
+          theme="normal"
+          align="right"
+          suffix="%"
+        ></TInputNumber>
+      </TFormItem>
+      <TFormItem label="粗灰分" name="ash">
+        <TInputNumber
+          v-model="formData.ash"
+          clearable
+          placeholder="请输入粗灰分含比"
+          theme="normal"
+          align="right"
+          suffix="%"
+        ></TInputNumber>
+      </TFormItem>
+      <TFormItem label="水分" name="moisture">
         <TInputNumber
-          v-model="formData.totalCalories"
+          v-model="formData.moisture"
           clearable
-          placeholder="请输入总热量"
+          placeholder="请输入水分含比"
           theme="normal"
           align="right"
-          suffix="kcal"
+          suffix="%"
         ></TInputNumber>
       </TFormItem>
     </TForm>

+ 18 - 2
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: '创建时间',