| 1 | /** |
| 2 | * ChannelManager - 频道管理器类型定义 |
| 3 | * 包含三页面视图状态、授权状态、侧边栏状态等类型 |
| 4 | */ |
| 5 | |
| 6 | import type { SocialAccount } from '@/api/accounts/account.types' |
| 7 | import type { PlatType } from '@/app/config/platConfig' |
| 8 | import type { PluginPlatformType } from '@/store/plugin' |
| 9 | |
| 10 | /** 频道管理器视图类型 */ |
| 11 | export type ChannelManagerView = 'main' | 'connect-list' | 'auth-loading' |
| 12 | |
| 13 | /** 授权状态 */ |
| 14 | export interface AuthState { |
| 15 | /** 正在授权的平台 */ |
| 16 | platform: PlatType | null |
| 17 | /** 授权 Session ID */ |
| 18 | sessionId: string | null |
| 19 | /** 授权URL */ |
| 20 | authUrl: string | null |
| 21 | /** Authorization mode */ |
| 22 | authMode?: 'oauth' | 'miniappQr' |
| 23 | /** Mini app QR code image for authorization */ |
| 24 | qrCodeDataUrl?: string | null |
| 25 | /** Mini app QR code embedded page path */ |
| 26 | qrCodePath?: string | null |
| 27 | /** 倒计时秒数(默认300秒 = 5分钟) */ |
| 28 | countdown: number |
| 29 | /** 是否正在轮询 */ |
| 30 | isPolling: boolean |
| 31 | /** 授权错误信息 */ |
| 32 | error: string | null |
| 33 | /** 是否授权超时 */ |
| 34 | isTimeout: boolean |
| 35 | } |
| 36 | |
| 37 | /** 频道管理器状态 */ |
| 38 | export interface ChannelManagerState { |
| 39 | /** 弹窗是否打开 */ |
| 40 | open: boolean |
| 41 | /** 当前页面视图 */ |
| 42 | currentView: ChannelManagerView |
| 43 | /** 侧边栏选中的频道类型,'all' 表示全部频道 */ |
| 44 | selectedPlatform: PlatType | 'all' |
| 45 | /** 授权相关状态 */ |
| 46 | authState: AuthState |
| 47 | /** 目标空间ID(授权成功后账号添加到哪个空间) */ |
| 48 | targetSpaceId: string | null |
| 49 | /** 授权成功回调(外部设置) */ |
| 50 | onAuthSuccess: ((account: SocialAccount, platform: PlatType) => void) | null |
| 51 | /** 是否为新用户(没有任何账号) */ |
| 52 | isNewUser: boolean |
| 53 | } |
| 54 | |
| 55 | /** 频道管理器方法 */ |
| 56 | export interface ChannelManagerMethods { |
| 57 | /** 打开弹框(默认显示主页) */ |
| 58 | openModal: () => void |
| 59 | /** 关闭弹框 */ |
| 60 | closeModal: () => void |
| 61 | /** 直接打开并进入指定平台的授权流程 */ |
| 62 | openAndAuth: (platform: PlatType, spaceId?: string) => void |
| 63 | /** 直接打开并进入连接新频道列表页 */ |
| 64 | openConnectList: (spaceId?: string) => void |
| 65 | /** 设置授权成功回调 */ |
| 66 | setOnAuthSuccess: ( |
| 67 | callback: ((account: SocialAccount, platform: PlatType) => void) | null, |
| 68 | ) => void |
| 69 | /** 切换视图 */ |
| 70 | setCurrentView: (view: ChannelManagerView) => void |
| 71 | /** 设置侧边栏选中的平台 */ |
| 72 | setSelectedPlatform: (platform: PlatType | 'all') => void |
| 73 | /** 设置目标空间ID */ |
| 74 | setTargetSpaceId: (spaceId: string | null) => void |
| 75 | /** 开始授权流程 */ |
| 76 | startAuth: (platform: PlatType, spaceId?: string) => Promise<void> |
| 77 | /** 处理插件平台的授权(小红书、抖音等) */ |
| 78 | handlePluginPlatformAuth: (platform: PluginPlatformType, spaceId?: string) => Promise<void> |
| 79 | /** 停止授权(取消/超时) */ |
| 80 | stopAuth: () => void |
| 81 | /** 重新打开授权页面 */ |
| 82 | reopenAuthWindow: () => void |
| 83 | /** 授权成功处理 */ |
| 84 | handleAuthSuccess: (account: SocialAccount) => void |
| 85 | /** 重置状态 */ |
| 86 | reset: () => void |
| 87 | /** 检查是否为新用户 */ |
| 88 | checkIsNewUser: () => void |
| 89 | } |
| 90 | |
| 91 | /** 授权URL响应 */ |
| 92 | export interface AuthUrlResponse { |
| 93 | url: string |
| 94 | sessionId: string |
| 95 | expiresAt?: string |
| 96 | } |
| 97 | |
| 98 | /** 默认授权倒计时时间(秒) */ |
| 99 | export const DEFAULT_AUTH_COUNTDOWN = 300 |
| 100 | |
| 101 | /** 轮询间隔(毫秒) */ |
| 102 | export const POLLING_INTERVAL = 2000 |
| 103 |