refactor: 截图理解并入图片工具 — image-tools新增「AI看图理解」tab(5预设问题+自定义提问+结果面板), 移除独立/screenshot-qa入口, 授权与试用归入image-tools

This commit is contained in:
personal82555 committed 2026-10-13 00:02:43 +08:00
1 parent 5797fed492
commit 6bcdfebf04
7 files changed
+97 -339

No files matched your search

+2 -2
View File
@@ -1704,7 +1704,7 @@ class Handler(BaseHTTPRequestHandler):
def _handle_vision(self):
payload = self._read_payload()
machine = str(payload.get("machine") or "")
if check(machine, "screenshot-qa") != 200:
if check(machine, "image-tools") != 200:
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
return
b64 = str(payload.get("image") or "")
@@ -1723,7 +1723,7 @@ class Handler(BaseHTTPRequestHandler):
{"type": "image_url", "image_url": {"url": "data:image/png;base64," + b64}},
]},
])
log_usage(machine, "screenshot-qa")
log_usage(machine, "image-tools")
self._reply(200, json.dumps({"code": 200, "message": "ok", "data": {"reply": reply}}, ensure_ascii=False).encode("utf-8"), "application/json")
except Exception as e: # noqa: BLE001
self._reply(502, json.dumps({"code": 502, "message": f"AI 服务异常: {e}"}, ensure_ascii=False).encode(), "application/json")
-1
View File
@@ -21,7 +21,6 @@ const NEW_FEATURES = [
{ path: '/ai-image-lab', icon: '🪄', name: 'AI 图片实验室', desc: '智能抠图去背景、AI 无损放大变清晰、一键证件照' },
{ path: '/ai-chat', icon: '🤖', name: 'AI 问答', desc: '报错解读、文案写作、代码问题随口问,支持多轮对话' },
{ path: '/copywriting', icon: '✍️', name: '文案工具箱', desc: '一键改写、降 AIGC 率、爆款标题、小红书/朋友圈文案' },
{ path: '/screenshot-qa', icon: '👁️', name: '截图理解', desc: '丢张截图/票据/报错图,AI 读懂并提取关键信息' },
{ path: '/video-subtitle', icon: '🎬', name: '视频字幕 AI', desc: 'Whisper 自动生成 SRT + AI 翻译英日文' },
];
import { config } from '@/config';
+95
View File
@@ -7,6 +7,7 @@ import wasmUrl from 'zxing-wasm/reader/zxing_reader.wasm?url';
import { useStorage } from '@vueuse/core';
import GenHistory from '@/tools/gen-history/GenHistory.vue';
import { useGenHistory } from '@/tools/gen-history/gen-history';
import { getMachineId, licenseHeaders } from '@/tools/license/license';
prepareZXingModule({ overrideWasmUrl: wasmUrl });
const genHist = useGenHistory('image-tools');
@@ -26,6 +27,7 @@ const TABS: TabDef[] = [
{ key: 'qrread', label: '二维码识别', desc: '识别图片中的二维码/条码内容' },
{ key: 'watermark', label: '加水印', desc: '为图片添加文字水印(居中或平铺)' },
{ key: 'stitch', label: '多图拼接', desc: '横向/纵向长图/九宫格/瀑布流/交错双列/拍立得 6 种方式', multi: true },
{ key: 'vision', label: 'AI 看图理解', desc: '截图/票据/报错图,AI 读懂并提取关键信息' },
];
const tabKey = useStorage('image-tools:tab', 'compress');
@@ -346,6 +348,9 @@ async function execute() {
else if (k === 'stitch') {
await doStitch();
}
else if (k === 'vision') {
await doVision();
}
const ms = Math.round(performance.now() - start);
statusMsg.value = `完成,用时 ${ms}ms`;
}
@@ -609,6 +614,49 @@ async function doWatermark() {
resultDim.value = `${c.width}×${c.height}`;
}
// ============ AI 看图理解 ============
const VISION_QUESTIONS = [
'提取图片中的所有文字,结构化整理',
'图里写了什么关键信息?(金额/日期/编号)',
'这是什么报错?原因和解决办法?',
'把表格内容转成 Markdown 表格',
'用三句话总结这张图',
];
const visionQ = ref(VISION_QUESTIONS[0]);
const visionOut = ref('');
const visionBusy = ref(false);
async function doVision() {
const f = files.value[0];
if (!f) {
throw new Error('请先上传图片');
}
visionBusy.value = true;
visionOut.value = '';
try {
const b64 = await new Promise<string>((resolve, reject) => {
const r = new FileReader();
r.onload = () => resolve(String(r.result).split(',')[1]);
r.onerror = () => reject(new Error('读取图片失败'));
r.readAsDataURL(f);
});
const res = await fetch('/relay/ai/vision', {
method: 'POST',
headers: { ...licenseHeaders('image-tools'), 'Content-Type': 'application/json' },
body: JSON.stringify({ machine: getMachineId(), image: b64, question: visionQ.value }),
});
const j = await res.json().catch(() => ({}));
if (!res.ok || j.code !== 200) {
throw new Error(j.message || `HTTP ${res.status}`);
}
visionOut.value = j.data.reply;
genHist.add({ title: `AI 看图: ${f.name}`, detail: visionQ.value.slice(0, 20) });
}
finally {
visionBusy.value = false;
}
}
async function doStitch() {
if (files.value.length < 2) {
throw new Error('请至少选择 2 张图片');
@@ -1000,6 +1048,20 @@ onUnmounted(() => {
<input v-model.number="stitchGap" type="range" min="0" max="40" step="2" class="it-range">
<span class="it-val">{{ stitchGap }}px</span>
</template>
<template v-else-if="tab.key === 'vision'">
<label>问它什么</label>
<div class="it-vision-chips">
<button v-for="q in VISION_QUESTIONS" :key="q" class="it-chip" :class="{ on: visionQ === q }" @click="visionQ = q">
{{ q.length > 14 ? q.slice(0, 14) + '…' : q }}
</button>
</div>
<input v-model="visionQ" class="it-input" placeholder="或直接输入你的问题…" style="width:100%;box-sizing:border-box">
<div v-if="visionBusy" class="it-vision-busy">⏳ AI 正在看图…</div>
<div v-if="visionOut" class="it-vision-out">
<pre>{{ visionOut }}</pre>
<button class="it-chip" @click="navigator.clipboard.writeText(visionOut)">📋 复制回答</button>
</div>
</template>
</div>
</div>
@@ -1051,6 +1113,39 @@ onUnmounted(() => {
</template>
<style lang="less" scoped>
.it-vision-chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
width: 100%;
}
.it-vision-busy {
font-size: 12.5px;
color: #2563eb;
font-weight: 700;
width: 100%;
}
.it-vision-out {
width: 100%;
background: rgba(128, 128, 128, 0.06);
border: 1px solid rgba(128, 128, 128, 0.18);
border-radius: 9px;
padding: 11px 13px;
margin-top: 4px;
pre {
margin: 0 0 9px;
white-space: pre-wrap;
word-break: break-word;
font-family: inherit;
font-size: 13px;
line-height: 1.75;
max-height: 320px;
overflow-y: auto;
}
}
.it-root {
display: flex;
flex-direction: column;
-2
View File
@@ -91,7 +91,6 @@ import { tool as pinyinConverter } from './pinyin-converter';
import { tool as aiImageLab } from './ai-image-lab';
import { tool as aiChat } from './ai-chat';
import { tool as copywriting } from './copywriting';
import { tool as screenshotQa } from './screenshot-qa';
import { tool as videoSubtitle } from './video-subtitle';
import { tool as docConvert } from './doc-convert';
import { tool as aiRetouch } from './ai-retouch';
@@ -213,7 +212,6 @@ export const toolsByCategory: ToolCategory[] = [
aiImageLab,
aiChat,
copywriting,
screenshotQa,
videoSubtitle,
],
},
-1
View File
@@ -20,7 +20,6 @@ export const PROTECTED_TOOLS: Record<string, string> = {
'/ai-image-lab': 'AI图片实验室',
'/ai-chat': 'AI问答',
'/copywriting': '文案工具箱',
'/screenshot-qa': '截图理解',
'/video-subtitle': '视频字幕AI',
};
-11
View File
@@ -1,11 +0,0 @@
import { Eye } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: '截图理解',
path: '/screenshot-qa',
description: 'AI 看图说话:截图/票据/合同/报错图,读懂并提取关键信息',
keywords: ['vision', 'screenshot', 'ocr', 'ai', '截图', '看图', '识别', '票据', '合同'],
component: () => import('./screenshot-qa.vue'),
icon: Eye,
});
-322
View File
@@ -1,322 +0,0 @@
<script setup lang="ts">
import { ref } from 'vue';
import { useHead } from '@vueuse/head';
import { getMachineId } from '@/tools/license/license';
import { useGenHistory } from '@/tools/gen-history/gen-history';
useHead({ title: '截图理解 - IT-TOOLS-PRO' });
const genHist = useGenHistory('screenshot-qa');
const QUESTIONS = [
'提取图片中的所有文字,结构化整理',
'图里写了什么关键信息?(金额/日期/编号)',
'这是什么报错?原因和解决办法是什么?',
'把表格内容转成 Markdown 表格',
'用三句话总结这张图的内容',
];
const srcUrl = ref('');
const file = ref<File | null>(null);
const question = ref(QUESTIONS[0]);
const output = ref('');
const busy = ref(false);
const error = ref('');
const fileInput = ref<HTMLInputElement>();
function pick() {
fileInput.value?.click();
}
function onInput(e: Event) {
const input = e.target as HTMLInputElement;
setFile(input.files?.[0] ?? null);
input.value = '';
}
function onDrop(e: DragEvent) {
setFile(e.dataTransfer?.files?.[0] ?? null);
}
function setFile(f: File | null) {
if (srcUrl.value) {
URL.revokeObjectURL(srcUrl.value);
}
file.value = f;
srcUrl.value = f ? URL.createObjectURL(f) : '';
output.value = '';
error.value = '';
}
async function ask() {
if (!file.value || busy.value) {
error.value = '请先上传截图/图片';
return;
}
busy.value = true;
error.value = '';
try {
const b64 = await new Promise<string>((resolve, reject) => {
const r = new FileReader();
r.onload = () => resolve(String(r.result).split(',')[1]);
r.onerror = () => reject(new Error('读取图片失败'));
r.readAsDataURL(file.value!);
});
const res = await fetch('/relay/ai/vision', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ machine: getMachineId(), image: b64, question: question.value }),
});
const j = await res.json().catch(() => ({}));
if (!res.ok || j.code !== 200) {
throw new Error(j.message || `HTTP ${res.status}`);
}
output.value = j.data.reply;
genHist.add({ title: `截图理解: ${question.value.slice(0, 16)}`, detail: file.value.name });
}
catch (e: any) {
error.value = String(e?.message || e);
}
finally {
busy.value = false;
}
}
async function copyOut() {
await navigator.clipboard.writeText(output.value);
}
</script>
<template>
<div class="sq-root">
<div class="sq-head">
<div>
<div class="sq-title">👁️ 截图理解 · AI 看图说话</div>
<div class="sq-sub">丢一张截图 / 票据 / 合同 / 报错图,AI 直接读懂并回答——金额日期编号原样保留</div>
</div>
</div>
<div class="sq-cols">
<div class="sq-left">
<input ref="fileInput" type="file" hidden accept="image/*" @change="onInput">
<div class="sq-drop" @click="pick" @dragover.prevent @drop.prevent="onDrop">
<template v-if="!file">
<div class="sq-drop-hint">📁 点击或拖入截图<br><span>PNG / JPG / WebP · ≤15MB</span></div>
</template>
<img v-else :src="srcUrl" class="sq-thumb" alt="preview">
</div>
<div class="sq-sec">问它什么</div>
<div class="sq-chips">
<button v-for="q in QUESTIONS" :key="q" class="sq-chip" :class="{ on: question === q }" @click="question = q">
{{ q.length > 16 ? q.slice(0, 16) + '…' : q }}
</button>
</div>
<textarea v-model="question" class="sq-input" rows="3" placeholder="或直接输入你的问题…" />
<button class="sq-go" :disabled="busy || !file" @click="ask()">
{{ busy ? '⏳ AI 正在看图…' : '👁️ 让 AI 看图回答' }}
</button>
<div v-if="error" class="sq-error">⚠️ {{ error }}</div>
</div>
<div class="sq-right">
<div class="sq-sec">
AI 回答
<button v-if="output" class="sq-mini" @click="copyOut()">📋 复制</button>
</div>
<div class="sq-out">
<pre v-if="output" class="sq-text">{{ output }}</pre>
<div v-else class="sq-empty">上传截图并提问,AI 的回答在这里</div>
</div>
<GenHistory tool="screenshot-qa" label="看图记录" class="mt-10px" />
</div>
</div>
</div>
</template>
<style lang="less" scoped>
.sq-root {
padding-bottom: 16px;
}
.sq-head {
margin-bottom: 14px;
.sq-title {
font-size: 17px;
font-weight: 800;
}
.sq-sub {
font-size: 12.5px;
opacity: 0.55;
margin-top: 3px;
}
}
.sq-cols {
display: flex;
gap: 14px;
align-items: flex-start;
}
.sq-left {
width: 400px;
flex-shrink: 0;
border: 1px solid rgba(128, 128, 128, 0.2);
border-radius: 12px;
padding: 14px;
}
.sq-right {
flex: 1;
min-width: 0;
border: 1px solid rgba(128, 128, 128, 0.2);
border-radius: 12px;
padding: 14px;
}
.sq-drop {
border: 1.5px dashed rgba(128, 128, 128, 0.4);
border-radius: 10px;
padding: 16px;
text-align: center;
cursor: pointer;
margin-bottom: 12px;
transition: border-color 0.15s;
&:hover {
border-color: #2563eb;
}
.sq-drop-hint {
font-size: 13.5px;
font-weight: 600;
line-height: 1.7;
span {
font-size: 11.5px;
font-weight: 400;
opacity: 0.5;
}
}
.sq-thumb {
max-width: 100%;
max-height: 260px;
border-radius: 8px;
}
}
.sq-sec {
font-size: 12.5px;
font-weight: 700;
opacity: 0.75;
margin: 8px 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.sq-chips {
display: flex;
gap: 6px;
flex-wrap: wrap;
margin-bottom: 8px;
}
.sq-chip {
border: 1px solid rgba(128, 128, 128, 0.3);
background: #fff;
border-radius: 999px;
padding: 4px 11px;
font-size: 11.5px;
cursor: pointer;
&.on {
background: rgba(37, 99, 235, 0.1);
border-color: #2563eb;
color: #2563eb;
font-weight: 700;
}
}
.sq-input {
width: 100%;
box-sizing: border-box;
resize: vertical;
border: 1px solid rgba(128, 128, 128, 0.35);
border-radius: 9px;
padding: 9px 11px;
font-size: 13px;
font-family: inherit;
outline: none;
&:focus {
border-color: #2563eb;
}
}
.sq-go {
width: 100%;
margin-top: 11px;
border: none;
background: #2563eb;
color: #fff;
border-radius: 9px;
padding: 11px;
font-size: 14px;
font-weight: 700;
cursor: pointer;
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
&:hover:not(:disabled) {
background: #1d4ed8;
}
}
.sq-error {
color: #d03050;
font-size: 12.5px;
margin-top: 9px;
}
.sq-mini {
border: 1px solid rgba(128, 128, 128, 0.3);
background: #fff;
border-radius: 6px;
padding: 3px 10px;
font-size: 11.5px;
cursor: pointer;
&:hover {
border-color: #18a058;
color: #18a058;
}
}
.sq-out {
min-height: 400px;
background: rgba(128, 128, 128, 0.05);
border-radius: 10px;
padding: 14px;
}
.sq-text {
margin: 0;
white-space: pre-wrap;
word-break: break-word;
font-family: inherit;
font-size: 13.5px;
line-height: 1.8;
}
.sq-empty {
font-size: 13px;
opacity: 0.45;
text-align: center;
padding: 70px 0;
}
</style>