- 修正角色选项展示字段,从 name 改为 roleName - 调整列表底部自适应偏移量为 120 - 性别字段由 sex 修改为 gender,更新展示和标签逻辑 - 角色分配功能改为异步操作,调用 assignUserRoles 接口分配角色 - 弹窗数据改为异步获取完整角色列表,提升准确性 - 增加操作成功与失败的消息提示 - 角色相关类型定义优化,角色列表类型改为 SysRole,选中角色类型改为 number[]
This commit is contained in:
@@ -41,9 +41,9 @@ const newFormInline = ref(props.formInline);
|
|||||||
v-for="(item, index) in newFormInline.roleOptions"
|
v-for="(item, index) in newFormInline.roleOptions"
|
||||||
:key="index"
|
:key="index"
|
||||||
:value="item.id"
|
:value="item.id"
|
||||||
:label="item.name"
|
:label="item.roleName"
|
||||||
>
|
>
|
||||||
{{ item.name }}
|
{{ item.roleName }}
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ const {
|
|||||||
ref="tableRef"
|
ref="tableRef"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
adaptive
|
adaptive
|
||||||
:adaptiveConfig="{ offsetBottom: 108 }"
|
:adaptiveConfig="{ offsetBottom: 10 }"
|
||||||
align-whole="center"
|
align-whole="center"
|
||||||
table-layout="auto"
|
table-layout="auto"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ import {
|
|||||||
hideTextAtIndex,
|
hideTextAtIndex,
|
||||||
deviceDetection
|
deviceDetection
|
||||||
} from "@pureadmin/utils";
|
} from "@pureadmin/utils";
|
||||||
import { getUserRoleIds, getUserList, getAllRoleList } from "@/api/system";
|
import {
|
||||||
|
getUserRoleIds,
|
||||||
|
getUserList,
|
||||||
|
getAllRoleList,
|
||||||
|
assignUserRoles
|
||||||
|
} from "@/api/system";
|
||||||
import { syncFeishuUsers } from "@/api/feishu";
|
import { syncFeishuUsers } from "@/api/feishu";
|
||||||
import {
|
import {
|
||||||
ElForm,
|
ElForm,
|
||||||
@@ -86,15 +91,15 @@ export function useUser(tableRef: Ref) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "性别",
|
label: "性别",
|
||||||
prop: "sex",
|
prop: "gender",
|
||||||
minWidth: 90,
|
minWidth: 90,
|
||||||
cellRenderer: ({ row, props }) => (
|
cellRenderer: ({ row, props }) => (
|
||||||
<el-tag
|
<el-tag
|
||||||
size={props.size}
|
size={props.size}
|
||||||
type={row.sex === 1 ? "danger" : null}
|
type={row.gender === 2 ? "danger" : null}
|
||||||
effect="plain"
|
effect="plain"
|
||||||
>
|
>
|
||||||
{row.sex === 1 ? "女" : "男"}
|
{row.gender === 1 ? "男" : "女"}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -429,7 +434,10 @@ export function useUser(tableRef: Ref) {
|
|||||||
|
|
||||||
/** 分配角色 */
|
/** 分配角色 */
|
||||||
async function handleRole(row) {
|
async function handleRole(row) {
|
||||||
// 选中的角色列表
|
// 获取所有角色列表
|
||||||
|
const rolesRes = await getAllRoleList();
|
||||||
|
const roleList = rolesRes.data ?? [];
|
||||||
|
// 获取用户当前的角色列表
|
||||||
const ids = (await getUserRoleIds(row.id)).data ?? [];
|
const ids = (await getUserRoleIds(row.id)).data ?? [];
|
||||||
addDialog({
|
addDialog({
|
||||||
title: `分配 ${row.username} 用户的角色`,
|
title: `分配 ${row.username} 用户的角色`,
|
||||||
@@ -437,7 +445,7 @@ export function useUser(tableRef: Ref) {
|
|||||||
formInline: {
|
formInline: {
|
||||||
username: row?.username ?? "",
|
username: row?.username ?? "",
|
||||||
nickname: row?.nickname ?? "",
|
nickname: row?.nickname ?? "",
|
||||||
roleOptions: roleOptions.value ?? [],
|
roleOptions: roleList,
|
||||||
ids
|
ids
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -447,12 +455,18 @@ export function useUser(tableRef: Ref) {
|
|||||||
fullscreenIcon: true,
|
fullscreenIcon: true,
|
||||||
closeOnClickModal: false,
|
closeOnClickModal: false,
|
||||||
contentRenderer: () => h(roleForm),
|
contentRenderer: () => h(roleForm),
|
||||||
beforeSure: (done, { options }) => {
|
beforeSure: async (done, { options }) => {
|
||||||
const curData = options.props.formInline as RoleFormItemProps;
|
const curData = options.props.formInline as RoleFormItemProps;
|
||||||
console.log("curIds", curData.ids);
|
try {
|
||||||
// 根据实际业务使用curData.ids和row里的某些字段去调用修改角色接口即可
|
const { code } = await assignUserRoles(row.id, curData.ids);
|
||||||
|
if (code === 200) {
|
||||||
|
message(`已成功为 ${row.username} 分配角色`, { type: "success" });
|
||||||
done(); // 关闭弹框
|
done(); // 关闭弹框
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
message("分配角色失败", { type: "error" });
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { SysRole } from "@/api/system";
|
||||||
|
|
||||||
interface FormItemProps {
|
interface FormItemProps {
|
||||||
id?: number;
|
id?: number;
|
||||||
/** 用于判断是`新增`还是`修改` */
|
/** 用于判断是`新增`还是`修改` */
|
||||||
@@ -25,9 +27,9 @@ interface RoleFormItemProps {
|
|||||||
username: string;
|
username: string;
|
||||||
nickname: string;
|
nickname: string;
|
||||||
/** 角色列表 */
|
/** 角色列表 */
|
||||||
roleOptions: any[];
|
roleOptions: SysRole[];
|
||||||
/** 选中的角色列表 */
|
/** 选中的角色列表 */
|
||||||
ids: Record<number, unknown>[];
|
ids: number[];
|
||||||
}
|
}
|
||||||
interface RoleFormProps {
|
interface RoleFormProps {
|
||||||
formInline: RoleFormItemProps;
|
formInline: RoleFormItemProps;
|
||||||
|
|||||||
Reference in New Issue
Block a user