Skip to content

Commit

Permalink
feat: add data scope dialog for role management and enhance departmen…
Browse files Browse the repository at this point in the history
…t tree retrieval by role ID
  • Loading branch information
xorsheng committed Jan 1, 2025
1 parent 9de2162 commit 3cbb8cc
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 24 deletions.
18 changes: 18 additions & 0 deletions src/api/system/dept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export function getDeptDetail(params?: string) {
);
}

export function getDeptTreeByRoleId(params: string) {
return request.get<
{
checkedKeys: string[];
depts: components['schemas']['TreeLong'][];
},
null,
true
>(
{
url: urlTypeHelper('/system/role/deptTree/{roleId}', { roleId: params ?? '' }),
},
{
isTransformResponse: true,
},
);
}

export function addDept(params: components['schemas']['SysDeptBo']) {
return request.post<null, null, true>(
{
Expand Down
161 changes: 161 additions & 0 deletions src/pages/system/role/components/DialogDataScope.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<template>
<t-dialog
v-model:visible="formVisible"
:header="dialogTitle"
:width="680"
:footer="false"
destroy-on-close
@opened="handleDialogOpened"
>
<template #body>
<t-form ref="form" :data="formData" :rules="RULES" :label-width="120" label-align="right" @submit="onSubmit">
<!-- 角色名称 -->
<t-form-item label="角色名称" name="roleName">
<t-input v-model="formData.roleName" :readonly="true" clearable placeholder="请输入角色名称" />
</t-form-item>
<!-- 角色权限字符串 -->
<t-form-item label="角色权限字符" name="roleKey">
<t-input v-model="formData.roleKey" :readonly="true" clearable placeholder="请输入角色权限字符" />
</t-form-item>
<!-- 数据范围 -->
<t-form-item label="数据范围" name="dataScope">
<t-select v-model="formData.dataScope">
<t-option value="1" label="全部数据权限">全部数据权限</t-option>
<t-option value="2" label="自定数据权限">自定数据权限</t-option>
<t-option value="3" label="本部门数据权限">本部门数据权限</t-option>
<t-option value="4" label="本部门及以下数据权限">本部门及以下数据权限</t-option>
</t-select>
</t-form-item>

<t-form-item v-if="formData.dataScope === '2'" label="菜单权限">
<t-space direction="vertical">
<t-space>
<t-checkbox v-model="expandAll" @change="handleExpandAll">展开/折叠</t-checkbox>
<t-checkbox v-model="checkedAll" @click="handleCheckAll">全选/全不选</t-checkbox>
<t-checkbox v-model="formData.menuCheckStrictly">父子联动</t-checkbox>
</t-space>
<t-tree
ref="tree"
v-model="allCheckedKeys"
v-model:expanded="allExpandedKeys"
:data="deptTree"
:keys="{
label: 'label',
value: 'id',
}"
checkable
:check-strictly="!formData.menuCheckStrictly"
:value-mode="valueMode"
hover
/>
</t-space>
</t-form-item>

<t-form-item style="float: right">
<t-button variant="outline" @click="onClickCloseBtn">取消</t-button>
<t-button theme="primary" type="submit">确定</t-button>
</t-form-item>
</t-form>
</template>
</t-dialog>
</template>

<script setup lang="ts">
import { CheckboxProps, MessagePlugin, SubmitContext, TreeInstanceFunctions, TreeProps } from 'tdesign-vue-next';
import { computed, ref, watch } from 'vue';
import { getDeptTreeByRoleId } from '@/api/system/dept';
import { getRoleDetail } from '@/api/system/role';
import { components } from '@/types/schema';
import { INITIAL_DATA, RULES } from '../constants';
interface Props {
data: typeof INITIAL_DATA;
visible: boolean;
}
const props = withDefaults(defineProps<Props>(), {
data: undefined,
visible: false,
});
const emit = defineEmits(['update:visible', 'submit']);
const formVisible = ref(false);
const formData = ref({ ...INITIAL_DATA });
const deptTree = ref<components['schemas']['TreeLong'][]>();
const tree = ref<TreeInstanceFunctions>();
const valueMode = ref<TreeProps['valueMode']>('all');
const allCheckedKeys = ref([]);
const allExpandedKeys = ref<TreeProps['expanded']>([]);
const expandAll = ref(false);
const checkedAll = ref(false);
const handleExpandAll: CheckboxProps['onChange'] = (checked) => {
if (checked) {
allExpandedKeys.value = deptTree.value.map((i) => i.id);
} else {
allExpandedKeys.value = [];
}
};
const handleCheckAll: CheckboxProps['onChange'] = (checked) => {
if (checked) {
allCheckedKeys.value = tree.value.getItems().map((i) => i.value);
} else {
allCheckedKeys.value = [];
}
};
const dialogTitle = computed(() => {
return '数据权限';
});
const onSubmit = async ({ validateResult, firstError }: SubmitContext) => {
if (!firstError) {
formData.value.deptIds = allCheckedKeys.value;
emit('submit');
MessagePlugin.success('提交成功');
formVisible.value = false;
} else {
console.log('Errors: ', validateResult);
MessagePlugin.warning(firstError);
}
};
const onClickCloseBtn = () => {
formVisible.value = false;
formData.value = { ...INITIAL_DATA };
};
const handleDialogOpened = async () => {
if (props.data.roleId) {
const result = await getRoleDetail(props.data.roleId as unknown as string);
formData.value = { ...INITIAL_DATA, ...result };
}
const result = await getDeptTreeByRoleId(props.data.roleId as unknown as string);
allCheckedKeys.value = result.checkedKeys;
deptTree.value = result.depts;
};
watch(
() => formVisible.value,
(val) => {
emit('update:visible', val);
},
);
watch(
() => props.visible,
(val) => {
formVisible.value = val;
},
);
watch(
() => props.data,
(val) => {
formData.value = val;
},
);
</script>
28 changes: 7 additions & 21 deletions src/pages/system/role/components/DialogUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
>
<template #body>
<t-card :bordered="false">
<advance-search :fields="fields" :col-props="{ md: 6 }" @submit="handleFormSubmit" @reset="handleFormReset" />
<advance-search
:fields="fields"
:col-props="{ xs: 6, sm: 6, md: 6 }"
@submit="handleFormSubmit"
@reset="handleFormReset"
/>
</t-card>
<t-card :bordered="false">
<t-table
Expand Down Expand Up @@ -72,28 +77,9 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits(['update:visible', 'submit']);
const fields = [
// { label: '创建部门', name: 'createDept', type: 'input' },
// { label: '创建者', name: 'createBy', type: 'input' },
// { label: '创建时间', name: 'createTime', type: 'input' },
// { label: '更新者', name: 'updateBy', type: 'input' },
// { label: '更新时间', name: 'updateTime', type: 'input' },
// { label: '请求参数', name: 'params', type: 'input' },
// { label: '用户ID', name: 'userId', type: 'input' },
// { label: '部门ID', name: 'deptId', type: 'input' },
{ label: '用户账号', name: 'userName', type: 'input' },
{ label: '用户昵称', name: 'nickName', type: 'input' },
// { label: '用户类型(sys_user系统用户)', name: 'userType', type: 'input' },
// { label: '用户邮箱', name: 'email', type: 'input' },
{ label: '手机号码', name: 'phonenumber', type: 'input' },
// { label: '用户性别', name: 'sex', type: 'input' },
// { label: '密码', name: 'password', type: 'input' },
// { label: '帐号状态', name: 'status', type: 'input' },
// { label: '备注', name: 'remark', type: 'input' },
// { label: '角色组', name: 'roleIds', type: 'input' },
// { label: '岗位组', name: 'postIds', type: 'input' },
// { label: '数据权限 当前角色ID', name: 'roleId', type: 'input' },
// { label: '排除不查询的用户(工作流用)', name: 'excludeUserIds', type: 'input' },
// { label: '超级管理员', name: 'superAdmin', type: 'input' },
];
const searchData = ref<components['schemas']['SysUserBo']>({
userName: undefined,
Expand Down Expand Up @@ -188,7 +174,7 @@ watch(
watch(
() => props.roleId,
(val) => {
searchData.value.roleId = val;
searchData.value.roleId = val as unknown as number;
},
);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/system/role/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ export const COLUMNS: PrimaryTableCol<TableRowData>[] = [
{ title: '角色名称', colKey: 'roleName' },
{ title: '角色权限字符串', colKey: 'roleKey' },
{ title: '显示顺序', colKey: 'roleSort' },
// (1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
{
title: '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)',
title: '数据范围',
colKey: 'dataScope',
},
{ title: '菜单树选择项是否关联显示', colKey: 'menuCheckStrictly' },
{ title: '部门树选择项是否关联显示', colKey: 'deptCheckStrictly' },
{ title: '角色状态', colKey: 'status' },
{ title: '备注', colKey: 'remark' },
{ title: '创建时间', colKey: 'createTime' },
{ title: '用户是否存在此角色标识 默认不存在', colKey: 'flag' },
{ title: '用户是否存在此角色标识', colKey: 'flag' },
{ title: '超级管理员', colKey: 'superAdmin' },
{
title: '操作',
align: 'left',
fixed: 'right',
width: 220,
width: 320,
colKey: 'op',
},
];
Expand Down
16 changes: 16 additions & 0 deletions src/pages/system/role/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
</t-table>
</t-card>

<dialog-data-scope v-model:visible="dataScopeDialogVisible" :data="formData" @submit="handleDialogSubmit" />

<t-dialog
v-model:visible="confirmVisible"
header="确认删除当前所选项?"
Expand Down Expand Up @@ -86,6 +88,7 @@ import { prefix } from '@/config/global';
import { useSettingStore } from '@/store';
import { components } from '@/types/schema';
import DialogDataScope from './components/DialogDataScope.vue';
import DialogForm from './components/DialogForm.vue';
import { COLUMNS, COLUMNS_CONTROLLER_CONFIG, INIT_PAGE, INITIAL_DATA, ROW_KEY } from './constants';
Expand Down Expand Up @@ -134,6 +137,7 @@ const handleFormReset = (data: components['schemas']['SysRoleBo']) => {
};
const formDialogVisible = ref(false);
const dataScopeDialogVisible = ref(false);
const formData = ref({ ...INITIAL_DATA });
const staticColumn = ['row-select', 'status', 'op'];
const displayColumns = ref<TableProps['displayColumns']>(
Expand Down Expand Up @@ -223,6 +227,13 @@ const ops: Action<LinkProps>[] = [
},
handler: (slotProps) => handleClickEdit(slotProps),
},
{
label: '数据权限',
props: {
theme: 'primary',
},
handler: (slotProps) => handleClickDataScope(slotProps),
},
{
label: '授权用户',
props: {
Expand Down Expand Up @@ -302,6 +313,11 @@ const handleClickEdit = (row: { row: components['schemas']['SysRoleVo'] }) => {
formDialogVisible.value = true;
};
const handleClickDataScope = (row: { row: components['schemas']['SysRoleVo'] }) => {
formData.value = { ...INITIAL_DATA, ...row.row };
dataScopeDialogVisible.value = true;
};
const handleClickUser = (row: { row: components['schemas']['SysRoleVo'] }) => {
const { roleId } = row.row;
router.push({
Expand Down

0 comments on commit 3cbb8cc

Please sign in to comment.