fix:通知和设备分配/回收
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m49s

This commit is contained in:
luo
2026-07-28 17:23:23 +08:00
parent b51a3f5537
commit ee266c51cc
7 changed files with 114 additions and 69 deletions

View File

@@ -1,70 +1,56 @@
import type { Router } from 'vue-router'
import type { NotificationTarget } from '@/types/api'
import type { RouteLocationRaw, Router } from 'vue-router'
import type { NotificationRefType, NotificationTarget } from '@/types/api'
import { RoutesAlias } from '@/router/routesAlias'
type TargetRoute = {
path: string
query?: Record<string, string>
type TargetRoute = RouteLocationRaw
const resolveTargetRoute = (
refType: NotificationRefType | null,
target: NotificationTarget
): TargetRoute | null => {
const targetId = target.target_id === null ? '' : String(target.target_id)
switch (refType) {
case 'system_config':
return { path: RoutesAlias.SystemConfigs }
case 'refund':
return { path: RoutesAlias.RefundManagement }
case 'agent_recharge':
return { path: RoutesAlias.AgentRecharge }
case 'iot_card':
return targetId ? { path: RoutesAlias.AssetInformation, query: { iccid: targetId } } : null
case 'device':
return targetId
? { path: RoutesAlias.AssetInformation, query: { virtual_no: targetId } }
: null
case 'expiring_asset':
return { path: RoutesAlias.ExpiringAssets }
case 'shop_fund':
return { path: RoutesAlias.AgentFundOverview }
case 'integration_log':
case 'package':
case 'asset':
case 'wecom_approval':
case 'card_sync':
default:
return null
}
}
const resolveTargetRoute = (target: NotificationTarget): TargetRoute | null => {
const targetId = target.target_id === null ? undefined : String(target.target_id)
const targetKey = target.target_key || ''
if (target.target_type === 'refund_detail' && targetId) {
return { path: `${RoutesAlias.RefundDetail}/${targetId}` }
export const navigateNotificationTarget = (
router: Router,
refType: NotificationRefType | null,
target?: NotificationTarget | null
) => {
if (!target) return false
if (!target.available) {
void router.push(RoutesAlias.Exception403)
return true
}
if (target.target_type === 'agent_recharge_detail' && targetId) {
return { path: `${RoutesAlias.AgentRechargeDetail}/${targetId}` }
}
if (target.target_type === 'iot_card_detail' && (targetKey || targetId)) {
return {
path: RoutesAlias.AssetInformation,
query: { iccid: targetKey || targetId || '' }
}
}
if (target.target_type === 'device_detail' && (targetKey || targetId)) {
return {
path: RoutesAlias.AssetInformation,
query: { virtual_no: targetKey || targetId || '' }
}
}
if (
target.target_type === 'expiring_asset_list' ||
target.target_key === 'expiring_assets' ||
target.target_key === 'expiring_asset_list'
) {
return { path: RoutesAlias.ExpiringAssets }
}
if (target.target_type === 'shop_fund_summary') {
return {
path: RoutesAlias.AgentFundOverview,
query: targetId ? { shop_id: targetId } : undefined
}
}
if (target.target_type === 'system_config') {
return {
path: RoutesAlias.SystemConfigs,
query: targetKey ? { config_key: targetKey } : undefined
}
}
return null
}
export const navigateNotificationTarget = (router: Router, target?: NotificationTarget | null) => {
if (!target?.available) return false
const route = resolveTargetRoute(target)
const route = resolveTargetRoute(refType, target)
if (!route) return false
const resolved = router.resolve({ path: route.path, query: route.query })
if (!resolved.matched.length || resolved.name === 'Exception404') return false
void router.push(resolved)
void router.push(route)
return true
}