管道基础大数据平台系统开发-【前端】-新系統界面
王旭
2023-02-20 fda6fcfc6598c4349d486ca71d57c74e33043d76
src/views/datamanage/catalogueManage.vue
@@ -1,13 +1,15 @@
<template>
  <div class="subpage_Box">
    <My-bread :list="[
        `${$t('dataManage.dataManage')}`,
        `${$t('dataManage.catalogueManage')}`,
      ]"></My-bread>
    <el-divider />
    <div class="cataLogContent">
      <div class="cataLog_leftTree subpage_Div">
        <div style="min-width:450px">
        <My-bread
          :list="[
            `${$t('dataManage.dataManage')}`,
            `${$t('dataManage.catalogueManage')}`,
          ]"
        ></My-bread>
        <el-divider />
        <div style="min-width: 450px">
          <el-tree
            ref="tree"
            :props="defaultProps"
@@ -18,26 +20,26 @@
            :default-expanded-keys="expandData"
            @node-click="handleNodeClick"
          >
          </el-tree>
        </div>
      </div>
      <div class="cataLog_rightContent subpage_Div">
        <div style="align-items: center;display:flex;justify-content:space-between">
        <div
          style="
            align-items: center;
            display: flex;
            justify-content: space-between;
          "
        >
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">{{
            $t('dataManage.dictionaryManageObj.particulars')
          }}</el-breadcrumb-item>
              $t("dataManage.dictionaryManageObj.particulars")
            }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div style="margin-right: -5px;">
          <div style="margin-right: -5px">
            <div class="menuTop">
              <el-form
                :inline="true"
                class="demo-form-inline"
              >
              <el-form :inline="true" class="demo-form-inline">
                <el-form-item>
                  <el-upload
                    action
                    accept=".xlsx, .xls"
@@ -46,13 +48,10 @@
                    :on-change="handleChange"
                    :file-list="fileList"
                  >
                    <el-button
                    type="success"
                      icon="el-icon-plus"
                      size="small"
                    >上传文件</el-button>
                    <el-button type="success" icon="el-icon-plus" size="small"
                      >上传文件</el-button
                    >
                  </el-upload>
                </el-form-item>
                <el-form-item>
                  <el-button
@@ -62,7 +61,8 @@
                    type="success"
                    icon="el-icon-plus"
                    size="small"
                  >新增同级</el-button>
                    >新增同级</el-button
                  >
                </el-form-item>
                <el-form-item>
                  <el-button
@@ -72,7 +72,8 @@
                    type="success"
                    icon="el-icon-plus"
                    size="small"
                  >新增子级</el-button>
                    >新增子级</el-button
                  >
                </el-form-item>
                <el-form-item>
                  <el-button
@@ -82,7 +83,8 @@
                    type="danger"
                    icon="el-icon-delete"
                    size="small"
                  >删除</el-button>
                    >删除</el-button
                  >
                </el-form-item>
                <el-form-item>
                  <el-button
@@ -92,7 +94,8 @@
                    type="info"
                    icon="el-icon-top"
                    size="small"
                  >向上移动</el-button>
                    >向上移动</el-button
                  >
                </el-form-item>
                <el-form-item>
                  <el-button
@@ -102,26 +105,21 @@
                    type="info"
                    icon="el-icon-bottom"
                    size="small"
                  >向下移动</el-button>
                    >向下移动</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
        <el-divider />
        <el-form
          :model="itemdetail"
          ref="itemdetail"
          :rules="rules"
        >
        <el-form :model="itemdetail" ref="itemdetail" :rules="rules">
          <el-form-item
            prop="name"
            :label="$t('dataManage.dataUpObj.directoryName')"
            :label-width="formLabelWidth"
          >
            <el-input v-model="itemdetail.name" style="max-width: 400px;"/>
            <el-input v-model="itemdetail.name" style="max-width: 400px" />
          </el-form-item>
          <el-form-item
            :label="$t('dataManage.dataUpObj.catalogDescription')"
@@ -131,7 +129,7 @@
              v-model="itemdetail.descr"
              type="textarea"
              resize="none"
              style="height: 100%; overflow: auto;max-width: 400px;"
              style="height: 100%; overflow: auto; max-width: 400px"
            />
          </el-form-item>
          <el-form-item
@@ -142,7 +140,7 @@
              v-model="itemdetail.bak"
              type="textarea"
              resize="none"
              style="max-width: 400px;"
              style="max-width: 400px"
            />
          </el-form-item>
          <div class="btnBox">
@@ -151,17 +149,15 @@
              class="primary"
              size="small"
              @click="updCata('itemdetail')"
            >{{
              $t('common.preservation')
            }}</el-button>
              >{{ $t("common.preservation") }}</el-button
            >
            <el-button
              v-if="menuStatus.update"
              type="info"
              size="small"
              @click="reset"
            >{{
              $t('common.cancel')
            }}</el-button>
              >{{ $t("common.cancel") }}</el-button
            >
          </div>
        </el-form>
      </div>
@@ -185,52 +181,37 @@
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        :rules="rules"
      >
      <el-form :model="ruleForm" ref="ruleForm" :rules="rules">
        <el-form-item
          :label="$t('dataManage.dataUpObj.directoryName')"
          prop="name"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="ruleForm.name"
            autocomplete="off"
          ></el-input>
          <el-input v-model="ruleForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          :label="$t('dataManage.dataUpObj.catalogDescription')"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="ruleForm.descr"
            autocomplete="off"
          ></el-input>
          <el-input v-model="ruleForm.descr" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          :label="$t('dataManage.dataUpObj.catalogRemarks')"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="ruleForm.bak"
            autocomplete="off"
          ></el-input>
          <el-input v-model="ruleForm.bak" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('ruleForm')">{{
          $t('common.cancel')
          $t("common.cancel")
        }}</el-button>
        <el-button
          class="primary"
          @click="submitForm('ruleForm')"
          v-loading.fullscreen.lock="fullscreenLoading"
        >{{ $t('common.preservation') }}</el-button>
          >{{ $t("common.preservation") }}</el-button
        >
      </div>
    </el-dialog>
  </div>
@@ -245,19 +226,19 @@
  insertDir,
  deleteDir,
  getPerms,
} from '../../api/api';
import * as XSLX from 'xlsx';
import MyBread from '../../components/MyBread.vue';
import clone from '@turf/clone';
} from "../../api/api";
import * as XSLX from "xlsx";
import MyBread from "../../components/MyBread.vue";
import clone from "@turf/clone";
export default {
  name: 'catalogueManage',
  name: "catalogueManage",
  components: {
    MyBread,
  },
  data() {
    let validName = (rule, value, callback) => {
      if (value === '' || value === null || value === undefined) {
        return callback(new Error('目录名称不能为空'));
      if (value === "" || value === null || value === undefined) {
        return callback(new Error("目录名称不能为空"));
      } else {
        callback();
      }
@@ -269,8 +250,8 @@
        update: false,
      },
      defaultProps: {
        children: 'children',
        label: 'name',
        children: "children",
        label: "name",
      },
      fullscreenLoading: false,
      oriData: [], //原始树数据
@@ -279,21 +260,21 @@
      newData: [], //拖动后原始数据
      itemdetail: {},
      itemaName: null,
      backUpData: '',
      formLabelWidth: '150px',
      delChildID: '',
      backUpData: "",
      formLabelWidth: "150px",
      delChildID: "",
      delChildIDs: [],
      dialogFormVisible: false,
      ruleForm: {
        level: null,
        orderNum: null,
        pid: null,
        name: '',
        descr: '',
        bak: '',
        name: "",
        descr: "",
        bak: "",
      },
      rules: {
        name: [{ required: true, validator: validName, trigger: 'blur' }],
        name: [{ required: true, validator: validName, trigger: "blur" }],
      },
      newNode: null,
      expandData: [],
@@ -329,12 +310,15 @@
          }
          const XLSX = require("xlsx");
          const wb = XLSX.read(binary, {
            type: "binary"
            type: "binary",
          });
          const outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]], { defval: null }); // 默认第一行下为空也能解析出第一四行
          const outdata = XLSX.utils.sheet_to_json(
            wb.Sheets[wb.SheetNames[0]],
            { defval: null }
          ); // 默认第一行下为空也能解析出第一四行
          var data = [...outdata];
          const arr = [];
          data.map(v => {
          data.map((v) => {
            const obj = {};
            obj.name = v.name;
            obj.pname = v.pname;
@@ -344,9 +328,9 @@
            obj.pid = null;
            arr.push(obj);
          });
          that.tableData = arr
          that.setInsertData(that.tableData)
        }
          that.tableData = arr;
          that.setInsertData(that.tableData);
        };
      }
    },
    setInsertData(res) {
@@ -354,15 +338,14 @@
      if (list.length != 0) {
        if (list[0].pname != null) {
          return this.$message.error('上传数据错误,第一条数据不为空');
          return this.$message.error("上传数据错误,第一条数据不为空");
        }
        this.getAllNodeId(list)
        this.getAllNodeId(list);
      }
    },
    async getAllNodeId(res) {
      for (let i = 0; i < res.length; i++) {
        var val = res[i];
        if (val.pname == null) {
@@ -371,29 +354,25 @@
        } 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)
          this.getAllNodeId(res[i].children);
        }
      }
    },
@@ -403,7 +382,7 @@
        // 循环所有项
        let branchArr = cloneData.filter((child) => father.name == child.pname); // 对比ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ''; // 给父级添加一个children属性,并赋值
        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; // 返回一级菜单
@@ -411,10 +390,10 @@
    },
    readFile(file) {
      //文件读取
      return new Promise(resolve => {
      return new Promise((resolve) => {
        let reader = new FileReader();
        reader.readAsBinaryString(file); //以二进制的方式读取
        reader.onload = ev => {
        reader.onload = (ev) => {
          resolve(ev.target.result);
        };
      });
@@ -441,32 +420,28 @@
          //   });
          if (this.itemaName != null) {
            this.$nextTick(() => {
              this.expandData = [this.itemaName]
              this.expandData = [this.itemaName];
              this.$refs.tree.setCurrentKey(this.itemaName);
            });
          }
        } else {
          console.log('接口报错');
          console.log("接口报错");
        }
      });
    },
    handleClose() {
      this.$confirm('确认关闭?')
      this.$confirm("确认关闭?")
        .then((_) => {
          this.resetForm();
        })
        .catch((_) => { });
        .catch((_) => {});
    },
    treeData(source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
      return cloneData.filter((father) => {
        // 循环所有项
        let branchArr = cloneData.filter((child) => father.id == child.pid); // 对比ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ''; // 给父级添加一个children属性,并赋值
        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.pid == 0; // 返回一级菜单
@@ -482,104 +457,105 @@
        }
      }
      switch (res) {
        case 1://向上移动
        case 1: //向上移动
          if (currentId != 0) {
            const tempChildrenNodex1 = pchildNodes[currentId - 1];
            const tempChildrenNodex2 = pchildNodes[currentId];
            tempChildrenNodex2.orderNum = pchildNodes[currentId - 1].data.orderNum;
            tempChildrenNodex1.orderNum = pchildNodes[currentId].data.orderNum
            var arr = [];
            this.oriData.filter(res => {
              if (res.id == tempChildrenNodex2.data.id) {
                res.orderNum = tempChildrenNodex2.orderNum;
                arr.push(res)
              } else if (res.id == tempChildrenNodex1.data.id) {
                res.orderNum = tempChildrenNodex1.orderNum;
                arr.push(res)
              }
            })
            this.newData = arr;
            this.sendChange();
          } else {
            this.$message({
              message: '处于顶端,不能继续上移',
              type: 'warning'
            });
          }
          break;
        case 2://向下移动
          if (currentId < (pchildNodes.length - 1)) {
            const tempChildrenNodex1 = pchildNodes[currentId + 1];
            const tempChildrenNodex2 = pchildNodes[currentId];
            tempChildrenNodex2.orderNum = pchildNodes[currentId + 1].data.orderNum;
            tempChildrenNodex2.orderNum =
              pchildNodes[currentId - 1].data.orderNum;
            tempChildrenNodex1.orderNum = pchildNodes[currentId].data.orderNum;
            var arr = [];
            this.oriData.filter(res => {
            this.oriData.filter((res) => {
              if (res.id == tempChildrenNodex2.data.id) {
                res.orderNum = tempChildrenNodex2.orderNum;
                arr.push(res)
                arr.push(res);
              } else if (res.id == tempChildrenNodex1.data.id) {
                res.orderNum = tempChildrenNodex1.orderNum;
                arr.push(res)
                arr.push(res);
              }
            })
            });
            this.newData = arr;
            this.sendChange();
          } else {
            this.$message({
              message: '处于底端,不能继续下移',
              type: 'warning'
              message: "处于顶端,不能继续上移",
              type: "warning",
            });
          }
          break;
        case 2: //向下移动
          if (currentId < pchildNodes.length - 1) {
            const tempChildrenNodex1 = pchildNodes[currentId + 1];
            const tempChildrenNodex2 = pchildNodes[currentId];
            tempChildrenNodex2.orderNum =
              pchildNodes[currentId + 1].data.orderNum;
            tempChildrenNodex1.orderNum = pchildNodes[currentId].data.orderNum;
            var arr = [];
            this.oriData.filter((res) => {
              if (res.id == tempChildrenNodex2.data.id) {
                res.orderNum = tempChildrenNodex2.orderNum;
                arr.push(res);
              } else if (res.id == tempChildrenNodex1.data.id) {
                res.orderNum = tempChildrenNodex1.orderNum;
                arr.push(res);
              }
            });
            this.newData = arr;
            this.sendChange();
          } else {
            this.$message({
              message: "处于底端,不能继续下移",
              type: "warning",
            });
          }
          break;
      }
    },
    setDelNode() {
      this.$confirm('此操作将永久删除该目录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.remove(this.newNode, this.itemdetail)
        }).catch(() => {
      this.$confirm("此操作将永久删除该目录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.remove(this.newNode, this.itemdetail);
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
            type: "info",
            message: "已取消删除",
          });
        });
    },
    setNewNode(res) {
      var id, lever, orderNum;
      if (res == 1) {//新增同级
      if (res == 1) {
        //新增同级
        id = this.itemdetail.pid;
        orderNum = this.getMaxOrderNum(this.newNode.parent.childNodes)
        orderNum = this.getMaxOrderNum(this.newNode.parent.childNodes);
        lever = this.itemdetail.level;
      } else if (res == 2) {//新增子级
      } else if (res == 2) {
        //新增子级
        id = this.itemdetail.id;
        orderNum = this.getMaxOrderNum(this.newNode.childNodes)
        orderNum = this.getMaxOrderNum(this.newNode.childNodes);
        lever = this.itemdetail.level + 1;
      }
      this.ruleForm.pid = id;
      this.ruleForm.level = lever;
      this.ruleForm.orderNum = orderNum
      this.ruleForm.orderNum = orderNum;
      this.dialogFormVisible = true;
    },
    getMaxOrderNum(res) {
      var val = -100;
      for (var i in res) {
        if (res[i].data.orderNum > val) {
          val = res[i].data.orderNum
          val = res[i].data.orderNum;
        }
      }
      val = val + 1;
      return val;
    },
    append(node, data) {
      this.dialogFormVisible = true;
@@ -607,8 +583,8 @@
                  if (res.code == 200) {
                    this.$message({
                      message: '添加成功',
                      type: 'success',
                      message: "添加成功",
                      type: "success",
                    });
                    this.itemaName = res.result;
                    this.itemdetail = {};
@@ -621,7 +597,7 @@
              })
              .catch((res) => {
                this.itemdetail = {};
                this.$message.error('添加失败');
                this.$message.error("添加失败");
                this.fullscreenLoading = false;
                console.log(res);
              });
@@ -635,10 +611,10 @@
    remove(node, data) {
      this.itemaName = node.parent.data.id;
      this.$confirm('此操作将删除该节点, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      this.$confirm("此操作将删除该节点, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //兄弟重新排序
@@ -659,29 +635,29 @@
            .then((res) => {
              if (res[0].code == 200 && res[1].code == 200) {
                this.$message({
                  type: 'success',
                  message: '删除成功!',
                  type: "success",
                  message: "删除成功!",
                });
                this.itemdetail = {};
                this.getDirTree();
              } else if (res[0].code == 200) {
                this.$message.error('删除成功,位置调整失败');
                this.$message.error("删除成功,位置调整失败");
              } else if (res[1].code == 200) {
                this.$message.error('删除失败,位置调整成功');
                this.$message.error("删除失败,位置调整成功");
              } else {
                this.$message.error('删除失败');
                this.$message.error("删除失败");
              }
            })
            .catch(() => {
              this.$message.error('删除失败');
              this.$message.error("删除失败");
              this.itemdetail = {};
            });
          //重置要删除的子ID
          this.delChildIDs = [];
        })
        .catch(() => {
          this.$message('已取消删除');
          this.$message("已取消删除");
        });
      // this.dialogMessage="是否删除"
      // this.dialogFlag = 1;
@@ -723,20 +699,20 @@
      this.old_dirDat = JSON.parse(JSON.stringify(this.dirList)); //将备份的dir重新赋值
    },
    handleDrop(draggingNode, dropNode, dropType, ev) {
      this.$confirm('此操作将保存目录更改, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      this.$confirm("此操作将保存目录更改, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //父节点
          let data = dropType != 'inner' ? dropNode.parent.data : dropNode.data;
          let data = dropType != "inner" ? dropNode.parent.data : dropNode.data;
          // 父节点中全部子节点
          let nodeData =
            dropNode.level == 1 && dropType != 'inner' ? data : data.children;
            dropNode.level == 1 && dropType != "inner" ? data : data.children;
          //变更节点
          nodeData.forEach((item, i) => {
            if (dropType != 'inner') {
            if (dropType != "inner") {
              if (draggingNode.data.pid === dropNode.data.pid) {
                item.pid = item.pid;
              } else {
@@ -760,7 +736,7 @@
          this.sendChange();
        })
        .catch(() => {
          this.$message('已取消更改');
          this.$message("已取消更改");
          this.dirList = this.old_dirDat; //将备份的dir重新赋值
        });
    },
@@ -771,11 +747,11 @@
            this.getDirTree();
            return;
          } else {
            this.$message.error('修改失败,请重试!');
            this.$message.error("修改失败,请重试!");
          }
        })
        .catch(() => {
          this.$message.error('修改失败,请重试!');
          this.$message.error("修改失败,请重试!");
        });
    },
    handleNodeClick(data, node) {
@@ -802,7 +778,7 @@
                }, 500);
              })
              .catch((res) => {
                this.$message.error('修改失败,请重试!');
                this.$message.error("修改失败,请重试!");
                this.fullscreenLoading = false;
              });
          } else {
@@ -814,20 +790,19 @@
    reset(formName) {
      this.itemdetail = {};
      // this.$refs[formName].resetFields();
      if (this.backUpData != '') {
      if (this.backUpData != "") {
        this.itemdetail = JSON.parse(this.backUpData);
      }
    },
    showPermsMenu(res) {
      switch (res.tag) {
        case '/delete':
        case "/delete":
          this.menuStatus.delete = true;
          break;
        case '/insert':
        case "/insert":
          this.menuStatus.insert = true;
          break;
        case '/update':
        case "/update":
          this.menuStatus.update = true;
          break;
      }
@@ -844,7 +819,6 @@
      }
      for (var i = 0; i < permsEntity.length; i++) {
        if (val === permsEntity[i].perms) {
          this.showPermsMenu(permsEntity[i]);
        }
      }
@@ -859,29 +833,28 @@
<style lang="less" scoped>
.subpage_Box {
  height: 98%;
  height: 96%;
  width: 98%;
  padding: 1%;
 padding: 1%;
  border-radius: 10px;
  .cataLogContent {
    width: 100%;
    height: 100%;
    max-height: 670px;
    display: flex;
    align-items: center;
    // align-items: center;
    justify-content: space-between;
    .cataLog_leftTree {
      width: 15%;
      height: 100%;
      width: 30%;
      height: 98%;
      border-radius: 5px;
      padding: 1%;
      padding: 10px;
      overflow-y: auto;
    }
    .cataLog_rightContent {
      width: 80%;
      height: 100%;
      max-height: 670px;
      width: 66%;
      height: 98%;
      border-radius: 5px;
      padding: 1%;
      padding: 10px;
      .menuTop {
        /deep/ .el-form-item {
          margin-bottom: 0px;
@@ -890,4 +863,7 @@
    }
  }
}
.btnBox{
  text-align: right;
}
</style>