From 0c116b0f5624786bd06990b86c467be25e2411fd Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 26 一月 2026 17:51:38 +0800
Subject: [PATCH] feat: BOM导入模板下载,导入导出接口添加菜单权限

---
 src/views/productionManagement/productStructure/index.vue |   65 ++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/src/views/productionManagement/productStructure/index.vue b/src/views/productionManagement/productStructure/index.vue
index ce88565..1ae3f77 100644
--- a/src/views/productionManagement/productStructure/index.vue
+++ b/src/views/productionManagement/productStructure/index.vue
@@ -1,9 +1,10 @@
 <template>
   <div class="app-container">
     <div style="text-align: right; margin-bottom: 10px;">
-      <el-button type="info" plain icon="Upload" @click="handleImport">瀵煎叆</el-button>
-      <el-button type="warning" plain icon="Download" @click="handleExport"
-        :disabled="selectedRows.length !== 1">瀵煎嚭</el-button>
+      <el-button type="info" plain icon="Upload" @click="handleImport"
+        v-hasPermi="['product:bom:import']">瀵煎叆</el-button>
+      <el-button type="warning" plain icon="Download" @click="handleExport" :disabled="selectedRows.length !== 1"
+        v-hasPermi="['product:bom:export']">瀵煎嚭</el-button>
       <el-button type="primary" @click="handleAdd">鏂板</el-button>
       <el-button type="danger" plain @click="handleBatchDelete" :disabled="selectedRows.length === 0">鍒犻櫎</el-button>
     </div>
@@ -42,35 +43,21 @@
     <ProductSelectDialog v-model="showProductSelectDialog" @confirm="handleProductSelect" single />
 
     <!-- BOM瀵煎叆瀵硅瘽妗� -->
-    <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
-      <el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
-        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
-        :auto-upload="false" drag>
-        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
-        <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
-        <template #tip>
-          <div class="el-upload__tip text-center">
-            <span>浠呭厑璁稿鍏ls銆亁lsx鏍煎紡鏂囦欢銆�</span>
-          </div>
-        </template>
-      </el-upload>
-      <template #footer>
-        <div class="dialog-footer">
-          <el-button type="primary" @click="submitFileForm">纭� 瀹�</el-button>
-          <el-button @click="upload.open = false">鍙� 娑�</el-button>
-        </div>
-      </template>
-    </el-dialog>
+    <ImportDialog ref="uploadRef" v-model="upload.open" :title="upload.title" :action="upload.url"
+      :headers="upload.headers" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress"
+      :on-success="handleFileSuccess" :show-download-template="true" @confirm="submitFileForm"
+      @download-template="handleDownloadTemplate" @close="handleImportClose" />
   </div>
 </template>
 
 <script setup>
 import { ref, reactive, toRefs, onMounted, getCurrentInstance, defineAsyncComponent } from "vue";
 import { getToken } from "@/utils/auth";
-import { listPage, add, update, batchDelete, exportBom } from "@/api/productionManagement/productBom.js";
+import { listPage, add, update, batchDelete, exportBom, downloadTemplate } from "@/api/productionManagement/productBom.js";
 import { useRouter } from 'vue-router'
 import { ElMessageBox } from 'element-plus'
 import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue";
+import ImportDialog from "@/components/Dialog/ImportDialog.vue";
 
 const router = useRouter()
 const { proxy } = getCurrentInstance()
@@ -336,6 +323,11 @@
   upload.open = true;
 };
 
+// 鍏抽棴瀵煎叆瀵硅瘽妗嗘椂娓呴櫎鏂囦欢
+const handleImportClose = () => {
+  proxy.$refs["uploadRef"].clearFiles();
+};
+
 //  鏂囦欢涓婁紶涓鐞�
 const handleFileUploadProgress = (event, file, fileList) => {
   upload.isUploading = true;
@@ -345,7 +337,7 @@
 const handleFileSuccess = (response, file, fileList) => {
   upload.open = false;
   upload.isUploading = false;
-  proxy.$refs["uploadRef"].handleRemove(file);
+  proxy.$refs["uploadRef"].clearFiles();
   if (response.code === 200) {
     proxy.$modal.msgSuccess(response.msg || "瀵煎叆鎴愬姛");
     getList();
@@ -397,6 +389,31 @@
   });
 };
 
+//  涓嬭浇妯℃澘
+const handleDownloadTemplate = async () => {
+  const res = await downloadTemplate();
+  // 杩斿洖鐨勬暟鎹槸鍚︿负绌�
+  if (!res) {
+    proxy.$modal.msgError("涓嬭浇澶辫触锛岃繑鍥炴暟鎹负绌�");
+    return;
+  }
+
+  const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
+  const downloadElement = document.createElement('a');
+  const href = window.URL.createObjectURL(blob);
+
+  downloadElement.href = href;
+  downloadElement.download = "BOM妯℃澘.xlsx";
+
+  document.body.appendChild(downloadElement);
+  downloadElement.click();
+
+  document.body.removeChild(downloadElement);
+  window.URL.revokeObjectURL(href);
+
+  proxy.$modal.msgSuccess("涓嬭浇鎴愬姛");
+};
+
 // 鏌ョ湅璇︽儏
 const showDetail = (row) => {
   router.push({

--
Gitblit v1.9.3