管道基础大数据平台系统开发-【前端】-新系統界面
Surpriseplus
2023-01-16 3c0bcd367dbc9aff25202d1a8ec2eb143f3e8261
src/views/datamanage/catalogueManage.vue
@@ -1,63 +1,89 @@
<template>
  <div class="cataSettings_box">
    <div class="cataSettings_tree">
      <My-bread :list="['数据管理', '目录管理']"></My-bread>
      <!-- <el-button class="saveBtn" type="primary" size="mini" @click="sendChange" -->
      <!-- >保存</el-button -->
      <!-- > -->
      <el-divider />
      <div class="cataTreeBox">
        <el-tree
          ref="tree"
          :props="defaultProps"
          node-key="id"
          :data="dirList"
          :expand-on-click-node="false"
          :default-expand-all="true"
          draggable
          @node-click="handleNodeClick"
          @node-drag-start="handleDragStart"
          @node-drag-end="handleDrop"
  <div class="cataLogBox">
    <My-bread :list="[
        `${$t('dataManage.dataManage')}`,
        `${$t('dataManage.catalogueManage')}`,
      ]"></My-bread>
    <el-divider />
    <div class="cataLogContent">
      <div class="cataLog_leftTree">
        <div style="min-width:450px">
          <el-tree
            ref="tree"
            :props="defaultProps"
            node-key="id"
            :data="dirList"
            :highlight-current="true"
            :expand-on-click-node="false"
            :default-expand-all="true"
            @node-click="handleNodeClick"
          >
          </el-tree>
        </div>
      </div>
      <div class="cataLog_rightContent">
        <div style="display:flex;justify-content:space-between">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">{{
            $t('dataManage.dictionaryManageObj.particulars')
          }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div>
            <el-button
              :disabled="itemdetail.pid == null ? true : false"
              @click="setEditNode(1)"
              type="info"
              icon="el-icon-top"
              size="small"
            >向上移动</el-button>
            <el-button
              :disabled="itemdetail.pid == null ? true : false"
              @click="setEditNode(2)"
              type="info"
              icon="el-icon-bottom"
              size="small"
            >向下移动</el-button>
            <el-button
              :disabled="itemdetail.pid == null ? true : false"
              @click="setNewNode(1)"
              type="success"
              icon="el-icon-plus"
              size="small"
            >新增同级</el-button>
            <el-button
              :disabled="itemdetail.pid == null ? true : false"
              @click="setNewNode(2)"
              type="success"
              icon="el-icon-plus"
              size="small"
            >新增子级</el-button>
            <el-button
              @click="setDelNode()"
              :disabled="itemdetail.pid == null ? true : false"
              type="danger"
              icon="el-icon-delete"
              size="small"
            >删除</el-button>
          </div>
        </div>
        <el-divider />
        <el-form
          :model="itemdetail"
          ref="itemdetail"
          :rules="rules"
        >
          <span class="custom-tree-node" slot-scope="{ node, data }">
            <span>{{ node.label }}</span>
            <span class="btnBox">
              <el-button
                type="text"
                size="mini"
                @click="() => append(node, data)"
              >
                <i class="el-icon-circle-plus"></i>
              </el-button>
              <el-button
                type="text"
                size="mini"
                @click="() => remove(node, data)"
              >
                <i class="el-icon-delete-solid"></i>
              </el-button>
            </span>
          </span>
        </el-tree>
      </div>
    </div>
    <div class="itemSettings">
      <div class="title_box">
        <h4>详细信息</h4>
      </div>
      <div class="form_box">
        <el-form :model="itemdetail" ref="itemdetail" :rules="rules">
          <!-- <el-form-item label="目录编码" :label-width="formLabelWidth">
            <el-input v-model="itemdetail.id" disabled />
          </el-form-item> -->
          <el-form-item
            prop="name"
            label="目录名称"
            :label="$t('dataManage.dataUpObj.directoryName')"
            :label-width="formLabelWidth"
          >
            <el-input v-model="itemdetail.name" />
          </el-form-item>
          <el-form-item label="目录说明" :label-width="formLabelWidth">
          <el-form-item
            :label="$t('dataManage.dataUpObj.catalogDescription')"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="itemdetail.descr"
              type="textarea"
@@ -65,46 +91,100 @@
              style="height: 100%; overflow: auto"
            />
          </el-form-item>
          <el-form-item label="目录备注" :label-width="formLabelWidth">
            <el-input v-model="itemdetail.bak" type="textarea" resize="none" />
          <el-form-item
            :label="$t('dataManage.dataUpObj.catalogRemarks')"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="itemdetail.bak"
              type="textarea"
              resize="none"
            />
          </el-form-item>
          <div class="btnBox">
            <el-button type="primary" @click="updCata('itemdetail')"
              >保存</el-button
            >
            <el-button type="primary" @click="reset('itemdetail')"
              >取消</el-button
            >
            <el-button
              class="primary"
              size="small"
              @click="updCata('itemdetail')"
            >{{
              $t('common.preservation')
            }}</el-button>
            <el-button
              type="info"
              size="small"
              @click="reset"
            >{{
              $t('common.cancel')
            }}</el-button>
          </div>
        </el-form>
      </div>
    </div>
    '
    <!-- <div class="cataSettings_tree"> -->
    <el-dialog title="新增子目录" :visible.sync="dialogFormVisible">
      <el-form :model="ruleForm" ref="ruleForm" :rules="rules">
    <!-- <div class="cataTreeBox">
      </div> -->
    <!-- </div> -->
    <!-- <div class="itemSettings"> -->
    <!-- <div class="title_box">
        <h4>详细信息</h4>
      </div> -->
    <!-- <div class="form_box">
      </div> -->
    <!-- </div> -->
    <el-dialog
      :title="$t('dataManage.dataUpObj.newDirectory')"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        :rules="rules"
      >
        <el-form-item
          label="目录名称"
          :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="目录说明" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.descr" autocomplete="off"></el-input>
        <el-form-item
          :label="$t('dataManage.dataUpObj.catalogDescription')"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="ruleForm.descr"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="目录备注" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.bak" autocomplete="off"></el-input>
        <el-form-item
          :label="$t('dataManage.dataUpObj.catalogRemarks')"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="ruleForm.bak"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="resetForm('ruleForm')">{{
          $t('common.cancel')
        }}</el-button>
        <el-button
          type="primary"
          class="primary"
          @click="submitForm('ruleForm')"
          v-loading.fullscreen.lock="fullscreenLoading"
          >提交</el-button
        >
        >{{ $t('common.preservation') }}</el-button>
      </div>
    </el-dialog>
  </div>
@@ -118,25 +198,25 @@
  updateDirTrees,
  insertDir,
  deleteDir,
} from "../../api/api";
import MyBread from "../../components/MyBread.vue";
} from '../../api/api';
import MyBread from '../../components/MyBread.vue';
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();
      }
    };
    return {
      defaultProps: {
        children: "children",
        label: "name",
        children: 'children',
        label: 'name',
      },
      fullscreenLoading: false,
      oriData: [], //原始树数据
@@ -144,22 +224,23 @@
      old_dirDat: [], //el树数据(拖动前)
      newData: [], //拖动后原始数据
      itemdetail: {},
      backUpData: "",
      formLabelWidth: "130px",
      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,
    };
  },
  methods: {
@@ -176,22 +257,137 @@
          this.oriData = res.result;
          this.newData = res.result;
          this.dirList = this.treeData(res.result);
          if (this.itemdetail.id != null) {
            this.$nextTick(() => {
              this.$refs.tree.setCurrentKey(this.itemdetail.id);
            });
          }
        } else {
          console.log("接口报错");
          console.log('接口报错');
        }
      });
    },
    handleClose() {
      this.$confirm('确认关闭?')
        .then((_) => {
          this.resetForm();
        })
        .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; // 返回一级菜单
      });
    },
    setEditNode(res) {
      let node = this.$refs.tree.getCurrentNode();
      let pchildNodes = this.$refs.tree.getNode(node.id).parent.childNodes;
      let currentId = {};
      for (let i = 0; i < pchildNodes.length; i++) {
        if (pchildNodes[i].data.id == node.id) {
          currentId = i;
        }
      }
      switch (res) {
        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;
            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.remove(this.newNode, this.itemdetail)
    },
    setNewNode(res) {
      var id, lever, orderNum;
      if (res == 1) {//新增同级
        id = this.itemdetail.pid;
        orderNum = this.getMaxOrderNum(this.newNode.parent.childNodes)
        lever = this.itemdetail.level;
      } else if (res == 2) {//新增子级
        id = this.itemdetail.id;
        orderNum = this.getMaxOrderNum(this.newNode.childNodes)
        lever = this.itemdetail.level + 1;
      }
      this.ruleForm.pid = id;
      this.ruleForm.level = lever;
      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 = val + 1;
      return val;
    },
    append(node, data) {
      this.dialogFormVisible = true;
      this.ruleForm.pid = data.id;
@@ -200,6 +396,7 @@
    },
    resetForm(formName) {
      this.dialogFormVisible = false;
      this.ruleForm = {};
      this.$nextTick(() => {
        this.ruleForm = {};
        this.$refs[formName].resetFields();
@@ -216,19 +413,20 @@
                  this.fullscreenLoading = false;
                  if (res.code == 200) {
                    this.$message({
                      message: "添加成功",
                      type: "success",
                      message: '添加成功',
                      type: 'success',
                    });
                    this.itemdetail = {};
                    this.ruleForm = {};
                    this.dialogFormVisible = false;
                    this.$refs[formName].resetFields();
                    this.getDirTree();
                  }
                }, 500);
              })
              .catch((res) => {
                this.itemdetail = {};
                this.$message.error("添加失败");
                this.$message.error('添加失败');
                this.fullscreenLoading = false;
                console.log(res);
              });
@@ -240,10 +438,10 @@
      });
    },
    remove(node, data) {
      this.$confirm("此操作将删除该节点, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      this.$confirm('此操作将删除该节点, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          //兄弟重新排序
@@ -262,23 +460,23 @@
            updateDirTrees(children),
          ])
            .then((res) => {
              console.log(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 = {};
            });
@@ -286,7 +484,7 @@
          this.delChildIDs = [];
        })
        .catch(() => {
          this.$message("已取消删除");
          this.$message('已取消删除');
        });
      // this.dialogMessage="是否删除"
      // this.dialogFlag = 1;
@@ -328,20 +526,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 {
@@ -365,7 +563,7 @@
          this.sendChange();
        })
        .catch(() => {
          this.$message("已取消更改");
          this.$message('已取消更改');
          this.dirList = this.old_dirDat; //将备份的dir重新赋值
        });
    },
@@ -376,15 +574,16 @@
            this.getDirTree();
            return;
          } else {
            alert("调整失败,请重试!");
            alert('调整失败,请重试!');
          }
        })
        .catch(() => {
          alert("修改失败,请重试!");
          alert('修改失败,请重试!');
        });
    },
    handleNodeClick(data) {
    handleNodeClick(data, node) {
      // console.log(data);
      this.newNode = node;
      this.backUpData = JSON.stringify(data);
      this.itemdetail = JSON.parse(JSON.stringify(data));
    },
@@ -405,7 +604,7 @@
                }, 500);
              })
              .catch((res) => {
                alert("修改失败,请重试!");
                alert('修改失败,请重试!');
                this.fullscreenLoading = false;
              });
          } else {
@@ -415,8 +614,9 @@
      });
    },
    reset(formName) {
      this.$refs[formName].resetFields();
      if (this.backUpData != "") {
      this.itemdetail = {};
      // this.$refs[formName].resetFields();
      if (this.backUpData != '') {
        this.itemdetail = JSON.parse(this.backUpData);
      }
    },
@@ -428,93 +628,143 @@
</script>
<style lang="less" scoped>
.cataSettings_box {
  border-radius: 10px;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  .cataSettings_tree {
    position: relative;
    width: 344px;
    height: 100%;
    background: rgb(240, 242, 245);
    padding: 20px;
    border-radius: 10px;
    box-sizing: border-box;
    overflow: auto;
    .saveBtn {
      position: absolute;
      left: 250px;
      top: 23px;
.cataLogBox {
  height: 98%;
  width: 98%;
  padding: 1%;
  .cataLogContent {
    width: 100%;
    height: 92%;
    display: flex;
    justify-content: space-between;
    .cataLog_leftTree {
      width: 15%;
      height: 91%;
      border: 1px solid white;
      border-radius: 5px;
      padding: 1%;
      overflow-y: auto;
    }
    .cataTreeBox {
      height: 88%;
      width: 100%;
      overflow: auto;
      .el-tree {
        background: transparent;
        font-size: 15px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        /deep/ .el-tree-node {
          padding-top: 10px;
          // padding-bottom: 10px;
        }
        /deep/ .el-tree-node:focus > .el-tree-node__content {
          background-color: #b9b9b9;
        }
        /deep/ .el-tree-node__content:hover {
          background-color: rgb(153, 153, 153);
        }
        .btnBox {
          margin: 0 10px 0 5px;
          .el-button + .el-button {
            margin-left: 5px;
          }
        }
      }
    .cataLog_rightContent {
      width: 80%;
      height: 91%;
      border: 1px solid white;
      border-radius: 5px;
      padding: 1%;
    }
  }
  .itemSettings {
    width: calc(100% - 344px);
    border-radius: 10px;
    background: rgb(240, 242, 245);
    margin-left: 10px;
    height: 100%;
    padding: 10px;
    box-sizing: border-box;
    .title_box {
      background: #fff;
      padding: 10px;
      margin-bottom: 24px;
      display: flex;
      border-radius: 10px;
      border: 1px solid rgb(202, 201, 204);
      box-sizing: border-box;
    }
    .form_box {
      border: 1px solid rgb(202, 201, 204);
      border-radius: 10px;
      background: #fff;
      padding-top: 30px;
      box-sizing: border-box;
      width: 100%;
      .el-input,
      /deep/ .el-textarea {
        width: 400px;
      }
      .btnBox {
        margin: 0 270px 20px;
        width: 200px;
        display: flex;
        justify-content: space-between;
      }
    }
  // .cataSettings_tree {
  //   position: relative;
  //   width: 344px;
  //   height: 100%;
  //   background: rgb(240, 242, 245);
  //   padding: 20px;
  //   border-radius: 10px;
  //   box-sizing: border-box;
  //   overflow: auto;
  //   .saveBtn {
  //     position: absolute;
  //     left: 250px;
  //     top: 23px;
  //   }
  //   .cataTreeBox {
  //     height: 88%;
  //     width: 100%;
  //     overflow: auto;
  //     .el-tree {
  //       background: transparent;
  //       font-size: 15px;
  //       font-family: Microsoft YaHei;
  //       font-weight: 400;
  //       color: #000000;
  //       /deep/ .el-tree-node {
  //         padding-top: 10px;
  //         // padding-bottom: 10px;
  //       }
  //       /deep/ .el-tree-node:focus > .el-tree-node__content {
  //         background-color: #b9b9b9;
  //       }
  //       /deep/ .el-tree-node__content:hover {
  //         background-color: rgb(153, 153, 153);
  //       }
  //       .btnBox {
  //         margin: 0 10px 0 5px;
  //         .el-button + .el-button {
  //           margin-left: 5px;
  //         }
  //       }
  //     }
  //   }
  // }
  // .itemSettings {
  //   width: calc(100% - 344px);
  //   border-radius: 10px;
  //   background: rgb(240, 242, 245);
  //   margin-left: 10px;
  //   height: 100%;
  //   padding: 10px;
  //   box-sizing: border-box;
  //   .title_box {
  //     background: #fff;
  //     padding: 10px;
  //     margin-bottom: 24px;
  //     display: flex;
  //     border-radius: 10px;
  //     border: 1px solid rgb(202, 201, 204);
  //     box-sizing: border-box;
  //   }
  //   .form_box {
  //     border: 1px solid rgb(202, 201, 204);
  //     border-radius: 10px;
  //     background: #fff;
  //     padding-top: 30px;
  //     box-sizing: border-box;
  //     width: 100%;
  //     .el-input,
  //     /deep/ .el-textarea {
  //       width: 400px;
  //     }
  //     .btnBox {
  //       margin: 0 270px 20px;
  //       width: 200px;
  //       display: flex;
  //       justify-content: space-between;
  //     }
  //   }
  // }
  // /deep/ .el-dialog__body {
  //   padding: 0 30px 0 0;
  // }
  .el-icon-delete-solid {
    color: gray;
  }
  /deep/ .el-dialog__body {
    padding: 0 30px 0 0;
  .el-icon-circle-plus {
    color: gray;
  }
  /deep/.el-form-item__label {
    color: white;
  }
  // 设置输入框的背景色、字体颜色、边框属性设置;
  /deep/.el-input__inner {
    background-color: transparent !important ;
    color: #fff;
    border: 1px solid;
  }
  /deep/ .el-dialog {
    background: #303030;
  }
  /deep/.el-range-editor.is-active,
  .el-range-editor.is-active:hover,
  .el-select .el-input.is-focus .el-input__inner {
    border: 1px solid;
  }
  /deep/.el-dialog__title {
    color: white;
  }
  .primary {
    background: #409eff;
    border: #409eff;
    color: white;
  }
}
</style>