gaoshp
2024-11-19 f29900986f01cf5d39b5755cec674825cef27961
src/views/console/system/data-scope-manager.vue
@@ -2,13 +2,13 @@
 * @Author: lzhe lzhe@example.com
 * @Date: 2024-03-26 10:28:33
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-05-02 22:20:47
 * @LastEditTime: 2024-10-09 16:08:25
 * @FilePath: /smart-web/src/views/master/person/main/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
   <div class="dict-main">
      <el-form :inline="true" :model="searchData" abel-width="120px">
      <el-form :inline="true" :model="searchData" label-width="80px">
         <el-form-item label="权限名称">
            <el-input v-model="searchData.deptName" placeholder="权限名称" clearable />
         </el-form-item>
@@ -26,8 +26,8 @@
            <el-button type="danger" @click="delData">删除</el-button>
            <el-button type="primary" @click="addAuthority">权限设置</el-button>
         </div>
         <div class="dict-table">
            <el-table ref="multipleTableRef" :data="tableData" border row-key="id" style="width: 100%" class="multipleTableRef" @selection-change="handleSelectionChange" :tree-props="{ children: 'children', hasChildren: 'has' }">
         <div class="dict-table" v-if="showTable">
            <el-table ref="multipleTableRef" :data="tableData" border row-key="id" style="width: 100%" class="multipleTableRef" @selection-change="handleSelectionChange" lazy :load="tableLoad" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" default-expand-all>
               <el-table-column type="selection" width="55" />
               <el-table-column prop="deptName" label="权限名称"></el-table-column>
               <el-table-column prop="fullName" label="权限描述"></el-table-column>
@@ -36,15 +36,27 @@
               <el-table-column fixed="right" label="操作" width="280">
                  <template #default="scope">
                     <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
                     <el-button text type="primary" size="small" @click="showDrawer(scope.row, scope.$index)">编辑</el-button>
                     <el-button text type="primary" size="small" @click="showDrawer(scope.row, scope.$index)">删除</el-button>
                     <el-button text type="primary" size="small" @click="showDrawer(scope.row, scope.$index)">新增子项</el-button>
                     <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                     <el-button text type="primary" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
                     <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index,'fixed')">新增子项</el-button>
                  </template>
               </el-table-column>
            </el-table>
         </div>
      </div>
      <save-dialog v-if="dialog.save" ref="saveDialog" :deptCategoryList="deptCategoryList" :parentIdList ="parentIdList" @success="addDatascopeSuccess" @closed="dialog.save=false"></save-dialog>
      <el-dialog title="权限配置" v-model="authorityVisible" :width="800" destroy-on-close>
         <el-tabs type="border-card">
             <el-tab-pane label="数据权限">
                <el-tree ref="authorityTree" :data="authorityTreeData" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="treeHandleCheckChange" :default-checked-keys="treeCheck" />
             </el-tab-pane>
         </el-tabs>
      <template #footer>
         <el-button @click="authorityVisible=false" >取 消</el-button>
         <el-button type="primary" :loading="authoritySaveing" @click="authoritySubmit">确定</el-button>
      </template>
   </el-dialog>
   </div>
</template>
<script>
@@ -58,6 +70,11 @@
      name: "datascope",
      data(){
         return {
            showTable: false,
            treeCheck: [],
            authorityTreeData: [],
            authoritySaveing: false,
            authorityVisible: false,
            scopeTypeNameList: [],
            dialog: {
               save: false
@@ -107,6 +124,33 @@
          ...ElementPlusIconsVue,saveDialog
       },
      methods: {
         treeHandleCheckChange() {
         },
         authoritySubmit() {
            var obj = {
               dataScopeIds: this.$refs.authorityTree.getCheckedKeys(),
               deptId: this.selectId
            }
            this.authoritySaveing = true;
            this.$HTTP.post("/api/blade-system/data-scope-manager/grant",obj).then(res=> {
               this.authoritySaveing = false;
               if(res.code == 200) {
                  this.authorityVisible = false;
                  this.$message.success("操作成功");
                  this.searchClearBtn();
               }else {
                  this.$alert(res.message, "提示", {type: 'error'});
               }
            })
         },
         tableLoad(row,treeNode,resolve) {
            this.$HTTP.get(`/api/blade-system/data-scope-manager/lazy-list?parentId=${row.id}`).then(res=> {
               if(res.code == 200) {
                  resolve(res.data);
               }
            })
         },
         getParentIdList() {
            this.$HTTP.get("/api/blade-system/data-scope-manager/tree").then(res=> {
               if(res.code == 200) {
@@ -121,25 +165,44 @@
               }
            })
         },
         addDatascopeSuccess() {
         addDatascopeSuccess(addDictForm,mode) {
            this.searchclick();
         },
         //添加
         addData(){
            this.dialog.save = true;
            this.$nextTick(() => {
               this.$refs.saveDialog.open();
               this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList);
            })
         },
         getTreeSelect(id) {
            this.$HTTP.get(`/api/blade-system/data-scope-manager/grant-select?deptId=${id}`).then(res=> {
               if(res.code == 200) {
                  this.treeCheck = res.data;
               }
            })
         },
         addAuthority() {
            this.$message({
               message: '只能选择一条数据',
               type: 'warning'
            });
            if(this.selection.length != 1) {
               this.$message({
                  message: '只能选择一条数据',
                  type: 'warning'
               });
                 return;
            }
            this.selectId = this.selection[0].id;
            this.treeCheck = [];
            this.$HTTP.get("/api/blade-system/menu/grant-tree").then(res=> {
               if(res.code == 200) {
                  this.authorityTreeData = res.data.dataScope;
                  this.getTreeSelect(this.selectId);
                  this.authorityVisible = true;
               }
            })
         },
         // 删除
         delData() {
            if(this.drawerSelection.length == 0) {
            if(this.selection.length == 0) {
               this.$message({
                   message: '请选择至少一条数据',
                   type: 'warning'
@@ -147,33 +210,32 @@
                 return;
            }
            var selStr = "";
            this.drawerSelection.map(item=> {
            this.selection.map(item=> {
               selStr += item.id + ","
            })
            selStr = selStr.replace(/,$/, '');
            var that = this;
            this.$HTTP.post("/api/blade-system/data-scope/remove?ids="+selStr).then(res=> {
            this.$HTTP.post("/api/blade-system/data-scope-manager/remove?ids="+selStr).then(res=> {
               if(res.code == 200) {
                  that.$message.success("操作成功");
                  that.searchclick();
               }
            })
         },
         table_edit(row){  //编辑
         table_edit(row,index,fixed){  //编辑
            this.dialog.save = true
            this.$HTTP.get("/api/blade-system/data-scope/detail?id="+row.id).then(res=> {
               if(res.code == 200) {
                  this.dialog.save = true;
                  this.$nextTick(() => {
                     this.$refs.saveDialog.open('edit').setData(res.data);
                  })
            this.$nextTick(() => {
               if(fixed) {  //判断新增子项
                  row.fixed = "fixed";
               }
               this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList,'edit').setData(row)
            })
         },
         //查看
         table_show(row){  //查看
            this.dialog.save = true
            this.$nextTick(() => {
               this.$refs.saveDialog.open('show').setData(row)
               this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList,'show').setData(row)
            })
         },
         table_del(row) {
@@ -181,9 +243,10 @@
            this.$confirm(`确定将选择数据删除?`, '', {
               type: 'warning'
            }).then(() => {
               this.$HTTP.post("/api/blade-system/data-scope/remove?ids="+row.id).then(res=> {
               this.$HTTP.post("/api/blade-system/data-scope-manager/remove?ids="+row.id).then(res=> {
                  if(res.code == 200) {
                     that.$message.success("操作成功");
                     that.searchBtn();
                  }
               })
            }).catch(() => {
@@ -213,35 +276,23 @@
            this.searchBtn();
         },
         searchBtn() {
            this.showTable = false;
            var obj = {};
            for(var key in this.searchData) {
               if(this.searchData[key]) {
                  obj[key] = this.searchData[key];
               }
            }
            this.tableData = [];
            this.$HTTP.get("/api/blade-system/data-scope-manager/lazy-list?" + this.$TOOL.qsStringify(obj)).then(res=> {
               if(res.code == 200) {
                  this.showTable = true;
                  this.tableData = res.data;
               }
            })
         },
         handleSelectionChange(selection) {
            this.selection = selection;
         },
         drawerHandleSelectionChange(selection) {
            this.drawerSelection = selection;
         },
         changeDepartment() {
            this.departmentVisible = true;
         },
         handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.drawerSearchData.current = "1";
            this.drawerSearchData.size = val;
         },
         handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.drawerSearchData.current = val;
         }
      }
   }
@@ -276,7 +327,7 @@
      margin-bottom: 8px;
   }
   .attachSize {
      color:#3b8e8e;
      color:#409eff;
      padding: 0 10px;
       font-size: 12px;
      background-color: #ebf4f4;