Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
003f98e388 | ||
|
|
66c3fede6b | ||
|
|
94ccaf2c0f | ||
|
|
c75f2882f7 | ||
|
|
855378df2c | ||
|
|
c6341ea35b | ||
|
|
cd4b324740 | ||
|
|
15d21235cd | ||
|
|
55b1111d96 | ||
|
|
9d75776d52 | ||
|
|
f420785887 | ||
|
|
7b22e53d1a | ||
|
|
ea4e3deb50 | ||
|
|
b4c4f5de8a |
No files matched your search
@@ -2,9 +2,27 @@
|
||||
|
||||
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 流量
|
||||
|
||||
@@ -32,6 +32,37 @@
|
||||
- **生成记录**:翻译/OCR/修图/转换等 9 个工具自动留痕,数据存本地
|
||||
- **体验优化**:全站中文默认、收藏与最近使用、菜单一键展开/收起、宽屏自适应、品牌页脚等数十项细节
|
||||
|
||||
### 留言反馈(2026.11 新增)
|
||||
|
||||
- **访客提交**:顶栏「留言反馈」按钮打开弹窗 —— 类型(功能建议/意见建议/Bug 反馈/其他)+ 内容(上限 1000 字)+ 联系方式(可选),图形验证码防刷,同一 IP 一小时内限提交 1 次
|
||||
- **管理后台**:`/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 新增)
|
||||
|
||||
- **模型来源与免费说明**:站内 10 个生图模型全部经自建 NewAPI 网关聚合——5 个 `pollinations-*` 走 Pollinations.ai(完全免费、无需 KEY),4 个 `flux*` + `dall-e-3` 走 Cloudflare Workers AI(站主账号承担免费额度),**对使用者全部免费**;模型列表由后端从网关实时拉取。
|
||||
- **我的提供商**:左侧「+ 使用我的提供商 / 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]`(图片文件/下载)。
|
||||
|
||||
## 优势
|
||||
|
||||
- **一次激活,全站通用**:输入一次卡密,全部授权功能解锁,无需逐个购买
|
||||
@@ -84,6 +115,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
+8
@@ -29,6 +29,7 @@ declare module '@vue/runtime-core' {
|
||||
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']
|
||||
@@ -91,6 +92,7 @@ declare module '@vue/runtime-core' {
|
||||
Encryption: typeof import('./src/tools/encryption/encryption.vue')['default']
|
||||
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.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']
|
||||
@@ -151,6 +153,7 @@ 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']
|
||||
@@ -161,6 +164,7 @@ declare module '@vue/runtime-core' {
|
||||
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']
|
||||
@@ -171,6 +175,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']
|
||||
@@ -192,12 +197,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']
|
||||
|
||||
@@ -13,7 +13,7 @@ COPY piper-models /app/piper-models
|
||||
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,744 @@
|
||||
"""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 "
|
||||
"WHERE at>? ORDER BY at DESC LIMIT 300", (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)
|
||||
+1220
-28
File diff suppressed because it is too large.
Load diff
+5
-1
@@ -274,6 +274,10 @@ tools:
|
||||
title: Translator
|
||||
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
|
||||
description: Extract text from images with OCR - click, drag & drop or paste a screenshot, get recognized lines with confidence scores, copy or download as TXT.
|
||||
@@ -385,7 +389,7 @@ tools:
|
||||
|
||||
my-ip:
|
||||
title: My IP address
|
||||
description: Check your device's public IPv4/IPv6 address and location (with an IPv6 setup guide when unsupported). This site supports IPv6 direct connection. Measure latency to popular places and test your download/upload speed to this server.
|
||||
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
|
||||
|
||||
+5
-1
@@ -271,6 +271,10 @@ tools:
|
||||
title: 在线翻译
|
||||
description: 文本翻译支持中英日韩法德等 16 种语言,自动识别源语言:中英互译走本地开源引擎不限流,其他语种自动切 MyMemory 备用线路;文档整篇翻译(中英),扫描件/图片自动 OCR 识别后翻译,修改文本自动翻译。
|
||||
|
||||
mcp-connect:
|
||||
title: MCP 接入(AI 调用本站工具)
|
||||
description: 让 Claude、Hermes 等 AI 客户端通过 MCP 协议直接调用本站 13 个授权工具(翻译、OCR、生图、视频处理等);查看接入教程、生成与管理调用令牌,未购买卡密时提供购买入口。
|
||||
|
||||
image-ocr:
|
||||
title: 图片OCR文字识别
|
||||
description: 上传、拖拽或粘贴截图识别图片中的文字,逐行输出识别结果和置信度,支持复制全部和下载TXT。
|
||||
@@ -381,7 +385,7 @@ tools:
|
||||
|
||||
my-ip:
|
||||
title: 本机IP查询
|
||||
description: 查询你设备的公网IPv4/IPv6地址与所属地(IPv6不支持时提供开启教程),本站已支持IPv6直连,测连接热门地点延迟,一键测试你到本站服务器的下载/上传网速。
|
||||
description: 查询你设备的公网IPv4/IPv6地址与所属地(IPv6不支持时提供开启教程),代理/VPN检测(出口IP归属判定+WebRTC泄漏实测),热门地点延迟实测(百度、本省运营商门户、全国镜像站与海外节点),测速历史自动记录延迟快照,本站已支持IPv6直连,一键测试你到本站服务器的下载/上传网速。
|
||||
|
||||
hash-text:
|
||||
title: Hash 文本
|
||||
|
||||
+29
@@ -17,6 +17,35 @@ 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;
|
||||
|
||||
@@ -183,6 +183,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', '/code-reader', '/my-ip']);
|
||||
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']);
|
||||
const isWide = computed(() => WIDE_TOOLS.has(route.path));
|
||||
|
||||
const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
{
|
||||
title: '原创工具',
|
||||
items: [
|
||||
{ name: '本机IP查询', icon: '网', desc: '仅显示你设备的公网IPv4/IPv6地址与所属地(多源容错+中文归属地+一键复制),IPv6不支持时明示并给出开启教程,本站已支持IPv6直连(速度更快),网速测试为你的设备↔本站服务器真实收发计时,进入页面自动测9个热门地点延迟', tag: '全新' },
|
||||
{ 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 不上传);生成:自定义前景/背景颜色、中间插入本地 Logo 图片,生成后自动自扫验证可下载 PNG', tag: '全新' },
|
||||
|
||||
+254
-7
@@ -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) {
|
||||
@@ -272,12 +276,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 +316,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 +399,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 +465,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 +484,17 @@ 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();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -434,8 +524,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>
|
||||
@@ -614,7 +709,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 +727,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 +940,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 +1188,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;
|
||||
@@ -1194,6 +1429,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,702 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { AUTH_BASE, getMachineId, licenseState, checkAuth } from '@/tools/license/license';
|
||||
|
||||
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 ? '授权已生效,13 个高级功能已解锁' : '卡密已发放,授权暂未刷新,请点击下方重新核验';
|
||||
} 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">
|
||||
支付成功后本页直接显示卡密,同时本机立即解锁 13 个高级功能
|
||||
</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) }} · 13 个高级功能</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">🎁 支付成功即解锁 13 个高级功能,无需等待人工发货。</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>
|
||||
@@ -1,9 +1,16 @@
|
||||
<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';
|
||||
|
||||
useHead({ title: '授权应用 - IT-TOOLS-PRO' });
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
/** 「前往购买卡密」→ 站内支付页 /buy */
|
||||
function goBuy(): void {
|
||||
router.push('/buy');
|
||||
}
|
||||
|
||||
interface Feature {
|
||||
path: string;
|
||||
name: string;
|
||||
@@ -189,7 +196,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;
|
||||
+450
-17
@@ -1,13 +1,114 @@
|
||||
<script setup lang="ts">
|
||||
import { getMachineId, licenseHeaders } from '@/tools/license/license';
|
||||
|
||||
const models = ref<{ id: string; i2i: boolean }[]>([]);
|
||||
const models = ref<{ id: string; i2i: boolean; custom?: boolean }[]>([]);
|
||||
const model = ref('pollinations-flux');
|
||||
const prompt = ref('');
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const resultUrl = ref('');
|
||||
|
||||
// ---------- 自定义提供商(KEY 只存本机浏览器 localStorage) ----------
|
||||
const PROVIDER_KEY = 'it-tools-ai-provider';
|
||||
const provider = ref<{ base_url: string; api_key: string; models: string[] }>({ base_url: '', api_key: '', models: [] });
|
||||
const provOpen = ref(false);
|
||||
const provBusy = ref(false);
|
||||
const provErr = ref('');
|
||||
const manualModel = ref('');
|
||||
|
||||
function loadProvider() {
|
||||
try {
|
||||
const raw = localStorage.getItem(PROVIDER_KEY);
|
||||
if (raw) {
|
||||
const p = JSON.parse(raw);
|
||||
provider.value = {
|
||||
base_url: typeof p.base_url === 'string' ? p.base_url : '',
|
||||
api_key: typeof p.api_key === 'string' ? p.api_key : '',
|
||||
models: Array.isArray(p.models) ? p.models.map((x: any) => String(x)) : [],
|
||||
};
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
function saveProvider() {
|
||||
try { localStorage.setItem(PROVIDER_KEY, JSON.stringify(provider.value)); } catch { /* ignore */ }
|
||||
}
|
||||
watch(provider, saveProvider, { deep: true });
|
||||
|
||||
const hasCreds = computed(() => !!(provider.value.base_url.trim() && provider.value.api_key.trim()));
|
||||
|
||||
async function connectProvider() {
|
||||
provErr.value = '';
|
||||
if (!hasCreds.value) { provErr.value = '请填写接口地址和 API KEY'; return; }
|
||||
provBusy.value = true;
|
||||
try {
|
||||
const res = await fetch('/relay/ai/custom-models', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
machine: getMachineId(),
|
||||
base_url: provider.value.base_url.trim(),
|
||||
api_key: provider.value.api_key.trim(),
|
||||
}),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
if (j.code === 200 && Array.isArray(j.data) && j.data.length) {
|
||||
provider.value.models = j.data.map((x: any) => String(x));
|
||||
saveProvider();
|
||||
mergeModels();
|
||||
if (!models.value.some((m) => m.id === model.value) && provider.value.models.length) {
|
||||
model.value = provider.value.models[0];
|
||||
}
|
||||
} else {
|
||||
provErr.value = j.message || '连接失败';
|
||||
}
|
||||
} catch (e: any) {
|
||||
provErr.value = String(e?.message || e);
|
||||
} finally {
|
||||
provBusy.value = false;
|
||||
}
|
||||
}
|
||||
function addManualModel() {
|
||||
const v = manualModel.value.trim();
|
||||
if (!v) return;
|
||||
if (!provider.value.models.includes(v)) provider.value.models.push(v);
|
||||
manualModel.value = '';
|
||||
saveProvider();
|
||||
mergeModels();
|
||||
}
|
||||
function removeProviderModel(m: string) {
|
||||
provider.value.models = provider.value.models.filter((x) => x !== m);
|
||||
saveProvider();
|
||||
mergeModels();
|
||||
}
|
||||
function clearProvider() {
|
||||
provider.value = { base_url: '', api_key: '', models: [] };
|
||||
provErr.value = '';
|
||||
saveProvider();
|
||||
mergeModels();
|
||||
}
|
||||
|
||||
// 站内模型 + 用户自填模型合并(自定义款 custom=true 排后面)
|
||||
let inhouseModels: { id: string; i2i: boolean }[] = [];
|
||||
function mergeModels() {
|
||||
const inhouse = inhouseModels.map((m) => ({ ...m, custom: false }));
|
||||
const mine = provider.value.models.map((id) => ({ id, i2i: false, custom: true }));
|
||||
models.value = [...inhouse, ...mine];
|
||||
}
|
||||
|
||||
// ---------- 生成历史(服务端落盘,点缩略图回看/下载) ----------
|
||||
const history = ref<{ id: string; at: number; model: string; prompt: string; img_url: string }[]>([]);
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const res = await fetch(`/relay/ai/img-history?machine=${encodeURIComponent(getMachineId())}`);
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && Array.isArray(j.data)) history.value = j.data;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
function openHist(it: any) {
|
||||
resultUrl.value = it.img_url || '';
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
// 宽高比
|
||||
type Ratio = { label: string; w: number; h: number; sw: number; sh: number };
|
||||
const RATIOS: Ratio[] = [
|
||||
@@ -38,19 +139,24 @@ const EXAMPLES = [
|
||||
const canGen = computed(() => !!prompt.value.trim());
|
||||
|
||||
onMounted(async () => {
|
||||
loadProvider();
|
||||
loadHistory();
|
||||
try {
|
||||
const res = await fetch('/relay/ai/image-models');
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && Array.isArray(j.data) && j.data.length) {
|
||||
models.value = j.data;
|
||||
if (!j.data.some((m: any) => m.id === model.value)) {
|
||||
inhouseModels = j.data;
|
||||
mergeModels();
|
||||
if (!models.value.some((m: any) => m.id === model.value)) {
|
||||
// 默认选一个 pollinations(稳定可用)
|
||||
const p = j.data.find((m: any) => m.id.startsWith('pollinations'));
|
||||
model.value = (p || j.data[0]).id;
|
||||
}
|
||||
} else {
|
||||
mergeModels();
|
||||
}
|
||||
}
|
||||
catch { /* 模型列表加载失败则用默认 */ }
|
||||
catch { mergeModels(); /* 模型列表加载失败则用默认 */ }
|
||||
});
|
||||
|
||||
function b64DataUrl(b64: string) {
|
||||
@@ -60,6 +166,13 @@ function b64DataUrl(b64: string) {
|
||||
return `data:${mime};base64,${b64}`;
|
||||
}
|
||||
|
||||
// 站内历史文件下载带 ?dl=1(触发 attachment);dataUrl/外链原样
|
||||
const dlHref = computed(() => {
|
||||
const u = resultUrl.value;
|
||||
if (!u) return '#';
|
||||
return u.startsWith('/relay/ai/img/') ? u + '?dl=1' : u;
|
||||
});
|
||||
|
||||
async function generate() {
|
||||
if (loading.value || !canGen.value) return;
|
||||
loading.value = true;
|
||||
@@ -67,20 +180,28 @@ async function generate() {
|
||||
resultUrl.value = '';
|
||||
try {
|
||||
const r = ratioObj.value;
|
||||
const body: any = {
|
||||
machine: getMachineId(),
|
||||
prompt: prompt.value.trim(),
|
||||
model: model.value,
|
||||
width: r.w,
|
||||
height: r.h,
|
||||
};
|
||||
const isMine = provider.value.models.includes(model.value);
|
||||
if (isMine) {
|
||||
if (!hasCreds.value) throw new Error('已选自定义模型:请先在「我的提供商」填写接口地址和 API KEY');
|
||||
body.provider = { base_url: provider.value.base_url.trim(), api_key: provider.value.api_key.trim() };
|
||||
}
|
||||
const res = await fetch('/relay/ai/gen-image', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders('ai-gen') },
|
||||
body: JSON.stringify({
|
||||
machine: getMachineId(),
|
||||
prompt: prompt.value.trim(),
|
||||
model: model.value,
|
||||
width: r.w,
|
||||
height: r.h,
|
||||
}),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
if (!res.ok || j.code !== 200) throw new Error(j.message || `HTTP ${res.status}`);
|
||||
resultUrl.value = j.data.b64 ? b64DataUrl(j.data.b64) : j.data.url;
|
||||
const dataUrl = j.data.b64 ? b64DataUrl(j.data.b64) : '';
|
||||
resultUrl.value = j.data.img_url || dataUrl || j.data.url;
|
||||
loadHistory();
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
@@ -100,7 +221,12 @@ async function generate() {
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">模型</div>
|
||||
<select v-model="model" class="gen-model-sel">
|
||||
<option v-for="m in models" :key="m.id" :value="m.id">{{ m.id }}</option>
|
||||
<optgroup label="站内免费模型">
|
||||
<option v-for="m in models.filter(x => !x.custom)" :key="m.id" :value="m.id">{{ m.id }}</option>
|
||||
</optgroup>
|
||||
<optgroup v-if="models.some(x => x.custom)" label="我的模型">
|
||||
<option v-for="m in models.filter(x => x.custom)" :key="m.id" :value="m.id">{{ m.id }}(我的)</option>
|
||||
</optgroup>
|
||||
<option v-if="!models.length" value="pollinations-flux">pollinations-flux</option>
|
||||
</select>
|
||||
<div class="gen-pills">
|
||||
@@ -108,12 +234,43 @@ async function generate() {
|
||||
v-for="m in models"
|
||||
:key="m.id"
|
||||
class="gen-pill"
|
||||
:class="{ on: model === m.id }"
|
||||
:class="{ on: model === m.id, mine: m.custom }"
|
||||
@click="model = m.id"
|
||||
>
|
||||
{{ m.id }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 自定义提供商:KEY 只存本机 -->
|
||||
<div class="prov">
|
||||
<button type="button" class="prov-toggle" @click="provOpen = !provOpen">
|
||||
<span>{{ hasCreds ? '✓ 我的提供商已配置' : '+ 使用我的提供商 / API KEY' }}</span>
|
||||
<span class="prov-caret">{{ provOpen ? '▾' : '▸' }}</span>
|
||||
</button>
|
||||
<div v-show="provOpen" class="prov-form">
|
||||
<input v-model="provider.base_url" class="prov-input" placeholder="接口地址(OpenAI 兼容,如 https://api.openai.com/v1)" spellcheck="false" />
|
||||
<input v-model="provider.api_key" class="prov-input" type="password" placeholder="API KEY(仅保存在本机浏览器)" spellcheck="false" autocomplete="off" />
|
||||
<div class="prov-actions">
|
||||
<button type="button" class="prov-btn prov-primary" :disabled="provBusy" @click="connectProvider">
|
||||
{{ provBusy ? '⏳ 连接中…' : '🔌 连接并拉取模型' }}
|
||||
</button>
|
||||
<button type="button" class="prov-btn" @click="saveProvider">💾 保存到本地</button>
|
||||
<button v-if="provider.base_url || provider.api_key || provider.models.length" type="button" class="prov-btn prov-danger" @click="clearProvider">清除</button>
|
||||
</div>
|
||||
<div v-if="provErr" class="prov-err">⚠️ {{ provErr }}</div>
|
||||
<div class="prov-hint">接口地址与 KEY 只保存在你的浏览器(localStorage),生成时临时发给服务器转发,不入库、不落盘。</div>
|
||||
<div v-if="provider.models.length" class="prov-models">
|
||||
<span v-for="m in provider.models" :key="m" class="prov-tag">
|
||||
{{ m }}
|
||||
<i title="移除" @click="removeProviderModel(m)">×</i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="prov-manual">
|
||||
<input v-model="manualModel" class="prov-input" placeholder="手动输入模型名,回车添加" @keyup.enter="addManualModel" />
|
||||
<button type="button" class="prov-btn" @click="addManualModel">添加</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示词 -->
|
||||
@@ -159,12 +316,12 @@ async function generate() {
|
||||
<div v-if="error" class="gen-err">⚠️ {{ error }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧结果(占满剩余空间) -->
|
||||
<!-- 中间结果(占满剩余空间) -->
|
||||
<div class="gen-result">
|
||||
<div v-if="resultUrl" class="gen-img-box">
|
||||
<img :src="resultUrl" alt="生成结果">
|
||||
<div class="gen-img-acts">
|
||||
<a class="gen-dl" :href="resultUrl" target="_blank" rel="noopener" download>⬇ 下载图片</a>
|
||||
<a class="gen-dl" :href="dlHref" target="_blank" rel="noopener" download>⬇ 下载图片</a>
|
||||
<a class="gen-dl" :href="resultUrl" target="_blank" rel="noopener">🔗 新窗口打开</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -174,6 +331,22 @@ async function generate() {
|
||||
</div>
|
||||
<div v-else class="gen-empty">生成的图片会显示在这里</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧历史:50×50 缩略图竖排 -->
|
||||
<div class="gen-hist">
|
||||
<div class="hist-t">历史<em v-if="history.length">{{ history.length }}</em></div>
|
||||
<div v-if="history.length" class="hist-list">
|
||||
<img
|
||||
v-for="it in history"
|
||||
:key="it.id"
|
||||
:src="it.img_url"
|
||||
:title="it.prompt"
|
||||
:class="{ on: resultUrl === it.img_url }"
|
||||
@click="openHist(it)"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="hist-empty">还没有<br>生成记录</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -184,7 +357,7 @@ async function generate() {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
// 占满屏幕:控制面板 + 结果区填满可视高度
|
||||
// 占满屏幕:控制面板 + 结果区填满可视高度 + 右侧历史列
|
||||
.gen-body {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
@@ -258,6 +431,175 @@ async function generate() {
|
||||
color: #0e8b87;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
// 用户自填的模型
|
||||
&.mine {
|
||||
border-style: dashed;
|
||||
border-color: #9b6cff;
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
&.mine.on {
|
||||
background: #9b6cff;
|
||||
border-style: solid;
|
||||
border-color: #9b6cff;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- 自定义提供商 ---- */
|
||||
.prov {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-top: 4px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px dashed rgba(128, 128, 128, 0.3);
|
||||
}
|
||||
|
||||
.prov-toggle {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 8px 11px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
background: rgba(128, 128, 128, 0.05);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: #0ea5a0;
|
||||
color: #0e8b87;
|
||||
}
|
||||
}
|
||||
|
||||
.prov-caret {
|
||||
font-size: 11px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.prov-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.prov-input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 9px 11px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
background: #fff;
|
||||
outline: none;
|
||||
font-family: inherit;
|
||||
|
||||
&:focus {
|
||||
border-color: #0ea5a0;
|
||||
}
|
||||
}
|
||||
|
||||
.prov-actions {
|
||||
display: flex;
|
||||
gap: 7px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.prov-btn {
|
||||
padding: 7px 12px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
border-color: #0ea5a0;
|
||||
color: #0e8b87;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.prov-primary {
|
||||
background: linear-gradient(48deg, #0e9384, #14b8a6);
|
||||
border: none;
|
||||
color: #fff;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
opacity: 0.88;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.prov-danger:hover:not(:disabled) {
|
||||
border-color: #d03050;
|
||||
color: #d03050;
|
||||
}
|
||||
|
||||
.prov-hint {
|
||||
font-size: 11.5px;
|
||||
line-height: 1.6;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.prov-err {
|
||||
font-size: 12.5px;
|
||||
color: #d03050;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.prov-models {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.prov-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 3px 9px;
|
||||
border-radius: 999px;
|
||||
border: 1px dashed #9b6cff;
|
||||
background: rgba(155, 108, 255, 0.08);
|
||||
color: #7c4dff;
|
||||
font-size: 12px;
|
||||
|
||||
i {
|
||||
font-style: normal;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
opacity: 0.6;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: #d03050;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.prov-manual {
|
||||
display: flex;
|
||||
gap: 7px;
|
||||
|
||||
.prov-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,4 +760,95 @@ async function generate() {
|
||||
margin-top: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
// 右侧历史:50×50 缩略图竖排
|
||||
.gen-hist {
|
||||
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;
|
||||
|
||||
.hist-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;
|
||||
}
|
||||
}
|
||||
|
||||
.hist-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 9px 13px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
img {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 7px;
|
||||
border: 2px solid transparent;
|
||||
cursor: pointer;
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.15s;
|
||||
display: block;
|
||||
|
||||
&:hover {
|
||||
border-color: #0ea5a0;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&.on {
|
||||
border-color: #0ea5a0;
|
||||
box-shadow: 0 2px 8px rgba(14, 165, 160, 0.35);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hist-empty {
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
opacity: 0.45;
|
||||
padding: 16px 4px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
flex: none;
|
||||
width: 100%;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.hist-t {
|
||||
border-bottom: none;
|
||||
border-right: 1px solid rgba(128, 128, 128, 0.18);
|
||||
padding: 8px 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.hist-list {
|
||||
flex-direction: row;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -93,6 +93,7 @@ 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 wifiQrCodeGenerator } from './wifi-qr-code-generator';
|
||||
@@ -170,6 +171,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
{
|
||||
name: 'Development',
|
||||
components: [
|
||||
mcpConnect,
|
||||
gitMemo,
|
||||
randomPortGenerator,
|
||||
crontabGenerator,
|
||||
|
||||
@@ -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> = {
|
||||
@@ -238,3 +238,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,
|
||||
});
|
||||
+290
-5
@@ -1,6 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
// 本机IP查询:用户端公网 IPv4/IPv6 + 归属地 + 本站IPv6直连 + 热门地点延迟 + 网速测试(浏览器 <-> 本站服务器真实收发)
|
||||
type Geo = { country?: string; region?: string; city?: string; isp?: string; as?: string; lan?: boolean } | null;
|
||||
// 代理/VPN 出口判定(relay /ip-check 返回)
|
||||
type ChkInfo = { ip?: string; lan?: boolean; proxy?: boolean | null; type?: string; provider?: string; hostname?: string; asn?: string } | null;
|
||||
|
||||
// ---------- IP 查询(仅用户端视角,不显示服务器地址) ----------
|
||||
const ipLoading = ref(true);
|
||||
@@ -97,6 +99,111 @@ async function loadIps() {
|
||||
v4Geo.value = g4;
|
||||
v6Geo.value = g6;
|
||||
ipLoading.value = false;
|
||||
ensureIspNode(); // 归属运营商已知 → 插入「本省运营商门户」延迟节点并补测
|
||||
// 拿到地址后并行做代理/VPN 检测(不阻塞主卡片)
|
||||
runProxyCheck();
|
||||
rtcProbe();
|
||||
}
|
||||
|
||||
// ---------- 代理/VPN 检测(出口 IP 判定 + WebRTC 泄漏检测,均免费) ----------
|
||||
const pcLoading = ref(false);
|
||||
const chk4 = ref<ChkInfo | null>(null); // v4 出口判定
|
||||
const chk6 = ref<ChkInfo | null>(null); // v6 出口判定
|
||||
const rtcPub = ref<string[]>([]); // STUN 实测公网候选(代理漏出的真实地址线索)
|
||||
const rtcLocal = ref<string[]>([]); // 本机内网候选
|
||||
const rtcState = ref<'wait' | 'run' | 'done'>('wait');
|
||||
|
||||
async function runProxyCheck() {
|
||||
if (!v4.value && !v6.value) return;
|
||||
pcLoading.value = true;
|
||||
const [c4, c6] = await Promise.all([
|
||||
v4.value ? jfetch(`/relay/ip-check?ip=${encodeURIComponent(v4.value)}`, 12000).catch(() => null) : null,
|
||||
v6.value ? jfetch(`/relay/ip-check?ip=${encodeURIComponent(v6.value)}`, 12000).catch(() => null) : null,
|
||||
]);
|
||||
chk4.value = (c4 && c4.data) || null;
|
||||
chk6.value = (c6 && c6.data) || null;
|
||||
pcLoading.value = false;
|
||||
}
|
||||
|
||||
// WebRTC 探测:STUN srflx 候选=公网(代理/VPN 漏洞常见线索);host 候选=本机内网 IP。
|
||||
// Chrome 会把 host 候选打成 mDNS(.local) 域名,此时内网 IP 显示为「浏览器隐私保护已隐藏」。
|
||||
async function rtcProbe() {
|
||||
if (typeof RTCPeerConnection === 'undefined') {
|
||||
rtcState.value = 'done';
|
||||
return;
|
||||
}
|
||||
rtcState.value = 'run';
|
||||
const pub = new Set<string>();
|
||||
const loc = new Set<string>();
|
||||
let pc: RTCPeerConnection;
|
||||
try {
|
||||
pc = new RTCPeerConnection({
|
||||
iceServers: [
|
||||
{ urls: 'stun:stun.l.google.com:19302' },
|
||||
{ urls: 'stun:stun1.l.google.com:19302' },
|
||||
],
|
||||
});
|
||||
} catch {
|
||||
rtcState.value = 'done';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
pc.createDataChannel('probe');
|
||||
pc.onicecandidate = (e) => {
|
||||
if (!e.candidate) return;
|
||||
const m = /candidate:\S+ \d+ \S+ \d+ (\S+) \d+ typ (\w+)/.exec(e.candidate.candidate);
|
||||
if (!m) return;
|
||||
const ip = m[1].split('%')[0]; // 去 zone id
|
||||
const typ = m[2];
|
||||
if (ip.includes('.local')) return; // mDNS 伪地址,忽略
|
||||
if (typ === 'srflx') pub.add(ip);
|
||||
else if (typ === 'host') {
|
||||
const v4m = ip.match(/^(\d+)\./);
|
||||
const priv4 = v4m && ['10', '172', '192', '169'].includes(v4m[1]);
|
||||
const priv6 = ip.startsWith('fe80') || ip.startsWith('fc') || ip.startsWith('fd');
|
||||
if (ip.includes(':') ? priv6 : priv4) loc.add(ip); // 只留私网地址,公网 host 候选归入 pub 语义
|
||||
else pub.add(ip);
|
||||
}
|
||||
};
|
||||
pc.createOffer().then((o) => pc.setLocalDescription(o)).catch(() => {});
|
||||
await new Promise<void>((res) => {
|
||||
const to = setTimeout(res, 6000);
|
||||
pc.onicecandidate = ((orig) => (e: RTCPeerConnectionIceEvent) => {
|
||||
orig(e);
|
||||
if (!e.candidate) {
|
||||
clearTimeout(to);
|
||||
res();
|
||||
}
|
||||
})(pc.onicecandidate!);
|
||||
});
|
||||
} catch {
|
||||
/* 探测失败按无候选处理 */
|
||||
}
|
||||
try {
|
||||
pc.close();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
rtcPub.value = [...pub];
|
||||
rtcLocal.value = [...loc];
|
||||
rtcState.value = 'done';
|
||||
}
|
||||
|
||||
// WebRTC 公网候选与主 IP 不一致的地址(可能的真实出口)
|
||||
const rtcMismatch = computed<string[]>(() => {
|
||||
const known = new Set([v4.value, v6.value].filter(Boolean));
|
||||
return rtcPub.value.filter((ip) => !known.has(ip));
|
||||
});
|
||||
|
||||
function chkVerdict(c: ChkInfo | null): { icon: string; text: string; cls: string } {
|
||||
if (pcLoading.value) return { icon: '⏳', text: '检测中…', cls: '' };
|
||||
if (!c) return { icon: '⚪', text: '无法判定(查询服务暂不可用)', cls: 'px-unknown' };
|
||||
if (c.lan) return { icon: '🏠', text: '内网地址,不适用代理判定', cls: '' };
|
||||
if (c.proxy) return { icon: '🔴', text: `检测到代理/VPN(${c.type}${c.provider ? ' · ' + c.provider : ''})`, cls: 'px-bad' };
|
||||
if (c.type === 'Business' || c.type === 'Hosting') {
|
||||
return { icon: '🟡', text: `${c.type === 'Hosting' ? '数据中心' : '企业'}网络出口,通常非家庭宽带`, cls: 'px-warn' };
|
||||
}
|
||||
return { icon: '🟢', text: `未检测到代理/VPN(${c.type || '家庭宽带线路'}${c.provider ? ' · ' + c.provider : ''})`, cls: 'px-ok' };
|
||||
}
|
||||
|
||||
function geoLine(g: Geo): string {
|
||||
@@ -131,10 +238,11 @@ async function copyIp(text: string, key: string) {
|
||||
}
|
||||
|
||||
// ---------- 热门地点延迟(你的浏览器到各地点的实测延迟) ----------
|
||||
type LatNode = { name: string; url: string; ms: number | null; st: 'wait' | 'run' | 'ok' | 'fail' };
|
||||
type LatNode = { name: string; url: string; ms: number | null; st: 'wait' | 'run' | 'ok' | 'fail'; note?: string };
|
||||
const latTesting = ref(false);
|
||||
const nodes = ref<LatNode[]>([
|
||||
{ name: '本站服务器', url: `${location.origin}/favicon.ico`, ms: null, st: 'wait' },
|
||||
{ name: '百度', url: 'https://www.baidu.com/favicon.ico', ms: null, st: 'wait' },
|
||||
{ name: '清华 TUNA(北京)', url: 'https://mirrors.tuna.tsinghua.edu.cn/', ms: null, st: 'wait' },
|
||||
{ name: '阿里云镜像(杭州)', url: 'https://mirrors.aliyun.com/', ms: null, st: 'wait' },
|
||||
{ name: '腾讯云镜像(广州)', url: 'https://mirrors.cloud.tencent.com/', ms: null, st: 'wait' },
|
||||
@@ -145,6 +253,33 @@ const nodes = ref<LatNode[]>([
|
||||
{ name: 'Cloudflare(海外)', url: 'https://speed.cloudflare.com/__down?bytes=0', ms: null, st: 'wait' },
|
||||
]);
|
||||
|
||||
// 按用户 IPv4 归属运营商动态插入「本省运营商门户」节点(三大运营商+广电,无匹配则不插)
|
||||
function ensureIspNode() {
|
||||
if (nodes.value.some((n) => n.name.startsWith('本省'))) return;
|
||||
const g = v4Geo.value;
|
||||
const isp = `${g?.isp || ''} ${g?.as || ''}`;
|
||||
const province = g?.regionName || '';
|
||||
let portal = '';
|
||||
let short = '';
|
||||
if (/联通|Unicom/i.test(isp)) {
|
||||
portal = 'https://www.10010.com/favicon.ico'; // favicon 直链无 302;首页会被风控挂到超时
|
||||
short = '联通';
|
||||
} else if (/电信|Telecom/i.test(isp)) {
|
||||
portal = 'https://www.189.cn/favicon.ico';
|
||||
short = '电信';
|
||||
} else if (/移动|Mobile|铁通|Tietong/i.test(isp)) {
|
||||
portal = 'https://www.10086.cn/'; // 移动 favicon 不可达,用首页(200 稳定)
|
||||
short = '移动';
|
||||
} else if (/广电|Broadnet/i.test(isp)) {
|
||||
portal = 'https://www.10099.com.cn/favicon.ico';
|
||||
short = '广电';
|
||||
}
|
||||
if (!portal) return; // 未知运营商(教育网/长城等)不插行
|
||||
const node: LatNode = { name: `本省·${short}`, url: portal, ms: null, st: 'wait', note: province ? `${g?.isp || short} · ${province}` : (g?.isp || '') };
|
||||
nodes.value.splice(1, 0, node);
|
||||
ping(node); // 其余节点已在测,单独补测这一项
|
||||
}
|
||||
|
||||
const latSummary = computed(() => {
|
||||
const ok = nodes.value.filter((n) => n.st === 'ok' && n.ms != null);
|
||||
if (!ok.length) return '';
|
||||
@@ -316,6 +451,7 @@ interface SpeedRec {
|
||||
ms: number; // 到本站延迟
|
||||
route: 'IPv6 直连' | '公网中转'; // 测试时所走线路
|
||||
host: string; // 测试时的访问域名
|
||||
lat?: string; // 测速时点的热门地点延迟快照:"百度5 本省联通6 清华12 …"(空串=当时未测完)
|
||||
}
|
||||
const speedHistory = ref<SpeedRec[]>([]);
|
||||
|
||||
@@ -338,6 +474,14 @@ function saveSpeedHistory() {
|
||||
}
|
||||
}
|
||||
|
||||
// 把当前热门地点延迟压成短串快照(写入历史记录):"百度5 本省联通6 清华12 …"
|
||||
function latSnapshot(): string {
|
||||
return nodes.value
|
||||
.filter((n) => n.st === 'ok' && n.ms != null)
|
||||
.map((n) => `${n.name.replace(/([^)]*)/g, '').replace(/[\s·]/g, '')}${n.ms}`)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
function pushSpeedRec() {
|
||||
speedHistory.value.unshift({
|
||||
t: Date.now(),
|
||||
@@ -346,6 +490,7 @@ function pushSpeedRec() {
|
||||
ms: serverMs.value ?? 0,
|
||||
route: onV6Host ? 'IPv6 直连' : '公网中转',
|
||||
host: location.host,
|
||||
lat: latSnapshot(),
|
||||
});
|
||||
speedHistory.value = speedHistory.value.slice(0, 20);
|
||||
saveSpeedHistory();
|
||||
@@ -500,6 +645,7 @@ onMounted(() => {
|
||||
<span>下载 Mbps</span>
|
||||
<span>上传 Mbps</span>
|
||||
<span>延迟 ms</span>
|
||||
<span>热门地点延迟快照</span>
|
||||
</div>
|
||||
<div v-for="r in speedHistory" :key="r.t" class="sp-hrow">
|
||||
<span>{{ fmtTime(r.t) }}</span>
|
||||
@@ -507,12 +653,61 @@ onMounted(() => {
|
||||
<span class="c-down">{{ r.down }}</span>
|
||||
<span class="c-up">{{ r.up }}</span>
|
||||
<span class="c-ms">{{ r.ms }}</span>
|
||||
<span class="c-lat">{{ r.lat || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sp-hist-tip">对比方法:在当前线路测一次 → 点横幅「切换 IPv6 直连」再测一次,两条线路的下载/上传/延迟直接在表里对照。</div>
|
||||
<div class="sp-hist-tip">对比方法:在当前线路测一次 → 点横幅「切换 IPv6 直连」再测一次,下载/上传/延迟与各地点(百度/本省运营商/镜像站等)延迟直接在表里对照。</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 代理 / VPN 检测(出口 IP 判定 + WebRTC 泄漏检测) -->
|
||||
<div v-if="v4 || v6" class="sec">
|
||||
<div class="sec-head">
|
||||
<h3>🕵 代理 / VPN 检测</h3>
|
||||
<button class="sec-refresh" :disabled="pcLoading" @click="runProxyCheck()">
|
||||
{{ pcLoading ? '检测中…' : '重新检测' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="px-rows">
|
||||
<div class="px-row">
|
||||
<span class="px-k">IPv4 出口判定</span>
|
||||
<span class="px-v" :class="chkVerdict(chk4).cls">{{ chkVerdict(chk4).icon }} {{ chkVerdict(chk4).text }}</span>
|
||||
</div>
|
||||
<div v-if="v6" class="px-row">
|
||||
<span class="px-k">IPv6 出口判定</span>
|
||||
<span class="px-v" :class="chkVerdict(chk6).cls">{{ chkVerdict(chk6).icon }} {{ chkVerdict(chk6).text }}</span>
|
||||
</div>
|
||||
<div class="px-row">
|
||||
<span class="px-k">WebRTC 实测公网地址</span>
|
||||
<span class="px-v">
|
||||
<template v-if="rtcState === 'run'">⏳ 探测中…</template>
|
||||
<template v-else-if="rtcPub.length">
|
||||
<code v-for="ip in rtcPub" :key="ip" class="px-ip">{{ ip }}</code>
|
||||
<template v-if="rtcMismatch.length">
|
||||
<span class="px-bad">⚠ 与上方 IP 不一致:{{ rtcMismatch.join('、') }} —— 浏览器经 STUN 拿到的另一公网地址,若你在用代理/VPN,这可能才是你的实际网络出口</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="px-ok">✓ 与上方一致</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>未检出(浏览器已禁用 WebRTC,或被代理软件/网络阻断 STUN)</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="px-row">
|
||||
<span class="px-k">本机内网 IP</span>
|
||||
<span class="px-v">
|
||||
<template v-if="rtcState === 'run'">⏳ 探测中…</template>
|
||||
<template v-else-if="rtcLocal.length">
|
||||
<code v-for="ip in rtcLocal" :key="ip" class="px-ip">{{ ip }}</code>
|
||||
</template>
|
||||
<template v-else-if="rtcState === 'done'">浏览器隐私保护已隐藏(现代 Chrome 默认用虚拟域名代替)</template>
|
||||
<template v-else>—</template>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="px-note">说明:浏览器无法直接读取系统代理软件的开关状态;判定依据为出口 IP 归属数据库(proxycheck.io)与 WebRTC 泄漏实测——高级代理/VPN 可能伪装归属地或阻断 STUN,结果仅供参考。</p>
|
||||
</div>
|
||||
|
||||
<!-- 热门地点延迟 -->
|
||||
<div class="sec">
|
||||
<div class="sec-head">
|
||||
@@ -522,7 +717,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="lat-grid">
|
||||
<div v-for="n in nodes" :key="n.name" class="lat-card" :class="latCls(n)">
|
||||
<span class="lat-name">{{ n.name }}</span>
|
||||
<span class="lat-name" :title="n.note || ''">{{ n.name }}</span>
|
||||
<span class="lat-ms">
|
||||
{{ n.st === 'run' ? '测速中…' : n.st === 'fail' ? '超时' : n.st === 'ok' ? `${n.ms} ms` : '待测' }}
|
||||
</span>
|
||||
@@ -876,6 +1071,88 @@ onMounted(() => {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* ---------- 代理/VPN 检测 ---------- */
|
||||
.px-rows {
|
||||
font-size: 14px;
|
||||
|
||||
.px-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
padding: 7px 0;
|
||||
border-bottom: 1px dashed rgba(128, 128, 128, 0.18);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.px-k {
|
||||
flex: 0 0 150px;
|
||||
opacity: 0.75;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.px-v {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.px-ip {
|
||||
font-family: monospace;
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
padding: 1px 8px;
|
||||
border-radius: 6px;
|
||||
margin-right: 8px;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.px-ok {
|
||||
color: #18a058;
|
||||
}
|
||||
|
||||
.px-warn {
|
||||
color: #d0a000;
|
||||
}
|
||||
|
||||
.px-bad {
|
||||
color: #d03050;
|
||||
}
|
||||
|
||||
.px-unknown {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.px-note {
|
||||
margin-top: 8px;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.65;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.sec-refresh {
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
border-radius: 8px;
|
||||
padding: 5px 14px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
border-color: rgba(128, 128, 128, 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 测速历史 ---------- */
|
||||
.sp-history {
|
||||
margin-top: 14px;
|
||||
@@ -904,7 +1181,7 @@ onMounted(() => {
|
||||
|
||||
.sp-hrow {
|
||||
display: grid;
|
||||
grid-template-columns: 1.1fr 1.1fr 1fr 1fr 0.9fr;
|
||||
grid-template-columns: 1.1fr 1.1fr 1fr 1fr 0.9fr 2.4fr;
|
||||
gap: 6px;
|
||||
padding: 6px 4px;
|
||||
align-items: center;
|
||||
@@ -972,8 +1249,16 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
.sp-hist-table .sp-hrow {
|
||||
grid-template-columns: 1fr 1fr 1fr 1fr 0.8fr;
|
||||
grid-template-columns: 0.9fr 1fr 0.8fr 0.8fr 0.7fr 2.6fr;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
.sp-hist-table .c-lat {
|
||||
font-family: monospace;
|
||||
font-size: 11.5px;
|
||||
opacity: 0.85;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user