From 2b72d8220cf274e9b6586c7d4d9fae612fec3a14 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 03 四月 2026 11:24:51 +0800
Subject: [PATCH] 军泰伟业 1.部署修改

---
 src/views/basicData/product/index.vue |   91 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 85 insertions(+), 6 deletions(-)

diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index b887d9d..b2e169a 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -172,6 +172,7 @@
         :limit="1"
         accept=".xlsx,.xls"
         :action="importUpload.url"
+        :http-request="importUpload.httpRequest"
         :headers="importUpload.headers"
         :before-upload="importUpload.beforeUpload"
         :on-success="importUpload.onSuccess"
@@ -198,6 +199,7 @@
 
 <script setup>
 import { ref, reactive, onMounted } from "vue";
+import axios from "axios";
 import { ElMessageBox } from "element-plus";
 import { Plus } from "@element-plus/icons-vue";
 import { getToken } from "@/utils/auth.js";
@@ -264,6 +266,11 @@
     minWidth: 100,
   },
   {
+    label: "瀛愰」鏁伴噺",
+    prop: "subItemCount",
+    minWidth: 100,
+  },
+  {
     label: "浜у搧灞炴��",
     prop: "productType",
     width: 100,
@@ -274,6 +281,16 @@
       return typeMap[String(v)] || "info";
     },
   },
+	{
+		label: "鍒涘缓鏃堕棿",
+		prop: "createTime",
+		width: 120,
+	},
+	{
+		label: "淇敼鏃堕棿",
+		prop: "updateTime",
+		width: 120,
+	},
   {
     dataType: "action",
     label: "鎿嶄綔",
@@ -314,12 +331,79 @@
 });
 const { modelForm, modelRules } = toRefs(data);
 
+const downloadImportErrorFile = (blob, filename = "import-error.xlsx") => {
+  const downloadElement = document.createElement("a");
+  const href = window.URL.createObjectURL(blob);
+  downloadElement.href = href;
+  downloadElement.download = filename;
+  document.body.appendChild(downloadElement);
+  downloadElement.click();
+  document.body.removeChild(downloadElement);
+  window.URL.revokeObjectURL(href);
+};
+
+const tryParseJsonBlob = async (blob) => {
+  try {
+    const text = await blob.text();
+    if (!text || !text.trim()) {
+      return null;
+    }
+    return JSON.parse(text);
+  } catch (_) {
+    return null;
+  }
+};
+
 const importUpload = reactive({
   title: "浜у搧瀵煎叆",
   open: false,
   url: import.meta.env.VITE_APP_BASE_API + "/basic/product/import",
   headers: { Authorization: "Bearer " + getToken() },
   isUploading: false,
+  httpRequest: async (options) => {
+    const { file, onProgress, onSuccess, onError } = options;
+    importUpload.isUploading = true;
+    const formData = new FormData();
+    formData.append("file", file);
+    try {
+      const response = await axios({
+        url: importUpload.url,
+        method: "post",
+        headers: {
+          ...importUpload.headers,
+          "Content-Type": "multipart/form-data",
+        },
+        data: formData,
+        responseType: "blob",
+        onUploadProgress: (progressEvent) => {
+          const total = progressEvent.total || 1;
+          const percent = Math.round((progressEvent.loaded * 100) / total);
+          onProgress?.({ percent }, file);
+        },
+      });
+      importUpload.isUploading = false;
+      const blob = response.data;
+      // Contract: success => empty response body; failure => binary error file.
+      if (!blob || blob.size === 0) {
+        onSuccess?.({ code: 200, msg: "import success" }, file);
+        return;
+      }
+      const json = await tryParseJsonBlob(blob);
+      if (json) {
+        if (String(json.code) === "200" || json.success === true) {
+          onSuccess?.(json, file);
+        } else {
+          onError?.(new Error(json.msg || json.message || "import failed"), file);
+        }
+        return;
+      }
+      downloadImportErrorFile(blob);
+      onError?.(new Error("import failed, error file downloaded"), file);
+    } catch (error) {
+      importUpload.isUploading = false;
+      onError?.(error, file);
+    }
+  },
   beforeUpload: (file) => {
     const isExcel = file.name.endsWith('.xlsx') || file.name.endsWith('.xls');
     const isLt10M = file.size / 1024 / 1024 < 10;
@@ -342,7 +426,7 @@
   onSuccess: (response, file, fileList) => {
     console.log('涓婁紶鎴愬姛', response, file, fileList);
     importUpload.isUploading = false;
-    if (response.code === 200) {
+    if (String(response?.code) === "200" || response?.success === true) {
       proxy.$modal.msgSuccess("瀵煎叆鎴愬姛");
       importDia.value = false;
       if (importUploadRef.value) {
@@ -621,11 +705,6 @@
 }
 
 :deep(.el-upload--picture-card) {
-  width: 148px;
-  height: 148px;
-}
-
-:deep(.el-upload-list__item) {
   width: 148px;
   height: 148px;
 }

--
Gitblit v1.9.3