This commit is contained in:
69
src/utils/business/auditNavigation.ts
Normal file
69
src/utils/business/auditNavigation.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import type { AuditSubjectResourceType } from '@/types/api'
|
||||
import type { AuditFinanceField, AuditInvestigationTarget } from '@/components/business/audit/types'
|
||||
|
||||
interface AuditResourceRouteOptions {
|
||||
userType?: number
|
||||
resourceType: AuditSubjectResourceType | string
|
||||
internalId?: string | number | null
|
||||
businessIdentifier?: string | null
|
||||
}
|
||||
|
||||
/** 根据当前主体选择平台内部 ID 或主体安全业务标识。 */
|
||||
export function resolveAuditResourceTarget(
|
||||
options: AuditResourceRouteOptions
|
||||
): AuditInvestigationTarget | null {
|
||||
const { userType, resourceType, internalId, businessIdentifier } = options
|
||||
const normalizedBusinessIdentifier = businessIdentifier?.trim()
|
||||
if (userType === 3) {
|
||||
if (
|
||||
!normalizedBusinessIdentifier ||
|
||||
![
|
||||
'iot_card',
|
||||
'device',
|
||||
'asset_allocation_record',
|
||||
'exchange_order',
|
||||
'shop',
|
||||
'enterprise'
|
||||
].includes(resourceType)
|
||||
)
|
||||
return null
|
||||
return {
|
||||
mode: 'agent',
|
||||
resourceType: resourceType as AuditSubjectResourceType,
|
||||
id: normalizedBusinessIdentifier
|
||||
}
|
||||
}
|
||||
if (userType === 4) {
|
||||
if (!normalizedBusinessIdentifier || !['iot_card', 'device'].includes(resourceType)) return null
|
||||
return {
|
||||
mode: 'enterprise',
|
||||
resourceType: resourceType as AuditSubjectResourceType,
|
||||
id: normalizedBusinessIdentifier
|
||||
}
|
||||
}
|
||||
if (
|
||||
internalId === undefined ||
|
||||
internalId === null ||
|
||||
internalId === '' ||
|
||||
(typeof internalId === 'string' && !internalId.trim()) ||
|
||||
(typeof internalId === 'number' && (!Number.isFinite(internalId) || internalId <= 0))
|
||||
)
|
||||
return null
|
||||
return { mode: 'resource', resourceType, id: String(internalId).trim() }
|
||||
}
|
||||
|
||||
export function resolveFinanceAuditTarget(
|
||||
field: AuditFinanceField,
|
||||
value?: string | number | null
|
||||
): AuditInvestigationTarget | null {
|
||||
const normalizedValue = typeof value === 'string' ? value.trim() : value
|
||||
if (
|
||||
normalizedValue === undefined ||
|
||||
normalizedValue === null ||
|
||||
normalizedValue === '' ||
|
||||
(typeof normalizedValue === 'number' &&
|
||||
(!Number.isFinite(normalizedValue) || normalizedValue <= 0))
|
||||
)
|
||||
return null
|
||||
return { mode: 'finance', field, value: normalizedValue }
|
||||
}
|
||||
Reference in New Issue
Block a user