重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import type { SystemMessageVO } from '@/api/user'
|
||||
|
||||
type MessageLike = Pick<SystemMessageVO, 'actionPath' | 'businessType' | 'businessId'>
|
||||
|
||||
const USER_ACTION_PREFIXES = [
|
||||
'/orders',
|
||||
'/after-sales',
|
||||
'/after-sale/apply',
|
||||
'/service-progress',
|
||||
'/help',
|
||||
'/product/',
|
||||
'/shop/',
|
||||
'/coupons',
|
||||
'/vip-center',
|
||||
'/cart',
|
||||
'/notifications',
|
||||
'/wishlist',
|
||||
'/profile',
|
||||
'/settings',
|
||||
'/artist-orders',
|
||||
'/artist-calendar'
|
||||
]
|
||||
|
||||
const appendQuery = (path: string, query: Record<string, string | number | undefined>) => {
|
||||
const params = new URLSearchParams()
|
||||
Object.entries(query).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== '') {
|
||||
params.set(key, String(value))
|
||||
}
|
||||
})
|
||||
const queryString = params.toString()
|
||||
return queryString ? `${path}?${queryString}` : path
|
||||
}
|
||||
|
||||
const isAllowedUserActionPath = (actionPath: string) => {
|
||||
const pathOnly = actionPath.split('?')[0] || ''
|
||||
return USER_ACTION_PREFIXES.some(prefix => {
|
||||
if (prefix.endsWith('/')) {
|
||||
return pathOnly.startsWith(prefix)
|
||||
}
|
||||
return pathOnly === prefix || pathOnly.startsWith(`${prefix}/`)
|
||||
})
|
||||
}
|
||||
|
||||
export const normalizeSystemMessageActionPath = (value?: string) => {
|
||||
const actionPath = String(value || '').trim()
|
||||
if (!actionPath || !actionPath.startsWith('/') || actionPath.startsWith('//') || actionPath.includes('\\')) {
|
||||
return ''
|
||||
}
|
||||
return isAllowedUserActionPath(actionPath) ? actionPath : ''
|
||||
}
|
||||
|
||||
export const buildSystemMessageActionPath = (message: MessageLike) => {
|
||||
const actionPath = normalizeSystemMessageActionPath(message.actionPath)
|
||||
if (actionPath) {
|
||||
return actionPath
|
||||
}
|
||||
|
||||
const businessType = String(message.businessType || '').toUpperCase()
|
||||
const businessId = message.businessId === undefined || message.businessId === null ? '' : String(message.businessId)
|
||||
if (businessType === 'ORDER_ARTIST_REVIEW') {
|
||||
return businessId
|
||||
? appendQuery('/orders', { reviewId: businessId, source: 'message' })
|
||||
: appendQuery('/orders', { review: 'pending', source: 'message' })
|
||||
}
|
||||
if (businessType === 'ORDER' && businessId) {
|
||||
return `/orders/${encodeURIComponent(businessId)}`
|
||||
}
|
||||
if (businessType === 'ORDER_ARTIST_CHANGE' && businessId) {
|
||||
return appendQuery('/service-progress', { orderId: businessId, source: 'message' })
|
||||
}
|
||||
if (businessType === 'ORDER_ARTIST_CHANGE' || businessType === 'ORDER') {
|
||||
return appendQuery('/orders', { orderId: businessId || undefined, source: 'message' })
|
||||
}
|
||||
if (businessType === 'AFTER_SALE') {
|
||||
return appendQuery('/after-sales', { orderId: businessId || undefined, source: 'message' })
|
||||
}
|
||||
if (businessType === 'PRODUCT' && businessId) {
|
||||
return `/product/${encodeURIComponent(businessId)}`
|
||||
}
|
||||
if (businessType === 'SHOP' && businessId) {
|
||||
return `/shop/${encodeURIComponent(businessId)}`
|
||||
}
|
||||
if (businessType === 'VIP') {
|
||||
return '/vip-center'
|
||||
}
|
||||
if (businessType === 'COUPON') {
|
||||
return '/coupons'
|
||||
}
|
||||
if (businessType === 'CART') {
|
||||
return '/cart'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
Reference in New Issue
Block a user