feat: 完善接口19-顶部通知铃铛与站内通知中心
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m5s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m5s
This commit is contained in:
@@ -29,3 +29,11 @@ export const getExpiryEstimateTooltip = (estimate: ExpiryEstimate): string => {
|
||||
if (!estimate.is_expiring || estimate.days_until_final_expiry == null) return ''
|
||||
return `剩余${estimate.days_until_final_expiry}天`
|
||||
}
|
||||
|
||||
export const getExpiryEstimateClass = (estimate: ExpiryEstimate): string => {
|
||||
if (!estimate.is_expiring || estimate.days_until_final_expiry == null) return ''
|
||||
if (estimate.days_until_final_expiry <= 3) return 'expiry-estimate--critical'
|
||||
if (estimate.days_until_final_expiry <= 7) return 'expiry-estimate--warning'
|
||||
if (estimate.days_until_final_expiry <= 15) return 'expiry-estimate--notice'
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import type { Router } from 'vue-router'
|
||||
import type { NotificationTarget } from '@/types/api'
|
||||
import { RoutesAlias } from '@/router/routesAlias'
|
||||
|
||||
export const navigateNotificationTarget = (router: Router, target?: NotificationTarget | null) => {
|
||||
if (!target || target.available === false) return false
|
||||
const query = target.query
|
||||
? Object.fromEntries(Object.entries(target.query).map(([key, value]) => [key, String(value)]))
|
||||
: undefined
|
||||
type TargetRoute = {
|
||||
path: string
|
||||
query?: Record<string, string>
|
||||
}
|
||||
|
||||
if (target.route_name) {
|
||||
if (!router.hasRoute(target.route_name)) return false
|
||||
void router.push({
|
||||
name: target.route_name,
|
||||
params: target.route_params || undefined,
|
||||
query
|
||||
})
|
||||
return true
|
||||
const resolveTargetRoute = (target: NotificationTarget): TargetRoute | null => {
|
||||
const targetValues = [target.target_key, target.target_type]
|
||||
|
||||
if (targetValues.includes('expiring_assets') || targetValues.includes('expiring_asset_list')) {
|
||||
return { path: RoutesAlias.ExpiringAssets }
|
||||
}
|
||||
|
||||
const path = target.route_path || ''
|
||||
if (!path.startsWith('/') || path.startsWith('//') || /^https?:\/\//i.test(path)) return false
|
||||
if (targetValues.includes('notification_center')) return { path: RoutesAlias.Notifications }
|
||||
|
||||
const resolved = router.resolve({
|
||||
path,
|
||||
query
|
||||
})
|
||||
return null
|
||||
}
|
||||
|
||||
export const navigateNotificationTarget = (router: Router, target?: NotificationTarget | null) => {
|
||||
if (!target?.available) return false
|
||||
const route = resolveTargetRoute(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)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user