/** * 平台类型枚举定义 */ export enum PlatformType { /** * 微信公众号 */ WECHAT_OFFICIAL = 'WECHAT_OFFICIAL', /** * 微信小程序 */ WECHAT_MINI = 'WECHAT_MINI', /** * 支付宝 */ ALIPAY = 'ALIPAY', /** * 钉钉 */ DINGTALK = 'DINGTALK', /** * 第三方应用 */ THIRD_PARTY_APP = 'THIRD_PARTY_APP', /** * 飞书 */ FEISHU = 'FEISHU', /** * 抖音 */ TIKTOK = 'TIKTOK', /** * 自定义平台 */ CUSTOM = 'CUSTOM', } /** * 平台配置信息 */ export interface PlatformConfig { /** 平台类型 */ type: PlatformType /** 平台显示名称 */ name: string /** 平台路由前缀 */ routePrefix: string /** 平台描述 */ description?: string /** 认证加载显示名称 */ authDisplayName?: string } /** * 平台类型与路由前缀的映射配置 */ export const PLATFORM_ROUTE_MAP: Record = { [PlatformType.WECHAT_OFFICIAL]: '/wechat/', [PlatformType.WECHAT_MINI]: '/wx-mini-program/', [PlatformType.ALIPAY]: '/alipay/', [PlatformType.DINGTALK]: '/ding-talk/', [PlatformType.THIRD_PARTY_APP]: '/app/', [PlatformType.FEISHU]: '/feishu/', [PlatformType.TIKTOK]: '/tiktok/', [PlatformType.CUSTOM]: '/custom/', } /** * 平台详细配置信息 */ export const PLATFORM_CONFIGS: Record = { [PlatformType.WECHAT_OFFICIAL]: { type: PlatformType.WECHAT_OFFICIAL, name: '微信公众号', routePrefix: '/wechat/', description: '微信公众号外部用户', }, [PlatformType.WECHAT_MINI]: { type: PlatformType.WECHAT_MINI, name: '微信小程序', routePrefix: '/wx-mini-program/', description: '微信小程序用户', }, [PlatformType.ALIPAY]: { type: PlatformType.ALIPAY, name: '支付宝', routePrefix: '/alipay/', description: '支付宝用户', }, [PlatformType.DINGTALK]: { type: PlatformType.DINGTALK, name: '钉钉', routePrefix: '/ding-talk/', description: '钉钉用户', }, [PlatformType.THIRD_PARTY_APP]: { type: PlatformType.THIRD_PARTY_APP, name: '第三方应用', routePrefix: '/app/', description: '第三方应用用户', }, [PlatformType.FEISHU]: { type: PlatformType.FEISHU, name: '飞书', routePrefix: '/feishu/', description: '飞书用户', }, [PlatformType.TIKTOK]: { type: PlatformType.TIKTOK, name: '抖音', routePrefix: '/tiktok/', description: '抖音用户', }, [PlatformType.CUSTOM]: { type: PlatformType.CUSTOM, name: '自定义平台', routePrefix: '/custom/', description: '自定义平台用户', }, } /** * 根据平台类型获取路由前缀 * @param platformType 平台类型 * @returns 路由前缀,默认为 '/ex/' */ export function getPlatformRoutePrefix(platformType?: string): string { if (!platformType) { return '/ex/' // 默认外部用户路径 } const route = PLATFORM_ROUTE_MAP[platformType as PlatformType] return route || '/ex/' // 找不到时使用默认路径 } /** * 根据平台类型获取平台配置 * @param platformType 平台类型 * @returns 平台配置信息 */ export function getPlatformConfig(platformType?: string): PlatformConfig | null { if (!platformType) { return null } return PLATFORM_CONFIGS[platformType as PlatformType] || null } /** * 检查是否为有效的平台类型 * @param platformType 平台类型 * @returns 是否为有效平台类型 */ export function isValidPlatformType(platformType: string): platformType is PlatformType { return Object.values(PlatformType).includes(platformType as PlatformType) } /** * 获取所有支持的平台类型列表 * @returns 平台类型数组 */ export function getAllPlatformTypes(): PlatformType[] { return Object.values(PlatformType) } /** * 获取所有平台配置列表 * @returns 平台配置数组 */ export function getAllPlatformConfigs(): PlatformConfig[] { return Object.values(PLATFORM_CONFIGS) } /** * 根据平台类型获取认证显示名称 * @param platformType 平台类型 * @returns 认证显示名称,默认为 '第三方登录' */ export function getPlatformAuthDisplayName(platformType?: string): string { if (!platformType) { return '第三方登录' } const config = PLATFORM_CONFIGS[platformType as PlatformType] return config?.authDisplayName || '第三方登录' }