From 6c086fae275e7f3579654e374cadb85e7e054949 Mon Sep 17 00:00:00 2001
From: Surpriseplus <845948745@qq.com>
Date: 星期二, 07 二月 2023 19:16:54 +0800
Subject: [PATCH] 目录管理添加批量添加

---
 src/views/datamanage/catalogueManage.vue |  252 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 208 insertions(+), 44 deletions(-)

diff --git a/src/views/datamanage/catalogueManage.vue b/src/views/datamanage/catalogueManage.vue
index 1a79c33..8804a46 100644
--- a/src/views/datamanage/catalogueManage.vue
+++ b/src/views/datamanage/catalogueManage.vue
@@ -30,46 +30,84 @@
           }}</el-breadcrumb-item>
           </el-breadcrumb>
           <div>
-            <el-button
-              v-if="menuStatus.update"
-              :disabled="itemdetail.pid == null ? true : false"
-              @click="setEditNode(1)"
-              type="info"
-              icon="el-icon-top"
-              size="small"
-            >鍚戜笂绉诲姩</el-button>
-            <el-button
-              v-if="menuStatus.update"
-              :disabled="itemdetail.pid == null ? true : false"
-              @click="setEditNode(2)"
-              type="info"
-              icon="el-icon-bottom"
-              size="small"
-            >鍚戜笅绉诲姩</el-button>
-            <el-button
-              v-if="menuStatus.insert"
-              :disabled="itemdetail.pid == null ? true : false"
-              @click="setNewNode(1)"
-              type="success"
-              icon="el-icon-plus"
-              size="small"
-            >鏂板鍚岀骇</el-button>
-            <el-button
-              v-if="menuStatus.insert"
-              :disabled="itemdetail.pid == null ? true : false"
-              @click="setNewNode(2)"
-              type="success"
-              icon="el-icon-plus"
-              size="small"
-            >鏂板瀛愮骇</el-button>
-            <el-button
-              v-if="menuStatus.delete"
-              @click="setDelNode()"
-              :disabled="itemdetail.pid == null ? true : false"
-              type="danger"
-              icon="el-icon-delete"
-              size="small"
-            >鍒犻櫎</el-button>
+
+            <div class="menuTop">
+              <el-form
+                :inline="true"
+                class="demo-form-inline"
+              >
+                <el-form-item>
+
+                  <el-upload
+                    action
+                    accept=".xlsx, .xls"
+                    :auto-upload="false"
+                    :show-file-list="false"
+                    :on-change="handleChange"
+                    :file-list="fileList"
+                  >
+                    <el-button
+                      type="info"
+                      icon="el-icon-plus"
+                      size="small"
+                    >涓婁紶鏂囦欢</el-button>
+                  </el-upload>
+
+                </el-form-item>
+                <el-form-item>
+                  <el-button
+                    v-if="menuStatus.update"
+                    :disabled="itemdetail.pid == null ? true : false"
+                    @click="setEditNode(1)"
+                    type="info"
+                    icon="el-icon-top"
+                    size="small"
+                  >鍚戜笂绉诲姩</el-button>
+                </el-form-item>
+                <el-form-item>
+                  <el-button
+                    v-if="menuStatus.update"
+                    :disabled="itemdetail.pid == null ? true : false"
+                    @click="setEditNode(2)"
+                    type="info"
+                    icon="el-icon-bottom"
+                    size="small"
+                  >鍚戜笅绉诲姩</el-button>
+                </el-form-item>
+                <el-form-item>
+                  <el-button
+                    v-if="menuStatus.insert"
+                    :disabled="itemdetail.pid == null ? true : false"
+                    @click="setNewNode(1)"
+                    type="success"
+                    icon="el-icon-plus"
+                    size="small"
+                  >鏂板鍚岀骇</el-button>
+                </el-form-item>
+                <el-form-item>
+                  <el-button
+                    v-if="menuStatus.insert"
+                    :disabled="itemdetail.pid == null ? true : false"
+                    @click="setNewNode(2)"
+                    type="success"
+                    icon="el-icon-plus"
+                    size="small"
+                  >鏂板瀛愮骇</el-button>
+                </el-form-item>
+                <el-form-item>
+                  <el-button
+                    v-if="menuStatus.delete"
+                    @click="setDelNode()"
+                    :disabled="itemdetail.pid == null ? true : false"
+                    type="danger"
+                    icon="el-icon-delete"
+                    size="small"
+                  >鍒犻櫎</el-button>
+                </el-form-item>
+
+              </el-form>
+            </div>
+
           </div>
         </div>
         <el-divider />
@@ -207,7 +245,9 @@
   deleteDir,
   getPerms,
 } from '../../api/api';
+import * as XSLX from 'xlsx';
 import MyBread from '../../components/MyBread.vue';
+import clone from '@turf/clone';
 export default {
   name: 'catalogueManage',
   components: {
@@ -256,9 +296,129 @@
       },
       newNode: null,
       expandData: [],
+      fileList: [],
+      file: null,
+      tableData: [],
     };
   },
   methods: {
+    handleChange(file, fileList) {
+      this.file = file;
+      if (fileList.length > 0) {
+        this.fileList = [fileList[fileList.length - 1]]; //杩欎竴姝ワ紝鏄� 灞曠ず鏈�鍚庝竴娆¢�夋嫨鏂囦欢;
+        this.handle();
+      }
+    },
+    async handle() {
+      let file = this.file?.raw;
+      if (!this.file) {
+        console.log("鏂囦欢鎵撳紑澶辫触");
+        return;
+      } else {
+        const reader = new FileReader();
+        let that = this;
+        reader.readAsArrayBuffer(file);
+        reader.onload = function () {
+          const buffer = reader.result;
+          const bytes = new Uint8Array(buffer);
+          const length = bytes.byteLength;
+          let binary = "";
+          for (let i = 0; i < length; i++) {
+            binary += String.fromCharCode(bytes[i]);
+          }
+          const XLSX = require("xlsx");
+          const wb = XLSX.read(binary, {
+            type: "binary"
+          });
+          const outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]], { defval: null }); // 榛樿绗竴琛屼笅涓虹┖涔熻兘瑙f瀽鍑虹涓�鍥涜
+          var data = [...outdata];
+          const arr = [];
+          data.map(v => {
+            const obj = {};
+            obj.name = v.name;
+            obj.pname = v.pname;
+            obj.descr = v.explain;
+            obj.bak = v.bak;
+            obj.orderNum = null;
+            obj.pid = null;
+            arr.push(obj);
+          });
+          that.tableData = arr
+          that.setInsertData(that.tableData)
+        }
+      }
+    },
+    setInsertData(res) {
+      var list = this.excelData(res);
+
+      if (list.length != 0) {
+        if (list[0].pname != null) {
+          return this.$message.error('涓婁紶鏁版嵁閿欒锛岀涓�鏉℃暟鎹笉涓虹┖');
+        }
+
+        this.getAllNodeId(list)
+      }
+    },
+    async getAllNodeId(res) {
+      for (let i = 0; i < res.length; i++) {
+
+        var val = res[i];
+
+        if (val.pname == null) {
+          val.orderNum = this.dirList[this.dirList.length - 1].orderNum + 1;
+          val.pid = 0;
+        } else {
+          this.tableData.filter((child) => {
+            if (child.name == val.pname) {
+
+              val.pid = child.id;
+              val.orderNum = i + 1;
+            }
+          })
+        }
+
+        const data = await insertDir(val);
+        if (data.code != 200) {
+
+        }
+        this.tableData.filter((child) => {
+          if (child.name == val.name && child.pname == val.pname) {
+            child.id = data.result;
+          }
+        })
+        this.itemaName = data.result;
+        this.getDirTree();
+
+
+
+        if (res[i].children) {
+          this.getAllNodeId(res[i].children)
+        }
+      }
+    },
+    excelData(source) {
+      let cloneData = JSON.parse(JSON.stringify(source)); // 瀵规簮鏁版嵁娣卞害鍏嬮殕
+      return cloneData.filter((father) => {
+        // 寰幆鎵�鏈夐」
+        let branchArr = cloneData.filter((child) => father.name == child.pname); // 瀵规瘮ID锛屽垎鍒笂涓嬬骇鑿滃崟锛屽苟杩斿洖鏁版嵁
+
+        branchArr.length > 0 ? (father.children = branchArr) : ''; // 缁欑埗绾ф坊鍔犱竴涓猚hildren灞炴�э紝骞惰祴鍊�
+        // 灞炰簬鍚屼竴瀵硅薄闂锛屼緥濡傦細浠� a=b銆乧=1 锛岀劧鍚庡啀浠� b.c=c 锛� 閭d箞 a.c=b.c=c=1 锛涘悓鐞嗭紝鍚庣画浠� c.d=2 ,閭d箞 a.c.d 涔熸槸=2锛�
+        // 鐢辨寰幆澶氭鍚庯紝灏辫兘褰㈡垚鐩稿簲鐨勬爲褰㈡暟鎹粨鏋�
+        return father.pname == null; // 杩斿洖涓�绾ц彍鍗�
+      });
+    },
+    readFile(file) {
+      //鏂囦欢璇诲彇
+      return new Promise(resolve => {
+        let reader = new FileReader();
+        reader.readAsBinaryString(file); //浠ヤ簩杩涘埗鐨勬柟寮忚鍙�
+        reader.onload = ev => {
+          resolve(ev.target.result);
+        };
+      });
+    },
+
     // 璇锋眰鐩綍鏍�
     getDirTree() {
       //鑾峰彇鐩綍鏍戞渶澶D锛屾柊寤鸿妭鐐逛娇鐢�
@@ -461,8 +621,8 @@
       });
     },
     remove(node, data) {
-      this.itemaName =node.parent.data.id;
- 
+      this.itemaName = node.parent.data.id;
+
       this.$confirm('姝ゆ搷浣滃皢鍒犻櫎璇ヨ妭鐐�, 鏄惁缁х画?', '鎻愮ず', {
         confirmButtonText: '纭畾',
         cancelButtonText: '鍙栨秷',
@@ -505,7 +665,6 @@
               this.$message.error('鍒犻櫎澶辫触');
               this.itemdetail = {};
             });
-
           //閲嶇疆瑕佸垹闄ょ殑瀛怚D
           this.delChildIDs = [];
         })
@@ -673,7 +832,7 @@
       }
       for (var i = 0; i < permsEntity.length; i++) {
         if (val === permsEntity[i].perms) {
-          console.log(i, permsEntity[i])
+
           this.showPermsMenu(permsEntity[i]);
         }
       }
@@ -708,6 +867,11 @@
       height: 91%;
       border-radius: 5px;
       padding: 1%;
+      .menuTop {
+        /deep/ .el-form-item {
+          margin-bottom: 0px;
+        }
+      }
     }
   }
 }

--
Gitblit v1.9.3