wangting
2025-01-08 f22211dcc3767d8fb50a37eb424a258a12fe626b
Source/plt-web/plt-web-ui/src/views/authority/ui/uiAuthorization/UIDialog.vue
@@ -8,31 +8,38 @@
             :destroy-on-close="true"
             :close-on-click-modal="false"
             @close="cancelDialog">
    <el-aside>
      <basic-container>
        <avue-tree ref="tree" :data="treeData" :option="treeOption" @node-click="nodeClick">
    <el-container style="height: 550px">
    <el-aside style="height: 500px">
      <basic-container v-loading="leftLoading">
        <div style="height: 425px">
          <avue-tree ref="tree" :data="treeData" :option="treeOption" @node-click="nodeClick">
          <span slot-scope="{ node, data }" class="el-tree-node__label">
           <span style="font-size: 15px">
           <span>
              <i class="el-icon-user-solid"></i>
                {{ (node || {}).label }}
            </span>
          </span>
        </avue-tree>
          </avue-tree>
        </div>
      </basic-container>
    </el-aside>
    <el-main>
      <basic-container>
        <avue-tree ref="uiTree" :data="uiTreeData" :option="uiTreeOption">
    <el-main style="height: 500px">
      <basic-container v-loading="rightLoading">
        <h3 style="margin: 0">模块权限配置</h3>
        <div style="height: 445px;">
          <avue-tree ref="uiTree" :data="uiTreeData" :option="uiTreeOption">
          <span slot-scope="{ node, data }" class="el-tree-node__label">
           <span style="font-size: 15px">
              <i class="el-icon-user-solid"></i>
            <span>
              <i :class="data.icon"></i>
                {{ (node || {}).label }}
            </span>
          </span>
        </avue-tree>
          </avue-tree>
        </div>
      </basic-container>
    </el-main>
    </el-container>
    <div class="dialog-footer avue-dialog__footer">
      <el-button type="primary" plain size="small" @click="submitDialog" >授权</el-button>
      <el-button type="primary" plain size="small" @click="clearValue" >重置</el-button>
@@ -49,6 +56,8 @@
name: "UIDialog",
  data() {
    return {
      leftLoading:false,
      rightLoading:false,
      dialog: {
        showDialog: false,
        title: "UI授权",
@@ -58,7 +67,6 @@
      type:'',//业务类型
      context:'',//UI上下文code
      treeOption: {
        height: '500px',
        menu: false,
        addBtn: false,
        props: {
@@ -69,13 +77,17 @@
      },
      nodeRow: {},
      treeData: [],
      defaultExpandKeys:[],
      uiTreeOption: {
        height: '500px',
        nodeKey:'oid',
        checkOnClickNode:true,
        defaultExpandedKeys:this.defaultExpandKeys,
        multiple: true,
        menu: false,
        addBtn: false,
        filter:false,
        props: {
          label: 'name',
          label: 'label',
          value: 'oid',
          children: 'children'
        }
@@ -89,47 +101,97 @@
      this.context=context;
      this.dialog.showDialog = true;
      this.getTreeList()
      this.uiTreeData=[];
    },
    cancelDialog() {
      this.dialog.loading = false;
      this.dialog.showDialog = false;
    },
    getTreeList() {
      const loading = this.$loading({});
      this.leftLoading = true;
      gridRoles().then(res => {
        this.treeData = res.data.data;
        loading.close();
        this.leftLoading = false;
      }).catch(error=>{
        loading.close();
        this.leftLoading = false;
      })
    },
    // 角色点击
    nodeClick(row) {
    nodeClick(row,node) {
      this.nodeRow = row;
      const loading = this.$loading({});
      getUIAuthor().then(res => {
        this.uiTreeData = res.data.data;
        loading.close();
      }).catch(error=>{
        loading.close();
      this.rightLoading = true;
      const params = {
        'conditionMap[roleId]': this.nodeRow.oid,
        'conditionMap[type]': this.type,
        'conditionMap[context]': this.context
      }
      this.defaultExpandKeys=['root'];
      getUIAuthor(params).then(res => {
        this.processChildren(res.data.data[0]); // 处理每个节点
        this.uiTreeOption.defaultExpandedKeys=this.defaultExpandKeys;
        this.uiTreeData = [{
          attributes: {},
          checked: false,
          expanded: true,
          data: "root",
          level: 0,
          icon: 'el-icon-s-home',
          oid: res.data.data[0].oid,
          label: res.data.data[0].text,
          children: res.data.data[0].children
        }];
        this.rightLoading = false;
      }).catch(error => {
        this.rightLoading = false;
      })
    },
    //处理树
    processChildren(item) {
      if (item.children && item.children.length > 0) {
        item.children = item.children.map(child => {
          if(child.level<4){
            this.defaultExpandKeys.push(child.oid)
          }
          if(child.level==1){
            child.icon='el-icon-s-promotion';
            child.label=child.data.label+'('+child.data.name+')'
          }else if(child.level==2){
            child.icon='el-icon-s-order';
            child.label=child.text
          }else if(child.level==3){
            child.icon='el-icon-office-building';
            child.label=child.text
          }else if(child.level==4){
            child.icon='el-icon-document';
            child.label=child.text
          }else if(child.level==5){
            child.icon='el-icon-s-tools';
            child.label=child.text
          }
          this.processChildren(child); // 递归处理每个子节点
          return child; // 只返回子节点的 attributes
        });
      }
    },
    submitDialog() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const formData={}
          authorizedUI(formData).then(res => {
            if (res.data.success) {
              this.$message.success("保存成功");
              this.cancelDialog();
            }
          });
        } else {
          return false;
      const selectTreeList = this.$refs.uiTree.getCheckedNodes();
      if (selectTreeList.length == 0) {
        this.$message.error("请选择功能模块");
        return;
      }
      const formData = {
        roleId: this.nodeRow.oid,
        type: this.type,
        context: this.context,
        selectTreeList: selectTreeList
      }
      authorizedUI(formData).then(res => {
        if (res.data.success) {
          this.$message.success("授权成功");
          this.cancelDialog();
        }
      });
    },
    clearValue(){
      this.$refs.uiTree.setCheckedNodes([])