refactor event

This commit is contained in:
Timi
2026-08-05 22:50:22 +08:00
parent 22ff13b1fe
commit 1243068fc3
46 changed files with 961 additions and 789 deletions
@@ -1,7 +1,7 @@
import { AttachmentAPI } from "timi-web";
import type { RegistrationEventRecord } from "@/types/RegistrationEventRecord";
import type { EventRecord } from "@/types/EventRecord";
export function getRegistrationEventRecordPhotoURL(record?: RegistrationEventRecord): string {
export function getEventRecordPhotoURL(record?: EventRecord): string {
const attachment = record?.attachmentList?.find(item => item.attachType === "PHOTO") || record?.attachmentList?.[0];
if (!attachment?.id) {
return "";
@@ -9,3 +9,4 @@ export function getRegistrationEventRecordPhotoURL(record?: RegistrationEventRec
return AttachmentAPI.getReadURL(attachment.id);
}
+16 -1
View File
@@ -3,16 +3,31 @@ import imageCompression from "browser-image-compression";
const PHOTO_MAX_SIZE_MB = 300 / 1024;
const PHOTO_MAX_WIDTH_OR_HEIGHT = 1920;
/**
* 转为真正的 File,避免压缩库返回 Blob 后 FormData 使用默认文件名 blob。
*/
function normalizeUploadImageFile(source: File, compressed: Blob): File {
if (compressed instanceof File && compressed.name) {
return compressed;
}
return new File([compressed], source.name || "upload-image", {
type: compressed.type || source.type,
lastModified: source.lastModified
});
}
/**
* 压缩上传图片,统一限制到 300 KB。
*/
export async function compressUploadImage(file: File): Promise<File> {
return await imageCompression(file, {
const compressedFile = await imageCompression(file, {
maxSizeMB: PHOTO_MAX_SIZE_MB,
maxWidthOrHeight: PHOTO_MAX_WIDTH_OR_HEIGHT,
useWebWorker: true,
initialQuality: .86
});
return normalizeUploadImageFile(file, compressedFile);
}
/**
@@ -1,4 +1,4 @@
export const gaoPermissionCodes = {
export const permissionCodes = {
customer: {
create: "GAO:CUSTOMER:CREATE",
read: "GAO:CUSTOMER:READ",
@@ -6,18 +6,18 @@ export const gaoPermissionCodes = {
update: "GAO:CUSTOMER:UPDATE",
delete: "GAO:CUSTOMER:DELETE"
},
registrationEvent: {
create: "GAO:REGISTRATION_EVENT:CREATE",
read: "GAO:REGISTRATION_EVENT:READ",
update: "GAO:REGISTRATION_EVENT:UPDATE",
delete: "GAO:REGISTRATION_EVENT:DELETE"
event: {
create: "GAO:EVENT:CREATE",
read: "GAO:EVENT:READ",
update: "GAO:EVENT:UPDATE",
delete: "GAO:EVENT:DELETE"
},
registrationEventRecord: {
create: "GAO:REGISTRATION_EVENT_RECORD:CREATE",
read: "GAO:REGISTRATION_EVENT_RECORD:READ",
export: "GAO:REGISTRATION_EVENT_RECORD:EXPORT",
update: "GAO:REGISTRATION_EVENT_RECORD:UPDATE",
delete: "GAO:REGISTRATION_EVENT_RECORD:DELETE"
eventRecord: {
create: "GAO:EVENT_RECORD:CREATE",
read: "GAO:EVENT_RECORD:READ",
export: "GAO:EVENT_RECORD:EXPORT",
update: "GAO:EVENT_RECORD:UPDATE",
delete: "GAO:EVENT_RECORD:DELETE"
},
stat: {
read: "GAO:STAT:READ"
@@ -76,5 +76,6 @@ export const permissionManagementRoleAccess = {
mode: "or"
} as const;
export type GaoPermissionCodes = typeof gaoPermissionCodes;
export type PermissionCodes = typeof permissionCodes;
export type CorePermissionCodes = typeof corePermissionCodes;
+6 -5
View File
@@ -1,7 +1,7 @@
import type { Role } from "@/store/permissionSettingsStore";
import type { GaoUser } from "@/types/GaoUser";
import type { ManagedUser } from "@/types/ManagedUser";
type GaoUserRole = NonNullable<GaoUser["roleList"]>[number];
type ManagedUserRole = NonNullable<ManagedUser["roleList"]>[number];
function buildRoleCode(role: Role): string {
return role.moduleCode && !role.code.includes(":") ? `${role.moduleCode}:${role.code}` : role.code;
@@ -12,7 +12,7 @@ function getBareRoleCode(code: string): string {
return codePartList[codePartList.length - 1] || code;
}
function findRole(role: GaoUserRole, roleList: Role[]): Role | undefined {
function findRole(role: ManagedUserRole, roleList: Role[]): Role | undefined {
if (typeof role === "string") {
return roleList.find(roleItem => roleItem.code === role || buildRoleCode(roleItem) === role);
}
@@ -28,7 +28,7 @@ function appendCompatibleRoleCode(roleCodeSet: Set<string>, code: string): void
roleCodeSet.add(getBareRoleCode(code));
}
export function getGaoRoleName(role: GaoUserRole | undefined, roleList: Role[]): string {
export function getRoleDisplayName(role: ManagedUserRole | undefined, roleList: Role[]): string {
if (!role) {
return "未配置角色";
}
@@ -41,7 +41,7 @@ export function getGaoRoleName(role: GaoUserRole | undefined, roleList: Role[]):
return typeof role === "string" ? getBareRoleCode(role) : role.name || role.code || "未配置角色";
}
export function buildEffectiveRoleCodeSet(user: GaoUser, roleList: Role[]): Set<string> {
export function buildEffectiveRoleCodeSet(user: ManagedUser, roleList: Role[]): Set<string> {
const roleCodeSet = new Set<string>();
for (const role of user.roleList || []) {
const fullRole = findRole(role, roleList);
@@ -68,3 +68,4 @@ function appendRoleCode(roleCodeSet: Set<string>, role: Role, roleList: Role[],
}
}
}