管道基础大数据平台系统开发-【前端】-新系統界面
src/views/datamanage/catalogueManage.vue
@@ -46,6 +46,25 @@
                class="demo-form-inline"
              >
                <el-form-item>
                  <el-button
                    v-show="directoryFlag"
                    icon="el-icon-download"
                    type="info"
                    size="small"
                    @click="setDirectoryDownload"
                  >{{ $t("shuJuGuanLi.butten.directoryDownload") }}</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button
                    icon="el-icon-download"
                    type="info"
                    size="small"
                    @click="setTemplateDownload"
                  >{{ $t("shuJuGuanLi.butten.templateDownload") }}</el-button>
                </el-form-item>
                <el-form-item>
                  <el-upload
                    action
                    accept=".xlsx, .xls"
@@ -348,6 +367,11 @@
        >{{ $t("common.preservation") }}</el-button>
      </div>
    </el-dialog>
    <iframe
      id="Iframe1"
      src=""
      style="display: none; border: 0; padding: 0; height: 0; width: 0"
    ></iframe>
  </div>
</template>
@@ -364,6 +388,8 @@
import * as XSLX from "xlsx";
import MyBread from "../../components/MyBread.vue";
import clone from "@turf/clone";
import $ from 'jquery'
import { getToken } from '../../utils/auth';
export default {
  name: "catalogueManage",
  components: {
@@ -378,6 +404,8 @@
      }
    };
    return {
      directoryData: null,
      directoryFlag: false,
      menuStatus: {
        delete: false,
        insert: false,
@@ -418,6 +446,15 @@
    };
  },
  methods: {
    setTemplateDownload() {
      var url = window.location.href;
      var testurl = window.location.origin + "/";
      if (url.indexOf("web") != -1) {
        testurl = testurl + "/web/";
      }
      testurl += dirTemplateFile
      $("#Iframe1").attr("src", testurl).click()
    },
    handleChange(file, fileList) {
      this.file = file;
      if (fileList.length > 0) {
@@ -451,25 +488,59 @@
            { defval: null }
          ); // 默认第一行下为空也能解析出第一四行
          var data = [...outdata];
          const arr = [];
          data.map((v) => {
            const obj = {};
            obj.name = v.name;
            obj.pname = v.pname;
            obj.descr = v.explain;
            obj.checks = v.checks;
            obj.bak = v.bak;
            obj.exts = v.exts;
            obj.orderNum = null;
            obj.pid = null;
            arr.push(obj);
          });
          that.tableData = arr;
          that.setInsertData(that.tableData);
          that.setLeToFc(data);
        };
      }
    },
    setLeToFc(res) {
      var arr = [];
      for (var i in res) {
        var value = this.getNameAndPname(res[i], res, i)
        arr.push({
          name: value[0],
          pname: value[1],
          descr: res[i].explain,
          checks: res[i].checks,
          bak: res[i].bak,
          exts: res[i].exts,
          orderNum: null,
          pid: null,
          tid: parseInt(value[2]) + 1,
          sid: parseInt(value[3]) + 1
        })
      }
      this.tableData = arr;
      this.setInsertData(this.tableData);
    },
    getNameAndPname(res, result, flag) {
      var chLevel = null;
      var faLevel = null;
      for (var i = 1; i < 8; i++) {
        var lel = 'L' + i;
        if (res[lel] != null) {
          chLevel = i
        }
      }
      if (chLevel == 1) {
        return [res['L' + chLevel], null, flag, -1]
      } else {
        faLevel = chLevel - 1;
        for (var i = flag; i >= 0; i--) {
          var val = result[i]
          if (val['L' + faLevel]) {
            return [res['L' + chLevel], val['L' + faLevel], flag, i]
            break;
          }
        }
      }
    },
    setInsertData(res) {
      var list = this.excelData(res);
      if (list.length != 0) {
@@ -477,7 +548,7 @@
          return this.$message.error("上传数据错误,第一条数据不为空");
        }
        this.getAllNodeId(list);
        this.getAllNodeId(res);
      }
    },
    async getAllNodeId(res) {
@@ -488,8 +559,9 @@
          val.orderNum = this.dirList[this.dirList.length - 1].orderNum + 1;
          val.pid = 0;
        } else {
          this.tableData.filter((child) => {
            if (child.name == val.pname) {
            if (child.tid == val.sid) {
              val.pid = child.id;
              val.orderNum = i + 1;
            }
@@ -499,29 +571,31 @@
        const data = await insertDir(val);
        if (data.code != 200) {
        }
        this.tableData.filter((child) => {
          if (child.name == val.name && child.pname == val.pname) {
          if (child.name == val.name && child.tid == val.tid) {
            child.id = data.result;
          }
        });
        this.itemaName = data.result;
        this.getDirTree();
        if (res[i].children) {
          this.getAllNodeId(res[i].children);
        }
        // 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,分别上下级菜单,并返回数据
        let branchArr = cloneData.filter((child) => father.tid == child.sid); // 对比ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ""; // 给父级添加一个children属性,并赋值
        // 属于同一对象问题,例如:令 a=b、c=1 ,然后再令 b.c=c , 那么 a.c=b.c=c=1 ;同理,后续令 c.d=2 ,那么 a.c.d 也是=2;
        // 由此循环多次后,就能形成相应的树形数据结构
        return father.pname == null; // 返回一级菜单
        return father.sid == 0; // 返回一级菜单
      });
    },
    readFile(file) {
@@ -566,7 +640,7 @@
      });
    },
    handleClose() {
      this.$confirm("确认关闭?")
      this.$confirm("关闭后无法保存,是否关闭?")
        .then((_) => {
          this.resetForm();
        })
@@ -890,9 +964,20 @@
          this.$message.error("修改失败,请重试!");
        });
    },
    setDirectoryDownload() {
      var url = BASE_URL + '/dir/downloadDir?token=' + getToken() + '&id=' + this.directoryData.id
      console.log(url)
      $("#Iframe1").attr("src", url).click()
    },
    handleNodeClick(data, node) {
      // console.log(data);
      if (data.pid == 0) {
        this.directoryData = data;
        this.directoryFlag = true;
      } else {
        this.directoryFlag = false;
      }
      this.newNode = node;
      this.backUpData = JSON.stringify(data);
      this.itemdetail = JSON.parse(JSON.stringify(data));