2026-01-21 14:02:42 +08:00
|
|
|
|
// 开通页面地址(public/web/subscribe.html)
|
|
|
|
|
|
const SUBSCRIBE_PAGE_URL = '/web/subscribe.html';
|
2026-01-20 17:54:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 路由路径与 assetId 的映射关系
|
|
|
|
|
|
const ROUTE_ASSET_MAP: Record<string, { assetId: string; serviceName: string }> = {
|
|
|
|
|
|
// CID广告业务(聚合广告)
|
|
|
|
|
|
'/cidService': { assetId: '696f423705e496ba4ccbe665', serviceName: '聚合广告' },
|
|
|
|
|
|
|
|
|
|
|
|
// AI客服业务
|
|
|
|
|
|
'/customerService': { assetId: '696f421205e496ba4ccbe662', serviceName: 'AI客服' },
|
|
|
|
|
|
|
|
|
|
|
|
// 聚合电商业务(资产管理)
|
|
|
|
|
|
'/assets': { assetId: '696b4acd1be1c8b76c4b4c15', serviceName: '资产管理' },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据路由路径获取对应的 assetId 和服务名称
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getAssetInfoByRoute(routePath: string): { assetId: string; serviceName: string } | null {
|
|
|
|
|
|
// 精确匹配
|
|
|
|
|
|
if (ROUTE_ASSET_MAP[routePath]) {
|
|
|
|
|
|
return ROUTE_ASSET_MAP[routePath];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 前缀匹配
|
|
|
|
|
|
for (const [prefix, info] of Object.entries(ROUTE_ASSET_MAP)) {
|
|
|
|
|
|
if (routePath.startsWith(prefix)) {
|
|
|
|
|
|
return info;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-21 14:02:42 +08:00
|
|
|
|
* 跳转到外部开通页面
|
|
|
|
|
|
* @param assetId 资产ID
|
2026-01-20 17:54:29 +08:00
|
|
|
|
*/
|
2026-01-21 14:02:42 +08:00
|
|
|
|
export function redirectToSubscribePage(assetId: string) {
|
|
|
|
|
|
// 当前页面地址作为返回地址
|
|
|
|
|
|
const returnUrl = encodeURIComponent(window.location.href);
|
|
|
|
|
|
// 构建跳转URL
|
|
|
|
|
|
const url = `${SUBSCRIBE_PAGE_URL}?assetId=${assetId}&returnUrl=${returnUrl}`;
|
|
|
|
|
|
console.log('[redirectToSubscribePage] 跳转到开通页面:', url);
|
|
|
|
|
|
window.location.href = url;
|
2026-01-20 17:54:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-21 14:02:42 +08:00
|
|
|
|
* 处理 402 错误码(模块未开通)
|
2026-01-20 17:54:29 +08:00
|
|
|
|
*/
|
|
|
|
|
|
export function handleModuleNotEnabled(routePath: string): boolean {
|
|
|
|
|
|
console.log('[模块未开通] 当前路由路径:', routePath);
|
|
|
|
|
|
const assetInfo = getAssetInfoByRoute(routePath);
|
|
|
|
|
|
console.log('[模块未开通] 匹配到的资产信息:', assetInfo);
|
|
|
|
|
|
|
|
|
|
|
|
if (assetInfo) {
|
2026-01-21 14:02:42 +08:00
|
|
|
|
redirectToSubscribePage(assetInfo.assetId);
|
2026-01-20 17:54:29 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果没有匹配到路由,尝试使用默认的资产管理
|
|
|
|
|
|
console.warn('[模块未开通] 未匹配到路由,使用默认资产管理');
|
2026-01-21 14:02:42 +08:00
|
|
|
|
redirectToSubscribePage('696b4acd1be1c8b76c4b4c15');
|
2026-01-20 17:54:29 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|