From 24eceef6cba9d8934559ea80cf423f149e6ccb2f Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 12 Apr 2026 23:36:20 +0800 Subject: [PATCH] fix: stabilize weibo insight ui and cookie flow --- electron/services/social/weiboService.ts | 4 +- src/pages/SettingsPage.scss | 116 +++++++++++++++++++++++ src/pages/SettingsPage.tsx | 34 +++++-- 3 files changed, 146 insertions(+), 8 deletions(-) diff --git a/electron/services/social/weiboService.ts b/electron/services/social/weiboService.ts index 4b04d70..0d9faf2 100644 --- a/electron/services/social/weiboService.ts +++ b/electron/services/social/weiboService.ts @@ -184,7 +184,9 @@ class WeiboService { try { const uid = normalizeWeiboUid(uidInput) const cookie = normalizeWeiboCookieInput(cookieInput) - if (!cookie) return { success: false, error: '请先填写有效的微博 Cookie' } + if (!cookie) { + return { success: true, uid } + } const timeline = await this.fetchTimeline(uid, cookie) const firstItem = timeline.data?.list?.[0] diff --git a/src/pages/SettingsPage.scss b/src/pages/SettingsPage.scss index fe20d9f..a94c532 100644 --- a/src/pages/SettingsPage.scss +++ b/src/pages/SettingsPage.scss @@ -1849,6 +1849,20 @@ animation: fadeIn 0.2s ease; } +.social-cookie-modal-overlay { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.52); + display: flex; + align-items: center; + justify-content: center; + z-index: 2300; + animation: fadeIn 0.2s ease; +} + // API 警告弹窗 .api-warning-modal { width: 420px; @@ -1920,6 +1934,9 @@ .settings-inline-modal { width: min(560px, calc(100vw - 40px)); + max-height: min(720px, calc(100vh - 40px)); + display: flex; + flex-direction: column; background: var(--bg-primary); border-radius: 16px; overflow: hidden; @@ -1946,7 +1963,9 @@ } .modal-body { + flex: 1; padding: 20px 24px; + overflow-y: auto; .warning-text { margin: 0 0 16px; @@ -3580,6 +3599,103 @@ overflow: hidden; } + &.insight-social-tab { + .anti-revoke-list-header { + grid-template-columns: minmax(0, 1fr) minmax(300px, 420px) auto; + + .insight-social-column-title { + color: var(--text-tertiary); + } + } + + .anti-revoke-row { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(300px, 420px) auto; + align-items: center; + gap: 14px; + } + + .anti-revoke-row-main { + min-width: 0; + } + + .insight-social-binding-cell { + min-width: 0; + display: grid; + grid-template-columns: minmax(0, 1fr) auto; + gap: 8px 10px; + align-items: center; + } + + .insight-social-binding-input-wrap { + min-width: 0; + display: flex; + align-items: center; + gap: 8px; + } + + .binding-platform-chip { + flex-shrink: 0; + border-radius: 999px; + padding: 2px 8px; + font-size: 11px; + color: var(--text-secondary); + border: 1px solid color-mix(in srgb, var(--border-color) 84%, transparent); + background: color-mix(in srgb, var(--bg-secondary) 88%, var(--bg-primary) 12%); + } + + .insight-social-binding-input { + width: 100%; + min-width: 0; + height: 30px; + border-radius: 8px; + border: 1px solid var(--border-color); + background: color-mix(in srgb, var(--bg-primary) 92%, var(--bg-secondary) 8%); + color: var(--text-primary); + font-size: 12px; + padding: 0 10px; + outline: none; + transition: border-color 0.18s ease, box-shadow 0.18s ease; + + &:focus { + border-color: color-mix(in srgb, var(--primary) 55%, var(--border-color)); + box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 16%, transparent); + } + } + + .insight-social-binding-actions { + display: inline-flex; + align-items: center; + justify-self: flex-end; + gap: 8px; + } + + .insight-social-binding-feedback { + grid-column: 1 / span 2; + min-height: 18px; + } + + .binding-feedback { + font-size: 12px; + line-height: 1.4; + color: var(--text-secondary); + + &.error { + color: color-mix(in srgb, var(--danger) 72%, var(--text-primary) 28%); + } + + &.muted { + color: var(--text-tertiary); + } + } + + .anti-revoke-row-status { + justify-self: flex-end; + align-items: flex-end; + max-width: none; + } + } + @media (max-width: 980px) { .anti-revoke-hero { flex-direction: column; diff --git a/src/pages/SettingsPage.tsx b/src/pages/SettingsPage.tsx index b6687b2..354914b 100644 --- a/src/pages/SettingsPage.tsx +++ b/src/pages/SettingsPage.tsx @@ -2870,6 +2870,20 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { ) + const withAsyncTimeout = async (task: Promise, timeoutMs: number, timeoutMessage: string): Promise => { + let timeoutHandle: ReturnType | null = null + try { + return await Promise.race([ + task, + new Promise((_, reject) => { + timeoutHandle = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs) + }) + ]) + } finally { + if (timeoutHandle) clearTimeout(timeoutHandle) + } + } + const hasWeiboCookieConfigured = aiInsightWeiboCookie.trim().length > 0 const openWeiboCookieModal = () => { @@ -2884,7 +2898,11 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { setIsSavingWeiboCookie(true) setWeiboCookieError('') try { - const result = await window.electronAPI.social.saveWeiboCookie(draftToSave) + const result = await withAsyncTimeout( + window.electronAPI.social.saveWeiboCookie(draftToSave), + 10000, + '保存微博 Cookie 超时,请稍后重试' + ) if (!result.success) { setWeiboCookieError(result.error || '微博 Cookie 保存失败') return false @@ -2935,10 +2953,6 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { } const handleSaveWeiboBinding = async (sessionId: string, displayName: string) => { - if (!hasWeiboCookieConfigured) { - setWeiboBindingErrors((prev) => ({ ...prev, [sessionId]: '请先填写微博 Cookie,再进行 UID 绑定' })) - return - } const draftUid = getWeiboBindingDraftValue(sessionId) setWeiboBindingLoadingSessionId(sessionId) setWeiboBindingErrors((prev) => { @@ -2948,7 +2962,11 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { return next }) try { - const result = await window.electronAPI.social.validateWeiboUid(draftUid) + const result = await withAsyncTimeout( + window.electronAPI.social.validateWeiboUid(draftUid), + 12000, + '微博 UID 校验超时,请稍后重试' + ) if (!result.success || !result.uid) { setWeiboBindingErrors((prev) => ({ ...prev, [sessionId]: result.error || '微博 UID 校验失败' })) return @@ -3552,6 +3570,8 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { {weiboBindingError} ) : weiboBinding?.screenName ? ( @{weiboBinding.screenName} + ) : weiboBinding?.uid ? ( + 已绑定 UID:{weiboBinding.uid} ) : ( 仅支持手动填写数字 UID )} @@ -4563,7 +4583,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) { {showWeiboCookieModal && (
{ e.stopPropagation() void handleCloseWeiboCookieModal()