// Help Chat Button SDK 配置接口 export interface HelpChatButtonConfig { // 主题颜色配置 themeColor?: string | string[] // 按钮位置配置 position?: { top?: string right?: string bottom?: string left?: string } // 是否可拖拽 draggable?: boolean // AI 聊天配置 aiChatConfig?: { pollingInterval?: number botCode: string } // 用户信息 userId: string userName?: string // 反馈中心配置 feedbackConfig?: { systemId: string } } // 全局配置 let globalConfig: HelpChatButtonConfig = { themeColor: ['#667eea', '#764ba2'], position: { top: 'auto', right: '20px', bottom: '20px', left: 'auto' }, draggable: true, aiChatConfig: { pollingInterval: 500, botCode: '' }, userId: '', userName: 'name', feedbackConfig: { systemId: '' } } // 设置全局配置 export const setHelpChatButtonConfig = (config: Partial) => { globalConfig = { ...globalConfig, ...config } // 深度合并嵌套对象 if (config.position) { globalConfig.position = { ...globalConfig.position, ...config.position } } if (config.aiChatConfig) { globalConfig.aiChatConfig = { ...globalConfig.aiChatConfig, ...config.aiChatConfig } } if (config.feedbackConfig) { globalConfig.feedbackConfig = { ...globalConfig.feedbackConfig, ...config.feedbackConfig } } } // 获取全局配置 export const getHelpChatButtonConfig = (): HelpChatButtonConfig => ({ ...globalConfig }) // 验证配置 export const validateConfig = (config: HelpChatButtonConfig): void => { if (!config.userId) { throw new Error('userId 是必需参数') } if (!config.aiChatConfig?.botCode) { throw new Error('aiChatConfig.botCode 是必需参数') } if (!config.feedbackConfig?.systemId) { throw new Error('feedbackConfig.systemId 是必需参数') } }