// ==================== 所有弹窗组件 ==================== // -------------------- JSON 预览弹窗 -------------------- window.JsonPreviewDialog = { name: 'JsonPreviewDialog', props: { show: { type: Boolean, default: false }, jsonData: { type: Object, default: () => ({}) }, title: { type: String, default: '配置 JSON' } }, emits: ['close', 'copy', 'save'], data() { return { draft: '' }; }, watch: { show: { handler(value) { if (value) { this.draft = JSON.stringify(this.jsonData || {}, null, 2); } }, immediate: true }, jsonData: { handler() { if (this.show) { this.draft = JSON.stringify(this.jsonData || {}, null, 2); } }, deep: true } }, template: `

{{ title }}

` }; // -------------------- 控制面板访问密钥弹窗 -------------------- window.TokenDialog = { name: 'TokenDialog', props: { show: { type: Boolean, default: false }, modelValue: { type: String, default: '' } }, emits: ['close', 'save', 'update:modelValue'], computed: { tempToken: { get() { return this.modelValue; }, set(val) { this.$emit('update:modelValue', val); } } }, template: `

配置控制面板访问密钥

仅用于访问控制面板管理接口,不等同于对外服务 API Key
` }; // -------------------- 步骤模板弹窗 -------------------- window.StepTemplatesDialog = { name: 'StepTemplatesDialog', props: { show: { type: Boolean, default: false } }, emits: ['close', 'apply'], template: `

工作流模板

` }; // -------------------- 选择器测试弹窗 -------------------- window.TestDialog = { name: 'TestDialog', props: { show: { type: Boolean, default: false }, selector: { type: String, default: '' }, selectorKey: { type: String, default: '' }, timeoutValue: { type: Number, default: 2 }, highlightEnabled: { type: Boolean, default: false }, result: { type: Object, default: null }, testing: { type: Boolean, default: false } }, emits: ['close', 'test', 'apply-selector'], data() { return { selectorInput: '', timeout: 3, highlight: false, copyFeedback: '' }; }, watch: { show: { handler(value) { if (value) { this.syncFromProps(); } }, immediate: true }, selector(value) { if (this.show) { this.selectorInput = value || ''; } }, timeoutValue(value) { if (this.show && Number.isFinite(value)) { this.timeout = value; } }, highlightEnabled(value) { if (this.show) { this.highlight = !!value; } } }, computed: { diagnosis() { return this.result && this.result.diagnosis ? this.result.diagnosis : null; }, topCandidates() { return Array.isArray(this.result && this.result.top_candidates) ? this.result.top_candidates : []; }, resultElements() { return Array.isArray(this.result && this.result.elements) ? this.result.elements : []; }, selectorLabel() { const key = String(this.selectorKey || '').trim(); const labelMap = { input_box: '输入框', send_btn: '发送按钮', result_container: '回复容器', new_chat_btn: '新建对话按钮', message_wrapper: '消息外层', generating_indicator: '生成中指示器', retry_send_btn: '重试/重新运行按钮', upload_btn: '上传按钮', file_input: '原生文件输入框', drop_zone: '拖拽区域' }; return labelMap[key] || '当前字段'; }, canApplyCurrent() { return !!String(this.selectorInput || '').trim() && !!String(this.selectorKey || '').trim(); } }, methods: { syncFromProps() { this.selectorInput = this.selector || ''; this.timeout = Number.isFinite(this.timeoutValue) ? this.timeoutValue : 3; this.highlight = !!this.highlightEnabled; this.copyFeedback = ''; }, async copyText(value) { const text = String(value || '').trim(); if (!text) return; try { await navigator.clipboard.writeText(text); this.copyFeedback = '已复制到剪贴板'; window.setTimeout(() => { if (this.copyFeedback === '已复制到剪贴板') { this.copyFeedback = ''; } }, 1600); } catch (error) { this.copyFeedback = '复制失败'; window.setTimeout(() => { if (this.copyFeedback === '复制失败') { this.copyFeedback = ''; } }, 1600); } }, useCandidate(selector) { this.selectorInput = String(selector || '').trim(); }, retestCandidate(selector) { this.selectorInput = String(selector || '').trim(); if (!this.selectorInput) return; this.$emit('test', { selector: this.selectorInput, timeout: this.timeout, highlight: this.highlight }); }, applyCandidate(selector, rerun = false) { const value = String(selector || '').trim(); if (!value) return; this.selectorInput = value; this.$emit('apply-selector', { selector: value, rerun }); }, applyCurrentSelector(rerun = false) { if (!this.canApplyCurrent) return; this.$emit('apply-selector', { selector: this.selectorInput, rerun }); }, resultToneClass() { const status = this.diagnosis && this.diagnosis.status; if (status === 'unique') { return 'bg-emerald-50 dark:bg-emerald-900/20 border-emerald-200 dark:border-emerald-800'; } if (status === 'multiple') { return 'bg-amber-50 dark:bg-amber-900/20 border-amber-200 dark:border-amber-800'; } return 'bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800'; }, uniqueBadgeClass(candidate) { return candidate && candidate.unique ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300' : 'bg-slate-100 text-slate-600 dark:bg-slate-700 dark:text-slate-300'; } }, template: `

选择器测试工作台

不只是看“找到了没”,还会给出候选写法、风险提示和回填入口。

当前字段:{{ selectorKey }} · {{ selectorLabel }} {{ copyFeedback }}
{{ result.success ? (result.count === 1 ? '✅ 唯一命中' : '⚠️ 命中多个元素') : '❌ 没有命中元素' }} 匹配数量:{{ result.count }} 实际查询:{{ result.locator_used }} 已测试 {{ result.tabs_tested }} 个页面,{{ result.matched_tabs }} 个页面命中

{{ diagnosis.summary }}

{{ result.message }}

风险提示
{{ warning }}
下一步建议
{{ tip }}
逐页结果
{{ tab.tab_index ? '页面 #' + tab.tab_index : '浏览器页面' }} {{ tab.count > 0 ? '命中 ' + tab.count + ' 个' : '未命中' }}
{{ tab.url }}
另有 {{ result.skipped_busy_tabs }} 个同站点页面正在执行任务,本次未打断它们。
推荐候选选择器
优先把更稳、更容易唯一命中的写法拿去复测。
候选 {{ idx + 1 }} {{ candidate.unique ? '唯一命中' : '匹配 ' + candidate.count + ' 个' }} {{ candidate.reason }}
{{ candidate.selector }}
命中详情
{{ result ? '已展开 ' + resultElements.length + ' 个元素详情' + (result.truncated ? '(其余命中已省略)' : '') : '先跑一次测试,这里会显示命中的元素摘要和属性。' }}
暂无测试结果
这次没有拿到可展示的元素摘要
#{{ element.index + 1 }} <{{ element.tag || 'unknown' }}> {{ element.visible ? '可见' : '不可见/尺寸为 0' }} {{ element.rect.width }}×{{ element.rect.height }}
{{ element.text }}
{{ key }} {{ value }}
查看 HTML 摘要
{{ element.html_preview }}
{{ warning }}
这个元素的候选
{{ candidate.unique ? '唯一命中' : '匹配 ' + candidate.count + ' 个' }} {{ candidate.reason }}
{{ candidate.selector }}
` }; // -------------------- 导入确认弹窗 -------------------- window.ImportDialog = { name: 'ImportDialog', props: { show: { type: Boolean, default: false }, fileName: { type: String, default: '' }, importType: { type: String, default: 'full' }, suggestedDomain: { type: String, default: '' }, importedConfig: { type: Object, default: null } }, emits: ['close', 'confirm'], data() { return { mode: 'merge', singleDomain: '' }; }, watch: { show(val) { if (val) { this.mode = 'merge'; this.singleDomain = this.suggestedDomain || ''; } }, suggestedDomain(val) { if (this.show && !this.singleDomain.trim()) { this.singleDomain = val || ''; } } }, computed: { singleImportHint() { if (this.suggestedDomain) { return '已从导入文件推断站点名,直接确认即可,也可以手动修改。'; } return '未识别出站点名时,再手动补充即可。'; }, mergeDescription() { if (this.importType === 'single') { return '保留当前站点里未导入的预设;导入文件中的同名预设会被覆盖。'; } return '只导入文件里的站点;同名站点整站覆盖,未出现在文件中的站点会保留。'; }, replaceDescription() { if (this.importType === 'single') { return '用导入文件完整替换这个站点,当前站点已有预设和设置都会被清掉。'; } return '先清空当前全部站点配置,再写入导入文件中的站点。'; } }, template: `

导入配置

文件: {{ fileName }}
类型: {{ importType === 'single' ? '单站点配置' : '全量配置 (' + Object.keys(importedConfig || {}).length + ' 个站点)' }}
{{ Object.keys(importedConfig).join(', ') }}

{{ singleImportHint }}

` }; // -------------------- 新增/编辑元素定义弹窗 -------------------- window.DefinitionDialog = { name: 'DefinitionDialog', props: { show: { type: Boolean, default: false }, editIndex: { type: Number, default: null }, definition: { type: Object, default: () => ({ key: '', description: '', enabled: true }) } }, emits: ['close', 'save'], data() { return { form: { key: '', description: '', enabled: true } }; }, watch: { show(val) { if (val) { this.form = { ...this.definition }; } } }, computed: { isEdit() { return this.editIndex !== null; } }, template: `

{{ isEdit ? '编辑元素定义' : '新增元素定义' }}

用于工作流配置中引用此元素

AI 会根据这个描述在页面中查找对应的元素

默认启用
` };