This commit is contained in:
zlwu committed 2026-06-29 11:15:39 +08:00
1 parent 493f8d6756
commit d84f4b944c
406 files changed
+58954 -10376

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import { useUserStore } from '@/store/modules/user'
export const CREATOR_DELETE_TIP = '仅创建人可删除'
/** 当前登录用户 ID(UUID 字符串) */
export function getCurrentUserId(): string {
const info = useUserStore().info as Record<string, unknown>
const id = info?.id ?? info?.userId ?? info?.user_id
if (id === undefined || id === null || id === '') return ''
return String(id)
}
/** 是否 super_admin */
export function isSuperAdmin(): boolean {
const info = useUserStore().info as Record<string, unknown>
const roles = (info?.roles as string[] | undefined) ?? []
const role = (info?.role as string | undefined) ?? ''
return role === 'super_admin' || roles.includes('super_admin')
}
export function rowCreatorId(row: Record<string, unknown> | null | undefined): string {
if (!row) return ''
const creator =
row.createBy ??
row.create_by ??
row.applicantId ??
row.applicant_id
if (creator === undefined || creator === null || creator === '') return ''
return String(creator)
}
/** 是否允许删除(仅创建人或 super_admin) */
export function canDeleteByCreator(
row: Record<string, unknown> | null | undefined,
currentUserId?: string
): boolean {
if (!row) return false
if (isSuperAdmin()) return true
const uid = (currentUserId ?? getCurrentUserId()).trim()
const creator = rowCreatorId(row)
if (!creator) return false
if (uid && creator === uid) return true
const info = useUserStore().info as Record<string, unknown>
const names = [info?.realName, info?.real_name, info?.userName, info?.username, info?.nickName]
.filter(Boolean)
.map(String)
return names.includes(creator)
}
/** 批量删除前过滤可删行 */
export function filterDeletableByCreator<T extends Record<string, unknown>>(
rows: T[],
currentUserId?: string
): T[] {
return rows.filter((row) => canDeleteByCreator(row, currentUserId))
}
/** 选中项是否全部可删 */
export function allRowsDeletableByCreator(
rows: Record<string, unknown>[],
currentUserId?: string
): boolean {
if (!rows.length) return false
return rows.every((row) => canDeleteByCreator(row, currentUserId))
}