diff --git a/frontend/app/features/apiAdapters.test.ts b/frontend/app/features/apiAdapters.test.ts index a0ca3a0..feb29be 100644 --- a/frontend/app/features/apiAdapters.test.ts +++ b/frontend/app/features/apiAdapters.test.ts @@ -29,7 +29,7 @@ import { appendCardData,batchCreateCards,createCard,deleteCard,getCardDetails,ge import { getChatMessagePage,getChatMessages,getChatSessionPage,getChatSessions,markChatRead,sendChatImage,sendChatMessage } from './chat/api'; import { getDashboardStats,getOrderAnalytics,getValidOrders } from './dashboard/api'; import { cancelItemPublishBatch,createItem,deleteItem,deleteItemPublishBatch,getItemDetail,getItemPublishBatch,getItemPublishBatches,getItems,previewItemPublishBatch,publishItem,recommendPublishCategory,retryFailedItemPublishBatch,startItemPublishBatch,syncItemsFromAccount,updateItem } from './items/api'; -import { createNotificationChannel,deleteAccountNotifications,deleteMessageNotification,deleteNotificationChannel,getAccountBindings,getMessageNotifications,getNotificationChannels,setAccountBindings,setMessageNotification,testNotificationChannel,updateNotificationChannel } from './notifications/api'; +import { createNotificationChannel,deleteAccountNotifications,deleteMessageNotification,deleteNotificationChannel,getAccountBindings,getMessageNotifications,getNotificationChannels,setAccountBindings,setMessageNotification,testNotificationChannel,updateNotificationChannel,updateSystemSettings as updateNotificationSystemSettings } from './notifications/api'; import { cancelOrderRefreshJob,deleteOrder,getAdminStats,getOrderDetail,getOrders,importOrders,manualShipOrder,syncOrders,syncSingleOrder,updateOrder } from './orders/api'; import { clearDefaultReplyRecords,deleteDefaultReply,deleteReplyRule,deleteShippingRule,getAutomationIssues,getDefaultReplies,getDefaultReply,getReplyRules,getShippingRules,getShippingRulesPage,resolveAutomationRun,resolveDeferredAutomationTask,updateDefaultReply,updateReplyRule,updateShippingRule } from './rules/api'; import { initializeAdmin,login,logout,verifySession } from './session/api'; @@ -89,6 +89,18 @@ test('updateSystemSettings separates sensitive values into explicit commands', / }); }); +test('notification SMTP settings separate the authorization code into a secret command', /* 当前回调验证通知页不会把 SMTP 授权码写入普通设置。 */ async () => { + // fetchMock 是通知页系统设置更新请求的 HTTP 替身。 + const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); + stubContractFetch(fetchMock); + await updateNotificationSystemSettings({ smtp_server: 'smtp.example.com', smtp_port: 465, smtp_user: 'sender@example.com', smtp_password: 'test-smtp-secret' }); + // payload 是通知页适配器分流后的普通设置和敏感命令。 + const payload = JSON.parse(fetchMock.mock.calls[0][1].body); + expect(payload.values).toEqual({ smtp_server: 'smtp.example.com', smtp_port: 465, smtp_user: 'sender@example.com' }); + expect(payload.secrets).toEqual({ smtp_password: { action: 'replace', value: 'test-smtp-secret' } }); + expect(payload.values).not.toHaveProperty('smtp_password'); +}); + test('health API exposes build metadata through the request boundary', async () => { // fetchMock 是健康检查 API 的请求替身。 const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ version: '1.2.3', commit: 'abc123' })); diff --git a/frontend/app/features/notifications/api.ts b/frontend/app/features/notifications/api.ts index eea7647..0c5cac2 100644 --- a/frontend/app/features/notifications/api.ts +++ b/frontend/app/features/notifications/api.ts @@ -1,4 +1,5 @@ import type { MutationIDResponse,NotificationBinding,NotificationChannel,NotificationChannelResponse,NotificationEventType,OperationResponse,SystemSettings } from './models'; +import { normalizeSystemSettingsUpdate } from '../../../shared/api-contract/settings'; import { type RequestControlOptions } from '../../../shared/http/client'; import { contractClient, runContractRequest } from '../../../shared/api-contract/client'; export type * from './models'; @@ -128,4 +129,4 @@ export const getSystemSettings = async (options?: RequestControlOptions): Promis }; /** 保存通知 SMTP 编辑器提交的系统设置。 */ -export const updateSystemSettings = async (settings: Partial, options?: RequestControlOptions): Promise => runContractRequest(/* signal 控制系统设置更新请求的取消和超时。 */ signal => contractClient.PUT('/api/v1/settings/system', { body: settings as never, signal }), options); +export const updateSystemSettings = async (settings: Partial, options?: RequestControlOptions): Promise => runContractRequest(/* signal 控制系统设置更新请求的取消和超时。 */ signal => contractClient.PUT('/api/v1/settings/system', { body: normalizeSystemSettingsUpdate(settings), signal }), options); diff --git a/frontend/app/features/settings/api.ts b/frontend/app/features/settings/api.ts index 1eadc36..6786cfe 100644 --- a/frontend/app/features/settings/api.ts +++ b/frontend/app/features/settings/api.ts @@ -1,7 +1,11 @@ import type { OperationResponse,SystemSettings } from './models'; import { contractClient, runContractRequest } from '../../../shared/api-contract/client'; +import { normalizeSystemSettingsUpdate,SENSITIVE_SYSTEM_SETTING_KEYS } from '../../../shared/api-contract/settings'; import { type RequestControlOptions } from '../../../shared/http/client'; +import type { SystemSettingsUpdate } from '../../../shared/api-contract/settings'; export type * from './models'; +export { normalizeSystemSettingsUpdate } from '../../../shared/api-contract/settings'; +export type { SensitiveSettingChange,SystemSettingsUpdate } from '../../../shared/api-contract/settings'; /** 设置页面使用的会话状态传输契约,避免跨 feature 依赖。 */ export interface SettingsSessionStatusResponse { @@ -17,43 +21,6 @@ export interface SettingsSessionStatusResponse { is_admin?: boolean; } -/** 敏感系统设置的显式三态变更命令。 */ -export type SensitiveSettingChange = { - /** 敏感值的保存策略。 */ - action: 'retain' | 'replace' | 'clear'; - /** replace 策略需要保存的新值,只存在于提交请求中。 */ - value?: string; -}; - -/** 系统设置更新请求,将普通配置与敏感命令分开传输。 */ -export type SystemSettingsUpdate = { - /** 非敏感配置字段。 */ - values?: Record; - /** 由服务端解释的敏感值变更命令。 */ - secrets?: Record; -}; - -/** SENSITIVE_SYSTEM_SETTING_KEYS 标识不得写入普通 values 的秘密键。 */ -const SENSITIVE_SYSTEM_SETTING_KEYS = new Set(['ai_api_key', 'smtp_password', 'qq_reply_secret_key', 'captcha.remote_secret_key']); - -/** 将历史设置草稿转换为服务端要求的普通值与敏感命令结构。 */ -const normalizeSystemSettingsUpdate = (settings: Partial | SystemSettingsUpdate): SystemSettingsUpdate => { - if ('values' in settings || 'secrets' in settings) return settings as SystemSettingsUpdate; - // values 保存普通设置,永不容纳秘密文本。 - const values: Record = {}; - // secrets 保存服务端需要独立处理的敏感设置命令。 - const secrets: Record = {}; - for (const /* key、value 是当前待分流的设置键和值。 */ [key, value] of Object.entries(settings)) { - if (value === undefined || value === null) continue; - if (SENSITIVE_SYSTEM_SETTING_KEYS.has(key)) { - secrets[key] = value === '' ? { action: 'clear' } : { action: 'replace', value: String(value) }; - continue; - } - if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') values[key] = value; - } - return Object.keys(secrets).length > 0 ? { values, secrets } : values; -}; - /** 将服务端可兼容的字符串和数值设置归一为 UI 可消费的只读契约。 */ const normalizeSettings = (settings: Record): SystemSettings => { // result 是不修改原始响应的设置副本。 diff --git a/frontend/shared/api-contract/settings.ts b/frontend/shared/api-contract/settings.ts index 976095c..474d38c 100644 --- a/frontend/shared/api-contract/settings.ts +++ b/frontend/shared/api-contract/settings.ts @@ -1,7 +1,49 @@ -// settings 只公开 OpenAPI 生成的设置传输类型;表单状态属于 settings feature。 +// settings 只公开 OpenAPI 生成的设置传输类型和跨 feature 共用的更新契约;表单状态属于各自 feature。 import type { components } from './generated/schema'; /** SystemSettingsTransport 表示受约束动态键的设置响应。 */ export type SystemSettingsTransport = components['schemas']['SystemSettingsResponse']; /** AIModelsTransport 表示生成的模型发现响应。 */ export type AIModelsTransport = components['schemas']['AIModelsResponse']; + +/** 敏感系统设置的显式三态变更命令。 */ +export type SensitiveSettingChange = { + /** 敏感值的保存策略。 */ + action: 'retain' | 'replace' | 'clear'; + /** replace 策略需要保存的新值,只存在于提交请求中。 */ + value?: string; +}; + +/** 系统设置更新请求,将普通配置与敏感命令分开传输。 */ +export type SystemSettingsUpdate = { + /** 非敏感配置字段。 */ + values?: Record; + /** 由服务端解释的敏感值变更命令。 */ + secrets?: Record; +}; + +/** SENSITIVE_SYSTEM_SETTING_KEYS 标识不得写入普通 values 的秘密键。 */ +export const SENSITIVE_SYSTEM_SETTING_KEYS = new Set([ + 'ai_api_key', + 'smtp_password', + 'qq_reply_secret_key', + 'captcha.remote_secret_key', +]); + +/** 将各 feature 的设置草稿转换为服务端要求的普通值与敏感命令结构。 */ +export const normalizeSystemSettingsUpdate = (settings: Record | SystemSettingsUpdate): SystemSettingsUpdate => { + if ('values' in settings || 'secrets' in settings) return settings as SystemSettingsUpdate; + // values 保存普通设置,永不容纳秘密文本。 + const values: Record = {}; + // secrets 保存服务端需要独立处理的敏感设置命令。 + const secrets: Record = {}; + for (const /* key、value 是当前待分流的设置键和值。 */ [key, value] of Object.entries(settings)) { + if (value === undefined || value === null) continue; + if (SENSITIVE_SYSTEM_SETTING_KEYS.has(key)) { + secrets[key] = value === '' ? { action: 'clear' } : { action: 'replace', value: String(value) }; + continue; + } + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') values[key] = value; + } + return Object.keys(secrets).length > 0 ? { values, secrets } : values; +}; diff --git a/internal/webui/static/assets/Chat-8cCRP4iO.js b/internal/webui/static/assets/Chat-Di7cjGAh.js similarity index 99% rename from internal/webui/static/assets/Chat-8cCRP4iO.js rename to internal/webui/static/assets/Chat-Di7cjGAh.js index 68de1d6..9dba7d4 100644 --- a/internal/webui/static/assets/Chat-8cCRP4iO.js +++ b/internal/webui/static/assets/Chat-Di7cjGAh.js @@ -1 +1 @@ -import{d as E,j as e,a}from"./react-vendor-Bf9ELcll.js";import{L as pe}from"./vendor-BE-_xUHH.js";import{B as me}from"./audio-codec-mjVr_wwJ.js";import{L as G,an as de,ao as ge,u as xe,ap as ue,aq as he,M as Q0,V as _e,R as be,ag as D0,m as fe,ar as je,x as J0,as as we,at as Ne,au as ye,av as Ce,S as W0,X as Oe}from"./icons-vendor-BSp7PTZg.js";import{a as U0,i as R,d as i0,e as V0,f as z0,m as Z0,h as ve,j as ke,k as q0,l as Se,s as Re,n as Ee,o as Ie,p as Me,g as Le,q as G0,u as $0,t as P0,C as De}from"./chat-metadata-74T0w35U.js";import{p as Ue,s as qe}from"./index-dO7JyNQY.js";const H0="ydisks:chat-audio-play",Pe=[6,10,15,8,17,12,7,16,11,6,14,9];function Te(u){const _=u.trim();if(typeof location>"u"||location.protocol!=="https:")return _;try{const n=new URL(_);return n.protocol==="http:"&&n.hostname.endsWith(".aliyuncs.com")&&(n.protocol="https:"),n.toString()}catch{return _}}function T0(u){const _=Number.isFinite(u)?Math.max(0,Math.floor(u)):0,n=Math.floor(_/60),l=_%60;return`${n}:${l.toString().padStart(2,"0")}`}function A0(u){window.dispatchEvent(new CustomEvent(H0,{detail:u}))}const Ae=({messageKey:u,src:_,outgoing:n,initialDuration:l=0})=>{const x=E.useRef(null),C=E.useRef(0),[o,I]=E.useState("idle"),[M,L]=E.useState(l),[V,T]=E.useState(0);E.useEffect(()=>(()=>{var d;C.current+=1,(d=x.current)==null||d.destroy(),x.current=null}),[_]),E.useEffect(()=>{L(Math.max(0,l))},[l]),E.useEffect(()=>{const d=f=>{const w=f.detail,N=x.current;w!==u&&(N!=null&&N.isPlaying())&&N.pause()};return window.addEventListener(H0,d),(()=>window.removeEventListener(H0,d))},[u]),E.useEffect(()=>{if(o!=="playing")return;const d=window.setInterval(()=>{const f=x.current;f&&T(f.getCurrentPosition())},100);return(()=>window.clearInterval(d))},[o]);const A=(d,f)=>{const w=()=>C.current===f&&x.current===d;d.onPlay(()=>{w()&&I("playing")}),d.onResume(()=>{w()&&I("playing")}),d.onPause(()=>{w()&&I("paused")}),d.onStop(()=>{w()&&(I("idle"),T(0))}),d.onEnded(()=>{w()&&(I("idle"),T(0))})},r0=async()=>{var w;const d=x.current;if(d!=null&&d.isPlaying()){d.pause();return}if(d!=null&&d.isPaused()){A0(u),d.resume();return}if(d!=null&&d.isInit()){A0(u),d.play();return}if(o==="loading")return;const f=C.current+1;C.current=f,I("loading"),T(0);try{const N=new me;if(x.current=N,A(N,f),await N.initWithUrl(Te(_)),C.current!==f||x.current!==N){N.destroy();return}L(N.getDuration()||Math.max(0,l)),A0(u),N.play()}catch{if(C.current!==f)return;(w=x.current)==null||w.destroy(),x.current=null,I("error"),T(0)}},H=o==="playing"||o==="paused"?V:M,$=M>0?o==="playing"||o==="paused"?`${T0(H)} / ${T0(M)}`:T0(M):"--:--",P=o==="loading"?"正在解码":o==="playing"?"正在播放":o==="paused"?"已暂停":o==="error"?"加载失败,点击重试":"语音消息",O=o==="playing"?"暂停语音消息":o==="paused"?"继续播放语音消息":o==="error"?"重新加载语音消息":o==="loading"?"正在加载语音消息":"播放语音消息";return e.jsxs("div",{className:`flex h-11 min-w-56 items-center gap-2 rounded-2xl border px-2 shadow-sm ${n?"rounded-br-md border-sky-400 bg-sky-500 text-white":"rounded-bl-md border-slate-200 bg-white text-slate-800"}`,children:[e.jsx("button",{type:"button","aria-label":O,title:O,disabled:o==="loading",onClick:(()=>void r0()),className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-full transition focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-wait ${n?"bg-white text-sky-600 hover:bg-sky-50 focus-visible:ring-white":"bg-sky-50 text-sky-600 hover:bg-sky-100 focus-visible:ring-sky-400"}`,children:o==="loading"?e.jsx(G,{className:"h-4 w-4 animate-spin"}):o==="playing"?e.jsx(de,{className:"h-4 w-4 fill-current"}):o==="error"?e.jsx(ge,{className:"h-4 w-4"}):e.jsx(xe,{className:"ml-px h-4 w-4 fill-current"})}),e.jsxs("div",{className:"min-w-0 flex flex-1 items-center gap-2",children:[e.jsx("div",{className:"flex h-5 flex-1 items-center gap-0.5","aria-hidden":"true",children:Pe.map((d,f)=>e.jsx("span",{className:`w-0.5 rounded-full ${o==="playing"?"animate-pulse":""} ${n?"bg-sky-100":o==="error"?"bg-red-300":"bg-sky-400"}`,style:{height:`${d}px`,animationDelay:`${f*45}ms`}},`${u}-${f}`))}),e.jsx("span",{className:`shrink-0 font-mono text-[11px] font-semibold tabular-nums ${n?"text-sky-100":o==="error"?"text-red-500":"text-slate-500"}`,children:$}),e.jsx("span",{className:"sr-only",children:P})]})]})},X0=[["尊嘟假嘟","https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp"],["鸡哔你","https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp"],["谁懂啊","https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp"],["吗喽","https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp"],["功德+1","https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp"],["city不city啊","https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp"],["激推","https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp"],["微笑","https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp"],["龇牙","https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp"],["流泪","https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp"],["尴尬","https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp"],["撇嘴","https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp"],["破涕为笑","https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp"],["捂脸哭","https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp"],["害羞","https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp"],["感动","https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp"],["滴泪","https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp"],["暗中观察","https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp"],["偷笑","https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp"],["ok","https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp"],["送花","https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp"],["大哭","https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp"],["色","https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp"],["惊慌","https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp"],["惊讶","https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp"],["得意","https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp"],["睡","https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp"],["不好意思","https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp"],["托腮","https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["发怒","https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp"],["难过","https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp"],["调皮","https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp"],["愉快","https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp"],["白眼","https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp"],["拒绝","https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp"],["期待","https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp"],["困","https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp"],["流汗","https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp"],["憨笑","https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp"],["耶","https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp"],["奋斗","https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp"],["咒骂","https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp"],["疑问","https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp"],["嘘","https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp"],["晕","https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp"],["开心到模糊","https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp"],["衰","https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp"],["委屈","https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp"],["再见","https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp"],["鼓掌","https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp"],["吐","https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp"],["坏笑","https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp"],["抠鼻","https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp"],["叹气","https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp"],["无聊","https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp"],["思考","https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp"],["呆","https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["哇哦","https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp"],["飞吻","https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp"],["好喜欢","https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp"],["拜托","https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp"],["真棒","https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp"],["流鼻血","https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp"],["费解","https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp"],["秃头","https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp"],["嘿哈","https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp"],["吃土","https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp"],["机智","https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp"],["举杯","https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp"],["握手","https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp"],["挥手","https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp"],["yeah","https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp"],["666","https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp"],["棒","https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp"],["爱你","https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp"],["比心","https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp"],["感谢","https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp"],["拍手","https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp"],["拉钩","https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp"],["没钱","https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp"],["小刀","https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp"],["不刀","https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp"],["同出","https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp"],["递钱","https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp"],["数钱","https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp"],["打call","https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp"],["号外","https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp"],["包邮","https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp"],["求赞","https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp"],["非主流","https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp"],["吃瓜","https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp"],["种草","https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp"],["佛系","https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp"],["超便宜","https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp"],["拥抱","https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp"],["摊手","https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp"],["举手","https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp"],["蹲","https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp"],["跪了","https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp"],["拜","https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp"],["排","https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp"],["旺财","https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp"],["招财猫","https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp"],["酸了","https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp"],["鸭鸭","https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp"],["方了","https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp"],["白菜","https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp"],["桃子","https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp"],["打包","https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp"],["沙发","https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["南","https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp"],["盯","https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp"],["hot","https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp"],["new","https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp"],["cool","https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp"],["1","https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp"],["可","https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp"],["搬砖","https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp"],["菜狗","https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp"],["开心面具","https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp"],["快递","https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["裂开","https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp"],["啤酒","https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp"],["瑞思拜","https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp"],["小丑","https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp"],["爱心","https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp"]],He=u=>u,Fe=new Map(X0.map(([u,_])=>[u,_])),Be=u=>u.split(/(\[[^\]]+\])/g).map((_,n)=>{const l=_.startsWith("[")?Fe.get(_.slice(1,-1)):void 0;return l?e.jsx("img",{src:l,alt:_,title:_,className:"mx-0.5 inline-block h-7 w-7 align-middle"},n):e.jsx(E.Fragment,{children:_},n)}),Qe=()=>{const[u,_]=a.useState([]),[n,l]=a.useState(""),[x,C]=a.useState({}),[o,I]=a.useState(""),[M,L]=a.useState([]),[V,T]=a.useState(""),[A,r0]=a.useState(!1),[H,$]=a.useState(""),[P,O]=a.useState(null),[d,f]=a.useState(!0),[w,N]=a.useState(!1),[X,j0]=a.useState(!1),[l0,w0]=a.useState(!1),[N0,c0]=a.useState(),[o0,p0]=a.useState({}),[m0,d0]=a.useState({}),[g0,x0]=a.useState(!1),[S0,R0]=a.useState(!1),[v,Y]=a.useState(!1),[u0,k]=a.useState(""),[E0,I0]=a.useState("connecting"),[K,y0]=a.useState(null),[z,C0]=a.useState(null),Z=a.useRef(""),F=a.useRef(""),e0=a.useRef(null),t0=a.useRef({accountID:"",chatID:""}),s0=a.useRef(!0),J=a.useRef(!1),U=a.useRef(null),h0=a.useRef(new Set),s=a.useRef(0),h=a.useRef(null),S=a.useRef(0),B=a.useRef(null),q=a.useRef(0),_0=a.useRef(null),b0=a.useRef(0),O0=a.useRef(null),Q=a.useRef(0),a0=a.useRef(null);a.useEffect(()=>{Z.current=n},[n]),a.useEffect(()=>{F.current=o},[o]);const f0=a.useCallback(async t=>{var p;const i=++s.current;(p=h.current)==null||p.abort();const c=new AbortController;h.current=c;try{const r=await U0(t,void 0,{signal:c.signal},!0);if(!R(s.current,i,c.signal))return[];const g=r.sessions.map(m=>t===Z.current&&m.chat_id===F.current?{...m,unread_count:0}:m);return C(m=>({...m,[t]:g})),p0(m=>({...m,[t]:r.next_cursor})),d0(m=>({...m,[t]:r.has_more})),g}catch(r){return R(s.current,i,c.signal)&&!i0(r)&&k(r instanceof Error?r.message:"同步会话失败"),[]}},[]);a.useEffect(()=>{const t=new AbortController;return(async()=>{var c;f(!0);try{const[p,r]=await Promise.all([Le({signal:t.signal}),G0({signal:t.signal})]),m=p.map(y=>{var W,B0;return{...y,runtime_state:((W=r[y.id])==null?void 0:W.state)||(y.enabled?"connecting":"disabled"),runtime_connected:((B0=r[y.id])==null?void 0:B0.connected)===!0}}).filter(y=>y.enabled),j=await Promise.all(m.map(async y=>[y.id,await U0(y.id,void 0,{signal:t.signal})]));if(t.signal.aborted)return;_(m),C(Object.fromEntries(j.map(([y,W])=>[y,W.sessions]))),p0(Object.fromEntries(j.map(([y,W])=>[y,W.next_cursor]))),d0(Object.fromEntries(j.map(([y,W])=>[y,W.has_more])));const D=window.localStorage.getItem("ydisks.chat.account.v1")||"",L0=m.some(y=>y.id===D)?D:((c=m[0])==null?void 0:c.id)||"";l(L0)}catch(p){t.signal.aborted||k(p instanceof Error?p.message:"加载聊天数据失败")}finally{t.signal.aborted||f(!1)}})(),(()=>t.abort())},[]),a.useEffect(()=>{let t=!1,i=0,c=null;const p=async()=>{c=new AbortController;try{const r=await G0({signal:c.signal,timeoutMs:1e4});t||_(g=>g.map(m=>{var j,D;return{...m,runtime_state:((j=r[m.id])==null?void 0:j.state)||m.runtime_state,runtime_connected:((D=r[m.id])==null?void 0:D.connected)??m.runtime_connected}}))}catch{}finally{t||(i=window.setTimeout(p,3e3))}};return i=window.setTimeout(p,3e3),(()=>{t=!0,window.clearTimeout(i),c==null||c.abort()})},[]),a.useEffect(()=>{if(!n)return;window.localStorage.setItem("ydisks.chat.account.v1",n);const t=x[n]||[];I(i=>{var c;return t.some(p=>p.chat_id===i)?i:((c=t[0])==null?void 0:c.chat_id)||""})},[n,x]),a.useEffect(()=>{const t=Object.keys(x).length;if(d||u.length>0&&t===0)return;const i=Object.values(x).some(c=>c.some(p=>p.unread_count>0));Ue(i)},[u.length,d,x]),a.useEffect(()=>{!n||h0.current.has(n)||(h0.current.add(n),f0(n))},[n,f0]),a.useEffect(()=>{var c,p;if(!n||!o){S.current+=1,q.current+=1,(c=_0.current)==null||c.abort(),J.current=!1,L([]);return}const t=++S.current;(p=B.current)==null||p.abort();const i=new AbortController;return B.current=i,N(!0),V0(n,o,void 0,void 0,{signal:i.signal}).then(r=>{if(!R(S.current,t,i.signal))return;const g=z0(r.messages,o);Z0(n,o,g,{signal:i.signal}),L(r.messages),w0(r.has_more),c0(r.next_cursor),r.session&&C(m=>({...m,[n]:(m[n]||[]).map(j=>{var D;return j.chat_id===((D=r.session)==null?void 0:D.chat_id)?r.session:j})})),C(m=>({...m,[n]:(m[n]||[]).map(j=>j.chat_id===o?{...j,unread_count:0}:j)}))}).catch(r=>{R(S.current,t,i.signal)&&!i0(r)&&k(r instanceof Error?r.message:"加载消息失败")}).finally(()=>{R(S.current,t,i.signal)&&N(!1)}),(()=>i.abort())},[n,o]),a.useEffect(()=>{var t;(t=O0.current)==null||t.abort(),b0.current+=1},[n]),a.useEffect(()=>{var t;(t=a0.current)==null||t.abort(),Q.current+=1},[n,o]),a.useEffect(()=>{O(null)},[n,o]),a.useEffect(()=>{var t;q.current+=1,(t=_0.current)==null||t.abort(),J.current=!1},[n,o]),a.useEffect(()=>(()=>{var t,i,c,p,r;(t=h.current)==null||t.abort(),(i=B.current)==null||i.abort(),q.current+=1,(c=_0.current)==null||c.abort(),(p=O0.current)==null||p.abort(),(r=a0.current)==null||r.abort()}),[]),a.useEffect(()=>{const t=P;return(()=>{t&&URL.revokeObjectURL(t.url)})},[P]);const Y0=a.useCallback(async()=>{var g,m;if(!n||!o||X||!l0)return;const t=e0.current,i=(t==null?void 0:t.scrollHeight)||0,c=S.current,p=++q.current;(g=_0.current)==null||g.abort();const r=new AbortController;_0.current=r,J.current=!0,j0(!0),k("");try{const j=(m=M[0])==null?void 0:m.id,D=await V0(n,o,N0,j,{signal:r.signal});if(!R(S.current,c,r.signal)||p!==q.current)return;L(L0=>ve(L0,D.messages)),w0(D.has_more),c0(D.next_cursor),requestAnimationFrame(()=>{p===q.current&&!r.signal.aborted&&t&&(t.scrollTop+=t.scrollHeight-i)})}catch(j){J.current=!1,i0(j)||k(j instanceof Error?j.message:"加载历史消息失败")}finally{p===q.current&&j0(!1)}},[n,o,l0,N0,M,X]),F0=a.useCallback(t=>{const i=t.account_id;if(C(c=>{const p=c[i]||[];return p.some(g=>g.chat_id===t.chat_id)?{...c,[i]:p.map(g=>g.chat_id===t.chat_id?{...g,last_message:t.content,last_message_at:t.sent_at,unread_count:t.direction==="incoming"&&t.message_type!=="system"&&(Z.current!==i||F.current!==t.chat_id)?g.unread_count+1:g.unread_count}:g).sort((g,m)=>m.last_message_at-g.last_message_at)}:(f0(i),c)}),Z.current===i&&F.current===t.chat_id&&(L(c=>ke(q0(c,t),t)),t.direction==="incoming"&&t.message_type!=="system")){const c=z0([t],t.chat_id);Z0(i,t.chat_id,c)}},[f0]);a.useEffect(()=>qe(i=>{if(i.type==="connection"){I0(i.state);return}F0(i.message)}),[F0]);const K0=a.useCallback(()=>{const t=e0.current;if(!t)return;const i=t.scrollHeight-t.scrollTop-t.clientHeight;s0.current=i<=48},[]);a.useLayoutEffect(()=>{const t=t0.current.accountID!==n||t0.current.chatID!==o;t0.current={accountID:n,chatID:o},t&&(s0.current=!0);const i=e0.current;if(i){if(J.current){J.current=!1;return}(w||s0.current)&&(i.scrollTop=i.scrollHeight)}},[n,o,M,w]);const ee=u.find(t=>t.id===n),v0=x[n]||[],b=v0.find(t=>t.chat_id===o),te=a.useMemo(()=>Se(v0,V,A),[v0,V,A]),se=a.useCallback(t=>(x[t]||[]).reduce((i,c)=>i+c.unread_count,0),[x]),ae=a.useCallback(async()=>{var p;if(!n||g0||!m0[n])return;const t=++b0.current;(p=O0.current)==null||p.abort();const i=new AbortController;O0.current=i;const c=n;x0(!0),k("");try{const r=await U0(c,o0[c],{signal:i.signal},!0);if(!R(b0.current,t,i.signal))return;C(g=>({...g,[c]:r.sessions})),p0(g=>({...g,[c]:r.next_cursor})),d0(g=>({...g,[c]:r.has_more}))}catch(r){R(b0.current,t,i.signal)&&!i0(r)&&k(r instanceof Error?r.message:"加载历史联系人失败")}finally{R(b0.current,t,i.signal)&&x0(!1)}},[n,o0,g0,m0]),n0=a.useCallback(async(t,i,c)=>{var g;if(!b||!n||v)return;const p=++Q.current;(g=a0.current)==null||g.abort();const r=new AbortController;a0.current=r,Y(!0),k("");try{const m=await Re({account_id:n,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,item_id:b.item_id,item_title:b.item_title,text:t},{signal:r.signal});if(!R(Q.current,p,r.signal))return;c&&$(""),y0(null),L(j=>q0(j,m.message))}catch(m){R(Q.current,p,r.signal)&&(i&&y0(t),i0(m)||k(m instanceof Error?m.message:"消息发送失败"))}finally{R(Q.current,p,r.signal)&&Y(!1)}},[n,b,v]),k0=a.useCallback(async(t,i)=>{var r;if(!b||!n||v)return;const c=++Q.current;(r=a0.current)==null||r.abort();const p=new AbortController;a0.current=p,Y(!0),k("");try{const g=await Ee({account_id:n,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,buyer_avatar_url:b.buyer_avatar_url,item_id:b.item_id,item_title:b.item_title,image:t},{signal:p.signal});if(!R(Q.current,c,p.signal))return;C0(null),L(m=>q0(m,g.message))}catch(g){R(Q.current,c,p.signal)&&(i&&C0(t),i0(g)||k(g instanceof Error?g.message:"图片发送失败"))}finally{R(Q.current,c,p.signal)&&(Y(!1),U.current&&(U.current.value=""))}},[n,b,v]),ne=a.useCallback(async()=>{const t=H.trim();!t||!b||!n||v||await n0(t,!0,!0)},[n,H,b,n0,v]),ie=a.useCallback(async t=>{const i=t.trim();!i||!b||!n||v||await n0(i,!0,!1)},[n,b,n0,v]),M0=a.useCallback(async t=>{if(!(!t||!b||!n||v)){if(!t.type.startsWith("image/")){k("仅支持粘贴/发送图片文件");return}k(""),O({file:t,url:URL.createObjectURL(t)})}},[n,b,v]),re=a.useCallback(async t=>{const i=t.find(c=>c.type.startsWith("image/"));i&&await M0(i)},[M0]),le=a.useCallback(()=>{O(null),U.current&&(U.current.value="")},[]),ce=a.useCallback(async()=>{if(!P||!b||!n||v)return;const t=P.file;O(null),await k0(t,!0)},[n,P,b,k0,v]),oe=a.useCallback(async()=>{K?await n0(K,!1,!0):z&&await k0(z,!1)},[z,K,k0,n0]);return{accounts:u,activeAccountID:n,activeSessions:v0,selectedSession:b,activeAccount:ee,messages:M,search:V,unreadOnly:A,draft:H,loading:d,messagesLoading:w,olderLoading:X,hasOlder:l0,contactsLoading:g0,hasMoreContacts:m0[n]===!0,emojiOpen:S0,sending:v,error:u0,liveState:E0,pendingImage:P,activeChatID:o,filteredSessions:te,scrollRef:e0,imageInputRef:U,setActiveAccountID:l,setActiveChatID:I,setSearch:T,setUnreadOnly:r0,setDraft:$,setEmojiOpen:R0,reloadSessions:f0,loadMoreContacts:ae,loadOlderMessages:Y0,handleMessageScroll:K0,handleSend:ne,handleQuickReply:ie,handleImage:M0,handlePastedImages:re,confirmSendImage:ce,closeImagePreview:le,retrySend:oe,retryAvailable:!!(K||z),unreadForAccount:se,emojiURL:He,xianyuEmojis:X0,renderXianyuText:Be,formatClock:Me,messageTime:Ie}},$e=()=>{const{accounts:u,activeAccountID:_,activeChatID:n,activeAccount:l,selectedSession:x,filteredSessions:C,messages:o,search:I,unreadOnly:M,draft:L,loading:V,messagesLoading:T,olderLoading:A,hasOlder:r0,contactsLoading:H,hasMoreContacts:$,emojiOpen:P,sending:O,error:d,liveState:f,pendingImage:w,scrollRef:N,imageInputRef:X,setActiveAccountID:j0,setActiveChatID:l0,setSearch:w0,setUnreadOnly:N0,setDraft:c0,setEmojiOpen:o0,reloadSessions:p0,loadMoreContacts:m0,loadOlderMessages:d0,handleMessageScroll:g0,handleSend:x0,handleQuickReply:S0,handleImage:R0,handlePastedImages:v,confirmSendImage:Y,closeImagePreview:u0,retrySend:k,retryAvailable:E0,unreadForAccount:I0,emojiURL:K,xianyuEmojis:y0,renderXianyuText:z,formatClock:C0,messageTime:Z}=Qe(),F=E.useMemo(()=>o.filter(s=>s.message_type==="image"),[o]),e0=E.useMemo(()=>F.map(s=>({src:s.content,alt:"聊天图片"})),[F]),[t0,s0]=E.useState(-1),J=E.useCallback(s=>{s0(F.findIndex(h=>h.message_key===s))},[F]),[U,h0]=E.useState(!1);return V?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(G,{className:"h-8 w-8 animate-spin text-sky-500"})}):e.jsxs("section",{className:"flex h-[calc(100vh-4rem)] min-h-[560px] flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-chat",children:[e.jsxs("header",{className:"border-b border-slate-200 bg-slate-50/70 px-5 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black tracking-tight text-slate-950",children:"在线聊天"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-slate-500",children:"复用账号实时连接,消息按账号完全隔离"})]}),e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-xs font-bold ${f==="online"?"bg-emerald-50 text-emerald-700":f==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[f==="online"?e.jsx(ue,{className:"h-3.5 w-3.5"}):e.jsx(he,{className:"h-3.5 w-3.5"}),f==="online"?"实时同步中":f==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:u.map(s=>{const h=s.id===_,S=I0(s.id),B=P0(S),q=s.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":h,onClick:(()=>j0(s.id)),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${h?"border-sky-500 text-sky-700":"border-transparent text-slate-500 hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${q?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:s.nickname||s.remark||s.id}),S>0&&e.jsx("span",{"aria-label":`未读消息 ${B} 条`,className:$0(S),children:B})]},s.id)})})]}),u.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(Q0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-800",children:"暂无启用账号"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"先在账号管理中启用账号,聊天会话会自动出现。"})]}):e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden grid-cols-[320px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"flex min-h-0 flex-col border-r border-slate-200 bg-slate-50/40",children:[e.jsxs("div",{className:"space-y-3 border-b border-slate-200 p-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(_e,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:I,onChange:(s=>w0(s.target.value)),placeholder:"搜索用户、商品或消息",className:"h-10 w-full rounded-xl border border-slate-200 bg-white pl-9 pr-3 text-sm outline-none transition focus:border-sky-400 focus:ring-2 focus:ring-sky-100"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:(()=>N0(s=>!s)),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${M?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:M?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:(()=>void p0(_)),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(be,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[C.map(s=>e.jsxs("button",{type:"button",onClick:(()=>l0(s.chat_id)),className:`flex w-full gap-3 border-b border-slate-100 p-3.5 text-left transition-colors ${s.chat_id===n?"bg-white shadow-chat-active":"hover:bg-white/80"}`,children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-slate-200 text-slate-500",children:s.buyer_avatar_url?e.jsx("img",{src:s.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"truncate text-sm font-extrabold text-slate-900",children:s.buyer_name||`用户 ${s.buyer_id}`})}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-xs text-slate-500",children:s.last_message||"暂无消息"}),s.unread_count>0&&e.jsx("span",{"aria-label":`未读消息 ${P0(s.unread_count)} 条`,className:`ml-auto ${$0(s.unread_count)}`,children:P0(s.unread_count)})]}),s.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",s.item_title]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-slate-400",children:C0(s.last_message_at)}),s.item_image_url&&e.jsx("img",{src:s.item_image_url,alt:"",className:"h-9 w-11 rounded-[4px] border border-slate-200 object-cover"})]})]},s.chat_id)),C.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),$&&!I&&!M&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:(()=>void m0()),disabled:H,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 text-xs font-bold text-slate-500 shadow-sm hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[H&&e.jsx(G,{className:"h-3.5 w-3.5 animate-spin"}),H?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsxs("main",{className:"relative flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:[x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-20 shrink-0 items-start border-b border-slate-200 bg-white px-5 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-black text-slate-950",children:x.buyer_name||x.buyer_id}),e.jsxs("div",{className:"mt-0.5 flex flex-col text-xs text-slate-500",children:[e.jsx("span",{children:"用户 ID:"}),e.jsx("span",{className:"truncate",children:x.buyer_id})]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(l==null?void 0:l.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(l==null?void 0:l.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:N,onScroll:g0,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:T?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(G,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[r0&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:(()=>void d0()),disabled:A,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs font-bold text-slate-500 shadow-sm transition hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[A&&e.jsx(G,{className:"h-3.5 w-3.5 animate-spin"}),A?"正在加载":"加载更早消息"]})}),o.map(s=>{const h=s.direction==="outgoing";return s.message_type==="system"?e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500",children:[z(s.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:Z(s.sent_at)})]})},s.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${h?"justify-end":"justify-start"}`,children:[!h&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:x.buyer_avatar_url?e.jsx("img",{src:x.buyer_avatar_url,alt:x.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${h?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:h?(l==null?void 0:l.nickname)||(l==null?void 0:l.remark)||"我":x.buyer_name||s.sender_name||x.buyer_id}),s.message_type==="image"?e.jsx("button",{type:"button",title:"点击预览大图",onClick:J.bind(null,s.message_key),className:`block cursor-zoom-in overflow-hidden rounded-2xl border bg-white p-1 text-left shadow-sm ${h?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:s.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):s.message_type==="video"?e.jsx("video",{src:s.content,controls:!0,preload:"metadata",className:"max-h-80 max-w-full rounded-2xl bg-black"}):s.message_type==="audio"?e.jsx(Ae,{messageKey:s.message_key,src:s.content,outgoing:h,initialDuration:s.media_duration}):e.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-6 shadow-sm ${h?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:z(s.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[Z(s.sent_at),h&&(s.status==="failed"?e.jsx(fe,{className:"h-3 w-3 text-red-500","aria-label":"发送失败"}):s.read_status===2?e.jsx(je,{className:"h-3 w-3 text-sky-500","aria-label":"对方已读"}):s.status==="sent"?e.jsx(J0,{className:"h-3 w-3 text-sky-500","aria-label":"已发送未读"}):e.jsx(J0,{className:"h-3 w-3","aria-label":"发送中"}))]})]}),h&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:l!=null&&l.avatar_url?e.jsx("img",{src:l.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"m-2 h-5 w-5 text-sky-600"})})]},s.message_key)})]})}),d&&e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:[e.jsx("span",{children:d}),E0&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void k()),children:"重试发送"})]}),e.jsxs("div",{className:"relative z-10 shrink-0 border-t border-slate-200 bg-white p-4 shadow-chat-input",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:(()=>o0(s=>!s)),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"闲鱼表情",children:e.jsx(we,{className:"h-5 w-5"})}),P&&e.jsxs("div",{className:"absolute bottom-11 left-0 z-30 w-[360px] rounded-2xl border border-slate-200 bg-white p-3 shadow-2xl",children:[e.jsx("div",{className:"mb-2 text-xs font-bold text-slate-500",children:"全部表情"}),e.jsx("div",{className:"grid max-h-72 grid-cols-8 gap-1 overflow-y-auto",children:y0.map(([s,h])=>e.jsx("button",{type:"button",title:`[${s}]`,onClick:(()=>{c0(S=>S+`[${s}]`),o0(!1)}),className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:K(h),alt:`[${s}]`,className:"h-8 w-8 object-contain"})},s))})]})]}),e.jsx("input",{ref:X,type:"file",accept:"image/*",className:"hidden",onChange:(s=>{var h;return void R0((h=s.target.files)==null?void 0:h[0])})}),e.jsx("button",{type:"button",onClick:(()=>{var s;return(s=X.current)==null?void 0:s.click()}),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"发送图片(最大 10MB)",children:e.jsx(Ne,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:(()=>h0(!U)),className:"ml-auto rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600",title:U?"收起快捷回复":"展开快捷回复","aria-label":U?"收起快捷回复":"展开快捷回复",children:U?e.jsx(ye,{className:"h-5 w-5"}):e.jsx(Ce,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-2 transition focus-within:border-sky-400 focus-within:ring-2 focus-within:ring-sky-100",children:[e.jsx("textarea",{value:L,onChange:(s=>c0(s.target.value)),rows:2,maxLength:2e3,onKeyDown:(s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),x0())}),onPaste:(s=>{var B;const h=Array.from(((B=s.clipboardData)==null?void 0:B.files)||[]);h.find(q=>q.type.startsWith("image/"))&&(s.preventDefault(),v(h))}),disabled:(l==null?void 0:l.runtime_state)!=="online",placeholder:(l==null?void 0:l.runtime_state)==="online"?"输入消息,Enter 发送,Shift + Enter 换行,Ctrl + V 粘贴图片":"账号离线,暂时无法发送",className:"max-h-32 min-h-12 flex-1 resize-none bg-transparent px-2 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed"}),e.jsx("button",{type:"button",onClick:(()=>void x0()),disabled:!L.trim()||O||(l==null?void 0:l.runtime_state)!=="online",className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-sky-500 text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none","aria-label":"发送消息",children:O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(W0,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(Q0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-700",children:"选择一个用户开始聊天"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"该账号的新消息会实时出现在左侧列表。"})]}),e.jsx(De,{activeAccountID:_,selectedSession:x,quickReplyPanelOpen:U,closeQuickReplyPanel:(()=>h0(!1)),sendQuickReply:S0,sending:O,accountOnline:(l==null?void 0:l.runtime_state)==="online"})]})]}),w&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-950/60 p-4",onClick:u0,children:e.jsxs("div",{className:"flex max-h-full w-full max-w-2xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl",onClick:(s=>s.stopPropagation()),children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-slate-200 px-5 py-3",children:[e.jsx("div",{className:"text-sm font-black text-slate-900",children:"发送图片预览"}),e.jsx("button",{type:"button",title:"取消",onClick:u0,className:"rounded-lg p-1.5 text-slate-400 transition hover:bg-slate-100 hover:text-slate-700",children:e.jsx(Oe,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-slate-100 p-4",children:e.jsx("img",{src:w.url,alt:"待发送图片预览",className:"max-h-[55vh] max-w-full rounded-xl object-contain"})}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-slate-200 px-5 py-3",children:[e.jsxs("div",{className:"min-w-0 truncate text-xs text-slate-500",children:[w.file.name||"粘贴的图片"," · ",(w.file.size/1024).toFixed(0)," KB"]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:u0,className:"rounded-xl px-4 py-2 text-sm font-bold text-slate-600 transition hover:bg-slate-100",children:"取消"}),e.jsxs("button",{type:"button",onClick:(()=>void Y()),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"flex items-center gap-2 rounded-xl bg-sky-500 px-4 py-2 text-sm font-bold text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:opacity-50",children:[O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(W0,{className:"h-4 w-4"}),"发送"]})]})]})]})}),e.jsx(pe,{open:t0>=0,index:Math.max(t0,0),close:(()=>s0(-1)),slides:e0})]})};export{$e as default}; +import{d as E,j as e,a}from"./react-vendor-Bf9ELcll.js";import{L as pe}from"./vendor-BE-_xUHH.js";import{B as me}from"./audio-codec-mjVr_wwJ.js";import{L as G,an as de,ao as ge,u as xe,ap as ue,aq as he,M as Q0,V as _e,R as be,ag as D0,m as fe,ar as je,x as J0,as as we,at as Ne,au as ye,av as Ce,S as W0,X as Oe}from"./icons-vendor-BSp7PTZg.js";import{a as U0,i as R,d as i0,e as V0,f as z0,m as Z0,h as ve,j as ke,k as q0,l as Se,s as Re,n as Ee,o as Ie,p as Me,g as Le,q as G0,u as $0,t as P0,C as De}from"./chat-metadata-74T0w35U.js";import{p as Ue,s as qe}from"./index-Q3nlx6gR.js";const H0="ydisks:chat-audio-play",Pe=[6,10,15,8,17,12,7,16,11,6,14,9];function Te(u){const _=u.trim();if(typeof location>"u"||location.protocol!=="https:")return _;try{const n=new URL(_);return n.protocol==="http:"&&n.hostname.endsWith(".aliyuncs.com")&&(n.protocol="https:"),n.toString()}catch{return _}}function T0(u){const _=Number.isFinite(u)?Math.max(0,Math.floor(u)):0,n=Math.floor(_/60),l=_%60;return`${n}:${l.toString().padStart(2,"0")}`}function A0(u){window.dispatchEvent(new CustomEvent(H0,{detail:u}))}const Ae=({messageKey:u,src:_,outgoing:n,initialDuration:l=0})=>{const x=E.useRef(null),C=E.useRef(0),[o,I]=E.useState("idle"),[M,L]=E.useState(l),[V,T]=E.useState(0);E.useEffect(()=>(()=>{var d;C.current+=1,(d=x.current)==null||d.destroy(),x.current=null}),[_]),E.useEffect(()=>{L(Math.max(0,l))},[l]),E.useEffect(()=>{const d=f=>{const w=f.detail,N=x.current;w!==u&&(N!=null&&N.isPlaying())&&N.pause()};return window.addEventListener(H0,d),(()=>window.removeEventListener(H0,d))},[u]),E.useEffect(()=>{if(o!=="playing")return;const d=window.setInterval(()=>{const f=x.current;f&&T(f.getCurrentPosition())},100);return(()=>window.clearInterval(d))},[o]);const A=(d,f)=>{const w=()=>C.current===f&&x.current===d;d.onPlay(()=>{w()&&I("playing")}),d.onResume(()=>{w()&&I("playing")}),d.onPause(()=>{w()&&I("paused")}),d.onStop(()=>{w()&&(I("idle"),T(0))}),d.onEnded(()=>{w()&&(I("idle"),T(0))})},r0=async()=>{var w;const d=x.current;if(d!=null&&d.isPlaying()){d.pause();return}if(d!=null&&d.isPaused()){A0(u),d.resume();return}if(d!=null&&d.isInit()){A0(u),d.play();return}if(o==="loading")return;const f=C.current+1;C.current=f,I("loading"),T(0);try{const N=new me;if(x.current=N,A(N,f),await N.initWithUrl(Te(_)),C.current!==f||x.current!==N){N.destroy();return}L(N.getDuration()||Math.max(0,l)),A0(u),N.play()}catch{if(C.current!==f)return;(w=x.current)==null||w.destroy(),x.current=null,I("error"),T(0)}},H=o==="playing"||o==="paused"?V:M,$=M>0?o==="playing"||o==="paused"?`${T0(H)} / ${T0(M)}`:T0(M):"--:--",P=o==="loading"?"正在解码":o==="playing"?"正在播放":o==="paused"?"已暂停":o==="error"?"加载失败,点击重试":"语音消息",O=o==="playing"?"暂停语音消息":o==="paused"?"继续播放语音消息":o==="error"?"重新加载语音消息":o==="loading"?"正在加载语音消息":"播放语音消息";return e.jsxs("div",{className:`flex h-11 min-w-56 items-center gap-2 rounded-2xl border px-2 shadow-sm ${n?"rounded-br-md border-sky-400 bg-sky-500 text-white":"rounded-bl-md border-slate-200 bg-white text-slate-800"}`,children:[e.jsx("button",{type:"button","aria-label":O,title:O,disabled:o==="loading",onClick:(()=>void r0()),className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-full transition focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-wait ${n?"bg-white text-sky-600 hover:bg-sky-50 focus-visible:ring-white":"bg-sky-50 text-sky-600 hover:bg-sky-100 focus-visible:ring-sky-400"}`,children:o==="loading"?e.jsx(G,{className:"h-4 w-4 animate-spin"}):o==="playing"?e.jsx(de,{className:"h-4 w-4 fill-current"}):o==="error"?e.jsx(ge,{className:"h-4 w-4"}):e.jsx(xe,{className:"ml-px h-4 w-4 fill-current"})}),e.jsxs("div",{className:"min-w-0 flex flex-1 items-center gap-2",children:[e.jsx("div",{className:"flex h-5 flex-1 items-center gap-0.5","aria-hidden":"true",children:Pe.map((d,f)=>e.jsx("span",{className:`w-0.5 rounded-full ${o==="playing"?"animate-pulse":""} ${n?"bg-sky-100":o==="error"?"bg-red-300":"bg-sky-400"}`,style:{height:`${d}px`,animationDelay:`${f*45}ms`}},`${u}-${f}`))}),e.jsx("span",{className:`shrink-0 font-mono text-[11px] font-semibold tabular-nums ${n?"text-sky-100":o==="error"?"text-red-500":"text-slate-500"}`,children:$}),e.jsx("span",{className:"sr-only",children:P})]})]})},X0=[["尊嘟假嘟","https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp"],["鸡哔你","https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp"],["谁懂啊","https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp"],["吗喽","https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp"],["功德+1","https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp"],["city不city啊","https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp"],["激推","https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp"],["微笑","https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp"],["龇牙","https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp"],["流泪","https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp"],["尴尬","https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp"],["撇嘴","https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp"],["破涕为笑","https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp"],["捂脸哭","https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp"],["害羞","https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp"],["感动","https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp"],["滴泪","https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp"],["暗中观察","https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp"],["偷笑","https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp"],["ok","https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp"],["送花","https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp"],["大哭","https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp"],["色","https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp"],["惊慌","https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp"],["惊讶","https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp"],["得意","https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp"],["睡","https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp"],["不好意思","https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp"],["托腮","https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["发怒","https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp"],["难过","https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp"],["调皮","https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp"],["愉快","https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp"],["白眼","https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp"],["拒绝","https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp"],["期待","https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp"],["困","https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp"],["流汗","https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp"],["憨笑","https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp"],["耶","https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp"],["奋斗","https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp"],["咒骂","https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp"],["疑问","https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp"],["嘘","https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp"],["晕","https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp"],["开心到模糊","https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp"],["衰","https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp"],["委屈","https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp"],["再见","https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp"],["鼓掌","https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp"],["吐","https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp"],["坏笑","https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp"],["抠鼻","https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp"],["叹气","https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp"],["无聊","https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp"],["思考","https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp"],["呆","https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["哇哦","https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp"],["飞吻","https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp"],["好喜欢","https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp"],["拜托","https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp"],["真棒","https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp"],["流鼻血","https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp"],["费解","https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp"],["秃头","https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp"],["嘿哈","https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp"],["吃土","https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp"],["机智","https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp"],["举杯","https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp"],["握手","https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp"],["挥手","https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp"],["yeah","https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp"],["666","https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp"],["棒","https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp"],["爱你","https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp"],["比心","https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp"],["感谢","https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp"],["拍手","https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp"],["拉钩","https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp"],["没钱","https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp"],["小刀","https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp"],["不刀","https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp"],["同出","https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp"],["递钱","https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp"],["数钱","https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp"],["打call","https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp"],["号外","https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp"],["包邮","https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp"],["求赞","https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp"],["非主流","https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp"],["吃瓜","https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp"],["种草","https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp"],["佛系","https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp"],["超便宜","https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp"],["拥抱","https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp"],["摊手","https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp"],["举手","https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp"],["蹲","https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp"],["跪了","https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp"],["拜","https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp"],["排","https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp"],["旺财","https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp"],["招财猫","https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp"],["酸了","https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp"],["鸭鸭","https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp"],["方了","https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp"],["白菜","https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp"],["桃子","https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp"],["打包","https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp"],["沙发","https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["南","https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp"],["盯","https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp"],["hot","https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp"],["new","https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp"],["cool","https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp"],["1","https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp"],["可","https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp"],["搬砖","https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp"],["菜狗","https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp"],["开心面具","https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp"],["快递","https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["裂开","https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp"],["啤酒","https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp"],["瑞思拜","https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp"],["小丑","https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp"],["爱心","https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp"]],He=u=>u,Fe=new Map(X0.map(([u,_])=>[u,_])),Be=u=>u.split(/(\[[^\]]+\])/g).map((_,n)=>{const l=_.startsWith("[")?Fe.get(_.slice(1,-1)):void 0;return l?e.jsx("img",{src:l,alt:_,title:_,className:"mx-0.5 inline-block h-7 w-7 align-middle"},n):e.jsx(E.Fragment,{children:_},n)}),Qe=()=>{const[u,_]=a.useState([]),[n,l]=a.useState(""),[x,C]=a.useState({}),[o,I]=a.useState(""),[M,L]=a.useState([]),[V,T]=a.useState(""),[A,r0]=a.useState(!1),[H,$]=a.useState(""),[P,O]=a.useState(null),[d,f]=a.useState(!0),[w,N]=a.useState(!1),[X,j0]=a.useState(!1),[l0,w0]=a.useState(!1),[N0,c0]=a.useState(),[o0,p0]=a.useState({}),[m0,d0]=a.useState({}),[g0,x0]=a.useState(!1),[S0,R0]=a.useState(!1),[v,Y]=a.useState(!1),[u0,k]=a.useState(""),[E0,I0]=a.useState("connecting"),[K,y0]=a.useState(null),[z,C0]=a.useState(null),Z=a.useRef(""),F=a.useRef(""),e0=a.useRef(null),t0=a.useRef({accountID:"",chatID:""}),s0=a.useRef(!0),J=a.useRef(!1),U=a.useRef(null),h0=a.useRef(new Set),s=a.useRef(0),h=a.useRef(null),S=a.useRef(0),B=a.useRef(null),q=a.useRef(0),_0=a.useRef(null),b0=a.useRef(0),O0=a.useRef(null),Q=a.useRef(0),a0=a.useRef(null);a.useEffect(()=>{Z.current=n},[n]),a.useEffect(()=>{F.current=o},[o]);const f0=a.useCallback(async t=>{var p;const i=++s.current;(p=h.current)==null||p.abort();const c=new AbortController;h.current=c;try{const r=await U0(t,void 0,{signal:c.signal},!0);if(!R(s.current,i,c.signal))return[];const g=r.sessions.map(m=>t===Z.current&&m.chat_id===F.current?{...m,unread_count:0}:m);return C(m=>({...m,[t]:g})),p0(m=>({...m,[t]:r.next_cursor})),d0(m=>({...m,[t]:r.has_more})),g}catch(r){return R(s.current,i,c.signal)&&!i0(r)&&k(r instanceof Error?r.message:"同步会话失败"),[]}},[]);a.useEffect(()=>{const t=new AbortController;return(async()=>{var c;f(!0);try{const[p,r]=await Promise.all([Le({signal:t.signal}),G0({signal:t.signal})]),m=p.map(y=>{var W,B0;return{...y,runtime_state:((W=r[y.id])==null?void 0:W.state)||(y.enabled?"connecting":"disabled"),runtime_connected:((B0=r[y.id])==null?void 0:B0.connected)===!0}}).filter(y=>y.enabled),j=await Promise.all(m.map(async y=>[y.id,await U0(y.id,void 0,{signal:t.signal})]));if(t.signal.aborted)return;_(m),C(Object.fromEntries(j.map(([y,W])=>[y,W.sessions]))),p0(Object.fromEntries(j.map(([y,W])=>[y,W.next_cursor]))),d0(Object.fromEntries(j.map(([y,W])=>[y,W.has_more])));const D=window.localStorage.getItem("ydisks.chat.account.v1")||"",L0=m.some(y=>y.id===D)?D:((c=m[0])==null?void 0:c.id)||"";l(L0)}catch(p){t.signal.aborted||k(p instanceof Error?p.message:"加载聊天数据失败")}finally{t.signal.aborted||f(!1)}})(),(()=>t.abort())},[]),a.useEffect(()=>{let t=!1,i=0,c=null;const p=async()=>{c=new AbortController;try{const r=await G0({signal:c.signal,timeoutMs:1e4});t||_(g=>g.map(m=>{var j,D;return{...m,runtime_state:((j=r[m.id])==null?void 0:j.state)||m.runtime_state,runtime_connected:((D=r[m.id])==null?void 0:D.connected)??m.runtime_connected}}))}catch{}finally{t||(i=window.setTimeout(p,3e3))}};return i=window.setTimeout(p,3e3),(()=>{t=!0,window.clearTimeout(i),c==null||c.abort()})},[]),a.useEffect(()=>{if(!n)return;window.localStorage.setItem("ydisks.chat.account.v1",n);const t=x[n]||[];I(i=>{var c;return t.some(p=>p.chat_id===i)?i:((c=t[0])==null?void 0:c.chat_id)||""})},[n,x]),a.useEffect(()=>{const t=Object.keys(x).length;if(d||u.length>0&&t===0)return;const i=Object.values(x).some(c=>c.some(p=>p.unread_count>0));Ue(i)},[u.length,d,x]),a.useEffect(()=>{!n||h0.current.has(n)||(h0.current.add(n),f0(n))},[n,f0]),a.useEffect(()=>{var c,p;if(!n||!o){S.current+=1,q.current+=1,(c=_0.current)==null||c.abort(),J.current=!1,L([]);return}const t=++S.current;(p=B.current)==null||p.abort();const i=new AbortController;return B.current=i,N(!0),V0(n,o,void 0,void 0,{signal:i.signal}).then(r=>{if(!R(S.current,t,i.signal))return;const g=z0(r.messages,o);Z0(n,o,g,{signal:i.signal}),L(r.messages),w0(r.has_more),c0(r.next_cursor),r.session&&C(m=>({...m,[n]:(m[n]||[]).map(j=>{var D;return j.chat_id===((D=r.session)==null?void 0:D.chat_id)?r.session:j})})),C(m=>({...m,[n]:(m[n]||[]).map(j=>j.chat_id===o?{...j,unread_count:0}:j)}))}).catch(r=>{R(S.current,t,i.signal)&&!i0(r)&&k(r instanceof Error?r.message:"加载消息失败")}).finally(()=>{R(S.current,t,i.signal)&&N(!1)}),(()=>i.abort())},[n,o]),a.useEffect(()=>{var t;(t=O0.current)==null||t.abort(),b0.current+=1},[n]),a.useEffect(()=>{var t;(t=a0.current)==null||t.abort(),Q.current+=1},[n,o]),a.useEffect(()=>{O(null)},[n,o]),a.useEffect(()=>{var t;q.current+=1,(t=_0.current)==null||t.abort(),J.current=!1},[n,o]),a.useEffect(()=>(()=>{var t,i,c,p,r;(t=h.current)==null||t.abort(),(i=B.current)==null||i.abort(),q.current+=1,(c=_0.current)==null||c.abort(),(p=O0.current)==null||p.abort(),(r=a0.current)==null||r.abort()}),[]),a.useEffect(()=>{const t=P;return(()=>{t&&URL.revokeObjectURL(t.url)})},[P]);const Y0=a.useCallback(async()=>{var g,m;if(!n||!o||X||!l0)return;const t=e0.current,i=(t==null?void 0:t.scrollHeight)||0,c=S.current,p=++q.current;(g=_0.current)==null||g.abort();const r=new AbortController;_0.current=r,J.current=!0,j0(!0),k("");try{const j=(m=M[0])==null?void 0:m.id,D=await V0(n,o,N0,j,{signal:r.signal});if(!R(S.current,c,r.signal)||p!==q.current)return;L(L0=>ve(L0,D.messages)),w0(D.has_more),c0(D.next_cursor),requestAnimationFrame(()=>{p===q.current&&!r.signal.aborted&&t&&(t.scrollTop+=t.scrollHeight-i)})}catch(j){J.current=!1,i0(j)||k(j instanceof Error?j.message:"加载历史消息失败")}finally{p===q.current&&j0(!1)}},[n,o,l0,N0,M,X]),F0=a.useCallback(t=>{const i=t.account_id;if(C(c=>{const p=c[i]||[];return p.some(g=>g.chat_id===t.chat_id)?{...c,[i]:p.map(g=>g.chat_id===t.chat_id?{...g,last_message:t.content,last_message_at:t.sent_at,unread_count:t.direction==="incoming"&&t.message_type!=="system"&&(Z.current!==i||F.current!==t.chat_id)?g.unread_count+1:g.unread_count}:g).sort((g,m)=>m.last_message_at-g.last_message_at)}:(f0(i),c)}),Z.current===i&&F.current===t.chat_id&&(L(c=>ke(q0(c,t),t)),t.direction==="incoming"&&t.message_type!=="system")){const c=z0([t],t.chat_id);Z0(i,t.chat_id,c)}},[f0]);a.useEffect(()=>qe(i=>{if(i.type==="connection"){I0(i.state);return}F0(i.message)}),[F0]);const K0=a.useCallback(()=>{const t=e0.current;if(!t)return;const i=t.scrollHeight-t.scrollTop-t.clientHeight;s0.current=i<=48},[]);a.useLayoutEffect(()=>{const t=t0.current.accountID!==n||t0.current.chatID!==o;t0.current={accountID:n,chatID:o},t&&(s0.current=!0);const i=e0.current;if(i){if(J.current){J.current=!1;return}(w||s0.current)&&(i.scrollTop=i.scrollHeight)}},[n,o,M,w]);const ee=u.find(t=>t.id===n),v0=x[n]||[],b=v0.find(t=>t.chat_id===o),te=a.useMemo(()=>Se(v0,V,A),[v0,V,A]),se=a.useCallback(t=>(x[t]||[]).reduce((i,c)=>i+c.unread_count,0),[x]),ae=a.useCallback(async()=>{var p;if(!n||g0||!m0[n])return;const t=++b0.current;(p=O0.current)==null||p.abort();const i=new AbortController;O0.current=i;const c=n;x0(!0),k("");try{const r=await U0(c,o0[c],{signal:i.signal},!0);if(!R(b0.current,t,i.signal))return;C(g=>({...g,[c]:r.sessions})),p0(g=>({...g,[c]:r.next_cursor})),d0(g=>({...g,[c]:r.has_more}))}catch(r){R(b0.current,t,i.signal)&&!i0(r)&&k(r instanceof Error?r.message:"加载历史联系人失败")}finally{R(b0.current,t,i.signal)&&x0(!1)}},[n,o0,g0,m0]),n0=a.useCallback(async(t,i,c)=>{var g;if(!b||!n||v)return;const p=++Q.current;(g=a0.current)==null||g.abort();const r=new AbortController;a0.current=r,Y(!0),k("");try{const m=await Re({account_id:n,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,item_id:b.item_id,item_title:b.item_title,text:t},{signal:r.signal});if(!R(Q.current,p,r.signal))return;c&&$(""),y0(null),L(j=>q0(j,m.message))}catch(m){R(Q.current,p,r.signal)&&(i&&y0(t),i0(m)||k(m instanceof Error?m.message:"消息发送失败"))}finally{R(Q.current,p,r.signal)&&Y(!1)}},[n,b,v]),k0=a.useCallback(async(t,i)=>{var r;if(!b||!n||v)return;const c=++Q.current;(r=a0.current)==null||r.abort();const p=new AbortController;a0.current=p,Y(!0),k("");try{const g=await Ee({account_id:n,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,buyer_avatar_url:b.buyer_avatar_url,item_id:b.item_id,item_title:b.item_title,image:t},{signal:p.signal});if(!R(Q.current,c,p.signal))return;C0(null),L(m=>q0(m,g.message))}catch(g){R(Q.current,c,p.signal)&&(i&&C0(t),i0(g)||k(g instanceof Error?g.message:"图片发送失败"))}finally{R(Q.current,c,p.signal)&&(Y(!1),U.current&&(U.current.value=""))}},[n,b,v]),ne=a.useCallback(async()=>{const t=H.trim();!t||!b||!n||v||await n0(t,!0,!0)},[n,H,b,n0,v]),ie=a.useCallback(async t=>{const i=t.trim();!i||!b||!n||v||await n0(i,!0,!1)},[n,b,n0,v]),M0=a.useCallback(async t=>{if(!(!t||!b||!n||v)){if(!t.type.startsWith("image/")){k("仅支持粘贴/发送图片文件");return}k(""),O({file:t,url:URL.createObjectURL(t)})}},[n,b,v]),re=a.useCallback(async t=>{const i=t.find(c=>c.type.startsWith("image/"));i&&await M0(i)},[M0]),le=a.useCallback(()=>{O(null),U.current&&(U.current.value="")},[]),ce=a.useCallback(async()=>{if(!P||!b||!n||v)return;const t=P.file;O(null),await k0(t,!0)},[n,P,b,k0,v]),oe=a.useCallback(async()=>{K?await n0(K,!1,!0):z&&await k0(z,!1)},[z,K,k0,n0]);return{accounts:u,activeAccountID:n,activeSessions:v0,selectedSession:b,activeAccount:ee,messages:M,search:V,unreadOnly:A,draft:H,loading:d,messagesLoading:w,olderLoading:X,hasOlder:l0,contactsLoading:g0,hasMoreContacts:m0[n]===!0,emojiOpen:S0,sending:v,error:u0,liveState:E0,pendingImage:P,activeChatID:o,filteredSessions:te,scrollRef:e0,imageInputRef:U,setActiveAccountID:l,setActiveChatID:I,setSearch:T,setUnreadOnly:r0,setDraft:$,setEmojiOpen:R0,reloadSessions:f0,loadMoreContacts:ae,loadOlderMessages:Y0,handleMessageScroll:K0,handleSend:ne,handleQuickReply:ie,handleImage:M0,handlePastedImages:re,confirmSendImage:ce,closeImagePreview:le,retrySend:oe,retryAvailable:!!(K||z),unreadForAccount:se,emojiURL:He,xianyuEmojis:X0,renderXianyuText:Be,formatClock:Me,messageTime:Ie}},$e=()=>{const{accounts:u,activeAccountID:_,activeChatID:n,activeAccount:l,selectedSession:x,filteredSessions:C,messages:o,search:I,unreadOnly:M,draft:L,loading:V,messagesLoading:T,olderLoading:A,hasOlder:r0,contactsLoading:H,hasMoreContacts:$,emojiOpen:P,sending:O,error:d,liveState:f,pendingImage:w,scrollRef:N,imageInputRef:X,setActiveAccountID:j0,setActiveChatID:l0,setSearch:w0,setUnreadOnly:N0,setDraft:c0,setEmojiOpen:o0,reloadSessions:p0,loadMoreContacts:m0,loadOlderMessages:d0,handleMessageScroll:g0,handleSend:x0,handleQuickReply:S0,handleImage:R0,handlePastedImages:v,confirmSendImage:Y,closeImagePreview:u0,retrySend:k,retryAvailable:E0,unreadForAccount:I0,emojiURL:K,xianyuEmojis:y0,renderXianyuText:z,formatClock:C0,messageTime:Z}=Qe(),F=E.useMemo(()=>o.filter(s=>s.message_type==="image"),[o]),e0=E.useMemo(()=>F.map(s=>({src:s.content,alt:"聊天图片"})),[F]),[t0,s0]=E.useState(-1),J=E.useCallback(s=>{s0(F.findIndex(h=>h.message_key===s))},[F]),[U,h0]=E.useState(!1);return V?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(G,{className:"h-8 w-8 animate-spin text-sky-500"})}):e.jsxs("section",{className:"flex h-[calc(100vh-4rem)] min-h-[560px] flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-chat",children:[e.jsxs("header",{className:"border-b border-slate-200 bg-slate-50/70 px-5 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black tracking-tight text-slate-950",children:"在线聊天"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-slate-500",children:"复用账号实时连接,消息按账号完全隔离"})]}),e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-xs font-bold ${f==="online"?"bg-emerald-50 text-emerald-700":f==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[f==="online"?e.jsx(ue,{className:"h-3.5 w-3.5"}):e.jsx(he,{className:"h-3.5 w-3.5"}),f==="online"?"实时同步中":f==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:u.map(s=>{const h=s.id===_,S=I0(s.id),B=P0(S),q=s.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":h,onClick:(()=>j0(s.id)),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${h?"border-sky-500 text-sky-700":"border-transparent text-slate-500 hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${q?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:s.nickname||s.remark||s.id}),S>0&&e.jsx("span",{"aria-label":`未读消息 ${B} 条`,className:$0(S),children:B})]},s.id)})})]}),u.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(Q0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-800",children:"暂无启用账号"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"先在账号管理中启用账号,聊天会话会自动出现。"})]}):e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden grid-cols-[320px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"flex min-h-0 flex-col border-r border-slate-200 bg-slate-50/40",children:[e.jsxs("div",{className:"space-y-3 border-b border-slate-200 p-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(_e,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:I,onChange:(s=>w0(s.target.value)),placeholder:"搜索用户、商品或消息",className:"h-10 w-full rounded-xl border border-slate-200 bg-white pl-9 pr-3 text-sm outline-none transition focus:border-sky-400 focus:ring-2 focus:ring-sky-100"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:(()=>N0(s=>!s)),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${M?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:M?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:(()=>void p0(_)),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(be,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[C.map(s=>e.jsxs("button",{type:"button",onClick:(()=>l0(s.chat_id)),className:`flex w-full gap-3 border-b border-slate-100 p-3.5 text-left transition-colors ${s.chat_id===n?"bg-white shadow-chat-active":"hover:bg-white/80"}`,children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-slate-200 text-slate-500",children:s.buyer_avatar_url?e.jsx("img",{src:s.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"truncate text-sm font-extrabold text-slate-900",children:s.buyer_name||`用户 ${s.buyer_id}`})}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-xs text-slate-500",children:s.last_message||"暂无消息"}),s.unread_count>0&&e.jsx("span",{"aria-label":`未读消息 ${P0(s.unread_count)} 条`,className:`ml-auto ${$0(s.unread_count)}`,children:P0(s.unread_count)})]}),s.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",s.item_title]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-slate-400",children:C0(s.last_message_at)}),s.item_image_url&&e.jsx("img",{src:s.item_image_url,alt:"",className:"h-9 w-11 rounded-[4px] border border-slate-200 object-cover"})]})]},s.chat_id)),C.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),$&&!I&&!M&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:(()=>void m0()),disabled:H,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 text-xs font-bold text-slate-500 shadow-sm hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[H&&e.jsx(G,{className:"h-3.5 w-3.5 animate-spin"}),H?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsxs("main",{className:"relative flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:[x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-20 shrink-0 items-start border-b border-slate-200 bg-white px-5 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-black text-slate-950",children:x.buyer_name||x.buyer_id}),e.jsxs("div",{className:"mt-0.5 flex flex-col text-xs text-slate-500",children:[e.jsx("span",{children:"用户 ID:"}),e.jsx("span",{className:"truncate",children:x.buyer_id})]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(l==null?void 0:l.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(l==null?void 0:l.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:N,onScroll:g0,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:T?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(G,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[r0&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:(()=>void d0()),disabled:A,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs font-bold text-slate-500 shadow-sm transition hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[A&&e.jsx(G,{className:"h-3.5 w-3.5 animate-spin"}),A?"正在加载":"加载更早消息"]})}),o.map(s=>{const h=s.direction==="outgoing";return s.message_type==="system"?e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500",children:[z(s.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:Z(s.sent_at)})]})},s.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${h?"justify-end":"justify-start"}`,children:[!h&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:x.buyer_avatar_url?e.jsx("img",{src:x.buyer_avatar_url,alt:x.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${h?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:h?(l==null?void 0:l.nickname)||(l==null?void 0:l.remark)||"我":x.buyer_name||s.sender_name||x.buyer_id}),s.message_type==="image"?e.jsx("button",{type:"button",title:"点击预览大图",onClick:J.bind(null,s.message_key),className:`block cursor-zoom-in overflow-hidden rounded-2xl border bg-white p-1 text-left shadow-sm ${h?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:s.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):s.message_type==="video"?e.jsx("video",{src:s.content,controls:!0,preload:"metadata",className:"max-h-80 max-w-full rounded-2xl bg-black"}):s.message_type==="audio"?e.jsx(Ae,{messageKey:s.message_key,src:s.content,outgoing:h,initialDuration:s.media_duration}):e.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-6 shadow-sm ${h?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:z(s.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[Z(s.sent_at),h&&(s.status==="failed"?e.jsx(fe,{className:"h-3 w-3 text-red-500","aria-label":"发送失败"}):s.read_status===2?e.jsx(je,{className:"h-3 w-3 text-sky-500","aria-label":"对方已读"}):s.status==="sent"?e.jsx(J0,{className:"h-3 w-3 text-sky-500","aria-label":"已发送未读"}):e.jsx(J0,{className:"h-3 w-3","aria-label":"发送中"}))]})]}),h&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:l!=null&&l.avatar_url?e.jsx("img",{src:l.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(D0,{className:"m-2 h-5 w-5 text-sky-600"})})]},s.message_key)})]})}),d&&e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:[e.jsx("span",{children:d}),E0&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void k()),children:"重试发送"})]}),e.jsxs("div",{className:"relative z-10 shrink-0 border-t border-slate-200 bg-white p-4 shadow-chat-input",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:(()=>o0(s=>!s)),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"闲鱼表情",children:e.jsx(we,{className:"h-5 w-5"})}),P&&e.jsxs("div",{className:"absolute bottom-11 left-0 z-30 w-[360px] rounded-2xl border border-slate-200 bg-white p-3 shadow-2xl",children:[e.jsx("div",{className:"mb-2 text-xs font-bold text-slate-500",children:"全部表情"}),e.jsx("div",{className:"grid max-h-72 grid-cols-8 gap-1 overflow-y-auto",children:y0.map(([s,h])=>e.jsx("button",{type:"button",title:`[${s}]`,onClick:(()=>{c0(S=>S+`[${s}]`),o0(!1)}),className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:K(h),alt:`[${s}]`,className:"h-8 w-8 object-contain"})},s))})]})]}),e.jsx("input",{ref:X,type:"file",accept:"image/*",className:"hidden",onChange:(s=>{var h;return void R0((h=s.target.files)==null?void 0:h[0])})}),e.jsx("button",{type:"button",onClick:(()=>{var s;return(s=X.current)==null?void 0:s.click()}),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"发送图片(最大 10MB)",children:e.jsx(Ne,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:(()=>h0(!U)),className:"ml-auto rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600",title:U?"收起快捷回复":"展开快捷回复","aria-label":U?"收起快捷回复":"展开快捷回复",children:U?e.jsx(ye,{className:"h-5 w-5"}):e.jsx(Ce,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-2 transition focus-within:border-sky-400 focus-within:ring-2 focus-within:ring-sky-100",children:[e.jsx("textarea",{value:L,onChange:(s=>c0(s.target.value)),rows:2,maxLength:2e3,onKeyDown:(s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),x0())}),onPaste:(s=>{var B;const h=Array.from(((B=s.clipboardData)==null?void 0:B.files)||[]);h.find(q=>q.type.startsWith("image/"))&&(s.preventDefault(),v(h))}),disabled:(l==null?void 0:l.runtime_state)!=="online",placeholder:(l==null?void 0:l.runtime_state)==="online"?"输入消息,Enter 发送,Shift + Enter 换行,Ctrl + V 粘贴图片":"账号离线,暂时无法发送",className:"max-h-32 min-h-12 flex-1 resize-none bg-transparent px-2 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed"}),e.jsx("button",{type:"button",onClick:(()=>void x0()),disabled:!L.trim()||O||(l==null?void 0:l.runtime_state)!=="online",className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-sky-500 text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none","aria-label":"发送消息",children:O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(W0,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(Q0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-700",children:"选择一个用户开始聊天"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"该账号的新消息会实时出现在左侧列表。"})]}),e.jsx(De,{activeAccountID:_,selectedSession:x,quickReplyPanelOpen:U,closeQuickReplyPanel:(()=>h0(!1)),sendQuickReply:S0,sending:O,accountOnline:(l==null?void 0:l.runtime_state)==="online"})]})]}),w&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-950/60 p-4",onClick:u0,children:e.jsxs("div",{className:"flex max-h-full w-full max-w-2xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl",onClick:(s=>s.stopPropagation()),children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-slate-200 px-5 py-3",children:[e.jsx("div",{className:"text-sm font-black text-slate-900",children:"发送图片预览"}),e.jsx("button",{type:"button",title:"取消",onClick:u0,className:"rounded-lg p-1.5 text-slate-400 transition hover:bg-slate-100 hover:text-slate-700",children:e.jsx(Oe,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-slate-100 p-4",children:e.jsx("img",{src:w.url,alt:"待发送图片预览",className:"max-h-[55vh] max-w-full rounded-xl object-contain"})}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-slate-200 px-5 py-3",children:[e.jsxs("div",{className:"min-w-0 truncate text-xs text-slate-500",children:[w.file.name||"粘贴的图片"," · ",(w.file.size/1024).toFixed(0)," KB"]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:u0,className:"rounded-xl px-4 py-2 text-sm font-bold text-slate-600 transition hover:bg-slate-100",children:"取消"}),e.jsxs("button",{type:"button",onClick:(()=>void Y()),disabled:O||(l==null?void 0:l.runtime_state)!=="online",className:"flex items-center gap-2 rounded-xl bg-sky-500 px-4 py-2 text-sm font-bold text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:opacity-50",children:[O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(W0,{className:"h-4 w-4"}),"发送"]})]})]})]})}),e.jsx(pe,{open:t0>=0,index:Math.max(t0,0),close:(()=>s0(-1)),slides:e0})]})};export{$e as default}; diff --git a/internal/webui/static/assets/Notifications-BepLRaYn.js b/internal/webui/static/assets/Notifications-BepLRaYn.js deleted file mode 100644 index 6635172..0000000 --- a/internal/webui/static/assets/Notifications-BepLRaYn.js +++ /dev/null @@ -1 +0,0 @@ -import{j as e,b as _e,a as d}from"./react-vendor-Bf9ELcll.js";import{al as te,S as ae,am as je,y as Q,g as I,L as J,H as Ne,T as ve,x as V,X as ne,J as re,N as le,s as ke,R as we,P as Se}from"./icons-vendor-BSp7PTZg.js";import{r as R,c as B}from"./chat-metadata-74T0w35U.js";import"./vendor-BE-_xUHH.js";const Y=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],H=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},oe=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),a=Y.some(r=>String(s[r]??"").trim()!=="");return{...s,use_custom_smtp:t?H(s.use_custom_smtp,!1):a}},ie=(s,t)=>{const a={...s,use_custom_smtp:!0};for(const r of Y)String(a[r]??"").trim()===""&&t[r]!==void 0&&(a[r]=t[r]);return a.smtp_port||(a.smtp_port=587),a.smtp_from_address||(a.smtp_from_address=a.smtp_user||""),a.smtp_use_tls=H(a.smtp_use_tls,!0),a.smtp_use_ssl=H(a.smtp_use_ssl,!1),a},ce=s=>{const t=oe(s),a={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(a.use_custom_smtp)for(const r of Y)a[r]=t[r];return a},$={bark:{label:"Bark",icon:I,fields:[{key:"server_url",label:"Bark 服务器",placeholder:"https://api.day.app",required:!0},{key:"device_key",label:"Device Key",placeholder:"你的 Bark 设备 Key",required:!0},{key:"title",label:"标题(可选)",placeholder:"Ydisks闲鱼助手"},{key:"sound",label:"铃声(可选)",placeholder:"default"},{key:"group",label:"分组(可选)",placeholder:"xianyu"}],guide:{steps:["App Store 搜索并安装 Bark(免费)","打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app//这是测试推送内容","URL 路径里 那一段就是 Device Key,复制填入","服务器地址默认 https://api.day.app,自建服务端则填自建域名"],urlFormat:"https://api.day.app/<你的key>/测试内容",note:"不需要 secret,Device Key 本身就是唯一凭证。"}},dingtalk:{label:"钉钉机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=...",required:!0},{key:"secret",label:"加签密钥",placeholder:"SEC...",help:"安全设置勾选「加签」后生成,SEC 开头"}],guide:{steps:["钉钉进入一个群(可建单人群)→ 右上角 群设置","机器人 → 添加机器人 → 选择「自定义机器人」","安全设置勾选「加签」","完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制","Webhook URL 填上面,Secret 填加签密钥"],urlFormat:"https://oapi.dingtalk.com/robot/send?access_token=XXX",note:"加签密钥可选,但强烈建议启用,否则机器人可能被滥用。"}},feishu:{label:"飞书机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/...",required:!0},{key:"secret",label:"签名校验密钥",placeholder:"sec-...",help:"安全设置选「签名校验」后生成"}],guide:{steps:["飞书进入目标群 → 右上角 更多 → 设置","群机器人 → 添加机器人 → 自定义机器人","安全设置选择「签名校验」,复制生成的秘钥","完成会给 Webhook 地址,复制","Webhook URL 填上面,秘钥填签名校验密钥"],urlFormat:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx",note:"签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。"}},wechat:{label:"企业微信机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...",required:!0}],guide:{steps:["企业微信进入一个内部群 → 右上角 … → 群设置","找到「群机器人」(新版可能叫「消息推送」)","添加 → 选择自定义机器人","完成给 Webhook 地址(含 ?key=),复制填入"],urlFormat:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX",note:"不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。"}},webhook:{label:"自定义 Webhook",icon:je,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-server/notify",required:!0}],guide:{steps:["仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON","系统会 POST 这个 URL,Content-Type: application/json","请求体固定为右侧 JSON 格式,按需解析 message 字段"],urlFormat:'{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',note:"若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。"}},telegram:{label:"Telegram",icon:ae,fields:[{key:"bot_token",label:"Bot Token",placeholder:"123456:ABC-DEF...",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"-1001234567890 或你的用户 ID",required:!0}],guide:{steps:["在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token","把你的 Bot 拉进一个群,或私聊它发一条消息","浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates",'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'],urlFormat:"Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890",note:"群聊需先把 Bot 设为管理员才能发消息。"}},email:{label:"邮件",icon:te,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},de=[{value:"account_offline",label:"掉线通知",description:"账号过期、断线或登录态失效"},{value:"account_recovered",label:"恢复通知",description:"自动恢复成功并重新在线"},{value:"account_disabled",label:"禁用通知",description:"连续失败、账密错误等导致账号停用"},{value:"security_verification",label:"风控验证",description:"滑块、人脸、扫码验证等安全校验"},{value:"delivery_result",label:"交易通知",description:"订单发货、卡密发送等交易结果"},{value:"token_renewal",label:"续期通知",description:"Cookie/token 续期和自动恢复过程"},{value:"system_error",label:"系统错误",description:"后台任务或系统级异常"}],ee=()=>({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),Ce=s=>!s||s.length===0?"全部事件":s.map(t=>{var a;return((a=de.find(r=>r.value===t))==null?void 0:a.label)||t}).join("、"),Te=(s,t)=>{const a=s.type==="email"?oe({...s.config||{}}):null,r=a?a.use_custom_smtp===!0?ie(a,t):a:{...s.config||{}};return{name:s.name,type:s.type,enabled:s.enabled,config:r,event_types:s.event_types||[]}},Pe=s=>{const a=$[s.type].fields.find(r=>r.required&&!String(s.config[r.key]||"").trim());if(a)return`请填写 ${a.label}`;if(!s.name.trim())return"请填写渠道名称";if(s.type==="email"){const r=ce(s.config);if(r.use_custom_smtp){const k=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([b])=>!String(r[b]||"").trim());if(k)return`请填写 ${k[1]}`}}return""},Ee=s=>({name:s.name.trim(),type:s.type,config:s.type==="email"?ce(s.config):s.config,event_types:s.event_types,enabled:s.enabled}),g=(s,t)=>s===t,F=(s,t)=>s instanceof Error&&s.message?s.message:t,Me=({channels:s,testingId:t,onEdit:a,onDelete:r,onToggleEnabled:h,onTest:k})=>{const b=l=>s.find(o=>o.id===l.currentTarget.dataset.channelId)||null,j=l=>{const o=b(l);o&&h(o)},S=l=>{const o=b(l);o&&k(o)},E=l=>{const o=b(l);o&&a(o)},_=l=>{const o=b(l);o&&r(o)},M=l=>{const o=$[l.type]||$.webhook,P=o.icon;return e.jsxs("div",{className:"ios-card rounded-xl p-5 bg-white flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 truncate",children:l.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:o.label}),!l.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium",children:"已停用"})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 truncate",children:o.fields.map(x=>{var w;return(w=l.config)==null?void 0:w[x.key]}).filter(Boolean).map((x,w)=>e.jsx("span",{className:"mr-3",children:String(x).length>40?`${String(x).slice(0,40)}…`:String(x)},w))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Ce(l.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{"data-channel-id":l.id,onClick:j,className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${l.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:l.enabled?"启用中":"已停用"}),e.jsxs("button",{"data-channel-id":l.id,onClick:S,disabled:t===l.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[t===l.id?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(ae,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{"data-channel-id":l.id,onClick:E,className:"w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors",title:"编辑",children:e.jsx(Ne,{className:"w-4 h-4"})}),e.jsx("button",{"data-channel-id":l.id,onClick:_,className:"w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors",title:"删除",children:e.jsx(ve,{className:"w-4 h-4"})})]})]},l.id)};return s.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(I,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"还没有配置任何通知渠道"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"点击右上角「新建渠道」开始配置"})]}):e.jsx("div",{className:"space-y-3",children:s.map(M)})},qe=({selectedEvents:s,onToggleEvent:t})=>{const a=r=>{const h=r.currentTarget.dataset.event;h&&t(h)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"通知内容"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"不选择表示接收全部通知;选择后仅接收勾选类型。"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:de.map(r=>{const h=s.includes(r.value);return e.jsxs("button",{type:"button","data-event":r.value,onClick:a,className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${h?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center ${h?"bg-brand border-brand":"border-gray-300"}`,children:h&&e.jsx(V,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${h?"text-brand":"text-gray-800"}`,children:r.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:r.description})]},r.value)})})]})},Le=({showModal:s,editing:t,form:a,setForm:r,smtp:h,showChannelSmtpPassword:k,setShowChannelSmtpPassword:b,saving:j,onClose:S,onSave:E})=>{const _=$[a.type],M=n=>r(p=>({...p,name:n.target.value})),l=n=>{const p=n.currentTarget.dataset.type;p&&r(N=>({...N,type:p,config:{}}))},o=n=>{const p=n.currentTarget.dataset.field;p&&r(N=>({...N,config:{...N.config,[p]:n.target.value}}))},P=()=>r(n=>({...n,config:n.config.use_custom_smtp===!0?{...n.config,use_custom_smtp:!1}:ie(n.config,h)})),x=n=>r(p=>({...p,config:{...p.config,smtp_use_tls:n.target.checked,smtp_use_ssl:n.target.checked?!1:p.config.smtp_use_ssl}})),w=n=>r(p=>({...p,config:{...p.config,smtp_use_ssl:n.target.checked,smtp_use_tls:n.target.checked?!1:p.config.smtp_use_tls}})),X=n=>r(p=>({...p,event_types:p.event_types.includes(n)?p.event_types.filter(N=>N!==n):[...p.event_types,n]})),U=()=>r(n=>({...n,enabled:!n.enabled})),z=()=>b(n=>!n),G=(n,p)=>e.jsx("li",{children:n},p);return s?_e.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"36rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:t?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:S,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(ne,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道名称"}),e.jsx("input",{type:"text",value:a.name,onChange:M,placeholder:"例如:我的 Bark",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道类型"}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:Object.keys($).map(n=>{const p=$[n],N=p.icon,q=a.type===n;return e.jsxs("button",{"data-type":n,type:"button",onClick:l,className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${q?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(N,{className:`w-5 h-5 ${q?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${q?"text-brand":"text-gray-600"}`,children:p.label})]},n)})})]}),e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",_.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:_.guide.steps.map(G)}),_.guide.urlFormat&&e.jsxs("div",{className:"text-xs text-amber-900/90",children:[e.jsx("span",{className:"font-bold",children:"格式示例:"}),e.jsx("code",{className:"mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]",children:_.guide.urlFormat})]}),_.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",_.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:_.fields.map(n=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[n.label,n.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{"data-field":n.key,type:n.type==="password"?"password":n.type==="number"?"number":"text",value:String(a.config[n.key]||""),onChange:o,placeholder:n.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),n.help&&e.jsx("p",{className:"text-xs text-gray-500",children:n.help})]},n.key))}),a.type==="email"&&e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"SMTP 来源"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:a.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:P,className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${a.config.use_custom_smtp===!0?"bg-brand":"bg-gray-300"}`,"aria-label":"使用独立 SMTP",children:e.jsx("span",{className:`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${a.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),a.config.use_custom_smtp===!0&&e.jsxs("div",{className:"space-y-4 border-t border-blue-100 bg-white/80 p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 服务器 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:String(a.config.smtp_server||""),onChange:o,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 端口 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_port",type:"number",value:String(a.config.smtp_port||587),onChange:o,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["登录邮箱 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:String(a.config.smtp_user||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["密码 / 授权码 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{"data-field":"smtp_password",type:k?"text":"password",value:String(a.config.smtp_password||""),onChange:o,placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:z,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:k?e.jsx(re,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:String(a.config.smtp_from_name||""),onChange:o,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["发件邮箱地址 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:String(a.config.smtp_from_address||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_tls!==!1,onChange:x}),"STARTTLS(常用于 587)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_ssl===!0,onChange:w}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),e.jsx(qe,{selectedEvents:a.event_types,onToggleEvent:X}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:U,className:`relative w-11 h-6 rounded-full transition-colors ${a.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${a.enabled?"translate-x-5":""}`})}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"启用此渠道"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:S,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,disabled:j,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[j?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(V,{className:"w-4 h-4"}),j?"保存中...":"保存"]})]})]})}),document.body):null},Re=({smtp:s,setSmtp:t,smtpSaving:a,showPassword:r,setShowPassword:h,onSave:k})=>{const b=l=>{const o=l.currentTarget.dataset.field;o&&t(P=>({...P,[o]:l.target.value}))},j=l=>{t(o=>({...o,smtp_port:parseInt(l.target.value,10)||587}))},S=l=>{t(o=>({...o,smtp_use_tls:l.target.checked,smtp_use_ssl:l.target.checked?!1:o.smtp_use_ssl}))},E=l=>{t(o=>({...o,smtp_use_ssl:l.target.checked,smtp_use_tls:l.target.checked?!1:o.smtp_use_tls}))},_=l=>{t(o=>({...o,smtp_password:l.target.value}))},M=()=>h(l=>!l);return e.jsxs("section",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-extrabold text-gray-800",children:"SMTP 邮件配置"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"系统级邮件发送服务,供邮件通知渠道复用"})]}),e.jsx("div",{className:"p-2 rounded-xl bg-blue-50 text-blue-600",children:e.jsx(te,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 服务器"}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:typeof s.smtp_server=="string"?s.smtp_server:"",onChange:b,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 端口"}),e.jsx("input",{type:"number",value:typeof s.smtp_port=="number"?s.smtp_port:587,onChange:j,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱"}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:typeof s.smtp_user=="string"?s.smtp_user:"",onChange:b,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"邮箱密码 / 授权码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:r?"text":"password",value:typeof s.smtp_password=="string"?s.smtp_password:"",onChange:_,placeholder:s.smtp_password_configured?"已配置,如需替换请输入新密码":"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:M,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:r?e.jsx(re,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:typeof s.smtp_from_name=="string"?s.smtp_from_name:"",onChange:b,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱地址"}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:typeof s.smtp_from_address=="string"?s.smtp_from_address:typeof s.smtp_user=="string"?s.smtp_user:"",onChange:b,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_tls!==!1,onChange:S}),"STARTTLS(常用于 587 端口)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_ssl===!0,onChange:E}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:k,disabled:a,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ke,{className:"w-4 h-4"}),a?"保存中...":"保存 SMTP 配置"]})]})},Be=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},pe=s=>{const t=Array.from(new Set((s||[]).filter(Boolean)));return t.length>0?JSON.stringify(t):""},Ae=s=>{const t={},a=s.type==="ding_talk"?"dingtalk":s.type==="lark"?"feishu":s.type;return{id:String(s.id),name:s.name,type:a,config:t,event_types:Be(s.event_types),enabled:s.enabled}},Oe=async s=>({success:!0,data:(await R(a=>B.GET("/api/v1/notifications/channels",{signal:a}),s)).map(Ae)}),$e=async(s,t)=>R(a=>B.POST("/api/v1/notifications/channels",{body:{name:s.name,type:s.type,config:JSON.stringify(s.config),event_types:pe(s.event_types),enabled:s.enabled},signal:a}),t),se=async(s,t,a)=>{const r={name:t.name,type:t.type,config:t.config===void 0?void 0:JSON.stringify(t.config),event_types:t.event_types===void 0?void 0:pe(t.event_types),enabled:t.enabled};return R(h=>B.PUT("/api/v1/notifications/channels/{channel_id}",{params:{path:{channel_id:s}},body:r,signal:h}),a)},De=async(s,t)=>R(a=>B.DELETE("/api/v1/notifications/channels/{channel_id}",{params:{path:{channel_id:s}},signal:a}),t),Fe=async(s,t)=>R(a=>B.POST("/api/v1/notifications/channels/{channel_id}/test",{params:{path:{channel_id:s}},signal:a}),t),Ue=s=>{const t={...s};if("renewal_log_retention_days"in t){const a=Number(t.renewal_log_retention_days);t.renewal_log_retention_days=Number.isFinite(a)?a:10}return t},We=async s=>{const t=await R(a=>B.GET("/api/v1/settings/system",{signal:a}),s);return Ue(t.data||t.settings||t)},Ie=async(s,t)=>R(a=>B.PUT("/api/v1/settings/system",{body:s,signal:a}),t),Je=s=>{const[t,a]=d.useState([]),[r,h]=d.useState(!0),[k,b]=d.useState(!1),[j,S]=d.useState(null),[E,_]=d.useState(!1),[M,l]=d.useState(""),[o,P]=d.useState(null),[x,w]=d.useState({}),[X,U]=d.useState(!1),[z,G]=d.useState(!1),[n,p]=d.useState(!1),[N,q]=d.useState(ee),D=d.useRef(0),K=d.useRef(null),C=d.useRef(0),A=d.useRef(null),y=d.useRef(0),T=d.useRef(null),O=d.useRef(null),f=d.useCallback((i,c)=>{P({type:i,text:c}),O.current!==null&&window.clearTimeout(O.current),O.current=window.setTimeout(()=>{O.current=null,P(null)},3e3)},[]),L=d.useCallback(async()=>{var m;const i=++D.current;(m=K.current)==null||m.abort();const c=new AbortController;K.current=c,h(!0);try{const u=await Oe({signal:c.signal});if(!g(i,D.current))return;a(u.data||[])}catch(u){g(i,D.current)&&!c.signal.aborted&&console.error("加载通知渠道失败",u)}finally{g(i,D.current)&&h(!1)}},[]),Z=d.useCallback(async()=>{var m;const i=++C.current;(m=A.current)==null||m.abort();const c=new AbortController;A.current=c;try{const u=await We({signal:c.signal});g(i,C.current)&&w(u||{})}catch(u){g(i,C.current)&&!c.signal.aborted&&console.error("加载 SMTP 配置失败",u)}},[]);d.useEffect(()=>{var i;return L(),s?Z():(C.current+=1,(i=A.current)==null||i.abort(),w({})),(()=>{var c,m;D.current+=1,(c=K.current)==null||c.abort(),C.current+=1,(m=A.current)==null||m.abort()})},[s,L,Z]),d.useEffect(()=>(()=>{O.current!==null&&window.clearTimeout(O.current)}),[]);const me=d.useCallback(()=>{S(null),q(ee()),p(!1),b(!0)},[]),ue=d.useCallback(i=>{S(i),q(Te(i,x)),p(!1),b(!0)},[x]),xe=d.useCallback(()=>{var i;y.current+=1,(i=T.current)==null||i.abort(),_(!1),b(!1)},[]),ge=d.useCallback(async()=>{var u;const i=Pe(N);if(i){f("error",i);return}const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m,_(!0);try{const v=Ee(N);if(j?await se(j.id,v,{signal:m.signal}):await $e(v,{signal:m.signal}),!g(c,y.current)||(b(!1),await L(),!g(c,y.current)))return;f("success",j?"已更新":"已创建")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"保存失败"))}finally{g(c,y.current)&&_(!1)}},[j,N,L,f]),he=d.useCallback(async i=>{var u;if(!confirm(`确认删除渠道「${i.name}」吗?已绑定该渠道的账号会自动解绑。`))return;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await De(i.id,{signal:m.signal}),!g(c,y.current)||(await L(),!g(c,y.current)))return;f("success","已删除")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"删除失败"))}},[L,f]),be=d.useCallback(async i=>{var u;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await se(i.id,{enabled:!i.enabled},{signal:m.signal}),!g(c,y.current))return;a(v=>v.map(W=>W.id===i.id?{...W,enabled:!W.enabled}:W))}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"切换失败"))}},[f]),ye=d.useCallback(async i=>{var u;l(i.id);const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{await Fe(i.id,{signal:m.signal}),g(c,y.current)&&f("success","测试通知已发送,请检查对应渠道")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"发送失败"))}finally{g(c,y.current)&&l("")}},[f]),fe=d.useCallback(async()=>{var m;const i=++C.current;(m=A.current)==null||m.abort();const c=new AbortController;A.current=c,U(!0);try{const u={smtp_server:x.smtp_server||"",smtp_port:x.smtp_port||587,smtp_user:x.smtp_user||"",smtp_from_name:x.smtp_from_name||"",smtp_from_address:x.smtp_from_address||x.smtp_user||"",smtp_use_tls:x.smtp_use_tls!==!1,smtp_use_ssl:x.smtp_use_ssl===!0};Object.prototype.hasOwnProperty.call(x,"smtp_password")&&(u.smtp_password=x.smtp_password),await Ie(u,{signal:c.signal}),g(i,C.current)&&f("success","SMTP 配置已保存")}catch(u){g(i,C.current)&&!c.signal.aborted&&f("error",F(u,"保存失败"))}finally{g(i,C.current)&&U(!1)}},[f,x]);return{channels:t,loading:r,showModal:k,editing:j,saving:E,testingId:M,toast:o,smtp:x,smtpSaving:X,showSmtpPassword:z,showChannelSmtpPassword:n,form:N,setForm:q,setSmtp:w,setShowSmtpPassword:G,setShowChannelSmtpPassword:p,loadChannels:L,openCreate:me,openEdit:ue,closeModal:xe,showToast:f,handleSave:ge,handleDelete:he,handleToggleEnabled:be,handleTest:ye,handleSaveSmtp:fe}},Qe=({isAdmin:s=!1})=>{const t=Je(s);return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"通知设置"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"配置通知渠道,账号异常时主动推送告警"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:t.loadChannels,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(we,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:t.openCreate,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Se,{className:"w-4 h-4"}),"新建渠道"]})]})]}),e.jsx("div",{className:"ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"w-5 h-5 text-brand mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-gray-700 leading-6",children:["配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:",e.jsxs("ul",{className:"mt-2 space-y-1 text-gray-600",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"账号 session 失效"}),":系统正在尝试自动恢复(警告)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"自动恢复失败"}),":账号已停止,需人工处理(严重)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),t.loading?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(J,{className:"w-8 h-8 text-brand animate-spin"})}):e.jsx(Me,{channels:t.channels,testingId:t.testingId,onEdit:t.openEdit,onDelete:t.handleDelete,onToggleEnabled:t.handleToggleEnabled,onTest:t.handleTest}),s&&e.jsx(Re,{smtp:t.smtp,setSmtp:t.setSmtp,smtpSaving:t.smtpSaving,showPassword:t.showSmtpPassword,setShowPassword:t.setShowSmtpPassword,onSave:t.handleSaveSmtp}),e.jsx(Le,{showModal:t.showModal,editing:t.editing,form:t.form,setForm:t.setForm,smtp:t.smtp,showChannelSmtpPassword:t.showChannelSmtpPassword,setShowChannelSmtpPassword:t.setShowChannelSmtpPassword,saving:t.saving,onClose:t.closeModal,onSave:t.handleSave}),t.toast&&e.jsxs("div",{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${t.toast.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[t.toast.type==="success"?e.jsx(V,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"}),t.toast.text]})]})};export{Qe as default}; diff --git a/internal/webui/static/assets/Notifications-xaqRCmgU.js b/internal/webui/static/assets/Notifications-xaqRCmgU.js new file mode 100644 index 0000000..13d24d6 --- /dev/null +++ b/internal/webui/static/assets/Notifications-xaqRCmgU.js @@ -0,0 +1 @@ +import{j as e,b as _e,a as d}from"./react-vendor-Bf9ELcll.js";import{al as te,S as ae,am as je,y as Q,g as I,L as J,H as Ne,T as ve,x as V,X as ne,J as re,N as le,s as ke,R as we,P as Se}from"./icons-vendor-BSp7PTZg.js";import{n as Ce}from"./settings-D-mx9vFJ.js";import{r as R,c as B}from"./chat-metadata-74T0w35U.js";import"./vendor-BE-_xUHH.js";const Y=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],H=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},oe=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),a=Y.some(r=>String(s[r]??"").trim()!=="");return{...s,use_custom_smtp:t?H(s.use_custom_smtp,!1):a}},ie=(s,t)=>{const a={...s,use_custom_smtp:!0};for(const r of Y)String(a[r]??"").trim()===""&&t[r]!==void 0&&(a[r]=t[r]);return a.smtp_port||(a.smtp_port=587),a.smtp_from_address||(a.smtp_from_address=a.smtp_user||""),a.smtp_use_tls=H(a.smtp_use_tls,!0),a.smtp_use_ssl=H(a.smtp_use_ssl,!1),a},ce=s=>{const t=oe(s),a={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(a.use_custom_smtp)for(const r of Y)a[r]=t[r];return a},$={bark:{label:"Bark",icon:I,fields:[{key:"server_url",label:"Bark 服务器",placeholder:"https://api.day.app",required:!0},{key:"device_key",label:"Device Key",placeholder:"你的 Bark 设备 Key",required:!0},{key:"title",label:"标题(可选)",placeholder:"Ydisks闲鱼助手"},{key:"sound",label:"铃声(可选)",placeholder:"default"},{key:"group",label:"分组(可选)",placeholder:"xianyu"}],guide:{steps:["App Store 搜索并安装 Bark(免费)","打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app//这是测试推送内容","URL 路径里 那一段就是 Device Key,复制填入","服务器地址默认 https://api.day.app,自建服务端则填自建域名"],urlFormat:"https://api.day.app/<你的key>/测试内容",note:"不需要 secret,Device Key 本身就是唯一凭证。"}},dingtalk:{label:"钉钉机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=...",required:!0},{key:"secret",label:"加签密钥",placeholder:"SEC...",help:"安全设置勾选「加签」后生成,SEC 开头"}],guide:{steps:["钉钉进入一个群(可建单人群)→ 右上角 群设置","机器人 → 添加机器人 → 选择「自定义机器人」","安全设置勾选「加签」","完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制","Webhook URL 填上面,Secret 填加签密钥"],urlFormat:"https://oapi.dingtalk.com/robot/send?access_token=XXX",note:"加签密钥可选,但强烈建议启用,否则机器人可能被滥用。"}},feishu:{label:"飞书机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/...",required:!0},{key:"secret",label:"签名校验密钥",placeholder:"sec-...",help:"安全设置选「签名校验」后生成"}],guide:{steps:["飞书进入目标群 → 右上角 更多 → 设置","群机器人 → 添加机器人 → 自定义机器人","安全设置选择「签名校验」,复制生成的秘钥","完成会给 Webhook 地址,复制","Webhook URL 填上面,秘钥填签名校验密钥"],urlFormat:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx",note:"签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。"}},wechat:{label:"企业微信机器人",icon:Q,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...",required:!0}],guide:{steps:["企业微信进入一个内部群 → 右上角 … → 群设置","找到「群机器人」(新版可能叫「消息推送」)","添加 → 选择自定义机器人","完成给 Webhook 地址(含 ?key=),复制填入"],urlFormat:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX",note:"不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。"}},webhook:{label:"自定义 Webhook",icon:je,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-server/notify",required:!0}],guide:{steps:["仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON","系统会 POST 这个 URL,Content-Type: application/json","请求体固定为右侧 JSON 格式,按需解析 message 字段"],urlFormat:'{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',note:"若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。"}},telegram:{label:"Telegram",icon:ae,fields:[{key:"bot_token",label:"Bot Token",placeholder:"123456:ABC-DEF...",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"-1001234567890 或你的用户 ID",required:!0}],guide:{steps:["在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token","把你的 Bot 拉进一个群,或私聊它发一条消息","浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates",'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'],urlFormat:"Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890",note:"群聊需先把 Bot 设为管理员才能发消息。"}},email:{label:"邮件",icon:te,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},de=[{value:"account_offline",label:"掉线通知",description:"账号过期、断线或登录态失效"},{value:"account_recovered",label:"恢复通知",description:"自动恢复成功并重新在线"},{value:"account_disabled",label:"禁用通知",description:"连续失败、账密错误等导致账号停用"},{value:"security_verification",label:"风控验证",description:"滑块、人脸、扫码验证等安全校验"},{value:"delivery_result",label:"交易通知",description:"订单发货、卡密发送等交易结果"},{value:"token_renewal",label:"续期通知",description:"Cookie/token 续期和自动恢复过程"},{value:"system_error",label:"系统错误",description:"后台任务或系统级异常"}],ee=()=>({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),Te=s=>!s||s.length===0?"全部事件":s.map(t=>{var a;return((a=de.find(r=>r.value===t))==null?void 0:a.label)||t}).join("、"),Pe=(s,t)=>{const a=s.type==="email"?oe({...s.config||{}}):null,r=a?a.use_custom_smtp===!0?ie(a,t):a:{...s.config||{}};return{name:s.name,type:s.type,enabled:s.enabled,config:r,event_types:s.event_types||[]}},Ee=s=>{const a=$[s.type].fields.find(r=>r.required&&!String(s.config[r.key]||"").trim());if(a)return`请填写 ${a.label}`;if(!s.name.trim())return"请填写渠道名称";if(s.type==="email"){const r=ce(s.config);if(r.use_custom_smtp){const k=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([b])=>!String(r[b]||"").trim());if(k)return`请填写 ${k[1]}`}}return""},Me=s=>({name:s.name.trim(),type:s.type,config:s.type==="email"?ce(s.config):s.config,event_types:s.event_types,enabled:s.enabled}),g=(s,t)=>s===t,F=(s,t)=>s instanceof Error&&s.message?s.message:t,qe=({channels:s,testingId:t,onEdit:a,onDelete:r,onToggleEnabled:h,onTest:k})=>{const b=l=>s.find(o=>o.id===l.currentTarget.dataset.channelId)||null,j=l=>{const o=b(l);o&&h(o)},S=l=>{const o=b(l);o&&k(o)},E=l=>{const o=b(l);o&&a(o)},_=l=>{const o=b(l);o&&r(o)},M=l=>{const o=$[l.type]||$.webhook,P=o.icon;return e.jsxs("div",{className:"ios-card rounded-xl p-5 bg-white flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 truncate",children:l.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:o.label}),!l.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium",children:"已停用"})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 truncate",children:o.fields.map(x=>{var w;return(w=l.config)==null?void 0:w[x.key]}).filter(Boolean).map((x,w)=>e.jsx("span",{className:"mr-3",children:String(x).length>40?`${String(x).slice(0,40)}…`:String(x)},w))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Te(l.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{"data-channel-id":l.id,onClick:j,className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${l.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:l.enabled?"启用中":"已停用"}),e.jsxs("button",{"data-channel-id":l.id,onClick:S,disabled:t===l.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[t===l.id?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(ae,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{"data-channel-id":l.id,onClick:E,className:"w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors",title:"编辑",children:e.jsx(Ne,{className:"w-4 h-4"})}),e.jsx("button",{"data-channel-id":l.id,onClick:_,className:"w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors",title:"删除",children:e.jsx(ve,{className:"w-4 h-4"})})]})]},l.id)};return s.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(I,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"还没有配置任何通知渠道"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"点击右上角「新建渠道」开始配置"})]}):e.jsx("div",{className:"space-y-3",children:s.map(M)})},Le=({selectedEvents:s,onToggleEvent:t})=>{const a=r=>{const h=r.currentTarget.dataset.event;h&&t(h)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"通知内容"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"不选择表示接收全部通知;选择后仅接收勾选类型。"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:de.map(r=>{const h=s.includes(r.value);return e.jsxs("button",{type:"button","data-event":r.value,onClick:a,className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${h?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center ${h?"bg-brand border-brand":"border-gray-300"}`,children:h&&e.jsx(V,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${h?"text-brand":"text-gray-800"}`,children:r.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:r.description})]},r.value)})})]})},Re=({showModal:s,editing:t,form:a,setForm:r,smtp:h,showChannelSmtpPassword:k,setShowChannelSmtpPassword:b,saving:j,onClose:S,onSave:E})=>{const _=$[a.type],M=n=>r(p=>({...p,name:n.target.value})),l=n=>{const p=n.currentTarget.dataset.type;p&&r(N=>({...N,type:p,config:{}}))},o=n=>{const p=n.currentTarget.dataset.field;p&&r(N=>({...N,config:{...N.config,[p]:n.target.value}}))},P=()=>r(n=>({...n,config:n.config.use_custom_smtp===!0?{...n.config,use_custom_smtp:!1}:ie(n.config,h)})),x=n=>r(p=>({...p,config:{...p.config,smtp_use_tls:n.target.checked,smtp_use_ssl:n.target.checked?!1:p.config.smtp_use_ssl}})),w=n=>r(p=>({...p,config:{...p.config,smtp_use_ssl:n.target.checked,smtp_use_tls:n.target.checked?!1:p.config.smtp_use_tls}})),z=n=>r(p=>({...p,event_types:p.event_types.includes(n)?p.event_types.filter(N=>N!==n):[...p.event_types,n]})),U=()=>r(n=>({...n,enabled:!n.enabled})),X=()=>b(n=>!n),G=(n,p)=>e.jsx("li",{children:n},p);return s?_e.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"36rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:t?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:S,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(ne,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道名称"}),e.jsx("input",{type:"text",value:a.name,onChange:M,placeholder:"例如:我的 Bark",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道类型"}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:Object.keys($).map(n=>{const p=$[n],N=p.icon,q=a.type===n;return e.jsxs("button",{"data-type":n,type:"button",onClick:l,className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${q?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(N,{className:`w-5 h-5 ${q?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${q?"text-brand":"text-gray-600"}`,children:p.label})]},n)})})]}),e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",_.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:_.guide.steps.map(G)}),_.guide.urlFormat&&e.jsxs("div",{className:"text-xs text-amber-900/90",children:[e.jsx("span",{className:"font-bold",children:"格式示例:"}),e.jsx("code",{className:"mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]",children:_.guide.urlFormat})]}),_.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",_.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:_.fields.map(n=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[n.label,n.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{"data-field":n.key,type:n.type==="password"?"password":n.type==="number"?"number":"text",value:String(a.config[n.key]||""),onChange:o,placeholder:n.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),n.help&&e.jsx("p",{className:"text-xs text-gray-500",children:n.help})]},n.key))}),a.type==="email"&&e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"SMTP 来源"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:a.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:P,className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${a.config.use_custom_smtp===!0?"bg-brand":"bg-gray-300"}`,"aria-label":"使用独立 SMTP",children:e.jsx("span",{className:`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${a.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),a.config.use_custom_smtp===!0&&e.jsxs("div",{className:"space-y-4 border-t border-blue-100 bg-white/80 p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 服务器 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:String(a.config.smtp_server||""),onChange:o,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 端口 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_port",type:"number",value:String(a.config.smtp_port||587),onChange:o,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["登录邮箱 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:String(a.config.smtp_user||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["密码 / 授权码 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{"data-field":"smtp_password",type:k?"text":"password",value:String(a.config.smtp_password||""),onChange:o,placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:X,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:k?e.jsx(re,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:String(a.config.smtp_from_name||""),onChange:o,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["发件邮箱地址 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:String(a.config.smtp_from_address||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_tls!==!1,onChange:x}),"STARTTLS(常用于 587)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_ssl===!0,onChange:w}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),e.jsx(Le,{selectedEvents:a.event_types,onToggleEvent:z}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:U,className:`relative w-11 h-6 rounded-full transition-colors ${a.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${a.enabled?"translate-x-5":""}`})}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"启用此渠道"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:S,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,disabled:j,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[j?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(V,{className:"w-4 h-4"}),j?"保存中...":"保存"]})]})]})}),document.body):null},Be=({smtp:s,setSmtp:t,smtpSaving:a,showPassword:r,setShowPassword:h,onSave:k})=>{const b=l=>{const o=l.currentTarget.dataset.field;o&&t(P=>({...P,[o]:l.target.value}))},j=l=>{t(o=>({...o,smtp_port:parseInt(l.target.value,10)||587}))},S=l=>{t(o=>({...o,smtp_use_tls:l.target.checked,smtp_use_ssl:l.target.checked?!1:o.smtp_use_ssl}))},E=l=>{t(o=>({...o,smtp_use_ssl:l.target.checked,smtp_use_tls:l.target.checked?!1:o.smtp_use_tls}))},_=l=>{t(o=>({...o,smtp_password:l.target.value}))},M=()=>h(l=>!l);return e.jsxs("section",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-extrabold text-gray-800",children:"SMTP 邮件配置"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"系统级邮件发送服务,供邮件通知渠道复用"})]}),e.jsx("div",{className:"p-2 rounded-xl bg-blue-50 text-blue-600",children:e.jsx(te,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 服务器"}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:typeof s.smtp_server=="string"?s.smtp_server:"",onChange:b,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 端口"}),e.jsx("input",{type:"number",value:typeof s.smtp_port=="number"?s.smtp_port:587,onChange:j,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱"}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:typeof s.smtp_user=="string"?s.smtp_user:"",onChange:b,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"邮箱密码 / 授权码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:r?"text":"password",value:typeof s.smtp_password=="string"?s.smtp_password:"",onChange:_,placeholder:s.smtp_password_configured?"已配置,如需替换请输入新密码":"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:M,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:r?e.jsx(re,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:typeof s.smtp_from_name=="string"?s.smtp_from_name:"",onChange:b,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱地址"}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:typeof s.smtp_from_address=="string"?s.smtp_from_address:typeof s.smtp_user=="string"?s.smtp_user:"",onChange:b,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_tls!==!1,onChange:S}),"STARTTLS(常用于 587 端口)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_ssl===!0,onChange:E}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:k,disabled:a,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(ke,{className:"w-4 h-4"}),a?"保存中...":"保存 SMTP 配置"]})]})},Ae=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},pe=s=>{const t=Array.from(new Set((s||[]).filter(Boolean)));return t.length>0?JSON.stringify(t):""},Oe=s=>{const t={},a=s.type==="ding_talk"?"dingtalk":s.type==="lark"?"feishu":s.type;return{id:String(s.id),name:s.name,type:a,config:t,event_types:Ae(s.event_types),enabled:s.enabled}},$e=async s=>({success:!0,data:(await R(a=>B.GET("/api/v1/notifications/channels",{signal:a}),s)).map(Oe)}),De=async(s,t)=>R(a=>B.POST("/api/v1/notifications/channels",{body:{name:s.name,type:s.type,config:JSON.stringify(s.config),event_types:pe(s.event_types),enabled:s.enabled},signal:a}),t),se=async(s,t,a)=>{const r={name:t.name,type:t.type,config:t.config===void 0?void 0:JSON.stringify(t.config),event_types:t.event_types===void 0?void 0:pe(t.event_types),enabled:t.enabled};return R(h=>B.PUT("/api/v1/notifications/channels/{channel_id}",{params:{path:{channel_id:s}},body:r,signal:h}),a)},Fe=async(s,t)=>R(a=>B.DELETE("/api/v1/notifications/channels/{channel_id}",{params:{path:{channel_id:s}},signal:a}),t),Ue=async(s,t)=>R(a=>B.POST("/api/v1/notifications/channels/{channel_id}/test",{params:{path:{channel_id:s}},signal:a}),t),We=s=>{const t={...s};if("renewal_log_retention_days"in t){const a=Number(t.renewal_log_retention_days);t.renewal_log_retention_days=Number.isFinite(a)?a:10}return t},Ie=async s=>{const t=await R(a=>B.GET("/api/v1/settings/system",{signal:a}),s);return We(t.data||t.settings||t)},Je=async(s,t)=>R(a=>B.PUT("/api/v1/settings/system",{body:Ce(s),signal:a}),t),ze=s=>{const[t,a]=d.useState([]),[r,h]=d.useState(!0),[k,b]=d.useState(!1),[j,S]=d.useState(null),[E,_]=d.useState(!1),[M,l]=d.useState(""),[o,P]=d.useState(null),[x,w]=d.useState({}),[z,U]=d.useState(!1),[X,G]=d.useState(!1),[n,p]=d.useState(!1),[N,q]=d.useState(ee),D=d.useRef(0),K=d.useRef(null),C=d.useRef(0),A=d.useRef(null),y=d.useRef(0),T=d.useRef(null),O=d.useRef(null),f=d.useCallback((i,c)=>{P({type:i,text:c}),O.current!==null&&window.clearTimeout(O.current),O.current=window.setTimeout(()=>{O.current=null,P(null)},3e3)},[]),L=d.useCallback(async()=>{var m;const i=++D.current;(m=K.current)==null||m.abort();const c=new AbortController;K.current=c,h(!0);try{const u=await $e({signal:c.signal});if(!g(i,D.current))return;a(u.data||[])}catch(u){g(i,D.current)&&!c.signal.aborted&&console.error("加载通知渠道失败",u)}finally{g(i,D.current)&&h(!1)}},[]),Z=d.useCallback(async()=>{var m;const i=++C.current;(m=A.current)==null||m.abort();const c=new AbortController;A.current=c;try{const u=await Ie({signal:c.signal});g(i,C.current)&&w(u||{})}catch(u){g(i,C.current)&&!c.signal.aborted&&console.error("加载 SMTP 配置失败",u)}},[]);d.useEffect(()=>{var i;return L(),s?Z():(C.current+=1,(i=A.current)==null||i.abort(),w({})),(()=>{var c,m;D.current+=1,(c=K.current)==null||c.abort(),C.current+=1,(m=A.current)==null||m.abort()})},[s,L,Z]),d.useEffect(()=>(()=>{O.current!==null&&window.clearTimeout(O.current)}),[]);const me=d.useCallback(()=>{S(null),q(ee()),p(!1),b(!0)},[]),ue=d.useCallback(i=>{S(i),q(Pe(i,x)),p(!1),b(!0)},[x]),xe=d.useCallback(()=>{var i;y.current+=1,(i=T.current)==null||i.abort(),_(!1),b(!1)},[]),ge=d.useCallback(async()=>{var u;const i=Ee(N);if(i){f("error",i);return}const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m,_(!0);try{const v=Me(N);if(j?await se(j.id,v,{signal:m.signal}):await De(v,{signal:m.signal}),!g(c,y.current)||(b(!1),await L(),!g(c,y.current)))return;f("success",j?"已更新":"已创建")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"保存失败"))}finally{g(c,y.current)&&_(!1)}},[j,N,L,f]),he=d.useCallback(async i=>{var u;if(!confirm(`确认删除渠道「${i.name}」吗?已绑定该渠道的账号会自动解绑。`))return;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await Fe(i.id,{signal:m.signal}),!g(c,y.current)||(await L(),!g(c,y.current)))return;f("success","已删除")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"删除失败"))}},[L,f]),be=d.useCallback(async i=>{var u;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await se(i.id,{enabled:!i.enabled},{signal:m.signal}),!g(c,y.current))return;a(v=>v.map(W=>W.id===i.id?{...W,enabled:!W.enabled}:W))}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"切换失败"))}},[f]),ye=d.useCallback(async i=>{var u;l(i.id);const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{await Ue(i.id,{signal:m.signal}),g(c,y.current)&&f("success","测试通知已发送,请检查对应渠道")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",F(v,"发送失败"))}finally{g(c,y.current)&&l("")}},[f]),fe=d.useCallback(async()=>{var m;const i=++C.current;(m=A.current)==null||m.abort();const c=new AbortController;A.current=c,U(!0);try{const u={smtp_server:x.smtp_server||"",smtp_port:x.smtp_port||587,smtp_user:x.smtp_user||"",smtp_from_name:x.smtp_from_name||"",smtp_from_address:x.smtp_from_address||x.smtp_user||"",smtp_use_tls:x.smtp_use_tls!==!1,smtp_use_ssl:x.smtp_use_ssl===!0};Object.prototype.hasOwnProperty.call(x,"smtp_password")&&(u.smtp_password=x.smtp_password),await Je(u,{signal:c.signal}),g(i,C.current)&&f("success","SMTP 配置已保存")}catch(u){g(i,C.current)&&!c.signal.aborted&&f("error",F(u,"保存失败"))}finally{g(i,C.current)&&U(!1)}},[f,x]);return{channels:t,loading:r,showModal:k,editing:j,saving:E,testingId:M,toast:o,smtp:x,smtpSaving:z,showSmtpPassword:X,showChannelSmtpPassword:n,form:N,setForm:q,setSmtp:w,setShowSmtpPassword:G,setShowChannelSmtpPassword:p,loadChannels:L,openCreate:me,openEdit:ue,closeModal:xe,showToast:f,handleSave:ge,handleDelete:he,handleToggleEnabled:be,handleTest:ye,handleSaveSmtp:fe}},Ve=({isAdmin:s=!1})=>{const t=ze(s);return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"通知设置"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"配置通知渠道,账号异常时主动推送告警"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:t.loadChannels,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(we,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:t.openCreate,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Se,{className:"w-4 h-4"}),"新建渠道"]})]})]}),e.jsx("div",{className:"ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"w-5 h-5 text-brand mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-gray-700 leading-6",children:["配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:",e.jsxs("ul",{className:"mt-2 space-y-1 text-gray-600",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"账号 session 失效"}),":系统正在尝试自动恢复(警告)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"自动恢复失败"}),":账号已停止,需人工处理(严重)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),t.loading?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(J,{className:"w-8 h-8 text-brand animate-spin"})}):e.jsx(qe,{channels:t.channels,testingId:t.testingId,onEdit:t.openEdit,onDelete:t.handleDelete,onToggleEnabled:t.handleToggleEnabled,onTest:t.handleTest}),s&&e.jsx(Be,{smtp:t.smtp,setSmtp:t.setSmtp,smtpSaving:t.smtpSaving,showPassword:t.showSmtpPassword,setShowPassword:t.setShowSmtpPassword,onSave:t.handleSaveSmtp}),e.jsx(Re,{showModal:t.showModal,editing:t.editing,form:t.form,setForm:t.setForm,smtp:t.smtp,showChannelSmtpPassword:t.showChannelSmtpPassword,setShowChannelSmtpPassword:t.setShowChannelSmtpPassword,saving:t.saving,onClose:t.closeModal,onSave:t.handleSave}),t.toast&&e.jsxs("div",{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${t.toast.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[t.toast.type==="success"?e.jsx(V,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"}),t.toast.text]})]})};export{Ve as default}; diff --git a/internal/webui/static/assets/Settings-BMAitcQx.js b/internal/webui/static/assets/Settings-BMAitcQx.js deleted file mode 100644 index da74f4f..0000000 --- a/internal/webui/static/assets/Settings-BMAitcQx.js +++ /dev/null @@ -1 +0,0 @@ -import{a as r,j as e}from"./react-vendor-Bf9ELcll.js";import{r as M,c as q}from"./chat-metadata-74T0w35U.js";import{h as xe,R as ae,ad as ue,v as pe,J as T,N as D,ae as me,x as he,b as re,af as le,ag as ge,s as ye}from"./icons-vendor-BSp7PTZg.js";import"./vendor-BE-_xUHH.js";const ne="https://dashscope.aliyuncs.com/compatible-mode/v1",fe=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],be=new Set(["ai_api_key_configured","smtp_password_configured","qq_reply_secret_key_configured","captcha.remote_secret_key_configured","smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","smtp_from_name","smtp_from_address","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),oe=new Set(["ai_api_key","smtp_password","qq_reply_secret_key","captcha.remote_secret_key"]),we=s=>{if("values"in s||"secrets"in s)return s;const a={},n={};for(const[d,x]of Object.entries(s))if(x!=null){if(oe.has(d)){n[d]=x===""?{action:"clear"}:{action:"replace",value:String(x)};continue}(typeof x=="string"||typeof x=="number"||typeof x=="boolean")&&(a[d]=x)}return Object.keys(n).length>0?{values:a,secrets:n}:a},je=s=>{const a={...s};for(const n of oe){const d=`${n}_configured`;d in a&&(a[d]=a[d]===!0||a[d]==="true")}if("renewal_log_retention_days"in a){const n=Number(a.renewal_log_retention_days);a.renewal_log_retention_days=Number.isFinite(n)?n:10}return a},ve=async(s,a)=>M(n=>q.PUT("/api/v1/session/credentials",{body:s,signal:n}),a),_e=async s=>{const a=await M(n=>q.GET("/api/v1/settings/system",{signal:n}),s);return je(a)},Ne=async(s,a)=>M(n=>q.PUT("/api/v1/settings/system",{body:we(s),signal:n}),a),Se=async(s,a="",n)=>{const d=await M(x=>q.POST("/api/v1/settings/ai-models",{body:{base_url:s,api_key:a},signal:x}),n);return Array.isArray(d.models)?d.models:[]},ke=async s=>M(a=>q.GET("/api/v1/session",{signal:a}),s),Ce=s=>Object.fromEntries(Object.entries(s).filter(([a,n])=>!be.has(a)&&n!==void 0&&n!==null)),Ee=s=>s.new_username.trim().length<3?"用户名至少需要 3 个字符":s.current_password?s.new_password&&s.new_password.length<8?"新密码至少需要 8 个字符":s.new_password!==s.confirm_password?"两次输入的新密码不一致":"":"请输入当前密码确认身份",f=(s,a,n)=>s===a&&!n.aborted,K=s=>s instanceof Error&&s.message==="请求已取消",U=(s,a)=>s instanceof Error?s.message:a,Ae=(s="")=>({new_username:s,current_password:"",new_password:"",confirm_password:""}),$=(s,a)=>({type:s,text:a}),Ie=()=>{const[s,a]=r.useState(null),[n,d]=r.useState(!1),[x,m]=r.useState(""),[S,A]=r.useState(!1),[R,k]=r.useState(""),[C,w]=r.useState([]),[j,I]=r.useState(!1),[P,u]=r.useState(""),[G,v]=r.useState(!1),[z,L]=r.useState(!1),[F,p]=r.useState(!1),[b,J]=r.useState(!1),[V,Y]=r.useState(!1),[W,_]=r.useState(!1),[O,y]=r.useState(null),[t,ee]=r.useState(()=>Ae()),[ce,B]=r.useState("idle"),se=r.useRef(null),te=r.useRef(null),h=r.useRef(0),H=r.useRef(null);te.current=s;const E=r.useCallback(()=>{var c;(c=H.current)==null||c.abort();const o=new AbortController;return H.current=o,h.current+=1,{controller:o,sequence:h.current}},[]),Q=r.useCallback(async(o,c=!1,l)=>{const i=o||te.current,g=(i==null?void 0:i.ai_api_url)||(i==null?void 0:i.ai_base_url)||ne;I(!0),u("");try{const N=await Se(g,(i==null?void 0:i.ai_api_key)||"",{signal:l});if(l!=null&&l.aborted)return;w(N),v(c&&N.length>0),!(i!=null&&i.ai_model)&&N.length>0&&a(Z=>Z&&{...Z,ai_model:N[0]})}catch(N){if(l!=null&&l.aborted||K(N))return;w([]),v(!1),u(U(N,"读取模型失败"))}finally{l!=null&&l.aborted||I(!1)}},[]),X=r.useCallback(()=>{const{controller:o,sequence:c}=E();d(!0),B("loading"),m(""),Promise.all([_e({signal:o.signal}),ke({signal:o.signal})]).then(([l,i])=>{f(h.current,c,o.signal)&&(a(l),i.username&&ee(g=>({...g,new_username:i.username||""})),Q(l,!1,o.signal),B("success"))}).catch(l=>{!f(h.current,c,o.signal)||K(l)||(a(null),m(U(l,"加载配置失败")),B("error"))}).finally(()=>{f(h.current,c,o.signal)&&d(!1)})},[E,Q]);r.useEffect(()=>(X(),(()=>{var o;return(o=H.current)==null?void 0:o.abort()})),[X]),r.useEffect(()=>{const o=c=>{var l;(l=se.current)!=null&&l.contains(c.target)||v(!1)};return document.addEventListener("mousedown",o),(()=>document.removeEventListener("mousedown",o))},[]);const ie=r.useCallback(async()=>{if(!s||S)return;const{controller:o,sequence:c}=E();A(!0),k("");try{if(await Ne(Ce(s),{signal:o.signal}),!f(h.current,c,o.signal))return;window.alert("系统配置已保存")}catch(l){if(!f(h.current,c,o.signal)||K(l))return;k(U(l,"保存配置失败"))}finally{f(h.current,c,o.signal)&&A(!1)}},[E,S,s]),de=r.useCallback(async o=>{o.preventDefault(),y(null);const c=Ee(t);if(c){y($("error",c));return}const{controller:l,sequence:i}=E();_(!0);try{const g=await ve({current_password:t.current_password,new_username:t.new_username.trim(),new_password:t.new_password||void 0},{signal:l.signal});if(!f(h.current,i,l.signal))return;if(!g.success){y($("error",g.message||"登录凭据更新失败"));return}y($("success",g.message||"登录凭据已更新")),window.setTimeout(()=>window.location.reload(),1400)}catch(g){if(!f(h.current,i,l.signal)||K(g))return;y($("error",U(g,"登录凭据更新失败")))}finally{f(h.current,i,l.signal)&&_(!1)}},[E,t]);return{settings:s,loading:n,loadError:x,saving:S,saveError:R,aiModels:C,modelsLoading:j,modelError:P,modelDropdownOpen:G,showApiKey:z,showCaptchaSecret:F,showCurrentPassword:b,showNewPassword:V,credentialsSaving:W,credentialsMessage:O,credentials:t,requestStatus:ce,modelPickerRef:se,loadSettings:X,loadAIModels:((o,c)=>void Q(o,c)),handleSave:ie,handleCredentialsSave:de,setSettings:a,setModelDropdownOpen:v,setShowApiKey:L,setShowCaptchaSecret:p,setShowCurrentPassword:J,setShowNewPassword:Y,setCredentials:ee,setCredentialsMessage:y}},Le=()=>{const{settings:s,loading:a,loadError:n,saving:d,saveError:x,aiModels:m,modelsLoading:S,modelError:A,modelDropdownOpen:R,showApiKey:k,showCaptchaSecret:C,showCurrentPassword:w,showNewPassword:j,credentialsSaving:I,credentialsMessage:P,credentials:u,modelPickerRef:G,loadSettings:v,loadAIModels:z,handleSave:L,handleCredentialsSave:F,setSettings:p,setModelDropdownOpen:b,setShowApiKey:J,setShowCaptchaSecret:V,setShowCurrentPassword:Y,setShowNewPassword:W,setCredentials:_}=Ie();if(!s)return e.jsxs("div",{className:"p-8 text-center text-gray-400 space-y-3",children:[n||(a?"加载配置中...":"暂无配置"),!a&&n&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:v,children:"重新加载"})})]});const O=s.ai_model||"",y=m;return e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8 animate-fade-in pb-24",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl flex items-center justify-center",children:e.jsx(xe,{className:"w-6 h-6 text-gray-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900",children:"系统设置"}),e.jsx("p",{className:"text-gray-500 mt-1 text-sm font-medium",children:"配置全局自动化规则与系统参数"})]})]}),e.jsxs("button",{onClick:v,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(ae,{className:"w-4 h-4"}),"刷新"]})]}),x&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:x}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>{}),children:"重试保存"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-100 text-gray-600",children:e.jsx(ue,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:(t=>p({...s,log_level:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:fe.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:(t=>p({...s,log_format:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:(t=>p({...s,renewal_log_retention_days:parseInt(t.target.value)||0})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"365"}),e.jsx("p",{className:"text-xs text-gray-500",children:"0 表示不自动清理续期日志"})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-brand text-white",children:e.jsx(pe,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||ne,onChange:(t=>p({...s,ai_api_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-gray-500",children:"无需补全 /chat/completions"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:s.ai_api_key||"",onChange:(t=>p({...s,ai_api_key:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:s.ai_api_key_configured?"已配置,如需替换请输入新密钥":"sk-..."}),e.jsx("button",{type:"button",onClick:(()=>J(!k)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:k?e.jsx(T,{className:"w-4 h-4"}):e.jsx(D,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"模型"}),e.jsxs("div",{ref:G,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:O,onFocus:(()=>m.length>0&&b(!0)),onChange:(t=>{p({...s,ai_model:t.target.value}),m.length>0&&b(!0)}),onKeyDown:(t=>{t.key==="Escape"&&b(!1),t.key==="ArrowDown"&&m.length>0&&b(!0)}),className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:(()=>m.length>0&&b(t=>!t)),disabled:m.length===0,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 disabled:opacity-30","aria-label":"展开模型列表",children:e.jsx(me,{className:`w-4 h-4 transition-transform ${R?"rotate-180":""}`})}),R&&e.jsx("div",{className:"absolute left-0 right-0 top-[calc(100%+6px)] z-40 max-h-64 overflow-y-auto rounded-xl border border-gray-200 bg-white shadow-xl shadow-gray-200/70 py-1",children:y.length>0?y.map(t=>e.jsxs("button",{type:"button",onClick:(()=>{p({...s,ai_model:t}),b(!1)}),className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:t}),t===O&&e.jsx(he,{className:"w-4 h-4 shrink-0 text-brand"})]},t)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:(()=>z(void 0,!0)),disabled:S,className:"px-4 py-3 rounded-xl bg-gray-100 text-gray-700 hover:bg-gray-200 disabled:opacity-60 font-bold flex items-center justify-center gap-2 whitespace-nowrap",children:[e.jsx(ae,{className:`w-4 h-4 ${S?"animate-spin":""}`}),"读取模型"]})]}),A?e.jsx("p",{className:"text-xs text-red-500",children:A}):e.jsx("p",{className:"text-xs text-gray-500",children:m.length>0?`已从当前 API 地址读取到 ${m.length} 个模型`:"模型列表从当前 API 地址读取,也可以手动输入模型名"})]}),e.jsxs("div",{className:"p-3 bg-blue-50 rounded-xl text-xs text-blue-700",children:[e.jsx("strong",{children:"常见 AI 服务:"}),e.jsxs("ul",{className:"list-disc list-inside mt-1 space-y-0.5",children:[e.jsx("li",{children:"阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1"}),e.jsx("li",{children:"OpenAI: https://api.openai.com/v1"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-amber-500 text-white",children:e.jsx(re,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:(t=>p({...s,"captcha.remote_service_url":t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://example.com/internal/captcha/solve"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务秘钥"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:C?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:(t=>p({...s,"captcha.remote_secret_key":t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off",placeholder:s["captcha.remote_secret_key_configured"]?"已配置,如需替换请输入新密钥":"请输入服务秘钥"}),e.jsx("button",{type:"button",onClick:(()=>V(!C)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:C?"隐藏秘钥":"显示秘钥",children:C?e.jsx(T,{className:"w-4 h-4"}):e.jsx(D,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:(t=>p({...s,"captcha.remote_pass_cookies":t.target.checked})),className:"mt-0.5 w-4 h-4 rounded border-gray-300"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-bold text-amber-900",children:"允许向远程服务传递账号 Cookie"}),e.jsx("span",{className:"block mt-1 text-xs text-amber-700",children:"默认关闭。仅在信任远程服务且需要由其自动重取过期验证链接时开启。"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-900 text-white",children:e.jsx(le,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:F,className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"登录用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(ge,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:u.new_username,onChange:(t=>_({...u,new_username:t.target.value})),className:"w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm",autoComplete:"username"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"当前密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:w?"text":"password",value:u.current_password,onChange:(t=>_({...u,current_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm",placeholder:"用于确认当前身份",autoComplete:"current-password"}),e.jsx("button",{type:"button",onClick:(()=>Y(!w)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:w?"隐藏密码":"显示密码",children:w?e.jsx(T,{className:"w-4 h-4"}):e.jsx(D,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"新密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:j?"text":"password",value:u.new_password,onChange:(t=>_({...u,new_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm",placeholder:"不修改则留空",autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:(()=>W(!j)),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:j?"隐藏密码":"显示密码",children:j?e.jsx(T,{className:"w-4 h-4"}):e.jsx(D,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"确认新密码"}),e.jsx("input",{type:j?"text":"password",value:u.confirm_password,onChange:(t=>_({...u,confirm_password:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),P&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${P.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(re,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:P.text})]}),e.jsxs("button",{type:"submit",disabled:I||!u.new_username||!u.current_password,className:"w-full bg-gray-900 hover:bg-black text-white px-5 py-3 rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors disabled:opacity-40",children:[e.jsx(le,{className:"w-4 h-4"}),I?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:L,disabled:d,className:"ios-btn-primary px-10 py-5 rounded-xl text-lg shadow-2xl shadow-blue-200 flex items-center gap-3 transform hover:scale-105 active:scale-95 transition-all disabled:opacity-70",children:[e.jsx(ye,{className:"w-6 h-6"}),d?"保存中...":"保存所有配置"]})})]})};export{Le as default}; diff --git a/internal/webui/static/assets/Settings-CbgtqNcx.js b/internal/webui/static/assets/Settings-CbgtqNcx.js new file mode 100644 index 0000000..8f4939a --- /dev/null +++ b/internal/webui/static/assets/Settings-CbgtqNcx.js @@ -0,0 +1 @@ +import{a as r,j as e}from"./react-vendor-Bf9ELcll.js";import{r as M,c as R}from"./chat-metadata-74T0w35U.js";import{n as de,S as xe}from"./settings-D-mx9vFJ.js";import{h as ue,R as ae,ad as pe,v as me,J as D,N as O,ae as he,x as ge,b as re,af as le,ag as ye,s as fe}from"./icons-vendor-BSp7PTZg.js";import"./vendor-BE-_xUHH.js";const ne="https://dashscope.aliyuncs.com/compatible-mode/v1",be=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],we=new Set(["ai_api_key_configured","smtp_password_configured","qq_reply_secret_key_configured","captcha.remote_secret_key_configured","smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","smtp_from_name","smtp_from_address","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),je=s=>{const a={...s};for(const o of xe){const d=`${o}_configured`;d in a&&(a[d]=a[d]===!0||a[d]==="true")}if("renewal_log_retention_days"in a){const o=Number(a.renewal_log_retention_days);a.renewal_log_retention_days=Number.isFinite(o)?o:10}return a},ve=async(s,a)=>M(o=>R.PUT("/api/v1/session/credentials",{body:s,signal:o}),a),Ne=async s=>{const a=await M(o=>R.GET("/api/v1/settings/system",{signal:o}),s);return je(a)},_e=async(s,a)=>M(o=>R.PUT("/api/v1/settings/system",{body:de(s),signal:o}),a),Se=async(s,a="",o)=>{const d=await M(_=>R.POST("/api/v1/settings/ai-models",{body:{base_url:s,api_key:a},signal:_}),o);return Array.isArray(d.models)?d.models:[]},Ce=async s=>M(a=>R.GET("/api/v1/session",{signal:a}),s),ke=s=>Object.fromEntries(Object.entries(s).filter(([a,o])=>!we.has(a)&&o!==void 0&&o!==null)),Ee=s=>s.new_username.trim().length<3?"用户名至少需要 3 个字符":s.current_password?s.new_password&&s.new_password.length<8?"新密码至少需要 8 个字符":s.new_password!==s.confirm_password?"两次输入的新密码不一致":"":"请输入当前密码确认身份",y=(s,a,o)=>s===a&&!o.aborted,K=s=>s instanceof Error&&s.message==="请求已取消",U=(s,a)=>s instanceof Error?s.message:a,Ae=(s="")=>({new_username:s,current_password:"",new_password:"",confirm_password:""}),$=(s,a)=>({type:s,text:a}),Ie=()=>{const[s,a]=r.useState(null),[o,d]=r.useState(!1),[_,p]=r.useState(""),[S,A]=r.useState(!1),[L,C]=r.useState(""),[k,b]=r.useState([]),[w,I]=r.useState(!1),[P,x]=r.useState(""),[G,j]=r.useState(!1),[z,T]=r.useState(!1),[F,u]=r.useState(!1),[f,J]=r.useState(!1),[V,Y]=r.useState(!1),[W,v]=r.useState(!1),[q,g]=r.useState(null),[t,ee]=r.useState(()=>Ae()),[oe,B]=r.useState("idle"),se=r.useRef(null),te=r.useRef(null),m=r.useRef(0),H=r.useRef(null);te.current=s;const E=r.useCallback(()=>{var c;(c=H.current)==null||c.abort();const n=new AbortController;return H.current=n,m.current+=1,{controller:n,sequence:m.current}},[]),Q=r.useCallback(async(n,c=!1,l)=>{const i=n||te.current,h=(i==null?void 0:i.ai_api_url)||(i==null?void 0:i.ai_base_url)||ne;I(!0),x("");try{const N=await Se(h,(i==null?void 0:i.ai_api_key)||"",{signal:l});if(l!=null&&l.aborted)return;b(N),j(c&&N.length>0),!(i!=null&&i.ai_model)&&N.length>0&&a(Z=>Z&&{...Z,ai_model:N[0]})}catch(N){if(l!=null&&l.aborted||K(N))return;b([]),j(!1),x(U(N,"读取模型失败"))}finally{l!=null&&l.aborted||I(!1)}},[]),X=r.useCallback(()=>{const{controller:n,sequence:c}=E();d(!0),B("loading"),p(""),Promise.all([Ne({signal:n.signal}),Ce({signal:n.signal})]).then(([l,i])=>{y(m.current,c,n.signal)&&(a(l),i.username&&ee(h=>({...h,new_username:i.username||""})),Q(l,!1,n.signal),B("success"))}).catch(l=>{!y(m.current,c,n.signal)||K(l)||(a(null),p(U(l,"加载配置失败")),B("error"))}).finally(()=>{y(m.current,c,n.signal)&&d(!1)})},[E,Q]);r.useEffect(()=>(X(),(()=>{var n;return(n=H.current)==null?void 0:n.abort()})),[X]),r.useEffect(()=>{const n=c=>{var l;(l=se.current)!=null&&l.contains(c.target)||j(!1)};return document.addEventListener("mousedown",n),(()=>document.removeEventListener("mousedown",n))},[]);const ce=r.useCallback(async()=>{if(!s||S)return;const{controller:n,sequence:c}=E();A(!0),C("");try{if(await _e(ke(s),{signal:n.signal}),!y(m.current,c,n.signal))return;window.alert("系统配置已保存")}catch(l){if(!y(m.current,c,n.signal)||K(l))return;C(U(l,"保存配置失败"))}finally{y(m.current,c,n.signal)&&A(!1)}},[E,S,s]),ie=r.useCallback(async n=>{n.preventDefault(),g(null);const c=Ee(t);if(c){g($("error",c));return}const{controller:l,sequence:i}=E();v(!0);try{const h=await ve({current_password:t.current_password,new_username:t.new_username.trim(),new_password:t.new_password||void 0},{signal:l.signal});if(!y(m.current,i,l.signal))return;if(!h.success){g($("error",h.message||"登录凭据更新失败"));return}g($("success",h.message||"登录凭据已更新")),window.setTimeout(()=>window.location.reload(),1400)}catch(h){if(!y(m.current,i,l.signal)||K(h))return;g($("error",U(h,"登录凭据更新失败")))}finally{y(m.current,i,l.signal)&&v(!1)}},[E,t]);return{settings:s,loading:o,loadError:_,saving:S,saveError:L,aiModels:k,modelsLoading:w,modelError:P,modelDropdownOpen:G,showApiKey:z,showCaptchaSecret:F,showCurrentPassword:f,showNewPassword:V,credentialsSaving:W,credentialsMessage:q,credentials:t,requestStatus:oe,modelPickerRef:se,loadSettings:X,loadAIModels:((n,c)=>void Q(n,c)),handleSave:ce,handleCredentialsSave:ie,setSettings:a,setModelDropdownOpen:j,setShowApiKey:T,setShowCaptchaSecret:u,setShowCurrentPassword:J,setShowNewPassword:Y,setCredentials:ee,setCredentialsMessage:g}},qe=()=>{const{settings:s,loading:a,loadError:o,saving:d,saveError:_,aiModels:p,modelsLoading:S,modelError:A,modelDropdownOpen:L,showApiKey:C,showCaptchaSecret:k,showCurrentPassword:b,showNewPassword:w,credentialsSaving:I,credentialsMessage:P,credentials:x,modelPickerRef:G,loadSettings:j,loadAIModels:z,handleSave:T,handleCredentialsSave:F,setSettings:u,setModelDropdownOpen:f,setShowApiKey:J,setShowCaptchaSecret:V,setShowCurrentPassword:Y,setShowNewPassword:W,setCredentials:v}=Ie();if(!s)return e.jsxs("div",{className:"p-8 text-center text-gray-400 space-y-3",children:[o||(a?"加载配置中...":"暂无配置"),!a&&o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:j,children:"重新加载"})})]});const q=s.ai_model||"",g=p;return e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8 animate-fade-in pb-24",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl flex items-center justify-center",children:e.jsx(ue,{className:"w-6 h-6 text-gray-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900",children:"系统设置"}),e.jsx("p",{className:"text-gray-500 mt-1 text-sm font-medium",children:"配置全局自动化规则与系统参数"})]})]}),e.jsxs("button",{onClick:j,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(ae,{className:"w-4 h-4"}),"刷新"]})]}),_&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:_}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>{}),children:"重试保存"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-100 text-gray-600",children:e.jsx(pe,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:(t=>u({...s,log_level:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:be.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:(t=>u({...s,log_format:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:(t=>u({...s,renewal_log_retention_days:parseInt(t.target.value)||0})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"365"}),e.jsx("p",{className:"text-xs text-gray-500",children:"0 表示不自动清理续期日志"})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-brand text-white",children:e.jsx(me,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||ne,onChange:(t=>u({...s,ai_api_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-gray-500",children:"无需补全 /chat/completions"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:C?"text":"password",value:s.ai_api_key||"",onChange:(t=>u({...s,ai_api_key:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:s.ai_api_key_configured?"已配置,如需替换请输入新密钥":"sk-..."}),e.jsx("button",{type:"button",onClick:(()=>J(!C)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:C?e.jsx(D,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"模型"}),e.jsxs("div",{ref:G,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:q,onFocus:(()=>p.length>0&&f(!0)),onChange:(t=>{u({...s,ai_model:t.target.value}),p.length>0&&f(!0)}),onKeyDown:(t=>{t.key==="Escape"&&f(!1),t.key==="ArrowDown"&&p.length>0&&f(!0)}),className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:(()=>p.length>0&&f(t=>!t)),disabled:p.length===0,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 disabled:opacity-30","aria-label":"展开模型列表",children:e.jsx(he,{className:`w-4 h-4 transition-transform ${L?"rotate-180":""}`})}),L&&e.jsx("div",{className:"absolute left-0 right-0 top-[calc(100%+6px)] z-40 max-h-64 overflow-y-auto rounded-xl border border-gray-200 bg-white shadow-xl shadow-gray-200/70 py-1",children:g.length>0?g.map(t=>e.jsxs("button",{type:"button",onClick:(()=>{u({...s,ai_model:t}),f(!1)}),className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:t}),t===q&&e.jsx(ge,{className:"w-4 h-4 shrink-0 text-brand"})]},t)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:(()=>z(void 0,!0)),disabled:S,className:"px-4 py-3 rounded-xl bg-gray-100 text-gray-700 hover:bg-gray-200 disabled:opacity-60 font-bold flex items-center justify-center gap-2 whitespace-nowrap",children:[e.jsx(ae,{className:`w-4 h-4 ${S?"animate-spin":""}`}),"读取模型"]})]}),A?e.jsx("p",{className:"text-xs text-red-500",children:A}):e.jsx("p",{className:"text-xs text-gray-500",children:p.length>0?`已从当前 API 地址读取到 ${p.length} 个模型`:"模型列表从当前 API 地址读取,也可以手动输入模型名"})]}),e.jsxs("div",{className:"p-3 bg-blue-50 rounded-xl text-xs text-blue-700",children:[e.jsx("strong",{children:"常见 AI 服务:"}),e.jsxs("ul",{className:"list-disc list-inside mt-1 space-y-0.5",children:[e.jsx("li",{children:"阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1"}),e.jsx("li",{children:"OpenAI: https://api.openai.com/v1"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-amber-500 text-white",children:e.jsx(re,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:(t=>u({...s,"captcha.remote_service_url":t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://example.com/internal/captcha/solve"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务秘钥"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:(t=>u({...s,"captcha.remote_secret_key":t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off",placeholder:s["captcha.remote_secret_key_configured"]?"已配置,如需替换请输入新密钥":"请输入服务秘钥"}),e.jsx("button",{type:"button",onClick:(()=>V(!k)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:k?"隐藏秘钥":"显示秘钥",children:k?e.jsx(D,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:(t=>u({...s,"captcha.remote_pass_cookies":t.target.checked})),className:"mt-0.5 w-4 h-4 rounded border-gray-300"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-bold text-amber-900",children:"允许向远程服务传递账号 Cookie"}),e.jsx("span",{className:"block mt-1 text-xs text-amber-700",children:"默认关闭。仅在信任远程服务且需要由其自动重取过期验证链接时开启。"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-900 text-white",children:e.jsx(le,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:F,className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"登录用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(ye,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:x.new_username,onChange:(t=>v({...x,new_username:t.target.value})),className:"w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm",autoComplete:"username"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"当前密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:b?"text":"password",value:x.current_password,onChange:(t=>v({...x,current_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm",placeholder:"用于确认当前身份",autoComplete:"current-password"}),e.jsx("button",{type:"button",onClick:(()=>Y(!b)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:b?"隐藏密码":"显示密码",children:b?e.jsx(D,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"新密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:w?"text":"password",value:x.new_password,onChange:(t=>v({...x,new_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm",placeholder:"不修改则留空",autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:(()=>W(!w)),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:w?"隐藏密码":"显示密码",children:w?e.jsx(D,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"确认新密码"}),e.jsx("input",{type:w?"text":"password",value:x.confirm_password,onChange:(t=>v({...x,confirm_password:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),P&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${P.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(re,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:P.text})]}),e.jsxs("button",{type:"submit",disabled:I||!x.new_username||!x.current_password,className:"w-full bg-gray-900 hover:bg-black text-white px-5 py-3 rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors disabled:opacity-40",children:[e.jsx(le,{className:"w-4 h-4"}),I?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:T,disabled:d,className:"ios-btn-primary px-10 py-5 rounded-xl text-lg shadow-2xl shadow-blue-200 flex items-center gap-3 transform hover:scale-105 active:scale-95 transition-all disabled:opacity-70",children:[e.jsx(fe,{className:"w-6 h-6"}),d?"保存中...":"保存所有配置"]})})]})};export{qe as default}; diff --git a/internal/webui/static/assets/index-dO7JyNQY.js b/internal/webui/static/assets/index-Q3nlx6gR.js similarity index 81% rename from internal/webui/static/assets/index-dO7JyNQY.js rename to internal/webui/static/assets/index-Q3nlx6gR.js index 5994470..6768cc8 100644 --- a/internal/webui/static/assets/index-dO7JyNQY.js +++ b/internal/webui/static/assets/index-Q3nlx6gR.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-DBUkwLYQ.js","assets/react-vendor-Bf9ELcll.js","assets/dateTime-DDi7rqpW.js","assets/icons-vendor-BSp7PTZg.js","assets/charts-vendor-DBu_rVrn.js","assets/vendor-BE-_xUHH.js","assets/vendor-DUblxfbA.css","assets/chat-metadata-74T0w35U.js","assets/contract-COFcZjyb.js","assets/AccountList-D1PDvKjr.js","assets/OrderList-CKY0um79.js","assets/CardList-BG11KU7H.js","assets/ItemList-D-9IbEjX.js","assets/Settings-BMAitcQx.js","assets/Rules-DCuiI2LD.js","assets/Notifications-BepLRaYn.js","assets/Chat-8cCRP4iO.js","assets/audio-codec-mjVr_wwJ.js"])))=>i.map(i=>d[i]); -import{d as P,j as e,a as i,e as H}from"./react-vendor-Bf9ELcll.js";import{r as j,c as L,g as Z,a as Y}from"./chat-metadata-74T0w35U.js";import{L as D,a as A,b as K,U as W,A as J,c as Q,d as X,M as ee,e as te,B as se,f as ne,Z as ae,g as re,h as oe,G as I,i as ie,j as le,k as ce}from"./icons-vendor-BSp7PTZg.js";import"./vendor-BE-_xUHH.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))m(r);new MutationObserver(r=>{for(const l of r)if(l.type==="childList")for(const o of l.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&m(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const l={};return r.integrity&&(l.integrity=r.integrity),r.referrerPolicy&&(l.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?l.credentials="include":r.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function m(r){if(r.ep)return;r.ep=!0;const l=n(r);fetch(r.href,l)}})();class de extends P.Component{constructor(){super(...arguments),this.state={hasError:!1},this.handleReload=()=>{window.location.reload()}}static getDerivedStateFromError(){return{hasError:!0}}render(){const{hasError:s}=this.state,{children:n}=this.props;return s?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-6 text-ink",children:e.jsxs("section",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"页面暂时无法显示"}),e.jsx("button",{className:"ios-btn-primary mt-6 px-4 py-2",type:"button",onClick:this.handleReload,children:"重新加载"})]})}):n}}const ue=async t=>{const s=await j(n=>L.POST("/api/v1/session/login",{body:t,signal:n}),{skipAuthLogout:!0});return{...s,token:s.token??void 0}},he=async t=>{const s=await j(n=>L.POST("/api/v1/session/initialize",{body:{password:t},signal:n}),{skipAuthLogout:!0});return{...s,token:s.token??void 0}},me=async t=>j(s=>L.GET("/api/v1/session",{signal:s}),t),fe=async()=>({success:!0,message:(await j(s=>L.POST("/api/v1/session/logout",{body:{},signal:s}))).message}),$=i.createContext(void 0),xe=({children:t})=>{const[s,n]=i.useState(!1),[m,r]=i.useState(!1),[l,o]=i.useState(!0),[a,d]=i.useState(!1),c=()=>{n(!1),r(!1)};i.useEffect(()=>{const p=new AbortController;let x=!0;me({signal:p.signal}).then(b=>{if(x){if((b==null?void 0:b.initialized)===!1){d(!0),c();return}d(!1),b!=null&&b.authenticated?(n(!0),r(b.is_admin===!0)):c()}}).catch(b=>{!x||b instanceof DOMException&&b.name==="AbortError"||(d(!1),c())}).finally(()=>{x&&o(!1)});const u=()=>c();return window.addEventListener("auth:logout",u),(()=>{x=!1,p.abort(),window.removeEventListener("auth:logout",u)})},[]);const h=async p=>{const x=await ue(p);return x.success&&(d(!1),n(!0),r(x.is_admin===!0)),x},g=async p=>{const x=await he(p);return x.success&&(d(!1),n(!0),r(x.is_admin===!0)),x},f=async()=>{try{await fe()}finally{c()}};return e.jsx($.Provider,{value:{checkingAuth:l,isLoggedIn:s,isAdmin:m,needsInit:a,signIn:h,initialize:g,signOut:f},children:t})},M=()=>{const t=i.useContext($);if(!t)throw new Error("useSession 必须在 SessionProvider 内使用");return t},z="ydisks.sidebar.v1",pe=()=>{try{return window.localStorage.getItem(z)==="collapsed"}catch{return!1}},ge=t=>{try{window.localStorage.setItem(z,t?"collapsed":"expanded")}catch{}},be=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),U=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88.46 8.78 L 92.71 10.34 L 96.49 12.25 L 99.87 14.52 L 102.86 17.14 L 105.48 20.13 L 107.75 23.51 L 109.66 27.29 L 111.22 31.54 L 112.44 36.33 L 113.31 41.84 L 113.83 48.52 Z",fill:"url(#login-squircle-gradient)"})]}),e.jsx("div",{className:"relative z-10 flex items-center justify-center w-full h-full",children:e.jsx(be,{className:s})})]})]}),ve=()=>{const{checkingAuth:t,needsInit:s,signIn:n,initialize:m}=M(),[r,l]=i.useState(""),[o,a]=i.useState(""),[d,c]=i.useState(""),[h,g]=i.useState(""),[f,p]=i.useState(!1),[x,u]=i.useState(""),b=async v=>{v.preventDefault(),p(!0),u("");try{const w=await n({username:r,password:o});w.success||u(w.message||"登录失败")}catch(w){u(w instanceof Error&&w.message||"登录失败")}finally{p(!1)}},C=async v=>{if(v.preventDefault(),u(""),d.length<8){u("密码至少需要 8 个字符");return}if(d!==h){u("两次输入的密码不一致");return}p(!0);try{const w=await m(d);if(!w.success){u(w.message||"初始化失败,请重试");return}c(""),g("")}catch(w){u(w instanceof Error&&w.message||"初始化失败,请重试")}finally{p(!1)}};if(t)return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-surface","aria-label":"正在校验会话",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-brand"})});const q=s?"首次设置管理员密码":"欢迎回来",G=s?"设置完成后会自动进入系统,管理员账号为 admin。":"Ydisks闲鱼助手 · 自动发货与管家系统";return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-4 font-sans",children:e.jsxs("section",{className:"w-full max-w-lg rounded-xl border border-white bg-white/80 p-8 shadow-panel backdrop-blur-3xl md:p-12",children:[e.jsxs("header",{className:"mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(U,{sizeClass:"h-24 w-24"})}),e.jsx("h1",{className:"text-3xl font-extrabold text-gray-900",children:q}),e.jsx("p",{className:"mt-2 font-medium text-gray-600",children:G})]}),s?e.jsxs("form",{className:"space-y-5",onSubmit:C,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"设置管理员密码"}),e.jsx(A,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>c(v.target.value)),placeholder:"设置管理员密码(至少 8 个字符)",type:"password",value:d})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"确认管理员密码"}),e.jsx(K,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>g(v.target.value)),placeholder:"再次输入密码",type:"password",value:h})]}),e.jsx(R,{submitting:f,text:"设置密码并进入系统"})]}):e.jsxs("form",{className:"space-y-5",onSubmit:b,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员账号"}),e.jsx(W,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>l(v.target.value)),placeholder:"管理员账号",type:"text",value:r})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员密码"}),e.jsx(A,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>a(v.target.value)),placeholder:"密码",type:"password",value:o})]}),e.jsx(R,{submitting:f,text:"立即登录"})]}),x?e.jsx("p",{className:"mt-5 rounded-xl bg-red-50 p-3 text-center text-sm font-medium text-red-600",children:x}):null]})})},R=({submitting:t,text:s})=>e.jsx("button",{className:"ios-btn-primary flex h-14 w-full items-center justify-center gap-2 rounded-xl text-lg disabled:opacity-70",disabled:t,type:"submit",children:t?e.jsx(D,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:s}),e.jsx(J,{className:"h-5 w-5"})]})}),we="modulepreload",ye=function(t){return"/static/"+t},T={},y=function(s,n,m){let r=Promise.resolve();if(n&&n.length>0){let o=function(c){return Promise.all(c.map(h=>Promise.resolve(h).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),d=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));r=o(n.map(c=>{if(c=ye(c),c in T)return;T[c]=!0;const h=c.endsWith(".css"),g=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${g}`))return;const f=document.createElement("link");if(f.rel=h?"stylesheet":we,h||(f.as="script"),f.crossOrigin="",f.href=c,d&&f.setAttribute("nonce",d),document.head.appendChild(f),h)return new Promise((p,x)=>{f.addEventListener("load",p),f.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${c}`)))})}))}function l(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return r.then(o=>{for(const a of o||[])a.status==="rejected"&&l(a.reason);return s().catch(l)})},je=({activeTab:t,isAdmin:s=!1,collapsed:n,onToggleCollapsed:m,onNavigate:r,onLogout:l,buildInfo:o,hasUnreadChatMessage:a=!1})=>{const d=[{id:"dashboard",icon:Q,label:"仪表盘"},{id:"accounts",icon:X,label:"账号管理"},{id:"chat",icon:ee,label:"在线聊天"},{id:"cards",icon:te,label:"卡密库存"},{id:"items",icon:se,label:"商品列表"},{id:"orders",icon:ne,label:"订单管理"},{id:"rules",icon:ae,label:"自动化规则"},{id:"notifications",icon:re,label:"通知设置"},...s?[{id:"settings",icon:oe,label:"系统与AI"}]:[]],c=/^\d+\.\d+\.\d+$/.test(o.version)?`v${o.version}`:o.version;return e.jsxs("aside",{className:`fixed inset-y-0 left-0 z-20 flex flex-col border-r border-slate-200/80 bg-white/95 shadow-sidebar backdrop-blur-xl transition-[width] duration-300 ${n?"w-16":"w-64"}`,children:[e.jsxs("div",{className:`flex h-20 items-center border-b border-slate-100 ${n?"justify-center px-2":"gap-3 px-5"}`,children:[e.jsx(U,{sizeClass:"h-10 w-10"}),!n&&e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"truncate text-base font-black tracking-tight text-slate-950",children:"Ydisks 闲鱼助手"}),e.jsx("div",{className:"mt-1 text-[10px] font-extrabold uppercase tracking-[0.22em] text-sky-600",children:"Operations"})]})]}),e.jsx("nav",{className:`flex-1 space-y-1.5 overflow-y-auto pt-5 ${n?"px-2":"px-3"}`,"aria-label":"主导航",children:d.map(h=>{const g=h.icon,f=t===h.id;return e.jsx(P.Fragment,{children:e.jsxs("button",{type:"button",title:n?h.label:void 0,"aria-label":h.label,"aria-current":f?"page":void 0,onClick:(()=>r(h.id)),className:`group relative flex h-11 w-full items-center rounded-xl transition-colors ${n?"justify-center":"gap-3 px-3.5"} ${f?"bg-brand text-white shadow-brand-active":"text-slate-500 hover:bg-slate-100 hover:text-slate-900"}`,children:[e.jsxs("span",{className:"relative flex h-[19px] w-[19px] shrink-0",children:[e.jsx(g,{className:`h-[19px] w-[19px] ${f?"text-white":"text-slate-400 group-hover:text-slate-700"}`}),h.id==="chat"&&a&&e.jsx("span",{className:"absolute -right-1 -top-1 h-3 w-3 rounded-full border-2 border-white bg-red-500",role:"status","aria-label":"在线聊天有未读消息"})]}),!n&&e.jsx("span",{className:"truncate text-sm font-bold",children:h.label}),f&&!n&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-white/90"})]})},h.id)})}),e.jsxs("div",{children:[e.jsx("div",{title:n?`版本 ${o.version} · ${o.commit}`:void 0,className:`border-y border-slate-100 bg-slate-50/70 py-2.5 ${n?"flex justify-center px-1":"px-6"}`,children:n?e.jsx(I,{className:"h-[18px] w-[18px] text-slate-400","aria-label":`版本 ${o.version}`}):e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-extrabold uppercase tracking-[0.18em] text-slate-400",children:[e.jsx(I,{className:"h-3.5 w-3.5"}),"运行版本"]}),e.jsxs("div",{className:"mt-1 flex items-baseline gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs font-bold text-slate-700",children:c}),e.jsx("span",{className:"truncate font-mono text-[10px] text-slate-400",children:o.commit})]})]})}),e.jsxs("div",{className:`space-y-2 p-2 ${n?"":"p-3"}`,children:[e.jsxs("button",{type:"button",onClick:m,title:n?"展开侧边栏":"收起侧边栏","aria-label":n?"展开侧边栏":"收起侧边栏",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900 ${n?"justify-center":"gap-3 px-3"}`,children:[n?e.jsx(ie,{className:"h-5 w-5"}):e.jsx(le,{className:"h-5 w-5"}),!n&&e.jsx("span",{className:"text-sm font-bold",children:"收起侧边栏"})]}),e.jsxs("button",{type:"button",onClick:l,title:n?"退出登录":void 0,"aria-label":"退出登录",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-red-50 hover:text-red-600 ${n?"justify-center":"gap-3 px-3"}`,children:[e.jsx(ce,{className:"h-5 w-5"}),!n&&e.jsx("span",{className:"text-sm font-bold",children:"退出登录"})]})]})]})]})},S=new Set;let B="connecting";const k=new Set,Ye=t=>(t({type:"connection",state:B}),S.add(t),(()=>S.delete(t))),N=t=>{B=t;for(const s of S)s({type:"connection",state:t})},Le=t=>{for(const s of S)s({type:"message",message:t})},Ce=t=>(k.add(t),(()=>k.delete(t))),Ke=t=>{for(const s of k)s(t)},Ne=1e3,Se=t=>`【新消息】${t}`,Ee=()=>{const[t,s]=i.useState(0),[n,m]=i.useState(!1),r=i.useRef(document.title),l=i.useRef(0);return i.useEffect(()=>{const a=()=>s(0),d=()=>{document.visibilityState==="visible"&&a()};return window.addEventListener("focus",a),document.addEventListener("visibilitychange",d),(()=>{window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",d)})},[]),i.useEffect(()=>{if(t<=0){document.title=r.current;return}let a=!0;const d=()=>{document.title=a?Se(r.current):r.current};d();const c=window.setInterval(()=>{a=!a,d()},Ne);return(()=>{window.clearInterval(c),document.title=r.current})},[t]),i.useEffect(()=>{const a=new AbortController,d=l.current;return(async()=>{try{const g=(await Z({signal:a.signal})).filter(x=>x.enabled),f=await Promise.all(g.map(x=>Y(x.id,void 0,{signal:a.signal})));if(a.signal.aborted||l.current!==d)return;const p=f.some(x=>x.sessions.some(u=>u.unread_count>0));m(p)}catch{}})(),(()=>a.abort())},[]),i.useEffect(()=>Ce(m),[]),{notifyIncomingMessage:i.useCallback(a=>{a.direction!=="incoming"||a.message_type==="system"||(l.current+=1,s(d=>d+1),m(!0))},[]),hasUnreadChatMessage:n}},_e=()=>{const t=Ee(),{notifyIncomingMessage:s,hasUnreadChatMessage:n}=t;return i.useEffect(()=>{let m=!1,r=0,l=0,o=null;const a=()=>{if(m)return;N("connecting");const d=window.location.protocol==="https:"?"wss:":"ws:";o=new WebSocket(`${d}//${window.location.host}/api/v1/chat/ws`),o.onopen=()=>{l=0,N("online")},o.onmessage=c=>{try{const g=JSON.parse(c.data).message;g&&(s(g),Le(g))}catch{}},o.onclose=()=>{if(m)return;N("offline");const c=Math.min(15e3,1e3*2**Math.min(l++,4));r=window.setTimeout(a,c)},o.onerror=()=>o==null?void 0:o.close()};return a(),(()=>{m=!0,window.clearTimeout(r),o==null||o.close(),N("offline")})},[s]),{hasUnreadChatMessage:n}},ke=async t=>j(s=>L.GET("/health",{signal:s}),t),E=i.lazy(()=>y(()=>import("./Dashboard-DBUkwLYQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Pe=i.lazy(()=>y(()=>import("./AccountList-D1PDvKjr.js"),__vite__mapDeps([9,1,7,5,6,3,8]))),Ae=i.lazy(()=>y(()=>import("./OrderList-CKY0um79.js"),__vite__mapDeps([10,1,2,3,7,5,6,8]))),Ie=i.lazy(()=>y(()=>import("./CardList-BG11KU7H.js"),__vite__mapDeps([11,1,7,5,6,3,8]))),Re=i.lazy(()=>y(()=>import("./ItemList-D-9IbEjX.js"),__vite__mapDeps([12,1,7,5,6,3,8]))),Te=i.lazy(()=>y(()=>import("./Settings-BMAitcQx.js"),__vite__mapDeps([13,1,7,5,6,3]))),Oe=i.lazy(()=>y(()=>import("./Rules-DCuiI2LD.js"),__vite__mapDeps([14,1,3,7,5,6,8]))),De=i.lazy(()=>y(()=>import("./Notifications-BepLRaYn.js"),__vite__mapDeps([15,1,3,7,5,6]))),$e=i.lazy(()=>y(()=>import("./Chat-8cCRP4iO.js"),__vite__mapDeps([16,1,5,6,17,3,7]))),Me=()=>e.jsx("div",{className:"flex min-h-[24rem] items-center justify-center",role:"status","aria-label":"正在加载页面",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand/20 border-t-brand"})}),ze=({activeTab:t,isAdmin:s,deliveryRuleTarget:n,onConfigureDelivery:m,onDeliveryTargetHandled:r})=>{const l=a=>{m({cookieId:a.cookie_id,itemId:a.item_id,requestId:Date.now()})},o=()=>{switch(t){case"dashboard":return e.jsx(E,{});case"accounts":return e.jsx(Pe,{});case"chat":return e.jsx($e,{});case"orders":return e.jsx(Ae,{});case"cards":return e.jsx(Ie,{});case"items":return e.jsx(Re,{onConfigureDelivery:l});case"rules":return e.jsx(Oe,{initialDeliveryTarget:n,onDeliveryTargetHandled:r});case"notifications":return e.jsx(De,{isAdmin:s});case"settings":return s?e.jsx(Te,{}):e.jsx(E,{});default:return e.jsx(E,{})}};return e.jsx(i.Suspense,{fallback:e.jsx(Me,{}),children:o()})},Ue=({activeTab:t,isAdmin:s,collapsed:n,deliveryRuleTarget:m,onToggleCollapsed:r,onNavigate:l,onLogout:o,onConfigureDelivery:a,onDeliveryTargetHandled:d})=>{const[c,h]=i.useState({version:"dev",commit:"unknown"}),{hasUnreadChatMessage:g}=_e();return i.useEffect(()=>{const f=new AbortController;return ke({signal:f.signal}).then(p=>h({version:String(p.version||"dev"),commit:String(p.commit||"unknown")})).catch(p=>{p instanceof DOMException&&p.name}),(()=>f.abort())},[]),e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(je,{activeTab:t,isAdmin:s,collapsed:n,onToggleCollapsed:r,onNavigate:l,onLogout:o,buildInfo:c,hasUnreadChatMessage:g}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${n?"ml-16":"ml-64"} ${t==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 -z-10 h-[800px] w-[800px] pointer-events-none rounded-full bg-gradient-to-bl from-blue-50 to-transparent opacity-60 blur-[120px]"}),e.jsx("div",{className:`${t==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:e.jsx(ze,{activeTab:t,isAdmin:s,deliveryRuleTarget:m,onConfigureDelivery:a,onDeliveryTargetHandled:d})})]})]})},V={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/chat":"chat","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},_=Object.fromEntries(Object.entries(V).map(([t,s])=>[s,t])),O=()=>V[window.location.pathname]??"dashboard",Be=()=>{const{isLoggedIn:t,isAdmin:s,signOut:n}=M(),[m,r]=i.useState(O),[l,o]=i.useState(),[a,d]=i.useState(pe);i.useEffect(()=>{const u=()=>r(O());return window.addEventListener("popstate",u),(()=>window.removeEventListener("popstate",u))},[]),i.useEffect(()=>{t&&!s&&m==="settings"&&(window.history.replaceState({},"",_.dashboard),r("dashboard"))},[m,s,t]);const c=u=>{const b=u==="settings"&&!s?"dashboard":u,C=_[b];C!==window.location.pathname&&window.history.pushState({},"",C),r(b)},h=u=>{const b=Object.prototype.hasOwnProperty.call(_,u)?u:"dashboard";c(b)},g=async()=>{try{await n()}catch(u){console.error("退出登录失败",u)}},f=()=>{d(u=>{const b=!u;return ge(b),b})},p=u=>{o(u),c("rules")},x=()=>o(void 0);return t?e.jsx(Ue,{activeTab:m,isAdmin:s,collapsed:a,deliveryRuleTarget:l,onToggleCollapsed:f,onNavigate:h,onLogout:g,onConfigureDelivery:p,onDeliveryTargetHandled:x}):e.jsx(ve,{})},Ve=()=>e.jsx(de,{children:e.jsx(xe,{children:e.jsx(Be,{})})}),F=document.getElementById("root");if(!F)throw new Error("Could not find root element to mount to");const Fe=H.createRoot(F);Fe.render(e.jsx(P.StrictMode,{children:e.jsx(Ve,{})}));export{Ke as p,Ye as s}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-DBUkwLYQ.js","assets/react-vendor-Bf9ELcll.js","assets/dateTime-DDi7rqpW.js","assets/icons-vendor-BSp7PTZg.js","assets/charts-vendor-DBu_rVrn.js","assets/vendor-BE-_xUHH.js","assets/vendor-DUblxfbA.css","assets/chat-metadata-74T0w35U.js","assets/contract-COFcZjyb.js","assets/AccountList-D1PDvKjr.js","assets/OrderList-CKY0um79.js","assets/CardList-BG11KU7H.js","assets/ItemList-D-9IbEjX.js","assets/Settings-CbgtqNcx.js","assets/settings-D-mx9vFJ.js","assets/Rules-DCuiI2LD.js","assets/Notifications-xaqRCmgU.js","assets/Chat-Di7cjGAh.js","assets/audio-codec-mjVr_wwJ.js"])))=>i.map(i=>d[i]); +import{d as P,j as e,a as i,e as H}from"./react-vendor-Bf9ELcll.js";import{r as j,c as L,g as Z,a as Y}from"./chat-metadata-74T0w35U.js";import{L as D,a as A,b as K,U as W,A as J,c as Q,d as X,M as ee,e as te,B as se,f as ne,Z as ae,g as re,h as oe,G as I,i as ie,j as le,k as ce}from"./icons-vendor-BSp7PTZg.js";import"./vendor-BE-_xUHH.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))m(r);new MutationObserver(r=>{for(const l of r)if(l.type==="childList")for(const o of l.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&m(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const l={};return r.integrity&&(l.integrity=r.integrity),r.referrerPolicy&&(l.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?l.credentials="include":r.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function m(r){if(r.ep)return;r.ep=!0;const l=n(r);fetch(r.href,l)}})();class de extends P.Component{constructor(){super(...arguments),this.state={hasError:!1},this.handleReload=()=>{window.location.reload()}}static getDerivedStateFromError(){return{hasError:!0}}render(){const{hasError:s}=this.state,{children:n}=this.props;return s?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-6 text-ink",children:e.jsxs("section",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"页面暂时无法显示"}),e.jsx("button",{className:"ios-btn-primary mt-6 px-4 py-2",type:"button",onClick:this.handleReload,children:"重新加载"})]})}):n}}const ue=async t=>{const s=await j(n=>L.POST("/api/v1/session/login",{body:t,signal:n}),{skipAuthLogout:!0});return{...s,token:s.token??void 0}},he=async t=>{const s=await j(n=>L.POST("/api/v1/session/initialize",{body:{password:t},signal:n}),{skipAuthLogout:!0});return{...s,token:s.token??void 0}},me=async t=>j(s=>L.GET("/api/v1/session",{signal:s}),t),fe=async()=>({success:!0,message:(await j(s=>L.POST("/api/v1/session/logout",{body:{},signal:s}))).message}),$=i.createContext(void 0),xe=({children:t})=>{const[s,n]=i.useState(!1),[m,r]=i.useState(!1),[l,o]=i.useState(!0),[a,d]=i.useState(!1),c=()=>{n(!1),r(!1)};i.useEffect(()=>{const p=new AbortController;let x=!0;me({signal:p.signal}).then(b=>{if(x){if((b==null?void 0:b.initialized)===!1){d(!0),c();return}d(!1),b!=null&&b.authenticated?(n(!0),r(b.is_admin===!0)):c()}}).catch(b=>{!x||b instanceof DOMException&&b.name==="AbortError"||(d(!1),c())}).finally(()=>{x&&o(!1)});const u=()=>c();return window.addEventListener("auth:logout",u),(()=>{x=!1,p.abort(),window.removeEventListener("auth:logout",u)})},[]);const h=async p=>{const x=await ue(p);return x.success&&(d(!1),n(!0),r(x.is_admin===!0)),x},g=async p=>{const x=await he(p);return x.success&&(d(!1),n(!0),r(x.is_admin===!0)),x},f=async()=>{try{await fe()}finally{c()}};return e.jsx($.Provider,{value:{checkingAuth:l,isLoggedIn:s,isAdmin:m,needsInit:a,signIn:h,initialize:g,signOut:f},children:t})},M=()=>{const t=i.useContext($);if(!t)throw new Error("useSession 必须在 SessionProvider 内使用");return t},z="ydisks.sidebar.v1",pe=()=>{try{return window.localStorage.getItem(z)==="collapsed"}catch{return!1}},ge=t=>{try{window.localStorage.setItem(z,t?"collapsed":"expanded")}catch{}},be=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),U=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88.46 8.78 L 92.71 10.34 L 96.49 12.25 L 99.87 14.52 L 102.86 17.14 L 105.48 20.13 L 107.75 23.51 L 109.66 27.29 L 111.22 31.54 L 112.44 36.33 L 113.31 41.84 L 113.83 48.52 Z",fill:"url(#login-squircle-gradient)"})]}),e.jsx("div",{className:"relative z-10 flex items-center justify-center w-full h-full",children:e.jsx(be,{className:s})})]})]}),ve=()=>{const{checkingAuth:t,needsInit:s,signIn:n,initialize:m}=M(),[r,l]=i.useState(""),[o,a]=i.useState(""),[d,c]=i.useState(""),[h,g]=i.useState(""),[f,p]=i.useState(!1),[x,u]=i.useState(""),b=async v=>{v.preventDefault(),p(!0),u("");try{const w=await n({username:r,password:o});w.success||u(w.message||"登录失败")}catch(w){u(w instanceof Error&&w.message||"登录失败")}finally{p(!1)}},C=async v=>{if(v.preventDefault(),u(""),d.length<8){u("密码至少需要 8 个字符");return}if(d!==h){u("两次输入的密码不一致");return}p(!0);try{const w=await m(d);if(!w.success){u(w.message||"初始化失败,请重试");return}c(""),g("")}catch(w){u(w instanceof Error&&w.message||"初始化失败,请重试")}finally{p(!1)}};if(t)return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-surface","aria-label":"正在校验会话",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-brand"})});const q=s?"首次设置管理员密码":"欢迎回来",G=s?"设置完成后会自动进入系统,管理员账号为 admin。":"Ydisks闲鱼助手 · 自动发货与管家系统";return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-4 font-sans",children:e.jsxs("section",{className:"w-full max-w-lg rounded-xl border border-white bg-white/80 p-8 shadow-panel backdrop-blur-3xl md:p-12",children:[e.jsxs("header",{className:"mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(U,{sizeClass:"h-24 w-24"})}),e.jsx("h1",{className:"text-3xl font-extrabold text-gray-900",children:q}),e.jsx("p",{className:"mt-2 font-medium text-gray-600",children:G})]}),s?e.jsxs("form",{className:"space-y-5",onSubmit:C,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"设置管理员密码"}),e.jsx(A,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>c(v.target.value)),placeholder:"设置管理员密码(至少 8 个字符)",type:"password",value:d})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"确认管理员密码"}),e.jsx(K,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>g(v.target.value)),placeholder:"再次输入密码",type:"password",value:h})]}),e.jsx(R,{submitting:f,text:"设置密码并进入系统"})]}):e.jsxs("form",{className:"space-y-5",onSubmit:b,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员账号"}),e.jsx(W,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>l(v.target.value)),placeholder:"管理员账号",type:"text",value:r})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员密码"}),e.jsx(A,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(v=>a(v.target.value)),placeholder:"密码",type:"password",value:o})]}),e.jsx(R,{submitting:f,text:"立即登录"})]}),x?e.jsx("p",{className:"mt-5 rounded-xl bg-red-50 p-3 text-center text-sm font-medium text-red-600",children:x}):null]})})},R=({submitting:t,text:s})=>e.jsx("button",{className:"ios-btn-primary flex h-14 w-full items-center justify-center gap-2 rounded-xl text-lg disabled:opacity-70",disabled:t,type:"submit",children:t?e.jsx(D,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:s}),e.jsx(J,{className:"h-5 w-5"})]})}),we="modulepreload",ye=function(t){return"/static/"+t},T={},y=function(s,n,m){let r=Promise.resolve();if(n&&n.length>0){let o=function(c){return Promise.all(c.map(h=>Promise.resolve(h).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),d=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));r=o(n.map(c=>{if(c=ye(c),c in T)return;T[c]=!0;const h=c.endsWith(".css"),g=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${g}`))return;const f=document.createElement("link");if(f.rel=h?"stylesheet":we,h||(f.as="script"),f.crossOrigin="",f.href=c,d&&f.setAttribute("nonce",d),document.head.appendChild(f),h)return new Promise((p,x)=>{f.addEventListener("load",p),f.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${c}`)))})}))}function l(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return r.then(o=>{for(const a of o||[])a.status==="rejected"&&l(a.reason);return s().catch(l)})},je=({activeTab:t,isAdmin:s=!1,collapsed:n,onToggleCollapsed:m,onNavigate:r,onLogout:l,buildInfo:o,hasUnreadChatMessage:a=!1})=>{const d=[{id:"dashboard",icon:Q,label:"仪表盘"},{id:"accounts",icon:X,label:"账号管理"},{id:"chat",icon:ee,label:"在线聊天"},{id:"cards",icon:te,label:"卡密库存"},{id:"items",icon:se,label:"商品列表"},{id:"orders",icon:ne,label:"订单管理"},{id:"rules",icon:ae,label:"自动化规则"},{id:"notifications",icon:re,label:"通知设置"},...s?[{id:"settings",icon:oe,label:"系统与AI"}]:[]],c=/^\d+\.\d+\.\d+$/.test(o.version)?`v${o.version}`:o.version;return e.jsxs("aside",{className:`fixed inset-y-0 left-0 z-20 flex flex-col border-r border-slate-200/80 bg-white/95 shadow-sidebar backdrop-blur-xl transition-[width] duration-300 ${n?"w-16":"w-64"}`,children:[e.jsxs("div",{className:`flex h-20 items-center border-b border-slate-100 ${n?"justify-center px-2":"gap-3 px-5"}`,children:[e.jsx(U,{sizeClass:"h-10 w-10"}),!n&&e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"truncate text-base font-black tracking-tight text-slate-950",children:"Ydisks 闲鱼助手"}),e.jsx("div",{className:"mt-1 text-[10px] font-extrabold uppercase tracking-[0.22em] text-sky-600",children:"Operations"})]})]}),e.jsx("nav",{className:`flex-1 space-y-1.5 overflow-y-auto pt-5 ${n?"px-2":"px-3"}`,"aria-label":"主导航",children:d.map(h=>{const g=h.icon,f=t===h.id;return e.jsx(P.Fragment,{children:e.jsxs("button",{type:"button",title:n?h.label:void 0,"aria-label":h.label,"aria-current":f?"page":void 0,onClick:(()=>r(h.id)),className:`group relative flex h-11 w-full items-center rounded-xl transition-colors ${n?"justify-center":"gap-3 px-3.5"} ${f?"bg-brand text-white shadow-brand-active":"text-slate-500 hover:bg-slate-100 hover:text-slate-900"}`,children:[e.jsxs("span",{className:"relative flex h-[19px] w-[19px] shrink-0",children:[e.jsx(g,{className:`h-[19px] w-[19px] ${f?"text-white":"text-slate-400 group-hover:text-slate-700"}`}),h.id==="chat"&&a&&e.jsx("span",{className:"absolute -right-1 -top-1 h-3 w-3 rounded-full border-2 border-white bg-red-500",role:"status","aria-label":"在线聊天有未读消息"})]}),!n&&e.jsx("span",{className:"truncate text-sm font-bold",children:h.label}),f&&!n&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-white/90"})]})},h.id)})}),e.jsxs("div",{children:[e.jsx("div",{title:n?`版本 ${o.version} · ${o.commit}`:void 0,className:`border-y border-slate-100 bg-slate-50/70 py-2.5 ${n?"flex justify-center px-1":"px-6"}`,children:n?e.jsx(I,{className:"h-[18px] w-[18px] text-slate-400","aria-label":`版本 ${o.version}`}):e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-extrabold uppercase tracking-[0.18em] text-slate-400",children:[e.jsx(I,{className:"h-3.5 w-3.5"}),"运行版本"]}),e.jsxs("div",{className:"mt-1 flex items-baseline gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs font-bold text-slate-700",children:c}),e.jsx("span",{className:"truncate font-mono text-[10px] text-slate-400",children:o.commit})]})]})}),e.jsxs("div",{className:`space-y-2 p-2 ${n?"":"p-3"}`,children:[e.jsxs("button",{type:"button",onClick:m,title:n?"展开侧边栏":"收起侧边栏","aria-label":n?"展开侧边栏":"收起侧边栏",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900 ${n?"justify-center":"gap-3 px-3"}`,children:[n?e.jsx(ie,{className:"h-5 w-5"}):e.jsx(le,{className:"h-5 w-5"}),!n&&e.jsx("span",{className:"text-sm font-bold",children:"收起侧边栏"})]}),e.jsxs("button",{type:"button",onClick:l,title:n?"退出登录":void 0,"aria-label":"退出登录",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-red-50 hover:text-red-600 ${n?"justify-center":"gap-3 px-3"}`,children:[e.jsx(ce,{className:"h-5 w-5"}),!n&&e.jsx("span",{className:"text-sm font-bold",children:"退出登录"})]})]})]})]})},S=new Set;let B="connecting";const k=new Set,Ye=t=>(t({type:"connection",state:B}),S.add(t),(()=>S.delete(t))),N=t=>{B=t;for(const s of S)s({type:"connection",state:t})},Le=t=>{for(const s of S)s({type:"message",message:t})},Ce=t=>(k.add(t),(()=>k.delete(t))),Ke=t=>{for(const s of k)s(t)},Ne=1e3,Se=t=>`【新消息】${t}`,Ee=()=>{const[t,s]=i.useState(0),[n,m]=i.useState(!1),r=i.useRef(document.title),l=i.useRef(0);return i.useEffect(()=>{const a=()=>s(0),d=()=>{document.visibilityState==="visible"&&a()};return window.addEventListener("focus",a),document.addEventListener("visibilitychange",d),(()=>{window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",d)})},[]),i.useEffect(()=>{if(t<=0){document.title=r.current;return}let a=!0;const d=()=>{document.title=a?Se(r.current):r.current};d();const c=window.setInterval(()=>{a=!a,d()},Ne);return(()=>{window.clearInterval(c),document.title=r.current})},[t]),i.useEffect(()=>{const a=new AbortController,d=l.current;return(async()=>{try{const g=(await Z({signal:a.signal})).filter(x=>x.enabled),f=await Promise.all(g.map(x=>Y(x.id,void 0,{signal:a.signal})));if(a.signal.aborted||l.current!==d)return;const p=f.some(x=>x.sessions.some(u=>u.unread_count>0));m(p)}catch{}})(),(()=>a.abort())},[]),i.useEffect(()=>Ce(m),[]),{notifyIncomingMessage:i.useCallback(a=>{a.direction!=="incoming"||a.message_type==="system"||(l.current+=1,s(d=>d+1),m(!0))},[]),hasUnreadChatMessage:n}},_e=()=>{const t=Ee(),{notifyIncomingMessage:s,hasUnreadChatMessage:n}=t;return i.useEffect(()=>{let m=!1,r=0,l=0,o=null;const a=()=>{if(m)return;N("connecting");const d=window.location.protocol==="https:"?"wss:":"ws:";o=new WebSocket(`${d}//${window.location.host}/api/v1/chat/ws`),o.onopen=()=>{l=0,N("online")},o.onmessage=c=>{try{const g=JSON.parse(c.data).message;g&&(s(g),Le(g))}catch{}},o.onclose=()=>{if(m)return;N("offline");const c=Math.min(15e3,1e3*2**Math.min(l++,4));r=window.setTimeout(a,c)},o.onerror=()=>o==null?void 0:o.close()};return a(),(()=>{m=!0,window.clearTimeout(r),o==null||o.close(),N("offline")})},[s]),{hasUnreadChatMessage:n}},ke=async t=>j(s=>L.GET("/health",{signal:s}),t),E=i.lazy(()=>y(()=>import("./Dashboard-DBUkwLYQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Pe=i.lazy(()=>y(()=>import("./AccountList-D1PDvKjr.js"),__vite__mapDeps([9,1,7,5,6,3,8]))),Ae=i.lazy(()=>y(()=>import("./OrderList-CKY0um79.js"),__vite__mapDeps([10,1,2,3,7,5,6,8]))),Ie=i.lazy(()=>y(()=>import("./CardList-BG11KU7H.js"),__vite__mapDeps([11,1,7,5,6,3,8]))),Re=i.lazy(()=>y(()=>import("./ItemList-D-9IbEjX.js"),__vite__mapDeps([12,1,7,5,6,3,8]))),Te=i.lazy(()=>y(()=>import("./Settings-CbgtqNcx.js"),__vite__mapDeps([13,1,7,5,6,3,14]))),Oe=i.lazy(()=>y(()=>import("./Rules-DCuiI2LD.js"),__vite__mapDeps([15,1,3,7,5,6,8]))),De=i.lazy(()=>y(()=>import("./Notifications-xaqRCmgU.js"),__vite__mapDeps([16,1,3,14,7,5,6]))),$e=i.lazy(()=>y(()=>import("./Chat-Di7cjGAh.js"),__vite__mapDeps([17,1,5,6,18,3,7]))),Me=()=>e.jsx("div",{className:"flex min-h-[24rem] items-center justify-center",role:"status","aria-label":"正在加载页面",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand/20 border-t-brand"})}),ze=({activeTab:t,isAdmin:s,deliveryRuleTarget:n,onConfigureDelivery:m,onDeliveryTargetHandled:r})=>{const l=a=>{m({cookieId:a.cookie_id,itemId:a.item_id,requestId:Date.now()})},o=()=>{switch(t){case"dashboard":return e.jsx(E,{});case"accounts":return e.jsx(Pe,{});case"chat":return e.jsx($e,{});case"orders":return e.jsx(Ae,{});case"cards":return e.jsx(Ie,{});case"items":return e.jsx(Re,{onConfigureDelivery:l});case"rules":return e.jsx(Oe,{initialDeliveryTarget:n,onDeliveryTargetHandled:r});case"notifications":return e.jsx(De,{isAdmin:s});case"settings":return s?e.jsx(Te,{}):e.jsx(E,{});default:return e.jsx(E,{})}};return e.jsx(i.Suspense,{fallback:e.jsx(Me,{}),children:o()})},Ue=({activeTab:t,isAdmin:s,collapsed:n,deliveryRuleTarget:m,onToggleCollapsed:r,onNavigate:l,onLogout:o,onConfigureDelivery:a,onDeliveryTargetHandled:d})=>{const[c,h]=i.useState({version:"dev",commit:"unknown"}),{hasUnreadChatMessage:g}=_e();return i.useEffect(()=>{const f=new AbortController;return ke({signal:f.signal}).then(p=>h({version:String(p.version||"dev"),commit:String(p.commit||"unknown")})).catch(p=>{p instanceof DOMException&&p.name}),(()=>f.abort())},[]),e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(je,{activeTab:t,isAdmin:s,collapsed:n,onToggleCollapsed:r,onNavigate:l,onLogout:o,buildInfo:c,hasUnreadChatMessage:g}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${n?"ml-16":"ml-64"} ${t==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 -z-10 h-[800px] w-[800px] pointer-events-none rounded-full bg-gradient-to-bl from-blue-50 to-transparent opacity-60 blur-[120px]"}),e.jsx("div",{className:`${t==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:e.jsx(ze,{activeTab:t,isAdmin:s,deliveryRuleTarget:m,onConfigureDelivery:a,onDeliveryTargetHandled:d})})]})]})},V={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/chat":"chat","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},_=Object.fromEntries(Object.entries(V).map(([t,s])=>[s,t])),O=()=>V[window.location.pathname]??"dashboard",Be=()=>{const{isLoggedIn:t,isAdmin:s,signOut:n}=M(),[m,r]=i.useState(O),[l,o]=i.useState(),[a,d]=i.useState(pe);i.useEffect(()=>{const u=()=>r(O());return window.addEventListener("popstate",u),(()=>window.removeEventListener("popstate",u))},[]),i.useEffect(()=>{t&&!s&&m==="settings"&&(window.history.replaceState({},"",_.dashboard),r("dashboard"))},[m,s,t]);const c=u=>{const b=u==="settings"&&!s?"dashboard":u,C=_[b];C!==window.location.pathname&&window.history.pushState({},"",C),r(b)},h=u=>{const b=Object.prototype.hasOwnProperty.call(_,u)?u:"dashboard";c(b)},g=async()=>{try{await n()}catch(u){console.error("退出登录失败",u)}},f=()=>{d(u=>{const b=!u;return ge(b),b})},p=u=>{o(u),c("rules")},x=()=>o(void 0);return t?e.jsx(Ue,{activeTab:m,isAdmin:s,collapsed:a,deliveryRuleTarget:l,onToggleCollapsed:f,onNavigate:h,onLogout:g,onConfigureDelivery:p,onDeliveryTargetHandled:x}):e.jsx(ve,{})},Ve=()=>e.jsx(de,{children:e.jsx(xe,{children:e.jsx(Be,{})})}),F=document.getElementById("root");if(!F)throw new Error("Could not find root element to mount to");const Fe=H.createRoot(F);Fe.render(e.jsx(P.StrictMode,{children:e.jsx(Ve,{})}));export{Ke as p,Ye as s}; diff --git a/internal/webui/static/assets/settings-D-mx9vFJ.js b/internal/webui/static/assets/settings-D-mx9vFJ.js new file mode 100644 index 0000000..731632f --- /dev/null +++ b/internal/webui/static/assets/settings-D-mx9vFJ.js @@ -0,0 +1 @@ +const a=new Set(["ai_api_key","smtp_password","qq_reply_secret_key","captcha.remote_secret_key"]),c=t=>{if("values"in t||"secrets"in t)return t;const n={},o={};for(const[r,e]of Object.entries(t))if(e!=null){if(a.has(r)){o[r]=e===""?{action:"clear"}:{action:"replace",value:String(e)};continue}(typeof e=="string"||typeof e=="number"||typeof e=="boolean")&&(n[r]=e)}return Object.keys(o).length>0?{values:n,secrets:o}:n};export{a as S,c as n}; diff --git a/internal/webui/static/index.html b/internal/webui/static/index.html index d17425e..2cd4044 100644 --- a/internal/webui/static/index.html +++ b/internal/webui/static/index.html @@ -6,7 +6,7 @@ Ydisks闲鱼助手 - 自动发货与管家系统 - +