From 43cf1a348650fc00b3e638396406814bf5f7ebfd Mon Sep 17 00:00:00 2001
From: zhaowei <zhaowei>
Date: 星期三, 15 一月 2025 17:55:02 +0800
Subject: [PATCH] 1、产品结构树页面新增工步功能 2、产品结构树页面新增导入文档或NC程序功能

---
 src/views/dnc/common/ImportFileModal.vue |  102 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 66 insertions(+), 36 deletions(-)

diff --git a/src/views/dnc/common/ImportFileModal.vue b/src/views/dnc/common/ImportFileModal.vue
index 13aee43..653ad41 100644
--- a/src/views/dnc/common/ImportFileModal.vue
+++ b/src/views/dnc/common/ImportFileModal.vue
@@ -1,7 +1,7 @@
 <template>
   <a-modal :title="title" :visible="visible" @cancel="handleModalClose" :maskClosable="false">
     <a-upload :multiple="true" :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload">
-      <a-button type="primary">
+      <a-button type="primary" :disabled="uploading">
         <a-icon type="import"/>
         閫夊彇鏂囦欢
       </a-button>
@@ -26,6 +26,8 @@
 </template>
 
 <script>
+  import dncApi from '@/api/dnc'
+
   export default {
     name: 'ImportFileModal',
     components: {},
@@ -34,6 +36,7 @@
         visible: false,
         title: '',
         fileList: [],
+        uploadParams: {},
         uploading: false
       }
     },
@@ -42,8 +45,26 @@
       this.$bus.$on('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
     },
     methods: {
-      handleImport(modalTitle) {
-        this.handleModalOpen(modalTitle)
+      /**
+       * 鐐瑰嚮瀵煎叆鏂囨。鎴朜C绋嬪簭鏃惰Е鍙�
+       * @param treeNodeInfo 鐐瑰嚮鏍戣妭鐐瑰彸閿彍鍗曞鍏ョ▼搴忔椂浼犲叆鏍戣妭鐐逛俊鎭�
+       * @param tableRowInfo 鐐瑰嚮琛ㄦ牸琛屽彸閿彍鍗曞鍏ョ▼搴忔椂浼犲叆琛屼俊鎭�
+       */
+      handleImport(treeNodeInfo, tableRowInfo) {
+        let attributionId // 鏂囨。鎵�灞炲眰绾d
+        let attributionType  // 鏂囨。鎵�灞炲眰绾х被鍨�
+        let docClassCode // 鏂囨。绫诲瀷
+        if (treeNodeInfo) {
+          attributionId = treeNodeInfo.treeKey
+          attributionType = treeNodeInfo.type
+        } else {
+          attributionId = tableRowInfo.attributionId
+          attributionType = tableRowInfo.attributionType
+        }
+        if (attributionType === 5 || attributionType === 6) docClassCode = 'NC'
+        else docClassCode = 'OTHER'
+        this.uploadParams = Object.assign({}, { attributionId, attributionType, docClassCode })
+        this.visible = true
       },
 
       handleRemove(file) {
@@ -54,43 +75,48 @@
       },
 
       beforeUpload(file) {
-        this.fileList = [...this.fileList, file]
+        if (!this.fileList.find(item => item.name === file.name)) this.fileList = [...this.fileList, file]
         return false
       },
 
       handleUpload() {
-        const { fileList } = this
-        const formData = new FormData()
-        fileList.forEach(file => {
-          formData.append('files[]', file)
-        })
+        const { fileList, $notification } = this
         this.uploading = true
-
-        // You can use any AJAX library you like
-        request({
-          url: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
-          method: 'post',
-          processData: false,
-          data: formData,
-          success: () => {
-            this.fileList = []
-            this.uploading = false
-            this.$message.success('upload successfully.')
-          },
-          error: () => {
-            this.uploading = false
-            this.$message.error('upload failed.')
-          }
+        let uploadedFileCount = 0
+        let uploadSuccessFileCount = 0
+        fileList.forEach((file, index) => {
+          const formData = new FormData()
+          formData.append('file', file)
+          file.status = 'uploading'
+          dncApi.importDocumentFromLocalApi(this.uploadParams, formData)
+            .then(res => {
+              if (res.success) {
+                file.status = 'done'
+                uploadSuccessFileCount++
+                $notification.success({
+                  message: '娑堟伅',
+                  description: res.message
+                })
+              } else {
+                file.status = 'error'
+                $notification.error({
+                  message: '娑堟伅',
+                  description: res.message
+                })
+              }
+            })
+            .catch(err => {
+              file.status = 'error'
+            })
+            .finally(() => {
+              uploadedFileCount++
+              fileList.splice(index, 1, file)
+              if (uploadedFileCount === fileList.length) {
+                if (uploadSuccessFileCount > 0) this.$bus.$emit('importFileSuccess', this.uploadParams)
+                this.uploading = false
+              }
+            })
         })
-      },
-
-      /**
-       * 鎺у埗鏂囦欢涓婁紶绐楀彛寮�鍚苟璁剧疆绐楀彛鏍囬
-       * @param modalTitle 绐楀彛鏍囬
-       */
-      handleModalOpen(modalTitle) {
-        this.title = modalTitle
-        this.visible = true
       },
 
       /**
@@ -101,8 +127,12 @@
         this.fileList = []
       },
 
-      triggerCorrespondingMethod({ methodName, modalTitle }) {
-        if (this[methodName]) this[methodName](modalTitle)
+      triggerCorrespondingMethod({ methodName, modalTitle, treeNodeInfo, tableRowInfo }) {
+        if (this[methodName]) {
+          this[methodName](treeNodeInfo, tableRowInfo)
+          this.title = modalTitle
+
+        }
       }
     }
   }

--
Gitblit v1.9.3