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
+17 -11
View File
@@ -32,7 +32,7 @@
note="为用户授权业务角色"
arrow
hover
@click="goRoleAssign"
@click="toRoleAssign"
>
<template #leftIcon>
<t-icon name="usergroup" size="1.75rem" />
@@ -55,7 +55,7 @@
<div v-if="!scopeList.length" class="empty-card">未配置</div>
</div>
</section>
<t-button v-can="permissionCodes.user.update" class="edit" theme="primary" @click="goEdit">编辑用户</t-button>
<t-button v-can="permissionCodes.user.update" class="edit" theme="primary" @click="toEdit">编辑用户</t-button>
</div>
</template>
@@ -77,6 +77,9 @@ defineOptions({
const route = useRoute();
const router = useRouter();
const permissionStore = usePermissionSettingsStore();
// ---------- 用户数据 ----------
const managedUser = ref<ManagedUser>();
const eventList = ref<EventItem[]>([]);
@@ -105,7 +108,9 @@ const scopeList = computed(() => {
.map(item => item.name);
});
async function goEdit(): Promise<void> {
// ---------- 导航 ----------
async function toEdit(): Promise<void> {
if (!currentUser.value) {
return;
}
@@ -113,7 +118,7 @@ async function goEdit(): Promise<void> {
await router.push(`/management/users/${currentUser.value.id}/edit`);
}
async function goRoleAssign(): Promise<void> {
async function toRoleAssign(): Promise<void> {
if (!currentUser.value) {
return;
}
@@ -123,6 +128,8 @@ async function goRoleAssign(): Promise<void> {
});
}
// ---------- 头像 ----------
function buildFallbackAvatar(name: string): string {
const text = encodeURIComponent((name.trim() || "用户").slice(0, 2));
return [
@@ -144,6 +151,8 @@ function isUser(user?: Partial<User>): user is User {
return typeof user?.name === "string";
}
// ---------- 事件范围 ----------
function canEventItem(action: EventItem, item: ManagedUser): boolean {
const userRoleCodeSet = buildEffectiveRoleCodeSet(item, permissionStore.roleList);
const roleCodeList = action.roleCodeList || [];
@@ -153,11 +162,13 @@ function canEventItem(action: EventItem, item: ManagedUser): boolean {
return roleCodeList.some(code => userRoleCodeSet.has(code));
}
// ---------- 页面数据 ----------
async function loadData(): Promise<void> {
const routeId = String(route.params.id || "");
const [detail, actions] = await Promise.all([
ManagedUserAPI.detail(routeId),
EventAPI.enabledList(),
EventAPI.listValid(),
permissionStore.loadAll()
]);
managedUser.value = detail;
@@ -168,11 +179,7 @@ onMounted(async () => {
try {
await loadData();
} catch {
Toast({
theme: "error",
direction: "row",
message: "用户详情加载失败"
});
Toast.error("用户详情加载失败");
}
});
</script>
@@ -242,4 +249,3 @@ onMounted(async () => {
}
}
</style>