// R2-8:站点适配器维护面板——健康巡检(R1-6)、选择器脆弱度(R1-7)、适配器在线更新(R1-3)。 // 由 ConfigTab 以 使用;request 为带鉴权与超时的请求函数(返回解析后的 JSON,出错抛异常)。 window.AdapterPanel = { name: 'AdapterPanel', props: { domain: { type: String, default: '' }, presetName: { type: String, default: '' }, request: { type: Function, required: true } }, data() { return { health: null, healthLoading: false, healthError: '', lint: null, lintLoading: false, lintError: '', updates: null, updatesLoading: false, updatesError: '', applyResult: null, applying: false }; }, computed: { healthTab() { return (this.health && Array.isArray(this.health.tabs) && this.health.tabs[0]) || null; }, lintRows() { const presets = (this.lint && this.lint.presets) || {}; const rows = presets[this.presetName] || Object.values(presets)[0] || []; return rows.filter(row => row.score < 100 || (row.issues || []).length); }, updateRows() { return ((this.updates && this.updates.sites) || []).filter(row => row.status !== 'up_to_date'); }, safeUpdateCount() { return this.updateRows.filter(row => row.status === 'update_available' || row.status === 'new_site').length; } }, watch: { domain() { this.health = null; this.healthError = ''; this.lint = null; this.lintError = ''; } }, methods: { statusLabel(status) { return ({ healthy: '健康', degraded: '部分缺失', broken: '异常', unreachable: '无可用页面', ok: '命中', missing: '未命中', invalid: '语法无效', up_to_date: '已是最新', update_available: '可安全更新', conflict: '本地已修改', new_site: '新站点', local_only: '仅本地', requires_newer_app: '需要更新程序' })[status] || status; }, statusClass(status) { if (['healthy', 'ok', 'up_to_date'].includes(status)) return 'adapter-badge is-good'; if (['degraded', 'missing', 'update_available', 'new_site', 'conflict'].includes(status)) return 'adapter-badge is-warn'; if (['broken', 'invalid', 'requires_newer_app'].includes(status)) return 'adapter-badge is-bad'; return 'adapter-badge'; }, async runHealth() { if (!this.domain) return; this.healthLoading = true; this.healthError = ''; try { const query = new URLSearchParams({ site: this.domain }); if (this.presetName) query.set('preset', this.presetName); this.health = await this.request('/api/adapters/health?' + query.toString()); } catch (error) { this.healthError = error.message || String(error); } finally { this.healthLoading = false; } }, async runLint() { if (!this.domain) return; this.lintLoading = true; this.lintError = ''; try { this.lint = await this.request('/api/adapters/lint?' + new URLSearchParams({ site: this.domain }).toString()); } catch (error) { this.lintError = error.message || String(error); } finally { this.lintLoading = false; } }, async checkUpdates(keepApplyResult = false) { // 应用更新后会自动刷新列表:这时要保留“已更新 N 个站点”的结果提示,不能被清掉 this.updatesLoading = true; this.updatesError = ''; if (!keepApplyResult) this.applyResult = null; try { this.updates = await this.request('/api/adapters/updates'); } catch (error) { this.updatesError = error.message || String(error); } finally { this.updatesLoading = false; } }, async applyUpdates(sites = null, includeConflicts = false) { if (includeConflicts && !window.confirm('该站点的本地配置改过:将按「本地优先」与官方新版合并(保留你的修改,补入新增字段)。继续?')) { return; } this.applying = true; this.updatesError = ''; try { const body = { include_conflicts: includeConflicts }; if (sites) body.sites = sites; this.applyResult = await this.request('/api/adapters/updates/apply', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); this.$emit('updated', this.applyResult); await this.checkUpdates(true); } catch (error) { this.updatesError = error.message || String(error); } finally { this.applying = false; } } }, template: `

健康巡检

在浏览器里已打开的 {{ domain || '当前站点' }} 页面上检查各选择器能否命中。只读取页面,不会输入、点击或发送消息。

{{ healthError }}

结果:{{ statusLabel(health.status) }} 预设:{{ health.preset }}

  • {{ problem }}
元素状态命中数稳健度说明
{{ row.key }} {{ statusLabel(row.status) }} {{ row.count }} {{ row.quality ? row.quality.score : '-' }} {{ row.hint }} 可尝试:{{ row.suggestions[0].selector }}

选择器稳健度

静态检查当前预设的选择器:生成的哈希类名、依赖元素顺序或界面文字的写法,在站点改版时容易失效。

{{ lintError }}

当前预设的选择器没有发现明显问题。

元素得分问题
{{ row.key }} {{ row.score }} {{ (row.issues || []).map(issue => issue.message).join(';') || '—' }}

适配器更新(全部站点)

与官方仓库的站点配置比较。没改过的站点可以一键更新;改过的站点会单独标出,需要你确认后按「本地优先」合并。

{{ updatesError }}

所有站点配置都是最新的。

已更新 {{ (applyResult.applied || []).length }} 个站点,跳过 {{ applyResult.skipped.length }} 个。

` };