Просмотр исходного кода

feat(系统管理): 优化角色管理功能,添加编码字段并修复表格合并逻辑

yusheng 5 месяцев назад
Родитель
Сommit
821d1fcbdb

+ 2 - 2
src/views/rulesManagement/releaseRules/components/experimentationProcess.vue

@@ -244,8 +244,8 @@
 </template>
 
 <script>
-  import customText from './customText.vue';
-  import customTable from './customTable.vue';
+  import customText from '../components/templateDiv/customText.vue';
+  import customTable from '../components/templateDiv/customTable.vue';
   import VueDraggable from 'vuedraggable';
   import { generateRandomString } from '@/utils/util';
 

+ 74 - 13
src/views/rulesManagement/releaseRules/components/templateDiv/customTable.vue

@@ -183,7 +183,6 @@
         this.startY = event.clientY;
         this.endX = this.startX;
         this.endY = this.startY;
-        console.log(this.startX, this.startY, this.endX, this.endY);
       },
       updateSelection(event) {
         if (this.isSelecting) {
@@ -225,7 +224,7 @@
         let rowspan = this.selectedItems
           .filter((item) => item.columnIndex === _columnIndex)
           .reduce((acc, cur) => acc + cur.rowspan, 0);
-        if (this.verify(_colspan, rowspan, this.selectedItems)) {
+        if (this.verify(_colspan, rowspan, this.selectedItems, _rowIndex)) {
           return;
         }
         for (let index = 0; index < this.selectedItems.length; index++) {
@@ -262,13 +261,20 @@
       colspanSum(rowIndex) {
         return this.selectedItems.filter((item) => item.rowIndex == rowIndex);
       },
-      verify(_colspan, _rowspan, arr) {
-        console.log(arr, 'arr');
-        console.log(_colspan, '_colspan');
-        console.log(_rowspan, '_rowspan');
-
+      verify(_colspan, _rowspan, arr, _rowIndex) {
         for (let index = 0; index < arr.length; index++) {
           let item = arr[index];
+          if (_rowIndex === 0 && _rowIndex != item.rowIndex) {
+            //表头不能和其他行合并
+            return true;
+          }
+          if (
+            item.rowIndex != this.selectedItems[0].rowIndex &&
+            _colspan > this.colspanSum(item.rowIndex).length &&
+            item.colspan != 0
+          ) {
+            return true;
+          }
 
           if (item.rowspan > _rowspan) {
             return true;
@@ -311,17 +317,72 @@
           id: generateRandomString(5)
         };
       },
+      getIndex(id) {
+        let columnIndex, rowIndex;
+        console.log(id);
+        this.columns.forEach((cell, _columnIndex) => {
+          let cellIndex = cell.findIndex((data) => data.id == id);
+          if (cellIndex != '-1') {
+            columnIndex = _columnIndex;
+            rowIndex = cellIndex;
+          }
+        });
+        return { columnIndex, rowIndex };
+      },
 
       // 方法:删除指定列
       removeColumn(item, index) {
-        this.columns.splice(index, 1);
-        this.columns.forEach((row, columnIndex) => {
-          row.forEach((cell, index) => {
-            if (item?.colspanKey.includes(cell.id)) {
-              this.columns.splice(columnIndex, 1);
+        this.columns[index].forEach((cell, rowIndex) => {
+          if (cell.colspanKey.length) {
+            //当前删除的列其他行有合并过单元格的处理
+            let data = this.columns[index + 1][rowIndex];
+
+            data.colspan = cell.colspan - 1;
+            data.rowspan = cell.rowspan;
+            data.style = cell.style;
+            data.colspanKey = cell.colspanKey.filter((item) => item != data.id);
+            if (data.rowspan > 1) {
+              for (let j = 1; j < data.rowspan; j++) {
+                this.$set(this.columns[index + 1][rowIndex + j], 'rowspan', 0);
+              }
             }
-          });
+            this.$set(this.columns[index + 1], rowIndex, data);
+          }
         });
+        if (item?.colspanKey.length) {
+          item.colspanKey.forEach((id) => {
+            let { columnIndex } = this.getIndex(id);
+            console.log(columnIndex, 'columnIndex');
+
+            this.columns[columnIndex].forEach((cell, rowIndex) => {
+              if (cell.colspanKey.length) {
+                //当前删除的列其他行有合并过单元格的处理
+                let data = this.columns[columnIndex + 1][rowIndex];
+
+                data.colspan = cell.colspan - 1;
+                data.rowspan = cell.rowspan;
+                data.style = cell.style;
+                data.colspanKey = cell.colspanKey.filter(
+                  (item) => item != data.id
+                );
+                if (data.rowspan > 1) {
+                  for (let j = 1; j < data.rowspan; j++) {
+                    this.$set(
+                      this.columns[columnIndex + 1][rowIndex + j],
+                      'rowspan',
+                      0
+                    );
+                  }
+                }
+                this.$set(this.columns[columnIndex + 1], rowIndex, data);
+              }
+            });
+
+            this.columns.splice(index + 1, 1);
+          });
+        }
+        this.columns.splice(index, 1);
+        //当前删除的列合并过单元格的列都删除
       },
 
       // 方法:添加新行

+ 45 - 52
src/views/system/role/components/role-edit.vue

@@ -17,18 +17,9 @@
           placeholder="请输入角色名称"
         />
       </el-form-item>
-      <!-- <el-form-item label="组织ID:" prop="groupId">
-        <ele-tree-select
-          clearable
-          :data="organizationList"
-          label-key="name"
-          value-key="id"
-          default-expand-all
-          placeholder="请选择所属机构"
-            v-model="form.groupId"
-
-        />
-      </el-form-item> -->
+      <el-form-item label="编码:" prop="code">
+        <el-input placeholder=" " v-model="form.code" />
+      </el-form-item>
       <el-form-item label="启用状态:" prop="enable">
         <el-switch
           v-model="form.enable"
@@ -41,7 +32,12 @@
       </el-form-item>
       <el-form-item label="密级:" prop="secretLevel">
         <el-select v-model="form.secretLevel" style="width: 100%">
-          <el-option v-for="item in secretLevelList()" :key="item.value" :label="item.label" :value="item.value"></el-option>
+          <el-option
+            v-for="item in secretLevelList()"
+            :key="item.value"
+            :label="item.label"
+            :value="item.value"
+          ></el-option>
         </el-select>
       </el-form-item>
       <el-form-item label="权限范围" prop="dataScope">
@@ -54,10 +50,11 @@
       </el-form-item>
       <el-form-item prop="dataScope">
         <el-scrollbar
-          v-if="form.dataScope=='2'"
+          v-if="form.dataScope == '2'"
           v-loading="authLoading"
           style="height: 40vh"
-          wrap-style="overflow-x: hidden;">
+          wrap-style="overflow-x: hidden;"
+        >
           <el-tree
             ref="tree"
             :data="deptData"
@@ -72,7 +69,6 @@
           />
         </el-scrollbar>
       </el-form-item>
-
     </el-form>
     <template v-slot:footer>
       <el-button @click="updateVisible(false)">取消</el-button>
@@ -85,11 +81,8 @@
 
 <script>
   import { addRole, putRoles } from '@/api/system/role';
-  import {
-    listOrganizations,
-
-  } from '@/api/system/organization';
-  import {secretLevelList} from "@/enum/dict";
+  import { listOrganizations } from '@/api/system/organization';
+  import { secretLevelList } from '@/enum/dict';
   export default {
     props: {
       // 弹窗是否打开
@@ -98,7 +91,7 @@
       data: Object
     },
     created() {
-      this.getListOrganizations()
+      this.getListOrganizations();
     },
     data() {
       const defaultForm = {
@@ -107,7 +100,7 @@
         enable: 1,
         dataScope: '',
         dataScopeDeptIds: '',
-        secretLevel: 1,
+        secretLevel: 1,code:''
       };
       return {
         defaultForm,
@@ -141,10 +134,9 @@
     },
     methods: {
       secretLevelList() {
-        return secretLevelList
+        return secretLevelList;
       },
 
-
       query() {
         this.loading = true;
         listOrganizations()
@@ -155,30 +147,28 @@
               idField: 'id',
               parentIdField: 'parentId'
             });
-
           })
           .catch((e) => {
             this.loading = false;
-
           });
       },
-    getListOrganizations(){
-      this.authLoading = true;
-      listOrganizations()
-        .then((list) => {
-          let _list = list.filter((i) => i.name != '超级管理员')
-          this.authLoading = false;
-          this.deptData = this.$util.toTreeData({
-            data: _list,
-            idField: 'id',
-            parentIdField: 'parentId'
+      getListOrganizations() {
+        this.authLoading = true;
+        listOrganizations()
+          .then((list) => {
+            let _list = list.filter((i) => i.name != '超级管理员');
+            this.authLoading = false;
+            this.deptData = this.$util.toTreeData({
+              data: _list,
+              idField: 'id',
+              parentIdField: 'parentId'
+            });
+          })
+          .catch((e) => {
+            this.loading = false;
+            // this.$message.error(e.message);
           });
-        })
-        .catch((e) => {
-          this.loading = false;
-          // this.$message.error(e.message);
-        });
-    },
+      },
       /* 保存编辑 */
       save() {
         this.$refs.form.validate((valid) => {
@@ -186,8 +176,10 @@
             return false;
           }
           this.loading = true;
-          if(this.form.dataScope=='2'){
-            const ids = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
+          if (this.form.dataScope == '2') {
+            const ids = this.$refs.tree
+              .getCheckedKeys()
+              .concat(this.$refs.tree.getHalfCheckedKeys());
             this.form.dataScopeDeptIds = ids.join(',');
           }
           const saveOrUpdate = this.isUpdate ? putRoles : addRole;
@@ -212,18 +204,19 @@
     watch: {
       visible(visible) {
         if (visible) {
-          this.query()
+          this.query();
           if (this.data != null) {
             // this.$util.assignObject(this.form, this.data);
             // this.form = this.data;
             this.form = Object.assign(this.data);
-            this.form.dataScope = this.form.dataScope + ''
-            this.$nextTick(()=>{
-              if(this.form.dataScope=='2'){
-                this.$refs.tree.setCheckedKeys(this.form.dataScopeDeptIds.split(','))
+            this.form.dataScope = this.form.dataScope + '';
+            this.$nextTick(() => {
+              if (this.form.dataScope == '2') {
+                this.$refs.tree.setCheckedKeys(
+                  this.form.dataScopeDeptIds.split(',')
+                );
               }
-
-            })
+            });
             this.isUpdate = true;
           } else {
             this.isUpdate = false;

+ 210 - 214
src/views/system/role/index.vue

@@ -96,12 +96,7 @@
             v-if="$hasPermission('sys:role:delete')"
           >
             <template v-slot:reference>
-              <el-link
-                type="danger"
-           
-                :underline="false"
-                icon="el-icon-delete"
-              >
+              <el-link type="danger" :underline="false" icon="el-icon-delete">
                 删除
               </el-link>
             </template>
@@ -124,225 +119,226 @@
 </template>
 
 <script>
-import tabMixins from '@/mixins/tableColumnsMixin';
-import RoleSearch from './components/role-search.vue';
-import RoleEdit from './components/role-edit.vue';
-import RoleAuth from './components/role-auth.vue';
-import roleDataAuth from './components/role-data-auth.vue';
-import {
-  pageRoles,
-  removeRole,
-  removeRoles,
-  putRoles,
-  copyRole
-} from '@/api/system/role';
-import { secretLevelList } from '@/enum/dict';
+  import tabMixins from '@/mixins/tableColumnsMixin';
+  import RoleSearch from './components/role-search.vue';
+  import RoleEdit from './components/role-edit.vue';
+  import RoleAuth from './components/role-auth.vue';
+  import roleDataAuth from './components/role-data-auth.vue';
+  import {
+    pageRoles,
+    removeRole,
+    removeRoles,
+    putRoles,
+    copyRole
+  } from '@/api/system/role';
+  import { secretLevelList } from '@/enum/dict';
 
-export default {
-  name: 'SystemRole',
-  mixins: [tabMixins],
-  components: {
-    RoleSearch,
-    RoleEdit,
-    RoleAuth,
-    roleDataAuth
-  },
-  data() {
-    return {
-      // 表格列配置
-      columns: [
-        {
-          columnKey: 'selection',
-          type: 'selection',
-          width: 45,
-          align: 'center',
-          fixed: 'left'
-        },
-        {
-          columnKey: 'index',
-          label: '序号',
-          type: 'index',
-          width: 55,
-          align: 'center',
-          showOverflowTooltip: true,
-          fixed: 'left'
-        },
-        {
-          prop: 'name',
-          label: '角色名称',
-          align: 'center',
+  export default {
+    name: 'SystemRole',
+    mixins: [tabMixins],
+    components: {
+      RoleSearch,
+      RoleEdit,
+      RoleAuth,
+      roleDataAuth
+    },
+    data() {
+      return {
+        // 表格列配置
+        columns: [
+          {
+            columnKey: 'selection',
+            type: 'selection',
+            width: 45,
+            align: 'center',
+            fixed: 'left'
+          },
+          {
+            columnKey: 'index',
+            label: '序号',
+            type: 'index',
+            width: 55,
+            align: 'center',
+            showOverflowTooltip: true,
+            fixed: 'left'
+          },
+          {
+            width: 120,
+            align: 'center',
+            showOverflowTooltip: true,
+            prop: 'code',
+            label: '编码'
+          },
+          {
+            prop: 'name',
+            label: '角色名称',
+            align: 'center',
+
+            showOverflowTooltip: true,
+            minWidth: 110
+          },
 
-          showOverflowTooltip: true,
-          minWidth: 110
-        },
-        // {
-        //   prop: 'groupName',
-        //   label: '组织名称',
-        //   align: 'center',
-        //   showOverflowTooltip: true,
-        //   minWidth: 110
-        // },
-        {
-          prop: 'secretLevel',
-          label: '密级',
-          align: 'center',
-          showOverflowTooltip: true,
-          slot: 'secretLevel',
-          minWidth: 110
-        },
-        {
-          prop: 'enable',
-          label: '启用状态',
-          align: 'center',
+          {
+            prop: 'secretLevel',
+            label: '密级',
+            align: 'center',
+            showOverflowTooltip: true,
+            slot: 'secretLevel',
+            minWidth: 110
+          },
+          {
+            prop: 'enable',
+            label: '启用状态',
+            align: 'center',
 
-          showOverflowTooltip: true,
-          slot: 'enable',
+            showOverflowTooltip: true,
+            slot: 'enable',
 
-          minWidth: 110
-        },
-        {
-          prop: 'createTime',
-          label: '创建时间',
-          align: 'center',
+            minWidth: 110
+          },
+          {
+            prop: 'createTime',
+            label: '创建时间',
+            align: 'center',
 
-          showOverflowTooltip: true,
-          minWidth: 110,
-          formatter: (_row, _column, cellValue) => {
-            return this.$util.toDateString(cellValue);
+            showOverflowTooltip: true,
+            minWidth: 110,
+            formatter: (_row, _column, cellValue) => {
+              return this.$util.toDateString(cellValue);
+            }
+          },
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 380,
+            align: 'center',
+            resizable: false,
+            slot: 'action',
+            showOverflowTooltip: true
           }
-        },
-        {
-          columnKey: 'action',
-          label: '操作',
-          width: 380,
-          align: 'center',
-          resizable: false,
-          slot: 'action',
-          showOverflowTooltip: true
-        }
-      ],
-      // 表格选中数据
-      selection: [],
-      // 当前编辑数据
-      current: null,
-      // 是否显示编辑弹窗
-      showEdit: false,
-      // 是否显示导入弹窗
-      showAuth: false,
-      isUpdate: false,
-      roleDataAuthDialogFlag: false,
-      pageSize: this.$store.state.tablePageSize,
-      cacheKeyUrl: '477af4f1-system-role'
-    };
-  },
-  created() {},
-  methods: {
-    /* 表格数据源 */
-    datasource({ page, limit, where, order }) {
-      return pageRoles({ pageNum: page, size: limit, ...where });
-    },
-    async changeEnable(row) {
-      const res = await putRoles(row);
-      if (res.code == 0) {
-        this.$message({
-          type: 'success',
-          message: '修改成功',
-          customClass: 'ele-message-border'
-        });
-        this.reload();
-      }
-    },
-    /* 刷新表格 */
-    reload(where) {
-      this.$refs.table.reload({ page: 1, where });
+        ],
+        // 表格选中数据
+        selection: [],
+        // 当前编辑数据
+        current: null,
+        // 是否显示编辑弹窗
+        showEdit: false,
+        // 是否显示导入弹窗
+        showAuth: false,
+        isUpdate: false,
+        roleDataAuthDialogFlag: false,
+        pageSize: this.$store.state.tablePageSize,
+        cacheKeyUrl: '477af4f1-system-role'
+      };
     },
-    getSecretLevel(i) {
-      let find = secretLevelList.find((item) => item.value == i) || {};
-      return find.label;
-    },
-    /* 显示编辑 */
-    openEdit(row) {
-      if (row) {
-        this.current = Object.assign({}, row);
-      } else {
-        this.current = null;
-      }
-      this.showEdit = true;
-    },
-    /* 显示分配权限 */
-    openAuth(row) {
-      if (row) {
-        this.isUpdate = true;
-        this.current = Object.assign({}, row);
-      } else {
-        this.isUpdate = false;
-      }
+    created() {},
+    methods: {
+      /* 表格数据源 */
+      datasource({ page, limit, where, order }) {
+        return pageRoles({ pageNum: page, size: limit, ...where });
+      },
+      async changeEnable(row) {
+        const res = await putRoles(row);
+        if (res.code == 0) {
+          this.$message({
+            type: 'success',
+            message: '修改成功',
+            customClass: 'ele-message-border'
+          });
+          this.reload();
+        }
+      },
+      /* 刷新表格 */
+      reload(where) {
+        this.$refs.table.reload({ page: 1, where });
+      },
+      getSecretLevel(i) {
+        let find = secretLevelList.find((item) => item.value == i) || {};
+        return find.label;
+      },
+      /* 显示编辑 */
+      openEdit(row) {
+        if (row) {
+          this.current = Object.assign({}, row);
+        } else {
+          this.current = null;
+        }
+        this.showEdit = true;
+      },
+      /* 显示分配权限 */
+      openAuth(row) {
+        if (row) {
+          this.isUpdate = true;
+          this.current = Object.assign({}, row);
+        } else {
+          this.isUpdate = false;
+        }
 
-      this.showAuth = true;
-    },
-    /* 显示分配权限 */
-    openDataAuth(row) {
-      this.roleDataAuthDialogFlag = true;
+        this.showAuth = true;
+      },
+      /* 显示分配权限 */
+      openDataAuth(row) {
+        this.roleDataAuthDialogFlag = true;
 
-      this.$nextTick(() => {
-        this.$refs.roleDataAuthDialogRef.init({ ...row });
-      });
-    },
-    //复制
-    async copyRole(row) {
-      const loading = this.$loading({ lock: true });
-      copyRole(row.id)
-        .then((msg) => {
-          loading.close();
-          this.$message.success(msg);
-          this.reload();
-        })
-        .catch((e) => {
-          loading.close();
-          this.$message.error(e.message);
+        this.$nextTick(() => {
+          this.$refs.roleDataAuthDialogRef.init({ ...row });
         });
-    },
-    /* 删除 */
-    remove(row) {
-      const loading = this.$loading({ lock: true });
-      removeRole(row.id)
-        .then((msg) => {
-          loading.close();
-          this.$message.success(msg);
-          this.reload();
+      },
+      //复制
+      async copyRole(row) {
+        const loading = this.$loading({ lock: true });
+        copyRole(row.id)
+          .then((msg) => {
+            loading.close();
+            this.$message.success(msg);
+            this.reload();
+          })
+          .catch((e) => {
+            loading.close();
+            this.$message.error(e.message);
+          });
+      },
+      /* 删除 */
+      remove(row) {
+        const loading = this.$loading({ lock: true });
+        removeRole(row.id)
+          .then((msg) => {
+            loading.close();
+            this.$message.success(msg);
+            this.reload();
+          })
+          .catch((e) => {
+            loading.close();
+            this.$message.error(e.message);
+          });
+      },
+      /* 批量删除 */
+      removeBatch() {
+        if (!this.selection.length) {
+          this.$message.error('请至少选择一条数据');
+          return;
+        }
+        this.$confirm('确定要删除选中的角色吗?', '提示', {
+          type: 'warning'
         })
-        .catch((e) => {
-          loading.close();
-          this.$message.error(e.message);
-        });
-    },
-    /* 批量删除 */
-    removeBatch() {
-      if (!this.selection.length) {
-        this.$message.error('请至少选择一条数据');
-        return;
+          .then(() => {
+            const loading = this.$loading({ lock: true });
+            removeRole(
+              this.selection.map((d) => d.id),
+              true
+            )
+              .then((msg) => {
+                loading.close();
+                this.$message.success(msg);
+                this.reload();
+              })
+              .catch((e) => {
+                loading.close();
+                this.$message.error(e.message);
+              });
+          })
+          .catch(() => {});
       }
-      this.$confirm('确定要删除选中的角色吗?', '提示', {
-        type: 'warning'
-      })
-        .then(() => {
-          const loading = this.$loading({ lock: true });
-          removeRole(
-            this.selection.map((d) => d.id),
-            true
-          )
-            .then((msg) => {
-              loading.close();
-              this.$message.success(msg);
-              this.reload();
-            })
-            .catch((e) => {
-              loading.close();
-              this.$message.error(e.message);
-            });
-        })
-        .catch(() => {});
     }
-  }
-};
+  };
 </script>

+ 5 - 3
src/views/system/user/components/user-edit.vue

@@ -49,6 +49,7 @@
             />
           </el-form-item>
         </el-col>
+     
         <el-col :span="12">
           <el-form-item label="岗位:" prop="postName">
             <el-input
@@ -157,7 +158,8 @@
         enable: 1,
         groupRolePOList: [],
         jobNumber: '',
-        phone: ''
+        phone: '',
+        code:''
       };
       return {
         defaultForm,
@@ -191,7 +193,7 @@
         // 是否是修改
         isUpdate: false,
         userInfo: {
-          postName: ''
+          postName: '',
         }
       };
     },
@@ -242,7 +244,7 @@
       },
       /* 保存编辑 */
       save() {
-        console.log(this.form.groupRolePOList,'this.form.groupRolePOList')
+        console.log(this.form.groupRolePOList, 'this.form.groupRolePOList');
         this.$refs.form.validate((valid) => {
           let isRole = true;
           if (!valid) {

+ 1 - 0
src/views/system/user/index.vue

@@ -188,6 +188,7 @@
             fixed: 'left',
             label: '序号'
           },
+  
           {
             prop: 'loginName',
             label: '用户账号',