137 lines
4.0 KiB
TypeScript
137 lines
4.0 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/api/http'
|
|||
|
|
|
||
|
|
export interface PlatformPermissionResource {
|
||
|
|
id: number
|
||
|
|
tenantId: number
|
||
|
|
appCode: 'PLATFORM'
|
||
|
|
permissionType: 'MENU' | 'BUTTON'
|
||
|
|
parentId: number
|
||
|
|
permissionCode: string
|
||
|
|
permissionName: string
|
||
|
|
routePath: string | null
|
||
|
|
httpMethod: string | null
|
||
|
|
sortNo: number
|
||
|
|
status: 'ACTIVE' | 'INACTIVE'
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface EnterpriseReview {
|
||
|
|
id: number
|
||
|
|
tenantId: number
|
||
|
|
status: 'PENDING' | 'APPROVED' | 'REJECTED'
|
||
|
|
tenantName?: string | null
|
||
|
|
tenantCode?: string | null
|
||
|
|
qualificationId?: number | null
|
||
|
|
qualificationType?: string | null
|
||
|
|
certificateNo?: string | null
|
||
|
|
documentUrl?: string | null
|
||
|
|
contactName?: string | null
|
||
|
|
contactPhone?: string | null
|
||
|
|
contactEmail?: string | null
|
||
|
|
submittedAt?: string | null
|
||
|
|
createdAt?: string | null
|
||
|
|
reviewComment?: string | null
|
||
|
|
[key: string]: unknown
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface PlatformTenantQualification {
|
||
|
|
id: number | string
|
||
|
|
tenantId: number | string
|
||
|
|
qualificationType: 'BUSINESS_LICENSE' | string
|
||
|
|
certificateNo: string | null
|
||
|
|
documentUrl: string
|
||
|
|
status: 'PENDING' | 'APPROVED' | 'REJECTED'
|
||
|
|
reviewComment: string | null
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface PlatformRoleResource {
|
||
|
|
id: number
|
||
|
|
tenantId: number
|
||
|
|
appCode: 'PLATFORM'
|
||
|
|
roleCode: string
|
||
|
|
roleName: string
|
||
|
|
roleType: 'SYSTEM' | 'CUSTOM' | string
|
||
|
|
status: 'ACTIVE' | 'INACTIVE' | string
|
||
|
|
description: string | null
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CreatePlatformRoleRequest {
|
||
|
|
roleCode: string
|
||
|
|
roleName: string
|
||
|
|
description: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CreatePlatformPermissionRequest {
|
||
|
|
type: 'MENU' | 'BUTTON'
|
||
|
|
code: string
|
||
|
|
name: string
|
||
|
|
parentId: number
|
||
|
|
routePath: string | null
|
||
|
|
httpMethod: null
|
||
|
|
sortNo: number
|
||
|
|
}
|
||
|
|
|
||
|
|
async function getData<T>(path: string): Promise<T> {
|
||
|
|
const response = await http.get<ApiEnvelope<T>, ApiEnvelope<T>>(path)
|
||
|
|
return unwrapApiResponse(response)
|
||
|
|
}
|
||
|
|
|
||
|
|
async function postData<T>(path: string, body: unknown): Promise<T> {
|
||
|
|
const response = await http.post<ApiEnvelope<T>, ApiEnvelope<T>>(path, body)
|
||
|
|
return unwrapApiResponse(response)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function listPlatformPermissions() {
|
||
|
|
return getData<PlatformPermissionResource[]>('/platform/v1/iam/permissions')
|
||
|
|
}
|
||
|
|
|
||
|
|
export function listEnterpriseReviews() {
|
||
|
|
return getData<EnterpriseReview[]>('/platform/v1/iam/reviews')
|
||
|
|
}
|
||
|
|
|
||
|
|
export function listTenantQualifications(tenantId: number | string) {
|
||
|
|
return getData<PlatformTenantQualification[]>(`/platform/v1/iam/tenants/${tenantId}/qualifications`)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function qualificationFileName(documentUrl: string) {
|
||
|
|
const path = documentUrl.split(/[?#]/, 1)[0]
|
||
|
|
const encodedName = path.split('/').filter(Boolean).at(-1)
|
||
|
|
if (!encodedName) throw new Error('资质文件地址无效')
|
||
|
|
let fileName: string
|
||
|
|
try {
|
||
|
|
fileName = decodeURIComponent(encodedName)
|
||
|
|
} catch {
|
||
|
|
throw new Error('资质文件地址无效')
|
||
|
|
}
|
||
|
|
if (!fileName || fileName === '.' || fileName === '..' || /[\\/]/.test(fileName)) {
|
||
|
|
throw new Error('资质文件地址无效')
|
||
|
|
}
|
||
|
|
return fileName
|
||
|
|
}
|
||
|
|
|
||
|
|
export function downloadTenantQualification(tenantId: number | string, documentUrl: string) {
|
||
|
|
const fileName = qualificationFileName(documentUrl)
|
||
|
|
return http.get<Blob, Blob>(`/platform/v1/files/qualifications/${tenantId}/${encodeURIComponent(fileName)}`, {
|
||
|
|
responseType: 'blob',
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export function listPlatformRoles() {
|
||
|
|
return getData<PlatformRoleResource[]>('/platform/v1/iam/roles')
|
||
|
|
}
|
||
|
|
|
||
|
|
export function createPlatformRole(payload: CreatePlatformRoleRequest) {
|
||
|
|
return postData<PlatformRoleResource>('/platform/v1/iam/roles', payload)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function createPlatformPermission(payload: CreatePlatformPermissionRequest) {
|
||
|
|
return postData<PlatformPermissionResource>('/platform/v1/iam/permissions', payload)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function approveEnterpriseReview(reviewId: number, comment: string) {
|
||
|
|
return postData<unknown>(`/platform/v1/iam/reviews/${reviewId}/approve`, { comment })
|
||
|
|
}
|
||
|
|
|
||
|
|
export function rejectEnterpriseReview(reviewId: number, comment: string) {
|
||
|
|
return postData<unknown>(`/platform/v1/iam/reviews/${reviewId}/reject`, { comment })
|
||
|
|
}
|