refactor event
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-can="gaoPermissionCodes.user.read" class="user-edit">
|
||||
<div v-can="permissionCodes.user.read" class="user-edit">
|
||||
<t-cell-group v-if="currentUser" theme="card">
|
||||
<t-cell
|
||||
:title="currentUser.name"
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<t-cell-group v-if="currentUser" theme="card">
|
||||
<t-cell
|
||||
v-can="gaoPermissionCodes.user.update"
|
||||
v-can="permissionCodes.user.update"
|
||||
title="配置角色"
|
||||
note="为用户授权业务角色"
|
||||
arrow
|
||||
@@ -55,20 +55,20 @@
|
||||
<div v-if="!scopeList.length" class="empty-card">未配置</div>
|
||||
</div>
|
||||
</section>
|
||||
<t-button v-can="gaoPermissionCodes.user.update" class="edit" theme="primary" @click="goEdit">编辑用户</t-button>
|
||||
<t-button v-can="permissionCodes.user.update" class="edit" theme="primary" @click="goEdit">编辑用户</t-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Toast } from "tdesign-mobile-vue";
|
||||
import { UserAPI, type User } from "timi-web";
|
||||
import RegistrationEventAPI from "@/api/RegistrationEventAPI";
|
||||
import GaoUserAPI from "@/api/GaoUserAPI";
|
||||
import type { GaoUser } from "@/types/GaoUser";
|
||||
import type { RegistrationEvent } from "@/types/RegistrationEvent";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import ManagedUserAPI from "@/api/ManagedUserAPI";
|
||||
import type { ManagedUser } from "@/types/ManagedUser";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import { usePermissionSettingsStore } from "@/store/permissionSettingsStore";
|
||||
import { buildEffectiveRoleCodeSet, getGaoRoleName } from "@/utils/gaoRole";
|
||||
import { gaoPermissionCodes } from "@/utils/gaoPermission";
|
||||
import { buildEffectiveRoleCodeSet, getRoleDisplayName } from "@/utils/role";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
|
||||
defineOptions({
|
||||
name: "UserDetail"
|
||||
@@ -77,11 +77,11 @@ defineOptions({
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const permissionStore = usePermissionSettingsStore();
|
||||
const gaoUser = ref<GaoUser>();
|
||||
const registrationEventList = ref<RegistrationEvent[]>([]);
|
||||
const managedUser = ref<ManagedUser>();
|
||||
const eventList = ref<EventItem[]>([]);
|
||||
|
||||
const currentUser = computed(() => {
|
||||
const item = gaoUser.value;
|
||||
const item = managedUser.value;
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
@@ -89,19 +89,19 @@ const currentUser = computed(() => {
|
||||
return {
|
||||
id: item.id || "",
|
||||
name: user?.nick || user?.name || "未命名用户",
|
||||
role: getGaoRoleName(item.roleList?.[0], permissionStore.roleList),
|
||||
role: getRoleDisplayName(item.roleList?.[0], permissionStore.roleList),
|
||||
avatar: buildUserAvatar(user),
|
||||
mobile: user?.phoneNo || "",
|
||||
lastLoginAt: user?.lastLoginAt ? new Date(user.lastLoginAt).toLocaleString() : ""
|
||||
};
|
||||
});
|
||||
const scopeList = computed(() => {
|
||||
const item = gaoUser.value;
|
||||
const item = managedUser.value;
|
||||
if (!item) {
|
||||
return [];
|
||||
}
|
||||
return registrationEventList.value
|
||||
.filter(action => canRegistrationEvent(action, item))
|
||||
return eventList.value
|
||||
.filter(action => canEventItem(action, item))
|
||||
.map(item => item.name);
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ function isUser(user?: Partial<User>): user is User {
|
||||
return typeof user?.name === "string";
|
||||
}
|
||||
|
||||
function canRegistrationEvent(action: RegistrationEvent, item: GaoUser): boolean {
|
||||
function canEventItem(action: EventItem, item: ManagedUser): boolean {
|
||||
const userRoleCodeSet = buildEffectiveRoleCodeSet(item, permissionStore.roleList);
|
||||
const roleCodeList = action.roleCodeList || [];
|
||||
if (!roleCodeList.length) {
|
||||
@@ -156,12 +156,12 @@ function canRegistrationEvent(action: RegistrationEvent, item: GaoUser): boolean
|
||||
async function loadData(): Promise<void> {
|
||||
const routeId = String(route.params.id || "");
|
||||
const [detail, actions] = await Promise.all([
|
||||
GaoUserAPI.detail(routeId),
|
||||
RegistrationEventAPI.enabledList(),
|
||||
ManagedUserAPI.detail(routeId),
|
||||
EventAPI.enabledList(),
|
||||
permissionStore.loadAll()
|
||||
]);
|
||||
gaoUser.value = detail;
|
||||
registrationEventList.value = actions || [];
|
||||
managedUser.value = detail;
|
||||
eventList.value = actions || [];
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -242,3 +242,4 @@ onMounted(async () => {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user