fix(projects): 修复角色用户分配未调用接口问题
This commit is contained in:
parent
312709706b
commit
ff87415d7b
@ -61,6 +61,7 @@ const local: App.I18n.Schema = {
|
||||
update: 'Update',
|
||||
saveSuccess: 'Save Success',
|
||||
updateSuccess: 'Update Success',
|
||||
noChange: 'No actions were taken',
|
||||
userCenter: 'User Center',
|
||||
yesOrNo: {
|
||||
yes: 'Yes',
|
||||
|
@ -61,6 +61,7 @@ const local: App.I18n.Schema = {
|
||||
update: '更新',
|
||||
saveSuccess: '保存成功',
|
||||
updateSuccess: '更新成功',
|
||||
noChange: '没有进行任何操作',
|
||||
userCenter: '个人中心',
|
||||
yesOrNo: {
|
||||
yes: '是',
|
||||
|
@ -78,3 +78,21 @@ export function fetchGetRoleUserList(params: Api.System.UserSearchParams) {
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
/** 批量选择用户授权 */
|
||||
export function fetchUpdateRoleAuthUser(roleId: CommonType.IdType, userIds: CommonType.IdType[]) {
|
||||
return request<boolean>({
|
||||
url: '/system/role/authUser/selectAll',
|
||||
method: 'put',
|
||||
params: { roleId, userIds: userIds.join(',') }
|
||||
});
|
||||
}
|
||||
|
||||
/** 批量取消用户授权 */
|
||||
export function fetchUpdateRoleAuthUserCancel(roleId: CommonType.IdType, userIds: CommonType.IdType[]) {
|
||||
return request<boolean>({
|
||||
url: '/system/role/authUser/cancelAll',
|
||||
method: 'put',
|
||||
params: { roleId, userIds: userIds.join(',') }
|
||||
});
|
||||
}
|
||||
|
1
src/typings/app.d.ts
vendored
1
src/typings/app.d.ts
vendored
@ -376,6 +376,7 @@ declare namespace App {
|
||||
update: string;
|
||||
updateSuccess: string;
|
||||
saveSuccess: string;
|
||||
noChange: string;
|
||||
userCenter: string;
|
||||
yesOrNo: {
|
||||
yes: string;
|
||||
|
@ -191,3 +191,13 @@ export function transformToURLSearchParams(obj: Record<string, any>, excludeKeys
|
||||
});
|
||||
return searchParams;
|
||||
}
|
||||
|
||||
/** 判断两个数组是否相等 */
|
||||
export function arraysEqualSet(arr1: Array<any>, arr2: Array<any>) {
|
||||
return (
|
||||
arr1.length === arr2.length &&
|
||||
new Set(arr1).size === arr1.length &&
|
||||
new Set(arr2).size === arr2.length &&
|
||||
[...arr1].sort().join() === [...arr2].sort().join()
|
||||
);
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
<script setup lang="tsx">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { NDatePicker } from 'naive-ui';
|
||||
import { fetchGetRoleUserList, fetchGetUserList } from '@/service/api/system';
|
||||
import {
|
||||
fetchGetRoleUserList,
|
||||
fetchGetUserList,
|
||||
fetchUpdateRoleAuthUser,
|
||||
fetchUpdateRoleAuthUserCancel
|
||||
} from '@/service/api/system';
|
||||
import { useAppStore } from '@/store/modules/app';
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
import { useTable, useTableOperate } from '@/hooks/common/table';
|
||||
import { arraysEqualSet } from '@/utils/common';
|
||||
import { $t } from '@/locales';
|
||||
import DictTag from '@/components/custom/dict-tag.vue';
|
||||
|
||||
@ -110,13 +116,16 @@ const { columns, data, getData, getDataByPage, loading, mobilePagination, search
|
||||
|
||||
const { checkedRowKeys } = useTableOperate(data, getData);
|
||||
|
||||
const checkedUserIds = ref<CommonType.IdType[]>([]);
|
||||
|
||||
async function handleUpdateModelWhenEdit() {
|
||||
checkedRowKeys.value = [];
|
||||
getDataByPage();
|
||||
const { data: roleUserList } = await fetchGetRoleUserList({
|
||||
roleId: props.rowData?.roleId
|
||||
});
|
||||
checkedRowKeys.value = roleUserList?.rows.map(item => item.userId) || [];
|
||||
checkedUserIds.value = roleUserList?.rows.map(item => item.userId) || [];
|
||||
checkedRowKeys.value = checkedUserIds.value;
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
@ -124,6 +133,25 @@ function closeDrawer() {
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (arraysEqualSet(checkedUserIds.value, checkedRowKeys.value)) {
|
||||
window.$message?.warning($t('common.noChange'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 批量取消用户授权
|
||||
const cancelUserIds = checkedUserIds.value.filter(item => !checkedRowKeys.value.includes(item));
|
||||
if (cancelUserIds.length > 0) {
|
||||
const { error: cancelError } = await fetchUpdateRoleAuthUserCancel(props.rowData!.roleId, cancelUserIds);
|
||||
if (cancelError) return;
|
||||
}
|
||||
|
||||
// 批量选择用户授权
|
||||
const addUserIds = checkedRowKeys.value.filter(item => !checkedUserIds.value.includes(item));
|
||||
if (addUserIds.length > 0) {
|
||||
const { error: addError } = await fetchUpdateRoleAuthUser(props.rowData!.roleId, addUserIds);
|
||||
if (addError) return;
|
||||
}
|
||||
|
||||
window.$message?.success($t('common.updateSuccess'));
|
||||
closeDrawer();
|
||||
emit('submitted');
|
||||
|
Loading…
Reference in New Issue
Block a user