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

This commit is contained in:
ilhamtahir committed 2025-02-17 05:28:29 +08:00
1 parent 57dcbe2d37
commit b17d62fbed
3 files changed
+107 -13

No files matched your search

+6 -2
View File
@@ -7,11 +7,15 @@ export interface Product extends BaseModel{
category: ProductCategory category: ProductCategory
photo: string; photo: string;
tags: string[]; tags: string[];
totalCalories: number;
totalWeight: 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{ export interface SearchProductFilter extends BaseFilterRequest{
} }
+83 -9
View File
@@ -14,7 +14,11 @@ const defaultData: CreateProductRequest = {
category: ProductCategory.DRY_FOOD, category: ProductCategory.DRY_FOOD,
tags: [], tags: [],
totalWeight: 0, totalWeight: 0,
totalCalories: 0 protein: 0,
fat: 0,
fiber: 0,
ash: 0,
moisture: 0
} }
const formData = ref<CreateProductRequest>(defaultData) const formData = ref<CreateProductRequest>(defaultData)
@@ -23,13 +27,19 @@ watch(
() => props.data, () => props.data,
(newData) => { (newData) => {
if (newData) { if (newData) {
// @ts-ignore
const existCategory = productCategoryOptions.find((item) => item.label === newData.category)
formData.value = { formData.value = {
name: newData.name, name: newData.name,
category: newData.category, category: existCategory ? existCategory.value : ProductCategory.DRY_FOOD,
photo: newData.photo, photo: newData.photo,
tags: newData.tags, tags: newData.tags,
protein: newData.protein,
fat: newData.fat,
fiber: newData.fiber,
ash: newData.ash,
moisture: newData.moisture,
totalWeight: newData.totalWeight, totalWeight: newData.totalWeight,
totalCalories: newData.totalCalories
} }
} else { } else {
formData.value = defaultData formData.value = defaultData
@@ -56,10 +66,34 @@ const rules: FormRules<CreateProductRequest> = {
message: '净重量不能为空' message: '净重量不能为空'
} }
], ],
totalCalories: [ protein: [
{ {
required: true, 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" suffix="g"
></TInputNumber> ></TInputNumber>
</TFormItem> </TFormItem>
<TFormItem label="总热量" name="totalCalories"> <TFormItem label="蛋白质" name="protein">
<TInputNumber <TInputNumber
v-model="formData.totalCalories" v-model="formData.protein"
clearable clearable
placeholder="请输入总热量" placeholder="请输入蛋白质含比"
theme="normal" theme="normal"
align="right" align="right"
suffix="kcal" 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.moisture"
clearable
placeholder="请输入水分含比"
theme="normal"
align="right"
suffix="%"
></TInputNumber> ></TInputNumber>
</TFormItem> </TFormItem>
</TForm> </TForm>
+18 -2
View File
@@ -35,8 +35,24 @@ const columns: BaseTableColumns = [
colKey: 'totalWeight', colKey: 'totalWeight',
}, },
{ {
title: '总热量', title: '蛋白质',
colKey: 'totalCalories' colKey: 'protein',
},
{
title: '脂肪',
colKey: 'fat',
},
{
title: '纤维',
colKey: 'fiber',
},
{
title: '粗灰分',
colKey: 'ash',
},
{
title: '水分',
colKey: 'moisture',
}, },
{ {
title: '创建时间', title: '创建时间',