From 0d0505232d49c9d09f15f03cb66a4f9be6257fce Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 26 一月 2026 14:23:19 +0800
Subject: [PATCH] feat: BOM导入模板下载功能
---
src/api/productionManagement/productBom.js | 9 ++++
src/views/productionManagement/productStructure/index.vue | 58 ++++++++++++++++++----------
2 files changed, 46 insertions(+), 21 deletions(-)
diff --git a/src/api/productionManagement/productBom.js b/src/api/productionManagement/productBom.js
index 8132e9c..2badea8 100644
--- a/src/api/productionManagement/productBom.js
+++ b/src/api/productionManagement/productBom.js
@@ -55,3 +55,12 @@
responseType: "blob",
});
}
+
+// 涓嬭浇妯℃澘
+export function downloadTemplate() {
+ return request({
+ url: "/productBom/downloadTemplate",
+ method: "get",
+ responseType: "blob",
+ });
+}
\ No newline at end of file
diff --git a/src/views/productionManagement/productStructure/index.vue b/src/views/productionManagement/productStructure/index.vue
index ce88565..a7e90e0 100644
--- a/src/views/productionManagement/productStructure/index.vue
+++ b/src/views/productionManagement/productStructure/index.vue
@@ -42,35 +42,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 +322,11 @@
upload.open = true;
};
+// 鍏抽棴瀵煎叆瀵硅瘽妗嗘椂娓呴櫎鏂囦欢
+const handleImportClose = () => {
+ proxy.$refs["uploadRef"].clearFiles();
+};
+
// 鏂囦欢涓婁紶涓鐞�
const handleFileUploadProgress = (event, file, fileList) => {
upload.isUploading = true;
@@ -345,7 +336,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 +388,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