feat: 新增 AI 生图工具(文生图/图生图)
- 新工具 ai-gen: 文生图+图生图, 模型来自NEWAPI生图模型 - 模型下拉+胶囊/提示词+示例/宽高比网格/结果预览下载 - relay: /ai/image-models + /ai/gen-image + /ai/edit-image, 接入ai-gen授权 - 修复 edit-image 对 cgi.FieldStorage 真值判断崩溃(TypeError)→is None - 文生图可用(pollinations); 图生图需NEWAPI有可用i2i通道(当前dall-e/flux上游500) 验证: 文生图出图✓, 图生图上传+清晰错误提示✓ CHANGELOG记录
This commit is contained in:
1 parent
3c9932b7e4
commit
04131a6145
7 files changed
+701
-2
No files matched your search
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. See [standa
|
||||
|
||||
## Version 2026.10.12-it-tools-pro
|
||||
|
||||
### 🎨 新增 AI 生图(文生图 / 图生图)
|
||||
- 新工具「AI 生图」(ai-gen):文生图 + 图生图双模式,模型来自 NEWAPI 生图模型
|
||||
- 界面:模型下拉 + 快速模型胶囊、提示词输入(0/1000)、6 个示例一键填入、宽高比网格(默认/1:1/3:2/2:3/9:16/16:9/3:4/4:3/21:9/9:21)
|
||||
- 文生图选宽高比出图;图生图上传原图(JPG/PNG/WEBP ≤10MB)+提示词编辑
|
||||
- 右侧实时结果区:生成图预览 + 下载/新窗口打开;加载态、错误提示
|
||||
- relay 新增 `/ai/image-models`(模型列表)、`/ai/gen-image`(文生图)、`/ai/edit-image`(图生图 multipart),接入 ai-gen 授权(30 分钟试用)
|
||||
- ⚠️ 现状:文生图可用(pollinations 通道);图生图需 NEWAPI 有可用 i2i 通道(当前 dall-e-3/flux 上游返回 500),接口已就绪,通道修复即可用
|
||||
|
||||
|
||||
### 📄 文档翻译支持批量上传(最多 10 个)
|
||||
- 文档翻译可一次选择多个文件(`multiple`),单批上限 10 个(超出自动截断)
|
||||
- 文件列表逐个显示状态(待翻/翻译中/✅完成/❌失败)、字数统计、进度 `x/N`
|
||||
|
||||
Vendored
+1
@@ -13,6 +13,7 @@ declare module '@vue/runtime-core' {
|
||||
About: typeof import('./src/pages/About.vue')['default']
|
||||
'Admin.page': typeof import('./src/pages/Admin.page.vue')['default']
|
||||
AiChat: typeof import('./src/tools/ai-chat/ai-chat.vue')['default']
|
||||
AiGen: typeof import('./src/tools/ai-gen/ai-gen.vue')['default']
|
||||
AiImageLab: typeof import('./src/tools/ai-image-lab/ai-image-lab.vue')['default']
|
||||
AiRetouch: typeof import('./src/tools/ai-retouch/ai-retouch.vue')['default']
|
||||
App: typeof import('./src/App.vue')['default']
|
||||
|
||||
@@ -44,7 +44,7 @@ AUTH_PASS = os.environ.get("AUTH_PASS", "")
|
||||
PROJECT_NAME = os.environ.get("PROJECT_NAME", "IT-Tools")
|
||||
TRIAL_FILE = os.environ.get("TRIAL_FILE", "/app/data/trials.json")
|
||||
TRIAL_MS = int(os.environ.get("TRIAL_MS_MIN", "30")) * 60 * 1000
|
||||
PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "text-to-image", "ai-image-tools", "ai-chat", "copywriting", "screenshot-qa", "video-subtitle"}
|
||||
PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "text-to-image", "ai-image-tools", "ai-chat", "copywriting", "screenshot-qa", "video-subtitle", "ai-gen"}
|
||||
MACHINE_RE = re.compile(r"^\d{10,16}$")
|
||||
|
||||
# verify() messages that unconditionally block activation
|
||||
@@ -1472,6 +1472,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
parsed = parse.urlparse(self.path)
|
||||
if parsed.path == "/ai/image-models":
|
||||
self._handle_image_models()
|
||||
return
|
||||
if parsed.path == "/ai/models":
|
||||
self._handle_ai_models()
|
||||
return
|
||||
@@ -2232,6 +2235,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if parsed.path == "/ai/models":
|
||||
self._handle_ai_models()
|
||||
return
|
||||
if parsed.path == "/ai/gen-image":
|
||||
self._handle_gen_image()
|
||||
return
|
||||
if parsed.path == "/ai/edit-image":
|
||||
self._handle_edit_image()
|
||||
return
|
||||
if parsed.path == "/translate-doc":
|
||||
self._handle_translate_doc()
|
||||
return
|
||||
@@ -2309,6 +2318,121 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
self._reply(404, b"not found")
|
||||
|
||||
# ---------- AI 生图 (NEWAPI) ----------
|
||||
def _nm_base(self):
|
||||
return os.environ.get("NEWAPI_URL", "http://192.168.68.19:3099/v1/chat/completions").replace("/chat/completions", "")
|
||||
|
||||
def _nm_image_models(self):
|
||||
key = os.environ.get("NEWAPI_KEY", "")
|
||||
req = request.Request(self._nm_base() + "/models", headers={"Authorization": "Bearer " + key})
|
||||
d = json.loads(request.urlopen(req, timeout=30).read())
|
||||
names = [m.get("id", "") for m in d.get("data", [])]
|
||||
out = []
|
||||
for n in names:
|
||||
if n.startswith(("dall-e", "flux", "pollinations")):
|
||||
# pollinations 通道仅文生图;dall-e/flux 理论支持图生图(视上游通道)
|
||||
out.append({"id": n, "i2i": not n.startswith("pollinations")})
|
||||
return out
|
||||
|
||||
def _nm_images_gen(self, model, prompt, size):
|
||||
key = os.environ.get("NEWAPI_KEY", "")
|
||||
body = json.dumps({"model": model, "prompt": prompt, "n": 1, "size": size}).encode()
|
||||
req = request.Request(self._nm_base() + "/images/generations", data=body,
|
||||
headers={"Content-Type": "application/json", "Authorization": "Bearer " + key})
|
||||
d = json.loads(request.urlopen(req, timeout=150).read())
|
||||
if "error" in d:
|
||||
raise RuntimeError(d["error"].get("message", "upstream error"))
|
||||
return d
|
||||
|
||||
def _nm_images_edit(self, model, prompt, img_bytes, filename):
|
||||
key = os.environ.get("NEWAPI_KEY", "")
|
||||
boundary = "----nm" + secrets.token_hex(8)
|
||||
parts = []
|
||||
|
||||
def fld(name, val):
|
||||
parts.append(f"--{boundary}\r\nContent-Disposition: form-data; name=\"{name}\"\r\n\r\n{val}\r\n".encode())
|
||||
fld("model", model)
|
||||
fld("prompt", prompt)
|
||||
parts.append(f"--{boundary}\r\nContent-Disposition: form-data; name=\"image\"; filename=\"{filename}\"\r\nContent-Type: application/octet-stream\r\n\r\n".encode())
|
||||
parts.append(img_bytes)
|
||||
parts.append(b"\r\n")
|
||||
parts.append(f"--{boundary}--\r\n".encode())
|
||||
req = request.Request(self._nm_base() + "/images/edits", data=b"".join(parts),
|
||||
headers={"Content-Type": f"multipart/form-data; boundary={boundary}", "Authorization": "Bearer " + key})
|
||||
d = json.loads(request.urlopen(req, timeout=150).read())
|
||||
if "error" in d:
|
||||
raise RuntimeError(d["error"].get("message", "upstream error"))
|
||||
return d
|
||||
|
||||
def _img_reply_ok(self, d):
|
||||
item = (d.get("data") or [{}])[0]
|
||||
url = item.get("url") or ""
|
||||
b64 = item.get("b64_json") or ""
|
||||
if not url and not b64:
|
||||
raise RuntimeError("上游未返回图片")
|
||||
self._reply(200, json.dumps({"code": 200, "message": "ok", "data": {"url": url, "b64": b64}}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
def _handle_image_models(self):
|
||||
try:
|
||||
models = self._nm_image_models()
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f"[img] models failed: {e}", flush=True)
|
||||
models = []
|
||||
self._reply(200, json.dumps({"code": 200, "message": "ok", "data": models}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
def _handle_gen_image(self):
|
||||
payload = self._read_payload()
|
||||
machine = str(payload.get("machine") or "")
|
||||
if check(machine, "ai-gen") != 200:
|
||||
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
prompt = str(payload.get("prompt") or "").strip()[:2000]
|
||||
if not prompt:
|
||||
self._reply(400, json.dumps({"code": 400, "message": "请输入提示词"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
model = str(payload.get("model") or "pollinations-flux")[:60]
|
||||
try:
|
||||
w = int(payload.get("width") or 1024)
|
||||
h = int(payload.get("height") or 1024)
|
||||
except Exception:
|
||||
w, h = 1024, 1024
|
||||
w = max(16, min(2048, w))
|
||||
h = max(16, min(2048, h))
|
||||
try:
|
||||
d = self._nm_images_gen(model, prompt, f"{w}x{h}")
|
||||
self._img_reply_ok(d)
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f"[img] gen failed: {e}", flush=True)
|
||||
self._reply(502, json.dumps({"code": 502, "message": f"生图失败:{e}"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
def _handle_edit_image(self):
|
||||
machine = self.headers.get("X-Machine-Id", "")
|
||||
if check(machine, "ai-gen") != 200:
|
||||
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
ctype = self.headers.get("Content-Type", "")
|
||||
if "multipart/form-data" not in ctype:
|
||||
self._reply(400, json.dumps({"code": 400, "message": "需要 multipart 上传"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
form = cgi.FieldStorage(fp=self.rfile, headers=self.headers, environ={"REQUEST_METHOD": "POST", "CONTENT_TYPE": ctype})
|
||||
prompt = str(form.getvalue("prompt") or "").strip()[:2000]
|
||||
model = str(form.getvalue("model") or "dall-e-3")[:60]
|
||||
if not prompt:
|
||||
self._reply(400, json.dumps({"code": 400, "message": "请输入提示词"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
up = form["image"] if "image" in form else None
|
||||
# 注意:cgi.FieldStorage 禁止真值判断(bool 会抛 TypeError),用 is None 判空
|
||||
if up is None or not getattr(up, "filename", None):
|
||||
self._reply(400, json.dumps({"code": 400, "message": "请上传图片"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
try:
|
||||
img = up.file.read()
|
||||
d = self._nm_images_edit(model, prompt, img, up.filename)
|
||||
self._img_reply_ok(d)
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f"[img] edit failed: {e}", flush=True)
|
||||
self._reply(502, json.dumps({"code": 502, "message": f"图生图失败:{e}"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
# ---------- conversion ----------
|
||||
def _handle_convert(self):
|
||||
try:
|
||||
|
||||
@@ -0,0 +1,552 @@
|
||||
<script setup lang="ts">
|
||||
import { getMachineId, licenseHeaders } from '@/tools/license/license';
|
||||
|
||||
type Mode = 'txt' | 'img';
|
||||
|
||||
const mode = ref<Mode>('txt');
|
||||
const models = ref<{ id: string; i2i: boolean }[]>([]);
|
||||
const model = ref('pollinations-flux');
|
||||
const prompt = ref('');
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const resultUrl = ref('');
|
||||
|
||||
// 图生图:源图(dataURL)
|
||||
const srcData = ref('');
|
||||
const srcInput = ref<HTMLInputElement>();
|
||||
|
||||
// 宽高比
|
||||
type Ratio = { label: string; w: number; h: number; sw: number; sh: number };
|
||||
const RATIOS: Ratio[] = [
|
||||
{ label: '默认', w: 1024, h: 1024, sw: 26, sh: 26 },
|
||||
{ label: '1:1', w: 1024, h: 1024, sw: 26, sh: 26 },
|
||||
{ label: '3:2', w: 1152, h: 768, sw: 30, sh: 20 },
|
||||
{ label: '2:3', w: 768, h: 1152, sw: 20, sh: 30 },
|
||||
{ label: '9:16', w: 720, h: 1280, sw: 15, sh: 27 },
|
||||
{ label: '16:9', w: 1280, h: 720, sw: 30, sh: 17 },
|
||||
{ label: '3:4', w: 768, h: 1024, sw: 21, sh: 28 },
|
||||
{ label: '4:3', w: 1024, h: 768, sw: 28, sh: 21 },
|
||||
{ label: '21:9', w: 1344, h: 576, sw: 32, sh: 14 },
|
||||
{ label: '9:21', w: 576, h: 1344, sw: 14, sh: 32 },
|
||||
];
|
||||
const ratio = ref('默认');
|
||||
const ratioObj = computed(() => RATIOS.find(r => r.label === ratio.value) || RATIOS[0]);
|
||||
|
||||
// 示例提示词
|
||||
const EXAMPLES = [
|
||||
{ n: '电影感人像', p: '电影感人像,柔和侧光,浅景深,35mm 胶片质感,戏剧性光影,细节丰富' },
|
||||
{ n: '奇幻风景', p: '奇幻风景,漂浮的岛屿与瀑布,魔幻光线,超广角,史诗感,细节丰富' },
|
||||
{ n: '赛博朋克城市', p: '赛博朋克城市夜景,霓虹灯,雨后街道反光,未来感,高细节' },
|
||||
{ n: '动漫角色', p: '动漫角色立绘,大眼睛,鲜艳色彩,干净线条,动漫风格,白底' },
|
||||
{ n: '产品摄影', p: '产品摄影,纯白背景,柔和打光,高清晰度,商业级,居中构图' },
|
||||
{ n: '油画风格', p: '油画风格,厚涂笔触,丰富色彩,印象派,艺术感,画布质感' },
|
||||
];
|
||||
|
||||
const currentModel = computed(() => models.value.find(m => m.id === model.value));
|
||||
const canGen = computed(() => {
|
||||
if (!prompt.value.trim()) return false;
|
||||
if (mode.value === 'img' && !srcData.value) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await fetch('/relay/ai/image-models');
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && Array.isArray(j.data) && j.data.length) {
|
||||
models.value = j.data;
|
||||
if (!j.data.some((m: any) => m.id === model.value)) {
|
||||
// 默认选一个 pollinations(稳定可用)
|
||||
const p = j.data.find((m: any) => m.id.startsWith('pollinations'));
|
||||
model.value = (p || j.data[0]).id;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { /* 模型列表加载失败则用默认 */ }
|
||||
});
|
||||
|
||||
function pickSrc() {
|
||||
srcInput.value?.click();
|
||||
}
|
||||
|
||||
function onSrc(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
const f = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!f) return;
|
||||
if (f.size > 10 * 1024 * 1024) {
|
||||
error.value = '图片超过 10MB,请压缩后再上传';
|
||||
return;
|
||||
}
|
||||
const rd = new FileReader();
|
||||
rd.onload = () => {
|
||||
srcData.value = String(rd.result || '');
|
||||
};
|
||||
rd.readAsDataURL(f);
|
||||
}
|
||||
|
||||
function b64DataUrl(b64: string) {
|
||||
let mime = 'image/png';
|
||||
if (b64.startsWith('/9j/')) mime = 'image/jpeg';
|
||||
else if (b64.startsWith('UklGR')) mime = 'image/webp';
|
||||
return `data:${mime};base64,${b64}`;
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
if (loading.value || !canGen.value) return;
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
resultUrl.value = '';
|
||||
try {
|
||||
if (mode.value === 'txt') {
|
||||
const r = ratioObj.value;
|
||||
const res = await fetch('/relay/ai/gen-image', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders('ai-gen') },
|
||||
body: JSON.stringify({
|
||||
machine: getMachineId(),
|
||||
prompt: prompt.value.trim(),
|
||||
model: model.value,
|
||||
width: r.w,
|
||||
height: r.h,
|
||||
}),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`);
|
||||
resultUrl.value = j.data.b64 ? b64DataUrl(j.data.b64) : j.data.url;
|
||||
}
|
||||
else {
|
||||
const blob = await (await fetch(srcData.value)).blob();
|
||||
const fd = new FormData();
|
||||
fd.append('image', blob, 'src.png');
|
||||
fd.append('prompt', prompt.value.trim());
|
||||
fd.append('model', model.value);
|
||||
const res = await fetch('/relay/ai/edit-image', {
|
||||
method: 'POST',
|
||||
headers: licenseHeaders('ai-gen'),
|
||||
body: fd,
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`);
|
||||
resultUrl.value = j.data.b64 ? b64DataUrl(j.data.b64) : j.data.url;
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="gen-root">
|
||||
<!-- 模式切换 -->
|
||||
<div class="gen-modes">
|
||||
<button class="gen-mode" :class="{ on: mode === 'txt' }" @click="mode = 'txt'">✏️ 文生图</button>
|
||||
<button class="gen-mode" :class="{ on: mode === 'img' }" @click="mode = 'img'">🖼️ 图生图</button>
|
||||
</div>
|
||||
|
||||
<div class="gen-body">
|
||||
<!-- 左侧控制 -->
|
||||
<div class="gen-ctrl">
|
||||
<!-- 模型 -->
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">模型</div>
|
||||
<select v-model="model" class="gen-model-sel">
|
||||
<option v-for="m in models" :key="m.id" :value="m.id">
|
||||
{{ m.id }}{{ m.i2i ? '' : ' · 仅文生图' }}
|
||||
</option>
|
||||
<option v-if="!models.length" value="pollinations-flux">pollinations-flux</option>
|
||||
</select>
|
||||
<div class="gen-pills">
|
||||
<button
|
||||
v-for="m in models"
|
||||
:key="m.id"
|
||||
class="gen-pill"
|
||||
:class="{ on: model === m.id }"
|
||||
:title="m.i2i ? '支持图生图' : '仅文生图'"
|
||||
@click="model = m.id"
|
||||
>
|
||||
{{ m.id }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 图生图:源图上传 -->
|
||||
<div v-if="mode === 'img'" class="gen-sec">
|
||||
<div class="gen-h">原图</div>
|
||||
<input ref="srcInput" type="file" hidden accept="image/*" @change="onSrc">
|
||||
<div class="gen-upload" @click="pickSrc">
|
||||
<template v-if="!srcData">
|
||||
📁 点击上传图片<br><span>JPG / PNG / WEBP · ≤10MB</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<img class="gen-thumb" :src="srcData" alt="">
|
||||
<a href="javascript:;" class="gen-clear" @click.stop="srcData = ''">✕</a>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示词 -->
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">提示词</div>
|
||||
<textarea
|
||||
v-model="prompt"
|
||||
class="gen-prompt"
|
||||
maxlength="1000"
|
||||
placeholder="描述你想生成的图像,例如:将背景更改为蓝天 / 一只戴帽子的柴犬,卡通风格"
|
||||
/>
|
||||
<div class="gen-count">{{ prompt.length }}/1000</div>
|
||||
</div>
|
||||
|
||||
<!-- 示例 -->
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">尝试这些示例</div>
|
||||
<div class="gen-examples">
|
||||
<button v-for="ex in EXAMPLES" :key="ex.n" class="gen-example" @click="prompt = ex.p">{{ ex.n }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 宽高比(仅文生图) -->
|
||||
<div v-if="mode === 'txt'" class="gen-sec">
|
||||
<div class="gen-h">宽高比</div>
|
||||
<div class="gen-ratios">
|
||||
<button
|
||||
v-for="r in RATIOS"
|
||||
:key="r.label"
|
||||
class="gen-ratio"
|
||||
:class="{ on: ratio === r.label }"
|
||||
@click="ratio = r.label"
|
||||
>
|
||||
<span class="gen-rshape" :style="{ width: r.sw + 'px', height: r.sh + 'px' }" />
|
||||
<span class="gen-rl">{{ r.label }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="gen-go" :disabled="loading || !canGen" @click="generate()">
|
||||
{{ loading ? '⏳ 生成中…' : '🎨 生成图片' }}
|
||||
</button>
|
||||
<div v-if="error" class="gen-err">⚠️ {{ error }}</div>
|
||||
<div v-if="mode === 'img' && !currentModel?.i2i && models.length" class="gen-hint">
|
||||
提示:当前模型偏文生图,图生图建议选 dall-e / flux 系列。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧结果 -->
|
||||
<div class="gen-result">
|
||||
<div v-if="resultUrl" class="gen-img-box">
|
||||
<img :src="resultUrl" alt="生成结果">
|
||||
<div class="gen-img-acts">
|
||||
<a class="gen-dl" :href="resultUrl" target="_blank" rel="noopener" download>⬇ 下载图片</a>
|
||||
<a class="gen-dl" :href="resultUrl" target="_blank" rel="noopener">🔗 新窗口打开</a>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="loading" class="gen-empty">
|
||||
<n-spin size="large" />
|
||||
<p>AI 正在生成图片,请稍候…</p>
|
||||
</div>
|
||||
<div v-else class="gen-empty">生成的图片会显示在这里</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.gen-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.gen-modes {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
.gen-mode {
|
||||
padding: 8px 18px;
|
||||
border-radius: 9px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
background: #fff;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&.on {
|
||||
background: #0ea5a0;
|
||||
border-color: #0ea5a0;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gen-body {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-ctrl {
|
||||
width: 380px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-sec {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
.gen-h {
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.gen-model-sel {
|
||||
padding: 8px 10px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
background: #fff;
|
||||
outline: none;
|
||||
|
||||
&:focus {
|
||||
border-color: #0ea5a0;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-pills {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
|
||||
.gen-pill {
|
||||
padding: 5px 10px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.28);
|
||||
background: rgba(128, 128, 128, 0.05);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&.on {
|
||||
background: rgba(14, 165, 160, 0.15);
|
||||
border-color: #0ea5a0;
|
||||
color: #0e8b87;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gen-upload {
|
||||
position: relative;
|
||||
border: 2px dashed rgba(14, 165, 160, 0.5);
|
||||
border-radius: 10px;
|
||||
padding: 18px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
color: #0e8b87;
|
||||
background: rgba(14, 165, 160, 0.04);
|
||||
overflow: hidden;
|
||||
|
||||
span {
|
||||
display: block;
|
||||
font-size: 11.5px;
|
||||
opacity: 0.6;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.gen-thumb {
|
||||
max-width: 100%;
|
||||
max-height: 180px;
|
||||
border-radius: 8px;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.gen-clear {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 8px;
|
||||
color: #d03050;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-prompt {
|
||||
width: 100%;
|
||||
min-height: 96px;
|
||||
resize: vertical;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 9px;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
font-family: inherit;
|
||||
|
||||
&:focus {
|
||||
border-color: #0ea5a0;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-count {
|
||||
text-align: right;
|
||||
font-size: 11.5px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.gen-examples {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
|
||||
.gen-example {
|
||||
padding: 6px 12px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.28);
|
||||
background: #fff;
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: #0ea5a0;
|
||||
color: #0e8b87;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gen-ratios {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 7px;
|
||||
|
||||
.gen-ratio {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 9px 4px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.28);
|
||||
border-radius: 9px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&.on {
|
||||
background: rgba(14, 165, 160, 0.12);
|
||||
border-color: #0ea5a0;
|
||||
}
|
||||
|
||||
.gen-rshape {
|
||||
background: #0ea5a0;
|
||||
border-radius: 3px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.gen-rl {
|
||||
font-size: 11px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gen-go {
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(48deg, #0e9384, #14b8a6);
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s;
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-err {
|
||||
font-size: 12.5px;
|
||||
color: #d03050;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.gen-hint {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.gen-result {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 420px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
background: rgba(128, 128, 128, 0.04);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.gen-img-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
max-width: 100%;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 60vh;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.gen-img-acts {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.gen-dl {
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
background: rgba(14, 165, 160, 0.12);
|
||||
color: #0e8b87;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.gen-empty {
|
||||
text-align: center;
|
||||
opacity: 0.5;
|
||||
font-size: 13.5px;
|
||||
|
||||
p {
|
||||
margin-top: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Photo } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'AI 生图',
|
||||
path: '/ai-gen',
|
||||
description: 'AI 文生图与图生图:多模型选择、宽高比、示例提示词,一键生成图片',
|
||||
keywords: ['ai', 'image', 'generate', '生图', '文生图', '图生图', 'ai绘画', 'ai图片', '生成图片', '绘图'],
|
||||
component: () => import('./ai-gen.vue'),
|
||||
icon: Photo,
|
||||
});
|
||||
+2
-1
@@ -86,6 +86,7 @@ import { tool as audioTools } from './audio-tools';
|
||||
import { tool as sealMaker } from './seal-maker';
|
||||
import { tool as signaturePad } from './signature-pad';
|
||||
import { tool as textToImage } from './text-to-image';
|
||||
import { tool as aiGen } from './ai-gen';
|
||||
import { tool as zhConvert } from './zh-convert';
|
||||
import { tool as pinyinConverter } from './pinyin-converter';
|
||||
import { tool as aiImageLab } from './ai-image-lab';
|
||||
@@ -162,7 +163,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Images and videos',
|
||||
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, videoTools, audioTools, sealMaker, signaturePad, textToImage, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
|
||||
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, videoTools, audioTools, sealMaker, signaturePad, textToImage, aiGen, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
|
||||
},
|
||||
{
|
||||
name: 'Development',
|
||||
|
||||
@@ -20,6 +20,7 @@ export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
'/ai-image-lab': 'AI图片实验室',
|
||||
'/ai-chat': 'AI问答',
|
||||
'/copywriting': '文案工具箱',
|
||||
'/ai-gen': 'AI 生图',
|
||||
};
|
||||
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能免费 30 分钟
|
||||
|
||||
Reference in new issue
Block a user