diff --git a/CHANGELOG.md b/CHANGELOG.md index 5117435..2eb4ae6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. See [standa ## Version 2026.10.12-it-tools-pro +### 🤖 每个工具页新增「问AI」按钮 +- 位置:工具页**左上角**(标题左侧),绿色胶囊按钮「🤖 问AI」 +- 点击**弹出窗口**,AI 即时生成该工具的三节说明:**使用方法**(3-5 步编号)/ **特色亮点**(3-4 点)/ **小提示**(1 条) +- 新端点 `POST /relay/ai/tool-help`,**免费开放**(不在 PROTECTED_TOOLS、不做授权检查),走 mimo-v2.6-flash,90s 超时 +- 前端 `markdown-it` 渲染(`html:false` 防注入),按 path 缓存内容,切换回来不重复请求;失败可重试;带加载动画 +- 验证:端点直测 7.3s 返回结构化 Markdown ✓;4 个工具页(翻译/JSON/OCR/印章)均有按钮 ✓;弹窗加载→三节渲染、控制台无报错 ✓;视觉排版清晰 ✓ + ### 📖 新功能介绍页同步更新 - **修正 AI 客服介绍**:去掉已移除的「模型可选」→「模型固定不开选择」 - **新增「首页资讯」分组 4 条**:每日资讯 5 列 / 最热股票实时刷新 / 自选股 / 首页推荐与全部工具(此前介绍页完全未提及) diff --git a/components.d.ts b/components.d.ts index 6fe1186..6ab2333 100644 --- a/components.d.ts +++ b/components.d.ts @@ -184,6 +184,7 @@ declare module '@vue/runtime-core' { NLayout: typeof import('naive-ui')['NLayout'] NLayoutSider: typeof import('naive-ui')['NLayoutSider'] NMenu: typeof import('naive-ui')['NMenu'] + NModal: typeof import('naive-ui')['NModal'] NProgress: typeof import('naive-ui')['NProgress'] NScrollbar: typeof import('naive-ui')['NScrollbar'] NSlider: typeof import('naive-ui')['NSlider'] diff --git a/src/layouts/tool.layout.vue b/src/layouts/tool.layout.vue index b1ba9a1..8a102f2 100644 --- a/src/layouts/tool.layout.vue +++ b/src/layouts/tool.layout.vue @@ -46,6 +46,55 @@ const isWide = computed(() => WIDE_TOOLS.has(route.path)); const i18nKey = computed(() => route.path.trim().replace('/', '')); const toolTitle = computed(() => t(`tools.${i18nKey.value}.title`, String(route.meta.name))); const toolDescription = computed(() => t(`tools.${i18nKey.value}.description`, String(route.meta.description))); + +// ===== 「问AI」按钮:弹窗展示当前工具的用法与特色 ===== +import MarkdownIt from 'markdown-it'; +const mdRenderer = new MarkdownIt({ html: false, linkify: true, breaks: true }); + +const showAiHelp = ref(false); +const aiHelpCache = ref>({}); // 按 path 缓存,切换回来不重复请求 +const aiHelpLoading = ref(false); +const aiHelpErr = ref(''); + +const aiHelpHtml = computed(() => { + const src = aiHelpCache.value[route.path] || ''; + return src ? mdRenderer.render(src) : ''; +}); + +async function askAiHelp() { + showAiHelp.value = true; + if (aiHelpCache.value[route.path] || aiHelpLoading.value) return; + aiHelpLoading.value = true; + aiHelpErr.value = ''; + try { + const res = await fetch('/relay/ai/tool-help', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + name: toolTitle.value, + description: toolDescription.value, + path: route.path, + }), + }); + const j = await res.json().catch(() => ({})); + if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`); + aiHelpCache.value = { ...aiHelpCache.value, [route.path]: String(j.data?.reply || '') }; + } + catch (e: any) { + aiHelpErr.value = String(e?.message || e); + } + finally { + aiHelpLoading.value = false; + } +} + +function retryAiHelp() { + const next = { ...aiHelpCache.value }; + delete next[route.path]; + aiHelpCache.value = next; + aiHelpErr.value = ''; + askAiHelp(); +}