task-23: 拆分 image-video / brand / permission / digital-human 模块 API 至 types/modules/,旧文件转 re-export 存根

This commit is contained in:
2026-08-31 19:57:38 +08:00
parent 57e607e1b2
commit 39b1b7edbf
9 changed files with 853 additions and 618 deletions
+1 -85
View File
@@ -1,85 +1 @@
import { requestGetJson } from '@/shared/api/http'
export interface PermissionMenuItem {
id: number | string
name?: string
column_key?: string
columnKey?: string
route_path?: string
routePath?: string
menu_type?: string
parent_id?: number | string | null
parentId?: number | string | null
root_column_key?: string
rootColumnKey?: string
sort_order?: number
created_at?: string
}
interface PermissionMenuResponse {
success: boolean
data?: PermissionMenuItem[]
items?: PermissionMenuItem[]
error?: string
message?: string
}
function getCurrentUserId() {
const raw = typeof window === 'undefined' ? '' : window.localStorage.getItem('uid') || ''
const value = Number(raw)
if (!Number.isFinite(value) || value <= 0) {
throw new Error('未获取到用户ID')
}
return value
}
function getAppPermissionCacheKey(uid: number) {
return `app_column_permissions:${String(uid)}`
}
function getAuthToken() {
return typeof window === 'undefined' ? '' : window.localStorage.getItem('aiimage_auth_token') || ''
}
function normalizeColumnKeys(items: PermissionMenuItem[] | undefined) {
const keys = new Set<string>()
for (const item of items || []) {
for (const value of [item.column_key, item.columnKey, item.route_path, item.routePath]) {
const key = String(value || '').trim().toLowerCase()
if (key) {
keys.add(key)
}
}
}
return Array.from(keys)
}
export async function getCurrentUserAppColumnKeys() {
const uid = getCurrentUserId()
const cacheKey = getAppPermissionCacheKey(uid)
const headers: Record<string, string> = {}
const token = getAuthToken()
if (token) {
headers.Authorization = `Bearer ${token}`
}
const res = await requestGetJson<PermissionMenuResponse>(
`/newApi/api/admin/permission-users/${encodeURIComponent(String(uid))}/column-permissions`,
{
params: { menuType: 'app' },
headers,
},
)
if (!res.success) {
throw new Error(res.error || res.message || '获取菜单权限失败')
}
const items = res.data || res.items || []
try {
window.localStorage.setItem(cacheKey, JSON.stringify(items))
} catch (_error) {}
return normalizeColumnKeys(items)
}
export * from './types/modules/permission'