|
@@ -1,255 +1,130 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <el-card class="box-card" v-loading="state.loading" element-loading-text="Loading...">
|
|
|
- <template #header>
|
|
|
- <div class="card-header">
|
|
|
- <span>权限管理</span>
|
|
|
- <div>
|
|
|
- <el-button type="default" @click="reFlush()">刷新列表</el-button>
|
|
|
- <el-button type="primary" @click="onOpenAddDept('add')">新增权限</el-button>
|
|
|
- <el-button type="danger" @click="del()">批量删除</el-button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
-
|
|
|
- <el-table ref="multipleTableRef" :data="state.tableData" style="width: 100%" @selection-change="handleSelectionChange">
|
|
|
- <el-table-column type="selection" width="55" />
|
|
|
- <el-table-column type="index" label="序号" width="90" />
|
|
|
- <el-table-column property="name" label="权限名称" />
|
|
|
-
|
|
|
- <el-table-column property="codes_cn" label="权限">
|
|
|
- <template #default="scope">
|
|
|
- <div v-if="scope.row.codes_cn">
|
|
|
- <span v-if="scope.row.codes_cn.length>1">{{scope.row.codes_cn[0]}},{{scope.row.codes_cn[1]}},等{{scope.row.codes_cn.length}}项权限</span>
|
|
|
- <span v-else v-for="(item,index) in scope.row.codes_cn" :key="index">
|
|
|
- <span>{{item}}</span>
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
-
|
|
|
- <!-- <el-table-column property="company.personnel_size" label="人数" width="90" /> -->
|
|
|
- <el-table-column property="update_time" label="最后修改时间" width="240" />
|
|
|
-
|
|
|
- <el-table-column property="valid" label="状态" width="90">
|
|
|
- <template #default="scope">
|
|
|
- <el-button link type="danger" size="default" v-if="scope.row.valid == 0">禁用</el-button>
|
|
|
- <el-button link type="primary" size="default" v-if="scope.row.valid == 1">启用</el-button>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
-
|
|
|
- <el-table-column property="remark" label="备注" />
|
|
|
-
|
|
|
- <el-table-column fixed="right" label="操作" width="120">
|
|
|
- <template #default="scope">
|
|
|
- <div class="disflex">
|
|
|
- <el-button link type="primary" size="small" @click="onOpenEditDept('edit',scope.row)">编辑</el-button>
|
|
|
- <el-button link type="danger" size="small" @click="handleClick_del(scope.row)">删除</el-button>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
-
|
|
|
- <el-pagination
|
|
|
- @size-change="onHandleSizeChange"
|
|
|
- @current-change="onHandleCurrentChange"
|
|
|
- class="mt15"
|
|
|
- :pager-count="5"
|
|
|
- :page-sizes="[10, 20, 30]"
|
|
|
- v-model:current-page="state.param.page"
|
|
|
- background
|
|
|
- v-model:page-size="state.param.list_rows"
|
|
|
- layout="total, sizes, prev, pager, next, jumper"
|
|
|
- :total="state.total"
|
|
|
- >
|
|
|
- </el-pagination>
|
|
|
+ <el-card class="box-card" v-loading="wholeLoading" element-loading-text="Loading..." style="height: 600px">
|
|
|
+ <template #header>
|
|
|
+ <div class="card-header">
|
|
|
+ <span>权限管理</span>
|
|
|
+ <div>
|
|
|
+ <el-button type="default" @click="reflush()">刷新列表</el-button>
|
|
|
+ <el-button type="primary" @click="create()">新增权限</el-button>
|
|
|
+ <el-button type="danger" @click="remove()">批量删除</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <el-auto-resizer>
|
|
|
+ <template #default="{ height, width }">
|
|
|
+ <el-table-v2 :data="data" :columns="columns" :width="width" :height="600" fixed />
|
|
|
+ </template>
|
|
|
+ </el-auto-resizer>
|
|
|
</el-card>
|
|
|
- <DeptDialog ref="deptDialogRef" @refresh="getTableData()" />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup name="underlyingRoleManage">
|
|
|
- import { ref, reactive, onMounted, defineAsyncComponent } from 'vue';
|
|
|
- import { ElTable, ElMessage, ElMessageBox } from 'element-plus';
|
|
|
- import Role from '/@/api/role/role.ts';
|
|
|
- import ruleReg from '/@/utils/ruleReg';
|
|
|
+import { ref, reactive, onMounted, h } from 'vue';
|
|
|
+import { ElSwitch, ElTag, ElMessage, ElMessageBox, ElButton, TableV2FixedDir } from 'element-plus';
|
|
|
+import type { Column, RowClassNameGetter } from 'element-plus';
|
|
|
+import _ from 'lodash';
|
|
|
+import { init, update } from '/@/api/role';
|
|
|
|
|
|
- const DeptDialog = defineAsyncComponent(() => import('/@/views/underlying/roleManage/edit.vue'));
|
|
|
- const deptDialogRef = ref();
|
|
|
- // 打开新增菜单弹窗
|
|
|
- const onOpenAddDept = (type: string) => {
|
|
|
- deptDialogRef.value.openDialog(type);
|
|
|
- };
|
|
|
- // 打开编辑菜单弹窗
|
|
|
- const onOpenEditDept = (type: string, row: any) => {
|
|
|
- row = JSON.parse(JSON.stringify(row));
|
|
|
- console.log('row',row);
|
|
|
- deptDialogRef.value.openDialog(type, row);
|
|
|
- };
|
|
|
+/**
|
|
|
+ * 表格数据
|
|
|
+ */
|
|
|
+const data = await init();
|
|
|
+/**
|
|
|
+ * 整个页面的loading
|
|
|
+ */
|
|
|
+const wholeLoading = ref(false);
|
|
|
+/**
|
|
|
+ * 编辑权限表单的显示控制
|
|
|
+ */
|
|
|
+const showCodesEditForm = ref(false);
|
|
|
|
|
|
- interface User {
|
|
|
- id: number
|
|
|
- name: string
|
|
|
- gender: number
|
|
|
- img_url: string
|
|
|
- company_id: number
|
|
|
- department_id: number
|
|
|
- id_card: string
|
|
|
- age: number
|
|
|
- phone: string
|
|
|
- password: string
|
|
|
- role_id: number
|
|
|
- is_root: number
|
|
|
- valid: number
|
|
|
- create_time: string
|
|
|
- update_time: string
|
|
|
- is_pass: number
|
|
|
- pass_time: string
|
|
|
- remark: string
|
|
|
- }
|
|
|
- const multipleTableRef = ref<InstanceType<typeof ElTable>>()
|
|
|
- const multipleSelection = ref<User[]>([])
|
|
|
- const toggleSelection = (rows?: User[]) => {
|
|
|
- if (rows) {
|
|
|
- rows.forEach((row) => {
|
|
|
- // TODO: improvement typing when refactor table
|
|
|
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
- // @ts-expect-error
|
|
|
- multipleTableRef.value!.toggleRowSelection(row, undefined)
|
|
|
- })
|
|
|
- } else {
|
|
|
- multipleTableRef.value!.clearSelection()
|
|
|
- }
|
|
|
- }
|
|
|
- const handleSelectionChange = (val: User[]) => {
|
|
|
- multipleSelection.value = val;
|
|
|
- console.log('multipleSelection',multipleSelection.value);
|
|
|
- }
|
|
|
- const handleCommand = (command: string | number | object) => {
|
|
|
- console.log('command',command);
|
|
|
- }
|
|
|
- const handleClick_edit = () => {
|
|
|
- ElMessage(`click on 编辑`);
|
|
|
- }
|
|
|
- const handleClick_del = (row: any) => {
|
|
|
- row = JSON.parse(JSON.stringify(row));
|
|
|
- console.log('row',row);
|
|
|
- ElMessageBox.confirm(`此操作将永久删除角色:“${row.name}”,是否继续?`, '提示', {
|
|
|
- confirmButtonText: '确认',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- delOnce(row.id);
|
|
|
- // getTableData();
|
|
|
- // ElMessage.success('删除成功');
|
|
|
- })
|
|
|
- .catch(() => {});
|
|
|
- }
|
|
|
- const del = () => {
|
|
|
- console.log('multipleSelection.value',multipleSelection.value.length);
|
|
|
- if(multipleSelection.value.length==0){
|
|
|
- return ElMessage.warning("请选择要操作的列表");
|
|
|
- }
|
|
|
- let name = [];
|
|
|
- state.ids = [];
|
|
|
- for(let i=0;i<multipleSelection.value.length;i++){
|
|
|
- name.push(multipleSelection.value[i].name);
|
|
|
- state.ids.push(multipleSelection.value[i].id);
|
|
|
- }
|
|
|
- ElMessageBox.confirm(`此操作将永久删除角色:“${name}”,是否继续?`, '提示', {
|
|
|
- confirmButtonText: '确认',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- console.log('ids',JSON.stringify(state.ids).split('[')[1].split(']')[0]);
|
|
|
- delOnce(JSON.stringify(state.ids).split('[')[1].split(']')[0]);
|
|
|
- // getTableData();
|
|
|
- // ElMessage.success('删除成功');
|
|
|
- })
|
|
|
- .catch(() => {});
|
|
|
- }
|
|
|
- const delOnce = async(ids: number | string) => {
|
|
|
- let res = await Role.del(ids);
|
|
|
- if(res.code != 0){
|
|
|
- return ElMessage.error(res.msg);
|
|
|
- }
|
|
|
- getTableData();
|
|
|
- ElMessage.success(res.msg);
|
|
|
- }
|
|
|
+/**
|
|
|
+ * 虚拟表格列信息
|
|
|
+ */
|
|
|
+const columns: Column<any>[] = [
|
|
|
+ {
|
|
|
+ key: 'name',
|
|
|
+ title: '角色名',
|
|
|
+ dataKey: 'name',
|
|
|
+ width: 150,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'codes_cn',
|
|
|
+ title: '权限值',
|
|
|
+ dataKey: 'codes_cn',
|
|
|
+ width: 400,
|
|
|
+ cellRenderer: ({ cellData: codes_cn }) => h('div', codes_cn?.join(',')),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'remark',
|
|
|
+ title: '备注',
|
|
|
+ dataKey: 'remark',
|
|
|
+ width: 300,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'valid',
|
|
|
+ title: '是否启用',
|
|
|
+ dataKey: 'valid',
|
|
|
+ width: 100,
|
|
|
+ cellRenderer: ({ cellData: valid }) => h(ElTag, valid ? '启用' : '禁用'),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'op',
|
|
|
+ title: '操作',
|
|
|
+ width: 400,
|
|
|
+ fixed: TableV2FixedDir.RIGHT,
|
|
|
+ flexGrow: 1,
|
|
|
+ cellRenderer: ({ rowData: row }) =>
|
|
|
+ h('div', [
|
|
|
+ // 启用禁用
|
|
|
+ h(
|
|
|
+ ElButton,
|
|
|
+ {
|
|
|
+ type: row.valid ? 'danger' : 'success',
|
|
|
+ onClick: _.throttle(() => {
|
|
|
+ row.valid = !row.valid;
|
|
|
+ update(row);
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ row.valid ? '禁用' : '启用'
|
|
|
+ ),
|
|
|
+ // 打开权限表单
|
|
|
+ h(
|
|
|
+ ElButton,
|
|
|
+ {
|
|
|
+ type: 'primary',
|
|
|
+ onClick: _.throttle(() => (showCodesEditForm.value = true)),
|
|
|
+ },
|
|
|
+ '权限'
|
|
|
+ ),
|
|
|
+ ]),
|
|
|
+ },
|
|
|
+];
|
|
|
|
|
|
- const state = reactive({
|
|
|
- tableData: [],
|
|
|
- total: 0,
|
|
|
- loading: false,
|
|
|
- param: {
|
|
|
- keyword: '',
|
|
|
- page: 1,
|
|
|
- list_rows: 10,
|
|
|
- },
|
|
|
- ids: [],
|
|
|
- });
|
|
|
- const getList = async() => {
|
|
|
- let res = await Role.list(state.param);
|
|
|
- if(res.code != 0){
|
|
|
- return ElMessage.error(res.msg);
|
|
|
- }
|
|
|
- res.data.data.forEach((item:any)=>{
|
|
|
- // console.log('item.codes_cn1',item.codes_cn);
|
|
|
- // console.log('item.codes1',item.codes);
|
|
|
- // console.log('item.code1',item.code);
|
|
|
- if(!ruleReg.emptyReg(item.codes_cn)){
|
|
|
- item.codes_cn = [];
|
|
|
- item.codes = [];
|
|
|
- item.code = [];
|
|
|
- }else{
|
|
|
- item.codes_cn = (item.codes_cn || '').split(',');
|
|
|
- item.codes = (item.codes || '').split(',');
|
|
|
- item.code = (item.code || '').split(',');
|
|
|
- }
|
|
|
- // console.log('item.codes_cn2',item.codes_cn.length);
|
|
|
- // console.log('item.codes2',item.codes.length);
|
|
|
- // console.log('item.code2',item.code.length);
|
|
|
- });
|
|
|
- state.tableData = res.data.data;
|
|
|
- state.total = res.data.total;
|
|
|
- }
|
|
|
- const reFlush = () => {
|
|
|
- getTableData();
|
|
|
- state.loading = true;
|
|
|
- setTimeout(() => {
|
|
|
- state.loading = false;
|
|
|
- ElMessage.success("刷新列表成功");
|
|
|
- }, 500);
|
|
|
- }
|
|
|
- // 初始化表格数据
|
|
|
- const getTableData = () => {
|
|
|
- getList();
|
|
|
- };
|
|
|
- // 分页改变
|
|
|
- const onHandleSizeChange = (val: number) => {
|
|
|
- state.param.list_rows = val;
|
|
|
- getTableData();
|
|
|
- };
|
|
|
- // 分页改变
|
|
|
- const onHandleCurrentChange = (val: number) => {
|
|
|
- state.param.page = val;
|
|
|
- getTableData();
|
|
|
- };
|
|
|
- // 页面加载时
|
|
|
- onMounted(() => {
|
|
|
- getTableData();
|
|
|
- });
|
|
|
+/**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+const remove = () => {};
|
|
|
+/**
|
|
|
+ * 创建
|
|
|
+ */
|
|
|
+const create = () => {};
|
|
|
+/**
|
|
|
+ * 刷新
|
|
|
+ */
|
|
|
+const reflush = () => {};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
- .box-card {
|
|
|
- margin: 10px;
|
|
|
- }
|
|
|
- .card-header {
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- align-items: center;
|
|
|
- }
|
|
|
+.box-card {
|
|
|
+ margin: 10px;
|
|
|
+}
|
|
|
+.card-header {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ overflow-x: auto;
|
|
|
+}
|
|
|
</style>
|