From 50ce131d6025045e046a52a185d04eeccc4c9496 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Sun, 16 Aug 2026 23:03:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E6=89=A9=E5=B1=95popup=E7=95=8C=E9=9D=A2=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser-extension/src/popup/App.vue | 203 ++++++++++---------- browser-extension/src/popup/styles.css | 250 ++++++++++++++++++++++++- 2 files changed, 341 insertions(+), 112 deletions(-) diff --git a/browser-extension/src/popup/App.vue b/browser-extension/src/popup/App.vue index 597194ec..17f40b1f 100644 --- a/browser-extension/src/popup/App.vue +++ b/browser-extension/src/popup/App.vue @@ -7,7 +7,7 @@ import { } from '@/api/open/extensionFeatures'; import type { ExtensionFeatureItem } from '@/features/runtime/types'; import { urlMatchesPatterns } from '@/features/runtime/types'; -import { EXTENSION_NAME, OPEN_SCOPES } from '@/shared/constants'; +import { EXTENSION_NAME } from '@/shared/constants'; import { toUserMessage } from '@/shared/errors'; import { getSettings, saveSettings } from '@/storage/settings'; @@ -28,6 +28,9 @@ const statusText = ref(''); const errorText = ref(''); const busy = ref(false); const checking = ref(false); +const configOpen = ref(false); + +const hasConfig = computed(() => Boolean(apiBaseUrl.value.trim() && apiKey.value.trim())); const matchedFeatures = computed(() => { const list = Array.isArray(features.value) ? features.value : []; @@ -35,40 +38,46 @@ const matchedFeatures = computed(() => { return list.filter((f) => urlMatchesPatterns(currentTabUrl.value, f?.matchUrlPatterns ?? [])); }); +const configSummary = computed(() => { + if (!hasConfig.value) return '未配置'; + try { + const host = new URL(apiBaseUrl.value.trim()).host; + return host || '已配置'; + } catch { + return '已配置'; + } +}); + async function loadLocalSettings() { const settings = await getSettings(); apiBaseUrl.value = settings.apiBaseUrl; apiKey.value = settings.apiKey; + // 未配置时默认展开 + configOpen.value = !(settings.apiBaseUrl && settings.apiKey); } -/** 只保存 URL / Key,不改动悬浮层里的店铺配置 */ -async function persistSettings() { - errorText.value = ''; - try { - await saveSettings({ - apiBaseUrl: apiBaseUrl.value.trim(), - apiKey: apiKey.value.trim(), - }); - statusText.value = '配置已保存'; - } catch (error) { - errorText.value = toUserMessage(error); - } +async function saveConfig() { + await saveSettings({ + apiBaseUrl: apiBaseUrl.value.trim(), + apiKey: apiKey.value.trim(), + }); } -async function checkConnectivity() { +async function persistAndCheck() { checking.value = true; errorText.value = ''; statusText.value = ''; try { - await saveSettings({ - apiBaseUrl: apiBaseUrl.value.trim(), - apiKey: apiKey.value.trim(), - }); + await saveConfig(); const manifest = await fetchFeatureManifest(); - const count = manifest.features?.length ?? 0; - statusText.value = `连通正常(清单 ${count} 项${manifest.updatedAt ? `,更新于 ${manifest.updatedAt}` : ''})`; + features.value = manifest.features ?? []; + featuresUpdatedAt.value = manifest.updatedAt ?? ''; + const count = features.value.length; + statusText.value = `已连接 · 清单 ${count} 项`; + configOpen.value = false; } catch (error) { errorText.value = toUserMessage(error); + configOpen.value = true; } finally { checking.value = false; } @@ -87,16 +96,14 @@ async function loadFeatures() { featuresLoading.value = true; errorText.value = ''; try { - await saveSettings({ - apiBaseUrl: apiBaseUrl.value.trim(), - apiKey: apiKey.value.trim(), - }); + await saveConfig(); const manifest = await fetchFeatureManifest(); features.value = manifest.features ?? []; featuresUpdatedAt.value = manifest.updatedAt ?? ''; - statusText.value = `已加载功能清单(${features.value.length})`; + statusText.value = `清单已刷新(${features.value.length})`; } catch (error) { errorText.value = toUserMessage(error); + configOpen.value = true; } finally { featuresLoading.value = false; } @@ -116,18 +123,11 @@ async function handleOpenFeature(item: ExtensionFeatureItem) { errorText.value = ''; statusText.value = ''; try { - await saveSettings({ - apiBaseUrl: apiBaseUrl.value.trim(), - apiKey: apiKey.value.trim(), - }); + await saveConfig(); const remote = await downloadAndVerifyFeature(item); - statusText.value = remote.verified - ? `远程脚本已校验(${item.version})` - : `已下载远程脚本(未配置 sha256)`; - await mountFeatureOnPage(item.id, remote.code); activeFeatureId.value = item.id; - statusText.value = `已打开:${item.name}(远程脚本)`; + statusText.value = `已打开 ${item.name}`; } catch (error) { errorText.value = toUserMessage(error); } finally { @@ -141,7 +141,7 @@ async function handleCloseFeature() { try { await unmountFeatureOnPage(); activeFeatureId.value = null; - statusText.value = '已关闭当前功能'; + statusText.value = '已关闭'; } catch (error) { errorText.value = toUserMessage(error); } finally { @@ -153,100 +153,95 @@ onMounted(async () => { await loadLocalSettings(); await refreshTabUrl(); await refreshPanelState(); - if (apiBaseUrl.value && apiKey.value) { + if (hasConfig.value) { await loadFeatures(); } }); diff --git a/browser-extension/src/popup/styles.css b/browser-extension/src/popup/styles.css index 4d1386c8..44b183b0 100644 --- a/browser-extension/src/popup/styles.css +++ b/browser-extension/src/popup/styles.css @@ -5,10 +5,9 @@ html, body { margin: 0; - min-width: 360px; - min-height: 480px; + min-width: 320px; color: rgba(0, 0, 0, 0.88); - background: #ffffff; + background: #f5f5f5; font-family: -apple-system, BlinkMacSystemFont, @@ -18,4 +17,249 @@ body { Arial, 'Noto Sans', sans-serif; + scrollbar-width: thin; + scrollbar-color: rgb(0 0 0 / 0.28) transparent; +} + +html::-webkit-scrollbar, +body::-webkit-scrollbar, +.popup-root::-webkit-scrollbar { + width: 6px; + height: 6px; +} + +html::-webkit-scrollbar-thumb, +body::-webkit-scrollbar-thumb, +.popup-root::-webkit-scrollbar-thumb { + background: rgb(0 0 0 / 0.28); + border-radius: 3px; +} + +.popup-root { + box-sizing: border-box; + width: 320px; + display: flex; + flex-direction: column; + gap: 10px; + padding: 12px; + background: #f5f5f5; + color: rgba(0, 0, 0, 0.88); +} + +.popup-header { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 8px; + padding: 2px 2px 0; +} + +.popup-header h1 { + margin: 0; + font-size: 15px; + font-weight: 600; + line-height: 1.3; +} + +.popup-sub { + margin: 2px 0 0; + font-size: 12px; + color: rgba(0, 0, 0, 0.45); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + max-width: 220px; +} + +.popup-card { + border: 1px solid #f0f0f0; + border-radius: 12px; + background: #fff; + padding: 12px; + box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); +} + +.popup-section-title { + margin: 0; + font-size: 12px; + font-weight: 600; + color: rgba(0, 0, 0, 0.45); +} + +.popup-label { + display: block; + font-size: 12px; + color: rgba(0, 0, 0, 0.45); +} + +.popup-input { + box-sizing: border-box; + display: block; + width: 100%; + margin-top: 4px; + border: 1px solid #d9d9d9; + border-radius: 8px; + padding: 6px 10px; + font-size: 13px; + outline: none; + background: #fff; + color: rgba(0, 0, 0, 0.88); +} + +.popup-input:focus { + border-color: #1677ff; + box-shadow: 0 0 0 2px rgb(22 119 255 / 0.2); +} + +.popup-btn { + border-radius: 8px; + border: 1px solid #d9d9d9; + background: #fff; + color: rgba(0, 0, 0, 0.88); + padding: 5px 10px; + font-size: 12px; + line-height: 1.4; + cursor: pointer; + transition: + color 0.15s, + border-color 0.15s, + background 0.15s; +} + +.popup-btn:disabled { + opacity: 0.45; + cursor: not-allowed; +} + +.popup-btn-primary { + border-color: #1677ff; + background: #1677ff; + color: #fff; +} + +.popup-btn-primary:hover:not(:disabled) { + border-color: #4096ff; + background: #4096ff; +} + +.popup-btn-ghost:hover:not(:disabled) { + color: #1677ff; + border-color: #1677ff; +} + +.popup-link { + border: 0; + background: transparent; + color: #1677ff; + font-size: 12px; + padding: 0; + cursor: pointer; + white-space: nowrap; +} + +.popup-link:hover:not(:disabled) { + text-decoration: underline; +} + +.popup-link:disabled { + opacity: 0.45; + cursor: not-allowed; +} + +.popup-feature { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + border: 1px solid #f0f0f0; + border-radius: 8px; + background: #fafafa; + padding: 8px 10px; +} + +.popup-hint { + margin: 0; + font-size: 12px; + color: rgba(0, 0, 0, 0.25); + line-height: 1.4; +} + +.popup-status { + margin: 0; + font-size: 12px; + color: #52c41a; + line-height: 1.4; +} + +.popup-error { + margin: 0; + font-size: 12px; + color: #ff4d4f; + line-height: 1.4; +} + +.w-full { + width: 100%; +} + +.space-y-2 > * + * { + margin-top: 8px; +} + +.flex { + display: flex; +} + +.items-center { + align-items: center; +} + +.justify-between { + justify-content: space-between; +} + +.gap-1\.5 { + gap: 6px; +} + +.gap-2 { + gap: 8px; +} + +.min-w-0 { + min-width: 0; +} + +.flex-1 { + flex: 1; +} + +.shrink-0 { + flex-shrink: 0; +} + +.truncate { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.text-sm { + font-size: 13px; +} + +.font-medium { + font-weight: 500; +} + +.text-antd-text { + color: rgba(0, 0, 0, 0.88); +} + +.text-antd-text-tertiary { + color: rgba(0, 0, 0, 0.25); +} + +.text-\[11px\] { + font-size: 11px; }