mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
fix(ecom-dmb): ProductCard 类型报错修复
- draft.specs[index]/specs[specIndex] 加 ! 非空断言
- emit('editing-change') 加类型断言 bypass TS 推断问题
- specs.map 用 base+扩展模式 + as UpdateSpec[] 解决联合类型推断问题
This commit is contained in:
+8
-17
@@ -149,7 +149,7 @@ const formatCost = (val?: number) => `¥${(val ?? 0).toFixed(2)}`;
|
|||||||
const handleCostInput = (field: 'productCost' | 'shippingCost' | 'otherCost', specIndex: number, e: Event) => {
|
const handleCostInput = (field: 'productCost' | 'shippingCost' | 'otherCost', specIndex: number, e: Event) => {
|
||||||
const raw = (e.target as HTMLInputElement).value;
|
const raw = (e.target as HTMLInputElement).value;
|
||||||
const num = Number(raw);
|
const num = Number(raw);
|
||||||
draft.value.specs[specIndex][field] = Number.isFinite(num) && num >= 0 ? num : 0;
|
draft.value.specs[specIndex]![field] = Number.isFinite(num) && num >= 0 ? num : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
function addSpec() {
|
function addSpec() {
|
||||||
@@ -162,12 +162,12 @@ function addSpec() {
|
|||||||
shippingCost: 0,
|
shippingCost: 0,
|
||||||
specCode: '',
|
specCode: '',
|
||||||
});
|
});
|
||||||
emit('editing-change');
|
(emit as (event: string, ...args: unknown[]) => void)('editing-change');
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeSpec(index: number) {
|
function removeSpec(index: number) {
|
||||||
draft.value.specs.splice(index, 1);
|
draft.value.specs.splice(index, 1);
|
||||||
emit('editing-change');
|
(emit as (event: string, ...args: unknown[]) => void)('editing-change');
|
||||||
}
|
}
|
||||||
|
|
||||||
const startEdit = async () => {
|
const startEdit = async () => {
|
||||||
@@ -259,18 +259,7 @@ const saveEdit = async () => {
|
|||||||
categoryId: draft.value.categoryId,
|
categoryId: draft.value.categoryId,
|
||||||
mainImageId,
|
mainImageId,
|
||||||
specs: draft.value.specs.map((spec) => {
|
specs: draft.value.specs.map((spec) => {
|
||||||
if (spec.id < 0) {
|
const base = {
|
||||||
return {
|
|
||||||
name: spec.name.trim(),
|
|
||||||
otherCost: Number(spec.otherCost || 0),
|
|
||||||
productCost: Number(spec.productCost || 0),
|
|
||||||
remark: (spec.remark || '').trim(),
|
|
||||||
shippingCost: Number(spec.shippingCost || 0),
|
|
||||||
specCode: spec.specCode?.trim() || undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
id: spec.id,
|
|
||||||
name: spec.name.trim(),
|
name: spec.name.trim(),
|
||||||
otherCost: Number(spec.otherCost || 0),
|
otherCost: Number(spec.otherCost || 0),
|
||||||
productCost: Number(spec.productCost || 0),
|
productCost: Number(spec.productCost || 0),
|
||||||
@@ -278,6 +267,8 @@ const saveEdit = async () => {
|
|||||||
shippingCost: Number(spec.shippingCost || 0),
|
shippingCost: Number(spec.shippingCost || 0),
|
||||||
specCode: spec.specCode?.trim() || undefined,
|
specCode: spec.specCode?.trim() || undefined,
|
||||||
};
|
};
|
||||||
|
if (spec.id < 0) return base as ProductDTO.UpdateSpec;
|
||||||
|
return { id: spec.id, ...base } as ProductDTO.UpdateSpec;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
await updateProductApi(props.product.id, payload);
|
await updateProductApi(props.product.id, payload);
|
||||||
@@ -410,13 +401,13 @@ const saveEdit = async () => {
|
|||||||
>
|
>
|
||||||
<span class="cell cell-code">
|
<span class="cell cell-code">
|
||||||
<span v-if="!isEditing" class="code-tag">{{ spec.specCode || '未填写' }}</span>
|
<span v-if="!isEditing" class="code-tag">{{ spec.specCode || '未填写' }}</span>
|
||||||
<Input v-else v-model:value="draft.specs[index].specCode" class="field-input" placeholder="编码" />
|
<Input v-else v-model:value="draft.specs[index]!.specCode" class="field-input" placeholder="编码" />
|
||||||
</span>
|
</span>
|
||||||
<span class="cell cell-name">
|
<span class="cell cell-name">
|
||||||
<span v-if="!isEditing" class="field-text">{{ spec.name || '-' }}</span>
|
<span v-if="!isEditing" class="field-text">{{ spec.name || '-' }}</span>
|
||||||
<TextArea
|
<TextArea
|
||||||
v-else
|
v-else
|
||||||
v-model:value="draft.specs[index].name"
|
v-model:value="draft.specs[index]!.name"
|
||||||
class="field-textarea"
|
class="field-textarea"
|
||||||
placeholder="规格名称"
|
placeholder="规格名称"
|
||||||
:auto-size="{ minRows: 1, maxRows: 3 }"
|
:auto-size="{ minRows: 1, maxRows: 3 }"
|
||||||
|
|||||||
Reference in New Issue
Block a user