diff --git a/src/api/canteen/canteenSpu.ts b/src/api/canteen/canteenSpu.ts index d7b27837..800e743e 100644 --- a/src/api/canteen/canteenSpu.ts +++ b/src/api/canteen/canteenSpu.ts @@ -55,7 +55,7 @@ export function putObj(obj?: Object) { }) } -/** Excel 导入菜品:cover=true 覆盖,false 仅新增 */ +/** Excel 导入菜品:importMode=cover|skip|force;兼容 cover=true/false */ export function importSpu(data: FormData, params: Object) { return request({ url: "/canteen/canteenSpu/import", diff --git a/src/views/canteen/canteenSpu/index.vue b/src/views/canteen/canteenSpu/index.vue index b85976b8..42b63cfa 100644 --- a/src/views/canteen/canteenSpu/index.vue +++ b/src/views/canteen/canteenSpu/index.vue @@ -130,9 +130,9 @@ - + + title="覆盖:同名更新;新增:同名跳过;不覆盖:同名套餐/单品也新增(分类仍按名称复用)。同一菜品若既有单品行又在套餐里,覆盖时以单品行单价为准。" /> @@ -142,9 +142,10 @@ Excel 分类名匹配不到时使用 - - 覆盖导入(同名更新价格/库存等) - 新增导入(同名跳过) + + 覆盖导入(同名更新价格/库存等) + 新增导入(同名跳过) + 不覆盖导入(同名也新增,分类除外) @@ -252,14 +253,15 @@ const importVisible = ref(false) const importLoading = ref(false) const importMerchantId = ref() const importCategoryId = ref() -const importCover = ref(true) +/** cover=覆盖 | skip=同名跳过 | force=同名也新增 */ +const importMode = ref<"cover" | "skip" | "force">("cover") const importFile = ref(null) const importUploadRef = ref() const openImport = () => { importMerchantId.value = state.queryForm?.merchantId || undefined importCategoryId.value = undefined - importCover.value = true + importMode.value = "cover" importFile.value = null importVisible.value = true } @@ -277,23 +279,23 @@ const submitImport = async () => { useMessage().warning("请选择 Excel 文件") return } - const cover = importCover.value === true + const mode = importMode.value || "skip" const fd = new FormData() fd.append("file", importFile.value) fd.append("merchantId", String(importMerchantId.value)) if (importCategoryId.value != null && importCategoryId.value !== "") { fd.append("categoryId", String(importCategoryId.value)) } - fd.append("cover", cover ? "true" : "false") + fd.append("importMode", mode) importLoading.value = true try { const res: any = await importSpu(fd, { merchantId: importMerchantId.value, categoryId: importCategoryId.value || undefined, - cover: cover ? "true" : "false", + importMode: mode, }) const tip = res.msg || "导入成功" - if (!cover && String(tip).includes("跳过")) { + if (mode === "skip" && String(tip).includes("跳过")) { useMessage().warning(tip) } else { useMessage().success(tip) @@ -332,3 +334,12 @@ const handleDelete = async (ids: string[]) => { } } + +