refactor event

This commit is contained in:
Timi
2026-08-06 20:53:22 +08:00
parent 1243068fc3
commit 9df6dfaf59
37 changed files with 1584 additions and 2316 deletions
+14 -5
View File
@@ -48,6 +48,9 @@ defineOptions({
const route = useRoute();
const router = useRouter();
const permissionStore = usePermissionSettingsStore();
// ---------- 路由权限 ----------
const routeId = computed(() => String(route.params.id || ""));
const isCreateMode = computed(() => !routeId.value);
const savePermissionCode = computed(() => isCreateMode.value ? corePermissionCodes.role.create : corePermissionCodes.role.update);
@@ -55,6 +58,9 @@ const pageAccess = computed(() => ({
value: [corePermissionCodes.role.read, corePermissionCodes.permission.read, savePermissionCode.value],
mode: "and" as const
}));
// ---------- 表单 ----------
const formModel = reactive({
id: "",
moduleCode: moduleCode,
@@ -63,6 +69,9 @@ const formModel = reactive({
description: "",
childRoleIdList: [] as string[]
});
// ---------- 子角色 ----------
const childOptions = computed(() => permissionStore.roleList.filter(item => item.id !== formModel.id && !hasChildRole(item.id, formModel.id)));
function hasChildRole(roleId: string, targetRoleId: string, visitedRoleIds = new Set<string>()): boolean {
@@ -79,6 +88,8 @@ function hasChildRole(roleId: string, targetRoleId: string, visitedRoleIds = new
return current.childRoleIdList.some(childRoleId => childRoleId === targetRoleId || hasChildRole(childRoleId, targetRoleId, visitedRoleIds));
}
// ---------- 页面数据 ----------
async function fillForm(): Promise<void> {
await permissionStore.loadAll();
const current = await permissionStore.loadRoleDetail(routeId.value);
@@ -92,6 +103,8 @@ async function fillForm(): Promise<void> {
});
}
// ---------- 保存 ----------
async function saveRole(): Promise<void> {
const role = await permissionStore.upsertRole({
id: formModel.id,
@@ -102,11 +115,7 @@ async function saveRole(): Promise<void> {
permissionIdList: permissionStore.getRoleById(formModel.id)?.permissionIdList || [],
childRoleIdList: [...formModel.childRoleIdList]
}, isCreateMode.value);
Toast({
theme: "success",
direction: "row",
message: "角色已保存"
});
Toast.success("角色已保存");
await router.push(isCreateMode.value ? "/management/permissions/roles" : `/management/permissions/roles/${role?.id || formModel.id}`);
}