Compare commits
61
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c126277eb | ||
|
|
225aa5ed68 | ||
|
|
846b161aa3 | ||
|
|
931c0b5673 | ||
|
|
6463aa81d8 | ||
|
|
67c320a2de | ||
|
|
afe73922cc | ||
|
|
d4ecefe313 | ||
|
|
65a125adfa | ||
|
|
75acc958be | ||
|
|
c78f322521 | ||
|
|
14bc300146 | ||
|
|
42155edf34 | ||
|
|
e2e36bac05 | ||
|
|
ac91ac468a | ||
|
|
45f2f117dd | ||
|
|
b819713ef9 | ||
|
|
136d1e9010 | ||
|
|
eefdc07786 | ||
|
|
b4e5d6ac6d | ||
|
|
6557d1fe7b | ||
|
|
4016d754df | ||
|
|
88a6823963 | ||
|
|
7d28d31c75 | ||
|
|
003f98e388 | ||
|
|
66c3fede6b | ||
|
|
94ccaf2c0f | ||
|
|
c75f2882f7 | ||
|
|
855378df2c | ||
|
|
c6341ea35b | ||
|
|
cd4b324740 | ||
|
|
15d21235cd | ||
|
|
55b1111d96 | ||
|
|
9d75776d52 | ||
|
|
f420785887 | ||
|
|
7b22e53d1a | ||
|
|
ea4e3deb50 | ||
|
|
b4c4f5de8a | ||
|
|
39ec9347e2 | ||
|
|
7992c83421 | ||
|
|
e48d165741 | ||
|
|
f73d7247bb | ||
|
|
f6ef20eef3 | ||
|
|
fdcd1f8de8 | ||
|
|
f4f1b373de | ||
|
|
aea420df79 | ||
|
|
458b508d7e | ||
|
|
7f915b07ec | ||
|
|
07ba0b3f24 | ||
|
|
704fabb9cb | ||
|
|
4410d6f055 | ||
|
|
a12886ea90 | ||
|
|
c54799fd89 | ||
|
|
e65eb89fa9 | ||
|
|
263d52475f | ||
|
|
d9d306956d | ||
|
|
72e06b24fe | ||
|
|
83d98a348e | ||
|
|
41f7f0671c | ||
|
|
a0b63f9a18 | ||
|
|
c7586f9c63 |
No files matched your search
+6
-1
@@ -28,8 +28,13 @@ coverage
|
||||
*.sw?
|
||||
|
||||
.env
|
||||
|
||||
# 本地 AI 换脸模型(宿主预置, 不入库: buffalo_l ~289MB + inswapper_128 ~554MB)
|
||||
docker/it-tools-relay/face-models/
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
||||
# Webkit with playwright creates a salt file
|
||||
salt
|
||||
salt
|
||||
# 本地离线构建用(基于已有镜像,非仓库产物)
|
||||
Dockerfile.offline
|
||||
+199
@@ -2,6 +2,205 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## Version 2026.11.12-it-tools-pro
|
||||
|
||||
### 📦 本次更新(2026-11-12)
|
||||
- **使用统计纳入未登录访客(本次核心)**:任意工具页打开即自动上报一次使用(路由全局钩子,浏览器 beacon),**未登录、未绑定机器码的访客同样计数**——原先只有走中转接口的在线翻译/图片工具等少数功能会被统计,现在全部工具的使用都会进入管理后台「使用统计」
|
||||
- **防刷三层保障**:前端同一工具 10 分钟内只上报一次(localStorage 去重)、relay 服务端同机同工具 10 分钟去重、每 IP 10 分钟上限 300 条 + tool 名格式校验,刷新页面/恶意刷接口都不会灌水
|
||||
- **管理后台展示升级**:总使用次数后新增「其中未登录 N 次」;「用户活跃排行」新增**未登录访客**行(按次数参与排序,访客使用一目了然);「功能使用排行」的工具名自动回退查工具目录显示正式名称(不再显示英文路径代号)
|
||||
|
||||
## Version 2026.11.11-it-tools-pro
|
||||
|
||||
### 📦 本次更新(2026-11-11)
|
||||
- **站内支付页 `/buy`(本次核心)**:新增独立支付页——自动读取本机机器码,直接列出本项目可购套餐(名称/价格/时长)、支持支付宝 / 微信支付 / QQ 钱包三种方式、优惠码选填;点击「立即支付」拉起收银台(新标签打开,本页留守轮询),**支付成功当场显示卡密**并自动核验授权,13 个高级功能立即解锁,全程无需人工发货、无需跳出本站
|
||||
- **购买入口全部改指 `/buy`**:顶栏浮条「永久解锁 13 个功能」、试用用尽锁定弹窗的「购买授权」、授权应用页的「💳 前往购买卡密」,三处统一跳转站内支付页(原先跳外部 `auth.88531.cn/#/shop`);页面未登录即可访问,支付状态本机留存,刷新/误关后自动恢复轮询
|
||||
- **CardAuth 后端补发卡**:订单支付完成时同步签发一张卡密并写回订单(原先「带机器码下单」只创建授权、不发卡,导致订单查不到卡密、支付结果页无卡可显示);优先取卡池未用卡,卡池不足自动新建,并绑定下单机器码
|
||||
- **页脚开源地址**:全站页脚新增「🐙 开源 gitea.88531.cn」链接,指向本项目 Gitea 仓库(`https://gitea.88531.cn/jinghui/it-tools-pro`,新标签打开、悬停显示完整地址);页脚改为放不下时自动换行,窄屏也不产生横向溢出
|
||||
|
||||
## Version 2026.11.01-it-tools-pro
|
||||
|
||||
### 📦 本次更新(2026-11-01)
|
||||
- **顶栏排版修复**:「⚡ IPv6 直连」按钮改为顶栏内正常排列(不再绝对定位悬浮),与「授权应用」等控件不重叠;窄屏(≤900px)自动收缩为纯图标并收紧间距,任何窗口宽度都不溢出、不遮挡
|
||||
- **热门地点扩容 + 测速历史快照**:热门地点延迟新增「百度」与「本省·运营商门户」(按你的 IPv4 归属自动匹配联通 10010 / 电信 189 / 移动 10086 / 广电 10099,悬停显示完整运营商与省份,未知运营商不插行);测速历史表新增「热门地点延迟快照」列——每次测速自动附带当时全部地点延迟(百度/本省运营商/镜像站/海外),跨线路、跨时间直接对照
|
||||
- **代理 / VPN 检测**(免费不授权):本机IP查询页新增检测区——出口 IP 归属判定(proxycheck.io 数据库,区分家庭宽带/VPN/代理/数据中心/企业网络,IPv4+IPv6 分别判定)+ WebRTC STUN 泄漏实测(浏览器实测公网候选地址,若与主 IP 不一致则提示可能的真实出口,另显示本机内网 IP);浏览器无法直读系统代理开关,判定仅供参考,可一键重新检测
|
||||
- **本机IP查询**(`/my-ip`,免费不授权):打开即显示**用户自己设备**的公网 IPv4 / IPv6 地址与中文归属地(多源容错、一键复制、不显示任何服务器信息);自动测量到 9 个热门地点(本站/清华TUNA/阿里云/腾讯云/华为云/中科大/香港Fedora/日本JAIST/Cloudflare)的延迟
|
||||
- **IPv6 直连通道**:新增 `itv6.88531.cn`(4443 端口,双栈 nginx + DDNS);支持 IPv6 的用户页面横幅一键切换直连,访问速度更快;不支持的用户给出五步开启教程
|
||||
- **网速测试**:测量**你到本站服务器**的真实吞吐(下载/上传/到站延迟),走当前访问线路,浏览器真实收发计时(relay 新增 `/relay/speed` 端点),约 13MB 流量
|
||||
- **测速历史记录**:每次测速自动记录时间/线路(公网中转 vs IPv6 直连)/下载/上传/延迟,存本机浏览器最多 20 条、可清空——切换线路前后各测一次即可直接对比两条线路差距
|
||||
- **文档翻译支持扫描件/图片**:扫描版 PDF、截图、照片自动 OCR 识别后整篇翻译,标注「已OCR识别 N 页」
|
||||
- **翻译切换本地引擎(LibreTranslate)**:中英翻译走本机 Docker 引擎,稳定不限流、不耗 AI 额度,告别 429 报错
|
||||
- **缓存修复**:`index.html`/`sw.js` 强制 `no-cache, must-revalidate`、内容哈希资源 `immutable` 长缓存——部署后用户无需强刷即见新版
|
||||
|
||||
### 🏠 站点功能总览(10 大分类 · 110+ 工具)
|
||||
|
||||
**AI 智能(本站核心,本地算力驱动)**
|
||||
- AI 图片实验室:本地模型智能抠图去背景、AI 无损放大变清晰(2x/4x + 5 档降噪)、一键证件照(一寸/二寸/护照,白红蓝底)
|
||||
- AI 修图:涂抹去水印/智能修复、抠图去背景、4x 超分辨率、人脸修复,10 秒级出图
|
||||
- AI 生图:文生图创作
|
||||
- AI 看图(截图理解):截图/票据/合同/报错图丢进去,多模态 AI 读懂并提取关键信息,金额日期编号原样保留
|
||||
- 在线翻译:16 种语言互译,中英走本地引擎不限流;Word/PDF/TXT 整篇文档翻译,扫描件/图片自动 OCR
|
||||
- 文案工具箱:一键改写、降 AIGC 率、爆款标题、小红书文案、朋友圈文案
|
||||
- AI 客服:只答本站功能相关问题(全站工具清单加持,越界自动拒绝),多会话、登录后云端同步
|
||||
- 视频字幕 AI:Whisper 本地转录生成 SRT、AI 一键翻译英日文
|
||||
- 音频工具:文字转音频(本地神经音色)、音频转文字(中英日粤自动检测)
|
||||
- 每日资讯 5 列:GitHub 热榜/国际新闻/AI 资讯/IT 技术/AI 最热股票,每天 08:00 自动更新;AI 股票交易时段 60 秒实时刷新,支持自选股云端同步
|
||||
- 每个工具页左上角「🤖 问AI」:弹窗即看该工具用法与亮点,无需翻文档
|
||||
|
||||
**深度改造的原版工具(比上游更强)**
|
||||
- PDF 工具:合并/拆分/旋转/重排/压缩/加密/解密/水印/提取文本/页码/转图片,11 功能全程浏览器本地处理
|
||||
- 图片工具:压缩/转换/裁剪/旋转/滤镜/打码 + PS 风格编辑器(图层+画笔+选区+历史记录+OCR 改字+文字模板)
|
||||
- 视频工具:格式转换/压缩/裁剪/旋转/变速/消音/提取音频/截图/GIF 互转/加去水印等 13 项
|
||||
- 二维码条码:识别(本地 WASM 不上传,多码批量)+ 生成(自定义颜色、中间插 Logo)+ 批量条码(12 种码制、打包下载)
|
||||
- 图片 OCR / PDF 文字识别:本地引擎,准确率 99%+,逐页识别导出 TXT
|
||||
- 面单设计:20 个快递面单模板(顺丰/中通/圆通/韵达/申通/京东/邮政/极兔/德邦/国际)
|
||||
- 文档格式转换:Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九格式互转
|
||||
- 印章生成器(mm 标尺画布)、多图拼接(6 种方式)、JSON 双栏工作台、Base64 图片互转、IT 网站收藏(91 个精选站点)
|
||||
|
||||
**网络与开发**
|
||||
- 本机IP查询、IPv4 子网/地址/范围计算、MAC 查询生成、IPv6 ULA、IP 子网掩码
|
||||
- 开发工具 14 项(git 备忘/crontab/JSON/Docker 转换/正则…)、密码学 11 项(Hash/Bcrypt/RSA/HMAC/BIP39…)、转换器 20 项、文本 13 项等
|
||||
|
||||
**账户与授权**
|
||||
- 用户中心:收藏/最近使用/生成记录(翻译/OCR/修图/条码等 9 工具留痕)/AI 对话/自选股全部云端同步,换电脑登录即恢复
|
||||
- 卡密授权:高级功能**每天免费试用 30 分钟**(每天 0 点重置),卡密激活全站通用,支持换卡密/自助撤销
|
||||
- 管理后台:首页推荐配置、用户管理、文件管理、使用统计
|
||||
|
||||
👉 体验地址:https://it.88531.cn
|
||||
|
||||
## Version 2026.10.30-it-tools-pro
|
||||
|
||||
### ✨ 新功能
|
||||
- **测速历史记录(多线路对比)**:每次测速完成自动记录时间、所走线路(公网中转/IPv6 直连)、下载/上传速度与到站延迟,以表格展示在测速卡片下方(仅存本机浏览器 localStorage,最多 20 条,可一键清空);切换 IPv6 直连前后各测一次即可直接对照两条线路差距
|
||||
- **文档翻译支持扫描件/图片自动 OCR**:非纯文字文档(扫描版 PDF、截图、照片、带文字图片)先自动 OCR 识别文字再整篇翻译,扫描版 PDF 逐页渲染识别(单文档最多 30 页),图片可直接上传翻译;结果标注「已OCR识别 N 页」,页面附处理说明
|
||||
- **修复「改版后用户看到旧页面」缓存问题**:nginx 对 `index.html`/`sw.js`/`manifest` 强制 `Cache-Control: no-cache, must-revalidate`(每次重新校验,杜绝 PWA 预缓存赖旧),对内容哈希静态资源 `immutable` 长缓存(加载更快),部署后无需用户强刷即见新版
|
||||
- **新增「本机IP查询」**(`/my-ip`,Network 分组,免费不授权):仅显示**用户端**公网 IPv4/IPv6 地址与所属地(多源容错、中文归属地、一键复制),不显示服务器地址;IPv6 不支持时明示「不支持 IPv6」并给出五步开启教程
|
||||
- **本站 IPv6 直连(速度更快)**:新增 `itv6.88531.cn`(AAAA→本机移动原生 v6,4443 防封端口 + 443,宝塔 nginx 双栈 + acme 证书 + DDNS 覆盖);页面顶部横幅「本站已支持 IPv6 访问,速度更快」,支持 IPv6 的用户一键切换直连
|
||||
- **连接热门地点延迟**:进入页面自动测量到 9 个热门地点(本站/清华 TUNA/阿里云/腾讯云/华为云/中科大/香港 Fedora/日本 JAIST/Cloudflare)的网络延迟,支持一键重新测速
|
||||
- **网速测试改测「你的设备 ↔ 本站服务器」**:relay 新增 `/relay/speed` 端点(GET 吐数据测下载、POST 收数据测上传),浏览器真实收发计时,测的是用户到本站服务器的实际吞吐(含到本站延迟),走当前访问线路(公网中转或 IPv6 直连,切换后可对比),约消耗 13MB 流量
|
||||
|
||||
### 🔧 优化
|
||||
- **文档翻译切换本地开源引擎(LibreTranslate)**:此前走 NewAPI LLM 被上游限流报 429「Too Many Requests」;现与文本翻译同用本机 Docker 引擎,不限流、不耗 AI 额度;目标语种支持中文/英文,其他语种给出明确提示(不再静默失败)
|
||||
|
||||
## Version 2026.10.16-it-tools-pro
|
||||
|
||||
### ✨ 二维码条码识别 → 新增「生成」页签(识别/生成一页双能力)
|
||||
- **二维码生成**:内容输入实时生成(网址/文本/名片),尺寸 256/512/1024/2048px,实时防抖渲染
|
||||
- **改颜色**:前景色/背景色取色器 + 各 6 个快捷色票,任意搭配
|
||||
- **中心本地图片(Logo)**:选择本地图插入二维码中心,大小 10%~35% 滑杆可调,自动切换 H 级纠错(容错 ~30%)+ 按背景色圆角白垫保可扫;文件全程浏览器本地处理
|
||||
- **自动自扫验证**:每次生成后用本页 ZXing 立即回扫一次,显示「✓ 可正常扫出(QR_CODE)· 与输入内容一致」或对比度/Logo 过大提示,生成即自证
|
||||
- 页面顶部「📷 识别 / 🧩 生成」Tab 切换;code-reader 加入 WIDE_TOOLS 宽屏;窗口加入「生成」关键词
|
||||
- 同步:zh/en 描述、About「二维码条码识别与生成」条目、首页近期新功能条目
|
||||
|
||||
### 🆕 首页「近期新功能」与「新功能介绍」页补录近期新功能
|
||||
- 首页 NEW_FEATURES 手动清单(注释约定"新工具上线时加一条")漏加近期工具,补 2 条置顶:**Base64图片互转**、**图片编辑·无痕改字**(PS式图层画笔选区+OCR自动匹配字号颜色角度无缝改字)
|
||||
- 新功能介绍页(About)「原创工具」组补 **Base64图片互转** 条目;「图片工具」条目原已覆盖 OCR 改字无需重复
|
||||
- 教训:新工具上线 checklist = 工具注册 + i18n + About + 首页 NEW_FEATURES + relay 推荐种子(可选),四页同步缺一不可
|
||||
|
||||
### ✨ 新工具「Base64图片互转」(/base64-image-converter):一页双向,纯浏览器本地
|
||||
- **Base64 转图片**:三种输入形态全吃(裸 base64 串 / `data:mediatype;base64,...` / `url("data:...")`),多行自动去空白、URL-safe 字符(- _)归一 + 自动补 = 填充;「图片类型」下拉(自动识别/png/jpeg/webp/gif/bmp/svg/ico),输入不含 mediatype 时手动类型优先、自动模式读文件魔数嗅探真实格式;Blob→objectURL 预览 + 转换后 Image 探针校验(数据损坏给友好错误)+ 下载
|
||||
- **图片 转 Base64**:点击/拖拽上传(图片文件校验),输出格式三档实时切换(纯 base64 / data:URI / CSS url(),按记录的 mime+裸串重排不重读文件);「复制结果」(clipboard API + 1.5s 回执)、「Base64 转图片」按钮带输出直跳另一半页并自动转换(双向闭环)
|
||||
- 顶部说明条「使用浏览器 API 实现,文件不上传云端」;双 Tab 一页承载参考图的两个独立页
|
||||
- i18n zh/en;注册于「图片与视频」分组(image-tools 旁)
|
||||
- 实测:①data URI 40598 字符→转换 1280×800 预览 ②裸多行 base64 魔数嗅探为 png 成功 ③上传→data URI 40598 字符头尾正确 ④三档格式切换 ⑤互转按钮回带自动转换闭环
|
||||
- 修复:输出格式从「纯 base64」切「CSS url()」时正则只认 data: 开头导致重排未执行 → 改记录值直排
|
||||
|
||||
### 🔧 隐藏「AI 无痕改字」(/ai-text-edit)
|
||||
- 从工具注册表/「图片与视频」分组/About 页推荐/relay 首页推荐种子四处摘除,界面与搜索不再出现;源码与 relay 端点保留(恢复只需重新注册三行)
|
||||
- 受控授权配置(PROTECTED_TOOLS)与 relay 管线不动,恢复即生效
|
||||
|
||||
### ✨ 新工具「AI 无痕改字」(/ai-text-edit):描述要改什么,AI 全自动无缝替换
|
||||
- **三段本地管线**:本地 OCR(rapidocr)定位全图文字块 → 本地 vision 模型(qwen3.8-max / qwen3.7-plus / kimi-k3 / deepseek-v4-flash-vision-exp 等 7 款,NewAPI 内网直连)理解需求选字块+定新文字 → relay 像素引擎(PIL+numpy)无缝重绘
|
||||
- **像素引擎**:从 OCR 框像素自动检测原字角度/字号/颜色/粗细(与 PS 编辑器同算法),Jacobi 迭代 320 轮背景扩散擦原字(非色块覆盖),按检测样式原位重绘新字,NotoSansCJK 粗细匹配,过框宽自动缩号
|
||||
- **产品页布局**(参考同类产品):左侧上传(拖拽/点击,JPEG/PNG/WEBP ≤24MB)+ 提示词(0/200 + 5 个示例快捷填充:改数字/改姓名/改价格/删除文字/改金额)+ 尺寸(默认/4:3/3:4/1:1/自定义,比例自动补边不裁内容)+ 输出数量(1~3 张 = 字号微调档位挑最像)+ 模型下拉(7 款本地 vision 模型)+ 橙色提交;右侧「最近任务」前后对比历史(localStorage 缩略图,仅本机)
|
||||
- **结果区**:原始文字/新文字两列对比图 + 改字记录行(「人数8」→「31」109px·粗体·5.2°)+ 多变体切换 + 下载/新窗口打开
|
||||
- **支持纯删除**:提示词写"删除/无痕去除"→ 只擦除不重绘
|
||||
- 受控工具(授权+每日试用覆盖);首页推荐种子置顶;About 页「AI 智能」分组新条目
|
||||
- 实测:①"人数8→31"(渐变背景白粗体倾斜)→ vision 正确选块,检出 109px·粗体·5.2°,无缝替换无残影(导出像素梯度 0.38)②删除左下角小字 → 白字 px 8028→0、中心大字保留、1:1 补边梯度 0.26 自然 ③浏览器 E2E:上传→提示→提交→对比图/记录/下载/历史全链路通过
|
||||
|
||||
### ✨ OCR 无痕改字:自动匹配原字样式,输入新字即改
|
||||
- **点字框自动检测原文字样式**:角度(OCR 框顶边斜率)、字号(行高×0.82)、颜色(框内墨迹中位色,白/黑/灰/彩色识别)、粗细(中心行带墨迹横向行程中位数判粗体)
|
||||
- **实时预览**:输入新文字时画布按检测样式原位重绘(所见即所得),新字过原框宽 1.15 倍自动缩号
|
||||
- **无缝替换**:inpainting 背景扩散重建擦掉原字(非色块覆盖)→ 按检测样式重绘新字 → 一步历史「无痕改字」整体撤销
|
||||
- 选项栏显示「检出 白色·粗·109px·-10°」检测徽标;「🧹 只消除」保留纯删除路径
|
||||
- 实测(渐变背景+白色粗体"人数8"倾斜-10°):检出 白色·109px·5.2°;输入"31"实时预览;回车后图层=文字「31」+智能消除+背景;导出像素验证原区域无白字残影、背景平滑无痕
|
||||
|
||||
### ✨ 文字模板扩到 47 套 · 新增 7 大平台分类
|
||||
- **新增 6 平台各 5 套共 30 套**(原 17 套经典款归入「通用」):
|
||||
- **小红书**:品牌红 #FF2442 种草/探店/避坑/好物/vlog(「今日份宝藏」「魔都探店」)
|
||||
- **抖音**:黑底霓虹青 #25F4EE / 玫红 #FE2C55 悬念/教程/卡点/BGM(「千万别划走」「3秒学会」)
|
||||
- **B站**:B站蓝 #00AEEC / 粉 #FB7299 三连/硬核/番剧/高能(「一键三连!」「前方高能」)
|
||||
- **公众号**:深蓝红金 长文/干货/头条/金句/观点(「深度长文」「这个行业要变天」)
|
||||
- **视频号**:微信绿 #07C160 直播/热转/私域/带货(「直播预告」「3步做出爆款封面」)
|
||||
- **封面图**:高冲击封面主标/数字/大标题/科技感/极简(「封面主标题」「10个神器」)
|
||||
- **分类标签条**(全部/通用/小红书/抖音/B站/公众号/视频号/封面图):上传前模板墙 + 编辑器侧栏模板区同步切换,一次只看一个平台
|
||||
- 实测:墙 47 套 8 标签默认全部;分类计数 17/5/5/5/5/5/5 全对;点小红书模板→选图→自动插入2行白字粉描边;侧栏切抖音→5 套;截图验收无溢出错位
|
||||
|
||||
### ✨ 文字默认 100 号 + 选框拖角直接缩放字号
|
||||
- **默认字号 36 → 100**(换 storage key 清掉旧缓存,新建文字/套模板均为 100 号起)
|
||||
- **选框四角新增白色方块缩放手柄**:拖任意角直接调字号(以文字中心为锚点,只变大小不漂移),拖动实时重绘,松手进历史(「缩放文字 Npx」),属性面板字号同步;范围 6~600px
|
||||
- 与顶部蓝点旋转手柄并存:四角缩放、顶点旋转、框内拖动=移动
|
||||
- 实测:插字默认 100;右下角外拖 100→219、左上角内拖 219→107,历史逐步可撤销;截图验收四角手柄+旋转点渲染正常
|
||||
|
||||
### ✨ 上传前模板墙:未选图就能看到全部模板
|
||||
- 图片编辑 tab **未上传图片时,上传区直接平铺 17 套文字模板预览墙**(真实文案小样+花字样式),不再是空白上传框
|
||||
- 点任意模板 → 直接弹出选图 → 选完图片**该模板整组文案自动套入画布**(无需再回编辑器找模板)
|
||||
- 底部一行"点这里选择图片"随时可直接上传(不套模板);模板墙几何验收首屏 17/17 全露出、无需滚动
|
||||
- 模板定义抽为共享模块 text-tpls.ts(画布内侧栏模板区与上传前模板墙共用一套数据)
|
||||
|
||||
### ✨ 文字模板升级为成套文案(17套,主副标题整组插入)
|
||||
- 每套模板不再是单个占位词,而是**完整标题组**(取自封面模板库真实文案):主标题+副标题 1~3 行成组——如「B站史上/点击最高的10首MV」「辣到没朋友!川菜/辣子鸡 · 水煮肉片」「秀翻全场!/ALL KILL!」「合法打工人/SLAVE の一天 DAILY」等 17 套
|
||||
- 点击一次插入整组:逐行独立居中、主大副小按比例递减、总高自动适配画布;**连续点击插入多组时自动级联排到已有文字下方**,空间不足自动缩字号塞入,绝不互相叠压
|
||||
- 模板小样直接显示真实文案(两行截断预览),hover 标题含全套内容
|
||||
- 交互定稿:点击=插入新组;**点中某行文字后再点模板=仅换该行样式**(保留内容/位置/旋转)
|
||||
|
||||
### ✨ 文字旋转 + 14 款花字模板(点击即套用)
|
||||
- **画布直旋**:选中文字后拖顶部蓝色圆点手柄实时旋转(拖动即所见),松手进历史(「旋转文字 N°」);按住 Shift 吸附 15°;旋转以文字框中心为锚点,命中检测同步旋转(斜着也能点中)
|
||||
- **旋转滑条**:属性面板「旋转」-180°~180° 精调 + 数字输入 + 一键回正
|
||||
- **14 款花字模板**(B站封面风格):白/黄/青字描边、红/蓝/黑/粉底白字、鎏金/烈焰渐变、白字投影、空心描边、荧光绿——右侧面板点击即套:未选文字层则插入画布并应用,已选中则原地换样式(保留内容/字号/位置/旋转),随后可继续改字/调号/拖动/旋转
|
||||
- 模板带 CSS 实时小样预览;渲染管线支持:色块底→投影→描边→渐变/纯色填充
|
||||
- 修复:侧栏内容超高时可滚动(模板库+属性+历史不再互相挤出可视区)
|
||||
- 文字层新增 rot/grad/stroke/shadow/badge 字段,旧历史数据自动兼容
|
||||
|
||||
### ✨ 消除实时预览 + 智能消除笔(橡皮升级)
|
||||
- **实时预览**:点 OCR 文字框或选框松手的**瞬间**,画布立即显示消除后的效果(蓝标「👁 实时预览已生成」+「预览(未应用)」角标),满意点「✓ 应用消除」落图层,不满意「✕ 取消预览」还原——先看效果再确认,不再是盲操作
|
||||
- **智能消除笔(橡皮 E 升级)**:直接在底图的文字/水印上涂抹(红色半透明笔迹实时跟随),**松手立即无痕消除**,无需框选、无需 OCR、无需点按钮;选中画笔层时仍是传统擦除
|
||||
- 消除层改为置顶图层(盖住底图及其上的文字/色块);导出前自动应用未确认预览(所见即所得);Escape/重框选自动清预览
|
||||
- 大区域消除加迭代预算(防卡顿)
|
||||
|
||||
### ✨ 图片编辑:智能消除(无痕删除图中文字/水印)
|
||||
- **OCR 路径**:识别文字后点框 →「🧹 消除文字」自动识别文字笔画像素,从周边背景扩散重建(inpainting),渐变/纹理背景自然补全,不再是纯色覆盖
|
||||
- **选框路径**:框选任意区域(文字/水印/杂物)→「🧹 消除选区内容」一键无痕消除,无需 OCR
|
||||
- 消除结果写入独立「智能消除」画笔图层:非破坏性、可撤销(Ctrl+Z)、可调不透明度、可再编辑
|
||||
- 修复:mask 检测覆盖选区全部像素(原实现跳过边缘 2px,选区边缘的字符会残留);视口尺寸变化时按中心补偿平移(原实现布局稳定后图片偏移导致交互坐标错位)
|
||||
|
||||
### ✨ 图片编辑升级为 PS 风格图层编辑器
|
||||
- **9 工具**:移动/选框/画笔/橡皮/文字/油漆桶(容差可调)/吸管取色/裁剪/抓手,快捷键 V M B E T G I C H,`[ ]` 调笔刷、`0` 适应、`1` 原尺寸
|
||||
- **图层面板**:背景/画笔/文字/色块四类图层,显示隐藏、不透明度、上移下移、删除、新建画笔层;文字层改内容/字号/颜色/加粗,色块改底色
|
||||
- **历史记录面板**:快照式撤销重做(Ctrl+Z / Ctrl+Y,最多 20 步),点击任意步骤可跳转
|
||||
- **画布**:滚轮缩放(3%-3200%)、空格/抓手平移、棋盘格透明背景、画笔光圈预览、选区/裁剪框蚂蚁线
|
||||
- **选区操作**:框选后填充/清除选区、Delete 快捷清除;裁剪框选后一键应用(全图层同步裁剪)
|
||||
- **保留 OCR 强项**:一键识别图中文字 → 点框替换(自动取底色)/只擦除,生成独立图层可再编辑
|
||||
- 重构:image-tools.vue 2284→1660 行,编辑器拆分为独立组件 PsEditor.vue;功能数 12 → 13
|
||||
|
||||
### 🔧 授权系统:通用卡激活传 project_id(适配 CardAuth 新版)
|
||||
- CardAuth 新版支持「通用卡」(不绑定项目的跨项目卡),激活时必须指定项目;relay 激活请求现在固定携带 `project_id`(IT-TOOLS-PRO=6),通用卡可在本站正常激活,专属卡不受影响
|
||||
- 授权校验/撤销同步改用 `project_id` + 历史项目名(IT-Tools / IT-TOOLS-PRO)双重匹配,项目改名后新旧授权都能正确识别
|
||||
- 新增环境变量 `PROJECT_ID`(默认 6)与 `PROJECT_ALIASES`(默认两个历史名),换项目无需改代码
|
||||
|
||||
### ✨ 图片工具新增「图片编辑」:改图中文字 + 加文字
|
||||
- **改图中文字**:一键 OCR 自动定位图内文字(复用本机 rapidocr,带坐标),画布上画红色虚线框+文字标签;点框选中 → 输入新文字 → 「✓ 替换」自动采样框外圈中位色作底色覆盖原字,再在原位生成可编辑文字图层(字号按原文字高度推算,也可「只擦除」不加字)
|
||||
- **涂改/加字**:画布拖拽框选任意区域按底色涂掉(自动取图/手动指定颜色);「+ 添加文字」放置新文字图层,支持字号/颜色/加粗
|
||||
- **图层面板**:所有文字图层(改字内容/字号/颜色/删除)和擦除区域(改底色/删除)统一列表管理,画布上可直接拖动文字调整位置
|
||||
- 执行后原尺寸导出(PNG 保 PNG,其他保 JPEG),擦除区与文字层逐像素合成
|
||||
- 图片工具功能数 12 → 13,About/关键词/中英文案同步
|
||||
|
||||
### 📈 「当天最热股票」改为「AI 最热股票」
|
||||
- 股票列选项卡「最热」→「AI最热」,列标题 → 「AI最热股票」
|
||||
- 数据源从「全市场涨幅榜」改为**聚合 12 个 AI 概念板块**(人工智能、AI 芯片、算力概念、AI 应用、AI 智能体、多模态 AI、AIGC 概念、CPO 概念、智谱 AI 概念、AI 语料、国产芯片、存储芯片),约 580 只成分股去重
|
||||
- **按成交额降序**取最热 10 只(涨幅榜常年被小盘股占据,成交额榜才是资金真正关注的主线龙头),行内显示「现价 · 成交额」
|
||||
- 交易时段每 60 秒自动刷新,标题行显示 交易中/休市 徽章
|
||||
- 自选股选项卡不变
|
||||
|
||||
## Version 2026.10.14-it-tools-pro
|
||||
|
||||
### 🎨 面单模板全部去掉头部背景色带
|
||||
|
||||
@@ -32,6 +32,82 @@
|
||||
- **生成记录**:翻译/OCR/修图/转换等 9 个工具自动留痕,数据存本地
|
||||
- **体验优化**:全站中文默认、收藏与最近使用、菜单一键展开/收起、宽屏自适应、品牌页脚等数十项细节
|
||||
|
||||
### 留言反馈(2026.11 新增)
|
||||
|
||||
- **访客提交**:顶栏「留言反馈」按钮打开弹窗 —— 类型(功能建议/意见建议/Bug 反馈/其他)+ 内容(上限 1000 字)+ 联系方式(可选),图形验证码防刷,同一 IP 一小时内限提交 1 次
|
||||
- **用户列表**:`/admin`「总览与用户」标签展示用户名/角色/状态/文件数/文件占用/设备/授权/注册/**最后登录**(relay `users.last_login`,登录与注册时写入,从未登录显示「未登录」),支持文件管理、改密、升降级、禁用/删除
|
||||
- **管理后台**:`/admin` 切到「留言反馈」标签(`X-Admin-Token` 鉴权,令牌存本地 `it-tools-admin-token`),列出时间/类型/内容/联系方式/真实 IP,支持状态流转(未处理→已处理→已回复)与删除,导航标签带未处理数角标;窄屏下表格容器内横向滚动不撑破页面
|
||||
- **链路**:公开页 → relay `POST /feedback`(验证码校验 + IP 限频)落盘 `data/feedback.json`;管理接口经 nginx `location /admin/` 反代到 `it-tools-relay:8091`。公网入口 https://it.88531.cn/
|
||||
|
||||
### 在线统计与公告推送(2026.11 新增)
|
||||
|
||||
- **右上角常驻**:🔔 公告铃铛(未读红点)+ `v2026.11.12` 版本徽标(源码常量 `SITE_VERSION`,与 Gitea Release tag 同步,发版时更新)
|
||||
- **公告推送**:铃铛下拉面板列出授权系统公告(标题/时间/正文,未读带红条,点击已读、支持全部已读);`is_popup` 类型公告进站即弹一次(每条只弹一次,已读记录存 localStorage `it-tools-ann-read`)
|
||||
- **在线统计**:打开页面即经 relay `POST /relay/hub/report` 向授权系统(auth.88531.cn 项目 6)登记安装并上报版本号(机器码复用 license 的 `getMachineId()`),每 30 分钟心跳一次;公告每 15 分钟拉取一次(`GET /relay/hub/announcements`),授权系统后台据此展示安装数/在线数/趋势
|
||||
- **失败开放**:授权系统不可达时静默降级,不影响站点任何功能
|
||||
- **实现注意**:公告面板与推送弹窗均 `<Teleport to="body">`——实测 top-nav 内 v-if 子树挂载会触发 Vue `insertBefore null` 崩溃;CardAuth 的 heartbeat 会清空 `client_version/device_info`,relay 侧先心跳后 check-update 保证版本号落库
|
||||
|
||||
### MCP 接入(2026.11 新增)
|
||||
|
||||
- **功能页 `/mcp-connect`**(顶栏 Plug 图标直达):连接信息、令牌管理、接入后怎么使用(三步上手 + 13 场景示例话术 + 成功自检 + 排错速查)、可调用工具清单与注意事项
|
||||
- **授权即站内卡密**:与站点卡密体系同一套,购买并激活后即自动可用,无需单独开通 MCP;已授权设备打开页面直接显示主令牌,客户端配置示例自动带真实令牌(复制即用),无令牌自动创建「默认」
|
||||
- **端点**:`https://<站点>/mcp`(MCP Streamable HTTP / JSON-RPC 2.0),`initialize`、`tools/list` 免鉴权,`tools/call` 必须 `Authorization: Bearer mcpt_…`
|
||||
- **13 个 AI 工具**:translate_text / translate_doc / ocr / gen_image / remove_bg / upscale_image / tts / speech_to_text / extract_subtitle / video_process / convert_doc / copywriting / vision_qa(文件类入参传服务器可读绝对路径,二进制结果返回下载 URL)
|
||||
- **调用记录**:Admin 左侧「MCP 调用」页(近 7 天总览 / 工具排行 / 调用流水),relay 侧 `mcp_usage` 表逐条落库
|
||||
- **客户端接入**:Hermes(`config.yaml` 的 `mcp_servers`)、任意支持 HTTP 传输的 MCP 客户端、curl;配置片段在功能页 ③ 区一键复制
|
||||
|
||||
### AI 生图:自定义提供商 + 生成历史(2026.11 新增)
|
||||
- **中文提示词自动转英文**(2026-11-13 新增):生成时检测到中文提示词,relay 自动用 LLM(mimo-v2.6-flash)转成高质量英文生图提示词再发上游(Flux/SDXL 系对英文理解最好),翻译失败回退原文绝不阻断;结果图操作行显示「🌐 已自动转英文发送(悬停查看)」,悬停可看完整英文;同词有缓存;生成历史存用户原文。
|
||||
- **首页「近期新功能」清单**(2026-11-13 补齐):把最新开发完的功能(AI 生图、AI 接入 MCP、管理后台升级)加进 `Home.page.vue` 的 `NEW_FEATURES` 顶部(新→旧),★铁规则:以后每完成一批新功能必须在此清单最前面加条目,否则首页看不到。
|
||||
- **生图页默认选中第一个模型**(2026-11-13 修复):打开 `/ai-gen` 页面,模型下拉与标签默认选中列表第一个(dall-e-3);原逻辑初始固定选 pollinations-flux(列表第 7 个),已改为列表加载后取 `j.data[0]` 并加空值兜底。
|
||||
- **示例提示词四组分类**(2026-11-13 新增,同日四次改版定稿):「尝试这些示例」区选项卡切换——**通用(14) / 自媒体(30) / 电商(18) / 软件类(24),共 86 个**即点即填的场景提示词。第四版全组扩容 +32 词热门题材(2026-11 实时热词):通用加人形机器人/智能眼镜/芯片晶圆/脑机接口/AI陪伴玩具/情绪治愈/低碳出行/露营户外;自媒体加 AI办公智能体/Token囤货/AI导购比价/具身智能/演唱会神器/情绪价值/后屏幕交互/科普热词;电商加双12年终/虚拟试衣/国补换新/囤货清单/直播秒杀/情绪好物/年货节/跨境出海;软件类加智能体办公/大模型对话/开源生态/机器人编程/词元Token/语音助手/云同步/无代码搭建。词多时示例区出现区域内滚动条(max-height 172px 细条滚动、切组回顶,放得下则不出现)。软件类=电脑软件+手机软件合并(办公桌面、AI 概念、手持 APP、通勤办公等 16 词,覆盖软件推荐文章配图);电商=促销主图/大促 Banner/秒杀/直播带货等 10 词;自媒体=好物开箱、测评天平、拆箱瞬间等种草内容 6 词;每词带文章配图的画幅/构图/配色关键词;1024×768 与 1600×800 双断言无溢出。
|
||||
|
||||
- **模型来源与免费说明**:站内 10 个生图模型全部经自建 NewAPI 网关聚合——5 个 `pollinations-*` 走 Pollinations.ai(站主 API Key 预算制、对使用者免费),4 个 `flux*` + `dall-e-3` 走 Cloudflare Workers AI(站主账号免费额度,官方 10,000 Neurons/天 ≈ **173 张/天**),**对使用者全部免费但共享池有限**;模型列表由后端从网关实时拉取,下拉标注各上游配额。
|
||||
- **我的提供商**:左侧「或使用自己的提供商 / API KEY」展开,填写 OpenAI 兼容接口地址 + KEY,点「连接并拉取模型」自动拉取上游模型列表;与站内模型合并展示(下拉分组「站内免费模型 / 我的模型」,自定义模型胶囊为紫色虚线框)。支持手动输入模型名回车添加、单个移除、一键清除。
|
||||
- **KEY 只存本地**:接口地址与 KEY 仅保存在浏览器 localStorage(`it-tools-ai-provider`),生成时临时发给后端转发,**不入库、不落盘**(已 grep 宿主与容器数据目录验证零残留)。
|
||||
- **生成历史**:每次生成成功自动落盘服务端(按机器隔离,每机上限 100 张、超限自动清理最旧),页面右侧新增 50×50 缩略图竖排历史列;点击任意缩略图回看大图,「下载图片」带 `?dl=1` 触发附件下载,「新窗口打开」直连原图,刷新后历史仍在。
|
||||
- **新增端点**:`POST /relay/ai/custom-models`(测试连接并拉取模型)、`POST /relay/ai/gen-image` 扩展可选 `provider` 字段(自定义提供商转发)、`GET /relay/ai/img-history?machine=`(历史列表)、`GET /relay/ai/img/<machine>/<id>[?dl=1]`(图片文件/下载)。
|
||||
- **内置免费每日次数 + 上游真实免费配额**(2026.11 新增;2026.11.13 按上游官方/实测补真实数字):「模型」区右侧实时显示、模型下拉每个选项标注上游配额、鼠标悬停显示出处——
|
||||
- **机器限额**:未授权每日 **10 次**(`DAILY_FREE_LIMIT` 环境变量可调,北京时间 0 点重置,**生成成功才扣次**;自带提供商/KEY 生成不计次)。
|
||||
- **上游免费池(全站共享,已授权同样受保护)**——内置模型上游是站主账号的免费额度,不存在「无限次」:
|
||||
- `flux*` / `dall-e-3`(5 个)→ Cloudflare Workers AI:**官方免费 10,000 Neurons/天**,proxy 固定 1024×1024/4 步 = 57.6 Neurons/张 → **约 173 张/天**(`CF_DAILY_LIMIT` 默认 173,北京时间约 08:00 重置,账号级共享,超出 Free plan 直接报错);服务端按 `daily_gen_cf.json` 全站计数保护,池尽返回 403 并提示。
|
||||
- `pollinations-*`(5 个)→ Pollinations.ai:站主 **API Key 预算制(pollen 余额)**,无固定每日张数(官方匿名档才是 45 秒/张按 IP);上游错误透传。
|
||||
- **界面文案**(按所选模型联动):未授权 `免费10次·剩N · CF池剩X/173张` / `… · Pollinations按Key余额`;已授权 `已授权 · CF池剩X/173张`;CF 池尽红色 `CF免费池已用完 · 08:00重置`。
|
||||
- 额度查询端点 `POST /relay/ai/quota`(带 `model` 返回 `authorized/limit/used/remaining` + `upstream/upstream_daily/upstream_used/upstream_remaining/upstream_note/cf_daily`;`remaining=-1` 表示机器维度不限,仍受共享池约束)。次数用完点「或使用自己的提供商 / API KEY」用自己的 KEY 继续生成,403 提示文案同步引导。
|
||||
|
||||
### AI 换脸(2026.11 新增)
|
||||
|
||||
- 上传源人脸照片 + 目标照片,本机 CPU 一键换脸(insightface buffalo_l 人脸检测,多脸自动取最大 + inswapper_128 换脸模型,模型 855MB 预置于镜像内)。
|
||||
- 接口 `POST /relay/ai/face-swap`(multipart:`source`/`target`/`consent`),需勾选授权承诺,结果走站内 `/relay/ai/img` 图链路,支持下载。
|
||||
- 授权应用:未授权用户每天可免费试用 3 次,卡密激活后不限次。
|
||||
|
||||
### AI 海报生成(2026.11 新增)
|
||||
|
||||
- 42 套热门海报模板、10 大分类(促销/节日/活动/美食/教育/校园/健身/招聘/生日/封面),模板画布 1080×1440;「校园」分类含教师节/开学第一课/家长会/秋季运动会/毕业季/社团招新/优秀学生表彰/快乐六一/考试加油/读书月等 10 款学校师生主题模板。
|
||||
- 选中模板后可:**修改文字**(内容/字号/颜色/粗细/对齐/行高/斜体,预览与导出换行一致)、**旋转任意图层**(文字/图片/形状均支持,-180°~180° 滑杆 + 一键复位,预览与导出同一旋转中心)、**替换图片**(本地上传 或 AI 生成,圆角可调)、拖动移动图层、图层排序/删除、添加文字与图片框、一键切换背景渐变、AI 生成整屏背景。
|
||||
- 编辑页整页自适应浏览器高度、不出现整体滚动条:内容超出时只在模板列表 / 画布 / 编辑面板各自区域内滚动(窄屏堆叠后统一为一个区域),画布始终完整可见。
|
||||
- AI 配图复用 `/relay/ai/gen-image` 与每日免费生图额度,按图框宽高比自动匹配上游尺寸档位。
|
||||
- 完成后一键导出 1080×1440 PNG(旋转图层同步导出)。授权应用,支持每日免费试用。
|
||||
|
||||
### 历史记录 100 条上限(2026.11 新增)
|
||||
|
||||
所有功能里的历史记录最多显示 100 条(按时间倒序取最新 100 条):
|
||||
|
||||
- 服务端 `GET /relay/ai/img-history` 与 `GET /admin/mcp-usage` 调用流水统一截断前 100 条(只影响展示条数,后台总记录数/总调用量统计不受影响);
|
||||
- 前端图片历史共享层(`loadImgHist`)、AI 生图与海报生成的自建历史均带 100 条本地兜底;
|
||||
- 已有上限低于 100 的(生成记录 50 条、网速测速 20 条等)保持原值。
|
||||
|
||||
### 后台文件管理(2026.11 新增)
|
||||
|
||||
管理后台「文件管理」页全面升级:
|
||||
|
||||
- **默认全量视图**:进入即显示**所有用户**上传的文件 + AI 生成图片(换脸/生图/海报/编辑)+ MCP 产出文件的聚合列表,无需先选用户;下拉仍可按「仅 AI 生成 / 仅某用户」过滤。
|
||||
- **50 条/页自动分页**:超过 50 条自动分页,页头页尾都有翻页控件,**显示总记录数与总大小**(如「共 81 条记录 · 合计 31.5 MB」)。
|
||||
- **图片 100×100 缩略图**:图片类型文件在「预览」列显示 100×100 缩略图,点击看原图;**其他文件显示文件类型徽标**(PDF/PNG/MP4…)。
|
||||
- **单独下载**:每一行都有「下载」链接(`Content-Disposition: attachment` 带原文件名),与「删除」并列;删除按来源分流(用户文件走 files 表、AI 生成图同步删 index、MCP 文件防路径穿越)。
|
||||
- **安全**:缩略图与下载走统一 `/relay/admin/file?path=…&token=…` 路由(`<img>`/`<a>` 无法携带 header,鉴权走 query token,与 header 双通道校验);路径白名单限定 `users/`、`gen_images/`、`mcp_files/` 三棵子树 + realpath 校验,防目录穿越;无 token 请求 403。
|
||||
- 服务端按 mtime 全局排序后切片分页,每项附带 `source`(user/gen/mcp)、`file_type`、`is_image`、相对 `path` 字段。
|
||||
|
||||
## 优势
|
||||
|
||||
- **一次激活,全站通用**:输入一次卡密,全部授权功能解锁,无需逐个购买
|
||||
@@ -84,6 +160,78 @@ docker run -d --name it-tools --restart always --network ittools-net -p 8080:80
|
||||
**不启动第三步也完全能用**,只是翻译/OCR/格式转换这几个高级功能会显示试用/授权提示,免费工具不受任何影响。
|
||||
> 注意:relay 与工具站必须在同一 Docker 网络(ittools-net),且先启动 relay 再启动工具站。
|
||||
|
||||
### 方式二:Docker Compose部署
|
||||
|
||||
上面三步 `docker run` 的等价编排(含全部参数)。前置要求不变:先 `pnpm install && pnpm build` 生成 `dist/`;`docker/it-tools-relay` 的 Dockerfile 需要 `hf-cache/`、`piper-models/`、`ai-models/`、`waifu2x/` 四个模型目录(未入库),没有的话把 relay 的 `build:` 换成现成镜像 `image: 192.168.68.19:3200/jinghui/it-tools-relay:latest`。
|
||||
|
||||
```yaml
|
||||
services:
|
||||
it-tools-relay:
|
||||
build: ./docker/it-tools-relay
|
||||
image: it-tools-relay:latest
|
||||
container_name: it-tools-relay
|
||||
restart: always
|
||||
ports:
|
||||
- "8091:8091"
|
||||
env_file:
|
||||
- ./docker/it-tools-relay/.env
|
||||
volumes:
|
||||
- relay-data:/app/data
|
||||
networks:
|
||||
- ittools-net
|
||||
|
||||
it-tools:
|
||||
build: .
|
||||
image: it-tools:custom
|
||||
container_name: it-tools
|
||||
restart: always
|
||||
depends_on:
|
||||
- it-tools-relay
|
||||
ports:
|
||||
- "8080:80"
|
||||
extra_hosts:
|
||||
# nginx 反代宿主机上的 rapidocr(5000) / iopaint(8060) 需要
|
||||
- "host.docker.internal:host-gateway"
|
||||
networks:
|
||||
- ittools-net
|
||||
|
||||
# 可选:本地 OCR 加速(不部署则图片OCR/PDF文字识别不可用)
|
||||
# rapidocr:
|
||||
# image: rapidocr/rapidocr:latest
|
||||
# container_name: rapidocr
|
||||
# restart: always
|
||||
# ports:
|
||||
# - "5000:5000"
|
||||
#
|
||||
# 可选:AI 修图(去水印/抠图/超分/人脸修复)
|
||||
# iopaint:
|
||||
# image: sanster/iopaint:latest
|
||||
# container_name: iopaint
|
||||
# restart: always
|
||||
# ports:
|
||||
# - "8060:8060"
|
||||
# volumes:
|
||||
# - iopaint-models:/root/.cache
|
||||
|
||||
volumes:
|
||||
relay-data:
|
||||
# iopaint-models:
|
||||
|
||||
networks:
|
||||
ittools-net:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
```bash
|
||||
git clone http://192.168.68.19:3200/jinghui/it-tools-pro.git
|
||||
cd it-tools-pro
|
||||
pnpm install && pnpm build # 生成 dist/(Dockerfile 不做前端构建)
|
||||
cd docker/it-tools-relay && cp .env.example .env && cd ../.. # 填 CardAuth 地址与密钥
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
打开 `http://服务器IP:8080`。只起工具站、不要 relay 时用 `docker compose up -d it-tools`(翻译/OCR/格式转换会显示试用提示,免费工具不受影响)。
|
||||
|
||||
### 可选:本地 OCR / AI 修图模型后端
|
||||
|
||||
| 服务 | 端口 | 用途 |
|
||||
|
||||
Vendored
+15
@@ -16,17 +16,20 @@ declare module '@vue/runtime-core' {
|
||||
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']
|
||||
AiTextEdit: typeof import('./src/tools/ai-text-edit/ai-text-edit.vue')['default']
|
||||
App: typeof import('./src/App.vue')['default']
|
||||
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
||||
AudioTools: typeof import('./src/tools/audio-tools/audio-tools.vue')['default']
|
||||
BarcodeBatchGenerator: typeof import('./src/tools/batch-barcode-generator/barcode-batch-generator.vue')['default']
|
||||
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
|
||||
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
|
||||
Base64ImageConverter: typeof import('./src/tools/base64-image-converter/base64-image-converter.vue')['default']
|
||||
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
|
||||
BasicAuthGenerator: typeof import('./src/tools/basic-auth-generator/basic-auth-generator.vue')['default']
|
||||
Bcrypt: typeof import('./src/tools/bcrypt/bcrypt.vue')['default']
|
||||
BenchmarkBuilder: typeof import('./src/tools/benchmark-builder/benchmark-builder.vue')['default']
|
||||
Bip39Generator: typeof import('./src/tools/bip39-generator/bip39-generator.vue')['default']
|
||||
'Buy.page': typeof import('./src/pages/Buy.page.vue')['default']
|
||||
CAlert: typeof import('./src/ui/c-alert/c-alert.vue')['default']
|
||||
'CAlert.demo': typeof import('./src/ui/c-alert/c-alert.demo.vue')['default']
|
||||
CameraRecorder: typeof import('./src/tools/camera-recorder/camera-recorder.vue')['default']
|
||||
@@ -88,7 +91,9 @@ declare module '@vue/runtime-core' {
|
||||
EmojiPicker: typeof import('./src/tools/emoji-picker/emoji-picker.vue')['default']
|
||||
Encryption: typeof import('./src/tools/encryption/encryption.vue')['default']
|
||||
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default']
|
||||
FaceSwap: typeof import('./src/tools/face-swap/face-swap.vue')['default']
|
||||
FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default']
|
||||
FeedbackModal: typeof import('./src/components/FeedbackModal.vue')['default']
|
||||
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
|
||||
GenHistory: typeof import('./src/tools/gen-history/GenHistory.vue')['default']
|
||||
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
|
||||
@@ -125,6 +130,7 @@ declare module '@vue/runtime-core' {
|
||||
IconMdiVideo: typeof import('~icons/mdi/video')['default']
|
||||
ImageOcr: typeof import('./src/tools/image-ocr/image-ocr.vue')['default']
|
||||
ImageTools: typeof import('./src/tools/image-tools/image-tools.vue')['default']
|
||||
ImgHist: typeof import('./src/tools/img-hist/ImgHist.vue')['default']
|
||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||
@@ -149,15 +155,18 @@ declare module '@vue/runtime-core' {
|
||||
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
|
||||
MarkdownToHtml: typeof import('./src/tools/markdown-to-html/markdown-to-html.vue')['default']
|
||||
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
|
||||
McpConnect: typeof import('./src/tools/mcp-connect/McpConnect.vue')['default']
|
||||
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.vue')['default']
|
||||
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
||||
MenuIconItem: typeof import('./src/components/MenuIconItem.vue')['default']
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
||||
NAlert: typeof import('naive-ui')['NAlert']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCard: typeof import('naive-ui')['NCard']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
@@ -168,6 +177,7 @@ declare module '@vue/runtime-core' {
|
||||
NDropdown: typeof import('naive-ui')['NDropdown']
|
||||
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NEmpty: typeof import('naive-ui')['NEmpty']
|
||||
NForm: typeof import('naive-ui')['NForm']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NGi: typeof import('naive-ui')['NGi']
|
||||
@@ -189,12 +199,15 @@ declare module '@vue/runtime-core' {
|
||||
NRadioButton: typeof import('naive-ui')['NRadioButton']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSelect: typeof import('naive-ui')['NSelect']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NTabPane: typeof import('naive-ui')['NTabPane']
|
||||
NTabs: typeof import('naive-ui')['NTabs']
|
||||
NTag: typeof import('naive-ui')['NTag']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
@@ -206,7 +219,9 @@ declare module '@vue/runtime-core' {
|
||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||
PinyinConverter: typeof import('./src/tools/pinyin-converter/pinyin-converter.vue')['default']
|
||||
Poster: typeof import('./src/tools/poster/poster.vue')['default']
|
||||
'Pricing.page': typeof import('./src/pages/Pricing.page.vue')['default']
|
||||
PsEditor: typeof import('./src/tools/image-tools/PsEditor.vue')['default']
|
||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||
RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default']
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
.env
|
||||
data/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
hf-cache/
|
||||
piper-models/
|
||||
ai-models/
|
||||
waifu2x/
|
||||
face-models/
|
||||
*.log
|
||||
.venv-hf/
|
||||
@@ -7,13 +7,16 @@ RUN apt-get update \
|
||||
# models are pre-downloaded on the host (build env has no internet)
|
||||
RUN pip install --no-cache-dir piper-tts faster-whisper
|
||||
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple "rembg[cpu]"
|
||||
# AI 换脸: insightface(纯Python wheel 免编译) + buffalo_l人脸检测 + inswapper_128换脸模型(宿主已预置)
|
||||
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple insightface
|
||||
COPY hf-cache /root/.cache/huggingface
|
||||
COPY face-models /app/face-models
|
||||
COPY piper-models /app/piper-models
|
||||
# AI 图片: u2net 抠图模型(预下载) + waifu2x-ncnn-vulkan 无损放大(CPU)
|
||||
COPY ai-models/u2net.onnx /root/.u2net/u2net.onnx
|
||||
COPY waifu2x/waifu2x-ncnn-vulkan-20220728-ubuntu /app/waifu2x
|
||||
WORKDIR /app
|
||||
COPY server.py video_ops.py audio_ops.py .
|
||||
COPY server.py video_ops.py audio_ops.py mcp_ops.py .
|
||||
ENV HF_HOME=/root/.cache/huggingface
|
||||
EXPOSE 8091
|
||||
CMD ["python", "server.py"]
|
||||
@@ -0,0 +1,745 @@
|
||||
"""MCP (Model Context Protocol) 接入模块 — IT-TOOLS-PRO 授权应用的 AI 调用入口。
|
||||
|
||||
设计(与 video_ops/audio_ops 同为 server.py 伴星模块):
|
||||
- 令牌:MCP 令牌存 DATA_DIR/mcp_tokens.json,与本机机器码绑定;生成与每次调用都复验
|
||||
query_authorized / 账号授权,卡密过期令牌即失效("购买卡密才能调用")。
|
||||
- 协议端点:POST /mcp —— MCP Streamable HTTP(JSON-RPC 2.0,无会话状态)。
|
||||
initialize / tools/list 免鉴权(让客户端先发现工具),tools/call 必须 Bearer 令牌。
|
||||
- 13 个工具经本机 loopback http://127.0.0.1:8091 直调 relay 自身端点(完整走
|
||||
check() 授权 + log_usage() 统计),OCR 直打宿主 rapidocr:5000。
|
||||
- 文件类结果落 DATA_DIR/mcp_files/,响应里返回可下载 URL(GET /mcp/file/<name>,同令牌鉴权)。
|
||||
- 每次 tools/call 记 mcp_usage 表(令牌尾号/机器/工具/耗时/成败),供后台「MCP 调用」页查询。
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import secrets
|
||||
import sqlite3
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
# ---- 由 server.py 启动时注入(避免循环 import) ----
|
||||
_CTX = {
|
||||
"data_dir": "/app/data",
|
||||
"usage_db": "/app/data/usage.db",
|
||||
"query_authorized": lambda machine: False,
|
||||
"account_ok": lambda machine: False,
|
||||
"machine_ok": lambda m: bool(re.match(r"^\d{13,20}$", m)),
|
||||
"public_base": "", # 空则按请求 Host 推断
|
||||
}
|
||||
|
||||
|
||||
def setup(**kw):
|
||||
_CTX.update({k: v for k, v in kw.items() if v is not None})
|
||||
_ensure_table()
|
||||
|
||||
|
||||
def _tokens_file():
|
||||
return os.path.join(_CTX["data_dir"], "mcp_tokens.json")
|
||||
|
||||
|
||||
def _files_dir():
|
||||
d = os.path.join(_CTX["data_dir"], "mcp_files")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
return d
|
||||
|
||||
|
||||
def _ensure_table():
|
||||
try:
|
||||
conn = sqlite3.connect(_CTX["usage_db"])
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS mcp_usage ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, token_tail TEXT, machine TEXT, "
|
||||
"tool TEXT, ok INTEGER, err TEXT, dur_ms INTEGER, at REAL)")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def log_mcp(token_tail: str, machine: str, tool: str, ok: bool, err: str, dur_ms: int):
|
||||
try:
|
||||
conn = sqlite3.connect(_CTX["usage_db"])
|
||||
conn.execute("INSERT INTO mcp_usage (token_tail, machine, tool, ok, err, dur_ms, at) "
|
||||
"VALUES (?,?,?,?,?,?,?)",
|
||||
(token_tail, machine, tool, 1 if ok else 0, (err or "")[:400], int(dur_ms), time.time()))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def mcp_usage_query(days: int = 7) -> dict:
|
||||
since = time.time() - days * 86400
|
||||
conn = sqlite3.connect(_CTX["usage_db"])
|
||||
rows = conn.execute(
|
||||
"SELECT token_tail, machine, tool, ok, err, dur_ms, at FROM mcp_usage "
|
||||
# 铁规则:所有功能历史最多显示 100 条
|
||||
"WHERE at>? ORDER BY at DESC LIMIT 100", (since,)).fetchall()
|
||||
by_tool = conn.execute(
|
||||
"SELECT tool, COUNT(*), SUM(ok) FROM mcp_usage WHERE at>? GROUP BY tool ORDER BY COUNT(*) DESC",
|
||||
(since,)).fetchall()
|
||||
total = conn.execute("SELECT COUNT(*), SUM(ok) FROM mcp_usage WHERE at>?", (since,)).fetchone()
|
||||
conn.close()
|
||||
return {
|
||||
"days": days,
|
||||
"total": int(total[0] or 0),
|
||||
"ok_total": int(total[1] or 0),
|
||||
"by_tool": [{"tool": t, "count": int(c), "ok": int(o or 0)} for t, c, o in by_tool],
|
||||
"rows": [{"token_tail": r[0], "machine": r[1], "tool": r[2], "ok": bool(r[3]),
|
||||
"err": r[4] or "", "dur_ms": int(r[5] or 0), "at": int(r[6] or 0)} for r in rows],
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 令牌管理
|
||||
|
||||
def _load_tokens() -> list:
|
||||
try:
|
||||
with open(_tokens_file(), "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data if isinstance(data, list) else []
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def _save_tokens(items: list):
|
||||
tmp = _tokens_file() + ".tmp"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
json.dump(items, f, ensure_ascii=False, indent=1)
|
||||
os.replace(tmp, _tokens_file())
|
||||
|
||||
|
||||
def _authorized(machine: str) -> bool:
|
||||
if not machine or not _CTX["machine_ok"](machine):
|
||||
return False
|
||||
try:
|
||||
return bool(_CTX["query_authorized"](machine)) or bool(_CTX["account_ok"](machine))
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _bearer(handler) -> str:
|
||||
auth = handler.headers.get("Authorization", "") or ""
|
||||
if auth.lower().startswith("bearer "):
|
||||
return auth[7:].strip()
|
||||
return (handler.headers.get("X-MCP-Token", "") or "").strip()
|
||||
|
||||
|
||||
def _find_token(tok: str):
|
||||
if not tok:
|
||||
return None
|
||||
for it in _load_tokens():
|
||||
if it.get("token") == tok:
|
||||
return it
|
||||
return None
|
||||
|
||||
|
||||
def tokens_api(method: str, payload: dict, qs: dict) -> tuple[int, dict]:
|
||||
"""令牌管理:GET /mcp/tokens、POST /mcp/tokens(生成)、POST /mcp/tokens/delete。"""
|
||||
machine = (payload.get("machine_id") or payload.get("machine")
|
||||
or (qs.get("machine_id") or qs.get("machine") or [""])[0] or "").strip()
|
||||
if not _authorized(machine):
|
||||
return 403, {"code": 403, "message": "本设备尚未授权:购买卡密并激活后才能生成 MCP 令牌"}
|
||||
|
||||
items = _load_tokens()
|
||||
if method == "GET":
|
||||
mine = [it for it in items if it.get("machine") == machine]
|
||||
return 200, {"code": 200, "message": "ok",
|
||||
"data": {"tokens": mine, "count": len(mine), "authorized": True}}
|
||||
|
||||
if method == "POST" and payload.get("action") == "delete":
|
||||
tok = payload.get("token") or ""
|
||||
kept = [it for it in items if not (it.get("token") == tok and it.get("machine") == machine)]
|
||||
if len(kept) != len(items):
|
||||
_save_tokens(kept)
|
||||
return 200, {"code": 200, "message": "已删除", "data": {"tokens": [i for i in kept if i.get("machine") == machine]}}
|
||||
return 404, {"code": 404, "message": "令牌不存在"}
|
||||
|
||||
# 生成
|
||||
mine = [it for it in items if it.get("machine") == machine]
|
||||
if len(mine) >= 10:
|
||||
return 400, {"code": 400, "message": "每台设备最多 10 个 MCP 令牌,请先删除不用的"}
|
||||
note = (payload.get("note") or "").strip()[:40]
|
||||
rec = {
|
||||
"token": "mcpt_" + secrets.token_hex(24),
|
||||
"machine": machine,
|
||||
"note": note or "MCP 客户端",
|
||||
"created": int(time.time()),
|
||||
"last_used": 0,
|
||||
"calls": 0,
|
||||
}
|
||||
items.append(rec)
|
||||
_save_tokens(items)
|
||||
return 200, {"code": 200, "message": "ok", "data": {"token": rec["token"], "record": rec}}
|
||||
|
||||
|
||||
def _touch_token(tok: str):
|
||||
items = _load_tokens()
|
||||
changed = False
|
||||
for it in items:
|
||||
if it.get("token") == tok:
|
||||
it["last_used"] = int(time.time())
|
||||
it["calls"] = int(it.get("calls") or 0) + 1
|
||||
changed = True
|
||||
break
|
||||
if changed:
|
||||
try:
|
||||
_save_tokens(items)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- http 内调
|
||||
|
||||
_LOOPBACK = "http://127.0.0.1:8091"
|
||||
_OCR_URL = "http://host.docker.internal:5000/ocr"
|
||||
|
||||
|
||||
def _req(base: str, method: str, path: str, headers: dict, body=None, timeout: int = 600):
|
||||
h = {"User-Agent": "ittools-mcp/1.0"}
|
||||
if headers:
|
||||
h.update(headers)
|
||||
url = base + path
|
||||
req = urllib.request.Request(url, data=body, headers=h, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||||
return r.status, dict(r.headers), r.read()
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, dict(e.headers), e.read()
|
||||
|
||||
|
||||
def _hdr(machine: str, tool: str, ct: str = "") -> dict:
|
||||
h = {"X-Machine-Id": machine, "X-Tool": tool}
|
||||
if ct:
|
||||
h["Content-Type"] = ct
|
||||
return h
|
||||
|
||||
|
||||
def _check(status, raw):
|
||||
if status == 403:
|
||||
raise RuntimeError("授权校验未通过(403):设备授权缺失或已过期")
|
||||
if status >= 400:
|
||||
raise RuntimeError(f"HTTP {status}: {raw.decode('utf-8', 'ignore')[:300]}")
|
||||
return raw
|
||||
|
||||
|
||||
def _json_api(status, raw):
|
||||
_check(status, raw)
|
||||
try:
|
||||
j = json.loads(raw.decode("utf-8"))
|
||||
except Exception:
|
||||
return raw.decode("utf-8", "ignore")[:5000]
|
||||
if isinstance(j, dict) and j.get("code") not in (None, 200, 0):
|
||||
raise RuntimeError(j.get("message") or f"接口返回 code={j.get('code')}")
|
||||
return j
|
||||
|
||||
|
||||
def _multipart(fields, files):
|
||||
boundary = uuid.uuid4().hex
|
||||
out = bytearray()
|
||||
for k, v in fields.items():
|
||||
out += f"--{boundary}\r\nContent-Disposition: form-data; name=\"{k}\"\r\n\r\n{v}\r\n".encode()
|
||||
for field, fname, data, ct in files:
|
||||
out += (f"--{boundary}\r\nContent-Disposition: form-data; name=\"{field}\"; "
|
||||
f"filename=\"{fname}\"\r\nContent-Type: {ct}\r\n\r\n").encode()
|
||||
out += data + b"\r\n"
|
||||
out += f"--{boundary}--\r\n".encode()
|
||||
return bytes(out), f"multipart/form-data; boundary={boundary}"
|
||||
|
||||
|
||||
def _mime(path: str) -> str:
|
||||
ext = os.path.splitext(path)[1].lower()
|
||||
return {
|
||||
".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp",
|
||||
".gif": "image/gif", ".pdf": "application/pdf", ".mp3": "audio/mpeg", ".wav": "audio/wav",
|
||||
".m4a": "audio/mp4", ".mp4": "video/mp4", ".mov": "video/quicktime", ".mkv": "video/x-matroska",
|
||||
".avi": "video/x-msvideo", ".webm": "video/webm",
|
||||
".doc": "application/msword",
|
||||
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
".xls": "application/vnd.ms-excel",
|
||||
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
".ppt": "application/vnd.ms-powerpoint",
|
||||
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
".txt": "text/plain", ".srt": "application/x-subrip", ".json": "application/json",
|
||||
}.get(ext, "application/octet-stream")
|
||||
|
||||
|
||||
def _save_file(data: bytes, name_hint: str, headers=None) -> dict:
|
||||
name = name_hint
|
||||
cd = (headers or {}).get("Content-Disposition") or ""
|
||||
m = re.search(r"filename\*=UTF-8''([^;]+)", cd) or re.search(r'filename="([^"]+)"', cd)
|
||||
if m:
|
||||
name = urllib.parse.unquote(m.group(1))
|
||||
safe = re.sub(r"[^\w.\-]+", "_", name)[-80:] or "result.bin"
|
||||
if "." not in safe:
|
||||
safe += ".bin"
|
||||
fname = f"{time.strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:6]}-{safe}"
|
||||
with open(os.path.join(_files_dir(), fname), "wb") as f:
|
||||
f.write(data)
|
||||
return {"file": fname, "name": safe, "bytes": len(data), "url": f"/mcp/file/{fname}"}
|
||||
|
||||
|
||||
def _host_path(path: str) -> str:
|
||||
"""AI 客户端(与宿主同机)传宿主绝对路径(/vol1/…),relay 容器内经 /:/hostfs 挂载可达。"""
|
||||
if not path or not str(path).startswith("/"):
|
||||
return path
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
alt = "/hostfs" + path
|
||||
if os.path.isfile(alt):
|
||||
return alt
|
||||
return path
|
||||
|
||||
|
||||
def _read_file(path: str) -> bytes:
|
||||
path = _host_path(path)
|
||||
if not path or not os.path.isfile(path):
|
||||
raise RuntimeError(f"文件不存在: {path}")
|
||||
with open(path, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def _ok(data):
|
||||
return json.dumps({"ok": True, "data": data}, ensure_ascii=False, default=str)
|
||||
|
||||
|
||||
def _err(e):
|
||||
return json.dumps({"ok": False, "error": str(e)[:1500]}, ensure_ascii=False)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 13 个工具
|
||||
|
||||
def tool_translate_text(machine, text, source="auto", target="zh-CN"):
|
||||
q = urllib.parse.urlencode({"client": "gtx", "sl": source, "tl": target, "dt": "t", "q": text})
|
||||
status, _, raw = _req(_LOOPBACK, "GET", "/translate?" + q, _hdr(machine, "translator"), timeout=60)
|
||||
j = json.loads(_check(status, raw).decode("utf-8"))
|
||||
segs = j[0] if isinstance(j, list) and j else []
|
||||
return _ok({"text": "".join(s[0] for s in segs if isinstance(s, list) and s and s[0])})
|
||||
|
||||
|
||||
def tool_ocr(machine, path):
|
||||
path = _host_path(path)
|
||||
if path.lower().endswith(".pdf"):
|
||||
pages = _pdf_pages(path)
|
||||
result = []
|
||||
for fn, data in pages:
|
||||
body, ct = _multipart({}, [("image_file", fn, data, "image/jpeg")])
|
||||
status, _, raw = _req("http://host.docker.internal:5000", "POST", "/ocr",
|
||||
_hdr(machine, "pdf-ocr", ct), body, timeout=120)
|
||||
j = json.loads(_check(status, raw).decode("utf-8"))
|
||||
lines = [{"text": j[k].get("rec_txt", ""), "score": j[k].get("score", 0)}
|
||||
for k in sorted(j, key=lambda x: int(x)) if j[k].get("rec_txt")]
|
||||
result.append({"page": fn, "lines": lines})
|
||||
return _ok({"pages": len(result), "detail": result,
|
||||
"text": "\n".join(l["text"] for p in result for l in p["lines"])})
|
||||
data = _read_file(path)
|
||||
body, ct = _multipart({}, [("image_file", os.path.basename(path), data, _mime(path))])
|
||||
status, _, raw = _req("http://host.docker.internal:5000", "POST", "/ocr",
|
||||
_hdr(machine, "image-ocr", ct), body, timeout=120)
|
||||
j = json.loads(_check(status, raw).decode("utf-8"))
|
||||
lines = [{"text": j[k].get("rec_txt", ""), "score": j[k].get("score", 0)}
|
||||
for k in sorted(j, key=lambda x: int(x)) if j[k].get("rec_txt")]
|
||||
return _ok({"lines": lines, "text": "\n".join(l["text"] for l in lines)})
|
||||
|
||||
|
||||
def _pdf_pages(path, dpi=150):
|
||||
try:
|
||||
import subprocess
|
||||
tmp = os.path.join(_files_dir(), f".pdf-{uuid.uuid4().hex[:8]}")
|
||||
os.makedirs(tmp, exist_ok=True)
|
||||
proc = subprocess.run(["pdftoppm", "-jpeg", "-r", str(dpi), path, os.path.join(tmp, "p")],
|
||||
capture_output=True, timeout=120)
|
||||
if proc.returncode == 0:
|
||||
pages = []
|
||||
for fn in sorted(os.listdir(tmp)):
|
||||
if fn.endswith(".jpg"):
|
||||
with open(os.path.join(tmp, fn), "rb") as f:
|
||||
pages.append((fn, f.read()))
|
||||
if pages:
|
||||
return pages
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
import fitz
|
||||
except ImportError:
|
||||
raise RuntimeError("PDF 渲染组件缺失(需 pdftoppm 或 pymupdf)")
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
doc = fitz.open(stream=data, filetype="pdf")
|
||||
return [(f"page-{i + 1}.jpg", p.get_pixmap(dpi=dpi).tobytes("jpg")) for i, p in enumerate(doc)]
|
||||
|
||||
|
||||
def tool_translate_doc(machine, path, to="en"):
|
||||
data = _read_file(path)
|
||||
body, ct = _multipart({"to": to}, [("file", os.path.basename(path), data, _mime(path))])
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/translate-doc", _hdr(machine, "translator", ct),
|
||||
body, timeout=480)
|
||||
j = _json_api(status, raw)
|
||||
d = j.get("data") or {}
|
||||
return _ok({"text": d.get("text"), "chars": d.get("chars"), "target": to})
|
||||
|
||||
|
||||
def tool_tts(machine, text, voice="", rate="", pitch=""):
|
||||
body = json.dumps({"text": text, "voice": voice, "rate": rate, "pitch": pitch}).encode()
|
||||
status, hdrs, raw = _req(_LOOPBACK, "POST", "/tts", _hdr(machine, "audio-tools", "application/json"),
|
||||
body, timeout=180)
|
||||
_check(status, raw)
|
||||
if raw[:1] in (b"{", b"["):
|
||||
raise RuntimeError(json.loads(raw.decode("utf-8")).get("message") or "TTS 失败")
|
||||
return _ok(_save_file(raw, "tts.mp3", hdrs))
|
||||
|
||||
|
||||
def tool_speech_to_text(machine, path, language="auto"):
|
||||
data = _read_file(path)
|
||||
body, ct = _multipart({"language": language}, [("file", os.path.basename(path), data, _mime(path))])
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/asr", _hdr(machine, "audio-tools", ct), body, timeout=300)
|
||||
j = _json_api(status, raw)
|
||||
d = j.get("data") or {}
|
||||
return _ok({"text": d.get("text"), "language": d.get("language"), "segments": d.get("segments")})
|
||||
|
||||
|
||||
def tool_extract_subtitle(machine, path, lang=""):
|
||||
data = _read_file(path)
|
||||
body, ct = _multipart({}, [("file", os.path.basename(path), data, _mime(path))])
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/subtitle?lang=" + urllib.parse.quote(lang),
|
||||
_hdr(machine, "video-tools", ct), body, timeout=600)
|
||||
j = _json_api(status, raw)
|
||||
d = j.get("data") or {}
|
||||
return _ok({"segments": d.get("segments"), "language": d.get("language")})
|
||||
|
||||
|
||||
_VIDEO_OPS = ("convert", "gif", "gif2video", "compress", "trim", "rotate", "flip",
|
||||
"speed", "mute", "watermark", "unwatermark", "audio", "screenshot")
|
||||
|
||||
|
||||
def tool_video_process(machine, path, op, options=None):
|
||||
if op == "subtitle":
|
||||
return tool_extract_subtitle(machine, path)
|
||||
if op not in _VIDEO_OPS:
|
||||
raise RuntimeError(f"op 须为 {'/'.join(_VIDEO_OPS)} 或 subtitle")
|
||||
data = _read_file(path)
|
||||
fields = {"op": op}
|
||||
for k, v in (options or {}).items():
|
||||
fields[k] = str(v)
|
||||
body, ct = _multipart(fields, [("file", os.path.basename(path), data, _mime(path))])
|
||||
status, hdrs, raw = _req(_LOOPBACK, "POST", "/video", _hdr(machine, "video-tools", ct), body, timeout=600)
|
||||
_check(status, raw)
|
||||
if raw[:1] in (b"{", b"["):
|
||||
raise RuntimeError(json.loads(raw.decode("utf-8")).get("message") or "视频处理失败")
|
||||
return _ok(_save_file(raw, f"{op}-out.bin", hdrs))
|
||||
|
||||
|
||||
def tool_gen_image(machine, prompt, model="pollinations-flux", width=1024, height=1024):
|
||||
body = json.dumps({"machine": machine, "prompt": prompt, "model": model,
|
||||
"width": int(width), "height": int(height)}).encode()
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/ai/gen-image",
|
||||
_hdr(machine, "ai-gen", "application/json"), body, timeout=300)
|
||||
j = _json_api(status, raw)
|
||||
d = (j.get("data") or {}) if isinstance(j, dict) else {}
|
||||
if d.get("b64"):
|
||||
import base64
|
||||
b64 = d["b64"].split(",", 1)[-1]
|
||||
return _ok(_save_file(base64.b64decode(b64), "ai-gen.png"))
|
||||
if d.get("url"):
|
||||
req = urllib.request.Request(d["url"], headers={"User-Agent": "ittools-mcp/1.0"})
|
||||
with urllib.request.urlopen(req, timeout=120) as r:
|
||||
return _ok(_save_file(r.read(), "ai-gen.png", dict(r.headers)))
|
||||
raise RuntimeError("接口未返回图片数据")
|
||||
|
||||
|
||||
def tool_convert_doc(machine, path, format):
|
||||
data = _read_file(path)
|
||||
body, ct = _multipart({"format": format}, [("files", os.path.basename(path), data, _mime(path))])
|
||||
status, hdrs, raw = _req(_LOOPBACK, "POST", "/convert", _hdr(machine, "doc-convert", ct),
|
||||
body, timeout=300)
|
||||
_check(status, raw)
|
||||
if raw[:1] in (b"{", b"["):
|
||||
raise RuntimeError(json.loads(raw.decode("utf-8")).get("message") or "格式转换失败")
|
||||
return _ok(_save_file(raw, os.path.basename(path) + f".{format.lstrip('.')}", hdrs))
|
||||
|
||||
|
||||
def _raw_image_op(machine, path, api_path, ct_override=None, timeout=300):
|
||||
data = _read_file(path)
|
||||
status, hdrs, raw = _req(_LOOPBACK, "POST", api_path,
|
||||
_hdr(machine, "image-tools", ct_override or _mime(path)),
|
||||
data, timeout=timeout)
|
||||
_check(status, raw)
|
||||
if raw[:1] in (b"{", b"["):
|
||||
raise RuntimeError(json.loads(raw.decode("utf-8")).get("message") or "图片处理失败")
|
||||
ext = ".png" if raw[:8] == b"\x89PNG\r\n\x1a\n" else (".jpg" if raw[:2] == b"\xff\xd8" else ".webp")
|
||||
return _ok(_save_file(raw, "out" + ext, hdrs))
|
||||
|
||||
|
||||
def tool_remove_bg(machine, path):
|
||||
return _raw_image_op(machine, path, "/remove-bg", timeout=300)
|
||||
|
||||
|
||||
def tool_upscale_image(machine, path, scale=2, noise=1):
|
||||
if int(scale) not in (2, 4):
|
||||
raise RuntimeError("scale 仅支持 2 或 4")
|
||||
return _raw_image_op(machine, path, f"/upscale?scale={int(scale)}&noise={int(noise)}", timeout=400)
|
||||
|
||||
|
||||
_COPY_SCENES = ("rewrite", "deaigc", "titles", "xhs", "moments")
|
||||
|
||||
|
||||
def tool_copywriting(machine, text, scene="rewrite", model="mimo-v2.6-flash"):
|
||||
if scene not in _COPY_SCENES:
|
||||
raise RuntimeError(f"scene 须为 {'/'.join(_COPY_SCENES)}")
|
||||
body = json.dumps({"machine": machine, "scene": scene, "text": text, "model": model}).encode()
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/ai/copy", _hdr(machine, "", "application/json"),
|
||||
body, timeout=180)
|
||||
j = _json_api(status, raw)
|
||||
d = j.get("data") if isinstance(j, dict) else j
|
||||
if isinstance(d, dict) and (d.get("text") or d.get("reply")):
|
||||
return _ok({"text": d.get("text") or d.get("reply")})
|
||||
if isinstance(d, str):
|
||||
return _ok({"text": d})
|
||||
return _ok({"result": d})
|
||||
|
||||
|
||||
def tool_vision_qa(machine, image_path, question="描述这张图片的内容"):
|
||||
import base64
|
||||
data = _read_file(image_path)
|
||||
body = json.dumps({"machine": machine, "image": base64.b64encode(data).decode(),
|
||||
"question": question}).encode()
|
||||
status, _, raw = _req(_LOOPBACK, "POST", "/ai/vision", _hdr(machine, "image-tools", "application/json"),
|
||||
body, timeout=180)
|
||||
j = _json_api(status, raw)
|
||||
d = j.get("data") if isinstance(j, dict) else j
|
||||
if isinstance(d, dict) and (d.get("text") or d.get("answer") or d.get("reply")):
|
||||
return _ok({"answer": d.get("text") or d.get("answer") or d.get("reply")})
|
||||
if isinstance(d, str):
|
||||
return _ok({"answer": d})
|
||||
return _ok({"result": d})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 工具注册表
|
||||
|
||||
_S = {"type": "object"}
|
||||
TOOLS = [
|
||||
{"name": "translate_text", "fn": tool_translate_text,
|
||||
"description": "翻译一段文本(谷歌引擎,多语言互译)。",
|
||||
"inputSchema": {"type": "object", "properties": {
|
||||
"text": {"type": "string"}, "source": {"type": "string", "default": "auto"},
|
||||
"target": {"type": "string", "default": "zh-CN"}}, "required": ["text"]}},
|
||||
{"name": "ocr", "fn": tool_ocr,
|
||||
"description": "识别图片/PDF 中的文字,返回逐行文本与置信度(PDF 自动逐页)。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string", "description": "服务器可访问的文件路径或已上传文件名"}},
|
||||
"required": ["path"]}},
|
||||
{"name": "translate_doc", "fn": tool_translate_doc,
|
||||
"description": "整篇文档翻译(docx/pdf 等 → 译文全文),耗时可达数分钟。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"},
|
||||
"to": {"type": "string", "default": "en"}},
|
||||
"required": ["path"]}},
|
||||
{"name": "tts", "fn": tool_tts,
|
||||
"description": "文字合成语音,返回 mp3 下载 URL。",
|
||||
"inputSchema": {"type": "object", "properties": {"text": {"type": "string"},
|
||||
"voice": {"type": "string"}, "rate": {"type": "string"},
|
||||
"pitch": {"type": "string"}}, "required": ["text"]}},
|
||||
{"name": "speech_to_text", "fn": tool_speech_to_text,
|
||||
"description": "音频转文字(ASR),返回识别文本与时间分段。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"},
|
||||
"language": {"type": "string", "default": "auto"}},
|
||||
"required": ["path"]}},
|
||||
{"name": "extract_subtitle", "fn": tool_extract_subtitle,
|
||||
"description": "视频/音频 AI 字幕生成:输出带时间轴的识别分段。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"}, "lang": {"type": "string"}},
|
||||
"required": ["path"]}},
|
||||
{"name": "video_process", "fn": tool_video_process,
|
||||
"description": "视频批处理:转码/压缩/裁剪/旋转/翻转/调速/消音/加去水印/提取音频/截图/GIF 等。",
|
||||
"inputSchema": {"type": "object", "properties": {
|
||||
"path": {"type": "string"}, "op": {"type": "string", "enum": list(_VIDEO_OPS) + ["subtitle"]},
|
||||
"options": {"type": "object", "description": "按 op 传参:trim={start,end}; speed={speed}; rotate={angle}; flip={dir}; watermark={text}; unwatermark={x,y,w,h}; convert={format}; gif={fps,w,h}"}},
|
||||
"required": ["path", "op"]}},
|
||||
{"name": "gen_image", "fn": tool_gen_image,
|
||||
"description": "AI 文生图,返回图片下载 URL。",
|
||||
"inputSchema": {"type": "object", "properties": {"prompt": {"type": "string"},
|
||||
"model": {"type": "string", "default": "pollinations-flux"},
|
||||
"width": {"type": "integer", "default": 1024},
|
||||
"height": {"type": "integer", "default": 1024}},
|
||||
"required": ["prompt"]}},
|
||||
{"name": "convert_doc", "fn": tool_convert_doc,
|
||||
"description": "文档格式转换(pdf/docx/xlsx/pptx 互转等),返回结果下载 URL。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"},
|
||||
"format": {"type": "string"}}, "required": ["path", "format"]}},
|
||||
{"name": "remove_bg", "fn": tool_remove_bg,
|
||||
"description": "图片抠图去背景,输出透明底 PNG 下载 URL。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}},
|
||||
{"name": "upscale_image", "fn": tool_upscale_image,
|
||||
"description": "图片超分辨率放大(2x/4x)并降噪。",
|
||||
"inputSchema": {"type": "object", "properties": {"path": {"type": "string"},
|
||||
"scale": {"type": "integer", "default": 2},
|
||||
"noise": {"type": "integer", "default": 1}},
|
||||
"required": ["path"]}},
|
||||
{"name": "copywriting", "fn": tool_copywriting,
|
||||
"description": "文案工具箱:改写/降AIGC率/爆款标题/小红书笔记/朋友圈文案。",
|
||||
"inputSchema": {"type": "object", "properties": {
|
||||
"text": {"type": "string"}, "scene": {"type": "string", "enum": list(_COPY_SCENES)},
|
||||
"model": {"type": "string", "default": "mimo-v2.6-flash"}}, "required": ["text", "scene"]}},
|
||||
{"name": "vision_qa", "fn": tool_vision_qa,
|
||||
"description": "看图问答:描述图片内容/提取图中信息/判断图片状态。",
|
||||
"inputSchema": {"type": "object", "properties": {"image_path": {"type": "string"},
|
||||
"question": {"type": "string"}},
|
||||
"required": ["image_path"]}},
|
||||
]
|
||||
TOOLS_MAP = {t["name"]: t for t in TOOLS}
|
||||
|
||||
|
||||
def tools_schema() -> list:
|
||||
return [{k: t[k] for k in ("name", "description", "inputSchema")} for t in TOOLS]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- JSON-RPC
|
||||
|
||||
def _public_base(handler) -> str:
|
||||
if _CTX.get("public_base"):
|
||||
return _CTX["public_base"].rstrip("/")
|
||||
host = handler.headers.get("Host", "") or "it.88531.cn"
|
||||
# 带端口的内网访问走 http,否则公网 https
|
||||
scheme = "http" if ":" in host else "https"
|
||||
return f"{scheme}://{host}"
|
||||
|
||||
|
||||
def _rpc_result(rid, result):
|
||||
return {"jsonrpc": "2.0", "id": rid, "result": result}
|
||||
|
||||
|
||||
def _rpc_error(rid, code, message):
|
||||
return {"jsonrpc": "2.0", "id": rid, "error": {"code": code, "message": message}}
|
||||
|
||||
|
||||
def _handle_rpc(req: dict, token_rec: dict | None, handler) -> dict | None:
|
||||
"""处理单个 JSON-RPC 请求;notification 返回 None。"""
|
||||
method = req.get("method")
|
||||
rid = req.get("id")
|
||||
params = req.get("params") or {}
|
||||
|
||||
if method in ("notifications/initialized", "notifications/cancelled", "notifications/roots/list_changed"):
|
||||
return None
|
||||
if rid is None and method and method.startswith("notifications/"):
|
||||
return None
|
||||
if method == "ping":
|
||||
return _rpc_result(rid, {})
|
||||
if method == "initialize":
|
||||
return _rpc_result(rid, {
|
||||
"protocolVersion": params.get("protocolVersion", "2025-06-18"),
|
||||
"capabilities": {"tools": {}},
|
||||
"serverInfo": {"name": "it-tools-pro", "version": "1.0.0",
|
||||
"title": "IT-TOOLS-PRO 授权应用 MCP"},
|
||||
"instructions": "本站 13 个授权工具的 MCP 入口。文件类入参传服务器可见的文件路径;"
|
||||
"结果中的 url 字段为可下载地址(需同款 Bearer 令牌)。",
|
||||
})
|
||||
if method == "tools/list":
|
||||
return _rpc_result(rid, {"tools": tools_schema()})
|
||||
if method == "tools/call":
|
||||
if not token_rec:
|
||||
return _rpc_error(rid, -32001, "未授权:请在请求头携带 Authorization: Bearer <MCP令牌>(站内「MCP 接入」页购买卡密后生成)")
|
||||
machine = token_rec.get("machine") or ""
|
||||
if not _authorized(machine):
|
||||
return _rpc_error(rid, -32001, "授权已失效:卡密过期或设备授权撤销,请重新激活")
|
||||
name = params.get("name")
|
||||
args = params.get("arguments") or {}
|
||||
tool = TOOLS_MAP.get(name)
|
||||
if not tool:
|
||||
return _rpc_error(rid, -32602, f"unknown tool: {name}")
|
||||
if name in ("ocr", "translate_doc", "tts", "speech_to_text", "extract_subtitle",
|
||||
"video_process", "convert_doc", "remove_bg", "upscale_image", "vision_qa"):
|
||||
# 文件类入参:允许直接传文件名(mcp_files 内已上传文件)或绝对路径
|
||||
for key in ("path", "image_path"):
|
||||
if key in args and args[key] and not os.path.isabs(str(args[key])):
|
||||
cand = os.path.join(_files_dir(), os.path.basename(str(args[key])))
|
||||
if os.path.isfile(cand):
|
||||
args[key] = cand
|
||||
t0 = time.time()
|
||||
ok, err = True, ""
|
||||
try:
|
||||
text = tool["fn"](machine, **args)
|
||||
except Exception as e: # noqa: BLE001
|
||||
text, ok, err = _err(e), False, str(e)
|
||||
dur = int((time.time() - t0) * 1000)
|
||||
log_mcp((token_rec.get("token") or "")[-6:], machine, name, ok, err, dur)
|
||||
_touch_token(token_rec.get("token") or "")
|
||||
# 下载 URL 补全域前缀
|
||||
try:
|
||||
obj = json.loads(text)
|
||||
base = _public_base(handler)
|
||||
|
||||
def _abs(o):
|
||||
if isinstance(o, dict):
|
||||
return {k: (base + v if k == "url" and isinstance(v, str) and v.startswith("/mcp/") else _abs(v))
|
||||
for k, v in o.items()}
|
||||
if isinstance(o, list):
|
||||
return [_abs(x) for x in o]
|
||||
return o
|
||||
text = json.dumps(_abs(obj), ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
return _rpc_result(rid, {"content": [{"type": "text", "text": text}], "isError": not ok})
|
||||
return _rpc_error(rid, -32601, f"method not found: {method}")
|
||||
|
||||
|
||||
def handle_post(handler) -> tuple[int, bytes, str]:
|
||||
"""POST /mcp —— 返回 (status, body, content_type)。"""
|
||||
try:
|
||||
length = int(handler.headers.get("Content-Length") or 0)
|
||||
except ValueError:
|
||||
length = 0
|
||||
raw = handler.rfile.read(length) if length else b"{}"
|
||||
try:
|
||||
payload = json.loads(raw.decode("utf-8") or "{}")
|
||||
except Exception:
|
||||
return 400, json.dumps({"jsonrpc": "2.0", "id": None,
|
||||
"error": {"code": -32700, "message": "parse error"}},
|
||||
ensure_ascii=False).encode(), "application/json"
|
||||
|
||||
tok = _bearer(handler)
|
||||
token_rec = _find_token(tok)
|
||||
# initialize/tools/list 免鉴权(发现能力),tools/call 必须有效令牌
|
||||
requests = payload if isinstance(payload, list) else [payload]
|
||||
needs_auth = any(isinstance(r, dict) and r.get("method") == "tools/call" for r in requests)
|
||||
if needs_auth and not token_rec:
|
||||
return 401, json.dumps({"error": "unauthorized",
|
||||
"message": "缺少或无效的 MCP 令牌(Authorization: Bearer mcpt_…)"},
|
||||
ensure_ascii=False).encode(), "application/json"
|
||||
|
||||
out = []
|
||||
for r in requests:
|
||||
if not isinstance(r, dict):
|
||||
continue
|
||||
resp = _handle_rpc(r, token_rec, handler)
|
||||
if resp is not None:
|
||||
out.append(resp)
|
||||
if not out:
|
||||
return 202, b"", "application/json"
|
||||
body = out[0] if len(out) == 1 else out
|
||||
return 200, json.dumps(body, ensure_ascii=False).encode("utf-8"), "application/json"
|
||||
|
||||
|
||||
def handle_get_file(handler, fname: str):
|
||||
"""GET /mcp/file/<name> —— 令牌鉴权后提供结果文件下载。"""
|
||||
tok = _bearer(handler)
|
||||
if not _find_token(tok):
|
||||
handler.send_response(401)
|
||||
handler.send_header("Content-Type", "application/json")
|
||||
handler.end_headers()
|
||||
handler.wfile.write(b'{"error":"unauthorized"}')
|
||||
return
|
||||
safe = os.path.basename(fname)
|
||||
path = os.path.join(_files_dir(), safe)
|
||||
if not os.path.isfile(path):
|
||||
handler.send_response(404)
|
||||
handler.end_headers()
|
||||
handler.wfile.write(b'{"error":"not found"}')
|
||||
return
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
handler.send_response(200)
|
||||
handler.send_header("Content-Type", "application/octet-stream")
|
||||
handler.send_header("Content-Length", str(len(data)))
|
||||
handler.send_header("Content-Disposition",
|
||||
f'attachment; filename="{safe}"; filename*=UTF-8\'\'{urllib.parse.quote(safe)}')
|
||||
handler.end_headers()
|
||||
handler.wfile.write(data)
|
||||
+2318
-62
File diff suppressed because it is too large.
Load diff
+14
-3
@@ -179,6 +179,9 @@ tools:
|
||||
title: BIP39 passphrase generator
|
||||
description: Generate a BIP39 passphrase from an existing or random mnemonic, or get the mnemonic from the passphrase.
|
||||
|
||||
base64-image-converter:
|
||||
title: Base64 Image Converter
|
||||
description: "Base64 to image and image to Base64 in one page - accepts bare string / data:URI / CSS url(), sniffs image type from magic bytes, fully local in your browser."
|
||||
base64-file-converter:
|
||||
title: Base64 file converter
|
||||
description: Convert a string, file, or image into its base64 representation.
|
||||
@@ -269,7 +272,11 @@ tools:
|
||||
|
||||
translator:
|
||||
title: Translator
|
||||
description: Translate text between 16 languages (Chinese, English, Japanese, Korean, French, ...) with automatic language detection, powered by Google Translate with a MyMemory fallback.
|
||||
description: Text translation in 16 languages with automatic detection - Chinese/English runs on a local open-source engine (no rate limits), other languages automatically fall back to MyMemory. Full-document translation (Chinese/English); scanned PDFs and images are OCR-recognized before translation.
|
||||
|
||||
mcp-connect:
|
||||
title: 'MCP Connect (let AI call site tools)'
|
||||
description: 'Let Claude, Hermes and other MCP clients call the 13 licensed tools directly (translate, OCR, image gen, video processing and more). See the setup guide, create and manage access tokens; a purchase link is shown until a card is activated.'
|
||||
|
||||
image-ocr:
|
||||
title: Image OCR
|
||||
@@ -302,7 +309,7 @@ tools:
|
||||
|
||||
code-reader:
|
||||
title: QR & barcode reader
|
||||
description: Upload, drag & drop or paste an image to decode QR codes and barcodes in one shot (multiple codes supported). Decoding runs locally via WASM - images never leave your browser.
|
||||
description: "Read: decode QR codes and barcodes from upload/drag/paste (multiple codes, local WASM, images never leave your browser). Generate: custom foreground/background colors, local image logo in the center, self-scan verification, PNG download."
|
||||
|
||||
doc-convert:
|
||||
title: Document converter
|
||||
@@ -310,7 +317,7 @@ tools:
|
||||
|
||||
image-tools:
|
||||
title: Image tools
|
||||
description: "In-browser image toolbox: compress, convert, resize, crop, rotate, filters, mosaic/redaction, EXIF viewer, QR generate/scan, watermark and stitching. Images never leave your device."
|
||||
description: "In-browser image toolbox: compress, convert, resize, crop, rotate, filters, mosaic/redaction, Photoshop-style editor (layers, brush, text, selection, OCR text replacement, 47 full-copy artistic text templates (7 categories: general/XHS/Douyin/Bilibili/WeChat/Channels/Cover) with canvas rotation, content-aware erase with live preview), EXIF viewer, QR generate/scan, watermark and stitching. Images never leave your device."
|
||||
|
||||
pdf-tools:
|
||||
title: PDF tools
|
||||
@@ -380,6 +387,10 @@ tools:
|
||||
title: IPv6 ULA generator
|
||||
description: Generate your own local, non-routable IP addresses for your network according to RFC4193.
|
||||
|
||||
my-ip:
|
||||
title: My IP address
|
||||
description: Check your device's public IPv4/IPv6 address and location (with an IPv6 setup guide when unsupported). Detects proxy/VPN via egress IP database and WebRTC leak test. This site supports IPv6 direct connection. Measure latency to popular places and test your download/upload speed to this server with history.
|
||||
|
||||
hash-text:
|
||||
title: Hash text
|
||||
description: 'Hash a text string using the function you need : MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3 or RIPEMD160'
|
||||
|
||||
+14
-3
@@ -177,6 +177,9 @@ tools:
|
||||
title: BIP39密码生成器
|
||||
description: 从现有或随机助记符生成BIP39密码短语,或从密码短语获取助记符。
|
||||
|
||||
base64-image-converter:
|
||||
title: Base64图片互转
|
||||
description: Base64转图片与图片转Base64合一页:三种输入格式(裸串/data:URI/CSS url())自动识别,图片类型魔数嗅探,纯浏览器本地处理不上传。
|
||||
base64-file-converter:
|
||||
title: Base64 文件转换器
|
||||
description: 将字符串、文件或图像转换为其 Base64 表示形式。
|
||||
@@ -266,7 +269,11 @@ tools:
|
||||
|
||||
translator:
|
||||
title: 在线翻译
|
||||
description: 支持中英日韩法德等16种语言互译,自动检测源语言,谷歌翻译主线路 + MyMemory 备用线路,修改文本自动翻译。
|
||||
description: 文本翻译支持中英日韩法德等 16 种语言,自动识别源语言:中英互译走本地开源引擎不限流,其他语种自动切 MyMemory 备用线路;文档整篇翻译(中英),扫描件/图片自动 OCR 识别后翻译,修改文本自动翻译。
|
||||
|
||||
mcp-connect:
|
||||
title: MCP 接入(AI 调用本站工具)
|
||||
description: 让 Claude、Hermes 等 AI 客户端通过 MCP 协议直接调用本站 13 个授权工具(翻译、OCR、生图、视频处理等);查看接入教程、生成与管理调用令牌,未购买卡密时提供购买入口。
|
||||
|
||||
image-ocr:
|
||||
title: 图片OCR文字识别
|
||||
@@ -299,7 +306,7 @@ tools:
|
||||
|
||||
code-reader:
|
||||
title: 二维码条码识别
|
||||
description: 上传、拖拽或粘贴图片,一键识别图中的二维码和条形码(支持多码混合、批量输出),本地 WASM 解码,图片不上传服务器。
|
||||
description: 识别:上传/拖拽/粘贴图片一键解码二维码和条形码(多码混合、批量输出,本地 WASM 解码不上传);生成:自定义前景/背景颜色、中间插入本地图片 Logo,生成后自动自扫验证,可下载 PNG。
|
||||
|
||||
doc-convert:
|
||||
title: 文档格式转换
|
||||
@@ -307,7 +314,7 @@ tools:
|
||||
|
||||
image-tools:
|
||||
title: 图片工具
|
||||
description: 浏览器本地处理的图片工具箱:图片压缩、格式转换、调整尺寸、裁剪、旋转、滤镜、打码、EXIF 查看、二维码生成/识别、加水印、多图拼接,图片全程不上传。
|
||||
description: 浏览器本地处理的图片工具箱:图片压缩、格式转换、调整尺寸、裁剪、旋转、滤镜、打码、PS 风格图片编辑(图层/画笔/文字/选区/OCR 改字/47套成套文案花字模板(通用/小红书/抖音/B站/公众号/视频号/封面图7类)+画布旋转拖角缩放/智能消除笔实时预览无痕去文字水印、OCR无痕改字(自动匹配原字字号/颜色/角度))、EXIF 查看、二维码生成/识别、加水印、多图拼接,图片全程不上传。
|
||||
|
||||
pdf-tools:
|
||||
title: PDF工具
|
||||
@@ -376,6 +383,10 @@ tools:
|
||||
title: IPv6 ULA生成器
|
||||
description: 根据RFC4193在网络上生成您自己的本地不可路由IP地址。
|
||||
|
||||
my-ip:
|
||||
title: 本机IP查询
|
||||
description: 查询你设备的公网IPv4/IPv6地址与所属地(IPv6不支持时提供开启教程),代理/VPN检测(出口IP归属判定+WebRTC泄漏实测),热门地点延迟实测(百度、本省运营商门户、全国镜像站与海外节点),测速历史自动记录延迟快照,本站已支持IPv6直连,一键测试你到本站服务器的下载/上传网速。
|
||||
|
||||
hash-text:
|
||||
title: Hash 文本
|
||||
description: '使用所需的函数哈希文本字符串:MD5、SHA1、SHA256、SHA224、SHA512、SHA384、SHA3或RIPEMD160'
|
||||
|
||||
+56
@@ -17,9 +17,40 @@ server {
|
||||
proxy_read_timeout 10s;
|
||||
}
|
||||
|
||||
# admin console SPA route (exact match beats the /admin/ API prefix below,
|
||||
# otherwise nginx 301s /admin -> /admin/ and the API proxy swallows the UI)
|
||||
location = /admin {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
|
||||
# admin console API (relay does its own Bearer auth; must beat SPA fallback)
|
||||
location /admin/ {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://it-tools-relay:8091;
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_read_timeout 30s;
|
||||
}
|
||||
|
||||
# MCP endpoint (JSON-RPC streamable HTTP + result file download).
|
||||
# Relay does its own Bearer-token auth here — no auth_request subrequest.
|
||||
# Boundary regex: must NOT swallow the /mcp-connect SPA page (prefix /mcp would).
|
||||
location ~ ^/mcp(/|$) {
|
||||
client_max_body_size 60m;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://it-tools-relay:8091;
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
}
|
||||
|
||||
# license relay (card activation etc; auth gate itself must stay open)
|
||||
location /relay/ {
|
||||
client_max_body_size 2g;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://it-tools-relay:8091/;
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_read_timeout 600s;
|
||||
@@ -62,7 +93,32 @@ server {
|
||||
proxy_read_timeout 30s;
|
||||
}
|
||||
|
||||
# ---- SPA shell & service worker: MUST revalidate every load ----
|
||||
# Without this header browsers heuristically cache index.html/sw.js and the
|
||||
# PWA keeps serving a stale precache after deploys (2026-10-30: users were
|
||||
# stuck on an old my-ip page that leaked the server egress IP).
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, must-revalidate";
|
||||
try_files $uri =404;
|
||||
}
|
||||
location = /sw.js {
|
||||
add_header Cache-Control "no-cache, must-revalidate";
|
||||
add_header Service-Worker-Allowed "/";
|
||||
try_files $uri =404;
|
||||
}
|
||||
location = /manifest.webmanifest {
|
||||
add_header Cache-Control "no-cache, must-revalidate";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# hashed build assets are content-addressed: cache forever
|
||||
location /assets/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
add_header Cache-Control "no-cache, must-revalidate";
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,11 @@ function expandAll() {
|
||||
for (const { name } of toolsByCategory.value) {
|
||||
m[name] = false;
|
||||
}
|
||||
// 我的收藏 / 授权应用 也在渲染菜单里,必须一起收放(2026-11-13 用户要求)
|
||||
if (props.favoriteCategory?.name) {
|
||||
m[props.favoriteCategory.name] = false;
|
||||
}
|
||||
m[PAID_GROUP_NAME] = false;
|
||||
collapsedCategories.value = m;
|
||||
}
|
||||
|
||||
@@ -52,6 +57,11 @@ function collapseAll() {
|
||||
for (const { name } of toolsByCategory.value) {
|
||||
m[name] = true;
|
||||
}
|
||||
// 我的收藏 / 授权应用 也在渲染菜单里,必须一起收放(2026-11-13 用户要求)
|
||||
if (props.favoriteCategory?.name) {
|
||||
m[props.favoriteCategory.name] = true;
|
||||
}
|
||||
m[PAID_GROUP_NAME] = true;
|
||||
collapsedCategories.value = m;
|
||||
}
|
||||
|
||||
@@ -183,6 +193,13 @@ const themeVars = useThemeVars();
|
||||
}
|
||||
|
||||
.menu-actions {
|
||||
// 滚动侧栏时吸顶固定,展开/收起全部始终可见。
|
||||
// top 对齐 hero 固定区高度(160px,与 .sider-content padding-top 配套),避免被 z-index:10 的 hero 盖住
|
||||
position: sticky;
|
||||
top: 160px;
|
||||
z-index: 5;
|
||||
background: var(--n-color, #fff);
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { useMessage } from 'naive-ui';
|
||||
|
||||
// 站内留言反馈弹窗(与授权系统无关,任何人可提交)
|
||||
const props = defineProps<{ show: boolean }>();
|
||||
const emit = defineEmits<{ (e: 'update:show', v: boolean): void }>();
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
const TYPES = ['功能建议', '意见反馈'];
|
||||
const typeOptions = TYPES.map(t => ({ label: t, value: t }));
|
||||
|
||||
const type = ref('功能建议');
|
||||
const content = ref('');
|
||||
const contact = ref('');
|
||||
const captchaId = ref('');
|
||||
const captchaImg = ref('');
|
||||
const captchaCode = ref('');
|
||||
const err = ref('');
|
||||
const submitting = ref(false);
|
||||
|
||||
function close() {
|
||||
emit('update:show', false);
|
||||
}
|
||||
|
||||
async function loadCaptcha() {
|
||||
try {
|
||||
const res = await fetch('/relay/feedback/captcha');
|
||||
const b = await res.json();
|
||||
if (b.code === 200) {
|
||||
captchaId.value = b.data.id;
|
||||
captchaImg.value = `data:image/png;base64,${b.data.img}`;
|
||||
err.value = '';
|
||||
}
|
||||
else {
|
||||
captchaImg.value = '';
|
||||
err.value = b.message || '验证码加载失败';
|
||||
}
|
||||
}
|
||||
catch {
|
||||
captchaImg.value = '';
|
||||
err.value = '网络异常,验证码加载失败';
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.show, (v) => {
|
||||
if (v) {
|
||||
err.value = '';
|
||||
captchaCode.value = '';
|
||||
loadCaptcha();
|
||||
}
|
||||
});
|
||||
|
||||
async function submit() {
|
||||
if (submitting.value) {
|
||||
return;
|
||||
}
|
||||
if (!content.value.trim()) {
|
||||
err.value = '请填写留言内容';
|
||||
return;
|
||||
}
|
||||
if (!captchaCode.value.trim()) {
|
||||
err.value = '请输入图形验证码';
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
err.value = '';
|
||||
try {
|
||||
const res = await fetch('/relay/feedback', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
type: type.value,
|
||||
content: content.value,
|
||||
contact: contact.value,
|
||||
captcha_id: captchaId.value,
|
||||
captcha_code: captchaCode.value,
|
||||
}),
|
||||
});
|
||||
const b = await res.json().catch(() => ({} as any));
|
||||
if (b.code === 200) {
|
||||
message.success('提交成功,我们会通过你留的联系方式回复');
|
||||
content.value = '';
|
||||
contact.value = '';
|
||||
captchaCode.value = '';
|
||||
close();
|
||||
return;
|
||||
}
|
||||
err.value = b.message || `提交失败(${res.status})`;
|
||||
// 验证码一次性:除了限频(429)以外都换一张,避免用户对着旧码重试
|
||||
if (res.status !== 429) {
|
||||
loadCaptcha();
|
||||
captchaCode.value = '';
|
||||
}
|
||||
}
|
||||
catch {
|
||||
err.value = '网络异常,请稍后重试';
|
||||
}
|
||||
finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-modal
|
||||
:show="show"
|
||||
preset="card"
|
||||
class="fb-modal"
|
||||
title="💬 留言反馈"
|
||||
:style="{ width: 'min(580px, 94vw)' }"
|
||||
:bordered="false"
|
||||
@update:show="(v: boolean) => emit('update:show', v)"
|
||||
>
|
||||
<div class="fb-hint">与授权系统无关,任何人都可以留言;内容我们会在后台查看,留了联系方式会回复你。</div>
|
||||
|
||||
<div class="fb-row">
|
||||
<label class="fb-label">留言类型</label>
|
||||
<n-select v-model:value="type" :options="typeOptions" size="medium" />
|
||||
</div>
|
||||
|
||||
<div class="fb-row">
|
||||
<label class="fb-label">留言内容 <i>*</i></label>
|
||||
<n-input
|
||||
v-model:value="content"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
maxlength="1000"
|
||||
show-count
|
||||
placeholder="请描述你的功能建议或遇到的问题,越具体越好…"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="fb-row">
|
||||
<label class="fb-label">联系方式(可选)</label>
|
||||
<n-input
|
||||
v-model:value="contact"
|
||||
:maxlength="64"
|
||||
placeholder="QQ / 微信 / 邮箱,方便我们回复你"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="fb-row">
|
||||
<label class="fb-label">图形验证码 <i>*</i></label>
|
||||
<div class="fb-captcha-line">
|
||||
<n-input
|
||||
v-model:value="captchaCode"
|
||||
:maxlength="4"
|
||||
placeholder="4 位字符"
|
||||
class="fb-captcha-input"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<img
|
||||
v-if="captchaImg"
|
||||
class="fb-captcha-img"
|
||||
:src="captchaImg"
|
||||
alt="图形验证码"
|
||||
title="点击换一张"
|
||||
@click="loadCaptcha"
|
||||
>
|
||||
<span v-else class="fb-captcha-img fb-captcha-loading" @click="loadCaptcha">加载中…</span>
|
||||
<span class="fb-captcha-refresh" role="button" tabindex="0" @click="loadCaptcha">换一张</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="err" class="fb-err">{{ err }}</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="fb-foot">
|
||||
<span class="fb-limit">同一 IP 一小时内限提交 1 次</span>
|
||||
<span class="fb-foot-btns">
|
||||
<n-button quaternary @click="close">取消</n-button>
|
||||
<n-button type="primary" :loading="submitting" @click="submit">提交留言</n-button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</template>
|
||||
|
||||
<!-- n-modal 会 teleport 到 body,故这里用非 scoped 样式(类名统一 fb- 前缀) -->
|
||||
<style lang="less">
|
||||
.fb-modal {
|
||||
.fb-hint {
|
||||
font-size: 14.5px;
|
||||
line-height: 1.6;
|
||||
opacity: 0.75;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.fb-row {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.fb-label {
|
||||
display: block;
|
||||
font-size: 14.5px;
|
||||
margin-bottom: 6px;
|
||||
|
||||
i {
|
||||
color: #e0115f;
|
||||
font-style: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.fb-captcha-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.fb-captcha-input {
|
||||
width: 140px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.fb-captcha-img {
|
||||
height: 40px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
padding: 0 12px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14.5px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.fb-captcha-refresh {
|
||||
font-size: 14.5px;
|
||||
cursor: pointer;
|
||||
opacity: 0.8;
|
||||
text-decoration: underline;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.fb-err {
|
||||
margin-top: 10px;
|
||||
font-size: 14.5px;
|
||||
color: #d03050;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.fb-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.fb-limit {
|
||||
font-size: 14px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.fb-foot-btns {
|
||||
display: inline-flex;
|
||||
gap: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+49
-67
@@ -7,76 +7,34 @@ import { useCloudSync } from '@/composable/cloud-sync';
|
||||
const { isLoggedIn, username, isAdmin, login, register, logout } = useUserAuth();
|
||||
const { syncNow } = useCloudSync();
|
||||
|
||||
// ---- Cloudflare Turnstile ----
|
||||
const CF_SITEKEY = '0x4AAAAAAFUO0U-CvL78Vr6y';
|
||||
const cfToken = ref('');
|
||||
const cfReady = ref(false);
|
||||
let cfWidgetId = '';
|
||||
// ---- 本地图片验证码(服务端出图,不依赖外网) ----
|
||||
const captchaId = ref('');
|
||||
const captchaImg = ref('');
|
||||
const captchaCode = ref('');
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
turnstile?: any;
|
||||
__cfOnload?: () => void;
|
||||
}
|
||||
}
|
||||
|
||||
function loadTurnstileScript(): Promise<void> {
|
||||
if (window.turnstile) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
window.__cfOnload = () => resolve();
|
||||
const s = document.createElement('script');
|
||||
s.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=__cfOnload&render=explicit';
|
||||
s.async = true;
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
}
|
||||
|
||||
function resetCf() {
|
||||
cfToken.value = '';
|
||||
if (window.turnstile && cfWidgetId) {
|
||||
try {
|
||||
window.turnstile.reset(cfWidgetId);
|
||||
async function loadCaptcha() {
|
||||
captchaCode.value = '';
|
||||
try {
|
||||
const res = await fetch('/relay/user/captcha');
|
||||
const body = await res.json().catch(() => ({} as any));
|
||||
if (body?.code === 200 && body.data?.id) {
|
||||
captchaId.value = body.data.id;
|
||||
captchaImg.value = `data:image/png;base64,${body.data.img}`;
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
async function mountCf() {
|
||||
await loadTurnstileScript();
|
||||
// wait until container is in DOM (modal just opened)
|
||||
await new Promise(r => setTimeout(r, 80));
|
||||
const el = document.querySelector('.cf-container');
|
||||
if (!el || cfWidgetId) {
|
||||
return;
|
||||
}
|
||||
cfWidgetId = window.turnstile.render(el as HTMLElement, {
|
||||
sitekey: CF_SITEKEY,
|
||||
theme: 'light',
|
||||
size: 'flexible',
|
||||
callback: (token: string) => {
|
||||
cfToken.value = token;
|
||||
},
|
||||
'expired-callback': () => {
|
||||
cfToken.value = '';
|
||||
},
|
||||
'error-callback': () => {
|
||||
cfToken.value = '';
|
||||
},
|
||||
});
|
||||
cfReady.value = true;
|
||||
catch { /* 静默:提交时服务端会再校验 */ }
|
||||
}
|
||||
|
||||
const showLogin = ref(false);
|
||||
|
||||
watch(showLogin, (v) => {
|
||||
if (v) {
|
||||
mountCf().catch(() => {});
|
||||
loadCaptcha().catch(() => {});
|
||||
}
|
||||
else {
|
||||
cfWidgetId = '';
|
||||
cfToken.value = '';
|
||||
captchaId.value = '';
|
||||
captchaImg.value = '';
|
||||
captchaCode.value = '';
|
||||
}
|
||||
});
|
||||
const mode = ref<'login' | 'register'>('login');
|
||||
@@ -105,10 +63,10 @@ async function submit() {
|
||||
busy.value = true;
|
||||
try {
|
||||
if (mode.value === 'login') {
|
||||
await login(formUser.value.trim(), formPass.value, cfToken.value);
|
||||
await login(formUser.value.trim(), formPass.value, captchaId.value, captchaCode.value.trim());
|
||||
}
|
||||
else {
|
||||
await register(formUser.value.trim(), formPass.value, cfToken.value);
|
||||
await register(formUser.value.trim(), formPass.value, captchaId.value, captchaCode.value.trim());
|
||||
}
|
||||
showLogin.value = false;
|
||||
formPass.value = '';
|
||||
@@ -119,7 +77,8 @@ async function submit() {
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
resetCf();
|
||||
// 验证码单次有效,失败后必须换一张
|
||||
loadCaptcha().catch(() => {});
|
||||
}
|
||||
finally {
|
||||
busy.value = false;
|
||||
@@ -182,8 +141,10 @@ function switchMode() {
|
||||
<input v-model="formPass" class="user-input" type="password" placeholder="密码(至少 6 位)" :autocomplete="mode === 'login' ? 'current-password' : 'new-password'" @keyup.enter="submit">
|
||||
<input v-if="mode === 'register'" v-model="formPass2" class="user-input" type="password" placeholder="确认密码" autocomplete="new-password" @keyup.enter="submit">
|
||||
|
||||
<div class="cf-wrap" :style="{ opacity: cfToken ? 0.4 : 1 }">
|
||||
<div class="cf-container" />
|
||||
<div class="captcha-row">
|
||||
<input v-model="captchaCode" class="user-input captcha-input" placeholder="验证码(4位)" autocomplete="off" @keyup.enter="submit">
|
||||
<img v-if="captchaImg" class="captcha-img" :src="captchaImg" alt="验证码" title="点击换一张" @click="loadCaptcha">
|
||||
<a v-else href="javascript:;" class="captcha-reload" @click="loadCaptcha">获取验证码</a>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="user-error">
|
||||
@@ -198,7 +159,7 @@ function switchMode() {
|
||||
<c-button size="small" @click="showLogin = false">
|
||||
取消
|
||||
</c-button>
|
||||
<c-button size="small" type="primary" ml-8px :disabled="busy || !formUser || !formPass || !cfToken" @click="submit">
|
||||
<c-button size="small" type="primary" ml-8px :disabled="busy || !formUser || !formPass || !captchaCode.trim() || !captchaId" @click="submit">
|
||||
{{ busy ? '请稍候…' : (mode === 'login' ? '登录' : '注册并登录') }}
|
||||
</c-button>
|
||||
</div>
|
||||
@@ -263,9 +224,30 @@ function switchMode() {
|
||||
}
|
||||
}
|
||||
|
||||
.cf-wrap {
|
||||
.captcha-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin: 2px 0 8px;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
.captcha-input {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.captcha-img {
|
||||
height: 40px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.captcha-reload {
|
||||
flex-shrink: 0;
|
||||
font-size: 13px;
|
||||
color: #18a058;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.user-mask {
|
||||
|
||||
@@ -52,11 +52,11 @@ export function useUserAuth() {
|
||||
const username = computed(() => state.value?.username ?? '');
|
||||
const isAdmin = computed(() => state.value?.role === 'admin');
|
||||
|
||||
async function login(u: string, p: string, cfToken = '') {
|
||||
async function login(u: string, p: string, captchaId = '', captchaCode = '') {
|
||||
const { status, body } = await apiFetch('/user/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders() },
|
||||
body: JSON.stringify({ username: u, password: p, cf_token: cfToken }),
|
||||
body: JSON.stringify({ username: u, password: p, captcha_id: captchaId, captcha_code: captchaCode }),
|
||||
});
|
||||
if (status !== 200) {
|
||||
throw new Error(body.message || '登录失败');
|
||||
@@ -66,11 +66,11 @@ export function useUserAuth() {
|
||||
return body.data.username;
|
||||
}
|
||||
|
||||
async function register(u: string, p: string, cfToken = '') {
|
||||
async function register(u: string, p: string, captchaId = '', captchaCode = '') {
|
||||
const { status, body } = await apiFetch('/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders() },
|
||||
body: JSON.stringify({ username: u, password: p, cf_token: cfToken }),
|
||||
body: JSON.stringify({ username: u, password: p, captcha_id: captchaId, captcha_code: captchaCode }),
|
||||
});
|
||||
if (status !== 200) {
|
||||
throw new Error(body.message || '注册失败');
|
||||
|
||||
+531
-2
@@ -2,7 +2,7 @@
|
||||
import { NIcon, useThemeVars } from 'naive-ui';
|
||||
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { Heart, Home2, Key, Menu2 } from '@vicons/tabler';
|
||||
import { Heart, Home2, Key, Menu2, Plug } from '@vicons/tabler';
|
||||
|
||||
import { storeToRefs } from 'pinia';
|
||||
import HeroGradient from '../assets/hero-gradient.svg?component';
|
||||
@@ -16,6 +16,8 @@ import { useToolStore } from '@/tools/tools.store';
|
||||
import { useTracker } from '@/modules/tracker/tracker.services';
|
||||
import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue';
|
||||
import UserMenu from '@/components/UserMenu.vue';
|
||||
import FeedbackModal from '@/components/FeedbackModal.vue';
|
||||
import { getMachineId } from '@/tools/license/license';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
const styleStore = useStyleStore();
|
||||
@@ -31,6 +33,144 @@ if (isLoggedIn.value) {
|
||||
const version = config.app.version;
|
||||
const commitSha = config.app.lastCommitSha.slice(0, 7);
|
||||
|
||||
// ---- 站内留言反馈(右上角入口,弹窗提交,与授权系统无关) ----
|
||||
const showFeedback = ref(false);
|
||||
|
||||
// ---- 授权系统接入(auth.88531.cn 项目 6):在线统计上报 + 公告推送 + 右上角铃铛/版本号 ----
|
||||
const SITE_VERSION = '2026.11.12'; // 当前版本号,与 Gitea Release tag 同步(发版时更新)
|
||||
const annOpen = ref(false);
|
||||
const announcements = ref<Record<string, any>[]>([]);
|
||||
const popupAnn = ref<Record<string, any> | null>(null);
|
||||
const annSeenVersion = ref(0);
|
||||
let annSeen: string[] = [];
|
||||
try {
|
||||
annSeen = JSON.parse(localStorage.getItem('it-tools-ann-read') || '[]');
|
||||
if (!Array.isArray(annSeen)) annSeen = [];
|
||||
}
|
||||
catch {
|
||||
annSeen = [];
|
||||
}
|
||||
const annUnread = computed(() => {
|
||||
annSeenVersion.value; // 依赖已读版本号,标记已读后重算
|
||||
return announcements.value.filter(a => !annSeen.includes(String(a.id))).length;
|
||||
});
|
||||
function annIsUnread(a: Record<string, any>) {
|
||||
annSeenVersion.value;
|
||||
return !annSeen.includes(String(a.id));
|
||||
}
|
||||
function annSaveSeen() {
|
||||
try {
|
||||
localStorage.setItem('it-tools-ann-read', JSON.stringify(annSeen));
|
||||
}
|
||||
catch { /* localStorage 不可用时忽略 */ }
|
||||
annSeenVersion.value++;
|
||||
}
|
||||
function annMarkRead(a: Record<string, any>) {
|
||||
const id = String(a?.id ?? '');
|
||||
if (id && !annSeen.includes(id)) {
|
||||
annSeen.push(id);
|
||||
annSaveSeen();
|
||||
}
|
||||
}
|
||||
function annMarkAll() {
|
||||
const ids = announcements.value.map(a => String(a?.id ?? '')).filter(Boolean);
|
||||
annSeen = [...new Set([...annSeen, ...ids])];
|
||||
annSaveSeen();
|
||||
}
|
||||
function annTime(t?: string) {
|
||||
return t ? String(t).slice(0, 16) : '';
|
||||
}
|
||||
function toggleAnn() {
|
||||
annOpen.value = !annOpen.value;
|
||||
if (annOpen.value) fetchAnnouncements();
|
||||
}
|
||||
async function fetchAnnouncements() {
|
||||
try {
|
||||
const res = await fetch('/relay/hub/announcements?limit=20');
|
||||
if (!res.ok) return;
|
||||
const body = await res.json();
|
||||
if (body?.code !== 200) return;
|
||||
announcements.value = Array.isArray(body.data?.list) ? body.data.list : [];
|
||||
// 公告推送:popup 列表里没看过的条目每次只弹第一条(其余在铃铛面板可读)
|
||||
const pops = (Array.isArray(body.data?.popup) ? body.data.popup : [])
|
||||
.filter((p: any) => p && !annSeen.includes(String(p.id)));
|
||||
if (pops.length && !popupAnn.value)
|
||||
popupAnn.value = pops[0];
|
||||
}
|
||||
catch {
|
||||
// 授权系统不可达时静默降级,不影响站点使用
|
||||
}
|
||||
}
|
||||
function closePopup() {
|
||||
if (popupAnn.value)
|
||||
annMarkRead(popupAnn.value);
|
||||
popupAnn.value = null;
|
||||
}
|
||||
// 在线统计:打开页面即登记安装 + 每 30 分钟心跳,授权系统后台据此统计安装/在线
|
||||
async function reportOnline() {
|
||||
try {
|
||||
await fetch('/relay/hub/report', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
machine_id: getMachineId(),
|
||||
client_version: SITE_VERSION,
|
||||
device_info: `web ${location.host}`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch {
|
||||
// 静默降级
|
||||
}
|
||||
}
|
||||
function onAnnDocClick(e: MouseEvent) {
|
||||
const el = e.target as Element | null;
|
||||
// 面板已 Teleport 到 body,不再位于 .ann-wrap 内,需一并放行
|
||||
if (annOpen.value && !el?.closest?.('.ann-wrap, .ann-panel'))
|
||||
annOpen.value = false;
|
||||
}
|
||||
onMounted(() => {
|
||||
reportOnline();
|
||||
fetchAnnouncements();
|
||||
setInterval(reportOnline, 30 * 60 * 1000);
|
||||
setInterval(fetchAnnouncements, 15 * 60 * 1000);
|
||||
document.addEventListener('click', onAnnDocClick);
|
||||
});
|
||||
onUnmounted(() => document.removeEventListener('click', onAnnDocClick));
|
||||
|
||||
// ---- 页脚售后微信:点击复制 ----
|
||||
const WECHAT_ID = 'q3970260761';
|
||||
const wechatCopied = ref(false);
|
||||
async function copyWechat() {
|
||||
let ok = false;
|
||||
try {
|
||||
await navigator.clipboard.writeText(WECHAT_ID);
|
||||
ok = true;
|
||||
}
|
||||
catch {
|
||||
// 剪贴板 API 不可用(非 https / 老浏览器)时退回 execCommand
|
||||
try {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = WECHAT_ID;
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
ok = document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
catch {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
wechatCopied.value = true;
|
||||
setTimeout(() => {
|
||||
wechatCopied.value = false;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
const { tracker } = useTracker();
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -49,6 +189,51 @@ const tools = computed<ToolCategory[]>(() => [
|
||||
...toolsByCategory.value,
|
||||
]);
|
||||
|
||||
// ---- 全站 IPv6 切换(公网入口 it.88531.cn ⇄ itv6.88531.cn:4443) ----
|
||||
const V6_HOST = 'itv6.88531.cn';
|
||||
const V6_PORT = 4443;
|
||||
const onV6Host = ref(location.hostname === V6_HOST);
|
||||
const onPublicHost = ['it.88531.cn', V6_HOST].includes(location.hostname);
|
||||
const v6ok = ref(false);
|
||||
const v6Switching = ref(false);
|
||||
|
||||
async function probeV6() {
|
||||
// 结果缓存 10 分钟,避免每次开页都探测
|
||||
try {
|
||||
const c = JSON.parse(localStorage.getItem('it_v6_probe') || 'null');
|
||||
if (c && typeof c.ok === 'boolean' && Date.now() - (c.ts || 0) < 600000) {
|
||||
v6ok.value = c.ok;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch { /* 探测 */ }
|
||||
let ok = false;
|
||||
try {
|
||||
const ctl = new AbortController();
|
||||
const timer = setTimeout(() => ctl.abort(), 4000);
|
||||
// api6.ipify.org 仅 AAAA:能连通即说明本机有 IPv6 出口
|
||||
const r = await fetch('https://api6.ipify.org?format=json', { signal: ctl.signal, cache: 'no-store' });
|
||||
clearTimeout(timer);
|
||||
const j = await r.json();
|
||||
ok = typeof j?.ip === 'string' && j.ip.includes(':');
|
||||
}
|
||||
catch { ok = false; }
|
||||
v6ok.value = ok;
|
||||
try { localStorage.setItem('it_v6_probe', JSON.stringify({ ok, ts: Date.now() })); }
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function switchV6() {
|
||||
if (v6Switching.value) {
|
||||
return;
|
||||
}
|
||||
v6Switching.value = true;
|
||||
const path = location.pathname + location.search + location.hash;
|
||||
location.href = onV6Host.value
|
||||
? `https://it.88531.cn${path}`
|
||||
: `https://${V6_HOST}:${V6_PORT}${path}`;
|
||||
}
|
||||
|
||||
// 右下角回到顶部火箭
|
||||
const showTop = ref(false);
|
||||
// 页面可能有多层 .n-layout-scroll-container(嵌套 n-layout),外层往往不滚、内层才滚;
|
||||
@@ -70,6 +255,9 @@ function bindTopScroll() {
|
||||
});
|
||||
}
|
||||
onMounted(() => {
|
||||
if (onPublicHost) {
|
||||
probeV6().catch(() => {});
|
||||
}
|
||||
// 等布局渲染后再绑定滚动容器(内层容器可能晚于挂载出现,多试几次)
|
||||
let tries = 0;
|
||||
const timer = setInterval(() => {
|
||||
@@ -145,6 +333,18 @@ onBeforeUnmount(() => {
|
||||
|
||||
<UserMenu />
|
||||
|
||||
<!-- 全站右上角:留言反馈(与授权系统无关,任何人可提交) -->
|
||||
<c-tooltip position="bottom" :tooltip="'给我们留言:功能建议 / 意见反馈'">
|
||||
<c-button
|
||||
round
|
||||
class="feedback-btn"
|
||||
:bordered="false"
|
||||
@click="showFeedback = true"
|
||||
>
|
||||
✍️ <span class="feedback-btn-text">留言反馈</span>
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<c-tooltip position="bottom" :tooltip="'查看授权功能与购买'">
|
||||
<RouterLink to="/pricing" class="pricing-link">
|
||||
<c-button
|
||||
@@ -157,6 +357,85 @@ onBeforeUnmount(() => {
|
||||
</c-button>
|
||||
</RouterLink>
|
||||
</c-tooltip>
|
||||
|
||||
<!-- 全站右上角:MCP 接入(教程/令牌管理入口,未购卡密显示购买链接) -->
|
||||
<c-tooltip position="bottom" :tooltip="'MCP 接入:让 AI 助手直接调用本站工具'">
|
||||
<RouterLink to="/mcp-connect" class="pricing-link">
|
||||
<c-button
|
||||
round
|
||||
class="support-button"
|
||||
:bordered="false"
|
||||
>
|
||||
MCP
|
||||
<NIcon v-if="!styleStore.isSmallScreen" :component="Plug" ml-2 />
|
||||
</c-button>
|
||||
</RouterLink>
|
||||
</c-tooltip>
|
||||
|
||||
<!-- 全站右上角:IPv6 直连切换(仅公网域名且探测到本机有 IPv6 时显示) -->
|
||||
<c-tooltip
|
||||
v-if="onV6Host || v6ok"
|
||||
position="bottom"
|
||||
:tooltip="onV6Host ? '当前 IPv6 直连入口,点击切回 IPv4 中转' : '检测到你的网络支持 IPv6,点击切换 IPv6 直连加速'"
|
||||
>
|
||||
<c-button
|
||||
round
|
||||
class="v6-switch"
|
||||
:bordered="false"
|
||||
:disabled="v6Switching"
|
||||
@click="switchV6"
|
||||
>
|
||||
<template v-if="onV6Host">⇄ IPv4</template>
|
||||
<template v-else>⚡ <span class="v6-text">IPv6 直连</span></template>
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<!-- 全站右上角:授权系统公告(铃铛 + 未读红点 + 下拉面板) -->
|
||||
<div class="ann-wrap">
|
||||
<c-tooltip position="bottom" :tooltip="annUnread ? `有 ${annUnread} 条新公告` : '系统公告'">
|
||||
<c-button
|
||||
round
|
||||
class="ann-btn"
|
||||
:bordered="false"
|
||||
aria-label="系统公告"
|
||||
@click.stop="toggleAnn"
|
||||
>
|
||||
🔔
|
||||
<span class="ann-dot" :style="{ display: annUnread ? 'block' : 'none' }"></span>
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
<!-- 面板 Teleport 到 body:避免 top-nav 内 v-if 子树挂载进 null 容器(实测 insertBefore 崩溃) -->
|
||||
<Teleport to="body">
|
||||
<div v-if="annOpen" class="ann-panel" @click.stop>
|
||||
<div class="ann-panel-head">
|
||||
<span>📢 系统公告</span>
|
||||
<button v-if="announcements.length" class="ann-readall" type="button" @click="annMarkAll">全部已读</button>
|
||||
</div>
|
||||
<div class="ann-panel-body">
|
||||
<div v-if="!announcements.length" class="ann-empty">暂无公告</div>
|
||||
<div
|
||||
v-for="a in announcements"
|
||||
:key="a.id"
|
||||
class="ann-item"
|
||||
:class="{ 'is-unread': annIsUnread(a) }"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="annMarkRead(a)"
|
||||
@keyup.enter="annMarkRead(a)"
|
||||
>
|
||||
<div class="ann-item-head">
|
||||
<b v-if="a.title">{{ a.title }}</b>
|
||||
<span class="ann-time">{{ annTime(a.created_at) }}</span>
|
||||
</div>
|
||||
<div class="ann-content">{{ a.content }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</div>
|
||||
|
||||
<!-- 全站右上角:当前版本号(与 Gitea Release tag 同步) -->
|
||||
<span class="ver-badge" :title="`IT-TOOLS-PRO v${SITE_VERSION}`">v{{ SITE_VERSION }}</span>
|
||||
</div>
|
||||
<slot />
|
||||
|
||||
@@ -167,8 +446,43 @@ onBeforeUnmount(() => {
|
||||
<span>
|
||||
<c-link target="_blank" rel="noopener" href="https://nav.88531.cn">🚀 更多应用尽在 nav.88531.cn</c-link>
|
||||
</span>
|
||||
<span class="footer-sep">·</span>
|
||||
<span>
|
||||
<c-link
|
||||
target="_blank" rel="noopener"
|
||||
href="https://gitea.88531.cn/jinghui/it-tools-pro"
|
||||
title="https://gitea.88531.cn/jinghui/it-tools-pro"
|
||||
>🐙 开源 gitea.88531.cn</c-link>
|
||||
</span>
|
||||
<span class="footer-sep">·</span>
|
||||
<span>
|
||||
<span
|
||||
class="footer-wechat"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
title="点击复制售后微信 q3970260761"
|
||||
@click="copyWechat"
|
||||
@keyup.enter="copyWechat"
|
||||
>💬 售后微信 {{ wechatCopied ? '已复制 ✓' : 'q3970260761' }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 留言反馈弹窗 -->
|
||||
<FeedbackModal v-model:show="showFeedback" />
|
||||
|
||||
<!-- 授权系统公告推送(popup 类型,每条只弹一次);Teleport 到 body 避免内容区补丁冲突 -->
|
||||
<Teleport to="body">
|
||||
<div v-if="popupAnn" class="ann-popup-mask" @click.self="closePopup">
|
||||
<div class="ann-popup" role="dialog" aria-label="系统公告">
|
||||
<div class="ann-popup-head">📢 系统公告</div>
|
||||
<div v-if="popupAnn.title" class="ann-popup-title">{{ popupAnn.title }}</div>
|
||||
<div class="ann-popup-content">{{ popupAnn.content }}</div>
|
||||
<div v-if="popupAnn.created_at" class="ann-popup-time">{{ annTime(popupAnn.created_at) }}</div>
|
||||
<c-button round class="ann-popup-ok" type="primary" @click="closePopup">我知道了</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
|
||||
<!-- 右下角回到顶部火箭 -->
|
||||
<button v-show="showTop" class="back-top" title="回到顶部" aria-label="回到顶部" @click="scrollToTop">🚀</button>
|
||||
</template>
|
||||
@@ -239,7 +553,7 @@ onBeforeUnmount(() => {
|
||||
color: #838587;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: nowrap; // 强制单行,不折行
|
||||
white-space: normal; // 放得下时保持单行(原 nowrap 的观感),放不下时折行而不是横向溢出
|
||||
user-select: none;
|
||||
|
||||
.footer-sep {
|
||||
@@ -247,6 +561,16 @@ onBeforeUnmount(() => {
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
// 售后微信:点击复制(固定底栏下 pointer-events:none,这里单独放行)
|
||||
.footer-wechat {
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
|
||||
&:hover {
|
||||
color: #0e9384;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(a) {
|
||||
color: #838587;
|
||||
text-decoration: none;
|
||||
@@ -282,6 +606,211 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
|
||||
// 顶部导航:滚动时固定在最顶部(sticky),通栏贴顶遮挡滚动内容
|
||||
.v6-switch {
|
||||
// 顶栏内正常排版(紧跟「授权应用」之后),不悬浮、不遮挡
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// 右上角「留言反馈」入口:与顶栏其它文字按钮同规格
|
||||
.feedback-btn {
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// 右上角:授权系统公告(铃铛 + 未读红点 + 下拉面板)
|
||||
.ann-wrap {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ann-btn {
|
||||
position: relative;
|
||||
font-size: 13px;
|
||||
padding-left: 8px;
|
||||
padding-right: 12px;
|
||||
}
|
||||
.ann-dot {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 6px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: #ff4d4f;
|
||||
box-shadow: 0 0 0 2px v-bind('themeVars.bodyColor');
|
||||
}
|
||||
.ann-panel {
|
||||
position: fixed;
|
||||
top: 60px;
|
||||
right: 26px;
|
||||
z-index: 3000;
|
||||
width: 320px;
|
||||
max-width: 84vw;
|
||||
background: v-bind('themeVars.bodyColor');
|
||||
border: 1px solid v-bind('themeVars.textColor3');
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
|
||||
overflow: hidden;
|
||||
text-align: left;
|
||||
}
|
||||
.ann-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
border-bottom: 1px solid v-bind('themeVars.textColor3');
|
||||
}
|
||||
.ann-readall {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
font-size: 12px;
|
||||
color: v-bind('themeVars.primaryColor');
|
||||
cursor: pointer;
|
||||
}
|
||||
.ann-panel-body {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
padding: 6px 0;
|
||||
}
|
||||
.ann-empty {
|
||||
padding: 18px 12px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.ann-item {
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
border-left: 3px solid transparent;
|
||||
|
||||
&:hover {
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
}
|
||||
&.is-unread {
|
||||
border-left-color: #ff4d4f;
|
||||
}
|
||||
}
|
||||
.ann-item-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
|
||||
b {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
.ann-time {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.ann-content {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
opacity: 0.85;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
// 右上角:当前版本号徽标
|
||||
.ver-badge {
|
||||
flex-shrink: 0;
|
||||
align-self: center;
|
||||
padding: 4px 9px;
|
||||
border-radius: 999px;
|
||||
font-size: 11px;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
cursor: default;
|
||||
background: rgba(128, 128, 128, 0.16);
|
||||
border: 1px solid v-bind('themeVars.textColor3');
|
||||
color: v-bind('themeVars.textColor2');
|
||||
}
|
||||
|
||||
// 授权系统公告推送弹窗(每条只弹一次)
|
||||
.ann-popup-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 6000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.ann-popup {
|
||||
width: 380px;
|
||||
max-width: 92vw;
|
||||
padding: 18px 20px 16px;
|
||||
border-radius: 12px;
|
||||
background: v-bind('themeVars.bodyColor');
|
||||
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
|
||||
text-align: left;
|
||||
}
|
||||
.ann-popup-head {
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.ann-popup-title {
|
||||
margin-bottom: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.ann-popup-content {
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
opacity: 0.9;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.ann-popup-time {
|
||||
margin-top: 8px;
|
||||
font-size: 11px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.ann-popup-ok {
|
||||
width: 100%;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
// 窄屏顶栏放不下完整文字时收缩为纯图标,并收紧间距,避免溢出右边缘
|
||||
.top-nav {
|
||||
gap: 4px;
|
||||
}
|
||||
.v6-switch {
|
||||
.v6-text {
|
||||
display: none;
|
||||
}
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
.feedback-btn {
|
||||
.feedback-btn-text {
|
||||
display: none;
|
||||
}
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.top-nav {
|
||||
position: sticky;
|
||||
// -26px 抵消滚动容器 padding-top 内缩,使导航真正贴到视口最顶(0)
|
||||
|
||||
@@ -40,7 +40,7 @@ useHead(head);
|
||||
const { t } = useI18n();
|
||||
|
||||
// 宽屏工具:不受 600px 限宽,占满可用宽度(画布/多栏类工具)
|
||||
const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools', '/seal-maker', '/signature-pad', '/ai-image-lab', '/ai-chat', '/copywriting', '/ai-gen']);
|
||||
const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools', '/seal-maker', '/signature-pad', '/ai-image-lab', '/ai-chat', '/copywriting', '/ai-gen', '/code-reader', '/my-ip', '/mcp-connect', '/poster-maker', '/ai-text-edit', '/ai-retouch']);
|
||||
const isWide = computed(() => WIDE_TOOLS.has(route.path));
|
||||
|
||||
const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
|
||||
|
||||
+7
-5
@@ -26,8 +26,8 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
{
|
||||
title: '首页资讯',
|
||||
items: [
|
||||
{ name: '每日资讯 5 列', icon: '讯', desc: '首页顶部并排 5 列:GitHub 热榜、国际新闻、AI 资讯、IT 最新技术、当天最热股票;每天 08:00 自动抓取更新,英文标题与简介自动翻译中文,点标题新标签打开原文', tag: '全新' },
|
||||
{ name: '最热股票实时刷新', icon: '股', desc: '交易时段(工作日 9:30-15:00)每 60 秒自动拉取东方财富最新涨幅;标题行显示 交易中/休市 状态徽章,收盘后与周末自动休市', tag: '全新' },
|
||||
{ name: '每日资讯 5 列', icon: '讯', desc: '首页顶部并排 5 列:GitHub 热榜、国际新闻、AI 资讯、IT 最新技术、AI 最热股票;每天 08:00 自动抓取更新,英文标题与简介自动翻译中文,点标题新标签打开原文', tag: '全新' },
|
||||
{ name: 'AI 最热股票实时刷新', icon: '股', desc: '交易时段(工作日 9:30-15:00)每 60 秒自动拉取东方财富数据;聚合人工智能、AI 芯片、算力概念、AI 应用等 12 个 AI 概念板块(约 580 只成分股)按成交额排序取最热 10 只,标题行显示 交易中/休市 状态徽章', tag: '全新' },
|
||||
{ name: '自选股', icon: '自', desc: '股票列「自选」选项卡:输入 6 位代码即可添加,行内看 名称·涨跌幅·现价,红涨绿跌,一键移出;自选股登录后云端同步,换电脑即恢复', tag: '全新' },
|
||||
{ name: '首页推荐与全部工具', icon: '首', desc: '管理员可配置首页「精选推荐」工具位;「近期新功能」随版本滚动更新;「全部工具」默认折叠并显示总数徽章,各分组标题右侧均显示功能数量', tag: '全新' },
|
||||
],
|
||||
@@ -35,9 +35,11 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
{
|
||||
title: '原创工具',
|
||||
items: [
|
||||
{ name: '本机IP查询', icon: '网', desc: '仅显示你设备的公网IPv4/IPv6地址与所属地(多源容错+中文归属地+一键复制),代理/VPN检测(出口IP归属判定+WebRTC泄漏实测+内网IP),热门地点延迟实测(百度、本省运营商门户按归属自动匹配、全国镜像站+海外节点),测速历史自动记录各地点延迟快照(跨线路/跨时间对照),IPv6不支持时明示并给出开启教程,本站已支持IPv6直连(速度更快),网速测试为你的设备↔本站服务器真实收发计时', tag: '全新' },
|
||||
{ name: 'Base64图片互转', icon: 'B', desc: 'Base64转图片与图片转Base64合一页双 Tab:三种输入形态(裸串/data:URI/CSS url())自动识别、图片类型魔数嗅探、输出三档格式实时切换、互转按钮带结果闭环跳转,纯浏览器本地不上传', tag: '全新' },
|
||||
{ name: '批量条码生成', icon: '条', desc: 'EAN/UPC/Code128/Code39/DataMatrix 等 12 种码制,批量生成、打包下载,尺寸颜色字号可调', tag: '全新' },
|
||||
{ name: '二维码条码识别', icon: '扫', desc: '上传/拖拽/粘贴图片一键识别,支持多码混合批量输出,本地 WASM 解码,图片不上传', tag: '全新' },
|
||||
{ name: '在线翻译', icon: '译', desc: '中英日韩等 16 种语言互译,自动识别源语言,支持导入 Word/PDF/TXT 等文档整篇翻译、并发处理大文档、译文可下载 TXT/DOCX', tag: '全新' },
|
||||
{ name: '二维码条码识别与生成', icon: '扫', desc: '识别:上传/拖拽/粘贴一键解码(多码混合批量输出,本地 WASM 不上传);生成:自定义前景/背景颜色、中间插入本地 Logo 图片,生成后自动自扫验证可下载 PNG', tag: '全新' },
|
||||
{ name: '在线翻译', icon: '译', desc: '文本翻译 16 种语言(中英走本地引擎不限流,其他语种自动备用线路),Word/PDF/TXT 整篇翻译,扫描件/图片自动 OCR 识别后翻译,译文可下载 TXT/DOCX', tag: '全新' },
|
||||
{ name: '图片OCR / PDF文字识别', icon: '识', desc: '本地 OCR 引擎,截图扫描件文字提取(准确率 99%+);PDF 逐页识别、预览、导出 TXT', tag: '全新' },
|
||||
{ name: '面单设计', icon: '单', desc: '内置 **20 个面单模板**并按「国内快递 / 国外快递 / 通用面单」三组归类——顺丰、中通、圆通、韵达、申通、京东、极兔、EMS,DHL、FedEx、UPS、USPS、TNT、亚马逊 FBA 等开箱即用;**每个模板按该快递真实电子面单独立排版**(尺寸/品牌色/三段码/撕开线/专属字段各不相同);上传 PDF 自动把**文字、条码、二维码、图片**全部提取成可编辑元素(可改内容、移动、删除)并**擦除底图原内容**,不产生重影;新增**实线/虚线 × 横线/竖线**线条组件可调粗度长度;300dpi 高清导出', tag: '全新' },
|
||||
{ name: 'IT网站收藏', icon: '藏', desc: '内置 91 个精选开发站点(社区/文档/工具/AI/设计/视频/媒体平台),数据存用户本地,可自选目录', tag: '全新' },
|
||||
@@ -53,7 +55,7 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
{ name: '多图拼接', icon: '拼', desc: '横向/纵向长图/九宫格/瀑布流/交错双列/拍立得 6 种方式,网格类 2-4 列可调,间距可调', tag: '改造' },
|
||||
{ name: 'JSON 美化和格式化', icon: 'J', desc: '双栏专业工作台:左侧行号编辑,右侧树视图/语法高亮切换,含 Dict/Get参数/XML/CSV 等 7 种转换', tag: '改造' },
|
||||
{ name: 'PDF工具', icon: 'P', desc: '合并/拆分/旋转/重排/压缩/加密/解密/水印/提取文本/页码/转图片,11 功能全程浏览器本地处理,需授权使用', tag: '授权' },
|
||||
{ name: '图片工具', icon: '图', desc: '压缩/转换/尺寸/裁剪/旋转/滤镜/打码/EXIF/二维码生成识别/水印/拼接,12 功能本地处理,需授权使用', tag: '授权' },
|
||||
{ name: '图片工具', icon: '图', desc: '压缩/转换/尺寸/裁剪/旋转/滤镜/打码/PS 风格编辑器(图层+画笔+文字+选区+历史记录+OCR 改字/文字模板+画布旋转、智能消除笔实时预览无痕去文字水印)/EXIF/二维码生成识别/水印/拼接,13 功能本地处理,需授权使用', tag: '授权' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
+435
-40
@@ -19,7 +19,10 @@ const loginPass = ref('');
|
||||
function authHeaders(): Record<string, string> {
|
||||
const h: Record<string, string> = {};
|
||||
if (token.value) {
|
||||
// Bearer = logged-in admin session (channel 2); X-Admin-Token = bootstrap
|
||||
// ADMIN_TOKEN paste flow (channel 1). Send both so either kind works.
|
||||
h['Authorization'] = `Bearer ${token.value}`;
|
||||
h['X-Admin-Token'] = token.value;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
@@ -61,6 +64,7 @@ async function login() {
|
||||
authed.value = true;
|
||||
localStorage.setItem(TOKEN_KEY, token.value);
|
||||
loadOverview();
|
||||
loadFeedback();
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
@@ -103,25 +107,66 @@ async function loadOverview() {
|
||||
overview.value = b.data;
|
||||
}
|
||||
|
||||
// ============ 文件管理 ============
|
||||
const fileUser = ref('');
|
||||
// ============ 文件管理(默认全量聚合,50 条/页自动分页)============
|
||||
const fileUser = ref(''); // ''=全部, '__gen__'=AI生成, 其他=指定用户
|
||||
const fileList = ref<any[]>([]);
|
||||
const fileTotal = ref(0);
|
||||
const fileTotal = ref(0); // 合计字节数
|
||||
const fileCount = ref(0); // 总记录数
|
||||
const filePage = ref(1);
|
||||
const filePages = ref(1);
|
||||
const FILE_PAGE_SIZE = 50;
|
||||
const cleanupDays = ref(7);
|
||||
const cleanupUser = ref('');
|
||||
const cleanupResult = ref('');
|
||||
|
||||
async function loadFiles() {
|
||||
if (!fileUser.value) {
|
||||
return;
|
||||
}
|
||||
const b = await api(`/admin/files?username=${encodeURIComponent(fileUser.value)}`);
|
||||
const q = new URLSearchParams();
|
||||
if (fileUser.value === '__gen__') q.set('scope', 'gen');
|
||||
else if (fileUser.value) q.set('username', fileUser.value);
|
||||
q.set('page', String(filePage.value));
|
||||
q.set('page_size', String(FILE_PAGE_SIZE));
|
||||
const b = await api(`/admin/files?${q}`);
|
||||
fileList.value = b.data?.files ?? [];
|
||||
fileTotal.value = b.data?.total_size ?? 0;
|
||||
fileCount.value = b.data?.total ?? 0;
|
||||
filePages.value = b.data?.pages ?? 1;
|
||||
filePage.value = b.data?.page ?? 1;
|
||||
}
|
||||
|
||||
async function delFile(id: string) {
|
||||
const b = await api('/admin/delete-file', { method: 'POST', body: JSON.stringify({ id, username: fileUser.value }) });
|
||||
function gotoFilePage(p: number) {
|
||||
filePage.value = Math.min(Math.max(1, p), filePages.value);
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
// 文件直链:缩略图 <img> 与下载 <a> 无法携带 header,鉴权走 ?token=
|
||||
function fileUrl(f: any, dl = false) {
|
||||
const q = new URLSearchParams();
|
||||
q.set('path', f.path || '');
|
||||
if (f.name) q.set('name', f.name);
|
||||
if (dl) q.set('dl', '1');
|
||||
if (token.value) q.set('token', token.value);
|
||||
return `/relay/admin/file?${q}`;
|
||||
}
|
||||
function windowOpen(url: string) {
|
||||
window.open(url, '_blank', 'noopener');
|
||||
}
|
||||
function fileOwner(f: any) {
|
||||
if (f.source === 'gen') return f.machine || 'AI';
|
||||
if (f.source === 'mcp') return 'MCP';
|
||||
return f.username || f.source || '-';
|
||||
}
|
||||
|
||||
async function delFile(f: any) {
|
||||
const body: any = { id: f.id };
|
||||
if (f.source === 'gen') {
|
||||
body.username = '__gen__';
|
||||
body.machine = f.machine;
|
||||
} else if (f.source === 'mcp') {
|
||||
body.username = '__mcp__';
|
||||
} else {
|
||||
body.username = f.username || fileUser.value;
|
||||
}
|
||||
const b = await api('/admin/delete-file', { method: 'POST', body: JSON.stringify(body) });
|
||||
if (b.code === 200) {
|
||||
await loadFiles();
|
||||
loadOverview();
|
||||
@@ -140,9 +185,8 @@ async function cleanup() {
|
||||
if (b.code === 200) {
|
||||
cleanupResult.value = `已删除 ${b.data.removed} 个文件,释放 ${fmtSize(b.data.freed)}`;
|
||||
loadOverview();
|
||||
if (fileUser.value) {
|
||||
loadFiles();
|
||||
}
|
||||
filePage.value = 1;
|
||||
loadFiles();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +194,7 @@ function pickUser(u: string) {
|
||||
fileUser.value = u;
|
||||
cleanupUser.value = u;
|
||||
tab.value = 'files';
|
||||
filePage.value = 1;
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
@@ -272,12 +317,30 @@ async function saveStorage() {
|
||||
// ============ 使用统计 ============
|
||||
const usageDays = ref(7);
|
||||
const usage = ref<any>(null);
|
||||
// 用户活跃排行 = 登录用户 + 未登录访客(访客功能使用也统计展示)
|
||||
const userRows = computed(() => {
|
||||
const rows: { username: string; count: number; last: number }[] = [...(usage.value?.by_user ?? [])];
|
||||
const g = usage.value?.guest;
|
||||
if (g && g.count > 0) {
|
||||
rows.push({ username: '__guest__', count: g.count, last: g.last });
|
||||
}
|
||||
return rows.sort((a, b) => b.count - a.count);
|
||||
});
|
||||
|
||||
async function loadUsage() {
|
||||
const b = await api(`/admin/usage?days=${usageDays.value}`);
|
||||
usage.value = b.data;
|
||||
}
|
||||
|
||||
// ============ MCP 调用记录 ============
|
||||
const mcpDays = ref(7);
|
||||
const mcpData = ref<any>(null);
|
||||
|
||||
async function loadMcpUsage() {
|
||||
const b = await api(`/admin/mcp-usage?days=${mcpDays.value}`);
|
||||
mcpData.value = b.data;
|
||||
}
|
||||
|
||||
const TOOL_LABELS: Record<string, string> = {
|
||||
'translator': '在线翻译',
|
||||
'image-ocr': '图片OCR',
|
||||
@@ -294,7 +357,12 @@ const TOOL_LABELS: Record<string, string> = {
|
||||
};
|
||||
|
||||
function toolLabel(t: string) {
|
||||
return TOOL_LABELS[t] ?? t;
|
||||
if (TOOL_LABELS[t]) {
|
||||
return TOOL_LABELS[t];
|
||||
}
|
||||
// 前端上报的是工具路径(如 json-to-xml),回退查工具目录显示名称
|
||||
const hit = toolStore.tools.find((x: any) => x.path === `/${t}` || x.path === t);
|
||||
return hit?.name || t;
|
||||
}
|
||||
|
||||
function fmtTime(t: number) {
|
||||
@@ -372,6 +440,55 @@ async function saveReco() {
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 留言反馈(网站访客提交,与授权系统无关) ============
|
||||
const feedback = ref<any[]>([]);
|
||||
|
||||
async function loadFeedback() {
|
||||
try {
|
||||
const b = await api('/admin/feedback');
|
||||
feedback.value = b.data ?? [];
|
||||
} catch (e: any) {
|
||||
setMsg(`留言加载失败:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function fbSetStatus(f: any, status: string) {
|
||||
try {
|
||||
const b = await api('/admin/feedback', { method: 'POST', body: JSON.stringify({ id: f.id, status }) });
|
||||
setMsg(b.code === 200 ? '已更新留言状态' : (b.message || '状态更新失败'));
|
||||
if (b.code === 200) f.status = status;
|
||||
} catch (e: any) {
|
||||
setMsg(`状态更新失败:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function fbOnStatus(f: any, e: Event) {
|
||||
fbSetStatus(f, (e.target as HTMLSelectElement).value);
|
||||
}
|
||||
|
||||
async function fbDelete(f: any) {
|
||||
if (!window.confirm('确定删除这条留言?删除后无法恢复。')) return;
|
||||
try {
|
||||
const b = await api('/admin/feedback', { method: 'POST', body: JSON.stringify({ id: f.id, action: 'delete' }) });
|
||||
setMsg(b.code === 200 ? '已删除' : (b.message || '删除失败'));
|
||||
if (b.code === 200) feedback.value = feedback.value.filter(x => x.id !== f.id);
|
||||
} catch (e: any) {
|
||||
setMsg(`删除失败:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function fbTime(ts: any) {
|
||||
try {
|
||||
const d = new Date(Number(ts) * 1000);
|
||||
const p = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
||||
} catch {
|
||||
return String(ts ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
const fbNewCount = computed(() => feedback.value.filter(f => f.status === 'new').length);
|
||||
|
||||
function recoAdd() {
|
||||
reco.value.unshift({ path: '', icon: '🧰', name: '', desc: '', enabled: true });
|
||||
}
|
||||
@@ -389,9 +506,16 @@ function recoMove(i: number, d: -1 | 1) {
|
||||
reco.value.splice(j, 0, it);
|
||||
}
|
||||
|
||||
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco'>('overview');
|
||||
const tab = ref<'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback'>('overview');
|
||||
|
||||
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
// 在线人数 30s 自动刷新(切走用量页签即停)
|
||||
let usageTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback') {
|
||||
if (usageTimer) {
|
||||
clearInterval(usageTimer);
|
||||
usageTimer = null;
|
||||
}
|
||||
tab.value = id;
|
||||
if (id === 'overview') {
|
||||
loadOverview();
|
||||
@@ -401,10 +525,20 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
}
|
||||
if (id === 'usage') {
|
||||
loadUsage();
|
||||
usageTimer = setInterval(loadUsage, 30000);
|
||||
}
|
||||
if (id === 'mcp') {
|
||||
loadMcpUsage();
|
||||
}
|
||||
if (id === 'storage') {
|
||||
loadStorage();
|
||||
}
|
||||
if (id === 'feedback') {
|
||||
loadFeedback();
|
||||
}
|
||||
if (id === 'files') {
|
||||
loadFiles();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -434,8 +568,13 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'overview' }" @click="switchTab('overview')">📊 总览与用户</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'files' }" @click="switchTab('files')">📁 文件管理</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'usage' }" @click="switchTab('usage')">📈 使用统计</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'mcp' }" @click="switchTab('mcp')">🤖 MCP 调用</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'storage' }" @click="switchTab('storage')">💾 存储设置</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'reco' }" @click="switchTab('reco')">🏠 首页推荐</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'feedback' }" @click="switchTab('feedback')">
|
||||
💬 留言反馈
|
||||
<span v-if="fbNewCount > 0" class="adm-badge bad" style="margin-left: 6px">{{ fbNewCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<a href="javascript:;" class="adm-logout" @click="authed = false; localStorage.removeItem(TOKEN_KEY)">退出</a>
|
||||
</div>
|
||||
@@ -468,7 +607,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr><th>用户名</th><th>角色</th><th>状态</th><th>文件数</th><th>文件占用</th><th>设备</th><th>授权</th><th>注册</th><th>操作</th></tr>
|
||||
<tr><th>用户名</th><th>角色</th><th>状态</th><th>文件数</th><th>文件占用</th><th>设备</th><th>授权</th><th>注册</th><th>最后登录</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="u in users" :key="u.username">
|
||||
@@ -480,6 +619,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<td>{{ u.devices }}</td>
|
||||
<td><span class="adm-badge" :class="u.licensed ? 'ok' : ''">{{ u.licensed ? '已授权' : '-' }}</span></td>
|
||||
<td>{{ fmtDate(u.created) }}</td>
|
||||
<td>{{ u.last_login ? fmtDate(u.last_login) : '未登录' }}</td>
|
||||
<td class="adm-ops">
|
||||
<a href="javascript:;" class="adm-link" @click="pickUser(u.username)">文件</a>
|
||||
<a href="javascript:;" class="adm-link" @click="resetPassword(u)">改密</a>
|
||||
@@ -488,7 +628,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<a v-if="u.username !== 'jinghui'" href="javascript:;" class="adm-del" @click="deleteUser(u)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!users.length"><td colspan="9" class="adm-none">暂无注册用户</td></tr>
|
||||
<tr v-if="!users.length"><td colspan="10" class="adm-none">暂无注册用户</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
@@ -496,11 +636,17 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<!-- files -->
|
||||
<template v-if="tab === 'files'">
|
||||
<div class="adm-toolbar">
|
||||
<select v-model="fileUser" class="adm-select" @change="loadFiles">
|
||||
<option value="">选择用户…</option>
|
||||
<option v-for="u in users" :key="u.username" :value="u.username">{{ u.username }}</option>
|
||||
<select v-model="fileUser" class="adm-select" @change="filePage = 1; loadFiles()">
|
||||
<option value="">全部(所有用户 + AI 生成 + MCP)</option>
|
||||
<option value="__gen__">仅 AI 生成图片(换脸/生图/海报)</option>
|
||||
<option v-for="u in users" :key="u.username" :value="u.username">仅 {{ u.username }}</option>
|
||||
</select>
|
||||
<span v-if="fileList.length" class="adm-sub">{{ fileList.length }} 个文件 · 合计 {{ fmtSize(fileTotal) }}</span>
|
||||
<span class="adm-sub">共 {{ fileCount }} 条记录 · 合计 {{ fmtSize(fileTotal) }}</span>
|
||||
<span v-if="filePages > 1" class="adm-pager">
|
||||
<button class="adm-btn adm-btn-sm" :disabled="filePage <= 1" @click="gotoFilePage(filePage - 1)">‹ 上一页</button>
|
||||
<span class="adm-pageinfo">第 {{ filePage }} / {{ filePages }} 页</span>
|
||||
<button class="adm-btn adm-btn-sm" :disabled="filePage >= filePages" @click="gotoFilePage(filePage + 1)">下一页 ›</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="adm-cleanup">
|
||||
@@ -521,21 +667,36 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<span v-if="cleanupResult" class="adm-ok">{{ cleanupResult }}</span>
|
||||
</div>
|
||||
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr><th>文件</th><th>类型</th><th>大小</th><th>时间</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="f in fileList" :key="f.id">
|
||||
<td class="adm-fname">{{ f.name }}</td>
|
||||
<td>{{ f.kind || '-' }}</td>
|
||||
<td>{{ fmtSize(f.size) }}</td>
|
||||
<td>{{ fmtTime(f.mtime) }}</td>
|
||||
<td><a href="javascript:;" class="adm-del" @click="delFile(f.id)">删除</a></td>
|
||||
</tr>
|
||||
<tr v-if="!fileList.length"><td colspan="5" class="adm-none">{{ fileUser ? '该用户暂无文件' : '请先选择用户' }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="adm-fscroll">
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr><th class="adm-thumbcol">预览</th><th>文件</th><th>来源</th><th>类型</th><th>大小</th><th>时间</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="f in fileList" :key="(f.source || '') + ':' + (f.machine || '') + ':' + f.id">
|
||||
<td class="adm-thumbcell">
|
||||
<img v-if="f.is_image" class="adm-thumb" :src="fileUrl(f)" alt="" @click="windowOpen(fileUrl(f))">
|
||||
<span v-else class="adm-ftype">{{ f.file_type || '文件' }}</span>
|
||||
</td>
|
||||
<td class="adm-fname" :title="f.prompt || f.name">{{ f.name }}</td>
|
||||
<td>{{ fileOwner(f) }}</td>
|
||||
<td>{{ f.kind || '-' }}</td>
|
||||
<td>{{ fmtSize(f.size) }}</td>
|
||||
<td>{{ fmtTime(f.mtime) }}</td>
|
||||
<td class="adm-ops">
|
||||
<a :href="fileUrl(f, true)" class="adm-dl" download>下载</a>
|
||||
<a href="javascript:;" class="adm-del" @click="delFile(f)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!fileList.length"><td colspan="7" class="adm-none">暂无文件</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-if="filePages > 1" class="adm-pager adm-pager-b">
|
||||
<button class="adm-btn adm-btn-sm" :disabled="filePage <= 1" @click="gotoFilePage(filePage - 1)">‹ 上一页</button>
|
||||
<span class="adm-pageinfo">第 {{ filePage }} / {{ filePages }} 页 · 共 {{ fileCount }} 条</span>
|
||||
<button class="adm-btn adm-btn-sm" :disabled="filePage >= filePages" @click="gotoFilePage(filePage + 1)">下一页 ›</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- storage -->
|
||||
@@ -614,7 +775,8 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<option :value="30">近 30 天</option>
|
||||
<option :value="90">近 90 天</option>
|
||||
</select>
|
||||
<span v-if="usage" class="adm-sub">总使用次数:{{ usage.total }}</span>
|
||||
<span v-if="usage" class="adm-sub" style="color:#16a34a;font-weight:600">● 当前在线(未登录,停留>1分钟):{{ usage.online ?? 0 }} 人</span>
|
||||
<span v-if="usage" class="adm-sub">总使用次数:{{ usage.total }}<template v-if="usage.guest?.count">(其中未登录 {{ usage.guest.count }} 次)</template></span>
|
||||
</div>
|
||||
<div class="adm-usage-grid">
|
||||
<div>
|
||||
@@ -631,17 +793,110 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
<table class="adm-table">
|
||||
<thead><tr><th>用户</th><th>次数</th><th>最近活跃</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="u in usage?.by_user ?? []" :key="u.username">
|
||||
<td class="adm-user">{{ u.username }}</td>
|
||||
<tr v-for="u in userRows" :key="u.username">
|
||||
<td :class="u.username === '__guest__' ? 'adm-user adm-guest' : 'adm-user'">{{ u.username === '__guest__' ? '未登录访客' : u.username }}</td>
|
||||
<td>{{ u.count }}</td>
|
||||
<td>{{ fmtTime(u.last) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!usage?.by_user?.length"><td colspan="3" class="adm-none">暂无登录用户使用记录</td></tr>
|
||||
<tr v-if="!userRows.length"><td colspan="3" class="adm-none">暂无登录用户使用记录</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- MCP 调用记录:AI 客户端经 /mcp 调用本站工具的流水 -->
|
||||
<template v-if="tab === 'mcp'">
|
||||
<div class="adm-toolbar">
|
||||
<select v-model.number="mcpDays" class="adm-select" @change="loadMcpUsage">
|
||||
<option :value="7">近 7 天</option>
|
||||
<option :value="30">近 30 天</option>
|
||||
<option :value="90">近 90 天</option>
|
||||
</select>
|
||||
<span v-if="mcpData" class="adm-sub">总调用:{{ mcpData.total }}(成功 {{ mcpData.ok_total }})</span>
|
||||
<span v-else class="adm-sub">加载中…</span>
|
||||
</div>
|
||||
<div class="adm-usage-grid">
|
||||
<div>
|
||||
<h3 class="adm-h3">工具调用排行</h3>
|
||||
<div v-for="t in mcpData?.by_tool ?? []" :key="t.tool" class="adm-bar-row">
|
||||
<span class="adm-bar-label">{{ t.tool }}</span>
|
||||
<div class="adm-bar-track"><div class="adm-bar" :style="{ width: Math.min(100, t.count * 100 / Math.max(1, mcpData.by_tool[0].count)) + '%' }" /></div>
|
||||
<span class="adm-bar-count">{{ t.count }}</span>
|
||||
</div>
|
||||
<div v-if="!mcpData?.by_tool?.length" class="adm-none">暂无 MCP 调用记录</div>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="adm-h3">调用流水(最近 {{ mcpData?.rows?.length ?? 0 }} 条)</h3>
|
||||
<div class="adm-mcp-scroll">
|
||||
<table class="adm-table">
|
||||
<thead><tr><th>时间</th><th>令牌</th><th>机器码</th><th>工具</th><th>结果</th><th>耗时</th><th>错误</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="(r, i) in mcpData?.rows ?? []" :key="i">
|
||||
<td>{{ fmtTime(r.at) }}</td>
|
||||
<td>…{{ r.token_tail }}</td>
|
||||
<td>{{ r.machine }}</td>
|
||||
<td>{{ r.tool }}</td>
|
||||
<td :style="{ color: r.ok ? '#16a34a' : '#dc2626', fontWeight: 600 }">{{ r.ok ? '✓ 成功' : '✗ 失败' }}</td>
|
||||
<td>{{ r.dur_ms }} ms</td>
|
||||
<td class="adm-mcp-err">{{ r.err || '—' }}</td>
|
||||
</tr>
|
||||
<tr v-if="!mcpData?.rows?.length"><td colspan="7" class="adm-none">暂无 MCP 调用记录</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 留言反馈:网站访客提交的留言,按时间倒序 -->
|
||||
<template v-if="tab === 'feedback'">
|
||||
<div class="adm-toolbar">
|
||||
<span class="adm-sub">
|
||||
共 {{ feedback.length }} 条 · 未处理 {{ fbNewCount }} 条(同一 IP 一小时内限提交 1 次 + 图形验证码)
|
||||
</span>
|
||||
<button class="adm-btn adm-btn-sm" @click="loadFeedback">🔄 刷新</button>
|
||||
</div>
|
||||
<div class="adm-fb-scroll">
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>时间</th>
|
||||
<th>类型</th>
|
||||
<th>内容</th>
|
||||
<th>联系方式</th>
|
||||
<th>IP</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="f in feedback" :key="f.id">
|
||||
<td class="adm-fb-time">{{ fbTime(f.ts) }}</td>
|
||||
<td>
|
||||
<span class="adm-badge" :class="f.type === '功能建议' ? 'ok' : 'admin'">{{ f.type }}</span>
|
||||
</td>
|
||||
<td class="adm-fb-content">{{ f.content }}</td>
|
||||
<td class="adm-fb-contact">{{ f.contact || '—' }}</td>
|
||||
<td class="adm-fb-ip">{{ f.ip }}</td>
|
||||
<td>
|
||||
<select class="adm-select" :value="f.status" @change="fbOnStatus(f, $event)">
|
||||
<option value="new">未处理</option>
|
||||
<option value="replied">已回复</option>
|
||||
<option value="done">已处理</option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="adm-fb-ops">
|
||||
<a href="javascript:;" class="adm-link" @click="fbDelete(f)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!feedback.length">
|
||||
<td colspan="7" class="adm-none">暂无留言,访客提交后会显示在这里</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -751,6 +1006,33 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
// ---- 留言反馈列表 ----
|
||||
.adm-fb-time {
|
||||
white-space: nowrap;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.adm-fb-content {
|
||||
max-width: 460px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.adm-fb-contact,
|
||||
.adm-fb-ip {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.adm-fb-ip {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.adm-fb-ops {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.adm-reco-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -972,6 +1254,25 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
}
|
||||
}
|
||||
|
||||
/* 留言反馈表:窄视口容器内横向滚动,表头保持横排不被挤成竖列 */
|
||||
.adm-fb-scroll {
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
|
||||
.adm-table {
|
||||
min-width: 820px;
|
||||
|
||||
th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
td {
|
||||
word-break: break-word;
|
||||
max-width: 360px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.adm-badge {
|
||||
font-size: 11px;
|
||||
padding: 1px 8px;
|
||||
@@ -1012,6 +1313,88 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 文件管理:缩略图/类型徽标/分页 ===== */
|
||||
.adm-fscroll {
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
|
||||
.adm-table {
|
||||
min-width: 860px;
|
||||
|
||||
th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.adm-thumbcol,
|
||||
.adm-thumbcell {
|
||||
width: 116px;
|
||||
padding-top: 8px !important;
|
||||
padding-bottom: 8px !important;
|
||||
}
|
||||
|
||||
.adm-thumb {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
background: rgba(128, 128, 128, 0.06);
|
||||
display: block;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
|
||||
.adm-ftype {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100px;
|
||||
height: 64px;
|
||||
border-radius: 8px;
|
||||
background: rgba(128, 128, 128, 0.1);
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
letter-spacing: 0.5px;
|
||||
color: rgba(128, 128, 128, 0.95);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.adm-ops {
|
||||
white-space: nowrap;
|
||||
|
||||
a + a {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-dl {
|
||||
color: #18a058;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-pager {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.adm-pager-b {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.adm-pageinfo {
|
||||
font-size: 12.5px;
|
||||
opacity: 0.75;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.adm-userbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1194,6 +1577,18 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.adm-mcp-scroll {
|
||||
max-height: 420px;
|
||||
overflow: auto;
|
||||
}
|
||||
.adm-mcp-err {
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #dc2626;
|
||||
font-size: 12px;
|
||||
}
|
||||
.adm-usage-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
|
||||
@@ -0,0 +1,705 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { AUTH_BASE, getMachineId, licenseState, checkAuth, PROTECTED_TOOLS } from '@/tools/license/license';
|
||||
|
||||
/** 授权功能数量:与 pricing/侧栏同源(license.ts PROTECTED_TOOLS),新授权应用上线自动 +1 */
|
||||
const paidCount = Object.keys(PROTECTED_TOOLS).length;
|
||||
|
||||
useHead({ title: '购买卡密 - IT-TOOLS-PRO' });
|
||||
|
||||
const PROJECT_ID = 6;
|
||||
const ORDER_KEY = 'it-tools-buy-order';
|
||||
const POLL_MS = 5000;
|
||||
|
||||
interface CardType {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
duration_days: number;
|
||||
price: string;
|
||||
original_price: string;
|
||||
}
|
||||
|
||||
const machineId = ref('');
|
||||
const loading = ref(true);
|
||||
const loadErr = ref('');
|
||||
const plans = ref<CardType[]>([]);
|
||||
const selPlan = ref<CardType | null>(null);
|
||||
|
||||
const payType = ref('alipay');
|
||||
const couponCode = ref('');
|
||||
|
||||
const ordering = ref(false);
|
||||
const errMsg = ref('');
|
||||
|
||||
const orderNo = ref('');
|
||||
const payUrl = ref('');
|
||||
const orderStatus = ref<'pending' | 'paid' | 'expired' | ''>('');
|
||||
const waitingPay = ref(false);
|
||||
const cardKey = ref('');
|
||||
const paidAt = ref('');
|
||||
const authMsg = ref('');
|
||||
const copied = ref<'machine' | 'card' | ''>('');
|
||||
|
||||
const PAY_METHODS = [
|
||||
{ key: 'alipay', label: '支付宝', icon: '💳' },
|
||||
{ key: 'wxpay', label: '微信支付', icon: '💚' },
|
||||
{ key: 'qqpay', label: 'QQ 钱包', icon: '🐧' },
|
||||
];
|
||||
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function fmtDays(d: number): string {
|
||||
if (d >= 999999) return '永久有效';
|
||||
if (d >= 365) return `${Math.floor(d / 365)} 年`;
|
||||
if (d >= 30) return `${Math.floor(d / 30)} 个月`;
|
||||
return `${d} 天`;
|
||||
}
|
||||
|
||||
async function loadPlans(): Promise<void> {
|
||||
loading.value = true;
|
||||
loadErr.value = '';
|
||||
try {
|
||||
const res = await fetch(`${AUTH_BASE}/public/projects/${PROJECT_ID}/card-types`);
|
||||
const j = await res.json();
|
||||
if (j.code !== 200) throw new Error(j.message || '获取套餐失败');
|
||||
plans.value = (j.data || []) as CardType[];
|
||||
if (plans.value.length && !selPlan.value) selPlan.value = plans.value[0];
|
||||
} catch (e: any) {
|
||||
loadErr.value = e?.message || '加载失败,请刷新重试';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function copyText(text: string, tag: 'machine' | 'card'): void {
|
||||
navigator.clipboard?.writeText(text).then(() => {
|
||||
copied.value = tag;
|
||||
setTimeout(() => {
|
||||
if (copied.value === tag) copied.value = '';
|
||||
}, 1600);
|
||||
});
|
||||
}
|
||||
|
||||
function stopPoll(): void {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
waitingPay.value = false;
|
||||
}
|
||||
|
||||
async function pollOnce(): Promise<void> {
|
||||
if (!orderNo.value) return;
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${AUTH_BASE}/public/orders/query?order_no=${encodeURIComponent(orderNo.value)}`
|
||||
);
|
||||
const j = await res.json();
|
||||
if (j.code !== 200) return;
|
||||
const d = j.data || {};
|
||||
orderStatus.value = d.status || '';
|
||||
if (d.status === 'paid') {
|
||||
stopPoll();
|
||||
cardKey.value = d.card_key || '';
|
||||
paidAt.value = d.paid_at || '';
|
||||
await refreshAuth();
|
||||
} else if (d.status === 'expired') {
|
||||
stopPoll();
|
||||
errMsg.value = '订单已过期,请重新下单';
|
||||
}
|
||||
} catch {
|
||||
/* 网络抖动忽略,继续轮询 */
|
||||
}
|
||||
}
|
||||
|
||||
function startPoll(): void {
|
||||
stopPoll();
|
||||
waitingPay.value = true;
|
||||
pollOnce();
|
||||
timer = setInterval(pollOnce, POLL_MS);
|
||||
}
|
||||
|
||||
async function refreshAuth(): Promise<void> {
|
||||
authMsg.value = '正在核验授权…';
|
||||
try {
|
||||
const ok = await checkAuth();
|
||||
authMsg.value = ok ? `授权已生效,${paidCount} 个高级功能已解锁` : '卡密已发放,授权暂未刷新,请点击下方重新核验';
|
||||
} catch {
|
||||
authMsg.value = '授权核验失败,请稍后重试';
|
||||
}
|
||||
}
|
||||
|
||||
async function buy(): Promise<void> {
|
||||
errMsg.value = '';
|
||||
if (!selPlan.value) {
|
||||
errMsg.value = '请先选择套餐';
|
||||
return;
|
||||
}
|
||||
ordering.value = true;
|
||||
try {
|
||||
const body: Record<string, any> = {
|
||||
project_id: PROJECT_ID,
|
||||
card_type_id: selPlan.value.id,
|
||||
pay_type: payType.value,
|
||||
bot_qq: machineId.value,
|
||||
contact_qq: machineId.value,
|
||||
};
|
||||
if (couponCode.value.trim()) body.coupon_code = couponCode.value.trim();
|
||||
|
||||
const res = await fetch(`${AUTH_BASE}/public/orders`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (j.code !== 200) throw new Error(j.message || '下单失败');
|
||||
|
||||
orderNo.value = j.data.order_no;
|
||||
payUrl.value = j.data.pay_url;
|
||||
orderStatus.value = 'pending';
|
||||
cardKey.value = '';
|
||||
authMsg.value = '';
|
||||
localStorage.setItem(ORDER_KEY, JSON.stringify({ order_no: orderNo.value }));
|
||||
|
||||
// 支付页新窗口打开,本页留守轮询
|
||||
window.open(payUrl.value, '_blank', 'noopener');
|
||||
startPoll();
|
||||
} catch (e: any) {
|
||||
errMsg.value = e?.message || '下单失败,请稍后重试';
|
||||
} finally {
|
||||
ordering.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function reopenPay(): void {
|
||||
if (payUrl.value) window.open(payUrl.value, '_blank', 'noopener');
|
||||
}
|
||||
|
||||
function clearOrder(): void {
|
||||
stopPoll();
|
||||
orderNo.value = '';
|
||||
payUrl.value = '';
|
||||
orderStatus.value = '';
|
||||
cardKey.value = '';
|
||||
authMsg.value = '';
|
||||
errMsg.value = '';
|
||||
localStorage.removeItem(ORDER_KEY);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
machineId.value = getMachineId();
|
||||
await loadPlans();
|
||||
// 恢复未完成订单,继续轮询
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(ORDER_KEY) || 'null');
|
||||
if (saved?.order_no) {
|
||||
orderNo.value = saved.order_no;
|
||||
orderStatus.value = 'pending';
|
||||
startPoll();
|
||||
}
|
||||
} catch {
|
||||
/* 忽略脏数据 */
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(stopPoll);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="px-page">
|
||||
<div class="hero">
|
||||
<div class="hero-title">🔐 购买卡密</div>
|
||||
<div class="hero-sub">
|
||||
支付成功后本页直接显示卡密,同时本机立即解锁 {{ paidCount }} 个高级功能
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 本机机器码 -->
|
||||
<div class="box machine-box">
|
||||
<div class="box-label">本机机器码</div>
|
||||
<div class="machine-row">
|
||||
<code class="machine-id">{{ machineId || '读取中…' }}</code>
|
||||
<c-button size="small" @click="copyText(machineId, 'machine')">
|
||||
{{ copied === 'machine' ? '已复制 ✓' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<div class="box-hint">
|
||||
下单会自动绑定到这台电脑;换电脑时用支付后得到的卡密重新激活即可。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="licenseState.authorized" class="box ok-box">
|
||||
✅ 本机已拥有授权,无需重复购买。
|
||||
</div>
|
||||
|
||||
<!-- 套餐 -->
|
||||
<div class="section">
|
||||
<div class="section-title">① 选择套餐</div>
|
||||
<div v-if="loading" class="tip">套餐加载中…</div>
|
||||
<div v-else-if="loadErr" class="tip err">{{ loadErr }}</div>
|
||||
<div v-else class="plan-grid">
|
||||
<div
|
||||
v-for="p in plans"
|
||||
:key="p.id"
|
||||
class="plan-card"
|
||||
:class="{ on: selPlan?.id === p.id }"
|
||||
@click="selPlan = p"
|
||||
>
|
||||
<div class="plan-name">{{ p.name }}</div>
|
||||
<div class="plan-price">
|
||||
<span class="cur">¥</span>{{ p.price }}
|
||||
<span v-if="Number(p.original_price) > 0" class="origin">¥{{ p.original_price }}</span>
|
||||
</div>
|
||||
<div class="plan-meta">{{ fmtDays(p.duration_days) }} · {{ paidCount }} 个高级功能</div>
|
||||
<div v-if="p.description" class="plan-desc">{{ p.description }}</div>
|
||||
</div>
|
||||
<div v-if="!plans.length" class="tip">暂无可售套餐</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 支付方式 -->
|
||||
<div class="section">
|
||||
<div class="section-title">② 选择支付方式</div>
|
||||
<div class="pay-grid">
|
||||
<div
|
||||
v-for="m in PAY_METHODS"
|
||||
:key="m.key"
|
||||
class="pay-card"
|
||||
:class="{ on: payType === m.key }"
|
||||
@click="payType = m.key"
|
||||
>
|
||||
<span class="pay-icon">{{ m.icon }}</span>{{ m.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 优惠码 -->
|
||||
<div class="section">
|
||||
<div class="section-title">③ 优惠码<span class="opt">(选填)</span></div>
|
||||
<input
|
||||
v-model="couponCode"
|
||||
class="coupon-input"
|
||||
placeholder="没有可留空"
|
||||
maxlength="32"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="buy-bar">
|
||||
<div class="amount">
|
||||
应付 <b>¥{{ selPlan ? selPlan.price : '0.00' }}</b>
|
||||
</div>
|
||||
<c-button type="primary" size="large" :loading="ordering" @click="buy">
|
||||
{{ ordering ? '正在创建订单…' : '立即支付' }}
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<div v-if="errMsg" class="tip err">{{ errMsg }}</div>
|
||||
|
||||
<!-- 订单状态 -->
|
||||
<div v-if="orderNo" class="box order-box">
|
||||
<div class="order-head">
|
||||
<span>订单号 <code>{{ orderNo }}</code></span>
|
||||
<a v-if="payUrl && orderStatus === 'pending'" href="javascript:;" class="lnk" @click="reopenPay">
|
||||
打开支付页 ↗
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div v-if="orderStatus === 'pending'" class="order-wait">
|
||||
<span class="dots" />
|
||||
等待支付完成…(支付页已在新标签打开,付款后本页会自动刷新)
|
||||
<a href="javascript:;" class="lnk" @click="pollOnce">刷新状态</a>
|
||||
<a href="javascript:;" class="lnk dim" @click="clearOrder">取消此单</a>
|
||||
</div>
|
||||
|
||||
<template v-if="orderStatus === 'paid'">
|
||||
<div class="paid-head">✅ 支付成功</div>
|
||||
|
||||
<div class="card-box">
|
||||
<div class="card-label">你的卡密(请妥善保存)</div>
|
||||
<div class="card-row">
|
||||
<code class="card-key">{{ cardKey || '—' }}</code>
|
||||
<c-button
|
||||
v-if="cardKey"
|
||||
size="small"
|
||||
type="primary"
|
||||
@click="copyText(cardKey, 'card')"
|
||||
>
|
||||
{{ copied === 'card' ? '已复制 ✓' : '复制卡密' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<div v-if="paidAt" class="box-hint">支付时间:{{ paidAt }}</div>
|
||||
</div>
|
||||
|
||||
<div class="auth-line" :class="{ pending: licenseState.authorized === false }">
|
||||
{{ authMsg || '授权核验中…' }}
|
||||
</div>
|
||||
|
||||
<div class="auth-actions">
|
||||
<c-button size="small" :loading="licenseState.checking" @click="refreshAuth">
|
||||
重新核验授权
|
||||
</c-button>
|
||||
<c-button size="small" @click="clearOrder">再买一单</c-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="orderStatus === 'expired'" class="tip err">订单已过期</div>
|
||||
</div>
|
||||
|
||||
<div class="notes">
|
||||
<div class="note-item">🔒 买断制:不按次、不按月,一次付费永久使用。</div>
|
||||
<div class="note-item">🧭 授权跟随机器码绑定,换电脑用卡密重新激活即可恢复。</div>
|
||||
<div class="note-item">🎁 支付成功即解锁 {{ paidCount }} 个高级功能,无需等待人工发货。</div>
|
||||
<div class="note-item">❓ 卡密丢失可凭订单号联系管理员找回。</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.px-page {
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px 80px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
|
||||
.hero-title {
|
||||
font-size: 30px;
|
||||
font-weight: 800;
|
||||
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 55%, rgba(20, 160, 88, 1) 100%);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.hero-sub {
|
||||
margin-top: 10px;
|
||||
font-size: 14.5px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
.box {
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.machine-box {
|
||||
.box-label,
|
||||
.card-label {
|
||||
font-size: 12.5px;
|
||||
opacity: 0.6;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.machine-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.machine-id {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
user-select: all;
|
||||
}
|
||||
}
|
||||
|
||||
.box-hint {
|
||||
margin-top: 8px;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.ok-box {
|
||||
color: #18a058;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 24px;
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.opt {
|
||||
font-size: 12.5px;
|
||||
font-weight: 400;
|
||||
opacity: 0.55;
|
||||
}
|
||||
}
|
||||
|
||||
.tip {
|
||||
font-size: 13.5px;
|
||||
opacity: 0.7;
|
||||
|
||||
&.err {
|
||||
color: #d03050;
|
||||
opacity: 1;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.plan-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.plan-card {
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(24, 160, 88, 0.5);
|
||||
}
|
||||
|
||||
&.on {
|
||||
border-color: #18a058;
|
||||
box-shadow: 0 0 0 1px rgba(24, 160, 88, 0.35), 0 6px 18px rgba(24, 160, 88, 0.12);
|
||||
}
|
||||
|
||||
.plan-name {
|
||||
font-size: 15.5px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.plan-price {
|
||||
margin-top: 8px;
|
||||
font-size: 30px;
|
||||
font-weight: 800;
|
||||
color: #18a058;
|
||||
|
||||
.cur {
|
||||
font-size: 16px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
.origin {
|
||||
margin-left: 8px;
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
opacity: 0.45;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
.plan-meta {
|
||||
margin-top: 6px;
|
||||
font-size: 13px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.plan-desc {
|
||||
margin-top: 6px;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
}
|
||||
|
||||
.pay-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.pay-card {
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(24, 160, 88, 0.5);
|
||||
}
|
||||
|
||||
&.on {
|
||||
border-color: #18a058;
|
||||
box-shadow: 0 0 0 1px rgba(24, 160, 88, 0.35);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pay-icon {
|
||||
font-size: 17px;
|
||||
}
|
||||
}
|
||||
|
||||
.coupon-input {
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
padding: 9px 12px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
|
||||
&:focus {
|
||||
border-color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.buy-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 16px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.amount {
|
||||
font-size: 14.5px;
|
||||
opacity: 0.75;
|
||||
|
||||
b {
|
||||
font-size: 26px;
|
||||
color: #18a058;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.order-box {
|
||||
border-color: rgba(24, 160, 88, 0.45);
|
||||
}
|
||||
|
||||
.order-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
font-size: 13.5px;
|
||||
opacity: 0.8;
|
||||
flex-wrap: wrap;
|
||||
|
||||
code {
|
||||
user-select: all;
|
||||
}
|
||||
}
|
||||
|
||||
.lnk {
|
||||
color: #18a058;
|
||||
text-decoration: none;
|
||||
font-size: 13.5px;
|
||||
|
||||
&.dim {
|
||||
opacity: 0.6;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.order-wait {
|
||||
margin-top: 12px;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.dots {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: #f0a020;
|
||||
animation: blink 1s infinite alternate;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
from { opacity: 0.25; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.paid-head {
|
||||
margin-top: 14px;
|
||||
font-size: 18px;
|
||||
font-weight: 800;
|
||||
color: #18a058;
|
||||
}
|
||||
|
||||
.card-box {
|
||||
margin-top: 12px;
|
||||
padding: 14px;
|
||||
border: 1px dashed rgba(24, 160, 88, 0.55);
|
||||
border-radius: 10px;
|
||||
background: rgba(24, 160, 88, 0.06);
|
||||
|
||||
.card-label {
|
||||
font-size: 12.5px;
|
||||
opacity: 0.7;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.card-key {
|
||||
font-size: 19px;
|
||||
font-weight: 800;
|
||||
letter-spacing: 1.2px;
|
||||
user-select: all;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.auth-line {
|
||||
margin-top: 12px;
|
||||
font-size: 14px;
|
||||
color: #18a058;
|
||||
font-weight: 600;
|
||||
|
||||
&.pending {
|
||||
color: #f0a020;
|
||||
}
|
||||
}
|
||||
|
||||
.auth-actions {
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.notes {
|
||||
margin-top: 28px;
|
||||
border-top: 1px solid rgba(128, 128, 128, 0.2);
|
||||
padding-top: 18px;
|
||||
|
||||
.note-item {
|
||||
font-size: 13.5px;
|
||||
opacity: 0.65;
|
||||
line-height: 1.9;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+17
-5
@@ -9,7 +9,19 @@ import { useToolStore } from '@/tools/tools.store';
|
||||
import { useRecentTools } from '@/composable/recent-tools';
|
||||
|
||||
// 近期新功能亮点(手动维护,新工具上线时加一条)
|
||||
// ★铁规则:每完成一批新功能/新工具,必须在这里最前面加条目(新→旧),否则首页看不到
|
||||
const NEW_FEATURES = [
|
||||
{ path: '/admin', icon: '📁', name: '后台文件管理', desc: '默认聚合所有用户文件与AI生成图片,每页50条自动分页显示总记录数,图片100×100缩略图、其他文件显示类型,全部支持单独下载' },
|
||||
{ path: '/ai-gen', icon: '🗂️', name: '图片历史铁规则', desc: '所有生图功能右侧 50×50 缩略图历史竖排、点击看大图,按登录账号/机器码只看本人的,生成即保存到后台指定目录,全部功能历史最多显示100条' },
|
||||
{ path: '/face-swap', icon: '🎭', name: 'AI 换脸', desc: '上传源人脸与目标照片,本地 AI 一键换脸(insightface 人脸检测+inswapper),授权功能支持免费试用' },
|
||||
{ path: '/poster-maker', icon: '🖼️', name: 'AI 海报生成', desc: '42套模板10分类(含校园师生款)、文字图片可旋转、整页自适应不滚动,改文字换图片AI生成配图,一键导出 PNG' },
|
||||
{ path: '/ai-gen', icon: '🎨', name: 'AI 生图', desc: '10款内置模型一键出图,四组86个现成提示词(通用/自媒体/电商/软件类),中文自动转英文发送' },
|
||||
{ path: '/mcp-connect', icon: '🔌', name: 'AI 接入 (MCP)', desc: '把本站能力接到任意 AI 客户端,13个工具、卡密令牌管理、调用记录后台可查' },
|
||||
{ path: '/admin', icon: '📊', name: '管理后台升级', desc: '使用统计含未登录访客、在线人数实时排行、留言反馈与公告推送、用户最后登录时间' },
|
||||
{ path: '/my-ip', icon: '🌍', name: '本机IP查询', desc: '公网IPv4/IPv6地址与所属地一键查询,自动测9个热门地点延迟,一键测试当前下载上传网速' },
|
||||
{ path: '/code-reader', icon: '🧩', name: '二维码生成', desc: '识别工具内新能力:自定义颜色、中间插入本地 Logo 图,生成后自动自扫验证' },
|
||||
{ path: '/base64-image-converter', icon: '🔁', name: 'Base64图片互转', desc: 'Base64转图片与图片转Base64合一页,三格式自动识别,纯浏览器本地不上传' },
|
||||
{ path: '/image-tools', icon: '🖌️', name: '图片编辑·无痕改字', desc: 'PS式图层画笔选区,OCR点字框自动匹配字号颜色角度无缝改字' },
|
||||
{ path: '/seal-maker', icon: '🔴', name: '印章生成器', desc: '圆形公章一键生成,盖章到图片/PDF,支持骑缝章' },
|
||||
{ path: '/signature-pad', icon: '✍️', name: '手写签名', desc: '真实笔触模拟,透明 PNG,签合同一步到位' },
|
||||
{ path: '/text-to-image', icon: '🖼️', name: '文字生成图片', desc: '多行文字排版出图,字体颜色可调,2x/3x 高清' },
|
||||
@@ -43,8 +55,8 @@ onMounted(async () => {
|
||||
catch { /* 无推荐则隐藏 */ }
|
||||
});
|
||||
|
||||
// 每日 5 列资讯:GITHUB/国际新闻/AI资讯/IT最新技术/当天最热股票
|
||||
// 前 4 列 relay 每天 08:00 抓取;「当天最热股票」交易时段 60s 高频刷新
|
||||
// 每日 5 列资讯:GITHUB/国际新闻/AI资讯/IT最新技术/AI最热股票
|
||||
// 前 4 列 relay 每天 08:00 抓取;「AI最热股票」交易时段 60s 高频刷新
|
||||
const newsCols = ref<any[]>([]);
|
||||
const newsDate = ref('');
|
||||
const newsMarket = ref<'open' | 'closed' | ''>('');
|
||||
@@ -74,7 +86,7 @@ onUnmounted(() => {
|
||||
if (newsTimer) clearInterval(newsTimer);
|
||||
});
|
||||
|
||||
// ===== 股票列选项卡:最热 / 自选(自选实时行情,登录后随云同步)=====
|
||||
// ===== 股票列选项卡:AI最热 / 自选(自选实时行情,登录后随云同步)=====
|
||||
const MY_STOCKS_KEY = 'it-tools-my-stocks';
|
||||
const stockTab = ref<'hot' | 'mine'>('hot');
|
||||
const stockInput = ref('');
|
||||
@@ -213,7 +225,7 @@ function onUpdateFavoriteTools() {
|
||||
>{{ newsMarket === 'open' ? '交易中' : '休市' }}</span>
|
||||
</div>
|
||||
<div v-if="col.key === 'stock'" class="stock-tabs">
|
||||
<button class="stock-tab" :class="{ on: stockTab === 'hot' }" @click="switchStockTab('hot')">最热</button>
|
||||
<button class="stock-tab" :class="{ on: stockTab === 'hot' }" @click="switchStockTab('hot')">AI最热</button>
|
||||
<button class="stock-tab" :class="{ on: stockTab === 'mine' }" @click="switchStockTab('mine')">自选<template v-if="myStocks.length">·{{ myStocks.length }}</template></button>
|
||||
</div>
|
||||
<div class="news-list">
|
||||
@@ -233,7 +245,7 @@ function onUpdateFavoriteTools() {
|
||||
<button class="mystock-x" title="移出自选" @click="removeMyStock(q.code)">✕</button>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 最热(默认) -->
|
||||
<!-- AI 最热(默认):AI 概念板块成分股按成交额排序 -->
|
||||
<template v-else>
|
||||
<a
|
||||
v-for="(it, i) in col.items"
|
||||
|
||||
+43
-62
@@ -1,9 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { BUY_URL, PROTECTED_TOOLS, getMachineId } from '@/tools/license/license';
|
||||
import { PROTECTED_TOOLS, getMachineId } from '@/tools/license/license';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
|
||||
useHead({ title: '授权应用 - IT-TOOLS-PRO' });
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
/** 「前往购买卡密」→ 站内支付页 /buy */
|
||||
function goBuy(): void {
|
||||
router.push('/buy');
|
||||
}
|
||||
|
||||
interface Feature {
|
||||
path: string;
|
||||
name: string;
|
||||
@@ -11,65 +19,38 @@ interface Feature {
|
||||
points: string[];
|
||||
}
|
||||
|
||||
const FEATURES: Feature[] = [
|
||||
{
|
||||
path: '/translator',
|
||||
name: '在线翻译',
|
||||
icon: '🌐',
|
||||
points: ['支持中英日韩等 16 种语言互译', '谷歌翻译主线 + MyMemory 备用双线路', '粘贴即译,自动识别源语言'],
|
||||
},
|
||||
{
|
||||
path: '/image-ocr',
|
||||
name: '图片OCR文字识别',
|
||||
icon: '📷',
|
||||
points: ['本地 OCR 引擎,中文识别准确率 99%+', '截图、扫描件、照片文字一键提取', '逐行输出带置信度,支持粘贴图片'],
|
||||
},
|
||||
{
|
||||
path: '/pdf-ocr',
|
||||
name: 'PDF文字识别',
|
||||
icon: '📄',
|
||||
points: ['逐页 OCR 中英文 PDF(最多 50 页)', '每页预览、翻页查看识别结果', '一键复制全部或下载 TXT'],
|
||||
},
|
||||
{
|
||||
path: '/ai-retouch',
|
||||
name: 'AI修图',
|
||||
icon: '🎨',
|
||||
points: ['去水印/修复:涂抹区域智能填充', '抠图去背景、4x 超分辨率、人脸修复', '本地 AI 模型推理,单张 10 秒级出图'],
|
||||
},
|
||||
{
|
||||
path: '/pdf-tools',
|
||||
name: 'PDF工具',
|
||||
icon: '📑',
|
||||
points: ['合并/拆分/旋转/重排/压缩等 11 种常用处理', '加密/解密/加水印/提取文本/加页码/转图片', '全程浏览器本地处理,文件不上传服务器'],
|
||||
},
|
||||
{
|
||||
path: '/image-tools',
|
||||
name: '图片工具',
|
||||
icon: '🖼️',
|
||||
points: ['压缩/转换/尺寸/裁剪/旋转/滤镜等 12 种常用处理', '打码、加水印、拼接、EXIF 查看编辑', '全程浏览器本地处理,图片不上传服务器'],
|
||||
},
|
||||
{
|
||||
path: '/video-tools',
|
||||
name: '视频工具',
|
||||
icon: '🎥',
|
||||
points: ['格式转换/压缩/裁剪/旋转/变速/消音/提取音频/截图/GIF互转等 11 个工具', '服务端 ffmpeg 高速转码,最大支持 2GB 视频', '处理完在线预览,一键下载结果'],
|
||||
},
|
||||
{
|
||||
path: '/audio-tools',
|
||||
name: '音频工具',
|
||||
icon: '🎙️',
|
||||
points: ['文字转音频:本地神经 TTS,离线可用速度快', '音频转文字:Whisper 引擎,中英日粤自动检测带时间轴', '声音克隆:5 秒样本克隆音色(即将上线)'],
|
||||
},
|
||||
{
|
||||
path: '/doc-convert',
|
||||
name: '文档格式转换',
|
||||
icon: '🔄',
|
||||
points: ['Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九种格式互转', '自建转换引擎,批量转换打包下载', '单文件最快几秒完成'],
|
||||
},
|
||||
];
|
||||
/** 授权功能营销卖点:key = 工具 path。
|
||||
* ★ 新开发的授权应用只要加进 license.ts 的 PROTECTED_TOOLS,本页会自动出现,
|
||||
* 没写文案的会用工具自身的名称/描述兜底(想更好看再往这张表里补 icon + points)。
|
||||
* (2026-11-13 用户要求:授权应用开发完必须自动同步到本页,禁止再手工维护清单) */
|
||||
const MARKETING: Record<string, { icon: string; points: string[] }> = {
|
||||
'/translator': { icon: '🌐', points: ['文本翻译 16 种语言,自动识别源语言', '中英互译走本地开源引擎不限流,其他语种自动切备用线路', '文档整篇翻译(中英),扫描件/图片自动 OCR,译文可下载'] },
|
||||
'/image-ocr': { icon: '📷', points: ['本地 OCR 引擎,中文识别准确率 99%+', '截图、扫描件、照片文字一键提取', '逐行输出带置信度,支持粘贴图片'] },
|
||||
'/pdf-ocr': { icon: '📄', points: ['逐页 OCR 中英文 PDF(最多 50 页)', '每页预览、翻页查看识别结果', '一键复制全部或下载 TXT'] },
|
||||
'/ai-retouch': { icon: '🎨', points: ['去水印/修复:涂抹区域智能填充', '抠图去背景、4x 超分辨率、人脸修复', '本地 AI 模型推理,单张 10 秒级出图'] },
|
||||
'/pdf-tools': { icon: '📑', points: ['合并/拆分/旋转/重排/压缩等 11 种常用处理', '加密/解密/加水印/提取文本/加页码/转图片', '全程浏览器本地处理,文件不上传服务器'] },
|
||||
'/image-tools': { icon: '🖼️', points: ['压缩/转换/尺寸/裁剪/旋转/滤镜等 12 种常用处理', '打码、加水印、拼接、EXIF 查看编辑', '全程浏览器本地处理,图片不上传服务器'] },
|
||||
'/video-tools': { icon: '🎥', points: ['格式转换/压缩/裁剪/旋转/变速/消音/提取音频/截图/GIF互转等 11 个工具', '服务端 ffmpeg 高速转码,最大支持 2GB 视频', '处理完在线预览,一键下载结果'] },
|
||||
'/audio-tools': { icon: '🎙️', points: ['文字转音频:本地神经 TTS,离线可用速度快', '音频转文字:Whisper 引擎,中英日粤自动检测带时间轴', '声音克隆:5 秒样本克隆音色(即将上线)'] },
|
||||
'/doc-convert': { icon: '🔄', points: ['Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九种格式互转', '自建转换引擎,批量转换打包下载', '单文件最快几秒完成'] },
|
||||
'/text-to-image': { icon: '🔤', points: ['输入文字一键排版成图,字体/颜色/尺寸/背景可调', '适合做封面、标语、社媒配图,出图即下载', '本地渲染不联网,批量出图不排队'] },
|
||||
'/ai-image-lab': { icon: '🪄', points: ['智能抠图去背景,发丝级边缘', 'AI 无损放大、模糊变清晰', '证件照制作:换底色、按规格裁剪'] },
|
||||
'/copywriting': { icon: '✍️', points: ['AI 一键改写、降低 AIGC 率', '爆款标题、小红书/朋友圈文案', '多风格模板,改完即可用'] },
|
||||
'/ai-gen': { icon: '🖌️', points: ['多模型文生图,宽高比可选', '内置示例提示词,新手一键出图', '生成记录可管理、可下载'] },
|
||||
};
|
||||
|
||||
// only show tools that are actually in the protected list
|
||||
const paidFeatures = FEATURES.filter(f => f.path in PROTECTED_TOOLS);
|
||||
/** 授权功能清单 = license.ts 的 PROTECTED_TOOLS(唯一权威源),本页零手工维护 */
|
||||
const toolStore = useToolStore();
|
||||
const paidFeatures = computed<Feature[]>(() => Object.keys(PROTECTED_TOOLS).map((path) => {
|
||||
const tool = toolStore.tools.find(t => t.path === path);
|
||||
const m = MARKETING[path];
|
||||
return {
|
||||
path,
|
||||
name: PROTECTED_TOOLS[path] || tool?.name || path,
|
||||
icon: m?.icon || '🧩',
|
||||
points: m?.points || [tool?.description || '授权高级功能,一次激活全部通用'],
|
||||
};
|
||||
}));
|
||||
|
||||
const machineId = getMachineId();
|
||||
const copied = ref(false);
|
||||
@@ -101,7 +82,7 @@ async function copyMachine() {
|
||||
<div class="hero">
|
||||
<div class="hero-title">🚀 授权解锁全部高级功能</div>
|
||||
<div class="hero-sub">
|
||||
IT-TOOLS-PRO 的 20+ 基础工具永久免费(含面单设计),下面 9 个算力型高级功能需要授权。一次激活,全部通用。
|
||||
IT-TOOLS-PRO 的 20+ 基础工具永久免费(含面单设计),下面 {{ paidFeatures.length }} 个算力型高级功能需要授权。一次激活,全部通用。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -137,7 +118,7 @@ async function copyMachine() {
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">🔑</div>
|
||||
<div class="adv-title">一次激活,全站通用</div>
|
||||
<div class="adv-desc">输入一次卡密,13 个高级功能全部解锁,无需逐个购买</div>
|
||||
<div class="adv-desc">输入一次卡密,{{ paidFeatures.length }} 个高级功能全部解锁,无需逐个购买</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">♾️</div>
|
||||
@@ -189,7 +170,7 @@ async function copyMachine() {
|
||||
</div>
|
||||
</div>
|
||||
<div class="cta-right">
|
||||
<c-button type="primary" class="cta-btn" tag="a" :href="BUY_URL" target="_blank" rel="noopener">
|
||||
<c-button type="primary" class="cta-btn" @click="goBuy">
|
||||
💳 前往购买卡密
|
||||
</c-button>
|
||||
<div class="cta-hint">
|
||||
|
||||
@@ -4,6 +4,7 @@ import HomePage from './pages/Home.page.vue';
|
||||
import NotFound from './pages/404.page.vue';
|
||||
import { tools } from './tools';
|
||||
import { config } from './config';
|
||||
import { reportToolUsage, startOnlineHeartbeat } from './tools/license/license';
|
||||
import { routes as demoRoutes } from './ui/demo/demo.routes';
|
||||
|
||||
const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({
|
||||
@@ -46,6 +47,11 @@ const router = createRouter({
|
||||
name: 'pricing',
|
||||
component: () => import('./pages/Pricing.page.vue'),
|
||||
},
|
||||
{
|
||||
path: '/buy',
|
||||
name: 'buy',
|
||||
component: () => import('./pages/Buy.page.vue'),
|
||||
},
|
||||
...toolsRoutes,
|
||||
...toolsRedirectRoutes,
|
||||
...(config.app.env === 'development' ? demoRoutes : []),
|
||||
@@ -53,4 +59,13 @@ const router = createRouter({
|
||||
],
|
||||
});
|
||||
|
||||
// 打开任意工具页即上报一次使用(未登录访客同样统计,见 license.ts reportToolUsage)
|
||||
router.afterEach((to) => {
|
||||
if (to.meta?.isTool) {
|
||||
reportToolUsage(String(to.path));
|
||||
}
|
||||
// 全站在线心跳:停留满 1 分钟的未登录访客才计在线(内部 once 保护)
|
||||
startOnlineHeartbeat();
|
||||
});
|
||||
|
||||
export default router;
|
||||
+779
-64
File diff suppressed because it is too large.
Load diff
@@ -2,11 +2,22 @@
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { licenseHeaders } from '@/tools/license/license';
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
import ImgHist from '@/tools/img-hist/ImgHist.vue';
|
||||
import { blobToB64, dataUrlToB64, saveImgHist } from '@/tools/img-hist/img-hist';
|
||||
|
||||
useHead({ title: 'AI 图片实验室 - IT-TOOLS-PRO' });
|
||||
const genHist = useGenHistory('ai-image-lab');
|
||||
const histRef = ref<InstanceType<typeof ImgHist> | null>(null);
|
||||
|
||||
/** 处理结果保存到服务器历史(失败静默,不影响下载) */
|
||||
async function saveLab(model: string, prompt: string, src: Blob | string) {
|
||||
try {
|
||||
const b64 = typeof src === 'string' ? dataUrlToB64(src) : await blobToB64(src);
|
||||
if (!b64) return;
|
||||
const ok = await saveImgHist({ kind: 'ai-image-lab', tool: 'ai-image-tools', b64, model, prompt });
|
||||
if (ok) histRef.value?.reload();
|
||||
}
|
||||
catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
type TabKey = 'matting' | 'upscale' | 'idphoto';
|
||||
const tab = ref<TabKey>('matting');
|
||||
@@ -83,7 +94,7 @@ async function doMatting() {
|
||||
}
|
||||
outUrl.value = URL.createObjectURL(blob);
|
||||
outBlob.value = blob;
|
||||
genHist.add({ title: `AI 抠图: ${curFile.value.name}`, detail: `${(blob.size / 1024).toFixed(0)}KB` });
|
||||
saveLab('AI抠图', curFile.value?.name || '', blob);
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
@@ -156,7 +167,7 @@ async function doUpscale() {
|
||||
await new Promise<void>((r) => {
|
||||
img.onload = () => r();
|
||||
});
|
||||
genHist.add({ title: `AI 放大 ${upScale.value}x: ${curFile.value.name}`, detail: `${img.naturalWidth}×${img.naturalHeight} · ${(blob.size / 1024).toFixed(0)}KB` });
|
||||
saveLab(`AI放大${upScale.value}x`, curFile.value?.name || '', blob);
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
@@ -211,7 +222,7 @@ async function makeIdPhoto() {
|
||||
URL.revokeObjectURL(idResult.value);
|
||||
}
|
||||
idResult.value = c.toDataURL('image/png');
|
||||
genHist.add({ title: `证件照: ${spec.name} ${idBg.value === 'white' ? '白底' : idBg.value === 'red' ? '红底' : '蓝底'}`, detail: `${spec.w}×${spec.h}` });
|
||||
saveLab('证件照', `${spec.name} ${idBg.value === 'white' ? '白底' : idBg.value === 'red' ? '红底' : '蓝底'}`, idResult.value || '');
|
||||
}
|
||||
|
||||
function downloadUrl(url: string, name: string) {
|
||||
@@ -319,7 +330,7 @@ onMounted(() => {});
|
||||
<div class="al-right">
|
||||
<div class="al-sec">
|
||||
{{ tab === 'idphoto' ? '证件照预览' : outUrl ? '处理结果' : '原图预览' }}
|
||||
<button v-if="tab === 'idphoto' && idResult" class="al-dl" @click="downloadUrl(idResult, '证件照.png')">⬇ 下载证件照</button>
|
||||
<button v-if="tab === 'idphoto' && idResult" class="al-dl" @click="saveLab('证件照', '证件照下载', idResult); downloadUrl(idResult, '证件照.png')">⬇ 下载证件照</button>
|
||||
<button v-else-if="outUrl && tab !== 'idphoto'" class="al-dl" @click="downloadUrl(outUrl, tab === 'matting' ? '抠图.png' : `放大${upScale}x.${(curFile?.name || '').split('.').pop() || 'jpg'}`)">⬇ 下载结果</button>
|
||||
</div>
|
||||
<div class="al-preview">
|
||||
@@ -328,8 +339,8 @@ onMounted(() => {});
|
||||
<img v-else-if="srcUrl" :src="srcUrl" class="al-img" alt="source">
|
||||
<div v-else class="al-empty">上传图片后在这里预览</div>
|
||||
</div>
|
||||
<GenHistory tool="ai-image-lab" label="AI 图片记录" class="mt-10px" />
|
||||
</div>
|
||||
<ImgHist ref="histRef" kind="ai-image-lab" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { useUserAuth } from '@/composable/user-auth';
|
||||
import { licenseHeaders } from '../license/license';
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
import ImgHist from '@/tools/img-hist/ImgHist.vue';
|
||||
import { blobToB64, saveImgHist } from '@/tools/img-hist/img-hist';
|
||||
|
||||
const genHist = useGenHistory('ai-retouch');
|
||||
const histRef = ref<InstanceType<typeof ImgHist> | null>(null);
|
||||
|
||||
/** 修图结果保存到服务器历史(失败静默,不影响下载) */
|
||||
async function saveRetouch(blob: Blob) {
|
||||
try {
|
||||
const b64 = await blobToB64(blob);
|
||||
if (!b64) return;
|
||||
const ok = await saveImgHist({ kind: 'ai-retouch', tool: 'ai-retouch', b64, model: tab.value.label, prompt: fileName.value || '' });
|
||||
if (ok) histRef.value?.reload();
|
||||
}
|
||||
catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
interface TabDef {
|
||||
key: string;
|
||||
@@ -211,6 +222,7 @@ async function submit() {
|
||||
}
|
||||
const blob = await res.blob();
|
||||
resultUrl.value = URL.createObjectURL(blob);
|
||||
saveRetouch(blob);
|
||||
if (tab.value.key === 'inpaint') clearMask();
|
||||
}
|
||||
catch (e: any) {
|
||||
@@ -219,12 +231,7 @@ async function submit() {
|
||||
finally {
|
||||
elapsed.value = Math.round(performance.now() - start);
|
||||
processing.value = false;
|
||||
if (resultUrl.value) {
|
||||
genHist.add({
|
||||
title: tab.value.label,
|
||||
detail: `原图 ${imgNatural.value.w}×${imgNatural.value.h} · 耗时 ${elapsed.value}ms`,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +418,7 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</n-spin>
|
||||
</div>
|
||||
<ImgHist ref="histRef" kind="ai-retouch" />
|
||||
</div>
|
||||
|
||||
<!-- bottom bar -->
|
||||
@@ -432,7 +440,6 @@ onUnmounted(() => {
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="ai-retouch" position="right" label="修图记录" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
<script setup lang="ts">
|
||||
import { getMachineId, licenseHeaders } from '@/tools/license/license';
|
||||
import ImgHist from '@/tools/img-hist/ImgHist.vue';
|
||||
import { authHdr } from '@/tools/img-hist/img-hist';
|
||||
|
||||
// ---------- 状态 ----------
|
||||
const file = ref<File | null>(null);
|
||||
const previewUrl = ref('');
|
||||
const prompt = ref('');
|
||||
const size = ref('default');
|
||||
const customW = ref(1024);
|
||||
const customH = ref(1024);
|
||||
const count = ref(1);
|
||||
const model = ref('qwen3.8-max');
|
||||
const models = ref<string[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const note = ref('');
|
||||
const edits = ref<{ old: string; new: string; style: string }[]>([]);
|
||||
const results = ref<{ url: string; scale: number }[]>([]);
|
||||
|
||||
const SIZES = [
|
||||
{ k: 'default', label: '默认' },
|
||||
{ k: '4:3', label: '4:3' },
|
||||
{ k: '3:4', label: '3:4' },
|
||||
{ k: '1:1', label: '1:1' },
|
||||
{ k: 'custom', label: '自定义' },
|
||||
];
|
||||
|
||||
const EXAMPLES = [
|
||||
{ n: '改数字', p: '把图中"人数8"改成"31",保持原字体样式、大小和颜色' },
|
||||
{ n: '改姓名', p: '把名字"张三"改成"李四",完全匹配原字体、字号和颜色,融合背景纹理' },
|
||||
{ n: '改价格', p: '把价格"99元"改成"199元",保持促销海报的立体金色渐变效果' },
|
||||
{ n: '删除文字', p: '把图片底部的水印文字无痕删除' },
|
||||
{ n: '改金额', p: '把转账金额"¥1000.00"改成"¥5000.00",保持界面原字体和绿色气泡背景' },
|
||||
];
|
||||
|
||||
const canGo = computed(() => !!file.value && !!prompt.value.trim() && !loading.value);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await fetch('/relay/ai/vision-models');
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && Array.isArray(j.data) && j.data.length) {
|
||||
models.value = j.data;
|
||||
if (!j.data.includes(model.value)) model.value = j.data[0];
|
||||
}
|
||||
}
|
||||
catch { /* 用默认 */ }
|
||||
loadTasks();
|
||||
});
|
||||
|
||||
// ---------- 最近任务(localStorage 缩略图) ----------
|
||||
interface SETask { id: string; time: number; prompt: string; before: string; after: string; count: number }
|
||||
const tasks = ref<SETask[]>([]);
|
||||
const histRef = ref<InstanceType<typeof ImgHist> | null>(null);
|
||||
const LS_KEY = 'it-ai-text-edit:tasks';
|
||||
|
||||
function loadTasks() {
|
||||
try {
|
||||
const arr = JSON.parse(localStorage.getItem(LS_KEY) ?? '[]');
|
||||
tasks.value = Array.isArray(arr) ? arr.slice(0, 12) : [];
|
||||
}
|
||||
catch { tasks.value = []; }
|
||||
}
|
||||
|
||||
function saveTasks() {
|
||||
try {
|
||||
localStorage.setItem(LS_KEY, JSON.stringify(tasks.value.slice(0, 12)));
|
||||
}
|
||||
catch { /* 缩略图过大则丢弃历史 */ }
|
||||
}
|
||||
|
||||
/** 200px 宽 JPEG 缩略图(控制 localStorage 体积) */
|
||||
function thumbOf(url: string): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
const im = new Image();
|
||||
im.onload = () => {
|
||||
const k = 200 / Math.max(im.width, im.height);
|
||||
const c = document.createElement('canvas');
|
||||
c.width = Math.max(1, Math.round(im.width * k));
|
||||
c.height = Math.max(1, Math.round(im.height * k));
|
||||
c.getContext('2d')!.drawImage(im, 0, 0, c.width, c.height);
|
||||
resolve(c.toDataURL('image/jpeg', 0.7));
|
||||
};
|
||||
im.onerror = () => resolve('');
|
||||
im.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
function fmtTime(t: number): string {
|
||||
const d = new Date(t);
|
||||
const p = (n: number) => String(n).padStart(2, '0');
|
||||
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
// ---------- 上传 ----------
|
||||
function onPick(e: Event) {
|
||||
const f = (e.target as HTMLInputElement).files?.[0];
|
||||
if (f) setFile(f);
|
||||
}
|
||||
|
||||
function onDrop(e: DragEvent) {
|
||||
const f = e.dataTransfer?.files?.[0];
|
||||
if (f) setFile(f);
|
||||
}
|
||||
|
||||
function setFile(f: File) {
|
||||
if (!/^image\/(jpeg|png|webp)$/.test(f.type)) {
|
||||
error.value = '仅支持 JPEG / PNG / WEBP';
|
||||
return;
|
||||
}
|
||||
if (f.size > 24 * 1024 * 1024) {
|
||||
error.value = '图片超过 24MB';
|
||||
return;
|
||||
}
|
||||
file.value = f;
|
||||
error.value = '';
|
||||
if (previewUrl.value) URL.revokeObjectURL(previewUrl.value);
|
||||
previewUrl.value = URL.createObjectURL(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 submit() {
|
||||
if (!canGo.value) return;
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
note.value = '';
|
||||
edits.value = [];
|
||||
results.value = [];
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('image', file.value!, file.value!.name || 'image.png');
|
||||
fd.append('prompt', prompt.value.trim());
|
||||
fd.append('model', model.value);
|
||||
fd.append('size', size.value);
|
||||
fd.append('count', String(count.value));
|
||||
if (size.value === 'custom') {
|
||||
fd.append('custom_w', String(customW.value));
|
||||
fd.append('custom_h', String(customH.value));
|
||||
}
|
||||
const res = await fetch('/relay/ai/seamless-edit', {
|
||||
method: 'POST',
|
||||
headers: { ...licenseHeaders('ai-text-edit'), ...authHdr() },
|
||||
body: fd,
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`);
|
||||
const d = j.data || {};
|
||||
edits.value = Array.isArray(d.edits) ? d.edits : [];
|
||||
note.value = String(d.note || '');
|
||||
results.value = (Array.isArray(d.images) ? d.images : []).map((x: any) => ({ url: b64DataUrl(x.b64), scale: x.scale }));
|
||||
if (results.value.length) {
|
||||
const [before, after] = await Promise.all([thumbOf(previewUrl.value), thumbOf(results.value[0].url)]);
|
||||
tasks.value.unshift({
|
||||
id: `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`,
|
||||
time: Date.now(),
|
||||
prompt: prompt.value.trim(),
|
||||
before,
|
||||
after,
|
||||
count: results.value.length,
|
||||
});
|
||||
tasks.value = tasks.value.slice(0, 12);
|
||||
saveTasks();
|
||||
}
|
||||
histRef.value?.reload();
|
||||
else if (!note.value) {
|
||||
note.value = '未产生结果,请调整描述后重试';
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
file.value = null;
|
||||
if (previewUrl.value) URL.revokeObjectURL(previewUrl.value);
|
||||
previewUrl.value = '';
|
||||
results.value = [];
|
||||
edits.value = [];
|
||||
note.value = '';
|
||||
error.value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="se-root">
|
||||
<div class="se-head">
|
||||
<div class="se-title">无痕改字</div>
|
||||
<div class="se-sub">AI 智能修改图片文字 · 自动匹配原字体/字号/颜色/角度 · 本地模型驱动</div>
|
||||
</div>
|
||||
|
||||
<div class="se-grid">
|
||||
<!-- 左:输入面板 -->
|
||||
<div class="se-ctrl">
|
||||
<!-- 上传 -->
|
||||
<div
|
||||
class="se-upload"
|
||||
:class="{ has: !!previewUrl }"
|
||||
@click="!previewUrl && ($refs.fileInput as HTMLInputElement).click()"
|
||||
@dragover.prevent
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<template v-if="previewUrl">
|
||||
<img :src="previewUrl" class="se-upload-img" alt="">
|
||||
<div class="se-upload-bar">
|
||||
<span class="se-upload-name">{{ file?.name }}</span>
|
||||
<a href="javascript:;" class="se-upload-x" @click.stop="clearAll">✕ 重新选择</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="se-upload-icon">☁️⬆️</div>
|
||||
<div class="se-upload-t">拖拽图片到此处 · 点击上传</div>
|
||||
<div class="se-upload-s">支持最大 24MB 的 JPEG、PNG 或 WEBP 格式,全程本地+内网处理</div>
|
||||
</template>
|
||||
<input ref="fileInput" type="file" accept="image/jpeg,image/png,image/webp" style="display: none" @change="onPick">
|
||||
</div>
|
||||
|
||||
<!-- 提示词 -->
|
||||
<div class="se-sec">
|
||||
<div class="se-h">提示</div>
|
||||
<textarea
|
||||
v-model="prompt"
|
||||
class="se-prompt"
|
||||
maxlength="200"
|
||||
placeholder="填写无痕改字的具体要求,包括需要修改的文字内容和样式,例如:把图中「人数8」改成「31」,保持原字体样式和背景"
|
||||
/>
|
||||
<div class="se-count">{{ prompt.length }}/200</div>
|
||||
<div class="se-examples">
|
||||
<button v-for="ex in EXAMPLES" :key="ex.n" class="se-example" @click="prompt = ex.p">{{ ex.n }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 尺寸 -->
|
||||
<div class="se-sec">
|
||||
<div class="se-h">尺寸</div>
|
||||
<div class="se-btns">
|
||||
<button
|
||||
v-for="s in SIZES"
|
||||
:key="s.k"
|
||||
class="se-btn"
|
||||
:class="{ on: size === s.k }"
|
||||
@click="size = s.k"
|
||||
>{{ s.label }}</button>
|
||||
</div>
|
||||
<div v-if="size === 'custom'" class="se-custom">
|
||||
<input v-model.number="customW" type="number" min="64" max="2048" class="se-num">
|
||||
<span>×</span>
|
||||
<input v-model.number="customH" type="number" min="64" max="2048" class="se-num">
|
||||
<span class="se-custom-s">px(自动补边不裁内容)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 输出数量 -->
|
||||
<div class="se-sec">
|
||||
<div class="se-h">输出数量</div>
|
||||
<div class="se-btns">
|
||||
<button v-for="n in [1, 2, 3]" :key="n" class="se-btn se-btn-n" :class="{ on: count === n }" @click="count = n">{{ n }}</button>
|
||||
</div>
|
||||
<div class="se-tip-s">多张输出为新文字大小的微调档位(字号自动估计有误差,出 2~3 张挑最像的)</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型 -->
|
||||
<div class="se-sec">
|
||||
<div class="se-h">模型</div>
|
||||
<select v-model="model" class="se-model">
|
||||
<option v-for="m in models" :key="m" :value="m">{{ m }}(本地)</option>
|
||||
<option v-if="!models.length" value="qwen3.8-max">qwen3.8-max(本地)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button class="se-go" :disabled="!canGo" @click="submit()">
|
||||
<span v-if="loading" class="se-spin">⏳</span>
|
||||
<span v-else>✨</span>
|
||||
{{ loading ? '处理中:识别 → AI 定位 → 无缝重绘…' : '提交' }}
|
||||
</button>
|
||||
|
||||
<div v-if="error" class="se-err">⚠️ {{ error }}</div>
|
||||
|
||||
<!-- 结果 -->
|
||||
<div v-if="results.length" class="se-results">
|
||||
<div class="se-h">修改结果</div>
|
||||
<div class="se-cmp">
|
||||
<div class="se-cmp-col">
|
||||
<div class="se-cmp-t">原始文字</div>
|
||||
<img :src="previewUrl" class="se-cmp-img" alt="">
|
||||
</div>
|
||||
<div class="se-cmp-col">
|
||||
<div class="se-cmp-t se-cmp-t-new">新文字</div>
|
||||
<img :src="results[0].url" class="se-cmp-img" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="edits.length" class="se-edits">
|
||||
<div v-for="(e, i) in edits" :key="i" class="se-edit-row">
|
||||
「{{ e.old }}」→「{{ e.new }}」<span class="se-edit-style">{{ e.style }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="results.length > 1" class="se-variants">
|
||||
<a v-for="(r, i) in results" :key="i" class="se-variant" :href="r.url" target="_blank" rel="noopener">
|
||||
变体 {{ i + 1 }}({{ Math.round(r.scale * 100) }}%字号)
|
||||
</a>
|
||||
</div>
|
||||
<div class="se-acts">
|
||||
<a class="se-dl" :href="results[0].url" target="_blank" rel="noopener" download>⬇ 下载图片</a>
|
||||
<a class="se-dl" :href="results[0].url" target="_blank" rel="noopener">🔗 新窗口打开</a>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="note" class="se-note">💡 {{ note }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 右:最近任务 -->
|
||||
<div class="se-side">
|
||||
<div class="se-side-h">
|
||||
最近任务
|
||||
<a href="javascript:;" class="se-refresh" @click="loadTasks()">刷新</a>
|
||||
</div>
|
||||
<div v-if="!tasks.length" class="se-side-empty">
|
||||
还没有任务——左侧上传图片并描述要改的文字,提交后这里会保留前后对比记录(仅本机浏览器)
|
||||
</div>
|
||||
<div v-for="t in tasks" :key="t.id" class="se-task">
|
||||
<div class="se-task-time">{{ fmtTime(t.time) }}<span v-if="t.count > 1" class="se-task-n">{{ t.count }}张</span></div>
|
||||
<div class="se-task-p">{{ t.prompt }}</div>
|
||||
<div class="se-task-imgs">
|
||||
<div class="se-task-col">
|
||||
<img :src="t.before" class="se-task-img" alt="">
|
||||
<div class="se-task-lb">原始文字</div>
|
||||
</div>
|
||||
<div class="se-task-col">
|
||||
<img :src="t.after" class="se-task-img" alt="">
|
||||
<div class="se-task-lb se-task-lb-new">新文字</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ImgHist ref="histRef" kind="seamless" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.se-root { max-width: 1200px; margin: 0 auto; padding: 18px 12px 40px; color: var(--n-text-color, #333); }
|
||||
.se-head { text-align: center; margin-bottom: 18px; }
|
||||
.se-title { font-size: 30px; font-weight: 800; letter-spacing: 2px; }
|
||||
.se-sub { margin-top: 6px; font-size: 13px; opacity: 0.6; }
|
||||
|
||||
.se-grid { display: grid; grid-template-columns: 380px 1fr 76px; gap: 16px; align-items: start; }
|
||||
@media (max-width: 900px) { .se-grid { grid-template-columns: 1fr; } }
|
||||
|
||||
.se-ctrl { background: #fff; border: 1px solid rgba(128,128,128,0.18); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
|
||||
html.dark .se-ctrl { background: rgba(255,255,255,0.04); }
|
||||
|
||||
.se-upload { border: 2px dashed rgba(128,128,128,0.45); border-radius: 10px; min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: border-color 0.15s; overflow: hidden; }
|
||||
.se-upload:hover { border-color: #ff7a1a; }
|
||||
.se-upload.has { padding: 8px; cursor: default; }
|
||||
.se-upload-icon { font-size: 28px; }
|
||||
.se-upload-t { margin-top: 8px; font-size: 14px; font-weight: 600; }
|
||||
.se-upload-s { margin-top: 5px; font-size: 11.5px; opacity: 0.55; text-align: center; padding: 0 14px; }
|
||||
.se-upload-img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin: 0 auto; }
|
||||
.se-upload-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 12px; }
|
||||
.se-upload-name { opacity: 0.7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.se-upload-x { color: #e53935; text-decoration: none; flex-shrink: 0; margin-left: 8px; }
|
||||
|
||||
.se-sec { display: flex; flex-direction: column; gap: 7px; }
|
||||
.se-h { font-size: 13px; font-weight: 700; opacity: 0.85; }
|
||||
.se-prompt { width: 100%; min-height: 86px; resize: vertical; border: 1px solid rgba(128,128,128,0.35); border-radius: 8px; padding: 9px 11px; font-size: 13px; line-height: 1.55; background: transparent; color: inherit; }
|
||||
.se-prompt:focus { outline: none; border-color: #ff7a1a; }
|
||||
.se-count { font-size: 11px; opacity: 0.45; text-align: right; }
|
||||
.se-examples { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.se-example { border: 1px solid rgba(128,128,128,0.3); background: transparent; color: inherit; border-radius: 999px; font-size: 11.5px; padding: 4px 10px; cursor: pointer; opacity: 0.8; transition: all 0.12s; }
|
||||
.se-example:hover { border-color: #ff7a1a; color: #ff7a1a; opacity: 1; }
|
||||
|
||||
.se-btns { display: flex; gap: 7px; flex-wrap: wrap; }
|
||||
.se-btn { border: 1.5px solid rgba(128,128,128,0.35); background: transparent; color: inherit; border-radius: 8px; font-size: 12.5px; padding: 6px 14px; cursor: pointer; transition: all 0.12s; }
|
||||
.se-btn.on { border-color: #ff7a1a; color: #ff7a1a; background: rgba(255,122,26,0.08); font-weight: 700; }
|
||||
.se-btn-n { width: 44px; text-align: center; }
|
||||
.se-custom { display: flex; align-items: center; gap: 6px; font-size: 12px; }
|
||||
.se-num { width: 70px; border: 1px solid rgba(128,128,128,0.35); border-radius: 6px; padding: 4px 6px; background: transparent; color: inherit; font-size: 12px; }
|
||||
.se-custom-s, .se-tip-s { opacity: 0.5; font-size: 11px; }
|
||||
|
||||
.se-model { border: 1px solid rgba(128,128,128,0.35); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; background: transparent; color: inherit; }
|
||||
|
||||
.se-go { margin-top: 2px; border: none; background: #ff7a1a; color: #fff; font-size: 15.5px; font-weight: 700; border-radius: 10px; padding: 12px; cursor: pointer; transition: filter 0.12s, opacity 0.12s; }
|
||||
.se-go:hover:not(:disabled) { filter: brightness(1.06); }
|
||||
.se-go:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.se-spin { display: inline-block; animation: se-rot 1s linear infinite; }
|
||||
@keyframes se-rot { to { transform: rotate(360deg); } }
|
||||
|
||||
.se-err { background: rgba(229,57,53,0.08); border: 1px solid rgba(229,57,53,0.35); color: #e53935; border-radius: 8px; font-size: 12.5px; padding: 9px 11px; }
|
||||
.se-note { background: rgba(255,122,26,0.08); border: 1px solid rgba(255,122,26,0.3); border-radius: 8px; font-size: 12.5px; padding: 9px 11px; }
|
||||
|
||||
.se-results { display: flex; flex-direction: column; gap: 10px; }
|
||||
.se-cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.se-cmp-col { text-align: center; }
|
||||
.se-cmp-t { font-size: 12px; font-weight: 700; opacity: 0.7; margin-bottom: 5px; }
|
||||
.se-cmp-t-new { color: #ff7a1a; opacity: 1; }
|
||||
.se-cmp-img { max-width: 100%; border-radius: 8px; border: 1px solid rgba(128,128,128,0.2); }
|
||||
.se-edits { font-size: 12px; background: rgba(128,128,128,0.07); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
|
||||
.se-edit-style { opacity: 0.5; margin-left: 6px; font-size: 11px; }
|
||||
.se-variants { display: flex; gap: 7px; flex-wrap: wrap; }
|
||||
.se-variant { font-size: 12px; border: 1px solid rgba(128,128,128,0.35); border-radius: 999px; padding: 4px 11px; text-decoration: none; color: inherit; }
|
||||
.se-variant:hover { border-color: #ff7a1a; color: #ff7a1a; }
|
||||
.se-acts { display: flex; gap: 9px; }
|
||||
.se-dl { flex: 1; text-align: center; font-size: 13px; font-weight: 700; text-decoration: none; color: #fff; background: #ff7a1a; border-radius: 9px; padding: 9px 0; }
|
||||
.se-dl + .se-dl { background: rgba(128,128,128,0.18); color: inherit; }
|
||||
|
||||
.se-side { background: #fff; border: 1px solid rgba(128,128,128,0.18); border-radius: 12px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
|
||||
html.dark .se-side { background: rgba(255,255,255,0.04); }
|
||||
.se-side-h { font-size: 15px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
|
||||
.se-refresh { font-size: 12px; font-weight: 400; color: #ff7a1a; text-decoration: none; border: 1px solid rgba(255,122,26,0.5); border-radius: 999px; padding: 3px 12px; }
|
||||
.se-side-empty { font-size: 12.5px; opacity: 0.5; line-height: 1.7; padding: 18px 6px; }
|
||||
|
||||
.se-task { border: 1px solid rgba(128,128,128,0.16); border-radius: 10px; padding: 11px; margin-bottom: 11px; }
|
||||
.se-task-time { font-size: 11px; opacity: 0.5; display: flex; align-items: center; gap: 6px; }
|
||||
.se-task-n { background: rgba(255,122,26,0.12); color: #ff7a1a; border-radius: 999px; padding: 1px 7px; font-size: 10.5px; }
|
||||
.se-task-p { font-size: 12.5px; margin: 6px 0 8px; line-height: 1.5; }
|
||||
.se-task-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
|
||||
.se-task-col { text-align: center; }
|
||||
.se-task-img { max-width: 100%; border-radius: 7px; border: 1px solid rgba(128,128,128,0.18); }
|
||||
.se-task-lb { font-size: 11px; opacity: 0.55; margin-top: 4px; }
|
||||
.se-task-lb-new { color: #ff7a1a; opacity: 1; font-weight: 700; }
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Edit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'AI 无痕改字',
|
||||
path: '/ai-text-edit',
|
||||
description: '上传图片说出改什么,AI 自动匹配原字体/字号/颜色/角度无缝替换,支持删除文字',
|
||||
keywords: ['ai', '无痕改字', '改字', '换字', '修改图片文字', '文字替换', '图片文字', '去文字', 'seamless', 'text', 'edit'],
|
||||
component: () => import('./ai-text-edit.vue'),
|
||||
icon: Edit,
|
||||
});
|
||||
@@ -0,0 +1,468 @@
|
||||
<script setup lang="ts">
|
||||
// Base64图片互转:Base64→图片 + 图片→Base64,一页双功能,纯浏览器本地(不上传)
|
||||
type TabKey = 'b2i' | 'i2b';
|
||||
|
||||
const tab = ref<TabKey>('b2i');
|
||||
|
||||
// ---------- Tab A:Base64 → 图片 ----------
|
||||
const b64Input = ref('');
|
||||
const imgType = ref('auto');
|
||||
const TYPES = [
|
||||
{ v: 'auto', t: '自动识别' },
|
||||
{ v: 'image/png', t: 'png' },
|
||||
{ v: 'image/jpeg', t: 'jpeg' },
|
||||
{ v: 'image/webp', t: 'webp' },
|
||||
{ v: 'image/gif', t: 'gif' },
|
||||
{ v: 'image/bmp', t: 'bmp' },
|
||||
{ v: 'image/svg+xml', t: 'svg' },
|
||||
{ v: 'image/x-icon', t: 'ico' },
|
||||
];
|
||||
const b2iErr = ref('');
|
||||
const b2iInfo = ref('');
|
||||
const b2iUrl = ref(''); // objectURL
|
||||
const b2iMime = ref('');
|
||||
const b2iExt = ref('png');
|
||||
|
||||
const EXT: Record<string, string> = {
|
||||
'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp', 'image/gif': 'gif',
|
||||
'image/bmp': 'bmp', 'image/svg+xml': 'svg', 'image/x-icon': 'ico', 'image/avif': 'avif',
|
||||
};
|
||||
|
||||
/** 三种输入形态都吃:裸 base64 / data:mediatype;base64,xxx / url("data:...") */
|
||||
function parseB64(raw: string): { mediatype: string; data: string } {
|
||||
let s = raw.trim();
|
||||
if (!s) throw new Error('请输入 Base64 内容');
|
||||
// url("data:...") 或 url(data:...)
|
||||
const urlM = s.match(/^url\(\s*(['"]?)([\s\S]*?)\1\s*\)$/i);
|
||||
if (urlM) s = urlM[2].trim();
|
||||
// data:mediatype;base64,xxx
|
||||
const dataM = s.match(/^data:([^;,]+)?(?:;[^;,]*)*;base64,([\s\S]*)$/i);
|
||||
if (dataM) return { mediatype: (dataM[1] || '').toLowerCase().split(';')[0], data: dataM[2].replace(/\s+/g, '') };
|
||||
// 裸 base64(去空白)
|
||||
return { mediatype: '', data: s.replace(/\s+/g, '') };
|
||||
}
|
||||
|
||||
/** 魔数嗅探真实类型 */
|
||||
function sniffMime(bytes: Uint8Array): string {
|
||||
if (bytes.length >= 8 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) return 'image/png';
|
||||
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) return 'image/jpeg';
|
||||
if (bytes.length >= 6 && bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46) return 'image/gif';
|
||||
if (bytes.length >= 12 && bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x46 && bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50) return 'image/webp';
|
||||
if (bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d) return 'image/bmp';
|
||||
if (bytes.length >= 4 && bytes[0] === 0x00 && bytes[1] === 0x00 && bytes[2] === 0x01 && bytes[3] === 0x00) return 'image/x-icon';
|
||||
return '';
|
||||
}
|
||||
|
||||
function b64ToBytes(data: string): Uint8Array {
|
||||
const clean = data.replace(/-/g, '+').replace(/_/g, '/');
|
||||
const pad = clean.length % 4 === 0 ? '' : '='.repeat(4 - (clean.length % 4));
|
||||
const bin = atob(clean + pad); // 非法字符会抛错
|
||||
const out = new Uint8Array(bin.length);
|
||||
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||
return out;
|
||||
}
|
||||
|
||||
function convertB2I() {
|
||||
b2iErr.value = '';
|
||||
b2iInfo.value = '';
|
||||
try {
|
||||
const { mediatype, data } = parseB64(b64Input.value);
|
||||
const bytes = b64ToBytes(data);
|
||||
if (!bytes.length) throw new Error('Base64 内容为空');
|
||||
const sniffed = sniffMime(bytes);
|
||||
let mime = mediatype || sniffed || (imgType.value !== 'auto' ? imgType.value : '');
|
||||
if (!mime) throw new Error('无法识别图片类型:请在「图片类型」中手动选择');
|
||||
if (imgType.value !== 'auto' && !mediatype) mime = imgType.value; // 手动选择优先(对应参考图提示)
|
||||
// SVG 特判:无魔数,按文本嗅探
|
||||
if (mime === 'image/svg+xml' && !sniffed) {
|
||||
const head = new TextDecoder().decode(bytes.slice(0, 400));
|
||||
if (!/\<svg|\<\?xml/i.test(head)) throw new Error('内容不是有效的 SVG');
|
||||
}
|
||||
const blob = new Blob([bytes], { type: mime });
|
||||
const url = URL.createObjectURL(blob);
|
||||
// 用 Image 验证可解码,失败给友好错误
|
||||
const probe = new Image();
|
||||
probe.onload = () => {
|
||||
if (b2iUrl.value) URL.revokeObjectURL(b2iUrl.value);
|
||||
b2iUrl.value = url;
|
||||
b2iMime.value = mime;
|
||||
b2iExt.value = EXT[mime] || 'bin';
|
||||
b2iInfo.value = `类型 ${mime} · 尺寸 ${probe.naturalWidth}×${probe.naturalHeight} · 大小 ${(blob.size / 1024).toFixed(1)} KB`;
|
||||
};
|
||||
probe.onerror = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
b2iUrl.value = '';
|
||||
b2iErr.value = `解码出的 ${mime} 数据无法渲染为有效图片,请检查 Base64 是否完整或图片类型选择是否正确`;
|
||||
};
|
||||
probe.src = url;
|
||||
}
|
||||
catch (e: any) {
|
||||
b2iErr.value = String(e?.message || e);
|
||||
b2iUrl.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function downloadB2I() {
|
||||
if (!b2iUrl.value) return;
|
||||
const a = document.createElement('a');
|
||||
a.href = b2iUrl.value;
|
||||
a.download = `converted-image.${b2iExt.value}`;
|
||||
a.click();
|
||||
}
|
||||
|
||||
function clearB2I() {
|
||||
b64Input.value = '';
|
||||
b2iErr.value = '';
|
||||
b2iInfo.value = '';
|
||||
if (b2iUrl.value) URL.revokeObjectURL(b2iUrl.value);
|
||||
b2iUrl.value = '';
|
||||
}
|
||||
|
||||
// ---------- Tab B:图片 → Base64 ----------
|
||||
const file = ref<File | null>(null);
|
||||
const fileUrl = ref('');
|
||||
const i2bErr = ref('');
|
||||
const i2bInfo = ref('');
|
||||
const outFormat = ref<'raw' | 'data' | 'css'>('data');
|
||||
const b64Out = ref('');
|
||||
const copied = ref(false);
|
||||
const lastRaw = ref(''); // 本图的裸 base64,供格式切换重排
|
||||
const lastMime = ref('');
|
||||
|
||||
const FORMATS = [
|
||||
{ v: 'raw', t: '纯 base64' },
|
||||
{ v: 'data', t: 'data: URI' },
|
||||
{ v: 'css', t: 'CSS url()' },
|
||||
];
|
||||
|
||||
function setFile(f: File) {
|
||||
if (!f.type.startsWith('image/')) {
|
||||
i2bErr.value = '仅支持图片文件';
|
||||
return;
|
||||
}
|
||||
clearI2B(false);
|
||||
file.value = f;
|
||||
if (fileUrl.value) URL.revokeObjectURL(fileUrl.value);
|
||||
fileUrl.value = URL.createObjectURL(f);
|
||||
i2bErr.value = '';
|
||||
}
|
||||
|
||||
function onPick(e: Event) {
|
||||
const f = (e.target as HTMLInputElement).files?.[0];
|
||||
if (f) setFile(f);
|
||||
}
|
||||
|
||||
function onDrop(e: DragEvent) {
|
||||
const f = e.dataTransfer?.files?.[0];
|
||||
if (f) setFile(f);
|
||||
}
|
||||
|
||||
function convertI2B() {
|
||||
i2bErr.value = '';
|
||||
b64Out.value = '';
|
||||
if (!file.value) {
|
||||
i2bErr.value = '请先选择图片';
|
||||
return;
|
||||
}
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => {
|
||||
const dataUrl = String(fr.result || '');
|
||||
const m = dataUrl.match(/^data:([^;,]+)?(?:;[^;,]*)*;base64,([\s\S]*)$/);
|
||||
if (!m) {
|
||||
i2bErr.value = '读取图片失败';
|
||||
return;
|
||||
}
|
||||
const mime = m[1] || file.value!.type || 'image/png';
|
||||
i2bInfo.value = `原始:${file.value!.name} · ${mime} · ${(file.value!.size / 1024).toFixed(1)} KB`;
|
||||
lastRaw.value = m[2];
|
||||
lastMime.value = mime;
|
||||
emitOut(mime, m[2]);
|
||||
};
|
||||
fr.onerror = () => {
|
||||
i2bErr.value = '读取图片失败(文件可能被占用)';
|
||||
};
|
||||
fr.readAsDataURL(file.value);
|
||||
}
|
||||
|
||||
function emitOut(mime: string, raw: string) {
|
||||
if (outFormat.value === 'raw') b64Out.value = raw;
|
||||
else if (outFormat.value === 'data') b64Out.value = `data:${mime};base64,${raw}`;
|
||||
else b64Out.value = `url("data:${mime};base64,${raw}")`;
|
||||
}
|
||||
|
||||
/** 切换输出格式时按记录的 mime+裸串重排(不重读文件) */
|
||||
function onFormatChange() {
|
||||
if (!lastRaw.value) return;
|
||||
emitOut(lastMime.value || file.value?.type || 'image/png', lastRaw.value);
|
||||
}
|
||||
|
||||
async function copyOut() {
|
||||
if (!b64Out.value) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(b64Out.value);
|
||||
copied.value = true;
|
||||
setTimeout(() => {
|
||||
copied.value = false;
|
||||
}, 1500);
|
||||
}
|
||||
catch {
|
||||
i2bErr.value = '复制失败,请手动全选复制';
|
||||
}
|
||||
}
|
||||
|
||||
function clearI2B(resetFile = true) {
|
||||
if (resetFile) {
|
||||
file.value = null;
|
||||
lastRaw.value = '';
|
||||
lastMime.value = '';
|
||||
if (fileUrl.value) URL.revokeObjectURL(fileUrl.value);
|
||||
fileUrl.value = '';
|
||||
i2bInfo.value = '';
|
||||
b64Out.value = '';
|
||||
}
|
||||
i2bErr.value = '';
|
||||
}
|
||||
|
||||
function onGoToB2I() {
|
||||
// 参考图的「Base64转图片」按钮:带当前输出切到另一半页
|
||||
if (b64Out.value) {
|
||||
b64Input.value = b64Out.value;
|
||||
tab.value = 'b2i';
|
||||
nextTick(convertB2I);
|
||||
}
|
||||
else {
|
||||
tab.value = 'b2i';
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (b2iUrl.value) URL.revokeObjectURL(b2iUrl.value);
|
||||
if (fileUrl.value) URL.revokeObjectURL(fileUrl.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="b64c-root">
|
||||
<div class="b64c-note">
|
||||
说明:使用浏览器 API 实现,您的文件不会被上传到云端,完全本地处理。
|
||||
</div>
|
||||
|
||||
<!-- 双功能切换 -->
|
||||
<div class="b64c-tabs">
|
||||
<button class="b64c-tab" :class="{ on: tab === 'b2i' }" @click="tab = 'b2i'">Base64 转图片</button>
|
||||
<button class="b64c-tab" :class="{ on: tab === 'i2b' }" @click="tab = 'i2b'">图片 转 Base64</button>
|
||||
</div>
|
||||
|
||||
<!-- ============ Tab A:Base64 → 图片 ============ -->
|
||||
<div v-show="tab === 'b2i'" class="b64c-panel">
|
||||
<div class="b64c-label">输入内容</div>
|
||||
<textarea
|
||||
v-model="b64Input"
|
||||
class="b64c-textarea"
|
||||
rows="7"
|
||||
spellcheck="false"
|
||||
placeholder="base64-string 或者 data:mediatype;base64,base64-string 或者 url("data:mediatype;base64,base64-string")"
|
||||
/>
|
||||
|
||||
<div class="b64c-row">
|
||||
<span class="b64c-label b64c-label-inline">图片类型</span>
|
||||
<select v-model="imgType" class="b64c-select">
|
||||
<option v-for="t in TYPES" :key="t.v" :value="t.v">{{ t.t }}</option>
|
||||
</select>
|
||||
<span class="b64c-hint">如果输入内容中不包含 mediatype,则按此处选择的类型处理(自动识别优先读文件魔数)</span>
|
||||
</div>
|
||||
|
||||
<div class="b64c-btns">
|
||||
<button class="b64c-btn b64c-btn-pri" @click="convertB2I">转换</button>
|
||||
<button class="b64c-btn" :disabled="!b2iUrl" @click="downloadB2I">下载</button>
|
||||
<button class="b64c-btn" @click="clearB2I">清空</button>
|
||||
</div>
|
||||
|
||||
<div v-if="b2iErr" class="b64c-err">{{ b2iErr }}</div>
|
||||
<div v-else-if="b2iInfo" class="b64c-info">{{ b2iInfo }}</div>
|
||||
|
||||
<div v-if="b2iUrl" class="b64c-preview">
|
||||
<img :src="b2iUrl" alt="preview">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ============ Tab B:图片 → Base64 ============ -->
|
||||
<div v-show="tab === 'i2b'" class="b64c-panel">
|
||||
<div
|
||||
class="b64c-drop"
|
||||
@click="!file && ($refs.pickInput as HTMLInputElement).click()"
|
||||
@dragover.prevent
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<template v-if="fileUrl">
|
||||
<img :src="fileUrl" class="b64c-drop-img" alt="">
|
||||
<div class="b64c-drop-bar">
|
||||
<span class="b64c-drop-name">{{ file?.name }}</span>
|
||||
<a href="javascript:;" class="b64c-drop-x" @click.stop="clearI2B()">✕ 重新选择</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="b64c-drop-icon">☁️⬆️</div>
|
||||
<div class="b64c-drop-t">点击选择,或将文件拖拽到此处</div>
|
||||
<div class="b64c-drop-s">支持 png / jpeg / webp / gif / bmp / svg / ico</div>
|
||||
</template>
|
||||
<input ref="pickInput" type="file" accept="image/*" style="display: none" @change="onPick">
|
||||
</div>
|
||||
|
||||
<div class="b64c-row">
|
||||
<span class="b64c-label b64c-label-inline">输出格式</span>
|
||||
<div class="b64c-segs">
|
||||
<button
|
||||
v-for="f in FORMATS"
|
||||
:key="f.v"
|
||||
class="b64c-seg"
|
||||
:class="{ on: outFormat === f.v }"
|
||||
@click="outFormat = f.v; onFormatChange()"
|
||||
>{{ f.t }}</button>
|
||||
</div>
|
||||
<span class="b64c-hint">三种格式都可直接粘回「Base64 转图片」侧</span>
|
||||
</div>
|
||||
|
||||
<div class="b64c-btns">
|
||||
<button class="b64c-btn b64c-btn-pri" @click="convertI2B()">图片转 Base64</button>
|
||||
<button class="b64c-btn b64c-btn-pri2" @click="onGoToB2I">Base64 转图片</button>
|
||||
<button class="b64c-btn" :disabled="!b64Out" @click="copyOut">{{ copied ? '✓ 已复制' : '复制结果' }}</button>
|
||||
<button class="b64c-btn" @click="clearI2B()">清空</button>
|
||||
</div>
|
||||
|
||||
<div v-if="i2bErr" class="b64c-err">{{ i2bErr }}</div>
|
||||
<div v-else-if="i2bInfo" class="b64c-info">{{ i2bInfo }}</div>
|
||||
|
||||
<div class="b64c-out">
|
||||
<div class="b64c-out-h">Base64内容</div>
|
||||
<textarea v-model="b64Out" class="b64c-textarea b64c-out-ta" rows="8" readonly spellcheck="false" placeholder="转换后的内容会显示在这里" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.b64c-root { max-width: 860px; }
|
||||
|
||||
.b64c-note {
|
||||
background: rgba(13, 148, 136, 0.08);
|
||||
border-left: 4px solid #0d9488;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
padding: 10px 14px;
|
||||
margin-bottom: 16px;
|
||||
opacity: 0.95;
|
||||
}
|
||||
|
||||
.b64c-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
|
||||
.b64c-tab {
|
||||
border: 1.5px solid rgba(128, 128, 128, 0.35);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
padding: 9px 22px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.12s;
|
||||
}
|
||||
.b64c-tab.on { border-color: #0d9488; background: #0d9488; color: #fff; }
|
||||
|
||||
.b64c-panel { display: flex; flex-direction: column; gap: 12px; }
|
||||
|
||||
.b64c-label { font-size: 13.5px; font-weight: 700; opacity: 0.85; }
|
||||
.b64c-label-inline { flex-shrink: 0; margin-right: 2px; }
|
||||
|
||||
.b64c-textarea {
|
||||
width: 100%;
|
||||
border: 1px solid rgba(128, 128, 128, 0.4);
|
||||
border-radius: 8px;
|
||||
padding: 11px 13px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
resize: vertical;
|
||||
word-break: break-all;
|
||||
}
|
||||
.b64c-textarea:focus { outline: none; border-color: #0d9488; }
|
||||
.b64c-textarea::placeholder { opacity: 0.42; }
|
||||
.b64c-out-ta { background: rgba(128, 128, 128, 0.04); }
|
||||
|
||||
.b64c-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.b64c-select {
|
||||
border: 1px solid rgba(128, 128, 128, 0.4);
|
||||
border-radius: 7px;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.b64c-hint { font-size: 12px; opacity: 0.5; }
|
||||
|
||||
.b64c-segs { display: flex; gap: 6px; }
|
||||
.b64c-seg {
|
||||
border: 1.5px solid rgba(128, 128, 128, 0.35);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 12.5px;
|
||||
padding: 5px 13px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition: all 0.12s;
|
||||
}
|
||||
.b64c-seg.on { border-color: #0d9488; color: #0d9488; background: rgba(13, 148, 136, 0.1); font-weight: 700; }
|
||||
|
||||
.b64c-btns { display: flex; gap: 9px; flex-wrap: wrap; }
|
||||
.b64c-btn {
|
||||
border: 1px solid rgba(128, 128, 128, 0.4);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
padding: 9px 20px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.12s;
|
||||
}
|
||||
.b64c-btn:hover:not(:disabled) { border-color: #0d9488; color: #0d9488; }
|
||||
.b64c-btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.b64c-btn-pri { background: #0d9488; border-color: #0d9488; color: #fff; }
|
||||
.b64c-btn-pri:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
|
||||
.b64c-btn-pri2 { background: transparent; border-color: #0d9488; color: #0d9488; }
|
||||
|
||||
.b64c-err { background: rgba(229, 57, 53, 0.08); border: 1px solid rgba(229, 57, 53, 0.35); color: #e53935; border-radius: 8px; font-size: 12.5px; padding: 9px 12px; word-break: break-all; }
|
||||
.b64c-info { background: rgba(13, 148, 136, 0.07); border: 1px solid rgba(13, 148, 136, 0.28); border-radius: 8px; font-size: 12.5px; padding: 9px 12px; }
|
||||
|
||||
.b64c-preview { border: 1px dashed rgba(128, 128, 128, 0.45); border-radius: 8px; padding: 14px; display: flex; justify-content: center; align-items: center; min-height: 120px; background: rgba(128, 128, 128, 0.03); }
|
||||
.b64c-preview img { max-width: 100%; max-height: 340px; border-radius: 6px; }
|
||||
|
||||
.b64c-drop {
|
||||
border: 2px dashed rgba(13, 148, 136, 0.5);
|
||||
border-radius: 10px;
|
||||
min-height: 150px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s;
|
||||
overflow: hidden;
|
||||
padding: 8px;
|
||||
}
|
||||
.b64c-drop:hover { border-color: #0d9488; background: rgba(13, 148, 136, 0.03); }
|
||||
.b64c-drop-icon { font-size: 30px; }
|
||||
.b64c-drop-t { margin-top: 8px; font-size: 14px; font-weight: 600; color: #0d9488; }
|
||||
.b64c-drop-s { margin-top: 5px; font-size: 11.5px; opacity: 0.5; }
|
||||
.b64c-drop-img { max-width: 100%; max-height: 230px; border-radius: 7px; display: block; margin: 0 auto; }
|
||||
.b64c-drop-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 12px; width: 100%; }
|
||||
.b64c-drop-name { opacity: 0.7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.b64c-drop-x { color: #e53935; text-decoration: none; flex-shrink: 0; margin-left: 8px; }
|
||||
|
||||
.b64c-out { border: 1px solid rgba(128, 128, 128, 0.35); border-radius: 8px; overflow: hidden; }
|
||||
.b64c-out-h { background: rgba(128, 128, 128, 0.1); font-size: 12.5px; font-weight: 700; padding: 7px 13px; opacity: 0.8; }
|
||||
.b64c-out-ta { border: none; border-radius: 0; }
|
||||
.b64c-out-ta:focus { border: none; }
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Exchange } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.base64-image-converter.title'),
|
||||
path: '/base64-image-converter',
|
||||
description: translate('tools.base64-image-converter.description'),
|
||||
keywords: ['base64', 'image', '图片', '互转', '转图片', '图片转base64', 'base64转图片', 'data uri', '编码', '解码', 'img'],
|
||||
component: () => import('./base64-image-converter.vue'),
|
||||
icon: Exchange,
|
||||
});
|
||||
@@ -140,6 +140,193 @@ function reRecognize() {
|
||||
|
||||
const allText = computed(() => results.value.map(r => r.text).join('\n'));
|
||||
|
||||
// ================= 生成二维码 =================
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
const mode = ref<'read' | 'gen'>('read');
|
||||
const genText = ref('https://it.88531.cn');
|
||||
const genSize = ref(512);
|
||||
const genDark = ref('#000000');
|
||||
const genLight = ref('#ffffff');
|
||||
const genLogo = ref(''); // 本地图片 dataURL
|
||||
const genLogoName = ref('');
|
||||
const genLogoRatio = ref(0.22); // 中心图片占 QR 比例
|
||||
const genPng = ref(''); // 生成结果 dataURL
|
||||
const genScanning = ref(false);
|
||||
const genScanMsg = ref('');
|
||||
const genScanOk = ref(false);
|
||||
const genError = ref('');
|
||||
const logoInput = ref<HTMLInputElement>();
|
||||
|
||||
const DARK_PRESETS = ['#000000', '#165DFF', '#00B42A', '#D03050', '#722ED1', '#FF7D00'];
|
||||
const LIGHT_PRESETS = ['#ffffff', '#F7F9FC', '#FFF7E8', '#E8F3FF', '#F0FFF4', '#FFF0F0'];
|
||||
|
||||
function pickLogo() {
|
||||
logoInput.value?.click();
|
||||
}
|
||||
|
||||
function onLogoChange(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
const f = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
if (!f.type.startsWith('image/')) {
|
||||
genError.value = '中间图片请选择图片文件';
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
genLogo.value = String(reader.result ?? '');
|
||||
genLogoName.value = f.name;
|
||||
genError.value = '';
|
||||
renderGen();
|
||||
};
|
||||
reader.readAsDataURL(f);
|
||||
}
|
||||
|
||||
function removeLogo() {
|
||||
genLogo.value = '';
|
||||
genLogoName.value = '';
|
||||
renderGen();
|
||||
}
|
||||
|
||||
let genTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
function renderGenDebounced() {
|
||||
clearTimeout(genTimer);
|
||||
genTimer = setTimeout(renderGen, 250);
|
||||
}
|
||||
|
||||
async function renderGen() {
|
||||
genError.value = '';
|
||||
genScanMsg.value = '';
|
||||
const text = genText.value.trim();
|
||||
if (!text) {
|
||||
genPng.value = '';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 有中心图片时必须 H 级纠错(容 ~30% 损毁)
|
||||
const dataUrl = await QRCode.toDataURL(text, {
|
||||
width: genSize.value,
|
||||
margin: 2,
|
||||
errorCorrectionLevel: genLogo.value ? 'H' : 'M',
|
||||
color: { dark: genDark.value, light: genLight.value },
|
||||
});
|
||||
if (!genLogo.value) {
|
||||
genPng.value = dataUrl;
|
||||
autoScan();
|
||||
return;
|
||||
}
|
||||
// 中心贴本地图片(白色圆角垫底,保证可扫)
|
||||
const qrImg = await loadImage(dataUrl);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = genSize.value;
|
||||
canvas.height = genSize.value;
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
ctx.drawImage(qrImg, 0, 0, canvas.width, canvas.height);
|
||||
const logo = await loadImage(genLogo.value);
|
||||
const side = Math.round(canvas.width * genLogoRatio.value);
|
||||
// 白垫比 logo 大 12%,留静区
|
||||
const pad = Math.round(side * 1.12);
|
||||
const cx = canvas.width / 2;
|
||||
const cy = canvas.height / 2;
|
||||
ctx.fillStyle = genLight.value;
|
||||
roundRect(ctx, cx - pad / 2, cy - pad / 2, pad, pad, Math.round(pad * 0.18));
|
||||
ctx.fill();
|
||||
const k = Math.min(side / logo.width, side / logo.height);
|
||||
const lw = Math.round(logo.width * k);
|
||||
const lh = Math.round(logo.height * k);
|
||||
ctx.drawImage(logo, cx - lw / 2, cy - lh / 2, lw, lh);
|
||||
genPng.value = canvas.toDataURL('image/png');
|
||||
autoScan();
|
||||
}
|
||||
catch (e: any) {
|
||||
genPng.value = '';
|
||||
genError.value = `生成失败:${e?.message ?? e}(内容过长?二维码上限约 2000 字符)`;
|
||||
}
|
||||
}
|
||||
|
||||
function loadImage(src: string): Promise<HTMLImageElement> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const im = new Image();
|
||||
im.onload = () => resolve(im);
|
||||
im.onerror = () => reject(new Error('图片加载失败'));
|
||||
im.src = src;
|
||||
});
|
||||
}
|
||||
|
||||
function roundRect(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + r, y);
|
||||
ctx.arcTo(x + w, y, x + w, y + h, r);
|
||||
ctx.arcTo(x + w, y + h, x, y + h, r);
|
||||
ctx.arcTo(x, y + h, x, y, r);
|
||||
ctx.arcTo(x, y, x + w, y, r);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
// 生成后自扫验证:复用本页 ZXing,证明颜色/中心图片没破坏可扫性
|
||||
async function autoScan() {
|
||||
if (!genPng.value) {
|
||||
return;
|
||||
}
|
||||
genScanning.value = true;
|
||||
genScanMsg.value = '';
|
||||
try {
|
||||
const blob = await (await fetch(genPng.value)).blob();
|
||||
const found = await readBarcodes(blob, { tryHarder: true, tryInvert: true, maxNumberOfSymbols: 0 });
|
||||
const hit = found.find(f => f.text === genText.value.trim());
|
||||
if (hit) {
|
||||
genScanOk.value = true;
|
||||
genScanMsg.value = `可正常扫出(${hit.format})· 与输入内容一致`;
|
||||
}
|
||||
else if (found.length) {
|
||||
genScanOk.value = false;
|
||||
genScanMsg.value = `扫出内容与输入不一致,请检查颜色对比度`;
|
||||
}
|
||||
else {
|
||||
genScanOk.value = false;
|
||||
genScanMsg.value = '扫不出来:请增大前景/背景对比度,或缩小中心图片比例';
|
||||
}
|
||||
genHist.add({ title: genText.value.trim().slice(0, 60), detail: `生成 ${genSize.value}px${genLogo.value ? ' + 中心图片' : ''}` });
|
||||
}
|
||||
catch (e: any) {
|
||||
genScanOk.value = false;
|
||||
genScanMsg.value = `自扫异常:${e?.message ?? e}`;
|
||||
}
|
||||
finally {
|
||||
genScanning.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function downloadGen() {
|
||||
if (!genPng.value) {
|
||||
return;
|
||||
}
|
||||
const a = document.createElement('a');
|
||||
a.href = genPng.value;
|
||||
a.download = 'qr-code.png';
|
||||
a.click();
|
||||
}
|
||||
|
||||
function clearGen() {
|
||||
genText.value = '';
|
||||
genLogo.value = '';
|
||||
genLogoName.value = '';
|
||||
genPng.value = '';
|
||||
genScanMsg.value = '';
|
||||
genError.value = '';
|
||||
}
|
||||
|
||||
function setMode(m: 'read' | 'gen') {
|
||||
mode.value = m;
|
||||
if (m === 'gen' && !genPng.value) {
|
||||
renderGen();
|
||||
}
|
||||
}
|
||||
|
||||
async function copyText(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
@@ -197,6 +384,7 @@ function fit() {
|
||||
let observer: ResizeObserver | undefined;
|
||||
onMounted(() => {
|
||||
fit();
|
||||
renderGen();
|
||||
window.addEventListener('resize', fit);
|
||||
window.addEventListener('paste', onPaste);
|
||||
observer = new ResizeObserver(() => fit());
|
||||
@@ -221,28 +409,53 @@ onUnmounted(() => {
|
||||
style="display:none"
|
||||
@change="onInputChange"
|
||||
>
|
||||
<input
|
||||
ref="logoInput"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
style="display:none"
|
||||
@change="onLogoChange"
|
||||
>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="stats">
|
||||
<div class="cr-tabs">
|
||||
<button type="button" :class="{ on: mode === 'read' }" @click="setMode('read')">
|
||||
📷 识别
|
||||
</button>
|
||||
<button type="button" :class="{ on: mode === 'gen' }" @click="setMode('gen')">
|
||||
🧩 生成
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="mode === 'read'" class="stats">
|
||||
<template v-if="results.length">
|
||||
识别到 {{ results.length }} 个码 · {{ elapsed }}ms
|
||||
</template>
|
||||
</div>
|
||||
<c-button :disabled="!imageSrc || loading" @click="reRecognize">
|
||||
重新识别
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="copyText(allText)">
|
||||
复制全部
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="downloadTxt">
|
||||
下载TXT
|
||||
</c-button>
|
||||
<c-button @click="clearAll">
|
||||
清空
|
||||
</c-button>
|
||||
<template v-if="mode === 'read'">
|
||||
<c-button :disabled="!imageSrc || loading" @click="reRecognize">
|
||||
重新识别
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="copyText(allText)">
|
||||
复制全部
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="downloadTxt">
|
||||
下载TXT
|
||||
</c-button>
|
||||
<c-button @click="clearAll">
|
||||
清空
|
||||
</c-button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<c-button :disabled="!genPng" @click="downloadGen">
|
||||
下载PNG
|
||||
</c-button>
|
||||
<c-button :disabled="!genText.trim() && !genLogo" @click="clearGen">
|
||||
清空
|
||||
</c-button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="body">
|
||||
<div v-if="mode === 'read'" class="body">
|
||||
<!-- left: image -->
|
||||
<div class="pane">
|
||||
<div
|
||||
@@ -298,6 +511,103 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 生成面板 -->
|
||||
<div v-else-if="mode === 'gen'" class="body">
|
||||
<!-- left: form -->
|
||||
<div class="pane gen-form">
|
||||
<div class="f-sec">
|
||||
<div class="f-label">
|
||||
二维码内容
|
||||
</div>
|
||||
<textarea v-model="genText" class="gen-text" rows="4" spellcheck="false" placeholder="网址 / 文本 / 名片信息…" @input="renderGenDebounced" />
|
||||
<div class="f-count">
|
||||
{{ genText.length }} 字符
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="f-sec">
|
||||
<div class="f-label">
|
||||
尺寸
|
||||
</div>
|
||||
<div class="row">
|
||||
<select v-model.number="genSize" class="sel" @change="renderGen()">
|
||||
<option :value="256">
|
||||
256 px
|
||||
</option>
|
||||
<option :value="512">
|
||||
512 px
|
||||
</option>
|
||||
<option :value="1024">
|
||||
1024 px
|
||||
</option>
|
||||
<option :value="2048">
|
||||
2048 px(高清)
|
||||
</option>
|
||||
</select>
|
||||
<span class="tip">输出图片边长</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="f-sec">
|
||||
<div class="f-label">
|
||||
颜色
|
||||
</div>
|
||||
<div class="row color-row">
|
||||
<span>前景</span>
|
||||
<input v-model="genDark" type="color" class="color" @input="renderGenDebounced">
|
||||
<span class="hex">{{ genDark }}</span>
|
||||
<span>背景</span>
|
||||
<input v-model="genLight" type="color" class="color" @input="renderGenDebounced">
|
||||
<span class="hex">{{ genLight }}</span>
|
||||
</div>
|
||||
<div class="row presets-row">
|
||||
<span class="tip">前景快捷</span>
|
||||
<button v-for="c in DARK_PRESETS" :key="c" type="button" class="swatch" :style="{ background: c }" @click="genDark = c; renderGen()" />
|
||||
<span class="tip">背景快捷</span>
|
||||
<button v-for="c in LIGHT_PRESETS" :key="c" type="button" class="swatch" :style="{ background: c }" @click="genLight = c; renderGen()" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="f-sec">
|
||||
<div class="f-label">
|
||||
中心图片(本地图片,不上传云端)
|
||||
</div>
|
||||
<div class="row">
|
||||
<c-button @click="pickLogo">
|
||||
{{ genLogo ? '更换图片' : '选择图片' }}
|
||||
</c-button>
|
||||
<c-button v-if="genLogo" size="small" @click="removeLogo">
|
||||
移除
|
||||
</c-button>
|
||||
<span v-if="genLogoName" class="tip">{{ genLogoName }}</span>
|
||||
</div>
|
||||
<div v-if="genLogo" class="row">
|
||||
<span class="tip">大小</span>
|
||||
<input v-model.number="genLogoRatio" type="range" min="0.10" max="0.35" step="0.01" class="ratio" @input="renderGenDebounced">
|
||||
<span class="tip">{{ Math.round(genLogoRatio * 100) }}%(自动 H 级纠错)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- right: preview -->
|
||||
<div class="pane">
|
||||
<div class="gen-preview">
|
||||
<img v-if="genPng" :src="genPng" class="qr-img" alt="二维码预览">
|
||||
<div v-else class="empty">
|
||||
输入内容后自动生成
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="genError" class="cr-error">
|
||||
{{ genError }}
|
||||
</div>
|
||||
<div class="scan-line">
|
||||
<n-spin v-if="genScanning" :size="14" />
|
||||
<span v-if="genScanMsg" class="scan-msg" :class="{ ok: genScanOk }">{{ genScanMsg }}</span>
|
||||
<span v-else-if="!genScanning && genPng" class="scan-msg">自扫验证中…</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="code-reader" position="bottom" label="识别记录" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -436,6 +746,173 @@ onUnmounted(() => {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.cr-tabs {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
|
||||
button {
|
||||
border: 1.5px solid rgba(128, 128, 128, 0.35);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
padding: 6px 18px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&.on {
|
||||
border-color: #18a058;
|
||||
background: #18a058;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gen-form {
|
||||
overflow-y: auto;
|
||||
gap: 14px;
|
||||
padding-right: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.f-sec {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
.f-label {
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.gen-text {
|
||||
width: 100%;
|
||||
border: 1px solid rgba(128, 128, 128, 0.4);
|
||||
border-radius: 8px;
|
||||
padding: 9px 11px;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
resize: vertical;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.f-count {
|
||||
font-size: 11px;
|
||||
opacity: 0.45;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
.sel {
|
||||
border: 1px solid rgba(128, 128, 128, 0.4);
|
||||
border-radius: 7px;
|
||||
padding: 6px 9px;
|
||||
font-size: 12.5px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.tip {
|
||||
opacity: 0.5;
|
||||
font-size: 11.5px;
|
||||
}
|
||||
|
||||
.color {
|
||||
width: 34px;
|
||||
height: 28px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 6px;
|
||||
padding: 2px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.hex {
|
||||
font-family: ui-monospace, Menlo, Consolas, monospace;
|
||||
font-size: 11.5px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.swatch {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid rgba(128, 128, 128, 0.4);
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
|
||||
&:hover {
|
||||
border-color: #18a058;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
|
||||
.presets-row {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ratio {
|
||||
flex: 1;
|
||||
min-width: 100px;
|
||||
accent-color: #18a058;
|
||||
}
|
||||
|
||||
.gen-preview {
|
||||
flex: 1;
|
||||
min-height: 180px;
|
||||
border: 1px dashed rgba(128, 128, 128, 0.45);
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
|
||||
.qr-img {
|
||||
max-width: 100%;
|
||||
max-height: calc(100vh - 420px);
|
||||
min-height: 160px;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.scan-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
min-height: 26px;
|
||||
font-size: 12.5px;
|
||||
margin-top: 8px;
|
||||
|
||||
.scan-msg {
|
||||
color: #d03050;
|
||||
}
|
||||
|
||||
.scan-msg.ok {
|
||||
color: #18a058;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.result-item {
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
border-radius: 6px;
|
||||
|
||||
@@ -6,7 +6,7 @@ export const tool = defineTool({
|
||||
name: translate('tools.code-reader.title'),
|
||||
path: '/code-reader',
|
||||
description: translate('tools.code-reader.description'),
|
||||
keywords: ['scan', 'reader', 'decode', 'qr', 'barcode', 'zxing', 'camera', 'image', '识别', '扫码', '读取', '解码', '二维码', '条码'],
|
||||
keywords: ['scan', 'reader', 'decode', 'generate', 'qr', 'barcode', 'zxing', 'camera', 'image', '识别', '扫码', '读取', '解码', '二维码', '条码', '生成', '改色', 'logo'],
|
||||
component: () => import('./code-reader.vue'),
|
||||
icon: Scan,
|
||||
});
|
||||
@@ -0,0 +1,366 @@
|
||||
<script setup lang="ts">
|
||||
import { onUnmounted, ref } from 'vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { licenseHeaders } from '@/tools/license/license';
|
||||
import ImgHist from '@/tools/img-hist/ImgHist.vue';
|
||||
import { authHdr } from '@/tools/img-hist/img-hist';
|
||||
|
||||
useHead({ title: 'AI 换脸 - IT-TOOLS-PRO' });
|
||||
|
||||
const srcUrl = ref('');
|
||||
const dstUrl = ref('');
|
||||
const srcFile = ref<File | null>(null);
|
||||
const dstFile = ref<File | null>(null);
|
||||
const consent = ref(false);
|
||||
const histRef = ref<InstanceType<typeof ImgHist> | null>(null);
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
const resultUrl = ref('');
|
||||
const elapsed = ref(0);
|
||||
const srcInput = ref<HTMLInputElement>();
|
||||
const dstInput = ref<HTMLInputElement>();
|
||||
|
||||
function pick(which: 'source' | 'target') {
|
||||
(which === 'source' ? srcInput : dstInput).value?.click();
|
||||
}
|
||||
|
||||
function setFile(which: 'source' | 'target', f: File | null) {
|
||||
const urlRef = which === 'source' ? srcUrl : dstUrl;
|
||||
const fileRef = which === 'source' ? srcFile : dstFile;
|
||||
if (urlRef.value) {
|
||||
URL.revokeObjectURL(urlRef.value);
|
||||
}
|
||||
if (f && !f.type.startsWith('image/')) {
|
||||
error.value = '请上传图片文件(JPG/PNG/WebP 等)';
|
||||
return;
|
||||
}
|
||||
if (f && f.size > 15 * 1024 * 1024) {
|
||||
error.value = '单张图片不能超过 15MB';
|
||||
return;
|
||||
}
|
||||
fileRef.value = f;
|
||||
urlRef.value = f ? URL.createObjectURL(f) : '';
|
||||
}
|
||||
|
||||
function onInput(which: 'source' | 'target', e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
setFile(which, input.files?.[0] ?? null);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function onDrop(which: 'source' | 'target', e: DragEvent) {
|
||||
e.preventDefault();
|
||||
setFile(which, e.dataTransfer?.files?.[0] ?? null);
|
||||
}
|
||||
|
||||
async function doSwap() {
|
||||
if (!srcFile.value || !dstFile.value) {
|
||||
error.value = '请先上传源人脸照片与目标照片';
|
||||
return;
|
||||
}
|
||||
if (!consent.value) {
|
||||
error.value = '请先勾选「我承诺仅使用已获本人授权的照片进行换脸」';
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
resultUrl.value = '';
|
||||
const fd = new FormData();
|
||||
fd.append('source', srcFile.value);
|
||||
fd.append('target', dstFile.value);
|
||||
fd.append('consent', '1');
|
||||
const ctrl = new AbortController();
|
||||
const timer = setTimeout(() => ctrl.abort(), 300000);
|
||||
try {
|
||||
const res = await fetch('/relay/ai/face-swap', {
|
||||
method: 'POST',
|
||||
headers: { ...licenseHeaders('face-swap'), ...authHdr() },
|
||||
body: fd,
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
const j = await res.json().catch(() => ({} as any));
|
||||
if (!res.ok || j.code !== 200) {
|
||||
throw new Error(j.message || `HTTP ${res.status}`);
|
||||
}
|
||||
resultUrl.value = j.data?.url || '';
|
||||
elapsed.value = Number(j.data?.elapsed_ms || 0);
|
||||
if (!resultUrl.value) {
|
||||
throw new Error('服务端未返回结果图片');
|
||||
}
|
||||
histRef.value?.reload();
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = e?.name === 'AbortError' ? '处理超时,请稍后重试' : String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timer);
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function downloadResult() {
|
||||
if (!resultUrl.value) {
|
||||
return;
|
||||
}
|
||||
const a = document.createElement('a');
|
||||
const url = new URL(resultUrl.value, location.origin);
|
||||
url.searchParams.set('dl', '1');
|
||||
a.href = url.toString();
|
||||
a.download = 'face-swap.jpg';
|
||||
a.click();
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (srcUrl.value) {
|
||||
URL.revokeObjectURL(srcUrl.value);
|
||||
}
|
||||
if (dstUrl.value) {
|
||||
URL.revokeObjectURL(dstUrl.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="fs-root">
|
||||
<div class="fs-main">
|
||||
<div class="fs-head">
|
||||
<h1>🎭 AI 换脸</h1>
|
||||
<span class="fs-note">insightface 人脸检测 + inswapper 本地 CPU 推理 · 照片不离开服务器</span>
|
||||
</div>
|
||||
|
||||
<div class="fs-uploads">
|
||||
<!-- 源人脸 -->
|
||||
<div
|
||||
class="fs-card" :class="{ has: !!srcUrl }" @click="pick('source')"
|
||||
@dragover.prevent @drop="onDrop('source', $event)"
|
||||
>
|
||||
<input ref="srcInput" type="file" accept="image/*" hidden @change="onInput('source', $event)">
|
||||
<template v-if="srcUrl">
|
||||
<img :src="srcUrl" alt="源人脸">
|
||||
<div class="fs-cap">① 源人脸(提供脸的人)· 点击更换</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="fs-plus">👤</div>
|
||||
<div class="fs-cap">① 上传源人脸照片<br><small>清晰正脸,脸将被取用</small></div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="fs-arrow">➜</div>
|
||||
|
||||
<!-- 目标照片 -->
|
||||
<div
|
||||
class="fs-card" :class="{ has: !!dstUrl }" @click="pick('target')"
|
||||
@dragover.prevent @drop="onDrop('target', $event)"
|
||||
>
|
||||
<input ref="dstInput" type="file" accept="image/*" hidden @change="onInput('target', $event)">
|
||||
<template v-if="dstUrl">
|
||||
<img :src="dstUrl" alt="目标照片">
|
||||
<div class="fs-cap">② 目标照片(被换脸的人)· 点击更换</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="fs-plus">🖼️</div>
|
||||
<div class="fs-cap">② 上传目标照片<br><small>人脸会被替换成源人脸</small></div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="fs-consent">
|
||||
<input v-model="consent" type="checkbox">
|
||||
<span>我承诺仅使用<b>已获本人授权</b>的照片进行换脸,不用于任何侵权、欺诈或违法用途</span>
|
||||
</label>
|
||||
|
||||
<div class="fs-actions">
|
||||
<button class="fs-go" :disabled="busy || !srcFile || !dstFile || !consent" @click="doSwap">
|
||||
{{ busy ? '换脸中…(首次约需几秒)' : '开始换脸' }}
|
||||
</button>
|
||||
<span v-if="elapsed && resultUrl" class="fs-elapsed">耗时 {{ (elapsed / 1000).toFixed(1) }}s</span>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="fs-error">⚠️ {{ error }}</div>
|
||||
|
||||
<div v-if="resultUrl" class="fs-result">
|
||||
<img :src="resultUrl" alt="换脸结果">
|
||||
<div class="fs-result-bar">
|
||||
<span>换脸结果(多张人脸时自动选取最大的一张)</span>
|
||||
<button class="fs-dl" @click="downloadResult">⬇ 下载图片</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="fs-tips">
|
||||
提示:两张图都需包含清晰人脸;源脸与目标脸角度、光线越接近效果越好。图片仅在服务器本地处理,不对外分享。
|
||||
</p>
|
||||
</div>
|
||||
<ImgHist ref="histRef" kind="face-swap" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.fs-root {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 12px;
|
||||
padding: 8px 4px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.fs-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.fs-root { flex-direction: column; }
|
||||
}
|
||||
.fs-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.fs-head h1 {
|
||||
font-size: 22px;
|
||||
margin: 0;
|
||||
}
|
||||
.fs-note {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.fs-uploads {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.fs-card {
|
||||
flex: 1 1 260px;
|
||||
min-height: 240px;
|
||||
border: 2px dashed rgba(128, 128, 128, 0.45);
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
padding: 12px;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
background: rgba(128, 128, 128, 0.05);
|
||||
}
|
||||
.fs-card:hover {
|
||||
border-color: rgba(128, 128, 128, 0.8);
|
||||
background: rgba(128, 128, 128, 0.1);
|
||||
}
|
||||
.fs-card img {
|
||||
max-width: 100%;
|
||||
max-height: 240px;
|
||||
border-radius: 8px;
|
||||
object-fit: contain;
|
||||
}
|
||||
.fs-plus {
|
||||
font-size: 42px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
.fs-cap {
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.fs-cap small {
|
||||
opacity: 0.55;
|
||||
}
|
||||
.fs-arrow {
|
||||
align-self: center;
|
||||
font-size: 26px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.fs-consent {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
cursor: pointer;
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 170, 0, 0.08);
|
||||
border: 1px solid rgba(255, 170, 0, 0.35);
|
||||
}
|
||||
.fs-consent input {
|
||||
margin-top: 3px;
|
||||
}
|
||||
.fs-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
.fs-go {
|
||||
padding: 10px 28px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
background: #3b82f6;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
.fs-go:hover:not(:disabled) {
|
||||
opacity: 0.88;
|
||||
}
|
||||
.fs-go:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.fs-elapsed {
|
||||
font-size: 13px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
.fs-error {
|
||||
font-size: 13px;
|
||||
color: #e5484d;
|
||||
background: rgba(229, 72, 77, 0.08);
|
||||
border: 1px solid rgba(229, 72, 77, 0.35);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
.fs-result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.fs-result img {
|
||||
width: 100%;
|
||||
max-height: 560px;
|
||||
object-fit: contain;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
}
|
||||
.fs-result-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
opacity: 0.8;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.fs-dl {
|
||||
padding: 7px 16px;
|
||||
font-size: 13px;
|
||||
color: #fff;
|
||||
background: #10b981;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.fs-dl:hover {
|
||||
opacity: 0.88;
|
||||
}
|
||||
.fs-tips {
|
||||
font-size: 12px;
|
||||
opacity: 0.55;
|
||||
line-height: 1.7;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { FaceId } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'AI 换脸',
|
||||
path: '/face-swap',
|
||||
description: 'AI 换脸:上传源人脸与目标照片,本地 AI 一键换脸',
|
||||
keywords: ['ai', '换脸', 'face', 'swap', '人脸', '人脸替换', 'ai换脸', '头像', '表情'],
|
||||
component: () => import('./face-swap.vue'),
|
||||
icon: FaceId,
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,8 @@ 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';
|
||||
import PsEditor from './PsEditor.vue';
|
||||
import { TEXT_TPLS, TPL_CATS, tplStyle, filterTpls, type TextTpl } from './text-tpls';
|
||||
|
||||
prepareZXingModule({ overrideWasmUrl: wasmUrl });
|
||||
const genHist = useGenHistory('image-tools');
|
||||
@@ -22,6 +24,7 @@ const TABS: TabDef[] = [
|
||||
{ key: 'rotate', label: '旋转', desc: '旋转或翻转图片' },
|
||||
{ key: 'filter', label: '滤镜', desc: '为图片应用滤镜效果(灰度/复古/模糊等)' },
|
||||
{ key: 'mosaic', label: '打码', desc: '在图片上拖拽框选区域,马赛克或涂黑打码' },
|
||||
{ key: 'edit', label: '图片编辑', desc: 'PS 风格图层编辑器:画笔/智能消除笔/文字/选区/油漆桶/吸管/裁剪,文字支持画布拖拽旋转+47套成套标题文案模板(通用/小红书/抖音/B站/公众号/视频号/封面图7类切换)点击即插(主副标题整组),消除实时预览,OCR 无痕改字(自动检出原字字号/颜色/粗细/角度,输入新字实时预览无缝替换)' },
|
||||
{ key: 'exif', label: 'EXIF 查看', desc: '查看拍摄设备、时间、参数等 EXIF 信息' },
|
||||
{ key: 'qrgen', label: '二维码生成', desc: '把文字/链接生成为二维码图片', noFile: true },
|
||||
{ key: 'qrread', label: '二维码识别', desc: '识别图片中的二维码/条码内容' },
|
||||
@@ -141,7 +144,9 @@ function loadMainImage() {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
mainImg.value = img;
|
||||
nextTick(drawMosaicCanvas);
|
||||
nextTick(() => {
|
||||
drawMosaicCanvas();
|
||||
});
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
@@ -272,6 +277,37 @@ function mosaicPos(e: MouseEvent) {
|
||||
return { x: e.clientX - r.left, y: e.clientY - r.top };
|
||||
}
|
||||
|
||||
// ---------- 图片编辑(PS 风格编辑器,组件内自带工具栏/图层/历史) ----------
|
||||
const psEditor = ref<{ exportDoc: () => Promise<{ blob: Blob; detail: string; w: number; h: number }> } | null>(null);
|
||||
// 上传前模板墙:先点模板记住,选图后由 PsEditor 自动套入
|
||||
const pendingTpl = ref<TextTpl | null>(null);
|
||||
// 模板分类:默认"全部",一次只看一个平台
|
||||
const tplCat = ref('全部');
|
||||
const wallTpls = computed(() => filterTpls(tplCat.value));
|
||||
|
||||
function chooseTpl(t: TextTpl) {
|
||||
pendingTpl.value = t;
|
||||
pickFiles(); // 选完图自动套用该模板
|
||||
}
|
||||
|
||||
function onPsError(msg: string) {
|
||||
errorMsg.value = msg;
|
||||
}
|
||||
|
||||
async function doEdit() {
|
||||
const ed = psEditor.value;
|
||||
if (!ed) {
|
||||
throw new Error('编辑器未就绪,请重新选择图片');
|
||||
}
|
||||
const { blob, detail, w, h } = await ed.exportDoc();
|
||||
setOutput(blob, `${baseName(files.value[0])}-edited.${extOf(blob.type)}`, {
|
||||
title: `编辑 ${files.value[0].name}`,
|
||||
detail,
|
||||
});
|
||||
resultDim.value = `${w}×${h}`;
|
||||
}
|
||||
|
||||
|
||||
function onMosaicDown(e: MouseEvent) {
|
||||
if (tab.value.key !== 'mosaic') {
|
||||
return;
|
||||
@@ -336,6 +372,9 @@ async function execute() {
|
||||
else if (k === 'mosaic') {
|
||||
await doMosaic();
|
||||
}
|
||||
else if (k === 'edit') {
|
||||
await doEdit();
|
||||
}
|
||||
else if (k === 'exif') {
|
||||
await doExif();
|
||||
}
|
||||
@@ -856,7 +895,9 @@ function fit() {
|
||||
rootStyle.value = { height: `${height}px`, flex: '1 1 100%' };
|
||||
}
|
||||
|
||||
watch(tabKey, () => nextTick(drawMosaicCanvas));
|
||||
watch(tabKey, () => nextTick(() => {
|
||||
drawMosaicCanvas();
|
||||
}));
|
||||
|
||||
onMounted(() => {
|
||||
fit();
|
||||
@@ -905,7 +946,7 @@ onUnmounted(() => {
|
||||
<div
|
||||
v-if="!tab.noFile"
|
||||
class="it-upload"
|
||||
:class="{ active: dragActive, has: files.length }"
|
||||
:class="{ active: dragActive, has: files.length, wall: !files.length && tab.key === 'edit' }"
|
||||
@click="!files.length && pickFiles()"
|
||||
@dragover.prevent="dragActive = true"
|
||||
@dragleave.prevent="dragActive = false"
|
||||
@@ -923,6 +964,9 @@ onUnmounted(() => {
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="files.length && tab.key === 'edit'">
|
||||
<PsEditor ref="psEditor" :file="files[0]" :auto-tpl="pendingTpl" @error="onPsError" @applied="pendingTpl = null" />
|
||||
</template>
|
||||
<template v-else-if="files.length">
|
||||
<div class="it-files">
|
||||
<div v-for="(f, i) in files" :key="i" class="it-file">
|
||||
@@ -933,6 +977,37 @@ onUnmounted(() => {
|
||||
<a v-if="tab.multi" href="javascript:;" class="it-add-more" @click.stop="pickFiles">+ 继续添加</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="tab.key === 'edit'">
|
||||
<div class="it-tpl-wall">
|
||||
<div class="it-tpl-wall-t">
|
||||
✨ 文字模板({{ TEXT_TPLS.length }} 套 · 7 类)
|
||||
<span class="it-tpl-wall-sub">点模板选图 → 整组标题自动套入画布</span>
|
||||
</div>
|
||||
<div class="it-tpl-cats">
|
||||
<button
|
||||
v-for="c in ['全部', ...TPL_CATS]"
|
||||
:key="c"
|
||||
class="it-tpl-cat"
|
||||
:class="{ on: tplCat === c }"
|
||||
@click.stop="tplCat = c"
|
||||
>{{ c }}</button>
|
||||
</div>
|
||||
<div class="it-tpl-wall-grid">
|
||||
<button
|
||||
v-for="t in wallTpls"
|
||||
:key="t.id"
|
||||
class="it-tpl-chip"
|
||||
:title="`[${t.cat}] ${t.name}:${t.parts.join(' / ')} — 点击后选图自动套用`"
|
||||
@click.stop="chooseTpl(t)"
|
||||
>
|
||||
<span class="it-tpl-chip-txt" :style="tplStyle(t)">{{ t.parts[0] }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="it-tpl-wall-foot" @click.stop="pickFiles">
|
||||
⬆️ 点这里选择图片({{ MAX_MB }} MB 内 · 本地处理不上传)
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="it-upload-icon">⬆️</div>
|
||||
<div class="it-upload-big">
|
||||
@@ -1001,6 +1076,9 @@ onUnmounted(() => {
|
||||
</button>
|
||||
<span class="it-hint">在左侧图片上按住拖拽框选打码区域</span>
|
||||
</template>
|
||||
<template v-else-if="tab.key === 'edit'">
|
||||
<span class="it-hint">编辑器内含:工具栏(移动/选框/画笔/橡皮/文字/油漆桶/吸管/裁剪/抓手)、图层面板、历史记录;Ctrl+Z 撤销、滚轮缩放、空格拖动。编辑完成后点下方「执行」导出成品。</span>
|
||||
</template>
|
||||
<template v-else-if="tab.key === 'qrgen'">
|
||||
<label>尺寸</label>
|
||||
<select v-model.number="qrSize" class="it-select">
|
||||
@@ -1285,6 +1363,13 @@ onUnmounted(() => {
|
||||
padding: 10px 14px;
|
||||
}
|
||||
|
||||
&.wall {
|
||||
justify-content: flex-start;
|
||||
padding: 12px 14px;
|
||||
overflow-y: auto;
|
||||
min-height: 322px;
|
||||
}
|
||||
|
||||
.it-upload-icon {
|
||||
font-size: 36px;
|
||||
}
|
||||
@@ -1301,6 +1386,117 @@ onUnmounted(() => {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.it-tpl-wall {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.it-tpl-wall-t {
|
||||
width: 100%;
|
||||
margin-bottom: 8px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
opacity: 0.9;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
|
||||
.it-tpl-wall-sub {
|
||||
font-size: 11.5px;
|
||||
font-weight: 400;
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.it-tpl-cats {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.it-tpl-cat {
|
||||
border: 1px solid rgba(128, 128, 128, 0.32);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
border-radius: 999px;
|
||||
font-size: 11.5px;
|
||||
line-height: 1;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
opacity: 0.75;
|
||||
transition: all 0.12s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
border-color: #2563eb;
|
||||
}
|
||||
|
||||
&.on {
|
||||
background: #2563eb;
|
||||
border-color: #2563eb;
|
||||
color: #fff;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.it-tpl-wall-grid {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.it-tpl-wall-foot {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px dashed rgba(128, 128, 128, 0.3);
|
||||
font-size: 12.5px;
|
||||
text-align: center;
|
||||
opacity: 0.65;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.12s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.it-tpl-chip {
|
||||
height: 40px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.32);
|
||||
border-radius: 8px;
|
||||
background: rgba(128, 128, 128, 0.07);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 6px;
|
||||
transition: border-color 0.12s, transform 0.12s;
|
||||
|
||||
&:hover {
|
||||
border-color: #2563eb;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.it-tpl-chip-txt {
|
||||
font-size: 11.5px;
|
||||
line-height: 1.12;
|
||||
text-align: center;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.it-files {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
@@ -1363,6 +1559,18 @@ onUnmounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 图片编辑(组件内样式见 PsEditor.vue) ----------
|
||||
|
||||
.it-colorswatch {
|
||||
width: 34px;
|
||||
height: 26px;
|
||||
padding: 1px 2px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.it-qrbox {
|
||||
flex: 1;
|
||||
min-height: 120px;
|
||||
|
||||
@@ -6,7 +6,7 @@ export const tool = defineTool({
|
||||
name: translate('tools.image-tools.title'),
|
||||
path: '/image-tools',
|
||||
description: translate('tools.image-tools.description'),
|
||||
keywords: ['image', 'compress', 'convert', 'resize', 'crop', 'rotate', 'filter', 'mosaic', 'exif', 'watermark', 'stitch', '图片', '压缩', '转换', '裁剪', '旋转', '滤镜', '打码', '水印', '拼接'],
|
||||
keywords: ['image', 'compress', 'convert', 'resize', 'crop', 'rotate', 'filter', 'mosaic', 'exif', 'watermark', 'stitch', 'edit', 'text', 'replace', 'photoshop', 'layer', 'brush', 'history', '图片', '压缩', '转换', '裁剪', '旋转', '滤镜', '打码', '水印', '拼接', '编辑', '改文字', '文字替换', '加文字', '画笔', '图层', '历史记录'],
|
||||
component: () => import('./image-tools.vue'),
|
||||
icon: Photo,
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
// 文字花字模板(成套文案):画布内与上传前模板墙共用
|
||||
// cat 分类:通用(经典17套)+ 小红书 / 抖音 / B站 / 公众号 / 视频号 / 封面图
|
||||
export interface TextTpl {
|
||||
id: string; name: string; color: string;
|
||||
cat: string; // 平台分类
|
||||
parts: string[]; // 主标题 → 副标题 → 小字,逐行成组插入
|
||||
grad?: [string, string]; bold?: boolean;
|
||||
stroke?: string; strokeW?: number; shadow?: string; badge?: string;
|
||||
}
|
||||
|
||||
/** 分类标签('全部' 由 UI 拼在最前) */
|
||||
export const TPL_CATS = ['通用', '小红书', '抖音', 'B站', '公众号', '视频号', '封面图'];
|
||||
|
||||
export const TEXT_TPLS: TextTpl[] = [
|
||||
// ---------- 通用(经典 17 套) ----------
|
||||
{ id: 'wp', cat: '通用', name: '白字黑描边·搞怪', color: '#ffffff', stroke: '#1a1a1a', strokeW: 0.10, bold: true, parts: ['最强拉轰!', '《躲汉子》'] },
|
||||
{ id: 'yp', cat: '通用', name: '黄字紫描边·热榜', color: '#ffe14d', stroke: '#7b2cbf', strokeW: 0.10, bold: true, parts: ['B站史上', '点击最高的10首MV'] },
|
||||
{ id: 'wpu', cat: '通用', name: '白字紫描边·科普', color: '#ffffff', stroke: '#8e44ad', strokeW: 0.09, bold: true, parts: ['熬夜', '如何科学修仙'] },
|
||||
{ id: 'yc', cat: '通用', name: '黄字青描边·美食', color: '#ffeb3b', stroke: '#00e5ff', strokeW: 0.11, bold: true, parts: ['辣到没朋友!川菜', '辣子鸡 · 水煮肉片'] },
|
||||
{ id: 'rb', cat: '通用', name: '红底白字·冠军', color: '#ffffff', badge: '#e53935', bold: true, parts: ['收视冠军?'] },
|
||||
{ id: 'bb', cat: '通用', name: '蓝底白字·力作', color: '#ffffff', badge: '#1e88e5', bold: true, parts: ['翻身力作?'] },
|
||||
{ id: 'kb', cat: '通用', name: '黑底黄字·高光', color: '#ffd600', badge: '#212121', bold: true, parts: ['秀翻全场!', 'ALL KILL!'] },
|
||||
{ id: 'gd', cat: '通用', name: '鎏金渐变·打卡', color: '#ffcc00', grad: ['#fff3b0', '#ff9500'], stroke: '#7a4a00', strokeW: 0.07, bold: true, parts: ['香浓拿铁', '网红打卡'] },
|
||||
{ id: 'fg', cat: '通用', name: '烈焰渐变·社会', color: '#ff4d4f', grad: ['#ff5252', '#ff8f00'], stroke: '#7a1f00', strokeW: 0.08, bold: true, parts: ['男子医院体验', '竟查出有孕在身'] },
|
||||
{ id: 'ws', cat: '通用', name: '白字投影·Vlog', color: '#ffffff', shadow: 'rgba(0,0,0,0.75)', bold: true, parts: ['Vlog', '我的旅行日记'] },
|
||||
{ id: 'cb', cat: '通用', name: '青字黑描边·热梗', color: '#18ffff', stroke: '#00364d', strokeW: 0.10, bold: true, parts: ['年轻人', '耗子尾汁'] },
|
||||
{ id: 'pb', cat: '通用', name: '粉底白字·生活', color: '#ffffff', badge: '#ec407a', bold: true, parts: ['我的', '上海日租生活'] },
|
||||
{ id: 'ol', cat: '通用', name: '空心描边·搞笑', color: 'rgba(255,255,255,0.06)', stroke: '#2962ff', strokeW: 0.10, bold: true, parts: ['你根本', '不会上厕所'] },
|
||||
{ id: 'gb', cat: '通用', name: '荧光绿描边·攻略', color: '#76ff03', stroke: '#1b3d00', strokeW: 0.09, bold: true, parts: ['角色养成攻略', '躺平吧 赶紧的'] },
|
||||
{ id: 'wp2', cat: '通用', name: '白字蓝边·职场', color: '#ffffff', stroke: '#0d47a1', strokeW: 0.10, bold: true, parts: ['合法打工人', 'SLAVE の一天 DAILY'] },
|
||||
{ id: 'gd2', cat: '通用', name: '金渐变·B站', color: '#ffe082', grad: ['#fffde7', '#ffb300'], stroke: '#5d4037', strokeW: 0.07, bold: true, parts: ['B站', '崛起的十二年'] },
|
||||
{ id: 'rb2', cat: '通用', name: '红底白字·毕业', color: '#ffffff', badge: '#c62828', bold: true, parts: ['毕业后找工作', '如此简单!'] },
|
||||
|
||||
// ---------- 小红书(品牌红 #FF2442,种草/探店/避雷风) ----------
|
||||
{ id: 'xhs1', cat: '小红书', name: '小红红底·种草', color: '#ffffff', badge: '#FF2442', bold: true, parts: ['今日份宝藏', '这款APP真的绝了'] },
|
||||
{ id: 'xhs2', cat: '小红书', name: '白字粉描边·探店', color: '#ffffff', stroke: '#FF6B8B', strokeW: 0.10, bold: true, parts: ['魔都探店', '藏在弄堂里的咖啡馆'] },
|
||||
{ id: 'xhs3', cat: '小红书', name: '粉底白字·好物', color: '#ffffff', badge: '#FF85A2', bold: true, parts: ['平价好物', '均价30的快乐'] },
|
||||
{ id: 'xhs4', cat: '小红书', name: '黄字红描边·避坑', color: '#FFE14D', stroke: '#FF2442', strokeW: 0.11, bold: true, parts: ['避雷!', '这5款千万别买'] },
|
||||
{ id: 'xhs5', cat: '小红书', name: '玫红底白字·vlog', color: '#ffffff', badge: '#FF3B5C', bold: true, parts: ['周末vlog', '把日子过成诗'] },
|
||||
|
||||
// ---------- 抖音(黑底+霓虹青 #25F4EE / 玫红 #FE2C55,爆款悬念风) ----------
|
||||
{ id: 'dy1', cat: '抖音', name: '抖音黑底青字·爆款', color: '#25F4EE', badge: '#161823', bold: true, parts: ['一招教你', '播放量翻10倍'] },
|
||||
{ id: 'dy2', cat: '抖音', name: '白字玫红描边·悬念', color: '#ffffff', stroke: '#FE2C55', strokeW: 0.11, bold: true, parts: ['千万别划走', '结局没想到…'] },
|
||||
{ id: 'dy3', cat: '抖音', name: '霓虹青黑描边·教程', color: '#25F4EE', stroke: '#000000', strokeW: 0.11, bold: true, parts: ['3秒学会', '手机拍大片'] },
|
||||
{ id: 'dy4', cat: '抖音', name: '玫红底白字·挑战', color: '#ffffff', badge: '#FE2C55', bold: true, parts: ['挑战全网', '最火BGM卡点'] },
|
||||
{ id: 'dy5', cat: '抖音', name: '青玫渐变·音乐', color: '#ffffff', grad: ['#25F4EE', '#FE2C55'], stroke: '#101014', strokeW: 0.08, bold: true, parts: ['循环100遍', '这歌也太上头'] },
|
||||
|
||||
// ---------- B站(B站蓝 #00AEEC / 粉 #FB7299,三连/硬核风) ----------
|
||||
{ id: 'bili1', cat: 'B站', name: 'B站蓝底白字·三连', color: '#ffffff', badge: '#00AEEC', bold: true, parts: ['一键三连!', '这期真的爆肝'] },
|
||||
{ id: 'bili2', cat: 'B站', name: '白字B站蓝描边·硬核', color: '#ffffff', stroke: '#00AEEC', strokeW: 0.10, bold: true, parts: ['硬核拆解', '全网最全攻略'] },
|
||||
{ id: 'bili3', cat: 'B站', name: 'B站粉底白字·番剧', color: '#ffffff', badge: '#FB7299', bold: true, parts: ['新番速报', '本季必追TOP5'] },
|
||||
{ id: 'bili4', cat: 'B站', name: '黄字B站蓝描边·高能', color: '#FFEB3B', stroke: '#00AEEC', strokeW: 0.11, bold: true, parts: ['前方高能', '第3次神转折'] },
|
||||
{ id: 'bili5', cat: 'B站', name: '白字投影·UP主', color: '#ffffff', shadow: 'rgba(0,60,90,0.85)', bold: true, parts: ['UP主精选', '百大UP合集'] },
|
||||
|
||||
// ---------- 公众号(深蓝/红金,深度长文风) ----------
|
||||
{ id: 'gzh1', cat: '公众号', name: '深蓝底白字·深度', color: '#ffffff', badge: '#1E3A5F', bold: true, parts: ['深度长文', '普通人逆袭的3条路'] },
|
||||
{ id: 'gzh2', cat: '公众号', name: '白字深蓝描边·干货', color: '#ffffff', stroke: '#2B6CB0', strokeW: 0.10, bold: true, parts: ['干货|', '一篇讲透提示词'] },
|
||||
{ id: 'gzh3', cat: '公众号', name: '红底白字·头条', color: '#ffffff', badge: '#C53030', bold: true, parts: ['头条', '这个行业要变天'] },
|
||||
{ id: 'gzh4', cat: '公众号', name: '黑字黄底·金句', color: '#1a1a1a', badge: '#F6E05E', bold: true, parts: ['句句戳心', '别再无效努力'] },
|
||||
{ id: 'gzh5', cat: '公众号', name: '白字深投影·观点', color: '#ffffff', shadow: 'rgba(20,40,80,0.9)', bold: true, parts: ['观点', '高手都在做减法'] },
|
||||
|
||||
// ---------- 视频号(微信绿 #07C160,直播/私域风) ----------
|
||||
{ id: 'sph1', cat: '视频号', name: '微信绿底白字·直播', color: '#ffffff', badge: '#07C160', bold: true, parts: ['直播预告', '今晚8点不见不散'] },
|
||||
{ id: 'sph2', cat: '视频号', name: '白字绿描边·热转', color: '#ffffff', stroke: '#07C160', strokeW: 0.10, bold: true, parts: ['热转|', '这条视频火了'] },
|
||||
{ id: 'sph3', cat: '视频号', name: '绿渐变·私域', color: '#ffffff', grad: ['#8CE99A', '#07C160'], stroke: '#04421f', strokeW: 0.08, bold: true, parts: ['私域干货', '3步做出爆款封面'] },
|
||||
{ id: 'sph4', cat: '视频号', name: '白底绿字·教程', color: '#07C160', badge: '#ffffff', bold: true, parts: ['手把手教', '视频号涨粉秘籍'] },
|
||||
{ id: 'sph5', cat: '视频号', name: '深底青字·带货', color: '#69F0AE', badge: '#0B1F17', bold: true, parts: ['爆单节奏', '这样挂车转化翻倍'] },
|
||||
|
||||
// ---------- 封面图(大标题冲击力,点击率优先) ----------
|
||||
{ id: 'cov1', cat: '封面图', name: '金渐变·封面主标', color: '#FFE58F', grad: ['#FFF7CC', '#FFB300'], stroke: '#7A4A00', strokeW: 0.08, bold: true, parts: ['封面主标题', '点击率翻倍的秘密'] },
|
||||
{ id: 'cov2', cat: '封面图', name: '撞色红块·数字', color: '#ffffff', badge: '#FF4D4F', bold: true, parts: ['10个神器', '第7个我真的吹爆'] },
|
||||
{ id: 'cov3', cat: '封面图', name: '白字粗黑边·大标题', color: '#ffffff', stroke: '#000000', strokeW: 0.13, bold: true, parts: ['超全合集', '2026必装软件'] },
|
||||
{ id: 'cov4', cat: '封面图', name: '蓝紫渐变·科技感', color: '#ffffff', grad: ['#4F46E5', '#9333EA'], stroke: '#1a1040', strokeW: 0.08, bold: true, parts: ['AI革命', '这5款工具先冲'] },
|
||||
{ id: 'cov5', cat: '封面图', name: '黑底白字·极简', color: '#ffffff', badge: '#111111', bold: true, parts: ['极简封面', '留白高级感'] },
|
||||
];
|
||||
|
||||
/** 按分类筛选(cat='' 表示全部) */
|
||||
export function filterTpls(cat: string): TextTpl[] {
|
||||
return !cat || cat === '全部' ? TEXT_TPLS : TEXT_TPLS.filter(t => t.cat === cat);
|
||||
}
|
||||
|
||||
// 模板 chip 的 CSS 预览样式
|
||||
export function tplStyle(t: TextTpl): Record<string, string> {
|
||||
const s: Record<string, string> = { fontWeight: '700' };
|
||||
if (t.badge) {
|
||||
s.background = t.badge;
|
||||
s.color = t.color;
|
||||
s.padding = '4px 7px';
|
||||
s.borderRadius = '5px';
|
||||
}
|
||||
else if (t.grad) {
|
||||
s.backgroundImage = `linear-gradient(90deg, ${t.grad[0]}, ${t.grad[1]})`;
|
||||
s.backgroundClip = 'text';
|
||||
s.WebkitBackgroundClip = 'text';
|
||||
s.color = 'transparent';
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `1px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s.color = t.color;
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `${Math.max(1, Math.round((t.strokeW ?? 0.08) * 16))}px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
if (t.shadow) {
|
||||
s.textShadow = `2px 2px 3px ${t.shadow}`;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { loadImgHist, type HistItem } from './img-hist';
|
||||
|
||||
/**
|
||||
* 图片历史右栏(铁规则统一实现):
|
||||
* 50×50 缩略图右侧竖排、点击查看大图、按本人隔离(登录=账号/未登录=机器码)。
|
||||
* 父级把本组件放在布局最右侧即可;生成成功后调用父组件暴露的 reload()。
|
||||
*/
|
||||
const props = withDefaults(defineProps<{ kind: string; label?: string }>(), {
|
||||
label: '历史',
|
||||
});
|
||||
|
||||
const items = ref<HistItem[]>([]);
|
||||
const viewUrl = ref('');
|
||||
|
||||
async function reload() {
|
||||
items.value = await loadImgHist(props.kind);
|
||||
}
|
||||
|
||||
defineExpose({ reload });
|
||||
onMounted(reload);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="ih">
|
||||
<div class="ih-t">
|
||||
{{ label }}<em v-if="items.length">{{ items.length }}</em>
|
||||
</div>
|
||||
<div v-if="items.length" class="ih-list">
|
||||
<img
|
||||
v-for="it in items"
|
||||
:key="it.id"
|
||||
:src="it.img_url"
|
||||
:title="it.prompt || '点击查看大图'"
|
||||
class="ih-thumb"
|
||||
@click="viewUrl = it.img_url"
|
||||
>
|
||||
</div>
|
||||
<div v-else class="ih-empty">
|
||||
还没有<br>生成记录
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div v-if="viewUrl" class="ih-view" @click="viewUrl = ''">
|
||||
<img :src="viewUrl" alt="历史图片">
|
||||
<span class="ih-view-tip">点击任意处关闭</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.ih {
|
||||
flex: 0 0 76px;
|
||||
width: 76px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
background: rgba(128, 128, 128, 0.04);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
align-self: flex-start;
|
||||
max-height: calc(100vh - 230px);
|
||||
|
||||
.ih-t {
|
||||
font-size: 11.5px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
padding: 9px 4px 7px;
|
||||
border-bottom: 1px solid rgba(128, 128, 128, 0.18);
|
||||
opacity: 0.75;
|
||||
flex-shrink: 0;
|
||||
|
||||
em {
|
||||
font-style: normal;
|
||||
color: #0ea5a0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.ih-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 9px 13px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ih-thumb {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 7px;
|
||||
border: 2px solid transparent;
|
||||
cursor: zoom-in;
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.15s;
|
||||
display: block;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
border-color: #0ea5a0;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
}
|
||||
|
||||
.ih-empty {
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
opacity: 0.45;
|
||||
padding: 16px 4px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
|
||||
.ih-view {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9999;
|
||||
background: rgba(0, 0, 0, 0.86);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: zoom-out;
|
||||
|
||||
img {
|
||||
max-width: 92vw;
|
||||
max-height: 88vh;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.ih-view-tip {
|
||||
position: absolute;
|
||||
bottom: 26px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.ih {
|
||||
flex: none;
|
||||
width: 100%;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
max-height: none;
|
||||
|
||||
.ih-t {
|
||||
border-bottom: none;
|
||||
border-right: 1px solid rgba(128, 128, 128, 0.18);
|
||||
padding: 8px 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ih-list {
|
||||
flex-direction: row;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,102 @@
|
||||
import { getMachineId } from '@/tools/license/license';
|
||||
|
||||
/**
|
||||
* 图片历史共享层(铁规则):
|
||||
* - 历史右栏 50×50 缩略图竖排 + 点击查看大图(ImgHist.vue)
|
||||
* - 按本人隔离:登录带 Authorization(服务端按账号归属过滤),未登录按机器码
|
||||
* - 生成结果保存到服务器后台「存储设置」目录(/relay/ai/img-save → DATA_DIR/gen_images)
|
||||
* 历史拉取/保存失败一律静默,不阻断生成与下载。
|
||||
*/
|
||||
|
||||
/** 登录态 Authorization(无登录返回空对象) */
|
||||
export function authHdr(): Record<string, string> {
|
||||
try {
|
||||
const a = JSON.parse(localStorage.getItem('it-tools-auth') ?? 'null');
|
||||
if (a && typeof a.token === 'string' && a.token) {
|
||||
const h: Record<string, string> = {};
|
||||
h['Authorization'] = 'Bearer ' + a.token;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
return {};
|
||||
}
|
||||
|
||||
export interface HistItem {
|
||||
id: string;
|
||||
at: number;
|
||||
model?: string;
|
||||
prompt?: string;
|
||||
kind?: string;
|
||||
img_url: string;
|
||||
w?: number;
|
||||
h?: number;
|
||||
}
|
||||
|
||||
/** 拉取本人某 kind 的图片历史(静默失败返回 []) */
|
||||
export async function loadImgHist(kind: string): Promise<HistItem[]> {
|
||||
try {
|
||||
const url = `/relay/ai/img-history?machine=${encodeURIComponent(getMachineId())}&kind=${encodeURIComponent(kind)}`;
|
||||
const res = await fetch(url, { headers: authHdr() });
|
||||
const j = await res.json();
|
||||
// 铁规则:所有功能历史最多显示 100 条(服务端已截断,此处兜底)
|
||||
if (j.code === 200 && Array.isArray(j.data)) return j.data.slice(0, 100);
|
||||
}
|
||||
catch { /* 静默 */ }
|
||||
return [];
|
||||
}
|
||||
|
||||
export interface SaveImgOpts {
|
||||
kind: string;
|
||||
tool: string;
|
||||
b64: string;
|
||||
model?: string;
|
||||
prompt?: string;
|
||||
}
|
||||
|
||||
/** 保存生成结果到服务器(后台 storage_root/gen_images),静默失败返回 false */
|
||||
export async function saveImgHist(o: SaveImgOpts): Promise<boolean> {
|
||||
try {
|
||||
const h = authHdr();
|
||||
h['Content-Type'] = 'application/json';
|
||||
const res = await fetch('/relay/ai/img-save', {
|
||||
method: 'POST',
|
||||
headers: h,
|
||||
body: JSON.stringify({
|
||||
machine: getMachineId(),
|
||||
b64: o.b64,
|
||||
kind: o.kind,
|
||||
tool: o.tool,
|
||||
model: o.model || '',
|
||||
prompt: o.prompt || '',
|
||||
}),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
return j.code === 200;
|
||||
}
|
||||
catch { /* 静默,不阻断下载 */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Blob → 纯 base64(不含 data: 前缀) */
|
||||
export function blobToB64(blob: Blob): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => {
|
||||
const s = String(fr.result || '');
|
||||
resolve(s.includes(',') ? s.split(',', 2)[1] : s);
|
||||
};
|
||||
fr.onerror = () => resolve('');
|
||||
fr.readAsDataURL(blob);
|
||||
}
|
||||
catch {
|
||||
resolve('');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** dataURL → 纯 base64 */
|
||||
export function dataUrlToB64(u: string): string {
|
||||
return u.includes(',') ? u.split(',', 2)[1] : u;
|
||||
}
|
||||
+8
-2
@@ -87,13 +87,17 @@ 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 base64ImageConverter } from './base64-image-converter';
|
||||
import { tool as zhConvert } from './zh-convert';
|
||||
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 mcpConnect } from './mcp-connect';
|
||||
import { tool as docConvert } from './doc-convert';
|
||||
import { tool as aiRetouch } from './ai-retouch';
|
||||
import { tool as faceSwap } from './face-swap';
|
||||
import { tool as posterMaker } from './poster';
|
||||
import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator';
|
||||
import { tool as randomPortGenerator } from './random-port-generator';
|
||||
import { tool as romanNumeralConverter } from './roman-numeral-converter';
|
||||
@@ -107,6 +111,7 @@ import { tool as urlEncoder } from './url-encoder';
|
||||
import { tool as urlParser } from './url-parser';
|
||||
import { tool as uuidGenerator } from './uuid-generator';
|
||||
import { tool as macAddressLookup } from './mac-address-lookup';
|
||||
import { tool as myIp } from './my-ip';
|
||||
import { tool as xmlFormatter } from './xml-formatter';
|
||||
import { tool as yamlViewer } from './yaml-viewer';
|
||||
|
||||
@@ -163,11 +168,12 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Images and videos',
|
||||
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, videoTools, audioTools, sealMaker, signaturePad, textToImage, aiGen, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
|
||||
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, base64ImageConverter, videoTools, audioTools, sealMaker, signaturePad, textToImage, aiGen, docConvert, aiRetouch, faceSwap, posterMaker, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
|
||||
},
|
||||
{
|
||||
name: 'Development',
|
||||
components: [
|
||||
mcpConnect,
|
||||
gitMemo,
|
||||
randomPortGenerator,
|
||||
crontabGenerator,
|
||||
@@ -186,7 +192,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Network',
|
||||
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator, myIp],
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
|
||||
@@ -17,6 +17,11 @@ const props = defineProps<{ path: string }>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
/** 跳转到站内支付页 /buy(未授权状态下所有购买入口统一走这里) */
|
||||
function goBuy(): void {
|
||||
router.push('/buy');
|
||||
}
|
||||
|
||||
const displayName = computed(() => PROTECTED_TOOLS[props.path] ?? '');
|
||||
const protectedTool = computed(() => !!PROTECTED_TOOLS[props.path]);
|
||||
|
||||
@@ -161,10 +166,9 @@ onUnmounted(() => {
|
||||
<template v-if="!licenseState.authorized">
|
||||
<a
|
||||
:href="BUY_URL"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
class="lg-buy"
|
||||
title="买断制授权,不按次不按月;一次激活,13 个高级功能全部解锁,授权跟随账号、换电脑可恢复"
|
||||
@click.prevent="goBuy"
|
||||
>永久解锁 13 个功能</a>
|
||||
<a href="javascript:;" class="lg-link" @click="showCardInput = !showCardInput">卡密</a>
|
||||
</template>
|
||||
@@ -202,7 +206,7 @@ onUnmounted(() => {
|
||||
</p>
|
||||
|
||||
<div class="lg-modal-actions">
|
||||
<c-button type="primary" :href="BUY_URL" target="_blank" rel="noopener">
|
||||
<c-button type="primary" @click="goBuy">
|
||||
购买授权
|
||||
</c-button>
|
||||
<c-button @click="showCardInput = !showCardInput">
|
||||
|
||||
@@ -2,7 +2,7 @@ import { reactive } from 'vue';
|
||||
|
||||
// ====== 授权服务器 (CardAuth) ======
|
||||
export const AUTH_BASE = 'https://auth.88531.cn/api';
|
||||
export const BUY_URL = 'https://auth.88531.cn/#/shop';
|
||||
export const BUY_URL = '/buy'; // 站内支付页:下单 -> 支付 -> 当场显示卡密
|
||||
|
||||
// 受控功能(消耗服务器性能:翻译走服务器代理、OCR 走本机识别服务)
|
||||
export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
@@ -19,6 +19,8 @@ export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
'/ai-image-lab': 'AI图片实验室',
|
||||
'/copywriting': '文案工具箱',
|
||||
'/ai-gen': 'AI 生图',
|
||||
'/face-swap': 'AI换脸',
|
||||
'/poster-maker': 'AI海报生成',
|
||||
};
|
||||
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能每天免费 30 分钟
|
||||
@@ -238,3 +240,78 @@ export async function activateCard(cardKey: string, contactQq: string, replace =
|
||||
licenseState.activating = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 工具使用统计上报:任何访客(含未登录)打开工具页即计一次 ----
|
||||
// 同一工具 10 分钟内只上报一次(防刷新刷量),服务端还会再做一层去重与限流。
|
||||
const USAGE_THROTTLE_MS = 10 * 60 * 1000;
|
||||
|
||||
export function reportToolUsage(path: string): void {
|
||||
try {
|
||||
const tool = String(path || '').replace(/^\/+/, '').slice(0, 64);
|
||||
if (!tool) {
|
||||
return;
|
||||
}
|
||||
const key = `it-tools-usage:${tool}`;
|
||||
const last = Number(localStorage.getItem(key) || 0);
|
||||
if (Date.now() - last < USAGE_THROTTLE_MS) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(key, String(Date.now()));
|
||||
let machine = '';
|
||||
try {
|
||||
machine = getMachineId();
|
||||
}
|
||||
catch {
|
||||
machine = '';
|
||||
}
|
||||
fetch('/relay/usage', {
|
||||
method: 'POST',
|
||||
keepalive: true,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine_id: machine, tool }),
|
||||
}).catch(() => {});
|
||||
}
|
||||
catch {
|
||||
// 统计失败绝不影响功能
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 在线统计心跳:打开满 1 分钟才开始上报;仅未登录访客被统计 ----
|
||||
const ONLINE_DELAY_MS = 60 * 1000; // 停留超过 1 分钟才计入在线(由前端延迟首发实现)
|
||||
const ONLINE_BEAT_MS = 30 * 1000; // 之后每 30s 心跳一次(后台标签被浏览器节流为 60s,服务端 90s 窗口判定)
|
||||
let onlineStarted = false;
|
||||
|
||||
function isGuest(): boolean {
|
||||
try {
|
||||
return !JSON.parse(localStorage.getItem('it-tools-auth') ?? 'null');
|
||||
}
|
||||
catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function startOnlineHeartbeat(): void {
|
||||
if (onlineStarted) {
|
||||
return;
|
||||
}
|
||||
onlineStarted = true;
|
||||
const beat = () => {
|
||||
try {
|
||||
fetch('/relay/online', {
|
||||
method: 'POST',
|
||||
keepalive: true,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine_id: getMachineId(), guest: isGuest() }),
|
||||
}).catch(() => {});
|
||||
}
|
||||
catch {
|
||||
// 统计失败绝不影响功能
|
||||
}
|
||||
};
|
||||
setTimeout(() => {
|
||||
beat();
|
||||
setInterval(beat, ONLINE_BEAT_MS);
|
||||
// 登录/登出立即同步:登录后该机器被移出在线统计
|
||||
window.addEventListener('it-tools-auth-changed', beat);
|
||||
}, ONLINE_DELAY_MS);
|
||||
}
|
||||
@@ -0,0 +1,645 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { Plug, Plus, Trash } from '@vicons/tabler';
|
||||
import { checkAuth, getMachineId } from '../license/license';
|
||||
|
||||
// ===== 连接信息 =====
|
||||
const endpoint = `${window.location.origin}/mcp`;
|
||||
const loading = ref(true);
|
||||
const authorized = ref(false);
|
||||
const machine = getMachineId();
|
||||
|
||||
// ===== 令牌管理 =====
|
||||
interface McpToken {
|
||||
token: string;
|
||||
machine: string;
|
||||
note: string;
|
||||
created: number;
|
||||
last_used: number;
|
||||
calls: number;
|
||||
}
|
||||
const tokens = ref<McpToken[]>([]);
|
||||
const genNote = ref('');
|
||||
const busy = ref(false);
|
||||
const copiedKey = ref('');
|
||||
|
||||
onMounted(async () => {
|
||||
authorized.value = await checkAuth();
|
||||
if (authorized.value) {
|
||||
await loadTokens();
|
||||
// 已购本站授权的设备:没有令牌就自动建一个默认的,打开页面即可复制即用
|
||||
if (!tokens.value.length) {
|
||||
genNote.value = '默认';
|
||||
await genToken();
|
||||
}
|
||||
}
|
||||
loading.value = false;
|
||||
});
|
||||
|
||||
// ===== 主令牌(列表第一条,配置示例与大展示块都用它) =====
|
||||
const primaryToken = computed(() => tokens.value[0]?.token ?? '');
|
||||
|
||||
async function loadTokens() {
|
||||
try {
|
||||
const res = await fetch(`/relay/mcp/tokens?machine_id=${encodeURIComponent(machine)}`);
|
||||
const j = await res.json();
|
||||
if (j?.code === 200) tokens.value = j.data?.tokens ?? [];
|
||||
} catch { /* 网络错误静默,页面仍可展示端点信息 */ }
|
||||
}
|
||||
|
||||
async function genToken() {
|
||||
if (busy.value) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
const res = await fetch('/relay/mcp/tokens', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine_id: machine, note: genNote.value }),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (j?.code === 200) {
|
||||
genNote.value = '';
|
||||
await loadTokens();
|
||||
} else {
|
||||
window.alert(j?.message || '生成失败');
|
||||
}
|
||||
} catch {
|
||||
window.alert('网络错误,请稍后重试');
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function delToken(tok: McpToken) {
|
||||
if (!window.confirm(`确定删除令牌「${tok.note || 'MCP 客户端'}」?删除后使用该令牌的 AI 客户端将立即失效。`)) return;
|
||||
try {
|
||||
const res = await fetch('/relay/mcp/tokens', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine_id: machine, action: 'delete', token: tok.token }),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (j?.code === 200) await loadTokens();
|
||||
else window.alert(j?.message || '删除失败');
|
||||
} catch {
|
||||
window.alert('网络错误,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
async function copyText(text: string, key: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedKey.value = key;
|
||||
setTimeout(() => (copiedKey.value = ''), 1600);
|
||||
} catch {
|
||||
window.alert('复制失败,请手动选择复制');
|
||||
}
|
||||
}
|
||||
|
||||
function fmtTime(ts: number) {
|
||||
if (!ts) return '—';
|
||||
const d = new Date(ts * 1000);
|
||||
const p = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
// ===== 客户端配置示例(授权机自动带真实主令牌,复制即用;未授权显示占位) =====
|
||||
const tokPlaceholder = 'mcpt_你的令牌';
|
||||
const tokForCfg = () => primaryToken.value || tokPlaceholder;
|
||||
const hermesCfg = computed(
|
||||
() => `mcp_servers:
|
||||
ittools-pro:
|
||||
url: "${endpoint}"
|
||||
headers:
|
||||
Authorization: "Bearer ${tokForCfg()}"
|
||||
timeout: 600`,
|
||||
);
|
||||
const jsonCfg = computed(
|
||||
() => JSON.stringify(
|
||||
{
|
||||
mcpServers: {
|
||||
'it-tools-pro': {
|
||||
type: 'http',
|
||||
url: endpoint,
|
||||
headers: { Authorization: `Bearer ${tokForCfg()}` },
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
const curlCfg = computed(
|
||||
() => `curl -sS ${endpoint} \\
|
||||
-H 'Content-Type: application/json' \\
|
||||
-H 'Authorization: Bearer ${tokForCfg()}' \\
|
||||
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'`,
|
||||
);
|
||||
|
||||
// ===== 接入后怎么使用:场景话术示例 =====
|
||||
const usageExamples = [
|
||||
{ scene: '文本翻译', say: '把这段话翻译成英文:公司的季度报告明天提交', tool: 'translate_text', got: '直接返回译文' },
|
||||
{ scene: '图片文字识别', say: '识别这张截图里的文字 /home/pics/发票.png', tool: 'ocr', got: '逐行文字 + 置信度' },
|
||||
{ scene: '整篇文档翻译', say: '把这份合同翻译成英文 /home/docs/合同.docx', tool: 'translate_doc', got: '译文全文(约 1-2 分钟)' },
|
||||
{ scene: '文字转语音', say: '把这段开场白合成一段普通话音频:大家好…', tool: 'tts', got: 'mp3 下载链接' },
|
||||
{ scene: '音频转文字', say: '把这段录音转成文字 /home/voice/meeting.mp3', tool: 'speech_to_text', got: '带时间轴的识别文本' },
|
||||
{ scene: '视频生成字幕', say: '给这个视频生成中文字幕 /home/video/demo.mp4', tool: 'extract_subtitle', got: '带时间轴的字幕分段' },
|
||||
{ scene: '视频批处理', say: '把这个视频压缩小一点 /home/video/big.mp4', tool: 'video_process', got: '处理后的视频下载链接' },
|
||||
{ scene: 'AI 生图', say: '画一张赛博朋克风格的雨夜城市插画', tool: 'gen_image', got: '图片下载链接' },
|
||||
{ scene: '文档格式转换', say: '把这份 PDF 转成可编辑的 Word /home/docs/资料.pdf', tool: 'convert_doc', got: '转换后文件下载链接' },
|
||||
{ scene: '图片抠图', say: '把这张商品图的背景去掉 /home/pics/shirt.jpg', tool: 'remove_bg', got: '透明底 PNG 链接' },
|
||||
{ scene: '图片放大', say: '把这张老照片放大两倍变清晰 /home/pics/old.jpg', tool: 'upscale_image', got: '高清大图链接' },
|
||||
{ scene: '文案改写', say: '把这段文案改写得更口语化发朋友圈:…', tool: 'copywriting', got: '改写后的文案' },
|
||||
{ scene: '看图问答', say: '这张图里写了什么?/home/pics/chart.png', tool: 'vision_qa', got: '对图片内容的解答' },
|
||||
];
|
||||
|
||||
// ===== 接入后排错速查 =====
|
||||
const mcpTroubles = [
|
||||
{ code: '连接成功但 AI 说没有相关工具', fix: '检查客户端配置是否已保存并重启/重连;工具列表里应出现 13 个本站工具(或让 AI「列出你能调用的工具」自检)' },
|
||||
{ code: '401 unauthorized', fix: '令牌没带上、拼错、或已被删除——复制页内最新令牌替换配置里的 Bearer 值' },
|
||||
{ code: '授权已失效 / 403', fix: '卡密过期或授权被撤销——续费购买新卡并重新激活后,原令牌自动恢复可用' },
|
||||
{ code: '连接超时', fix: '生图、文档翻译、视频处理是慢操作——把客户端 timeout 调到 ≥ 600 秒再试' },
|
||||
{ code: '文件不存在', fix: '文件类工具传服务器可读的绝对路径;与站点同机直接传本机路径即可' },
|
||||
];
|
||||
|
||||
// ===== 可调用的 13 个工具 =====
|
||||
const mcpTools = [
|
||||
{ name: 'translate_text', desc: '文本翻译(谷歌引擎,多语言互译)' },
|
||||
{ name: 'ocr', desc: '图片/PDF 文字识别,逐行文本+置信度(PDF 自动逐页)' },
|
||||
{ name: 'translate_doc', desc: '整篇文档翻译(docx/pdf → 译文全文)' },
|
||||
{ name: 'tts', desc: '文字合成语音(mp3 下载链接)' },
|
||||
{ name: 'speech_to_text', desc: '音频/语音转文字(ASR)' },
|
||||
{ name: 'extract_subtitle', desc: '视频字幕 AI 识别(带时间轴)' },
|
||||
{ name: 'video_process', desc: '视频批处理:转码/压缩/裁剪/去水印/截图/GIF 等 14 种' },
|
||||
{ name: 'gen_image', desc: 'AI 文生图(图片下载链接)' },
|
||||
{ name: 'convert_doc', desc: '文档格式转换(pdf/docx/xlsx/pptx 互转)' },
|
||||
{ name: 'remove_bg', desc: '图片抠图去背景(透明底 PNG)' },
|
||||
{ name: 'upscale_image', desc: '图片超分放大(2x/4x)并降噪' },
|
||||
{ name: 'copywriting', desc: '文案工具:改写/降AIGC/爆款标题/小红书/朋友圈' },
|
||||
{ name: 'vision_qa', desc: '看图问答:描述/提取/判断图片内容' },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mcp-page">
|
||||
<n-spin :show="loading">
|
||||
<!-- ===== 状态横幅 ===== -->
|
||||
<n-card class="mcp-card" :bordered="true">
|
||||
<template #header>
|
||||
<div class="mcp-h">
|
||||
<Plug :size="20" />
|
||||
<span>MCP 接入:让 AI 助手直接调用本站 13 个工具</span>
|
||||
</div>
|
||||
</template>
|
||||
<n-alert v-if="authorized" type="success" :show-icon="true">
|
||||
本设备已授权 ✓ — 可生成 MCP 令牌,接入任意支持 MCP 的 AI 客户端(Hermes / Claude / Cherry Studio 等)。
|
||||
</n-alert>
|
||||
<div v-else class="mcp-buy">
|
||||
<n-alert type="warning" :show-icon="true">
|
||||
本设备尚未授权:<b>购买卡密并激活</b>后才能生成 MCP 令牌、调用本站 MCP。
|
||||
</n-alert>
|
||||
<div class="mcp-buy-row">
|
||||
<c-button type="primary" to="/buy">
|
||||
💳 前往购买卡密
|
||||
</c-button>
|
||||
<c-button @click="copyText(machine, 'machine')">
|
||||
{{ copiedKey === 'machine' ? '✓ 已复制机器码' : `复制机器码 ${machine}` }}
|
||||
</c-button>
|
||||
<span class="mcp-hint">激活时在卡密页粘贴上方机器码</span>
|
||||
</div>
|
||||
</div>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 连接信息 ===== -->
|
||||
<n-card class="mcp-card" title="① 连接信息" :bordered="true">
|
||||
<div class="mcp-row">
|
||||
<span class="mcp-label">端点地址</span>
|
||||
<code class="mcp-code">{{ endpoint }}</code>
|
||||
<c-button size="small" @click="copyText(endpoint, 'ep')">
|
||||
{{ copiedKey === 'ep' ? '✓ 已复制' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<div class="mcp-row">
|
||||
<span class="mcp-label">协议</span>
|
||||
<span>MCP Streamable HTTP(JSON-RPC 2.0),所有支持 HTTP 传输的 MCP 客户端均可接入</span>
|
||||
</div>
|
||||
<div class="mcp-row">
|
||||
<span class="mcp-label">鉴权</span>
|
||||
<span>请求头 <code class="mcp-code">Authorization: Bearer <你的MCP令牌></code>(下方生成)</span>
|
||||
</div>
|
||||
<div class="mcp-row">
|
||||
<span class="mcp-label">机器码</span>
|
||||
<code class="mcp-code">{{ machine }}</code>
|
||||
<c-button size="small" @click="copyText(machine, 'machine2')">
|
||||
{{ copiedKey === 'machine2' ? '✓ 已复制' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 令牌管理 ===== -->
|
||||
<n-card class="mcp-card" :bordered="true">
|
||||
<template #header>
|
||||
<div class="mcp-h">
|
||||
<span>② MCP 令牌(调用凭证)</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="authorized">
|
||||
<div class="mcp-auth-ok">
|
||||
✓ 本设备已获授权(与站内卡密为同一套,购买并激活后即可直接调用,无需单独开通 MCP)
|
||||
</div>
|
||||
<div v-if="primaryToken" class="mcp-primary">
|
||||
<div class="mcp-primary-label">本设备可用令牌 — 复制即用,③ 的配置已自动带好:</div>
|
||||
<div class="mcp-primary-body">
|
||||
<code class="mcp-primary-token">{{ primaryToken }}</code>
|
||||
<c-button size="small" type="primary" @click="copyText(primaryToken, 'ptok')">
|
||||
{{ copiedKey === 'ptok' ? '✓ 已复制' : '复制令牌' }}
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mcp-gen-row">
|
||||
<n-input
|
||||
v-model:value="genNote"
|
||||
placeholder="备注,如:Hermes / Claude(可空)"
|
||||
:maxlength="40"
|
||||
style="max-width: 320px"
|
||||
@keydown.enter="genToken"
|
||||
/>
|
||||
<c-button type="primary" :loading="busy" @click="genToken">
|
||||
<Plus :size="14" /> 生成令牌
|
||||
</c-button>
|
||||
<span class="mcp-hint">每台设备最多 10 个;令牌等同授权凭证,泄露请立即删除重建</span>
|
||||
</div>
|
||||
<div v-if="tokens.length" class="mcp-tokens-scroll">
|
||||
<table class="mcp-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>备注</th>
|
||||
<th>令牌</th>
|
||||
<th>创建时间</th>
|
||||
<th>调用次数</th>
|
||||
<th>最后使用</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="t in tokens" :key="t.token">
|
||||
<td>{{ t.note || '—' }}</td>
|
||||
<td class="mcp-tok-cell">
|
||||
<code class="mcp-code">{{ t.token }}</code>
|
||||
<c-button size="small" @click="copyText(t.token, t.token)">
|
||||
{{ copiedKey === t.token ? '✓' : '复制' }}
|
||||
</c-button>
|
||||
</td>
|
||||
<td>{{ fmtTime(t.created) }}</td>
|
||||
<td>{{ t.calls ?? 0 }}</td>
|
||||
<td>{{ fmtTime(t.last_used) }}</td>
|
||||
<td>
|
||||
<c-button size="small" @click="delToken(t)">
|
||||
<Trash :size="13" /> 删除
|
||||
</c-button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<n-empty v-else description="还没有令牌,点击上方「生成令牌」创建" class="mcp-empty" />
|
||||
</template>
|
||||
<n-alert v-else type="info" :show-icon="true">
|
||||
未授权:购买卡密并激活后可在此生成令牌。
|
||||
<c-button size="small" type="primary" to="/buy" style="margin-left: 8px">
|
||||
💳 前往购买卡密
|
||||
</c-button>
|
||||
</n-alert>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 客户端配置 ===== -->
|
||||
<n-card class="mcp-card" title="③ AI 客户端配置(令牌已自动带好,直接复制保存)" :bordered="true">
|
||||
<n-alert type="info" :show-icon="true" class="mcp-ai-help">
|
||||
💡 <b>不想手动改配置?让 AI 帮你接入</b>:把本页的配置复制发给你正在使用的 AI 助手(Hermes / Claude / 豆包 / Cherry Studio 内的 AI 等),对它说一句
|
||||
<b>「帮我把这个 MCP 接入客户端」</b>,AI 会自动替你改好配置、保存并重启生效。
|
||||
</n-alert>
|
||||
<n-tabs type="line" animated>
|
||||
<n-tab-pane name="hermes" tab="Hermes(config.yaml)">
|
||||
<div class="mcp-codeblock">
|
||||
<pre>{{ hermesCfg }}</pre>
|
||||
<c-button size="small" class="mcp-copy-btn" @click="copyText(hermesCfg, 'hermes')">
|
||||
{{ copiedKey === 'hermes' ? '✓ 已复制' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<p class="mcp-note">
|
||||
保存后重启 Hermes 网关(<code>hermes gateway restart</code>),即可对 AI 说
|
||||
“把这张图识别出文字 / 翻译这段话 / 生成一张图” 等,AI 会自动调用。
|
||||
</p>
|
||||
</n-tab-pane>
|
||||
<n-tab-pane name="json" tab="通用(Claude / Cherry Studio 等)">
|
||||
<div class="mcp-codeblock">
|
||||
<pre>{{ jsonCfg }}</pre>
|
||||
<c-button size="small" class="mcp-copy-btn" @click="copyText(jsonCfg, 'json')">
|
||||
{{ copiedKey === 'json' ? '✓ 已复制' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<p class="mcp-note">
|
||||
Claude Desktop 若不支持 <code>type: http</code>,可用 mcp-remote 桥接:
|
||||
<code>npx mcp-remote {{ endpoint }} --header Authorization:"Bearer 你的令牌"</code>
|
||||
</p>
|
||||
</n-tab-pane>
|
||||
<n-tab-pane name="curl" tab="curl 自测">
|
||||
<div class="mcp-codeblock">
|
||||
<pre>{{ curlCfg }}</pre>
|
||||
<c-button size="small" class="mcp-copy-btn" @click="copyText(curlCfg, 'curl')">
|
||||
{{ copiedKey === 'curl' ? '✓ 已复制' : '复制' }}
|
||||
</c-button>
|
||||
</div>
|
||||
<p class="mcp-note">返回 <code>tools/list</code> 的 13 个工具即接入成功;不带令牌调用 tools/call 会返回 401。</p>
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 接入后怎么使用 ===== -->
|
||||
<n-card class="mcp-card" title="④ 接入后怎么使用" :bordered="true">
|
||||
<div class="mcp-steps">
|
||||
<div class="mcp-step">
|
||||
<b>第 1 步</b>:把上面的配置复制进 AI 客户端并<b>保存</b>——已授权设备的配置里<b>已自动带上真实令牌</b>,无需手工替换(显示 <code>mcpt_你的令牌</code> 占位说明本机未授权或令牌已删,先看 ②)。
|
||||
</div>
|
||||
<div class="mcp-step">
|
||||
<b>第 2 步</b>:<b>重启 / 重连</b>该客户端(Hermes 执行 <code>hermes gateway restart</code>;聊天类客户端重新打开会话)。
|
||||
</div>
|
||||
<div class="mcp-step">
|
||||
<b>第 3 步</b>:直接用<b>自然语言</b>下达任务,AI 会自己选工具、填参数、把结果带回来——你不需要记任何工具名。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="mcp-sub">接入成功自检(任选其一)</h4>
|
||||
<ul class="mcp-notes">
|
||||
<li>对 AI 说:<b>「列出你能调用的工具」</b>——应看到 13 个本站工具(translate_text、ocr、tts…)。</li>
|
||||
<li>客户端工具列表 / MCP 面板里应出现本站服务器 <code>it-tools-pro</code> 与 13 个工具。</li>
|
||||
<li>curl 里执行 ③ 的 <code>tools/list</code> 请求,返回 <code>"tools"</code> 数组含 13 项即链路正常。</li>
|
||||
</ul>
|
||||
|
||||
<h4 class="mcp-sub">典型用法(你只管这样对 AI 说)</h4>
|
||||
<div class="mcp-tokens-scroll">
|
||||
<table class="mcp-table">
|
||||
<thead>
|
||||
<tr><th>场景</th><th>你对 AI 说</th><th>AI 实际调用</th><th>你得到</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="u in usageExamples" :key="u.scene">
|
||||
<td>{{ u.scene }}</td>
|
||||
<td class="mcp-say">「{{ u.say }}」</td>
|
||||
<td><code class="mcp-code">{{ u.tool }}</code></td>
|
||||
<td>{{ u.got }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h4 class="mcp-sub">使用要点</h4>
|
||||
<ul class="mcp-notes">
|
||||
<li><b>文件怎么给</b>:直接在话里写服务器可读的绝对路径(如 <code>/home/pics/图.png</code>);与站点同机的 AI 助手传本机路径即可,无需先上传。</li>
|
||||
<li><b>结果怎么拿</b>:文本类结果 AI 会直接念给你;文件类结果返回 <code>url</code> 下载链接(带同款令牌访问),可让 AI 转发给你。</li>
|
||||
<li><b>一次说清</b>:目标语言、尺寸、格式等要求直接写在话里(如「翻译成英文」「放大两倍」「转成 Word」),AI 会作为参数传给工具。</li>
|
||||
<li><b>随时可换</b>:删掉旧令牌重新生成,改一下客户端配置里的 Bearer 值即可,不影响其它客户端。</li>
|
||||
</ul>
|
||||
|
||||
<h4 class="mcp-sub">排错速查</h4>
|
||||
<div class="mcp-trouble">
|
||||
<div v-for="t in mcpTroubles" :key="t.code" class="mcp-trouble-row">
|
||||
<code class="mcp-code">{{ t.code }}</code>
|
||||
<span>{{ t.fix }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 工具清单 ===== -->
|
||||
<n-card class="mcp-card" title="⑤ 可调用的 13 个工具" :bordered="true">
|
||||
<div class="mcp-tools-grid">
|
||||
<div v-for="t in mcpTools" :key="t.name" class="mcp-tool-item">
|
||||
<code class="mcp-code">{{ t.name }}</code>
|
||||
<span class="mcp-tool-desc">{{ t.desc }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</n-card>
|
||||
|
||||
<!-- ===== 注意事项 ===== -->
|
||||
<n-card class="mcp-card" title="⑥ 注意事项" :bordered="true">
|
||||
<ul class="mcp-notes">
|
||||
<li>令牌即授权凭证:<b>不要公开分享</b>;泄露后在上方删除该令牌,重新生成即可作废旧令牌。</li>
|
||||
<li>卡密过期或授权被撤销后,令牌<b>立即失效</b>(调用返回 401),续费激活后自动恢复。</li>
|
||||
<li>每次调用都会记录在管理后台「MCP 调用」中(令牌尾号 / 工具 / 耗时 / 结果),便于对账与排错。</li>
|
||||
<li>文件类工具(ocr / tts / 视频等)请传<b>服务器可读的文件路径</b>;与站点同机的 AI 助手直接传本机绝对路径即可,结果中的 <code>url</code> 为下载地址(需带同款令牌访问)。</li>
|
||||
<li>生图、文档翻译等为慢操作(可达数分钟),客户端 timeout 建议 ≥ 600 秒。</li>
|
||||
</ul>
|
||||
</n-card>
|
||||
</n-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.mcp-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
.mcp-card {
|
||||
border-radius: 10px;
|
||||
}
|
||||
.mcp-h {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.mcp-buy {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.mcp-buy-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.mcp-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 6px 0;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.mcp-label {
|
||||
min-width: 64px;
|
||||
color: var(--n-text-color-3, #888);
|
||||
font-size: 13px;
|
||||
}
|
||||
.mcp-code {
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
border-radius: 6px;
|
||||
padding: 2px 8px;
|
||||
font-family: var(--n-font-family-mono, monospace);
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.mcp-hint {
|
||||
color: var(--n-text-color-3, #999);
|
||||
font-size: 12px;
|
||||
}
|
||||
.mcp-gen-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.mcp-tokens-scroll {
|
||||
overflow-x: auto;
|
||||
}
|
||||
.mcp-table {
|
||||
width: 100%;
|
||||
min-width: 760px;
|
||||
border-collapse: collapse;
|
||||
font-size: 13px;
|
||||
}
|
||||
.mcp-table th,
|
||||
.mcp-table td {
|
||||
border-bottom: 1px solid rgba(128, 128, 128, 0.18);
|
||||
padding: 8px 10px;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.mcp-tok-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.mcp-empty {
|
||||
padding: 24px 0;
|
||||
}
|
||||
.mcp-codeblock {
|
||||
position: relative;
|
||||
background: rgba(128, 128, 128, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.mcp-codeblock pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.mcp-copy-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
}
|
||||
.mcp-note {
|
||||
margin: 10px 0 0;
|
||||
font-size: 13px;
|
||||
color: var(--n-text-color-2, #666);
|
||||
}
|
||||
.mcp-tools-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.mcp-tool-item {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.16);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.mcp-tool-desc {
|
||||
font-size: 12px;
|
||||
color: var(--n-text-color-2, #666);
|
||||
}
|
||||
.mcp-auth-ok {
|
||||
padding: 8px 14px;
|
||||
margin-bottom: 12px;
|
||||
border-radius: 8px;
|
||||
background: rgba(16, 186, 128, 0.12);
|
||||
border: 1px solid rgba(16, 186, 128, 0.35);
|
||||
color: #059669;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.mcp-primary {
|
||||
margin-bottom: 14px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
border: 1px dashed rgba(37, 99, 235, 0.5);
|
||||
background: rgba(37, 99, 235, 0.05);
|
||||
}
|
||||
.mcp-primary-label {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.mcp-primary-body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.mcp-primary-token {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 13.5px;
|
||||
word-break: break-all;
|
||||
user-select: all;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
flex: 1;
|
||||
min-width: 260px;
|
||||
}
|
||||
.mcp-steps {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.mcp-step {
|
||||
padding: 8px 12px;
|
||||
background: rgba(128, 128, 128, 0.07);
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.mcp-sub {
|
||||
margin: 16px 0 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.mcp-say {
|
||||
color: #2563eb;
|
||||
white-space: normal;
|
||||
min-width: 260px;
|
||||
}
|
||||
.mcp-trouble {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.mcp-trouble-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.mcp-trouble-row .mcp-code {
|
||||
flex: none;
|
||||
}
|
||||
.mcp-notes {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Plug } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.mcp-connect.title'),
|
||||
path: '/mcp-connect',
|
||||
description: translate('tools.mcp-connect.description'),
|
||||
keywords: ['mcp', 'ai', 'llm', 'claude', 'hermes', 'agent', 'api', 'token', '接入', '智能体', '大模型'],
|
||||
component: () => import('./McpConnect.vue'),
|
||||
icon: Plug,
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { World } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.my-ip.title'),
|
||||
path: '/my-ip',
|
||||
description: translate('tools.my-ip.description'),
|
||||
keywords: ['ip', 'ipv4', 'ipv6', '本机', '公网', '内网', '归属地', '网速', '测速', '延迟', 'ping', 'speed', 'address', 'location'],
|
||||
component: () => import('./my-ip.vue'),
|
||||
icon: World,
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,11 @@
|
||||
import { Template } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'AI 海报',
|
||||
path: '/poster-maker',
|
||||
description: 'AI 海报生成:热门海报模板任选,改文字、换图片、AI 配图,一键导出 PNG',
|
||||
keywords: ['poster', '海报', '模板', '宣传图', '朋友圈', '小红书', '电商', '海报生成', 'ai海报'],
|
||||
component: () => import('./poster.vue'),
|
||||
icon: Template,
|
||||
});
|
||||
@@ -0,0 +1,754 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
|
||||
import { getMachineId, licenseHeaders } from '@/tools/license/license';
|
||||
import { authHdr } from '@/tools/img-hist/img-hist';
|
||||
import {
|
||||
POSTER_TEMPLATES, POSTER_CATS, BG_PRESETS, POSTER_W, POSTER_H,
|
||||
type PosterTemplate, type PosterBg, type PosterImageLayer,
|
||||
} from './templates';
|
||||
|
||||
type L = any; // 图层运行时对象(text / image / shape 联合,编辑期动态增删)
|
||||
|
||||
const FONT_STACK = '"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Noto Sans CJK SC",sans-serif';
|
||||
const MINI_W = 116;
|
||||
|
||||
const cat = ref('hot');
|
||||
const cur = ref<PosterTemplate | null>(null);
|
||||
const tplId = ref('');
|
||||
const layers = ref<L[]>([]);
|
||||
const bg = ref<PosterBg>({});
|
||||
const selId = ref('');
|
||||
const scale = ref(0.5);
|
||||
const stageEl = ref<HTMLElement | null>(null);
|
||||
const pmRoot = ref<HTMLElement | null>(null);
|
||||
const pmH = ref(0); // 视口自适应高度:根不滚动,滚动只发生在内部区域
|
||||
const fileEl = ref<HTMLInputElement | null>(null);
|
||||
const pmError = ref('');
|
||||
const models = ref<{ id: string; name?: string }[]>([]);
|
||||
const model = ref('');
|
||||
const genBusy = ref(false);
|
||||
const bgPrompt = ref('');
|
||||
const exporting = ref(false);
|
||||
// ---------- 生成历史(服务端落盘,右侧 50×50 缩略图竖排) ----------
|
||||
const hist = ref<{ id: string; img_url: string; prompt?: string; kind?: string; at?: number }[]>([]);
|
||||
const histBusy = ref(false);
|
||||
const histView = ref(''); // 大图查看(点击缩略图打开,点空白关闭)
|
||||
async function loadHist() {
|
||||
histBusy.value = true;
|
||||
try {
|
||||
const res = await fetch(`/relay/ai/img-history?machine=${encodeURIComponent(getMachineId())}&kind=poster`, {
|
||||
headers: { ...licenseHeaders('poster-maker'), ...authHdr() },
|
||||
});
|
||||
const j = await res.json().catch(() => ({}) as any);
|
||||
// 铁规则:所有功能历史最多显示 100 条
|
||||
if (res.ok && j.code === 200 && Array.isArray(j.data)) hist.value = j.data.slice(0, 100);
|
||||
} catch { /* 历史拉取失败静默,不影响编辑 */ } finally { histBusy.value = false; }
|
||||
}
|
||||
let uid = 0;
|
||||
let ro: ResizeObserver | null = null;
|
||||
let scRO: ResizeObserver | null = null;
|
||||
|
||||
const filtered = computed(() =>
|
||||
cat.value === 'hot' ? POSTER_TEMPLATES : POSTER_TEMPLATES.filter((t) => t.category === cat.value));
|
||||
const sel = computed(() => layers.value.find((l) => l.id === selId.value) || null);
|
||||
const selName = computed(() => {
|
||||
const l = sel.value; if (!l) return '';
|
||||
if (l.type === 'text') return (l.text || '文字').slice(0, 10);
|
||||
if (l.type === 'image') return '图片';
|
||||
return l.shape === 'ellipse' ? '圆形色块' : '矩形色块';
|
||||
});
|
||||
|
||||
// ---------- 换模板 ----------
|
||||
function selectTemplate(t: PosterTemplate) {
|
||||
tplId.value = t.id;
|
||||
cur.value = t;
|
||||
bg.value = JSON.parse(JSON.stringify(t.bg));
|
||||
layers.value = JSON.parse(JSON.stringify(t.layers)).map((l: L) => ({ ...l, id: 'l' + ++uid }));
|
||||
selId.value = '';
|
||||
pmError.value = '';
|
||||
}
|
||||
function resetTpl() {
|
||||
const t = POSTER_TEMPLATES.find((x) => x.id === tplId.value);
|
||||
if (t) selectTemplate(t);
|
||||
}
|
||||
|
||||
// ---------- 文字排版(预览与导出共用,保证换行一致) ----------
|
||||
const mc = document.createElement('canvas');
|
||||
const mctx = mc.getContext('2d')!;
|
||||
const wrapCache = new Map<string, string[]>();
|
||||
const CLOSE_PUNCT = ',。、!?:;)】」』,.!?;:)';
|
||||
|
||||
function fontStr(l: L) {
|
||||
return `${l.italic ? 'italic ' : ''}${l.weight ?? 700} ${l.size}px ${FONT_STACK}`;
|
||||
}
|
||||
function linesOf(l: L): string[] {
|
||||
const key = `${l.text}|${l.w}|${fontStr(l)}`;
|
||||
const hit = wrapCache.get(key);
|
||||
if (hit) return hit;
|
||||
mctx.font = fontStr(l);
|
||||
const out: string[] = [];
|
||||
for (const para of String(l.text ?? '').split('\n')) {
|
||||
if (!para) { out.push(''); continue; }
|
||||
let line = '';
|
||||
for (const ch of para) {
|
||||
const test = line + ch;
|
||||
if (line && mctx.measureText(test).width > l.w && !CLOSE_PUNCT.includes(ch)) {
|
||||
out.push(line); line = ch;
|
||||
} else line = test;
|
||||
}
|
||||
out.push(line);
|
||||
}
|
||||
const res = out.length ? out : [''];
|
||||
wrapCache.set(key, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
// ---------- 样式 ----------
|
||||
function bgCss(b: PosterBg): string {
|
||||
if (b.color) return b.color;
|
||||
if (b.stops?.length) {
|
||||
const stops = b.stops.map((s) => `${s.c} ${Math.round(s.p * 100)}%`).join(', ');
|
||||
return `linear-gradient(${b.angle ?? 135}deg, ${stops})`;
|
||||
}
|
||||
return '#ffffff';
|
||||
}
|
||||
function boxStyle(l: L) {
|
||||
return {
|
||||
left: l.x + 'px', top: l.y + 'px', width: l.w + 'px',
|
||||
height: l.type === 'text' ? 'auto' : l.h + 'px',
|
||||
transform: l.rot ? `rotate(${l.rot}deg)` : undefined,
|
||||
};
|
||||
}
|
||||
function fontStyle(l: L) {
|
||||
return {
|
||||
fontFamily: FONT_STACK,
|
||||
fontSize: l.size + 'px',
|
||||
fontWeight: String(l.weight ?? 700),
|
||||
color: l.color,
|
||||
textAlign: l.align ?? 'center',
|
||||
lineHeight: l.size * (l.lineHeight ?? 1.25) + 'px',
|
||||
fontStyle: l.italic ? 'italic' : 'normal',
|
||||
textShadow: l.shadow ? `0 ${l.shadow.y}px ${l.shadow.blur}px ${l.shadow.color}` : 'none',
|
||||
};
|
||||
}
|
||||
function shapeStyle(l: L) {
|
||||
return {
|
||||
background: l.fill,
|
||||
borderRadius: l.shape === 'ellipse' ? '50%' : (l.radius ?? 0) + 'px',
|
||||
opacity: l.opacity ?? 1,
|
||||
};
|
||||
}
|
||||
function miniBoxStyle(l: L) { return boxStyle(l); }
|
||||
const tplLayers = (t: PosterTemplate): L[] => t.layers as any;
|
||||
function onFill(e: Event) { const l = sel.value; if (l) l.fill = (e.target as HTMLInputElement).value; }
|
||||
function onRot(e: Event) { const l = sel.value; if (l) l.rot = Number((e.target as HTMLInputElement).value); }
|
||||
|
||||
// ---------- 选中 / 拖动 ----------
|
||||
function onDown(e: PointerEvent, l: L) {
|
||||
selId.value = l.id;
|
||||
drag = { l, sx: e.clientX, sy: e.clientY, lx: l.x, ly: l.y };
|
||||
window.addEventListener('pointermove', onMove);
|
||||
window.addEventListener('pointerup', onUp);
|
||||
e.preventDefault();
|
||||
}
|
||||
let drag: { l: L; sx: number; sy: number; lx: number; ly: number } | null = null;
|
||||
function onMove(e: PointerEvent) {
|
||||
if (!drag) return;
|
||||
const s = scale.value || 1;
|
||||
const l = drag.l;
|
||||
let nx = drag.lx + (e.clientX - drag.sx) / s;
|
||||
let ny = drag.ly + (e.clientY - drag.sy) / s;
|
||||
const maxX = POSTER_W - l.w;
|
||||
const maxY = POSTER_H - (l.type === 'text' ? l.size : l.h);
|
||||
l.x = Math.min(Math.max(nx, 0), Math.max(maxX, 0));
|
||||
l.y = Math.min(Math.max(ny, 0), Math.max(maxY, 0));
|
||||
}
|
||||
function onUp() {
|
||||
drag = null;
|
||||
window.removeEventListener('pointermove', onMove);
|
||||
window.removeEventListener('pointerup', onUp);
|
||||
}
|
||||
|
||||
// ---------- 图层增删 ----------
|
||||
function addText() {
|
||||
const l = { id: 'l' + ++uid, type: 'text', text: '点击右侧修改文字', x: 140, y: 660, w: 800, size: 80, color: '#111111', weight: 700, align: 'center', lineHeight: 1.25 };
|
||||
layers.value.push(l); selId.value = l.id;
|
||||
}
|
||||
function addImage() {
|
||||
const l = { id: 'l' + ++uid, type: 'image', x: 190, y: 500, w: 700, h: 520, radius: 24, src: '', prompt: '' };
|
||||
layers.value.push(l); selId.value = l.id;
|
||||
}
|
||||
function delSel() {
|
||||
const i = layers.value.findIndex((l) => l.id === selId.value);
|
||||
if (i >= 0) layers.value.splice(i, 1);
|
||||
selId.value = '';
|
||||
}
|
||||
function moveLayer(dz: number) {
|
||||
const i = layers.value.findIndex((l) => l.id === selId.value);
|
||||
const j = i + dz;
|
||||
if (i < 0 || j < 0 || j >= layers.value.length) return;
|
||||
const [l] = layers.value.splice(i, 1);
|
||||
layers.value.splice(j, 0, l);
|
||||
}
|
||||
function pickFile() { fileEl.value?.click(); }
|
||||
function onFile(e: Event) {
|
||||
const f = (e.target as HTMLInputElement).files?.[0];
|
||||
const l = sel.value;
|
||||
if (f && l && l.type === 'image') l.src = URL.createObjectURL(f);
|
||||
(e.target as HTMLInputElement).value = '';
|
||||
}
|
||||
function clearImg() { const l = sel.value; if (l && l.type === 'image') l.src = ''; }
|
||||
|
||||
// ---------- AI 生图(复用 relay /ai/gen-image + 每日免费额度) ----------
|
||||
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 genFor(l: PosterImageLayer) {
|
||||
const prompt = String(l.prompt ?? '').trim();
|
||||
if (!prompt) { pmError.value = '请先填写图片描述'; return; }
|
||||
genBusy.value = true; pmError.value = '';
|
||||
try {
|
||||
// 上游生图模型只接受固定尺寸档位(如 dall-e-3 仅 1024²/1792×1024/1024×1792),
|
||||
// 按图框宽高比映射到三档,出图后由 CSS object-fit:cover 裁切填充
|
||||
const ar = l.w / Math.max(1, l.h);
|
||||
let width = 1024, height = 1024;
|
||||
if (ar > 1.25) { width = 1792; height = 1024; }
|
||||
else if (ar < 0.8) { width = 1024; height = 1792; }
|
||||
const res = await fetch('/relay/ai/gen-image', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders('poster-maker'), ...authHdr() },
|
||||
body: JSON.stringify({ machine: getMachineId(), prompt, model: model.value, width, height, kind: 'poster' }),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}) as any);
|
||||
if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`);
|
||||
const url = j.data?.img_url || (j.data?.b64 ? b64DataUrl(j.data.b64) : '') || j.data?.url || '';
|
||||
if (!url) throw new Error('未返回图片');
|
||||
l.src = url;
|
||||
loadHist(); // 服务端已落盘,刷新右侧历史
|
||||
} catch (err: any) {
|
||||
pmError.value = 'AI 生成失败:' + (err?.message || String(err));
|
||||
} finally {
|
||||
genBusy.value = false;
|
||||
}
|
||||
}
|
||||
async function genBg() {
|
||||
const l = {
|
||||
id: 'l' + ++uid, type: 'image', x: 0, y: 0, w: POSTER_W, h: POSTER_H, radius: 0,
|
||||
src: '', prompt: bgPrompt.value.trim() || '高级感海报背景图,留白构图,杂志风',
|
||||
};
|
||||
layers.value.unshift(l);
|
||||
selId.value = '';
|
||||
await genFor(l);
|
||||
if (!l.src) layers.value = layers.value.filter((x) => x !== l);
|
||||
}
|
||||
|
||||
// ---------- 缩放 ----------
|
||||
// 宽高双向适配:画布始终完整落在舞台内,舞台自身不出滚动条
|
||||
function fit() {
|
||||
measure(); // 舞台尺寸一变就顺带复测根高度(仅值变化才写,稳定后自收敛)
|
||||
const el = stageEl.value;
|
||||
const w = Math.max((el?.clientWidth || 600) - 20, 120);
|
||||
const h = Math.max((el?.clientHeight || 760) - 20, 160);
|
||||
scale.value = Math.min(Math.max(Math.min(w / POSTER_W, h / POSTER_H), 0.1), 0.85);
|
||||
}
|
||||
|
||||
// 测量所在滚动容器:根高度 = 容器可视高 - 上方占用,页面级永不出现滚动条
|
||||
function measure() {
|
||||
const el = pmRoot.value;
|
||||
if (!el) return;
|
||||
// 必须取最内层滚动容器:外层是套壳,高度口径不同,用外层算出来的值会错
|
||||
const sc = el.closest('.n-layout-scroll-container') as HTMLElement | null;
|
||||
if (!sc) return;
|
||||
const above = el.getBoundingClientRect().top - sc.getBoundingClientRect().top + sc.scrollTop;
|
||||
const h = Math.floor(sc.clientHeight - above - 18);
|
||||
if (h >= 160 && h !== pmH.value) pmH.value = h;
|
||||
}
|
||||
|
||||
// ---------- 导出 PNG ----------
|
||||
function rrPath(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {
|
||||
r = Math.min(r, w / 2, h / 2);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + r, y);
|
||||
ctx.lineTo(x + w - r, y);
|
||||
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
|
||||
ctx.lineTo(x + w, y + h - r);
|
||||
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
|
||||
ctx.lineTo(x + r, y + h);
|
||||
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
|
||||
ctx.lineTo(x, y + r);
|
||||
ctx.quadraticCurveTo(x, y, x + r, y);
|
||||
ctx.closePath();
|
||||
}
|
||||
function drawBg(ctx: CanvasRenderingContext2D, b: PosterBg) {
|
||||
if (b.color) { ctx.fillStyle = b.color; ctx.fillRect(0, 0, POSTER_W, POSTER_H); return; }
|
||||
if (!b.stops?.length) { ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, POSTER_W, POSTER_H); return; }
|
||||
const a = (b.angle ?? 135) * Math.PI / 180;
|
||||
const len = Math.abs(POSTER_W * Math.sin(a)) + Math.abs(POSTER_H * Math.cos(a));
|
||||
const cx = POSTER_W / 2, cy = POSTER_H / 2;
|
||||
const dx = Math.sin(a), dy = -Math.cos(a);
|
||||
const g = ctx.createLinearGradient(cx - dx * len / 2, cy - dy * len / 2, cx + dx * len / 2, cy + dy * len / 2);
|
||||
for (const s of b.stops) g.addColorStop(Math.min(Math.max(s.p, 0), 1), s.c);
|
||||
ctx.fillStyle = g;
|
||||
ctx.fillRect(0, 0, POSTER_W, POSTER_H);
|
||||
}
|
||||
function loadImg(src: string): Promise<HTMLImageElement | null> {
|
||||
return new Promise((res) => {
|
||||
const i = new Image();
|
||||
i.onload = () => res(i);
|
||||
i.onerror = () => res(null);
|
||||
i.src = src;
|
||||
});
|
||||
}
|
||||
// 绕 (cx, cy) 旋转画布坐标系:预览走 CSS transform、导出走 canvas,中心一致才不跑位
|
||||
function rotAround(ctx: CanvasRenderingContext2D, cx: number, cy: number, deg: number) {
|
||||
ctx.translate(cx, cy);
|
||||
ctx.rotate((deg * Math.PI) / 180);
|
||||
ctx.translate(-cx, -cy);
|
||||
}
|
||||
async function drawLayer(ctx: CanvasRenderingContext2D, l: L) {
|
||||
if (l.type === 'shape') {
|
||||
ctx.save();
|
||||
if (l.rot) rotAround(ctx, l.x + l.w / 2, l.y + l.h / 2, l.rot);
|
||||
ctx.globalAlpha = l.opacity ?? 1;
|
||||
ctx.fillStyle = l.fill;
|
||||
if (l.shape === 'ellipse') {
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(l.x + l.w / 2, l.y + l.h / 2, l.w / 2, l.h / 2, 0, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
} else {
|
||||
rrPath(ctx, l.x, l.y, l.w, l.h, l.radius ?? 0);
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.restore();
|
||||
return;
|
||||
}
|
||||
if (l.type === 'image') {
|
||||
ctx.save();
|
||||
if (l.rot) rotAround(ctx, l.x + l.w / 2, l.y + l.h / 2, l.rot);
|
||||
rrPath(ctx, l.x, l.y, l.w, l.h, l.radius ?? 0);
|
||||
ctx.clip();
|
||||
const img = l.src ? await loadImg(l.src) : null;
|
||||
if (img && img.naturalWidth) {
|
||||
const s = Math.max(l.w / img.naturalWidth, l.h / img.naturalHeight);
|
||||
const dw = img.naturalWidth * s, dh = img.naturalHeight * s;
|
||||
ctx.drawImage(img, l.x + (l.w - dw) / 2, l.y + (l.h - dh) / 2, dw, dh);
|
||||
} else {
|
||||
ctx.fillStyle = '#ececec';
|
||||
ctx.fillRect(l.x, l.y, l.w, l.h);
|
||||
ctx.fillStyle = '#999999';
|
||||
ctx.font = `400 ${Math.max(24, Math.round(l.h * 0.06))}px ${FONT_STACK}`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText('图片位', l.x + l.w / 2, l.y + l.h / 2);
|
||||
ctx.textBaseline = 'alphabetic';
|
||||
}
|
||||
ctx.restore();
|
||||
return;
|
||||
}
|
||||
// 文字
|
||||
ctx.font = fontStr(l);
|
||||
ctx.fillStyle = l.color;
|
||||
const lh = l.size * (l.lineHeight ?? 1.25);
|
||||
const m = ctx.measureText('字');
|
||||
const asc = (m as any).fontBoundingBoxAscent ?? l.size * 0.8;
|
||||
const desc = (m as any).fontBoundingBoxDescent ?? l.size * 0.2;
|
||||
const lines = linesOf(l);
|
||||
ctx.save();
|
||||
if (l.rot) rotAround(ctx, l.x + l.w / 2, l.y + (lines.length * lh) / 2, l.rot);
|
||||
ctx.textAlign = l.align === 'center' ? 'center' : l.align === 'right' ? 'right' : 'left';
|
||||
const tx = l.align === 'center' ? l.x + l.w / 2 : l.align === 'right' ? l.x + l.w : l.x;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const y = l.y + i * lh + (lh - (asc + desc)) / 2 + asc;
|
||||
if (l.shadow) {
|
||||
ctx.shadowColor = l.shadow.color; ctx.shadowBlur = l.shadow.blur; ctx.shadowOffsetY = l.shadow.y;
|
||||
} else {
|
||||
ctx.shadowColor = 'transparent'; ctx.shadowBlur = 0; ctx.shadowOffsetY = 0;
|
||||
}
|
||||
ctx.fillText(lines[i], tx, y);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
async function exportPng() {
|
||||
exporting.value = true; pmError.value = '';
|
||||
try {
|
||||
const c = document.createElement('canvas');
|
||||
c.width = POSTER_W; c.height = POSTER_H;
|
||||
const ctx = c.getContext('2d')!;
|
||||
drawBg(ctx, bg.value);
|
||||
for (const l of layers.value) await drawLayer(ctx, l);
|
||||
const blob: Blob | null = await new Promise((res) => c.toBlob(res, 'image/png'));
|
||||
if (!blob) throw new Error('画布导出失败');
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `${cur.value?.name || '海报'}.png`;
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(a.href), 8000);
|
||||
// 同步保存到服务器后台存储目录(后台「存储设置」的 gen_images),失败不阻断下载
|
||||
try {
|
||||
const b64 = await new Promise<string>((res, rej) => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => res(String(fr.result || ''));
|
||||
fr.onerror = () => rej(new Error('读取失败'));
|
||||
fr.readAsDataURL(blob);
|
||||
});
|
||||
await fetch('/relay/ai/img-save', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders('poster-maker'), ...authHdr() },
|
||||
body: JSON.stringify({ machine: getMachineId(), b64, kind: 'poster', model: 'AI海报', prompt: cur.value?.name || '海报导出' }),
|
||||
});
|
||||
loadHist();
|
||||
} catch { /* 保存失败不影响本地下载 */ }
|
||||
} catch (err: any) {
|
||||
pmError.value = '导出失败:' + (err?.message || String(err));
|
||||
} finally {
|
||||
exporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
selectTemplate(POSTER_TEMPLATES[0]);
|
||||
loadHist();
|
||||
measure();
|
||||
fit();
|
||||
ro = new ResizeObserver(fit);
|
||||
if (stageEl.value) ro.observe(stageEl.value);
|
||||
const sc = pmRoot.value?.closest('.n-layout-scroll-container');
|
||||
if (sc) { scRO = new ResizeObserver(measure); scRO.observe(sc); }
|
||||
window.addEventListener('resize', measure);
|
||||
window.addEventListener('focus', measure);
|
||||
document.addEventListener('visibilitychange', measure);
|
||||
// 头部字体/公告条加载完高度会微变,延迟复测两次
|
||||
setTimeout(measure, 400);
|
||||
setTimeout(measure, 1500);
|
||||
try {
|
||||
const res = await fetch('/relay/ai/image-models', { headers: licenseHeaders('poster-maker') });
|
||||
const j = await res.json().catch(() => ({}) as any);
|
||||
if (res.ok && j.code === 200 && Array.isArray(j.data)) {
|
||||
models.value = j.data;
|
||||
model.value = j.data[0]?.id ?? '';
|
||||
}
|
||||
} catch { /* 模型列表拉取失败时用默认空值 */ }
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
ro?.disconnect();
|
||||
scRO?.disconnect();
|
||||
window.removeEventListener('resize', measure);
|
||||
window.removeEventListener('focus', measure);
|
||||
document.removeEventListener('visibilitychange', measure);
|
||||
onUp();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="pmRoot" class="pm-root" :style="pmH ? { height: pmH + 'px' } : undefined">
|
||||
<div class="pm-top">
|
||||
<div class="pm-cats">
|
||||
<button
|
||||
v-for="c in POSTER_CATS" :key="c.id"
|
||||
class="pm-cat" :class="{ on: cat === c.id }"
|
||||
@click="cat = c.id"
|
||||
>{{ c.name }}</button>
|
||||
</div>
|
||||
<div class="pm-actions">
|
||||
<button class="pm-btn" @click="addText">+ 文字</button>
|
||||
<button class="pm-btn" @click="addImage">+ 图片框</button>
|
||||
<button class="pm-btn" @click="resetTpl">重置模板</button>
|
||||
<button class="pm-btn primary" :disabled="exporting" @click="exportPng">
|
||||
{{ exporting ? '导出中…' : '⬇ 下载 PNG' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="pmError" class="pm-error">{{ pmError }}</div>
|
||||
|
||||
<div class="pm-main">
|
||||
<!-- 左:模板库 -->
|
||||
<aside class="pm-tpls">
|
||||
<div class="pm-sec-title">海报模板({{ filtered.length }})</div>
|
||||
<div class="pm-tpl-grid">
|
||||
<div
|
||||
v-for="t in filtered" :key="t.id"
|
||||
class="pm-tpl-card" :class="{ on: tplId === t.id }"
|
||||
@click="selectTemplate(t)"
|
||||
>
|
||||
<div class="pm-mini" :style="{ width: MINI_W + 'px', height: Math.round(MINI_W * POSTER_H / POSTER_W) + 'px' }">
|
||||
<div
|
||||
class="pm-mini-in"
|
||||
:style="{ width: POSTER_W + 'px', height: POSTER_H + 'px', transform: `scale(${MINI_W / POSTER_W})`, background: bgCss(t.bg) }"
|
||||
>
|
||||
<template v-for="(l, i) in tplLayers(t)" :key="i">
|
||||
<div v-if="l.type === 'shape'" class="pm-layer" :style="miniBoxStyle(l)">
|
||||
<div class="pm-shape" :style="shapeStyle(l)"></div>
|
||||
</div>
|
||||
<div v-else-if="l.type === 'image'" class="pm-layer" :style="miniBoxStyle(l)">
|
||||
<img v-if="l.src" :src="l.src" class="pm-img" draggable="false" />
|
||||
<div v-else class="pm-img pm-ph">📷</div>
|
||||
</div>
|
||||
<div v-else class="pm-layer" :style="miniBoxStyle(l)">
|
||||
<div :style="fontStyle(l)"><div v-for="(ln, li) in linesOf(l)" :key="li">{{ ln || '\u00a0' }}</div></div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pm-tpl-name">{{ t.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- 中:画布 -->
|
||||
<section class="pm-stage" ref="stageEl" @click.self="selId = ''">
|
||||
<div
|
||||
class="pm-frame"
|
||||
:style="{ width: POSTER_W * scale + 'px', height: POSTER_H * scale + 'px' }"
|
||||
>
|
||||
<div
|
||||
class="pm-canvas"
|
||||
:style="{ width: POSTER_W + 'px', height: POSTER_H + 'px', transform: `scale(${scale})`, background: bgCss(bg) }"
|
||||
@click.self="selId = ''"
|
||||
>
|
||||
<div
|
||||
v-for="l in layers" :key="l.id"
|
||||
class="pm-layer" :class="{ sel: selId === l.id }"
|
||||
:style="boxStyle(l)"
|
||||
@pointerdown.stop="onDown($event, l)"
|
||||
>
|
||||
<div v-if="l.type === 'text'" :style="fontStyle(l)">
|
||||
<div v-for="(ln, i) in linesOf(l)" :key="i">{{ ln || '\u00a0' }}</div>
|
||||
</div>
|
||||
<template v-else-if="l.type === 'image'">
|
||||
<img v-if="l.src" :src="l.src" class="pm-img" draggable="false" />
|
||||
<div v-else class="pm-img pm-ph">📷 点击右侧替换图片</div>
|
||||
</template>
|
||||
<div v-else class="pm-shape" :style="shapeStyle(l)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 右:编辑面板 -->
|
||||
<aside class="pm-panel">
|
||||
<div class="pm-sec">
|
||||
<div class="pm-sec-title">背景</div>
|
||||
<div class="pm-bgs">
|
||||
<button
|
||||
v-for="p in BG_PRESETS" :key="p.name"
|
||||
class="pm-bg-sw" :style="{ background: bgCss(p.bg) }"
|
||||
:title="p.name"
|
||||
@click="bg = JSON.parse(JSON.stringify(p.bg))"
|
||||
></button>
|
||||
</div>
|
||||
<div class="pm-row">
|
||||
<input v-model="bgPrompt" class="pm-input" placeholder="AI 背景描述,如:蓝色科技感海报背景" />
|
||||
</div>
|
||||
<button class="pm-btn wide" :disabled="genBusy" @click="genBg">
|
||||
{{ genBusy ? '生成中…' : '✨ AI 生成背景' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="pm-sec">
|
||||
<div class="pm-sec-title">图层(上层在前)</div>
|
||||
<div class="pm-layers">
|
||||
<div
|
||||
v-for="l in [...layers].reverse()" :key="l.id"
|
||||
class="pm-li" :class="{ on: selId === l.id }"
|
||||
@click="selId = l.id"
|
||||
>
|
||||
<span class="pm-li-ico">{{ l.type === 'text' ? 'T' : l.type === 'image' ? '🖼' : '■' }}</span>
|
||||
<span class="pm-li-name">{{ l.type === 'text' ? (l.text || '文字').slice(0, 10) : l.type === 'image' ? '图片' : (l.shape === 'ellipse' ? '圆形色块' : '矩形色块') }}</span>
|
||||
<span class="pm-li-ops" @click.stop>
|
||||
<button title="上移" @click.stop="selId = l.id; moveLayer(1)">▲</button>
|
||||
<button title="下移" @click.stop="selId = l.id; moveLayer(-1)">▼</button>
|
||||
<button title="删除" @click.stop="selId = l.id; delSel()">✕</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="sel" class="pm-sec">
|
||||
<div class="pm-sec-title">编辑「{{ selName }}」</div>
|
||||
|
||||
<div class="pm-row">
|
||||
<label>旋转</label>
|
||||
<input :value="sel.rot ?? 0" type="range" min="-180" max="180" step="1" @input="onRot" />
|
||||
<span>{{ sel.rot ?? 0 }}°</span>
|
||||
<button class="pm-mini-btn" @click="sel.rot = 0">复位</button>
|
||||
</div>
|
||||
|
||||
<template v-if="sel.type === 'text'">
|
||||
<textarea v-model="sel.text" class="pm-input ta" rows="3" placeholder="文字内容,支持换行"></textarea>
|
||||
<div class="pm-row">
|
||||
<label>字号</label>
|
||||
<input v-model.number="sel.size" type="range" min="20" max="240" />
|
||||
<span>{{ sel.size }}</span>
|
||||
</div>
|
||||
<div class="pm-row">
|
||||
<label>颜色</label>
|
||||
<input v-model="sel.color" type="color" class="pm-color" />
|
||||
<label class="chk"><input v-model="sel.italic" type="checkbox" /> 斜体</label>
|
||||
</div>
|
||||
<div class="pm-row">
|
||||
<label>粗细</label>
|
||||
<select v-model.number="sel.weight" class="pm-sel">
|
||||
<option :value="400">常规</option>
|
||||
<option :value="700">加粗</option>
|
||||
<option :value="900">特粗</option>
|
||||
</select>
|
||||
<label>行高</label>
|
||||
<input v-model.number="sel.lineHeight" type="range" min="1" max="2" step="0.05" />
|
||||
</div>
|
||||
<div class="pm-row">
|
||||
<label>对齐</label>
|
||||
<button class="pm-mini-btn" :class="{ on: sel.align === 'left' }" @click="sel.align = 'left'">左</button>
|
||||
<button class="pm-mini-btn" :class="{ on: sel.align === 'center' }" @click="sel.align = 'center'">中</button>
|
||||
<button class="pm-mini-btn" :class="{ on: sel.align === 'right' }" @click="sel.align = 'right'">右</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="sel.type === 'image'">
|
||||
<textarea v-model="sel.prompt" class="pm-input ta" rows="3" placeholder="AI 生成的图片描述"></textarea>
|
||||
<div class="pm-row" v-if="models.length">
|
||||
<label>模型</label>
|
||||
<select v-model="model" class="pm-sel">
|
||||
<option v-for="m in models" :key="m.id" :value="m.id">{{ m.name || m.id }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="pm-btn wide" :disabled="genBusy" @click="genFor(sel)">
|
||||
{{ genBusy ? '生成中…(约 10-30 秒)' : '✨ AI 生成图片' }}
|
||||
</button>
|
||||
<div class="pm-row gap">
|
||||
<button class="pm-btn" @click="pickFile">📁 上传图片</button>
|
||||
<button class="pm-btn" :disabled="!sel.src" @click="clearImg">清除图片</button>
|
||||
</div>
|
||||
<div class="pm-row">
|
||||
<label>圆角</label>
|
||||
<input v-model.number="sel.radius" type="range" min="0" max="360" />
|
||||
</div>
|
||||
<input ref="fileEl" type="file" accept="image/*" class="pm-hidden" @change="onFile" />
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="pm-row">
|
||||
<label>颜色</label>
|
||||
<input :value="sel.fill" type="color" class="pm-color" @input="onFill" />
|
||||
<label class="chk"><input v-model.number="sel.opacity" type="range" min="0.1" max="1" step="0.05" /> 透明</label>
|
||||
</div>
|
||||
<div class="pm-row" v-if="sel.shape === 'rect'">
|
||||
<label>圆角</label>
|
||||
<input v-model.number="sel.radius" type="range" min="0" :max="Math.min(sel.w, sel.h) / 2" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div v-else class="pm-tip">点击画布中的元素进行编辑,拖动可移动位置;右侧图层可排序、删除。</div>
|
||||
</aside>
|
||||
|
||||
<!-- 最右:生成历史(50×50 缩略图竖排,点击查看大图) -->
|
||||
<aside class="pm-hist">
|
||||
<div class="pm-hist-t">历史<em v-if="hist.length">{{ hist.length }}</em></div>
|
||||
<div v-if="hist.length" class="pm-hist-list">
|
||||
<img
|
||||
v-for="it in hist" :key="it.id"
|
||||
class="pm-hist-thumb"
|
||||
:src="it.img_url"
|
||||
:title="it.prompt || '点击查看大图'"
|
||||
@click="histView = it.img_url"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="pm-hist-empty">还没有<br />生成记录</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<!-- 大图查看 -->
|
||||
<div v-if="histView" class="pm-hist-view" @click="histView = ''">
|
||||
<img :src="histView" alt="生成图片大图" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.pm-root { display: flex; flex-direction: column; gap: 10px; padding: 12px; box-sizing: border-box; height: 100%; overflow: hidden; }
|
||||
.pm-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; flex-shrink: 0; }
|
||||
.pm-cats { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.pm-cat { padding: 5px 12px; border-radius: 14px; border: 1px solid var(--n-border-color, #d9d9d9); background: transparent; color: inherit; cursor: pointer; font-size: 13px; }
|
||||
.pm-cat.on { background: #3b82f6; border-color: #3b82f6; color: #fff; }
|
||||
.pm-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.pm-btn { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--n-border-color, #d9d9d9); background: var(--n-action-color, #fff); color: inherit; cursor: pointer; font-size: 13px; }
|
||||
.pm-btn:hover { border-color: #3b82f6; color: #3b82f6; }
|
||||
.pm-btn.primary { background: #3b82f6; border-color: #3b82f6; color: #fff; }
|
||||
.pm-btn.primary:hover { background: #2563eb; color: #fff; }
|
||||
.pm-btn.wide { width: 100%; margin-top: 6px; }
|
||||
.pm-btn:disabled { opacity: .55; cursor: not-allowed; }
|
||||
.pm-error { flex-shrink: 0; padding: 8px 12px; border-radius: 8px; background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; font-size: 13px; }
|
||||
.pm-main { display: flex; gap: 12px; align-items: stretch; flex: 1; min-height: 0; }
|
||||
|
||||
/* 模板库 */
|
||||
.pm-tpls { width: 292px; flex-shrink: 0; min-height: 0; overflow-y: auto; overflow-x: hidden; }
|
||||
.pm-sec-title { font-size: 13px; font-weight: 700; opacity: .75; margin-bottom: 8px; }
|
||||
.pm-tpl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
|
||||
.pm-tpl-card { border: 2px solid transparent; border-radius: 10px; padding: 6px; cursor: pointer; background: rgba(127,127,127,.07); }
|
||||
.pm-tpl-card:hover { border-color: rgba(59,130,246,.4); }
|
||||
.pm-tpl-card.on { border-color: #3b82f6; background: rgba(59,130,246,.10); }
|
||||
.pm-mini { position: relative; overflow: hidden; border-radius: 6px; margin: 0 auto; }
|
||||
.pm-mini-in { position: relative; transform-origin: 0 0; }
|
||||
.pm-tpl-name { font-size: 12px; text-align: center; margin-top: 4px; }
|
||||
|
||||
/* 画布 */
|
||||
.pm-stage { flex: 1; min-width: 0; min-height: 0; display: flex; justify-content: center; overflow: auto; padding-bottom: 8px; }
|
||||
.pm-frame { position: relative; flex-shrink: 0; box-shadow: 0 6px 24px rgba(0,0,0,.18); border-radius: 4px; overflow: hidden; }
|
||||
.pm-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden; }
|
||||
.pm-layer { position: absolute; box-sizing: border-box; user-select: none; -webkit-user-select: none; touch-action: none; }
|
||||
.pm-layer.sel { outline: 3px dashed #3b82f6; outline-offset: 2px; }
|
||||
.pm-img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
|
||||
.pm-ph { display: flex; align-items: center; justify-content: center; background: rgba(127,127,127,.14); border: 2px dashed rgba(127,127,127,.5); color: rgba(127,127,127,.9); font-size: 26px; text-align: center; box-sizing: border-box; }
|
||||
.pm-shape { width: 100%; height: 100%; pointer-events: none; }
|
||||
.pm-mini .pm-ph { font-size: 40px; }
|
||||
|
||||
/* 面板 */
|
||||
.pm-panel { width: 316px; flex-shrink: 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
|
||||
|
||||
/* 生成历史(右栏 76px,50×50 缩略图竖排) */
|
||||
.pm-hist { width: 76px; flex-shrink: 0; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
|
||||
.pm-hist-t { font-size: 12px; font-weight: 700; opacity: .75; text-align: center; }
|
||||
.pm-hist-t em { font-style: normal; color: #3b82f6; margin-left: 3px; }
|
||||
.pm-hist-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 8px; }
|
||||
.pm-hist-thumb { width: 50px; height: 50px; object-fit: cover; border-radius: 8px; cursor: zoom-in; border: 2px solid transparent; background: rgba(127,127,127,.12); flex-shrink: 0; transition: border-color .15s; }
|
||||
.pm-hist-thumb:hover { border-color: #3b82f6; }
|
||||
.pm-hist-empty { font-size: 11px; opacity: .55; text-align: center; line-height: 1.6; padding-top: 10px; }
|
||||
.pm-hist-view { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.78); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 24px; }
|
||||
.pm-hist-view img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: 8px; background: #fff; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
|
||||
.pm-sec { padding: 10px 12px; border: 1px solid var(--n-border-color, #e5e5e5); border-radius: 10px; background: rgba(127,127,127,.04); }
|
||||
.pm-bgs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
|
||||
.pm-bg-sw { height: 26px; border-radius: 6px; border: 1px solid rgba(127,127,127,.35); cursor: pointer; }
|
||||
.pm-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; flex-wrap: wrap; }
|
||||
.pm-row.gap { gap: 10px; }
|
||||
.pm-row label { opacity: .8; white-space: nowrap; }
|
||||
.pm-input { width: 100%; box-sizing: border-box; margin-top: 8px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--n-border-color, #d9d9d9); background: var(--n-action-color, #fff); color: inherit; font-size: 13px; }
|
||||
.pm-input.ta { resize: vertical; font-family: inherit; }
|
||||
.pm-input:focus { outline: none; border-color: #3b82f6; }
|
||||
.pm-color { width: 44px; height: 28px; padding: 0; border: 1px solid rgba(127,127,127,.35); border-radius: 6px; background: transparent; cursor: pointer; }
|
||||
.pm-sel { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--n-border-color, #d9d9d9); background: var(--n-action-color, #fff); color: inherit; font-size: 13px; }
|
||||
.pm-mini-btn { padding: 3px 10px; border-radius: 6px; border: 1px solid var(--n-border-color, #d9d9d9); background: transparent; color: inherit; cursor: pointer; font-size: 13px; }
|
||||
.pm-mini-btn.on { background: #3b82f6; border-color: #3b82f6; color: #fff; }
|
||||
.chk { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.pm-layers { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow: auto; }
|
||||
.pm-li { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; font-size: 13px; background: rgba(127,127,127,.06); }
|
||||
.pm-li.on { border-color: #3b82f6; background: rgba(59,130,246,.12); }
|
||||
.pm-li-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.pm-li-ops { display: inline-flex; gap: 2px; }
|
||||
.pm-li-ops button { border: none; background: transparent; cursor: pointer; color: inherit; padding: 2px 4px; font-size: 12px; border-radius: 4px; }
|
||||
.pm-li-ops button:hover { background: rgba(127,127,127,.2); }
|
||||
.pm-tip { font-size: 13px; opacity: .65; line-height: 1.7; padding: 8px 4px; }
|
||||
.pm-hidden { display: none; }
|
||||
@media (max-width: 1180px) {
|
||||
.pm-main { flex-direction: column; overflow-y: auto; }
|
||||
.pm-tpls, .pm-panel { width: 100%; max-height: none; overflow: visible; }
|
||||
.pm-stage { flex: none; height: 56vh; }
|
||||
.pm-tpl-grid { grid-template-columns: repeat(4, 1fr); }
|
||||
/* 窄屏:历史栏改为横排(缩略图仍 50×50) */
|
||||
.pm-hist { width: 100%; flex-direction: row; align-items: center; gap: 8px; }
|
||||
.pm-hist-t { flex-shrink: 0; }
|
||||
.pm-hist-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 0; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,457 @@
|
||||
// AI 海报模板库 —— 设计尺寸 1080×1440(3:4 通用朋友圈/小红书/电商比例)
|
||||
// 模板 = 背景(纯色/线性渐变) + 图层列表(文字/图片/色块),加载后进入画布编辑:
|
||||
// 支持改文字(内容/字号/颜色/粗细/对齐)、换图片(上传/AI生成)、拖动移动、增删图层、导出 PNG。
|
||||
|
||||
export interface PosterTextShadow { color: string; blur: number; y: number }
|
||||
|
||||
export interface PosterTextLayer {
|
||||
type: 'text';
|
||||
text: string;
|
||||
x: number; y: number; w: number;
|
||||
size: number;
|
||||
color: string;
|
||||
weight?: number;
|
||||
align?: 'left' | 'center' | 'right';
|
||||
lineHeight?: number; // 倍数,默认 1.25
|
||||
italic?: boolean;
|
||||
shadow?: PosterTextShadow;
|
||||
rot?: number; // 旋转角度(度,绕图层中心,可为负)
|
||||
}
|
||||
|
||||
export interface PosterImageLayer {
|
||||
type: 'image';
|
||||
x: number; y: number; w: number; h: number;
|
||||
radius?: number;
|
||||
rot?: number; // 旋转角度(度)
|
||||
src?: string; // 当前图片(上传或 AI 生成后写入)
|
||||
prompt?: string; // AI 生成默认提示词
|
||||
}
|
||||
|
||||
export interface PosterShapeLayer {
|
||||
type: 'shape';
|
||||
shape: 'rect' | 'ellipse';
|
||||
x: number; y: number; w: number; h: number;
|
||||
fill: string;
|
||||
radius?: number;
|
||||
opacity?: number;
|
||||
rot?: number; // 旋转角度(度)
|
||||
}
|
||||
|
||||
export type PosterLayer = PosterTextLayer | PosterImageLayer | PosterShapeLayer;
|
||||
|
||||
export interface PosterBg {
|
||||
color?: string;
|
||||
angle?: number;
|
||||
stops?: { c: string; p: number }[];
|
||||
}
|
||||
|
||||
export interface PosterTemplate {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string;
|
||||
w: number;
|
||||
h: number;
|
||||
bg: PosterBg;
|
||||
layers: PosterLayer[];
|
||||
}
|
||||
|
||||
export const POSTER_W = 1080;
|
||||
export const POSTER_H = 1440;
|
||||
|
||||
export const POSTER_CATS = [
|
||||
{ id: 'hot', name: '热门' },
|
||||
{ id: 'promo', name: '促销' },
|
||||
{ id: 'festival', name: '节日' },
|
||||
{ id: 'event', name: '活动' },
|
||||
{ id: 'food', name: '美食' },
|
||||
{ id: 'edu', name: '教育' },
|
||||
{ id: 'school', name: '校园' },
|
||||
{ id: 'sport', name: '健身' },
|
||||
{ id: 'recruit', name: '招聘' },
|
||||
{ id: 'birthday', name: '生日' },
|
||||
{ id: 'redbook', name: '封面' },
|
||||
];
|
||||
|
||||
const tx = (text: string, x: number, y: number, w: number, size: number, color: string,
|
||||
o: Partial<PosterTextLayer> = {}): PosterTextLayer =>
|
||||
({ type: 'text', text, x, y, w, size, color, weight: 700, align: 'center', lineHeight: 1.25, ...o });
|
||||
|
||||
const im = (x: number, y: number, w: number, h: number, prompt = '', o: Partial<PosterImageLayer> = {}): PosterImageLayer =>
|
||||
({ type: 'image', x, y, w, h, radius: 24, prompt, ...o });
|
||||
|
||||
const sh = (shape: 'rect' | 'ellipse', x: number, y: number, w: number, h: number, fill: string,
|
||||
o: Partial<PosterShapeLayer> = {}): PosterShapeLayer =>
|
||||
({ type: 'shape', shape, x, y, w, h, fill, ...o });
|
||||
|
||||
const solid = (color: string): PosterBg => ({ color });
|
||||
const grad = (angle: number, c1: string, c2: string): PosterBg =>
|
||||
({ angle, stops: [{ c: c1, p: 0 }, { c: c2, p: 1 }] });
|
||||
|
||||
const mk = (id: string, name: string, category: string, bg: PosterBg, layers: PosterLayer[]): PosterTemplate =>
|
||||
({ id, name, category, w: POSTER_W, h: POSTER_H, bg, layers });
|
||||
|
||||
export const POSTER_TEMPLATES: PosterTemplate[] = [
|
||||
// ---------------- 促销 ----------------
|
||||
mk('shuang11', '双11狂购节', 'promo', grad(135, '#ff2d55', '#ff9500'), [
|
||||
sh('ellipse', 640, 60, 420, 420, 'rgba(255,255,255,0.13)'),
|
||||
sh('ellipse', -60, 240, 300, 300, 'rgba(255,255,255,0.10)'),
|
||||
tx('双11狂购节', 50, 380, 980, 140, '#ffffff', { weight: 900 }),
|
||||
tx('全场5折起 · 满300减50', 50, 570, 980, 56, '#ffe082'),
|
||||
sh('rect', 340, 668, 400, 96, '#ffd60a', { radius: 48 }),
|
||||
tx('限时抢购 手慢无', 340, 686, 400, 44, '#c62828'),
|
||||
im(90, 830, 900, 430, '双11电商促销商品堆头,礼盒购物袋红色节日氛围,电商海报', { radius: 28 }),
|
||||
tx('活动时间:11月1日 - 11月11日', 50, 1300, 980, 40, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
mk('d618', '618年中大促', 'promo', grad(120, '#0052ff', '#00c6ff'), [
|
||||
tx('618年中大促', 50, 290, 980, 150, '#ffffff', { weight: 900 }),
|
||||
tx('跨店每满300减50', 50, 490, 980, 60, '#ffd60a', { weight: 900 }),
|
||||
im(140, 640, 800, 560, '618蓝色科技感电商商品展示,礼盒光效,促销banner', { radius: 32 }),
|
||||
sh('rect', 340, 1258, 400, 92, '#ffd60a', { radius: 46 }),
|
||||
tx('立即抢购', 340, 1274, 400, 44, '#0052ff'),
|
||||
]),
|
||||
mk('qingcang', '清仓大甩卖', 'promo', solid('#ffd60a'), [
|
||||
tx('清仓大甩卖', 50, 230, 980, 170, '#d32f2f', { weight: 900 }),
|
||||
tx('全场1折起', 50, 450, 980, 110, '#111111', { weight: 900 }),
|
||||
tx('数量有限 售完即止', 50, 610, 980, 48, '#333333'),
|
||||
im(120, 740, 840, 460, '工厂清仓甩卖商品堆头,衣服鞋帽纸箱,黄色促销海报', { radius: 24 }),
|
||||
sh('ellipse', 380, 1250, 320, 170, '#d32f2f'),
|
||||
tx('速抢', 380, 1298, 320, 56, '#ffffff', { weight: 900 }),
|
||||
]),
|
||||
mk('kaixin', '新店开业', 'promo', grad(135, '#e53935', '#ff7043'), [
|
||||
sh('ellipse', -100, -80, 420, 420, 'rgba(255,255,255,0.12)'),
|
||||
tx('新店开业', 50, 320, 980, 165, '#ffffff', { weight: 900 }),
|
||||
tx('全场8折 · 进店有礼', 50, 540, 980, 60, '#ffe082'),
|
||||
im(120, 700, 840, 480, '新店铺开业花篮与门头,喜庆红色氛围,开业典礼照片', { radius: 24 }),
|
||||
tx('地址:XX路88号 · 电话:138-0000-0000', 50, 1270, 980, 42, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
|
||||
// ---------------- 节日 ----------------
|
||||
mk('chunjie', '新春快乐', 'festival', grad(135, '#c62828', '#ff8f00'), [
|
||||
sh('ellipse', 390, 130, 300, 300, 'rgba(255,213,79,0.92)'),
|
||||
tx('2026', 390, 226, 300, 72, '#c62828', { weight: 900 }),
|
||||
tx('新春快乐', 50, 520, 980, 190, '#ffd54f', { weight: 900, shadow: { color: 'rgba(120,0,0,0.45)', blur: 24, y: 8 } }),
|
||||
tx('万事如意 · 阖家幸福 · 财源广进', 50, 770, 980, 52, '#ffffff', { weight: 700 }),
|
||||
im(140, 900, 800, 400, '中国春节红灯笼与梅花,喜庆新年氛围摄影', { radius: 24 }),
|
||||
tx('恭祝全市人民 新年大吉', 50, 1350, 980, 46, '#ffe0b2', { weight: 400 }),
|
||||
]),
|
||||
mk('zhongqiu', '中秋团圆', 'festival', grad(160, '#1a237e', '#6a1b9a'), [
|
||||
tx('中秋佳节', 50, 250, 980, 175, '#ffd54f', { weight: 900 }),
|
||||
tx('月圆人团圆', 50, 455, 980, 70, '#ffffff'),
|
||||
im(190, 620, 700, 700, '满月夜空,金色月亮特写,中秋节深蓝色氛围', { radius: 350 }),
|
||||
tx('但愿人长久 千里共婵娟', 50, 1372, 980, 44, '#c5cae9', { weight: 400 }),
|
||||
]),
|
||||
mk('shengdan', '圣诞快乐', 'festival', solid('#2e7d32'), [
|
||||
tx('圣诞快乐', 50, 230, 980, 175, '#ff5252', { weight: 900, shadow: { color: 'rgba(0,0,0,0.35)', blur: 18, y: 6 } }),
|
||||
tx('Merry Christmas', 50, 440, 980, 54, '#ffffff', { weight: 400, italic: true }),
|
||||
im(140, 570, 800, 550, '圣诞树彩灯装饰,温暖圣诞夜氛围', { radius: 24 }),
|
||||
sh('rect', 330, 1185, 420, 100, '#ff5252', { radius: 50 }),
|
||||
tx('圣诞好礼8折', 330, 1207, 420, 44, '#ffffff'),
|
||||
tx('12月24日 - 12月26日', 50, 1340, 980, 40, '#c8e6c9', { weight: 400 }),
|
||||
]),
|
||||
mk('yuandan', '元旦快乐', 'festival', grad(135, '#0d47a1', '#00acc1'), [
|
||||
tx('元旦快乐', 50, 300, 980, 165, '#ffffff', { weight: 900 }),
|
||||
tx('2026 新年新气象', 50, 510, 980, 64, '#b3e5fc'),
|
||||
im(120, 680, 840, 470, '跨年城市夜空烟花,蓝色新年氛围摄影', { radius: 24 }),
|
||||
tx('愿所有美好如期而至', 50, 1240, 980, 54, '#ffffff', { weight: 700 }),
|
||||
tx('Happy New Year', 50, 1345, 980, 40, '#b3e5fc', { weight: 400, italic: true }),
|
||||
]),
|
||||
|
||||
// ---------------- 活动 ----------------
|
||||
mk('choujiang', '幸运大抽奖', 'event', grad(135, '#6a1b9a', '#e91e63'), [
|
||||
sh('ellipse', 340, 110, 400, 400, 'rgba(255,255,255,0.15)'),
|
||||
tx('抽', 340, 205, 400, 200, '#ffd60a', { weight: 900 }),
|
||||
tx('幸运大抽奖', 50, 580, 980, 150, '#ffffff', { weight: 900 }),
|
||||
tx('100%中奖 · 最高赢免单', 50, 770, 980, 60, '#ffd60a'),
|
||||
im(140, 900, 800, 380, '抽奖转盘与紫色礼盒,霓虹活动海报背景', { radius: 24 }),
|
||||
sh('rect', 340, 1320, 400, 90, '#ffd60a', { radius: 45 }),
|
||||
tx('立即参与', 340, 1338, 400, 44, '#6a1b9a'),
|
||||
]),
|
||||
mk('fenxiang', '行业分享会', 'event', solid('#263238'), [
|
||||
sh('rect', 80, 110, 12, 130, '#00acc1'),
|
||||
tx('行业干货分享会', 130, 118, 870, 72, '#80deea', { align: 'left', weight: 700 }),
|
||||
tx('时间:11月20日 14:00\n地点:市图书馆 · 报告厅', 80, 320, 920, 44, '#b0bec5', { align: 'left', weight: 400, lineHeight: 1.6 }),
|
||||
im(80, 560, 920, 540, '讲师舞台演讲分享会现场,PPT大屏,专业会议照片', { radius: 16 }),
|
||||
sh('rect', 80, 1180, 920, 180, 'rgba(0,172,193,0.18)', { radius: 20 }),
|
||||
tx('限额50名 · 报名免费', 120, 1244, 840, 46, '#80deea', { align: 'left', weight: 700 }),
|
||||
]),
|
||||
mk('huiyuan', '会员日', 'event', solid('#ff6f00'), [
|
||||
tx('会员日', 50, 280, 980, 180, '#ffffff', { weight: 900 }),
|
||||
tx('每月8日 双倍积分', 50, 510, 980, 66, '#ffe0b2'),
|
||||
im(190, 660, 700, 560, '橙色暖调会员积分礼品展示,电商会员日配图', { radius: 28 }),
|
||||
tx('更有会员专属价等你来抢', 50, 1280, 980, 48, '#ffffff', { weight: 700 }),
|
||||
]),
|
||||
|
||||
// ---------------- 美食 ----------------
|
||||
mk('huoguo', '招牌火锅', 'food', solid('#b71c1c'), [
|
||||
tx('沸腾火锅', 50, 230, 980, 160, '#ffd54f', { weight: 900 }),
|
||||
tx('麻辣鲜香 · 越煮越有味', 50, 430, 980, 56, '#ffffff'),
|
||||
im(110, 580, 860, 560, '红油火锅翻滚特写,辣椒花椒热气腾腾,美食摄影', { radius: 24 }),
|
||||
tx('进店消费满100送50', 50, 1220, 980, 52, '#ffd54f', { weight: 900 }),
|
||||
tx('地址:美食街A12 · 11:00-次日02:00', 50, 1340, 980, 40, '#ffcdd2', { weight: 400 }),
|
||||
]),
|
||||
mk('naicha', '新品奶茶', 'food', grad(135, '#fce4ec', '#f8bbd0'), [
|
||||
tx('新品上市', 50, 270, 980, 150, '#ad1457', { weight: 900 }),
|
||||
tx('招牌奶茶 第二杯半价', 50, 470, 980, 64, '#880e4f'),
|
||||
im(160, 640, 760, 560, '粉色系珍珠奶茶饮品摄影,清新甜品海报', { radius: 28 }),
|
||||
sh('ellipse', 390, 1250, 300, 160, '#ad1457'),
|
||||
tx('尝鲜去', 390, 1292, 300, 46, '#ffffff', { weight: 900 }),
|
||||
]),
|
||||
mk('shaokao', '深夜烧烤', 'food', solid('#171717'), [
|
||||
tx('深夜烧烤', 50, 250, 980, 150, '#ff9100', { weight: 900 }),
|
||||
tx('串串香 · 啤酒畅饮', 50, 450, 980, 58, '#ffffff'),
|
||||
im(100, 600, 880, 540, '炭火烧烤羊肉串特写,火光油亮,夜市美食摄影', { radius: 20 }),
|
||||
tx('营业至凌晨2点 · 到店送烤串5串', 50, 1220, 980, 46, '#ffab40', { weight: 700 }),
|
||||
tx('XX路夜市3号摊', 50, 1330, 980, 38, '#9e9e9e', { weight: 400 }),
|
||||
]),
|
||||
|
||||
// ---------------- 教育 ----------------
|
||||
mk('shuxi', '暑期班招生', 'edu', grad(135, '#00695c', '#26a69a'), [
|
||||
tx('暑期班招生', 50, 280, 980, 150, '#ffffff', { weight: 900 }),
|
||||
tx('名额有限 · 报名立减500', 50, 480, 980, 60, '#b2dfdb'),
|
||||
im(130, 640, 820, 470, '学生在明亮教室上课,教育培训宣传照', { radius: 24 }),
|
||||
sh('rect', 290, 1200, 500, 100, '#ffd60a', { radius: 50 }),
|
||||
tx('免费试听一节课', 290, 1222, 500, 44, '#00695c'),
|
||||
tx('咨询电话:400-000-0000', 50, 1345, 980, 40, '#b2dfdb', { weight: 400 }),
|
||||
]),
|
||||
mk('kaixue', '开学季特惠', 'edu', solid('#1565c0'), [
|
||||
tx('开学季', 50, 260, 980, 170, '#ffd60a', { weight: 900 }),
|
||||
tx('学费立减500元', 50, 470, 980, 76, '#ffffff', { weight: 900 }),
|
||||
tx('再送开学大礼包', 50, 610, 980, 50, '#bbdefb'),
|
||||
im(150, 740, 780, 430, '书本文具开学用品摆拍,蓝色清爽背景', { radius: 24 }),
|
||||
sh('rect', 340, 1260, 400, 96, '#ffd60a', { radius: 48 }),
|
||||
tx('马上报名', 340, 1280, 400, 44, '#1565c0'),
|
||||
]),
|
||||
mk('chongci', '考试冲刺营', 'edu', solid('#283593'), [
|
||||
tx('考试冲刺营', 50, 250, 980, 140, '#ffd54f', { weight: 900 }),
|
||||
tx('30天高效提分计划', 50, 450, 980, 64, '#ffffff'),
|
||||
im(120, 610, 840, 470, '学生夜晚书桌台灯下复习,学习氛围照片', { radius: 24 }),
|
||||
tx('一对一辅导 · 名师划重点', 50, 1160, 980, 50, '#c5cae9'),
|
||||
sh('rect', 300, 1270, 480, 96, '#ffd54f', { radius: 48 }),
|
||||
tx('预约免费测评', 300, 1290, 480, 44, '#283593'),
|
||||
]),
|
||||
|
||||
// ---------------- 健身 ----------------
|
||||
mk('jianshen', '健身年卡', 'sport', solid('#1b1b1b'), [
|
||||
tx('年卡特惠', 50, 250, 980, 160, '#c6ff00', { weight: 900 }),
|
||||
tx('¥1999/年 限时开抢', 50, 460, 980, 72, '#ffffff', { weight: 900 }),
|
||||
im(100, 620, 880, 500, '健身房力量训练场景,深色调硬核健身摄影', { radius: 24 }),
|
||||
tx('私教体验课×3 免费送', 50, 1210, 980, 50, '#c6ff00', { weight: 700 }),
|
||||
tx('24小时营业 · 全城连锁', 50, 1330, 980, 38, '#9e9e9e', { weight: 400 }),
|
||||
]),
|
||||
mk('yujia', '瑜伽体验课', 'sport', grad(160, '#80cbc4', '#e0f2f1'), [
|
||||
tx('瑜伽体验课', 50, 280, 980, 140, '#00695c', { weight: 900 }),
|
||||
tx('新客免费 · 零基础友好', 50, 470, 980, 58, '#004d40'),
|
||||
im(140, 640, 800, 520, '瑜伽垫上的女性拉伸,明亮工作室清新氛围', { radius: 28 }),
|
||||
tx('每周六上午 10:00', 50, 1240, 980, 48, '#00695c', { weight: 700 }),
|
||||
tx('扫码预约 限前50名', 50, 1335, 980, 42, '#00897b', { weight: 400 }),
|
||||
]),
|
||||
|
||||
// ---------------- 招聘 ----------------
|
||||
mk('gaoxin', '高薪招聘', 'recruit', solid('#0d1b2a'), [
|
||||
sh('rect', 0, 0, 1080, 12, '#00e5ff'),
|
||||
tx('高薪招聘\n期待你加入', 80, 170, 920, 110, '#ffffff', { align: 'left', weight: 900, lineHeight: 1.35 }),
|
||||
tx('前端工程师 / 产品经理 / 运营', 80, 510, 920, 48, '#4dd0e1', { align: 'left', weight: 700 }),
|
||||
tx('13薪 · 五险一金 · 弹性工作 · 年度体检', 80, 630, 920, 44, '#90a4ae', { align: 'left', weight: 400 }),
|
||||
im(80, 770, 920, 430, '现代互联网公司开放办公区,团队协作照片', { radius: 16 }),
|
||||
sh('rect', 80, 1300, 460, 92, '#00e5ff', { radius: 46 }),
|
||||
tx('投递简历', 80, 1319, 460, 40, '#0d1b2a'),
|
||||
]),
|
||||
mk('mendi', '门店招聘', 'recruit', solid('#ffd60a'), [
|
||||
tx('门店招聘', 50, 270, 980, 160, '#111111', { weight: 900 }),
|
||||
tx('店员 / 收银 / 导购', 50, 480, 980, 64, '#b71c1c', { weight: 900 }),
|
||||
tx('月薪4500-8000 · 包吃住', 50, 610, 980, 52, '#111111'),
|
||||
im(140, 740, 800, 420, '明亮便利店门店员工微笑服务照片', { radius: 24 }),
|
||||
sh('rect', 300, 1250, 480, 100, '#b71c1c', { radius: 50 }),
|
||||
tx('电话:138-0000-0000', 300, 1274, 480, 44, '#ffffff', { weight: 900 }),
|
||||
]),
|
||||
|
||||
// ---------------- 生日 ----------------
|
||||
mk('shengri', '生日快乐', 'birthday', grad(135, '#f8bbd0', '#f48fb1'), [
|
||||
tx('生日快乐', 50, 260, 980, 170, '#ad1457', { weight: 900 }),
|
||||
tx('愿你所求皆如愿', 50, 465, 980, 56, '#880e4f'),
|
||||
im(170, 630, 740, 560, '粉色生日蛋糕蜡烛气球,生日派对摄影', { radius: 32 }),
|
||||
sh('ellipse', 380, 1250, 320, 160, '#ad1457'),
|
||||
tx('许愿时刻', 380, 1292, 320, 46, '#ffffff', { weight: 900 }),
|
||||
]),
|
||||
mk('zhousui', '宝宝周岁', 'birthday', grad(135, '#fff9c4', '#ffe0b2'), [
|
||||
tx('周岁快乐', 50, 250, 980, 150, '#ef6c00', { weight: 900 }),
|
||||
tx('宝宝成长纪念', 50, 450, 980, 56, '#e65100'),
|
||||
im(160, 620, 760, 560, '抓周物品与宝宝生日布置,暖黄色温馨照片', { radius: 32 }),
|
||||
tx('健康快乐 平安长大', 50, 1280, 980, 48, '#bf360c', { weight: 700 }),
|
||||
]),
|
||||
|
||||
// ---------------- 封面/宣传 ----------------
|
||||
mk('ganhuo', '干货分享封面', 'redbook', solid('#f7f7f7'), [
|
||||
sh('rect', 70, 90, 340, 92, '#ff2442', { radius: 46 }),
|
||||
tx('干货分享', 70, 111, 340, 42, '#ffffff', { weight: 900 }),
|
||||
tx('5个让效率翻倍\n的办公神器', 70, 240, 940, 96, '#111111', { align: 'left', weight: 900, lineHeight: 1.4 }),
|
||||
tx('收藏 = 用到', 70, 530, 940, 40, '#888888', { align: 'left', weight: 400 }),
|
||||
im(70, 640, 940, 640, '干净留白的桌面办公好物平铺摄影,小红书封面风格', { radius: 24 }),
|
||||
tx('关注我 持续分享实用工具', 70, 1350, 940, 36, '#999999', { align: 'left', weight: 400 }),
|
||||
]),
|
||||
mk('qiye', '企业宣传', 'redbook', grad(135, '#004d40', '#00897b'), [
|
||||
tx('企业宣传', 50, 300, 980, 150, '#ffffff', { weight: 900 }),
|
||||
tx('专业 · 高效 · 值得信赖', 50, 500, 980, 56, '#b2dfdb'),
|
||||
im(110, 660, 860, 520, '现代企业办公大楼玻璃幕墙蓝天,商务摄影', { radius: 20 }),
|
||||
tx('成立10年 · 服务客户10000+', 50, 1250, 980, 46, '#80cbc4', { weight: 700 }),
|
||||
sh('rect', 340, 1345, 400, 76, 'rgba(255,255,255,0.92)', { radius: 38 }),
|
||||
tx('了解更多', 340, 1363, 400, 36, '#004d40', { weight: 700 }),
|
||||
]),
|
||||
|
||||
// ---------------- 校园(学校/老师/学生) ----------------
|
||||
mk('jiaoshijie', '教师节快乐', 'school', grad(135, '#ff8f00', '#ffd54f'), [
|
||||
sh('ellipse', 660, 70, 380, 380, 'rgba(255,255,255,0.16)'),
|
||||
tx('教师节快乐', 50, 330, 980, 150, '#ffffff', { weight: 900, shadow: { color: 'rgba(180,80,0,0.4)', blur: 20, y: 6 } }),
|
||||
tx('三尺讲台 · 一生耕耘', 50, 540, 980, 56, '#fff3e0', { weight: 700 }),
|
||||
im(140, 670, 800, 470, '老师在黑板前讲课,明亮温暖教室,教师节主题摄影', { radius: 24 }),
|
||||
sh('rect', 340, 1195, 400, 96, '#c62828', { radius: 48 }),
|
||||
tx('感恩有您', 340, 1217, 400, 44, '#ffd54f'),
|
||||
tx('9月10日 · 致敬每一位恩师', 50, 1345, 980, 40, '#fff8e1', { weight: 400 }),
|
||||
]),
|
||||
mk('kaixue1', '开学第一课', 'school', grad(120, '#1565c0', '#42a5f5'), [
|
||||
tx('开学第一课', 50, 260, 980, 150, '#ffd60a', { weight: 900 }),
|
||||
tx('新学期 · 新起点 · 新目标', 50, 470, 980, 54, '#ffffff', { weight: 700 }),
|
||||
im(130, 620, 820, 480, '黑板与书本开学场景,粉笔字新学期,明亮教室', { radius: 24 }),
|
||||
sh('rect', 300, 1180, 480, 100, '#ffd60a', { radius: 50 }),
|
||||
tx('收心启航 立即返校', 300, 1206, 480, 44, '#1565c0'),
|
||||
tx('XX学校 9月1日正式上课', 50, 1340, 980, 40, '#bbdefb', { weight: 400 }),
|
||||
]),
|
||||
mk('jiazhanghui', '家长会通知', 'school', solid('#1a237e'), [
|
||||
sh('rect', 0, 0, 1080, 14, '#ffd60a'),
|
||||
tx('家长会通知', 60, 130, 960, 130, '#ffffff', { align: 'left', weight: 900 }),
|
||||
tx('时间:本周六 09:00\n地点:三年级(2)班教室\n主讲:班主任 王老师', 60, 350, 960, 46, '#c5cae9', { align: 'left', weight: 400, lineHeight: 1.7 }),
|
||||
im(60, 660, 960, 430, '教室家长会现场,课桌整齐排列,明亮校园教室', { radius: 16 }),
|
||||
sh('rect', 60, 1170, 480, 96, '#ffd60a', { radius: 48 }),
|
||||
tx('敬请准时出席', 60, 1193, 480, 44, '#1a237e'),
|
||||
tx('XX小学 三年级(2)班 家委会', 60, 1330, 960, 38, '#90a4ae', { align: 'left', weight: 400 }),
|
||||
]),
|
||||
mk('yundonghui', '秋季运动会', 'school', grad(135, '#d32f2f', '#ff7043'), [
|
||||
sh('ellipse', -80, 180, 320, 320, 'rgba(255,255,255,0.12)'),
|
||||
tx('秋季运动会', 50, 300, 980, 165, '#ffd54f', { weight: 900 }),
|
||||
tx('激情飞扬 · 超越自我', 50, 520, 980, 56, '#ffffff', { weight: 700 }),
|
||||
im(120, 660, 840, 470, '学校操场红色跑道与运动健儿,运动会场景', { radius: 24 }),
|
||||
sh('rect', 340, 1200, 400, 96, '#ffffff', { radius: 48 }),
|
||||
tx('报名参赛', 340, 1224, 400, 44, '#d32f2f'),
|
||||
tx('10月16日 · 学校操场', 50, 1345, 980, 40, '#ffe0b2', { weight: 400 }),
|
||||
]),
|
||||
mk('biyeji', '毕业季', 'school', grad(160, '#0d47a1', '#26c6da'), [
|
||||
tx('毕业快乐', 50, 250, 980, 175, '#ffffff', { weight: 900, shadow: { color: 'rgba(0,40,90,0.45)', blur: 22, y: 8 } }),
|
||||
tx('愿你前程似锦 · 顶峰相见', 50, 470, 980, 54, '#b3e5fc', { weight: 700 }),
|
||||
im(190, 620, 700, 640, '学士帽抛向蓝天,毕业季庆祝,青春校园', { radius: 32 }),
|
||||
tx('2026届 · 青春不散场', 50, 1350, 980, 42, '#e1f5fe', { weight: 400 }),
|
||||
]),
|
||||
mk('shezhaoxin', '社团招新', 'school', grad(135, '#8e24aa', '#ff6d00'), [
|
||||
tx('社团招新', 50, 270, 980, 170, '#ffffff', { weight: 900 }),
|
||||
tx('百团大战 · 就等你来', 50, 490, 980, 58, '#ffe0b2', { weight: 700 }),
|
||||
im(140, 640, 800, 470, '大学生社团活动,街舞音乐绘画丰富多彩,校园招新', { radius: 28 }),
|
||||
sh('ellipse', 370, 1180, 340, 170, '#ffd60a'),
|
||||
tx('加入我们', 370, 1228, 340, 48, '#6a1b9a', { weight: 900 }),
|
||||
tx('本周五中午 · 食堂广场', 50, 1380, 980, 38, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
mk('biaozhang', '优秀学生表彰', 'school', solid('#fff8e1'), [
|
||||
sh('rect', 36, 36, 1008, 1368, '#c62828'),
|
||||
sh('rect', 60, 60, 960, 1320, '#fff8e1'),
|
||||
tx('光荣榜', 50, 170, 980, 150, '#c62828', { weight: 900 }),
|
||||
tx('优秀学生表彰', 50, 370, 980, 96, '#d32f2f', { weight: 900, rot: -4 }),
|
||||
tx('张同学 · 李同学 · 王同学\n品学兼优 · 全面发展', 140, 570, 800, 52, '#5d4037', { weight: 700, lineHeight: 1.8 }),
|
||||
im(240, 810, 600, 380, '金色奖杯与奖状证书特写,表彰大会氛围', { radius: 20 }),
|
||||
tx('XX学校 教务处', 50, 1270, 980, 44, '#8d6e63', { weight: 400 }),
|
||||
]),
|
||||
mk('ertongjie', '快乐六一', 'school', grad(135, '#00bcd4', '#8bc34a'), [
|
||||
tx('快乐六一', 50, 270, 980, 165, '#ffffff', { weight: 900, shadow: { color: 'rgba(0,90,110,0.35)', blur: 18, y: 6 } }),
|
||||
tx('阳光自信 · 快乐成长', 50, 485, 980, 54, '#e0f7fa', { weight: 700 }),
|
||||
im(160, 630, 760, 550, '小学校园儿童欢笑庆祝,彩色气球彩带,六一儿童节', { radius: 32 }),
|
||||
sh('ellipse', 390, 1230, 300, 160, '#ff5722'),
|
||||
tx('6·1', 390, 1272, 300, 62, '#ffffff', { weight: 900 }),
|
||||
tx('XX小学 庆六一文艺汇演', 50, 1395, 980, 36, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
mk('kaoshi', '考试加油', 'school', solid('#b71c1c'), [
|
||||
sh('ellipse', 340, 90, 400, 400, 'rgba(255,213,79,0.92)'),
|
||||
tx('必胜', 340, 210, 400, 150, '#b71c1c', { weight: 900 }),
|
||||
tx('考试加油', 50, 560, 980, 165, '#ffd54f', { weight: 900 }),
|
||||
tx('以梦为马 · 不负韶华', 50, 780, 980, 54, '#ffffff', { weight: 700 }),
|
||||
im(140, 900, 800, 350, '学生伏案复习试卷书本特写,台灯下奋斗场景', { radius: 20 }),
|
||||
sh('rect', 300, 1300, 480, 96, '#ffd60a', { radius: 48 }),
|
||||
tx('金榜题名', 300, 1324, 480, 44, '#b71c1c'),
|
||||
]),
|
||||
mk('dushuyue', '书香校园读书月', 'school', grad(160, '#4e342e', '#8d6e63'), [
|
||||
tx('书香校园', 50, 260, 980, 160, '#ffe0b2', { weight: 900 }),
|
||||
tx('读书月 · 阅读分享活动', 50, 470, 980, 52, '#ffffff', { weight: 700 }),
|
||||
im(130, 620, 820, 480, '图书馆书架与学生阅读,温暖木质色调,书香氛围', { radius: 24 }),
|
||||
sh('rect', 290, 1170, 500, 96, '#ffe0b2', { radius: 48 }),
|
||||
tx('每天阅读30分钟', 290, 1194, 500, 44, '#4e342e'),
|
||||
tx('主办:语文教研组 · 11月', 50, 1330, 980, 40, '#d7ccc8', { weight: 400 }),
|
||||
]),
|
||||
|
||||
// ---------------- 更多促销/节日/活动/美食 ----------------
|
||||
mk('miaosha', '限时秒杀', 'promo', solid('#111111'), [
|
||||
tx('限时秒杀', 50, 260, 980, 170, '#ff1744', { weight: 900 }),
|
||||
tx('前100名 · 1元抢', 50, 480, 980, 72, '#ffffff', { weight: 900 }),
|
||||
im(80, 660, 580, 520, '爆款商品抢购堆头,红黑配色电商海报', { radius: 24 }),
|
||||
sh('ellipse', 700, 660, 320, 320, 'rgba(255,23,68,0.88)'),
|
||||
tx('1元', 700, 755, 320, 120, '#ffffff', { weight: 900, rot: -8 }),
|
||||
tx('每晚8点准时开抢', 50, 1260, 980, 52, '#ff8a80', { weight: 700 }),
|
||||
tx('活动截止:11月30日', 50, 1350, 980, 38, '#9e9e9e', { weight: 400 }),
|
||||
]),
|
||||
mk('shuang12', '双12年终盛典', 'promo', grad(135, '#4a148c', '#e91e63'), [
|
||||
sh('ellipse', 620, 50, 440, 440, 'rgba(255,255,255,0.12)'),
|
||||
tx('双12年终盛典', 40, 340, 1000, 130, '#ffffff', { weight: 900 }),
|
||||
tx('年终好价 · 全场包邮', 50, 530, 980, 58, '#ffd60a', { weight: 900 }),
|
||||
im(140, 670, 800, 470, '双12紫色电商促销礼盒堆头,霓虹光效', { radius: 28 }),
|
||||
sh('rect', 340, 1210, 400, 96, '#ffd60a', { radius: 48 }),
|
||||
tx('立即抢购', 340, 1234, 400, 44, '#4a148c'),
|
||||
tx('12月12日 0点开抢', 50, 1350, 980, 40, '#f3e5f5', { weight: 400 }),
|
||||
]),
|
||||
mk('muri', '母亲节快乐', 'festival', grad(160, '#ec407a', '#f8bbd0'), [
|
||||
tx('母亲节快乐', 50, 280, 980, 160, '#ffffff', { weight: 900, shadow: { color: 'rgba(150,20,60,0.35)', blur: 18, y: 6 } }),
|
||||
tx('时光不老 · 母爱永恒', 50, 490, 980, 54, '#fce4ec', { weight: 700 }),
|
||||
im(170, 640, 740, 540, '粉色康乃馨花束特写,母亲节温馨氛围', { radius: 32 }),
|
||||
sh('ellipse', 380, 1225, 320, 150, '#ad1457'),
|
||||
tx('感恩有你', 380, 1265, 320, 46, '#ffffff', { weight: 900 }),
|
||||
tx('5月第二个星期日', 50, 1395, 980, 36, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
mk('zhounian', '门店周年庆', 'event', grad(135, '#bf360c', '#ff6d00'), [
|
||||
tx('三周年庆', 50, 290, 980, 175, '#ffd54f', { weight: 900 }),
|
||||
tx('感恩回馈 · 全场5折', 50, 520, 980, 60, '#ffffff', { weight: 900 }),
|
||||
im(130, 670, 820, 460, '店铺周年庆气球拱门与礼盒,喜庆橙红色', { radius: 24 }),
|
||||
sh('rect', 300, 1195, 480, 100, '#ffffff', { radius: 50 }),
|
||||
tx('进店即送礼品', 300, 1222, 480, 44, '#bf360c'),
|
||||
tx('活动3天 · 11月20-22日', 50, 1345, 980, 40, '#ffe0b2', { weight: 400 }),
|
||||
]),
|
||||
mk('waimai', '外卖满减', 'food', solid('#ff6f00'), [
|
||||
tx('外卖满减', 50, 250, 980, 165, '#ffffff', { weight: 900 }),
|
||||
tx('满25减12 · 满40减20', 50, 465, 980, 62, '#ffe0b2', { weight: 900 }),
|
||||
im(140, 630, 800, 470, '外卖餐盒美食打包俯拍,橙色暖调餐饮摄影', { radius: 28 }),
|
||||
sh('ellipse', 700, 1140, 300, 160, '#b71c1c'),
|
||||
tx('立减', 700, 1184, 300, 50, '#ffd54f', { weight: 900 }),
|
||||
tx('扫码下单 · 30分钟送达', 50, 1350, 980, 44, '#ffffff', { weight: 700 }),
|
||||
]),
|
||||
mk('kafei', '咖啡新品', 'food', solid('#3e2723'), [
|
||||
tx('新品拿铁', 50, 250, 980, 160, '#ffab40', { weight: 900 }),
|
||||
tx('第二杯半价', 50, 450, 980, 66, '#ffffff', { weight: 900 }),
|
||||
im(150, 610, 780, 560, '咖啡拉花拿铁特写,木质桌面暖光,咖啡馆氛围', { radius: 32 }),
|
||||
tx('每日现磨 · 门店限量', 50, 1250, 980, 48, '#ffe0b2', { weight: 700 }),
|
||||
tx('活动时间:11:00 - 18:00', 50, 1350, 980, 38, '#bcaaa4', { weight: 400 }),
|
||||
]),
|
||||
mk('meishijie', '美食嘉年华', 'food', grad(135, '#e65100', '#ffb300'), [
|
||||
sh('ellipse', -70, 240, 300, 300, 'rgba(255,255,255,0.14)'),
|
||||
tx('美食嘉年华', 50, 300, 980, 155, '#ffffff', { weight: 900 }),
|
||||
tx('全场5折 · 吃货狂欢', 50, 510, 980, 58, '#fff3e0', { weight: 900 }),
|
||||
im(130, 660, 820, 470, '各类美食拼盘俯拍,烤串甜品饮品,热闹美食节', { radius: 24 }),
|
||||
sh('rect', 340, 1200, 400, 96, '#b71c1c', { radius: 48 }),
|
||||
tx('5折开吃', 340, 1224, 400, 44, '#ffd54f'),
|
||||
tx('本周六日 · 中心广场', 50, 1345, 980, 40, '#ffffff', { weight: 400 }),
|
||||
]),
|
||||
];
|
||||
|
||||
// 背景快捷预设(画布"背景"区一键切换)
|
||||
export const BG_PRESETS: { name: string; bg: PosterBg }[] = [
|
||||
{ name: '中国红', bg: grad(135, '#c62828', '#ff8f00') },
|
||||
{ name: '活力橙', bg: grad(135, '#ff6d00', '#ffb300') },
|
||||
{ name: '科技蓝', bg: grad(120, '#0052ff', '#00c6ff') },
|
||||
{ name: '魅紫', bg: grad(135, '#6a1b9a', '#e91e63') },
|
||||
{ name: '森绿', bg: grad(135, '#00695c', '#26a69a') },
|
||||
{ name: '樱花粉', bg: grad(135, '#f8bbd0', '#f48fb1') },
|
||||
{ name: '暗夜黑', bg: solid('#171717') },
|
||||
{ name: '奶油白', bg: solid('#f7f7f7') },
|
||||
];
|
||||
@@ -1,12 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
import ImgHist from '@/tools/img-hist/ImgHist.vue';
|
||||
import { blobToB64, saveImgHist } from '@/tools/img-hist/img-hist';
|
||||
|
||||
useHead({ title: '文字生成图片 - IT-TOOLS-PRO' });
|
||||
|
||||
const genHist = useGenHistory('text-to-image');
|
||||
const histRef = ref<InstanceType<typeof ImgHist> | null>(null);
|
||||
|
||||
/** 生成结果保存到服务器历史(失败静默,不影响本地下载) */
|
||||
async function persist(b64: string) {
|
||||
try {
|
||||
const ok = await saveImgHist({ kind: 'text-to-image', tool: 'text-to-image', b64, model: '文字生成图片', prompt: (text.value || '').slice(0, 100) });
|
||||
if (ok) histRef.value?.reload();
|
||||
}
|
||||
catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
const text = ref('在线免费文字生成图片工具\nIT-TOOLS-PRO 让你更高效地工作\n如果你觉得这个工具好用,可以分享给你的小伙伴们');
|
||||
const format = ref<'png' | 'jpg'>('png');
|
||||
@@ -36,7 +45,7 @@ const generated = ref(false);
|
||||
const resultUrl = ref('');
|
||||
const resultSize = ref(0);
|
||||
|
||||
function render(toBlob = false) {
|
||||
function render(toBlob = false, save = false) {
|
||||
const c = canvas.value;
|
||||
if (!c) {
|
||||
return;
|
||||
@@ -66,13 +75,15 @@ function render(toBlob = false) {
|
||||
}
|
||||
resultUrl.value = URL.createObjectURL(blob);
|
||||
resultSize.value = blob.size;
|
||||
if (save) {
|
||||
blobToB64(blob).then((b64) => { if (b64) persist(b64); });
|
||||
}
|
||||
}, mime, 0.92);
|
||||
}
|
||||
}
|
||||
|
||||
function download() {
|
||||
render(true);
|
||||
genHist.add({ title: `文字生成图片: ${text.value.slice(0, 20)}`, detail: `${width.value}×${height.value} ${format.value.toUpperCase()} · ${fontSize.value}px` });
|
||||
setTimeout(() => {
|
||||
const a = document.createElement('a');
|
||||
a.href = resultUrl.value;
|
||||
@@ -105,6 +116,7 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<div class="ti-root">
|
||||
<div class="ti-main">
|
||||
<div class="ti-panel">
|
||||
<div class="ti-panel-title">📝 文本内容</div>
|
||||
<textarea v-model="text" class="ti-textarea" rows="6" placeholder="输入要生成图片的文字,支持多行…" @input="render()" />
|
||||
@@ -175,7 +187,7 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<div class="ti-btns">
|
||||
<button class="ti-btn" @click="render(true)">
|
||||
<button class="ti-btn" @click="render(true, true)">
|
||||
🚀 生成
|
||||
</button>
|
||||
<button class="ti-btn ti-btn-ghost" :disabled="!resultUrl" @click="download">
|
||||
@@ -197,13 +209,25 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="text-to-image" label="生成记录" class="mt-10px" />
|
||||
</div>
|
||||
<ImgHist ref="histRef" kind="text-to-image" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.ti-root {
|
||||
padding-bottom: 40px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 12px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.ti-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.ti-root { flex-direction: column; }
|
||||
}
|
||||
|
||||
.ti-panel {
|
||||
|
||||
@@ -139,7 +139,8 @@ watch([source, from, to], () => {
|
||||
// ============ 文档翻译 ============
|
||||
const mode = ref<'text' | 'doc'>('text');
|
||||
const docTo = ref('zh-CN');
|
||||
const docLangOptions = langs.filter(l => l.value !== 'auto');
|
||||
// 文档翻译:本地引擎仅加载中英,下拉只给真实可选项
|
||||
const docLangOptions = langs.filter(l => l.value === 'zh-CN' || l.value === 'en');
|
||||
const docInput = ref<HTMLInputElement>();
|
||||
// 批量文档翻译:一次最多 10 个文件,每个文件一个任务
|
||||
const MAX_DOC_FILES = 10;
|
||||
@@ -183,7 +184,7 @@ async function translateOne(job: any) {
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('file', job.file);
|
||||
fd.append('to', langName(docTo.value));
|
||||
fd.append('to', docTo.value); // 传语言码,服务端本地引擎按码翻译(旧标签格式也兼容)
|
||||
// 单文件超时保护:超过 8 分钟视为失败
|
||||
const ctrl = new AbortController();
|
||||
const timer = setTimeout(() => ctrl.abort(), 8 * 60 * 1000);
|
||||
@@ -199,7 +200,7 @@ async function translateOne(job: any) {
|
||||
throw new Error(j.message || `HTTP ${res.status}`);
|
||||
}
|
||||
job.text = j.data.text;
|
||||
job.info = `${j.data.chars} 字 · ${j.data.blocks} 块 · 译文 ${j.data.text.length} 字`;
|
||||
job.info = `${j.data.ocr ? `📷已OCR识别${j.data.ocr_pages > 1 ? ` ${j.data.ocr_pages} 页` : ''} · ` : ''}${j.data.chars} 字 · ${j.data.blocks} 块 · 译文 ${j.data.text.length} 字`;
|
||||
job.status = 'done';
|
||||
genHist.add({ title: `文档翻译: ${job.file.name}`, detail: `${j.data.chars} 字 → ${langName(docTo.value)}` });
|
||||
}
|
||||
@@ -336,16 +337,16 @@ onUnmounted(() => {
|
||||
📄 文档翻译
|
||||
<span class="mode-new">新</span>
|
||||
</button>
|
||||
<span class="mode-hint">{{ mode === 'doc' ? '上传 Word / PDF / TXT 等文档,AI 整篇翻译并保留段落格式,可下载译文' : '输入文本自动翻译' }}</span>
|
||||
<span class="mode-hint">{{ mode === 'doc' ? '上传 Word / PDF / TXT / 图片,整篇翻译并保留段落格式;非纯文字(扫描件/图片)自动 OCR 识别后再翻译' : '输入文本自动翻译' }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 文档翻译面板 -->
|
||||
<div v-if="mode === 'doc'" class="doc-panel">
|
||||
<input ref="docInput" type="file" hidden multiple accept=".txt,.md,.docx,.doc,.pdf,.html,.htm,.epub,.rtf,.odt" @change="onDocInput">
|
||||
<input ref="docInput" type="file" hidden multiple accept=".txt,.md,.docx,.doc,.pdf,.html,.htm,.epub,.rtf,.odt,.png,.jpg,.jpeg,.webp,.bmp,.gif,.tiff,.tif" @change="onDocInput">
|
||||
<div class="doc-top">
|
||||
<div class="doc-drop" @click="pickDoc">
|
||||
<template v-if="!docJobs.length">
|
||||
📁 点击选择文档(可多选,最多 10 个)<br><span>Word / PDF / TXT / MD / HTML / EPUB · 每个 ≤20MB</span>
|
||||
📁 点击选择文档或图片(可多选,最多 10 个)<br><span>Word / PDF / TXT / MD / HTML / EPUB · 截图/扫描件/图片 · 每个 ≤20MB</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
📄 已选 {{ docJobs.length }} 个文件<span v-if="docJobs.length >= MAX_DOC_FILES" class="doc-size">(已达 10 个上限)</span>
|
||||
@@ -388,7 +389,8 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="doc-empty">
|
||||
支持整篇文档批量翻译(最多 10 个):AI 分块处理并保留原段落结构,逐个文件出译文,可下载 TXT 或 Word(DOCX)。
|
||||
支持整篇文档批量翻译(最多 10 个):分块处理并保留原段落结构,逐个文件出译文,可下载 TXT 或 Word(DOCX)。<br>
|
||||
<b>📌 非纯文字文档处理:</b>上传的文档或图片若不是纯文字(如扫描版 PDF、截图、照片、带文字的图片),系统会<b>先自动 OCR 识别出文字,再整篇翻译</b>——扫描件无需先手动转文字,直接传上来即可;识别结果可在译文里核对,建议图片清晰、光线均匀以保证识别准确率。
|
||||
</div>
|
||||
<n-spin v-if="docLoading" :show="docLoading" class="doc-spin" />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user