feat(semi-auto): 客户链接按平台严格绑定,注入后统一由前端打开指定页

This commit is contained in:
2026-11-17 17:27:19 +08:00
parent 7bd5b8bade
commit 77e1c69a2b
13 changed files with 459 additions and 56 deletions
@@ -1,6 +1,58 @@
/** 客户半自动履约入口:/c/:orderNo。 */
export type CustomerFulfillmentPlatform = 'huya' | 'weibo'
/** 客户半自动履约入口:虎牙 /c/:orderNo,微博 /d/:orderNo。 */
export function buildCustomerFulfillmentPath(orderNo: unknown, platform: unknown): string {
const normalizedOrderNo = String(orderNo || '').trim()
if (!normalizedOrderNo) return ''
const prefix =
String(platform || '')
.trim()
.toLowerCase() === 'weibo'
? 'd'
: 'c'
return `/${prefix}/${encodeURIComponent(normalizedOrderNo)}`
}
export function isCustomerFulfillmentPath(pathname: unknown): boolean {
const normalized = String(pathname || '').trim()
if (!normalized.startsWith('/')) return false
return normalized.split(/[?#]/)[0].replace(/\/+$/, '').split('/').filter(Boolean)[0] === 'c'
const first = normalized.split(/[?#]/)[0].replace(/\/+$/, '').split('/').filter(Boolean)[0]
return first === 'c' || first === 'd'
}
/**
* 严格绑定下的自动归一化:当前路径对应平台没有任务、但订单只有另一个平台任务时,
* 返回应跳转的平台;双平台订单返回 null(各路径只展示自己的任务),
* 无任务或平台未知也返回 null。
*/
export function resolveCustomerPlatformRedirect(
expectedPlatform: CustomerFulfillmentPlatform | null | undefined,
tasks: Array<{ platform?: string | null }>,
): CustomerFulfillmentPlatform | null {
if (expectedPlatform !== 'huya' && expectedPlatform !== 'weibo') return null
if (!Array.isArray(tasks) || tasks.length === 0) return null
if (
tasks.some(
(task) =>
String(task.platform || '')
.trim()
.toLowerCase() === expectedPlatform,
)
) {
return null
}
const platforms = new Set(
tasks
.map((task) =>
String(task.platform || '')
.trim()
.toLowerCase(),
)
.filter(
(platform): platform is CustomerFulfillmentPlatform =>
platform === 'huya' || platform === 'weibo',
),
)
if (platforms.size !== 1) return null
return [...platforms][0]
}
@@ -0,0 +1,15 @@
import type { SemiAutoPlatform } from '@/types/admin/semi-auto'
/**
* 注入浏览器成功后自动打开的平台页面。
* 只在客户页/后台侧使用;扩展只负责写入 Cookie,指定平台页由前端占位页打开。
*/
export const POST_INJECTION_URLS: Record<SemiAutoPlatform, string> = {
huya: 'https://m-shop.huya.com/points.html?pagecode=heping_baodian_credit_center_page&sourceId=yellowcarlist&pid=1199650619883&anchorUid=1199650619883&roomid=30596253',
weibo: 'https://vipclub.e.weibo.com/game/homepage?F=bowen_tjg',
}
export function resolvePostInjectionUrl(platform: string | null | undefined): string {
if (platform === 'huya' || platform === 'weibo') return POST_INJECTION_URLS[platform]
return ''
}