feat: 每个工具页新增「问AI」按钮

- 左上角绿色胶囊按钮, 点击弹窗显示该工具 使用方法/特色亮点/小提示
- 新端点 POST /relay/ai/tool-help (免费, 不做授权检查), mimo-v2.6-flash
- 前端 markdown-it 渲染(html:false防注入), 按path缓存, 失败可重试, 加载动画
- About 功能介绍新增「问AI 按钮」条目

验证: 端点直测7.3s结构化返回 ✓; 4工具页均有按钮 ✓; 弹窗三节渲染无报错 ✓

CHANGELOG记录
This commit is contained in:
personal82555 committed 2026-10-14 10:45:27 +08:00
1 parent 38caff5d82
commit 01fecba91b
4 files changed
+215

No files matched your search

+206
View File
@@ -46,6 +46,55 @@ const isWide = computed(() => WIDE_TOOLS.has(route.path));
const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
const toolTitle = computed<string>(() => t(`tools.${i18nKey.value}.title`, String(route.meta.name)));
const toolDescription = computed<string>(() => 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<Record<string, string>>({}); // 按 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();
}
</script>
<template>
@@ -53,6 +102,9 @@ const toolDescription = computed<string>(() => t(`tools.${i18nKey.value}.descrip
<div class="tool-layout" :class="{ wide: isWide }">
<div class="tool-header">
<div flex flex-nowrap items-center gap-12px>
<button class="ask-ai-btn" title="问 AI:本工具的用法与特色" @click="askAiHelp">
🤖 问AI
</button>
<n-h1 m-0>
{{ toolTitle }}
</n-h1>
@@ -68,6 +120,28 @@ const toolDescription = computed<string>(() => t(`tools.${i18nKey.value}.descrip
</div>
</div>
<!-- 问AI 弹窗:当前工具的用法与特色 -->
<n-modal
v-model:show="showAiHelp"
preset="card"
class="ai-help-modal"
:title="`🤖 问AI · ${toolTitle}`"
:style="{ width: 'min(680px, 94vw)' }"
>
<div class="ai-help-box">
<div v-if="aiHelpLoading" class="ai-help-state">
<span class="ai-help-dots"><i /><i /><i /></span>
AI 正在整理这个工具的用法…
</div>
<div v-else-if="aiHelpErr" class="ai-help-state err">
⚠️ {{ aiHelpErr }}
<button class="ai-help-retry" @click="retryAiHelp">重试</button>
</div>
<div v-else-if="aiHelpHtml" class="ai-help-body" v-html="aiHelpHtml" />
<div v-else class="ai-help-state">暂无内容</div>
</div>
</n-modal>
<div class="tool-content" :class="{ wide: isWide }">
<slot />
</div>
@@ -152,3 +226,135 @@ const toolDescription = computed<string>(() => t(`tools.${i18nKey.value}.descrip
}
}
</style>
<style lang="less" scoped>
// 「问AI」按钮 —— 工具页左上角
.ask-ai-btn {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 6px 14px;
border: 1px solid rgba(24, 160, 88, 0.45);
border-radius: 999px;
background: rgba(24, 160, 88, 0.1);
color: #18a058;
font-size: 14.5px;
font-weight: 600;
flex-shrink: 0;
cursor: pointer;
transition: all 0.15s;
&:hover {
background: #18a058;
color: #fff;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(24, 160, 88, 0.3);
}
}
// 问AI 弹窗
.ai-help-box {
min-height: 170px;
}
.ai-help-state {
display: flex;
align-items: center;
gap: 10px;
padding: 26px 4px;
font-size: 15px;
opacity: 0.75;
&.err {
color: #d03050;
opacity: 1;
}
}
.ai-help-dots {
display: inline-flex;
gap: 5px;
i {
width: 8px;
height: 8px;
border-radius: 50%;
background: #18a058;
animation: aihelp-blink 1.2s infinite ease-in-out;
&:nth-child(2) {
animation-delay: 0.2s;
}
&:nth-child(3) {
animation-delay: 0.4s;
}
}
}
@keyframes aihelp-blink {
0%,
80%,
100% {
opacity: 0.25;
transform: scale(0.8);
}
40% {
opacity: 1;
transform: scale(1);
}
}
.ai-help-retry {
margin-left: 4px;
padding: 4px 12px;
border: none;
border-radius: 6px;
background: #d03050;
color: #fff;
font-size: 13.5px;
cursor: pointer;
}
.ai-help-body {
font-size: 15px;
line-height: 1.75;
color: rgba(0, 0, 0, 0.85);
:deep(h3) {
margin: 14px 0 8px;
font-size: 16.5px;
color: #18a058;
&:first-child {
margin-top: 0;
}
}
:deep(ol),
:deep(ul) {
margin: 0 0 10px;
padding-left: 22px;
}
:deep(li) {
margin: 5px 0;
}
:deep(p) {
margin: 8px 0;
}
:deep(code) {
padding: 1px 6px;
border-radius: 4px;
background: rgba(0, 0, 0, 0.06);
font-size: 14px;
}
:deep(strong) {
color: #18a058;
}
}
</style>