From 1d09c293ef8d8dd1fcb29c26e4936518328d5f0b Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 10 二月 2026 15:34:36 +0800
Subject: [PATCH] fix: 产品规格型号导入接口错误,添加下载模版
---
src/views/basicData/product/ImportExcel/index.vue | 72 ++++++++++++++++++++++++++++++------
1 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/src/views/basicData/product/ImportExcel/index.vue b/src/views/basicData/product/ImportExcel/index.vue
index f1d6213..22df1f7 100644
--- a/src/views/basicData/product/ImportExcel/index.vue
+++ b/src/views/basicData/product/ImportExcel/index.vue
@@ -2,15 +2,10 @@
<el-button type="info" plain icon="Upload" @click="handleImport">
瀵煎叆
</el-button>
- <el-dialog v-model="upload.open" :title="upload.title">
- <FileUpload
- ref="fileUploadRef"
- accept=".xlsx, .xls"
- :headers="upload.headers"
- :action="upload.url + '?updateSupport=' + upload.updateSupport"
- :disabled="upload.isUploading"
- @success="handleFileSuccess"
- />
+ <el-dialog v-model="upload.open" :title="upload.title" @close="handleDialogClose">
+ <FileUpload ref="fileUploadRef" accept=".xlsx, .xls" :headers="upload.headers" :action="uploadUrl"
+ :disabled="upload.isUploading" :showTip="true" @success="handleFileSuccess"
+ :downloadTemplate="handleDownloadTemplate" />
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitFileForm">纭� 瀹�</el-button>
@@ -21,15 +16,19 @@
</template>
<script setup>
-import { reactive } from "vue";
+import { reactive, computed } from "vue";
import { getToken } from "@/utils/auth.js";
import { FileUpload } from "@/components/Upload";
import { ElMessage } from "element-plus";
+import { downloadProductModelImportTemplate } from "@/api/basicData/product.js";
defineOptions({
name: "浜у搧缁存姢瀵煎叆",
});
+const props = defineProps({
+ productId: { type: [String, Number], default: "" },
+});
const emits = defineEmits(["uploadSuccess"]);
const fileUploadRef = ref();
const upload = reactive({
@@ -41,17 +40,31 @@
isUploading: false,
// 璁剧疆涓婁紶鐨勮姹傚ご閮�
headers: { Authorization: "Bearer " + getToken() },
- // 涓婁紶鐨勫湴鍧�
- url: import.meta.env.VITE_APP_BASE_API + "/system/supplier/import",
});
+// 涓婁紶鐨勫湴鍧�锛堟惡甯� productId 鍙傛暟锛屼紶缁欏悗绔殑 importProduct 鎺ュ彛锛�
+const uploadUrl = computed(
+ () =>
+ import.meta.env.VITE_APP_BASE_API +
+ "/basic/product/import" +
+ (props.productId ? `?productId=${props.productId}` : "")
+);
// 鐐瑰嚮瀵煎叆
const handleImport = () => {
+ if (!props.productId) {
+ ElMessage({ message: "璇峰厛閫夋嫨浜у搧", type: "warning" });
+ return;
+ }
upload.open = true;
upload.title = "浜у搧瀵煎叆";
};
const submitFileForm = () => {
fileUploadRef.value.uploadApi();
+};
+
+// 鍏抽棴寮圭獥鏃舵竻闄ゅ凡閫夋枃浠�
+const handleDialogClose = () => {
+ fileUploadRef.value?.clearFiles?.();
};
const handleFileSuccess = (response) => {
@@ -64,4 +77,39 @@
ElMessage({ message: msg, type: "error" });
}
};
+
+// 涓嬭浇 Excel 瀵煎叆妯℃澘
+const handleDownloadTemplate = () => {
+ downloadProductModelImportTemplate()
+ .then((blobData) => {
+ const blob =
+ blobData instanceof Blob
+ ? blobData
+ : new Blob([blobData], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
+ const url = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = "浜у搧瀵煎叆妯℃澘.xlsx";
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ window.URL.revokeObjectURL(url);
+ ElMessage({ message: "妯℃澘涓嬭浇鎴愬姛", type: "success" });
+ })
+ .catch(() => {
+ ElMessage({ message: "妯℃澘涓嬭浇澶辫触", type: "error" });
+ });
+};
</script>
+
+<style scoped>
+.import-tip {
+ margin-top: 12px;
+ font-size: 12px;
+ color: var(--el-text-color-secondary);
+}
+
+.import-tip .el-button {
+ margin-left: 8px;
+}
+</style>
--
Gitblit v1.9.3