// ==================== 首页首次访问引导 ==================== (function () { const STORAGE_KEY = 'uwa_onboarding_v1'; const MODULE_STEPS = [ { key: 'config', code: 'Config', title: '站点配置', summary: '定义一个网站如何被转换为稳定的 API。', detail: '在这里管理反代站点规则、CSS / XPath 选择器、数据提取器、响应拦截检测,以及输入与输出转换工作流。' }, { key: 'tabpool', code: 'TabPool', title: '标签页池', summary: '掌握受控 Chrome 的实时工作状态。', detail: '查看多标签页并发池、网页匹配状态、会话隔离方式,以及每个 Tab 当前的线程占用情况。' }, { key: 'monitor', code: 'Monitor', title: '请求监控', summary: '观察每一次真实请求如何流经系统。', detail: '抓取并检查 HTTP / WebSocket 请求流量,快速核对请求 Payload、目标站点响应与最终提取结果。' }, { key: 'commands', code: 'Commands', title: '命令系统', summary: '把重复的浏览器操作编排成自动化流程。', detail: '配置和触发自动登录、点击交互、页面操作等动作序列,构建可重复执行的 UI 工作流。' }, { key: 'logs', code: 'Logs', title: '运行日志', summary: '从底层运行信息中快速定位异常。', detail: '实时查看后端 Python 服务和控制台日志,用于追踪请求链路、脚本执行过程与错误原因。' }, { key: 'settings', code: 'Settings', title: '设置', summary: '集中管理服务、安全与本地配置。', detail: '调整监听端口、面板 API Token、浏览器启动参数,并完成配置文件的导入导出、备份与恢复。' } ]; const SOP_STEPS = [ { key: 'principle', eyebrow: '核心原理', title: '网页交互,如何变成标准 API?', intro: 'Universal Web API 让受控 Chrome 保持真实网页的登录态和交互能力,再把网页会话桥接为 OpenAI 兼容接口。', note: '第三方客户端只需访问本地 API,无需直接理解每个网站的页面结构。' }, { key: 'browser', eyebrow: '步骤 1', title: '在受控浏览器中打开目标网页', intro: '运行系统后,在自动弹出的受控 Chrome 中打开需要反代的 AI 网站,并完成正常登录。', note: '例如打开 gemini.google.com。请始终使用系统启动的受控浏览器,而不是另一个普通浏览器窗口。' }, { key: 'interactive', eyebrow: '步骤 2 · 关键事项', title: '确保页面元素显性可交互', intro: '工作流要点击或提取的元素必须真实出现在页面中,不能处于折叠、遮挡或语言不匹配的状态。', note: '以 Gemini 为例,开始请求前请完成下面两项检查。' }, { key: 'routing', eyebrow: '步骤 3', title: '在标签页池确认网页并选择路由', intro: '登录成功后,标签页池会显示已捕获网页。根据使用场景选择全局、域名路径或 Query 参数路由。', note: '多站点同时运行时,显式指定域名最容易保持请求边界清晰。' }, { key: 'client', eyebrow: '步骤 4', title: '连接前端或第三方客户端', intro: '最后在 NextChat、LobeChat、LangChain 等客户端中填写 Base URL 与 API Key。', note: '未在设置中启用 Token 认证时,API Key 可以留空;若客户端强制要求,也可以填写任意值。' } ]; window.OnboardingGuide = { name: 'OnboardingGuide', emits: ['tour-start', 'tour-end'], data() { return { visible: false, view: 'welcome', phase: 'modules', moduleIndex: 0, sopIndex: 0, targetRect: null, cardStyle: {}, initialTimer: null, resizeHandler: null, keyHandler: null }; }, computed: { moduleSteps() { return MODULE_STEPS; }, sopSteps() { return SOP_STEPS; }, currentModule() { return this.moduleSteps[this.moduleIndex] || this.moduleSteps[0]; }, currentSop() { return this.sopSteps[this.sopIndex] || this.sopSteps[0]; }, totalTourSteps() { return this.moduleSteps.length + this.sopSteps.length; }, completedTourSteps() { return this.phase === 'modules' ? this.moduleIndex + 1 : this.moduleSteps.length + this.sopIndex + 1; }, progressPercent() { return Math.round((this.completedTourSteps / this.totalTourSteps) * 100); }, spotlightStyle() { if (!this.targetRect) { return { display: 'none' }; } return { left: this.targetRect.left + 'px', top: this.targetRect.top + 'px', width: this.targetRect.width + 'px', height: this.targetRect.height + 'px' }; }, shadeStyles() { if (!this.targetRect) { return [{ inset: '0' }]; } const rect = this.targetRect; return [ { left: '0', top: '0', right: '0', height: rect.top + 'px' }, { left: '0', top: rect.top + 'px', width: rect.left + 'px', height: rect.height + 'px' }, { left: (rect.left + rect.width) + 'px', top: rect.top + 'px', right: '0', height: rect.height + 'px' }, { left: '0', top: (rect.top + rect.height) + 'px', right: '0', bottom: '0' } ]; } }, mounted() { this.resizeHandler = () => this.schedulePositionUpdate(); this.keyHandler = (event) => this.handleKeydown(event); window.addEventListener('resize', this.resizeHandler, { passive: true }); window.addEventListener('scroll', this.resizeHandler, true); document.addEventListener('keydown', this.keyHandler); this.initialTimer = window.setTimeout(() => { if (!this.hasSavedDecision()) { this.open(false); } }, 650); }, beforeUnmount() { window.clearTimeout(this.initialTimer); window.removeEventListener('resize', this.resizeHandler); window.removeEventListener('scroll', this.resizeHandler, true); document.removeEventListener('keydown', this.keyHandler); }, methods: { hasSavedDecision() { try { return !!localStorage.getItem(STORAGE_KEY); } catch (error) { return false; } }, saveDecision(status) { try { localStorage.setItem(STORAGE_KEY, JSON.stringify({ version: 1, status: status, updatedAt: new Date().toISOString() })); } catch (error) { // Storage is optional; the guide remains usable for this session. } }, open(startDirectly) { window.clearTimeout(this.initialTimer); this.visible = true; this.view = startDirectly ? 'tour' : 'welcome'; this.phase = 'modules'; this.moduleIndex = 0; this.sopIndex = 0; this.targetRect = null; if (startDirectly) { this.$emit('tour-start'); this.$nextTick(() => this.updateSpotlight()); } this.$nextTick(() => this.focusDialog()); }, startTour() { this.view = 'tour'; this.phase = 'modules'; this.moduleIndex = 0; this.$emit('tour-start'); this.$nextTick(() => { this.updateSpotlight(); this.focusDialog(); }); }, dismissWelcome() { this.saveDecision('dismissed'); this.close(false); }, skipTour() { this.saveDecision('skipped'); this.close(true); }, finishTour() { this.saveDecision('completed'); this.close(true); }, close(wasTour) { this.visible = false; this.targetRect = null; if (wasTour || this.view === 'tour') { this.$emit('tour-end'); } }, previous() { if (this.phase === 'modules') { if (this.moduleIndex > 0) { this.moduleIndex -= 1; this.$nextTick(() => this.updateSpotlight()); } return; } if (this.sopIndex > 0) { this.sopIndex -= 1; return; } this.phase = 'modules'; this.moduleIndex = this.moduleSteps.length - 1; this.$nextTick(() => this.updateSpotlight()); }, next() { if (this.phase === 'modules') { if (this.moduleIndex < this.moduleSteps.length - 1) { this.moduleIndex += 1; this.$nextTick(() => this.updateSpotlight()); return; } this.phase = 'sop'; this.sopIndex = 0; this.targetRect = null; this.$nextTick(() => this.focusDialog()); return; } if (this.sopIndex < this.sopSteps.length - 1) { this.sopIndex += 1; this.$nextTick(() => this.focusDialog()); return; } this.finishTour(); }, goToSop(index) { this.sopIndex = index; this.$nextTick(() => this.focusDialog()); }, schedulePositionUpdate() { if (!this.visible || this.view !== 'tour' || this.phase !== 'modules') { return; } window.requestAnimationFrame(() => this.updateSpotlight()); }, updateSpotlight() { if (!this.visible || this.phase !== 'modules') { return; } const selector = '[data-tour-target="' + this.currentModule.key + '"]'; const target = document.querySelector(selector); if (!target) { this.targetRect = null; this.cardStyle = {}; return; } target.scrollIntoView({ block: 'nearest', behavior: 'smooth' }); window.setTimeout(() => { const bounds = target.getBoundingClientRect(); const gap = 7; const rect = { left: Math.max(0, bounds.left - gap), top: Math.max(0, bounds.top - gap), width: Math.min(window.innerWidth, bounds.width + gap * 2), height: Math.min(window.innerHeight, bounds.height + gap * 2) }; this.targetRect = rect; this.cardStyle = this.getCardStyle(rect); }, 120); }, getCardStyle(rect) { const viewportWidth = window.innerWidth; const viewportHeight = window.innerHeight; if (viewportWidth <= 700) { const estimatedHeight = 268; const placeAtTop = rect.top > viewportHeight * 0.48; return { left: '14px', right: '14px', top: placeAtTop ? '14px' : 'auto', bottom: placeAtTop ? 'auto' : '14px' }; } const cardWidth = 390; const preferredLeft = rect.left + rect.width + 20; const left = preferredLeft + cardWidth <= viewportWidth - 18 ? preferredLeft : Math.max(18, rect.left - cardWidth - 20); const top = Math.max(18, Math.min(rect.top - 22, viewportHeight - 340)); return { left: left + 'px', top: top + 'px', width: cardWidth + 'px' }; }, focusDialog() { const dialog = this.$el && this.$el.querySelector('[role="dialog"]'); if (dialog && typeof dialog.focus === 'function') { dialog.focus({ preventScroll: true }); } }, handleKeydown(event) { if (!this.visible) { return; } if (event.key === 'Escape') { event.preventDefault(); this.view === 'welcome' ? this.dismissWelcome() : this.skipTour(); return; } if (this.view !== 'tour') { return; } if (event.key === 'ArrowLeft') { event.preventDefault(); this.previous(); } else if (event.key === 'ArrowRight' || event.key === 'Enter') { event.preventDefault(); this.next(); } } }, template: `
` }; })();