refactor: 截图理解并入图片工具 — image-tools新增「AI看图理解」tab(5预设问题+自定义提问+结果面板), 移除独立/screenshot-qa入口, 授权与试用归入image-tools
This commit is contained in:
1 parent
5797fed492
commit
6bcdfebf04
7 files changed
+97
-339
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user