init: api-gateway v2.4.0(Agnes/b.ai/火山方舟 三家供应商网关)
This commit is contained in:
commit
d143d8da22
91 files changed
+24653
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
root: fileURLToPath(new URL('.', import.meta.url)),
|
||||
plugins: [vue()],
|
||||
base: './',
|
||||
build: { outDir: '/tmp/gw-visual-dist', emptyOutDir: true, chunkSizeWarningLimit: 3000 },
|
||||
})
|
||||
@@ -0,0 +1,93 @@
|
||||
# 前端重设计 v2 —— 页面改造规范
|
||||
|
||||
本文件是改造**页面**时必须遵守的约定。基础设施(主题、布局、图标、样式)已经完成,
|
||||
不需要你动。
|
||||
|
||||
## 0. 铁律
|
||||
|
||||
1. **不动业务逻辑。** API 调用、轮询定时器、SSE 流式解析、上传与压缩、localStorage 键名、
|
||||
错误分类、二次确认、权限判断 —— 全部保持与原文件**语义等价**。你只改模板结构与样式。
|
||||
2. **不写硬编码颜色。** 不许出现 `#fff` / `#909399` / `#3b5998` / `rgba(0,0,0,.06)` 这类
|
||||
具体色值(图表除外,图表用 `chartTheme()`)。一律用下面的 CSS 变量。
|
||||
3. **不用 emoji 当图标。** 用 `<Icon name="..." />`。
|
||||
4. **不改 `src/locales/*.ts`。** 文案优先复用已有 key;确实缺 key 时,把
|
||||
「key 路径 + 中文 + English」写进你的最终报告,由主流程统一补。
|
||||
5. **完成后必须跑 `npm run typecheck`,要求 0 error。**
|
||||
|
||||
## 1. 主题 token(src/style.css 已定义,直接用)
|
||||
|
||||
| 变量 | 用途 |
|
||||
| --- | --- |
|
||||
| `--bg` / `--bg-2` | 页面底色(bg 是内容区,bg-2 是最外层) |
|
||||
| `--surface` / `--surface-2` | 卡片底 / 次级底(输入框、只读控件) |
|
||||
| `--line` / `--line-2` | 分隔线(line 明显,line-2 极淡) |
|
||||
| `--text` / `--muted` / `--muted-2` | 主文字 / 次要 / 更淡 |
|
||||
| `--primary` / `--primary-ink` / `--primary-soft` | 主色 / 主色上的字 / 主色淡底 |
|
||||
| `--ok` `--warn` `--err` + `--ok-soft` `--warn-soft` `--err-soft` | 语义色与淡底 |
|
||||
| `--chip` | 灰色小底(标签、胶囊) |
|
||||
| `--radius` / `--radius-s` / `--radius-l` | 12 / 8 / 16 |
|
||||
| `--gap` | 14px 间距 |
|
||||
| `--chart-a` / `--chart-b` | 图表主/辅色(ECharts 用 `chartTheme()` 取) |
|
||||
|
||||
三套主题 A(深空蓝,深色)/ B(素白蓝紫,默认)/ C(暖砂墨绿)会自动切换这些变量,
|
||||
**页面不需要为某个主题写特例**。
|
||||
|
||||
## 2. 页面外壳
|
||||
|
||||
```vue
|
||||
<div class="page">…</div> <!-- 普通滚动页:列表、表单、表格 -->
|
||||
<div class="page-fill">…</div> <!-- 撑满高度的页:Chat / Images / Videos -->
|
||||
```
|
||||
|
||||
`.page` / `.page-fill` 自带 16/20 的内边距,窄屏自动收成 12/14。
|
||||
`.page-fill` 内部需要自己安排「固定区 + 可滚区」。
|
||||
|
||||
**不要再使用** `.main-scroll`、`.page-card`(已删除)、`el-row` + `el-col` 栅格。
|
||||
|
||||
## 3. 现成类(都在 src/style.css)
|
||||
|
||||
- 卡片:`.card`(白底圆角边框)+ `.card-h`(内放 `<b>标题</b>` 和 `<span class="sub">副标题</span>`
|
||||
以及右侧 `.pager`)
|
||||
- KPI:`.kpis`(4 列网格)> `.kpi` > `.k` / `.v` / `.f`;`.delta.up/.down/.flat`;
|
||||
窄屏自动两列
|
||||
- 栅格:`.grid2`(1.55fr 1fr)、`.grid3`(1.35fr 1fr)、`.grid-eq`(1fr 1fr),自带 `margin-top: var(--gap)`
|
||||
- 竖排信息行:`.pv` > `.pv-i` > `.nm` / `.st`;进度条 `.bar` > `i`(`width` 控制)
|
||||
- 状态胶囊:`.pill.ok/.warn/.err/.mute`;徽标 `.badge.g/.o/.r/.m`
|
||||
- 可选中的胶囊:`.chip-sel`(选中加 `.on`)
|
||||
- 表单:`.field`(`<label>` + 控件)、`.form-row`(横向一行)、`.ctl` / `.ctl.area`(只读展示态控件)
|
||||
- 行式设置项:`.set-grid` > `.card` > `.set-row`(左 `.lb`+`.sub`,右 `.rt`)
|
||||
- 主题卡:`.theme-card` / `.theme-prev`
|
||||
- 工具类:`.card-h`、`.muted`、`.muted-2`、`.hint`、`.flex-1`、`.mb`、`.nowrap`、`.code`、`.about-line`、`.sep`
|
||||
- 手机端:`.m-card`、`.seg`(分段控件)、`.m-kpis` / `.m-kpi`、`.m-grid`、`.m-thumb`
|
||||
|
||||
组件(el-*)已经被主题变量接管,**继续用 el-table / el-input / el-select / el-button /
|
||||
el-dialog / el-tag / el-switch / el-form**,不要自己重写交互控件。表格里不要写死颜色。
|
||||
|
||||
## 4. 图标
|
||||
|
||||
```vue
|
||||
import Icon from '../components/Icon.vue'
|
||||
<Icon name="dl" :size="14" />
|
||||
```
|
||||
|
||||
可用 name:`dash chat img vid model metric key users log set menu refresh dl bell plus up
|
||||
theme play eye bolt send chev chevD clip x check copy trash search user link stop filter dots`
|
||||
|
||||
## 5. ECharts
|
||||
|
||||
```ts
|
||||
import { chartTheme, categoryAxis, valueAxis, grid, legend, pieData, pieLabel,
|
||||
pieLabelLine, pieRadius, pieCenter } from '../lib/charts'
|
||||
const { resolved } = useTheme() // computed 里先 void resolved.value,切主题才会重算
|
||||
```
|
||||
|
||||
## 6. 参考实现(先读这三个,照它们的写法来)
|
||||
|
||||
- `src/views/Dashboard.vue` —— 数据页:KPI + 卡片 + 图表 + 表格 + 底部信息条
|
||||
- `src/views/Settings.vue` —— 表单/设置:`.set-grid` + `.set-row` + 行内控件
|
||||
- `src/views/Login.vue` —— 独立页(不在 MainLayout 里,自带整屏布局)
|
||||
|
||||
## 7. 设计稿(视觉基准,按需查阅)
|
||||
|
||||
`design/v2/*.png`(`03-images.png` / `04-videos.png` / `06-keys-users.png` / `07-logs-settings.png`)
|
||||
以及 `design/v2/screens.css`(类名与结构参考)。手机端设计在同一张画板的下半部分。
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>API 网关管理台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1787
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "api-gateway-web",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "npm run check:svg && npm run check:i18n && vite build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"preview": "vite preview",
|
||||
"check:svg": "node scripts/check-svg.mjs",
|
||||
"check:i18n": "node scripts/check-i18n.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"dompurify": "^3.4.15",
|
||||
"echarts": "^6.1.0",
|
||||
"element-plus": "^2.9.1",
|
||||
"highlight.js": "^11.12.0",
|
||||
"marked": "^18.0.12",
|
||||
"marked-highlight": "^2.2.4",
|
||||
"pinia": "^2.2.6",
|
||||
"vue": "^3.5.13",
|
||||
"vue-i18n": "^9.14.5",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"typescript": "^5.7.2",
|
||||
"vite": "^6.0.7",
|
||||
"vue-tsc": "^2.2.12"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// 文案体检(build 前置校验,第二十三轮补)
|
||||
//
|
||||
// 为什么需要它:vue-i18n 把文案里的 {...} 当占位符解析。踩过的坑 —— 一条提示文案写了
|
||||
// `{"status":"ok"}`,编译器把它当占位符、报 "Invalid token in placeholder",而这条错误
|
||||
// 是"渲染时才编译"时抛的:用到这条文案的整块界面直接不渲染,控制台里也只是一条 Vue 错误,
|
||||
// 表现看起来像"这个页签/卡片挂了"(当时误判成 Element Plus 的 pane 机制问题,查了两轮)。
|
||||
// 现在 build 前先把两份文案逐条过一遍,类似的写法在构建阶段就被拦下。
|
||||
//
|
||||
// 另外顺手核三件小事(都是会出现"界面里冒出 nav.xxx 原始键名"的原因):
|
||||
// 1. 中英两份键完全对称;2. 同一个对象里没有重复键;3. 没有空文案。
|
||||
//
|
||||
// 只依赖 Node 内置模块:不引第三方解析器,规则显式写在下面,谁都能看懂。
|
||||
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const ROOT = path.resolve(import.meta.dirname, '..')
|
||||
const FILES = { zh: 'src/locales/zh.ts', en: 'src/locales/en.ts' }
|
||||
|
||||
// 占位符第一个字符的合法集合:{name} {0} {n} {@.upper:name} {'字面量'} {-1}
|
||||
const OK_FIRST = /[A-Za-z0-9_$@'\u4e00-\u9fa5-]/
|
||||
|
||||
/** 逐行解析 locale 文件(2 空格缩进 + `key: '...'`)→ { `a.b.c`: [值, 行号] } */
|
||||
function parseLocale(file) {
|
||||
const out = new Map()
|
||||
const dup = []
|
||||
const stack = [] // [{ indent, key }]
|
||||
const abs = path.join(ROOT, file)
|
||||
const lines = fs.readFileSync(abs, 'utf8').split('\n')
|
||||
|
||||
lines.forEach((raw, i) => {
|
||||
const line = raw.replace(/\s+$/, '')
|
||||
const m = line.match(/^(\s*)([A-Za-z0-9_$]+):\s*(.*)$/)
|
||||
if (!m) return
|
||||
const indent = m[1].length
|
||||
const key = m[2]
|
||||
const rest = m[3]
|
||||
while (stack.length && stack[stack.length - 1].indent >= indent) stack.pop()
|
||||
if (rest === '{') { // 开一个子对象
|
||||
stack.push({ indent, key })
|
||||
return
|
||||
}
|
||||
// 字符串值(单/双引号都认;允许行尾逗号)。注意要认得"这条文案里带 {'{'} 字面量花括号时
|
||||
// 只能用双引号写"的情况,否则这条文案会被跳过、体检等于没查。
|
||||
const sm = rest.match(/^(['"])(.*)\1(,?)$/)
|
||||
if (!sm) return // 其它形态(注释、非字符串)不检查
|
||||
const full = [...stack.map((s) => s.key), key].join('.')
|
||||
if (out.has(full)) dup.push(`${full}(第 ${out.get(full)[1]} 行 与 第 ${i + 1} 行)`)
|
||||
else out.set(full, [unescape(sm[2]), i + 1])
|
||||
})
|
||||
return { map: out, dup }
|
||||
}
|
||||
|
||||
function unescape(s) {
|
||||
return s.replace(/\\(.)/g, (_, c) => (c === 'n' ? '\n' : c))
|
||||
}
|
||||
|
||||
/** 扫一条文案里的花括号,返回问题列表 */
|
||||
function checkBraces(value) {
|
||||
const bad = []
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const ch = value[i]
|
||||
if (ch === '}') { bad.push('有一个多余的 }'); continue }
|
||||
if (ch !== '{') continue
|
||||
const next = value[i + 1]
|
||||
if (next === undefined) { bad.push('{ 没有收尾的 }'); continue }
|
||||
if (!OK_FIRST.test(next)) {
|
||||
bad.push(`{ 后面跟着 ${JSON.stringify(value.slice(i, i + 20))} —— vue-i18n 会把 {...} 当占位符,` +
|
||||
`花括号要写成 {'{'} / {'}'} 才能当普通字符用`)
|
||||
continue
|
||||
}
|
||||
// 找到配对的 },期间不允许再出现 {(vue-i18n 不支持嵌套占位符)
|
||||
let j = i + 1
|
||||
let quoted = false
|
||||
for (; j < value.length; j++) {
|
||||
const c = value[j]
|
||||
if (c === "'") quoted = !quoted
|
||||
else if (!quoted && c === '{') { bad.push(`占位符里又出现了 {(不支持嵌套):${JSON.stringify(value.slice(i, j + 10))}`); break }
|
||||
else if (!quoted && c === '}') break
|
||||
}
|
||||
if (j >= value.length) { bad.push(`{ 没有收尾的 }:${JSON.stringify(value.slice(i, i + 20))}`); continue }
|
||||
if (j === i + 1) bad.push('{} 是空占位符')
|
||||
i = j
|
||||
}
|
||||
return bad
|
||||
}
|
||||
|
||||
const problems = []
|
||||
const parsed = {}
|
||||
|
||||
for (const [lang, file] of Object.entries(FILES)) {
|
||||
const { map, dup } = parseLocale(file)
|
||||
parsed[lang] = map
|
||||
for (const d of dup) problems.push(`${file} 重复键:${d}`)
|
||||
for (const [k, [v, line]] of map) {
|
||||
if (!v.trim()) problems.push(`${file}:${line} ${k} 是空文案`)
|
||||
for (const b of checkBraces(v)) problems.push(`${file}:${line} ${k} —— ${b}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 中英对称
|
||||
const zhKeys = new Set(parsed.zh.keys())
|
||||
const enKeys = new Set(parsed.en.keys())
|
||||
for (const k of zhKeys) if (!enKeys.has(k)) problems.push(`en 少了键:${k}(中文写好了英文没写 → 英文界面会显示这个原始键名)`)
|
||||
for (const k of enKeys) if (!zhKeys.has(k)) problems.push(`zh 少了键:${k}(英文写好了中文没写 → 中文界面会显示这个原始键名)`)
|
||||
|
||||
if (problems.length) {
|
||||
console.error(`\n✗ 文案体检不通过(${problems.length} 个问题):`)
|
||||
for (const p of problems) console.error(' - ' + p)
|
||||
console.error('\n改完再 build。\n')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(`✓ 文案体检通过:中 ${zhKeys.size} 条 / 英 ${enKeys.size} 条,键对称、无重复、占位符语法正常`)
|
||||
@@ -0,0 +1,47 @@
|
||||
// 静态资源自检:把 src/assets 下的 SVG 逐个按 XML 解析一遍。
|
||||
//
|
||||
// 为什么需要:SVG 里只要出现一处 XML 级错误(最典型的是注释里写了 CSS 变量名,
|
||||
// 也就是连续两个连字符 —— XML 注释不允许这个序列),浏览器就会整张图静默不画:
|
||||
// 页面不报错、控制台没有明显线索,只表现为「改完看起来什么都没变」。
|
||||
// 这个坑踩过一次,所以放进 build 前置步骤,坏了就构建失败,别再靠肉眼发现。
|
||||
import { readdirSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const dir = join(process.cwd(), 'src', 'assets')
|
||||
let files = []
|
||||
try {
|
||||
files = readdirSync(dir).filter((f) => f.toLowerCase().endsWith('.svg'))
|
||||
} catch {
|
||||
console.log('[check-svg] 没有 src/assets 目录,跳过')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const problems = []
|
||||
for (const f of files) {
|
||||
const text = readFileSync(join(dir, f), 'utf8')
|
||||
// ① 注释里出现连续两个连字符 —— XML 规范禁止,浏览器直接放弃整张图
|
||||
for (const m of text.matchAll(/<!--([\s\S]*?)-->/g)) {
|
||||
if (m[1].includes('--')) problems.push(`${f}: 注释里出现了连续两个连字符(XML 注释不允许)`)
|
||||
}
|
||||
// ② 标签配平与属性引号这类硬伤,用一个极简栈式检查兜住
|
||||
const stripped = text.replace(/<!--[\s\S]*?-->/g, '').replace(/<\?[\s\S]*?\?>/g, '')
|
||||
const stack = []
|
||||
for (const m of stripped.matchAll(/<(\/?)([A-Za-z][\w:.-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)(\/?)>/g)) {
|
||||
const [, close, name, , selfClose] = m
|
||||
if (close) {
|
||||
const top = stack.pop()
|
||||
if (top !== name) problems.push(`${f}: 标签不匹配(</${name}> 对应的是 <${top || '空'}>)`)
|
||||
} else if (!selfClose) {
|
||||
stack.push(name)
|
||||
}
|
||||
}
|
||||
if (stack.length) problems.push(`${f}: 有未闭合的标签 ${stack.join(', ')}`)
|
||||
if (!/<svg[\s>]/.test(text)) problems.push(`${f}: 找不到 <svg> 根标签`)
|
||||
}
|
||||
|
||||
if (problems.length) {
|
||||
console.error('[check-svg] 检查未通过:')
|
||||
for (const p of problems) console.error(' - ' + p)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`[check-svg] ${files.length} 个 SVG 全部通过(${files.join(', ')})`)
|
||||
@@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<!-- M5+: Element Plus 组件语言包跟随界面语言(分页/日期等文案中英对齐) -->
|
||||
<el-config-provider :locale="elLocale">
|
||||
<el-config-provider :z-index="3000">
|
||||
<router-view />
|
||||
</el-config-provider>
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
|
||||
import en from 'element-plus/dist/locale/en.mjs'
|
||||
|
||||
const { locale } = useI18n()
|
||||
const elLocale = computed(() => (locale.value === 'en' ? en : zhCn))
|
||||
</script>
|
||||
@@ -0,0 +1,95 @@
|
||||
// 与网关同源的请求层:所有调用带登录后换来的 sess- token。
|
||||
// M5+: 登录改用账号密码(账号密码只在 /auth/login 提交一次,之后前端不持有明文口令)。
|
||||
|
||||
export const TOKEN_KEY = 'gw_token'
|
||||
export const USER_KEY = 'gw_user'
|
||||
export const ROLE_KEY = 'gw_role'
|
||||
|
||||
export function getToken(): string {
|
||||
return localStorage.getItem(TOKEN_KEY) || ''
|
||||
}
|
||||
|
||||
export function setToken(token: string, user: string, role = ''): void {
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
localStorage.setItem(USER_KEY, user || '')
|
||||
localStorage.setItem(ROLE_KEY, role || '')
|
||||
}
|
||||
|
||||
export function clearToken(): void {
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
localStorage.removeItem(USER_KEY)
|
||||
localStorage.removeItem(ROLE_KEY)
|
||||
}
|
||||
|
||||
/** 从错误响应体里取出人能看懂的原因。
|
||||
|
||||
网关自己抛的 HTTPException 一律是 OpenAI 形状 `{"error":{"message":"账号已被停用,请联系管理员"}}`,
|
||||
而 FastAPI 原生的才是 `{"detail": ...}`。以前各页面只读 `body.detail`,于是网关的报错全被
|
||||
吞成「HTTP 400 / HTTP 403」—— 这里统一认两种信封,页面拿 e.message 就能直接展示。
|
||||
结构化 detail(如路由失败时的 {message, errors[]})取其中的 message。 */
|
||||
function errorMessage(body: any): string {
|
||||
if (!body) return ''
|
||||
if (typeof body === 'string') return body
|
||||
const d = body.detail
|
||||
if (typeof d === 'string') return d
|
||||
if (d && typeof d === 'object') return String(d.message || '')
|
||||
const m = body.error && body.error.message
|
||||
return m ? String(m) : ''
|
||||
}
|
||||
|
||||
/** 把捕获到的错误转成一句可展示的文案(页面 toast / 提示条直接用)。 */
|
||||
export function errText(e: any): string {
|
||||
return errorMessage(e?.body) || (e && e.message) || String(e ?? '')
|
||||
}
|
||||
|
||||
/** 账号密码登录 → 会话 token(登录唯一入口)。 */
|
||||
export async function login(username: string, password: string): Promise<any> {
|
||||
const resp = await fetch('/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password }),
|
||||
})
|
||||
const body = await parse(resp)
|
||||
if (!resp.ok) {
|
||||
// 与 api() 同形:抛 Error(带 status / body),message 里放服务端的真实原因
|
||||
const err: any = new Error(errorMessage(body) || `HTTP ${resp.status}`)
|
||||
err.status = resp.status
|
||||
err.body = body
|
||||
throw err
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
/** 通用网关调用(自动带会话 Bearer)。 */
|
||||
export async function api(path: string, opts: any = {}): Promise<any> {
|
||||
const headers: Record<string, string> = Object.assign(
|
||||
{ 'Content-Type': 'application/json' },
|
||||
opts.headers || {},
|
||||
)
|
||||
const token = getToken()
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
const resp = await fetch(path, Object.assign({}, opts, { headers }))
|
||||
const body = await parse(resp)
|
||||
if (!resp.ok) {
|
||||
// 会话过期:清空本地 token 并广播,让界面回登录页重新登录(避免 401/429 死循环)
|
||||
if (resp.status === 401 && getToken()) {
|
||||
clearToken()
|
||||
window.dispatchEvent(new Event('gw-auth-expired'))
|
||||
}
|
||||
const err: any = new Error(errorMessage(body) || `HTTP ${resp.status}`)
|
||||
err.status = resp.status
|
||||
err.body = body
|
||||
throw err
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
async function parse(resp: Response): Promise<any> {
|
||||
const text = await resp.text()
|
||||
if (!text) return null
|
||||
try {
|
||||
return JSON.parse(text)
|
||||
} catch {
|
||||
return text
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 420" width="1600" height="420" preserveAspectRatio="xMidYMid slice">
|
||||
<!--
|
||||
登录页背景图(图形层):科技抽象风。只画白色的低透明度形状,底色由 CSS 用主题 token 铺渐变
|
||||
(主题主色 → 页面底色,外加主题图表色的光晕),所以 A/B/C 三套主题自动对色,本文件不用改。
|
||||
不引任何外链资源。
|
||||
|
||||
注意:本文件里不能出现连续两个连字符(注释里写 CSS 变量名时最容易犯)—— XML 注释
|
||||
不允许这个序列,写了整个 SVG 会直接解析失败、图层静默不画(踩过一次:改完看起来「什么都没变」)。
|
||||
|
||||
构图要同时过两种裁切,所以「哪里能画」要按两种场景算:
|
||||
· 桌面端:图铺在顶部通栏,登录卡水平居中、压在图中部 —— 卡片上沿大约对应图里 y≈300~360,
|
||||
也就是「y < 300 全宽可见,y > 330 只剩两侧窄条」;x 150~1450 的中部下方会被卡片盖住。
|
||||
· 窄屏:色块只有 ~390×270,cover 之后左右各裁掉一大截 —— 只剩下图里 x 494~1105 的中间一列,
|
||||
但纵向 0~420 全可见。
|
||||
两条取交集:主要图形放在 **y 40~300 的中间带**,两侧(x<150 / x>1450)只用低密度的散射节点点缀。
|
||||
|
||||
透明度口径:这套形状是叠在「主色底 + 压深层」之上的,实测太淡会整张图只剩渐变、
|
||||
完全看不出科技感(第一版就是这样),所以形状的不透明度按「肉眼能在深底和浅底上都看清」来定。
|
||||
-->
|
||||
<defs>
|
||||
<radialGradient id="glow" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stop-color="#FFFFFF" stop-opacity=".26"/>
|
||||
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="core" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stop-color="#FFFFFF" stop-opacity=".34"/>
|
||||
<stop offset="65%" stop-color="#FFFFFF" stop-opacity=".1"/>
|
||||
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<linearGradient id="beam" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#FFFFFF" stop-opacity=".22"/>
|
||||
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
<pattern id="grid" width="46" height="46" patternUnits="userSpaceOnUse">
|
||||
<path d="M46 0 H0 V46" fill="none" stroke="#FFFFFF" stroke-width="1" opacity=".8"/>
|
||||
</pattern>
|
||||
<pattern id="dots" width="46" height="46" patternUnits="userSpaceOnUse">
|
||||
<circle cx="2" cy="2" r="1.6" fill="#FFFFFF" opacity=".5"/>
|
||||
</pattern>
|
||||
</defs>
|
||||
|
||||
<!-- ① 底纹:方格网 + 交错点阵(均匀铺满,任何裁切下都是一层「技术感」肌理) -->
|
||||
<rect width="1600" height="420" fill="url(#grid)" opacity=".22"/>
|
||||
<rect width="1600" height="420" fill="url(#dots)" opacity=".7"/>
|
||||
|
||||
<!-- ② 光带:两道自左上斜下的柔光,给画面一点方向感和纵深 -->
|
||||
<g>
|
||||
<polygon points="300,0 442,0 148,420 6,420" fill="url(#beam)"/>
|
||||
<polygon points="1078,0 1196,0 918,420 800,420" fill="url(#beam)"/>
|
||||
</g>
|
||||
|
||||
<!-- ③ 柔光团:把纯色底压出体积感 -->
|
||||
<circle cx="196" cy="40" r="300" fill="url(#glow)"/>
|
||||
<circle cx="1404" cy="96" r="280" fill="url(#glow)"/>
|
||||
|
||||
<!-- ④ 中心「核心」母题:同心环 + 六边形 + 六向辐射。放图中部安全带,
|
||||
桌面端在卡片上沿之上、窄屏正好落在色块正中,两种裁切都有主视觉。 -->
|
||||
<g transform="translate(800 232)">
|
||||
<circle r="150" fill="url(#core)"/>
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle r="124" opacity=".18" stroke-width="1"/>
|
||||
<circle r="86" opacity=".26" stroke-width="1" stroke-dasharray="7 9"/>
|
||||
<circle r="48" opacity=".36" stroke-width="1.3"/>
|
||||
<circle r="16" opacity=".44" stroke-width="1.5"/>
|
||||
<polygon points="0,-25 21.7,-12.5 21.7,12.5 0,25 -21.7,12.5 -21.7,-12.5" opacity=".42" stroke-width="1.3"/>
|
||||
</g>
|
||||
<circle r="6" fill="#FFFFFF" opacity=".75"/>
|
||||
<!-- 六向辐射短线 + 端点 -->
|
||||
<g stroke="#FFFFFF" stroke-width="1.3" opacity=".4">
|
||||
<path d="M0,-48 V-66"/><path d="M41.6,24 L56.5,32.6"/><path d="M-41.6,24 L-56.5,32.6"/>
|
||||
<path d="M0,48 V66"/><path d="M41.6,-24 L56.5,-32.6"/><path d="M-41.6,-24 L-56.5,-32.6"/>
|
||||
</g>
|
||||
<g fill="#FFFFFF" opacity=".6">
|
||||
<circle cx="0" cy="-70" r="3.2"/><circle cx="60.6" cy="35" r="3.2"/><circle cx="-60.6" cy="35" r="3.2"/>
|
||||
<circle cx="0" cy="70" r="3.2"/><circle cx="60.6" cy="-35" r="3.2"/><circle cx="-60.6" cy="-35" r="3.2"/>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- ⑤ 星座网络:节点 + 连线,铺在 y 40~200 的横带里(桌面端在卡片之上,窄屏在色块上部) -->
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="1.3" opacity=".4">
|
||||
<path d="M112 118 L232 58 L372 158 L512 92 L648 42"/>
|
||||
<path d="M512 92 L648 42 L800 74 L958 44 L1092 126"/>
|
||||
<path d="M1092 126 L1228 62 L1382 146 L1512 84"/>
|
||||
<path d="M112 118 L64 286 M372 158 L232 58 M1228 62 L1400 296 M1382 146 L1540 226"/>
|
||||
</g>
|
||||
<g fill="#FFFFFF">
|
||||
<circle cx="112" cy="118" r="4.4" opacity=".72"/>
|
||||
<circle cx="232" cy="58" r="3.6" opacity=".62"/>
|
||||
<circle cx="372" cy="158" r="4.4" opacity=".72"/>
|
||||
<circle cx="512" cy="92" r="3.6" opacity=".62"/>
|
||||
<circle cx="648" cy="42" r="4.4" opacity=".72"/>
|
||||
<circle cx="958" cy="44" r="3.6" opacity=".62"/>
|
||||
<circle cx="1092" cy="126" r="4.4" opacity=".72"/>
|
||||
<circle cx="1228" cy="62" r="3.6" opacity=".62"/>
|
||||
<circle cx="1382" cy="146" r="4.4" opacity=".72"/>
|
||||
<circle cx="1512" cy="84" r="3.6" opacity=".62"/>
|
||||
<circle cx="64" cy="286" r="3.6" opacity=".5"/>
|
||||
<circle cx="1400" cy="296" r="3.6" opacity=".5"/>
|
||||
<circle cx="1540" cy="226" r="3.2" opacity=".46"/>
|
||||
</g>
|
||||
<!-- 三个「发光节点」:给网络一点层次(外圈淡、内点实) -->
|
||||
<g fill="none" stroke="#FFFFFF" opacity=".32">
|
||||
<circle cx="232" cy="58" r="15"/><circle cx="1092" cy="126" r="15"/><circle cx="1382" cy="146" r="13"/>
|
||||
</g>
|
||||
|
||||
<!-- ⑥ 右上角轨道环(多半在画外,只露弧线,收边用) -->
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle cx="1330" cy="24" r="264" opacity=".14" stroke-width="1"/>
|
||||
<circle cx="1330" cy="24" r="190" opacity=".2" stroke-width="1" stroke-dasharray="4 10"/>
|
||||
<circle cx="1330" cy="24" r="122" opacity=".28" stroke-width="1.3"/>
|
||||
</g>
|
||||
<g fill="#FFFFFF" opacity=".55">
|
||||
<circle cx="1330" cy="-98" r="4"/><circle cx="1152" cy="112" r="3.2"/><circle cx="1450" cy="140" r="3.2"/>
|
||||
</g>
|
||||
|
||||
<!-- ⑦ 左下角弧线 + 十字标记:收另一侧的边,别让画面只有上方有东西 -->
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle cx="28" cy="452" r="238" opacity=".16" stroke-width="1"/>
|
||||
<circle cx="28" cy="452" r="176" opacity=".22" stroke-width="1" stroke-dasharray="6 9"/>
|
||||
</g>
|
||||
<g stroke="#FFFFFF" stroke-width="1.5" opacity=".42">
|
||||
<path d="M292,318 h18 M301,309 v18"/>
|
||||
<path d="M1332,330 h16 M1340,322 v16"/>
|
||||
<path d="M668,352 h16 M676,344 v16"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 7.0 KiB |
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<div ref="el" class="echart" :style="{ height: height }"></div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { echarts, type EChartsCoreOption } from '../lib/echarts'
|
||||
|
||||
const props = defineProps<{
|
||||
option: EChartsCoreOption
|
||||
height?: string
|
||||
}>()
|
||||
|
||||
const el = ref<HTMLElement>()
|
||||
let chart: any = null
|
||||
let ro: ResizeObserver | null = null
|
||||
|
||||
function setOpt() {
|
||||
if (chart) chart.setOption(props.option || {}, true)
|
||||
}
|
||||
function resize() { if (chart) chart.resize() }
|
||||
|
||||
onMounted(() => {
|
||||
chart = echarts.init(el.value!)
|
||||
setOpt()
|
||||
if (typeof ResizeObserver !== 'undefined') {
|
||||
ro = new ResizeObserver(resize)
|
||||
ro.observe(el.value!)
|
||||
}
|
||||
})
|
||||
watch(() => props.option, setOpt, { deep: true })
|
||||
onUnmounted(() => {
|
||||
if (ro) ro.disconnect()
|
||||
if (chart) { chart.dispose(); chart = null }
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.echart { width: 100%; }
|
||||
</style>
|
||||
@@ -0,0 +1,76 @@
|
||||
<template>
|
||||
<!-- 反馈附图:缩略图内嵌(服务端 JSON 里带着),点开才去取原图 —— 列表页因此零额外请求。 -->
|
||||
<div v-if="item.images && item.images.length" class="fb-imgs">
|
||||
<button
|
||||
v-for="(im, i) in item.images"
|
||||
:key="i"
|
||||
class="fb-th"
|
||||
type="button"
|
||||
:title="im.name || t('inbox.preview')"
|
||||
@click="open(i)"
|
||||
>
|
||||
<img v-if="im.thumb" :src="im.thumb" :alt="im.name || 'feedback image'" />
|
||||
<span v-else class="ph"><Icon name="img" :size="16" /></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="show" :title="title" width="min(860px, 92vw)">
|
||||
<div class="fb-full">
|
||||
<div v-if="loading" class="hint">{{ t('inbox.loading') }}</div>
|
||||
<img v-else-if="full" :src="full" alt="feedback image" />
|
||||
<div v-else class="hint">{{ t('inbox.loadFail') }}</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Icon from './Icon.vue'
|
||||
import { feedbackImage, type FeedbackItem } from '../lib/feedback'
|
||||
|
||||
const props = defineProps<{ item: FeedbackItem }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const show = ref(false)
|
||||
const loading = ref(false)
|
||||
const full = ref('')
|
||||
const title = ref('')
|
||||
|
||||
/** 同一张图重复点开时复用已取到的 data URI,别反复要同一份数据。 */
|
||||
const cache = new Map<number, string>()
|
||||
|
||||
async function open(idx: number) {
|
||||
const im = props.item.images[idx]
|
||||
const kb = im && im.bytes ? `${Math.round(im.bytes / 1024)}KB` : ''
|
||||
title.value = [im?.name || t('inbox.preview'), kb].filter(Boolean).join(' · ')
|
||||
show.value = true
|
||||
if (cache.has(idx)) {
|
||||
full.value = cache.get(idx) as string
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
full.value = ''
|
||||
try {
|
||||
const uri = await feedbackImage(props.item.id, idx)
|
||||
cache.set(idx, uri)
|
||||
full.value = uri
|
||||
} catch {
|
||||
full.value = ''
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fb-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
|
||||
.fb-th {
|
||||
width: 84px; height: 84px; padding: 0; border: 1px solid var(--line);
|
||||
border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: zoom-in;
|
||||
}
|
||||
.fb-th img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.fb-th .ph { display: grid; place-items: center; width: 100%; height: 100%; color: var(--muted-2); }
|
||||
.fb-full { display: grid; place-items: center; min-height: 120px; }
|
||||
.fb-full img { max-width: 100%; max-height: 68vh; border-radius: 10px; display: block; }
|
||||
</style>
|
||||
@@ -0,0 +1,97 @@
|
||||
<template>
|
||||
<!--
|
||||
处理记录时间线(第二十二轮追加):提交 + 每一次状态变更,old → new 逐条列出。
|
||||
提交人和管理员看到的是**同一串记录**(服务端 history 原样下发),不各算各的。
|
||||
|
||||
超过 LIMIT 条时默认只显示最后几条(最新的处理动作最重要),点开看全部。
|
||||
-->
|
||||
<div v-if="steps.length" class="tl">
|
||||
<div class="tl-h">
|
||||
<span>{{ t('fbLog.title') }}</span>
|
||||
<span class="cnt">{{ steps.length }}</span>
|
||||
</div>
|
||||
<ol class="tl-list">
|
||||
<li v-for="(s, i) in shown" :key="i" class="tl-i" :class="s.to">
|
||||
<span class="dot" />
|
||||
<!-- 第一格是「提交」(没有上一个状态);后面每格是「改到哪个状态 ← 原来是什么」 -->
|
||||
<span class="lbl">{{ s.from ? t(`fbStatus.${s.to}`) : t('fbLog.submitted') }}</span>
|
||||
<span v-if="s.from && s.from !== s.to" class="from">← {{ t(`fbStatus.${s.from}`) }}</span>
|
||||
<span v-if="s.by" class="who">{{ s.by }}</span>
|
||||
<span class="spacer" />
|
||||
<span class="ts">{{ fmt(s.ts) }}</span>
|
||||
<div v-if="s.note" class="note">{{ s.note }}</div>
|
||||
</li>
|
||||
</ol>
|
||||
<button v-if="steps.length > LIMIT" class="more" type="button" @click="expanded = !expanded">
|
||||
{{ expanded ? t('fbLog.less') : t('fbLog.more', { n: steps.length }) }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { FeedbackItem } from '../lib/feedback'
|
||||
|
||||
const props = defineProps<{ item: FeedbackItem }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const LIMIT = 4 // 默认最多显示 4 条(再长就折叠)
|
||||
const expanded = ref(false)
|
||||
|
||||
const steps = computed(() => props.item.history || [])
|
||||
const shown = computed(() => (expanded.value ? steps.value : steps.value.slice(-LIMIT)))
|
||||
|
||||
function fmt(ts: number): string {
|
||||
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())}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tl { margin-top: 12px; }
|
||||
.tl-h { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
|
||||
.tl-h .cnt {
|
||||
min-width: 16px; padding: 0 4px; border-radius: 6px; text-align: center;
|
||||
background: var(--chip); color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.tl-list { list-style: none; margin: 10px 0 0; padding: 0 0 0 2px; }
|
||||
.tl-i {
|
||||
position: relative; display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px;
|
||||
padding: 0 0 15px 20px; font-size: 11.5px; color: var(--muted); line-height: 1.5;
|
||||
}
|
||||
/* 竖线串起每一步:最后一条不再往下画 */
|
||||
.tl-i::before {
|
||||
content: ''; position: absolute; left: 5px; top: 7px; bottom: 0;
|
||||
width: 1px; background: var(--line);
|
||||
}
|
||||
.tl-i:last-child::before { display: none; }
|
||||
.dot {
|
||||
position: absolute; left: 2px; top: 5px; width: 7px; height: 7px; border-radius: 50%;
|
||||
background: var(--muted-2);
|
||||
}
|
||||
.tl-i.pending .dot { background: var(--warn, #d99b3a); }
|
||||
.tl-i.doing .dot { background: var(--primary); }
|
||||
.tl-i.done .dot { background: var(--ok, #3aa76d); }
|
||||
.tl-i .lbl { color: var(--text); font-weight: 600; }
|
||||
.tl-i .from { color: var(--muted-2); }
|
||||
.tl-i .who {
|
||||
padding: 0 5px; border-radius: 6px; background: var(--chip); color: var(--muted); font-size: 10.5px;
|
||||
}
|
||||
.tl-i .spacer { flex: 1; }
|
||||
.tl-i .ts { color: var(--muted-2); font-size: 10.5px; font-variant-numeric: tabular-nums; }
|
||||
/* 说明:左侧主题色竖线,和正文区分开("官方回复了"一眼可见) */
|
||||
.tl-i .note {
|
||||
flex: 1 0 100%; margin-top: 10px; padding: 8px 12px;
|
||||
border-left: 2px solid var(--primary); background: var(--primary-soft);
|
||||
border-radius: 0 8px 8px 0; color: var(--text); font-size: 11.5px;
|
||||
line-height: 1.62; word-break: break-word; white-space: pre-wrap;
|
||||
}
|
||||
.more {
|
||||
margin: 0 0 2px 16px; padding: 0; border: 0; background: none; cursor: pointer;
|
||||
color: var(--primary); font-size: 11.5px;
|
||||
}
|
||||
.more:hover { text-decoration: underline; }
|
||||
</style>
|
||||
@@ -0,0 +1,76 @@
|
||||
<template>
|
||||
<!-- 线性几何图标:跨设备字形不变(emoji 在 Windows/Android 上长得完全不一样)。 -->
|
||||
<svg
|
||||
:width="size"
|
||||
:height="size"
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
:stroke-width="stroke"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="gw-icon"
|
||||
aria-hidden="true"
|
||||
v-html="body"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{ name: string; size?: number; stroke?: number }>(), {
|
||||
size: 18,
|
||||
stroke: 1.7,
|
||||
})
|
||||
|
||||
// 图标表:键为语义名,值为 20×20 视框内的路径。与设计稿同一套几何。
|
||||
const ICONS: Record<string, string> = {
|
||||
dash: '<rect x="3" y="3" width="6.2" height="6.2" rx="1.8"/><rect x="10.8" y="3" width="6.2" height="6.2" rx="1.8"/><rect x="3" y="10.8" width="6.2" height="6.2" rx="1.8"/><rect x="10.8" y="10.8" width="6.2" height="6.2" rx="1.8"/>',
|
||||
chat: '<path d="M3.5 6.2A2.7 2.7 0 0 1 6.2 3.5h7.6a2.7 2.7 0 0 1 2.7 2.7v4.6a2.7 2.7 0 0 1-2.7 2.7H8.6L4.7 16.2v-2.9a2.7 2.7 0 0 1-1.2-2.2z"/>',
|
||||
img: '<rect x="3" y="4" width="14" height="12" rx="2.4"/><circle cx="7.4" cy="8.4" r="1.3"/><path d="M3.6 14.4l4-3.6 2.8 2.4 2.9-2.6 3.1 2.8"/>',
|
||||
vid: '<rect x="2.6" y="5" width="14.8" height="10" rx="2.4"/><path d="M8.6 8l3.6 2-3.6 2z"/>',
|
||||
model: '<path d="M10 3l6.6 3.6L10 10.2 3.4 6.6z"/><path d="M3.4 10.6L10 14.2l6.6-3.6"/><path d="M3.4 14L10 17.6 16.6 14"/>',
|
||||
metric: '<path d="M4 16.4V10"/><path d="M8 16.4V4.6"/><path d="M12 16.4v-4.2"/><path d="M16 16.4V7.4"/>',
|
||||
key: '<circle cx="6.6" cy="10" r="3.1"/><path d="M9.4 10h7"/><path d="M14.6 10v2.6"/><path d="M16.6 10v2"/>',
|
||||
users: '<circle cx="8" cy="7.4" r="2.9"/><path d="M3.4 16.2c0-2.6 2-4.2 4.6-4.2s4.6 1.6 4.6 4.2"/><path d="M13.6 5.5a2.9 2.9 0 0 1 0 5.2"/><path d="M14.6 12.4c1.7.6 2.9 1.9 2.9 3.8"/>',
|
||||
log: '<rect x="3.4" y="3.4" width="13.2" height="13.2" rx="2.4"/><path d="M6.6 8h6.8"/><path d="M6.6 11h6.8"/><path d="M6.6 14h4"/>',
|
||||
set: '<path d="M3.6 6.2h12.8"/><path d="M3.6 10h12.8"/><path d="M3.6 13.8h12.8"/><circle cx="7.4" cy="6.2" r="1.7"/><circle cx="13" cy="10" r="1.7"/><circle cx="8.8" cy="13.8" r="1.7"/>',
|
||||
menu: '<path d="M3.6 6h12.8"/><path d="M3.6 10h12.8"/><path d="M3.6 14h12.8"/>',
|
||||
refresh: '<path d="M16.2 8.6A6.4 6.4 0 1 0 16 12.6"/><path d="M16.6 3.6v4.4h-4.4"/>',
|
||||
dl: '<path d="M10 3.6v8"/><path d="M6.6 8.8L10 12.2l3.4-3.4"/><path d="M4.4 15.8h11.2"/>',
|
||||
bell: '<path d="M10 3.4A4.4 4.4 0 0 1 14.4 8c0 3 .8 4 1.3 4.6H4.3C4.8 12 5.6 11 5.6 8A4.4 4.4 0 0 1 10 3.4z"/><path d="M8.4 15.6a1.7 1.7 0 0 0 3.2 0"/>',
|
||||
plus: '<path d="M10 4.6v10.8"/><path d="M4.6 10h10.8"/>',
|
||||
up: '<path d="M10 15.6V4.8"/><path d="M5.6 9.2L10 4.8l4.4 4.4"/>',
|
||||
theme: '<circle cx="10" cy="10" r="6.8"/><circle cx="7.4" cy="8.2" r="1.05" fill="currentColor"/><circle cx="12.6" cy="8.2" r="1.05" fill="currentColor"/><circle cx="10" cy="12.8" r="1.05" fill="currentColor"/>',
|
||||
play: '<circle cx="10" cy="10" r="7"/><path d="M8.4 7.4l4.6 2.6-4.6 2.6z"/>',
|
||||
eye: '<path d="M2.6 10S5.4 5.4 10 5.4 17.4 10 17.4 10 14.6 14.6 10 14.6 2.6 10 2.6 10z"/><circle cx="10" cy="10" r="2.2"/>',
|
||||
bolt: '<path d="M11.6 2.2 4.8 11.1h4.3L8.7 17.8l6.9-9.3h-4.4z"/>',
|
||||
send: '<path d="M17 3 3.4 8.8l4.9 2.3L11 16.8z"/><path d="M17 3l-8.7 8.1"/>',
|
||||
chev: '<path d="M7.6 4.6 13 10l-5.4 5.4"/>',
|
||||
chevD: '<path d="M4.6 7.6 10 13l5.4-5.4"/>',
|
||||
clip: '<path d="M13.4 8.6 8 14a2.6 2.6 0 0 1-3.7-3.7l7-7a1.8 1.8 0 0 1 2.6 2.6l-7 7"/>',
|
||||
x: '<path d="M5.2 5.2l9.6 9.6"/><path d="M14.8 5.2l-9.6 9.6"/>',
|
||||
check: '<path d="M4.6 10.6l3.4 3.4 7.4-8"/>',
|
||||
copy: '<rect x="7" y="7" width="9.4" height="9.4" rx="2"/><path d="M13 4.4a1.8 1.8 0 0 0-1.8-1.8H5.4A1.8 1.8 0 0 0 3.6 4.4v5.8A1.8 1.8 0 0 0 5.4 12"/>',
|
||||
trash: '<path d="M4.4 6h11.2"/><path d="M8 6V4.6a1.2 1.2 0 0 1 1.2-1.2h1.6A1.2 1.2 0 0 1 12 4.6V6"/><path d="M5.8 6l.7 9.2a1.4 1.4 0 0 0 1.4 1.3h4.2a1.4 1.4 0 0 0 1.4-1.3L14.2 6"/>',
|
||||
search: '<circle cx="9" cy="9" r="5.2"/><path d="M12.9 12.9 17 17"/>',
|
||||
user: '<circle cx="10" cy="7" r="3.2"/><path d="M4 17c0-3 2.7-4.8 6-4.8s6 1.8 6 4.8"/>',
|
||||
link: '<path d="M8.6 11.4a3 3 0 0 0 4.2 0l2.2-2.2a3 3 0 0 0-4.2-4.2L9.6 6.2"/><path d="M11.4 8.6a3 3 0 0 0-4.2 0L5 10.8a3 3 0 0 0 4.2 4.2l1.2-1.2"/>',
|
||||
stop: '<rect x="5.6" y="5.6" width="8.8" height="8.8" rx="2"/>',
|
||||
filter: '<path d="M3.6 5.4h12.8"/><path d="M6.4 10h7.2"/><path d="M8.6 14.6h2.8"/>',
|
||||
dots: '<circle cx="5" cy="10" r="1.2" fill="currentColor"/><circle cx="10" cy="10" r="1.2" fill="currentColor"/><circle cx="15" cy="10" r="1.2" fill="currentColor"/>',
|
||||
// 第二十二轮:意见反馈(灯泡=想法)/ 用户反馈(收件盘=收到的意见)
|
||||
bulb: '<path d="M10 2.8a5 5 0 0 0-3 9v2.2h6V11.8a5 5 0 0 0-3-9z"/><path d="M8.2 16.6h3.6"/><path d="M8.8 18.4h2.4"/>',
|
||||
// 第二十三轮:网关配置(滑杆 = 调参数)
|
||||
sliders: '<path d="M3.6 6.8h5.6"/><path d="M12.6 6.8h3.8"/><circle cx="10.9" cy="6.8" r="1.7"/><path d="M3.6 13.2h3.8"/><path d="M10.8 13.2h5.6"/><circle cx="9.1" cy="13.2" r="1.7"/>',
|
||||
inbox: '<path d="M3.4 11.6 6 4.6h8l2.6 7v4.8H3.4z"/><path d="M3.4 11.6h3.2l.9 1.8h5l.9-1.8h3.2"/>',
|
||||
// 第二十四轮:账号停用(禁用符号「圆 + 斜杠」),启用配已有的 play(圆 + 三角)
|
||||
ban: '<circle cx="10" cy="10" r="7"/><path d="M5.1 5.1l9.8 9.8"/>',
|
||||
}
|
||||
|
||||
const body = computed(() => ICONS[props.name] || '')
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.gw-icon { display: block; flex: none; }
|
||||
</style>
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
// 第十三轮: element-plus 的语言包是 .mjs 且不带类型声明,vue-tsc 会报 TS7016。
|
||||
// 只是两个纯数据模块(locale 对象),补声明让类型检查保持干净(App.vue 用到)。
|
||||
declare module 'element-plus/dist/locale/zh-cn.mjs'
|
||||
declare module 'element-plus/dist/locale/en.mjs'
|
||||
@@ -0,0 +1,34 @@
|
||||
// M5+: 多语言基础设施。默认跟随 localStorage 的 gw_locale,缺省中文;fallback 回中文。
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import zh from './locales/zh'
|
||||
import en from './locales/en'
|
||||
|
||||
export const LOCALE_KEY = 'gw_locale'
|
||||
export type Locale = 'zh' | 'en'
|
||||
|
||||
export function getLocale(): Locale {
|
||||
const v = localStorage.getItem(LOCALE_KEY)
|
||||
return v === 'en' ? 'en' : 'zh'
|
||||
}
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
globalInjection: true,
|
||||
locale: getLocale(),
|
||||
fallbackLocale: 'zh',
|
||||
messages: { zh, en },
|
||||
})
|
||||
|
||||
export function setLocale(locale: Locale): void {
|
||||
i18n.global.locale.value = locale
|
||||
localStorage.setItem(LOCALE_KEY, locale)
|
||||
// 让 document 语言标签跟着变,便于 assistive tech / 字体
|
||||
document.documentElement.setAttribute('lang', locale)
|
||||
}
|
||||
|
||||
// 初始化也要把语言标签写进 <html>:setLocale 只覆盖「手动切换」这条路径,
|
||||
// 否则 localStorage 里存着 en 的老用户,<html lang> 会一直停在 index.html 里的 zh-CN
|
||||
// (读屏软件会按中文念英文界面,字体回退也跟着走中文)。
|
||||
if (typeof document !== 'undefined') document.documentElement.setAttribute('lang', getLocale())
|
||||
|
||||
export default i18n
|
||||
@@ -0,0 +1,239 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<!-- 宽屏:侧栏常驻 -->
|
||||
<aside v-if="!isMobile" class="rail">
|
||||
<SideNav :groups="groups" />
|
||||
</aside>
|
||||
|
||||
<div class="main">
|
||||
<!-- 宽屏顶栏:页面标题 + 副标题 + 连接状态 + 主题 / 刷新 / 通知 / 账号 -->
|
||||
<header v-if="!isMobile" class="top">
|
||||
<div>
|
||||
<h2>{{ pageTitle }}</h2>
|
||||
<div class="crumb">{{ pageSub }}</div>
|
||||
</div>
|
||||
<div class="top-right">
|
||||
<div class="host">
|
||||
<i class="dot" :class="connOk ? 'ok' : 'bad'"></i>
|
||||
<span>{{ connOk ? t('nav.connected') : t('nav.disconnected') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 第二十一轮:tooltip 必须在 dropdown **外面**。反过来(tooltip 包着触发按钮)
|
||||
Element Plus 的 ElOnlyChild 会把点击挂到内层 tooltip 的包装节点上,
|
||||
真正被点的 <button> 收不到事件 → 菜单永远不开(老板报的「主题点了没反应」)。 -->
|
||||
<el-tooltip :content="t('theme.choose')" placement="bottom">
|
||||
<el-dropdown trigger="click" @command="onTheme">
|
||||
<button class="icon-btn" type="button"><Icon name="theme" :size="16" /></button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="id in THEME_IDS" :key="id" :command="id" :disabled="theme === id">
|
||||
<span class="t-row"><i class="t-dot" :style="{ background: THEME_META[id].accent }" />{{ t(THEME_META[id].nameKey) }}</span>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided command="follow">
|
||||
<span class="t-row">
|
||||
<Icon name="check" :size="14" :style="{ opacity: followSystem ? 1 : 0 }" />
|
||||
{{ t('theme.followSystem') }}
|
||||
</span>
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-tooltip>
|
||||
|
||||
<el-tooltip :content="t('top.refresh')" placement="bottom">
|
||||
<button class="icon-btn" type="button" @click="refresh"><Icon name="refresh" :size="16" /></button>
|
||||
</el-tooltip>
|
||||
|
||||
<el-dropdown trigger="click" @command="onCmd">
|
||||
<div class="user">
|
||||
<div class="avatar">{{ initial }}</div>
|
||||
<span>{{ store.user }}<template v-if="store.isAdmin"> · {{ t('common.admin') }}</template></span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh" :disabled="locale === 'zh'">中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en" :disabled="locale === 'en'">English</el-dropdown-item>
|
||||
<el-dropdown-item divided command="logout">{{ t('common.logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 窄屏顶栏:汉堡唤出抽屉,右侧只留主题与账号 -->
|
||||
<header v-else class="m-top">
|
||||
<div class="ic" @click="drawerOpen = true"><Icon name="menu" :size="18" /></div>
|
||||
<h3>{{ pageTitle }}</h3>
|
||||
<div class="top-right">
|
||||
<div class="ic" @click="cycleTheme"><Icon name="theme" :size="18" /></div>
|
||||
<el-dropdown trigger="click" @command="onCmd">
|
||||
<div class="avatar">{{ initial }}</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh" :disabled="locale === 'zh'">中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en" :disabled="locale === 'en'">English</el-dropdown-item>
|
||||
<el-dropdown-item divided command="logout">{{ t('common.logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="gw-body">
|
||||
<!-- key 里带 refreshTick:点刷新时整页重挂载重新拉数据(页面内部状态清空是有意的) -->
|
||||
<router-view :key="route.fullPath + '-' + refreshTick" />
|
||||
</div>
|
||||
|
||||
<TabBar v-if="isMobile" @more="drawerOpen = true" />
|
||||
</div>
|
||||
|
||||
<!-- 抽屉:完整菜单 + 主题切换;选完菜单立即收起(否则看完页面还被挡着) -->
|
||||
<el-drawer v-model="drawerOpen" direction="ltr" :size="252" :with-header="false" class="nav-drawer">
|
||||
<div class="drawer-wrap">
|
||||
<SideNav :groups="groups" @navigate="drawerOpen = false" />
|
||||
<div class="drawer-themes">
|
||||
<div class="dt-title">{{ t('theme.choose') }}</div>
|
||||
<div class="dt-row">
|
||||
<button
|
||||
v-for="id in THEME_IDS"
|
||||
:key="id"
|
||||
type="button"
|
||||
class="dt-card"
|
||||
:class="{ on: theme === id }"
|
||||
@click="onTheme(id)"
|
||||
>
|
||||
<span class="dt-prev">
|
||||
<i class="l" :style="{ background: THEME_META[id].side }" />
|
||||
<i class="r" :style="{ background: THEME_META[id].canvas }">
|
||||
<b :style="{ background: THEME_META[id].accent }" />
|
||||
<b :style="{ background: THEME_META[id].accent, opacity: .4, width: '65%' }" />
|
||||
</i>
|
||||
</span>
|
||||
<span class="dt-name">{{ id }}</span>
|
||||
</button>
|
||||
<button type="button" class="dt-card" :class="{ on: followSystem }" @click="toggleFollow">
|
||||
<span class="dt-prev"><Icon name="theme" :size="18" /></span>
|
||||
<span class="dt-name">{{ t('theme.followShort') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSessionStore } from '../store/session'
|
||||
import { api } from '../api'
|
||||
import { setLocale } from '../i18n'
|
||||
import SideNav from './SideNav.vue'
|
||||
import TabBar from './TabBar.vue'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { useIsMobile } from '../lib/ui'
|
||||
import { navGroups } from '../lib/nav'
|
||||
import { useTheme, THEME_IDS, THEME_META, type ThemeId } from '../lib/theme'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const store = useSessionStore()
|
||||
const { t, locale } = useI18n()
|
||||
const { isMobile } = useIsMobile()
|
||||
const { theme, followSystem, setTheme, setFollowSystem } = useTheme()
|
||||
|
||||
const connOk = ref(true)
|
||||
const drawerOpen = ref(false)
|
||||
const refreshTick = ref(0)
|
||||
|
||||
const groups = computed(() => navGroups(store.isAdmin))
|
||||
const initial = computed(() => (store.user || '?').slice(0, 1).toUpperCase())
|
||||
|
||||
// 抽屉里选完菜单 / 浏览器前进后退,都收起
|
||||
watch(() => route.fullPath, () => { drawerOpen.value = false })
|
||||
|
||||
const pageTitle = computed(() => {
|
||||
const key = String(route.name || '')
|
||||
return key ? t(`nav.menu${key}`) : t('nav.control')
|
||||
})
|
||||
const pageSub = computed(() => {
|
||||
const key = String(route.name || '')
|
||||
const sub = t(`nav.sub${key}`)
|
||||
// 没写副标题的页面,t() 会把 key 原样返回 —— 这时显示连接地址兜底
|
||||
return sub.startsWith('nav.') ? '127.0.0.1:8808' : sub
|
||||
})
|
||||
|
||||
function onTheme(cmd: string | number | object) {
|
||||
if (cmd === 'follow') { toggleFollow(); return }
|
||||
setTheme(cmd as ThemeId)
|
||||
}
|
||||
function toggleFollow() { setFollowSystem(!followSystem.value) }
|
||||
/** 手机端只有一个图标位:循环 B → A → C(设置页里可以做精细选择) */
|
||||
function cycleTheme() {
|
||||
const i = THEME_IDS.indexOf(theme.value)
|
||||
setTheme(THEME_IDS[(i + 1) % THEME_IDS.length])
|
||||
}
|
||||
function refresh() { refreshTick.value++ }
|
||||
|
||||
async function onCmd(cmd: string) {
|
||||
if (cmd === 'logout') {
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
setLocale(cmd as 'zh' | 'en')
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
async function probe() {
|
||||
try {
|
||||
// 探 /health 而不是 /healthz:后者只回 {"status":"ok"},不带 uptime,
|
||||
// /health 带 version/uptime,顺带把连接状态一起判了(顶栏「连接正常」小灯)。
|
||||
const j = await api('/health')
|
||||
connOk.value = !!j && j.status === 'ok'
|
||||
} catch {
|
||||
connOk.value = false
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
probe()
|
||||
timer = setInterval(probe, 10000)
|
||||
window.addEventListener('gw-auth-expired', onAuthExpired)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
clearInterval(timer)
|
||||
window.removeEventListener('gw-auth-expired', onAuthExpired)
|
||||
})
|
||||
|
||||
async function onAuthExpired() {
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.t-row { display: flex; align-items: center; gap: 8px; }
|
||||
.t-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
|
||||
.host span { white-space: nowrap; }
|
||||
/* 抽屉内容:菜单撑满,主题卡固定在底部 */
|
||||
.drawer-wrap { display: flex; flex-direction: column; height: 100%; background: var(--surface); }
|
||||
.drawer-themes { flex: none; border-top: 1px solid var(--line); padding: 12px; }
|
||||
.dt-title { font-size: 11.5px; color: var(--muted-2); margin-bottom: 8px; }
|
||||
.dt-row { display: flex; gap: 8px; }
|
||||
.dt-card {
|
||||
flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface);
|
||||
border-radius: 10px; padding: 7px 5px; cursor: pointer; display: flex;
|
||||
flex-direction: column; align-items: center; gap: 5px;
|
||||
}
|
||||
.dt-card.on { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.dt-prev { width: 100%; height: 22px; border-radius: 6px; overflow: hidden; display: flex; border: 1px solid var(--line); }
|
||||
.dt-prev .l { width: 30%; display: block; }
|
||||
.dt-prev .r { flex: 1; padding: 3px; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
|
||||
.dt-prev .r b { height: 3px; border-radius: 2px; display: block; }
|
||||
.dt-name { font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 22px; }
|
||||
.dt-card.on .dt-name { color: var(--primary); }
|
||||
@media (max-width: 768px) {
|
||||
.top-right { gap: 6px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,78 @@
|
||||
<template>
|
||||
<!-- 侧栏:桌面常驻在左边,窄屏放进抽屉 —— 两处共用这一份,菜单项只维护一处 -->
|
||||
<div class="rail-inner">
|
||||
<div class="brand">
|
||||
<span class="logo"><Icon name="bolt" :size="17" /></span>
|
||||
<div>
|
||||
<b>{{ t('nav.title') }}</b>
|
||||
<span>127.0.0.1:8808</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav">
|
||||
<template v-for="(g, gi) in groups" :key="g.id">
|
||||
<div v-if="gi > 0" class="nav-sep" />
|
||||
<router-link
|
||||
v-for="m in g.items"
|
||||
:key="m.path"
|
||||
:to="m.path"
|
||||
class="nav-i"
|
||||
:class="{ on: isActive(m.path) }"
|
||||
@click="emit('navigate')"
|
||||
>
|
||||
<Icon :name="m.icon" :size="18" />
|
||||
<span>{{ t(`nav.menu${m.key}`) }}</span>
|
||||
</router-link>
|
||||
</template>
|
||||
</nav>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import type { NavGroup } from '../lib/nav'
|
||||
|
||||
// 第二十二轮:删掉侧栏底部那两行(「B · 素白蓝紫」+「v2.4.0 · 控制台」)。
|
||||
// 皮肤名在设置页「外观与语言」和顶栏调色盘里都能看到,版本号也没必要常驻占位。
|
||||
const props = defineProps<{ groups: NavGroup[] }>()
|
||||
const emit = defineEmits<{ (e: 'navigate'): void }>()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
// 用前缀匹配:/users 的子页(若有)也能让菜单高亮
|
||||
function isActive(path: string): boolean {
|
||||
return route.path === path || route.path.startsWith(path + '/')
|
||||
}
|
||||
void props
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.rail-inner {
|
||||
display: flex; flex-direction: column; height: 100%;
|
||||
background: var(--surface); padding: 14px 12px; overflow: hidden;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px; }
|
||||
.logo {
|
||||
width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
|
||||
color: var(--primary-ink); display: grid; place-items: center; flex: none;
|
||||
}
|
||||
.brand b { font-size: 15px; display: block; line-height: 1.25; color: var(--text); }
|
||||
.brand span { font-size: 11px; color: var(--muted-2); }
|
||||
.nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
|
||||
.nav-i {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
/* 第二十三轮追加(老板先「缩短一点让滚动条不要出现」,再「上下间距可以大一点」):
|
||||
行距随窗口高度自适应 —— 窗口高就宽松、窗口矮就收紧,两边都满足:
|
||||
下限 7px(行高 32px,与上一版一致,矮窗口不会顶出滚动条)、上限 11px(行高 40px,比原来 9px/36px 更松)。
|
||||
换算:600px 视口 ≈ 35px 行高、720px ≈ 38px、1080px 及以上封顶 40px;
|
||||
不滚动的下限:窗口高约 505px(yaml 那份固定值 36px 时是 ~605px 就会滚)。 */
|
||||
padding: clamp(7px, 1.4vh, 11px) 10px;
|
||||
border-radius: 10px; color: var(--muted); font-size: 13.5px;
|
||||
cursor: pointer; text-decoration: none; transition: background .15s, color .15s;
|
||||
}
|
||||
.nav-i:hover { background: var(--chip); color: var(--text); }
|
||||
.nav-i.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
|
||||
.nav-sep { height: 1px; background: var(--line-2); margin: clamp(7px, 1.2vh, 13px) 8px; flex: none; }
|
||||
</style>
|
||||
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<!-- 手机底部 Tab:4 个主功能 + 「更多」(打开抽屉里的完整菜单)。
|
||||
为什么要有「更多」:手机放不下 10 个菜单项,底部 Tab 只留高频入口,
|
||||
低频的(模型/指标/密钥/用户/日志/设置)走抽屉,不必牺牲可达性。 -->
|
||||
<nav class="tabbar">
|
||||
<div
|
||||
v-for="tb in tabs"
|
||||
:key="tb.path"
|
||||
:class="{ on: isActive(tb.path) }"
|
||||
@click="go(tb.path)"
|
||||
>
|
||||
<Icon :name="tb.icon" :size="18" />
|
||||
<span>{{ t(`nav.menu${tb.key}`) }}</span>
|
||||
</div>
|
||||
<div :class="{ on: moreActive }" @click="emit('more')">
|
||||
<Icon name="menu" :size="18" />
|
||||
<span>{{ t('nav.more') }}</span>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { MOBILE_TABS } from '../lib/nav'
|
||||
|
||||
const emit = defineEmits<{ (e: 'more'): void }>()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tabs = MOBILE_TABS
|
||||
|
||||
function isActive(path: string): boolean {
|
||||
return route.path === path || route.path.startsWith(path + '/')
|
||||
}
|
||||
/** 当前页不在前 4 个 Tab 里时,「更多」高亮(否则用户不知道自己在哪) */
|
||||
const moreActive = computed(() => !tabs.some((tb) => isActive(tb.path)))
|
||||
|
||||
function go(path: string) {
|
||||
if (route.path !== path) router.push(path)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,139 @@
|
||||
// M4: 图表公共样式。集中处理两类「文字挤压」问题:
|
||||
// ① 长模型名重叠 —— 类目轴喂完整名称(tooltip 显全称),轴上截断 + 倾斜 + hideOverlap,
|
||||
// grid 用 containLabel 让 ECharts 按标签实际占位留白;
|
||||
// ② ECharts 6 把 legend 默认位置从 top 改成了 bottom(LegendModel.defaultOption.bottom),
|
||||
// 于是图例压在 x 轴标签上 —— 这里统一显式 top: 0,并给 grid.top 留出图例行高。
|
||||
export function clip(v: string, n = 12): string {
|
||||
return v.length > n ? v.slice(0, n) + '…' : v
|
||||
}
|
||||
|
||||
/** 读一个主题 token 的当前值。ECharts 只吃具体色值(不认 CSS 变量),
|
||||
* 所以每次重算 option 时现取一次 —— 切主题后重新 computed 即可换色。 */
|
||||
export function cssVar(name: string, fallback = ''): string {
|
||||
if (typeof document === 'undefined') return fallback
|
||||
const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim()
|
||||
return v || fallback
|
||||
}
|
||||
|
||||
/** 图表用色板(随 A/B/C 主题变化)。 */
|
||||
export function chartTheme() {
|
||||
return {
|
||||
a: cssVar('--chart-a', '#4F63F5'),
|
||||
b: cssVar('--chart-b', '#35B8C9'),
|
||||
ok: cssVar('--ok', '#15A34A'),
|
||||
warn: cssVar('--warn', '#D97706'),
|
||||
err: cssVar('--err', '#DC2626'),
|
||||
text: cssVar('--text', '#16203A'),
|
||||
muted: cssVar('--muted', '#6B7891'),
|
||||
muted2: cssVar('--muted-2', '#98A3B7'),
|
||||
line: cssVar('--line', '#E5EAF4'),
|
||||
primary: cssVar('--primary', '#4F63F5'),
|
||||
}
|
||||
}
|
||||
|
||||
/** 类目轴配置:传入完整名称(tooltip 显全称),轴上按 maxLen 截断显示。 */
|
||||
export function categoryAxis(labels: string[], maxLen = 12) {
|
||||
const c = chartTheme()
|
||||
return {
|
||||
type: 'category' as const,
|
||||
data: labels,
|
||||
axisTick: { alignWithLabel: true },
|
||||
axisLine: { lineStyle: { color: c.line } },
|
||||
axisLabel: {
|
||||
interval: 0,
|
||||
rotate: labels.length > 4 ? 30 : 0,
|
||||
hideOverlap: true,
|
||||
margin: 8,
|
||||
fontSize: 11,
|
||||
color: c.muted2,
|
||||
formatter: (v: string) => clip(v, maxLen),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** 数值轴:统一网格线与轴色(深色主题下默认灰线会糊成一片)。 */
|
||||
export function valueAxis(name = '', minInterval = 0) {
|
||||
const c = chartTheme()
|
||||
return {
|
||||
type: 'value' as const,
|
||||
name,
|
||||
minInterval,
|
||||
axisLine: { show: false },
|
||||
axisTick: { show: false },
|
||||
axisLabel: { fontSize: 11, color: c.muted2 },
|
||||
splitLine: { lineStyle: { color: c.line } },
|
||||
}
|
||||
}
|
||||
|
||||
/** 图例:显式钉在顶部,避免 ECharts 6 默认落到底部压住 x 轴标签。 */
|
||||
export function legend(data: string[]) {
|
||||
return {
|
||||
data,
|
||||
top: 0,
|
||||
left: 'center',
|
||||
itemWidth: 14,
|
||||
itemHeight: 10,
|
||||
itemGap: 14,
|
||||
textStyle: { fontSize: 12, color: chartTheme().muted },
|
||||
}
|
||||
}
|
||||
|
||||
/** top 留出图例(约 22px);containLabel 自动为轴标签留白,不用再手算 bottom。 */
|
||||
export const grid = { left: 12, right: 18, top: 34, bottom: 10, containLabel: true }
|
||||
|
||||
/** 环形图:半径留足空间给外部标签,避免标签被容器裁掉。 */
|
||||
export const pieRadius = ['34%', '56%']
|
||||
export const pieCenter = ['50%', '52%']
|
||||
/** 环形图标签:色值必须现取(ECharts 默认 #333,深色主题 A 下会糊在底色里看不见)。
|
||||
* 和 legend/valueAxis 一样做成函数,切主题后重算 option 就会跟着换色。 */
|
||||
export function pieLabel() {
|
||||
return {
|
||||
overflow: 'truncate' as const,
|
||||
width: 110,
|
||||
formatter: '{b}: {c}',
|
||||
fontSize: 11,
|
||||
color: chartTheme().muted,
|
||||
}
|
||||
}
|
||||
|
||||
/** 空数据的图表别只留一副空坐标轴:在画布中央给一行灰字提示。
|
||||
* 传进来的数组全空(或全 0)时才出现,有数据时返回空数组、不影响原图。 */
|
||||
export function emptyTip(series: (number[] | undefined | null)[], text: string) {
|
||||
const allEmpty = series.every((s) => !s || !s.length || s.every((v) => !v))
|
||||
if (!allEmpty) return []
|
||||
return [
|
||||
{
|
||||
type: 'text',
|
||||
left: 'center',
|
||||
top: 'middle',
|
||||
silent: true,
|
||||
style: { text, fill: chartTheme().muted2, fontSize: 12 },
|
||||
},
|
||||
]
|
||||
}
|
||||
export const pieLabelLine = { length: 8, length2: 10, smooth: true }
|
||||
|
||||
/** 环形图配色:主色系渐次铺开,供应商/模型数量不定也不至于撞色。 */
|
||||
export function piePalette(n: number): string[] {
|
||||
const c = chartTheme()
|
||||
const base = [c.a, c.b, c.warn, c.ok, c.primary, c.muted2]
|
||||
return Array.from({ length: Math.max(n, 1) }, (_, i) => base[i % base.length])
|
||||
}
|
||||
|
||||
/** 空数据时环形图也得画个灰圈,别留白块。
|
||||
* 空态那一项只报名字(「暂无数据」),别拼成「暂无数据: 1」这种看着像真数据的怪文案。 */
|
||||
export function pieData(items: { name: string; value: number }[], emptyLabel = '暂无数据') {
|
||||
if (items.length) {
|
||||
const colors = piePalette(items.length)
|
||||
return items.map((it, i) => ({ ...it, itemStyle: { color: colors[i] } }))
|
||||
}
|
||||
const c = chartTheme()
|
||||
return [{
|
||||
name: emptyLabel,
|
||||
value: 1,
|
||||
itemStyle: { color: c.line },
|
||||
// 逐项覆盖:不显示数值、不画引导线,纯占位
|
||||
label: { show: true, formatter: emptyLabel, color: c.muted },
|
||||
labelLine: { show: false },
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// M2: 对话 Playground —— 流式 / 非流式调用网关 /v1/chat/completions。
|
||||
// 同源请求,带会话 Bearer;流式用 fetch + body reader 直接解析 SSE。
|
||||
|
||||
import { getToken } from '../api'
|
||||
|
||||
export interface Meta {
|
||||
served: string
|
||||
provider: string
|
||||
requested: string
|
||||
fallback: boolean
|
||||
}
|
||||
|
||||
export interface Usage {
|
||||
prompt_tokens?: number
|
||||
completion_tokens?: number
|
||||
total_tokens?: number
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: number
|
||||
role: 'user' | 'assistant'
|
||||
content: string
|
||||
images?: string[] // 第十一轮 #3:随该条用户消息附带的图片(URL 或 data URI)
|
||||
imgNames?: string[] // 第十三轮:图片文件名(展示用,data URI 看不出来源)
|
||||
imgThumbs?: string[] // 第十三轮:缩略图 data URI —— 落服务端历史时用它替代原图
|
||||
// (服务端单条 512KB,原图 base64 会被截断成坏图)
|
||||
reasoning?: string // 推理内容(reasoning_content),单独折叠展示
|
||||
meta?: Meta // 网关元信息(served/provider/fallback)
|
||||
usage?: Usage
|
||||
cost?: number // estimated_cost_cny(仅非流式)
|
||||
streaming?: boolean // 正在流式输出中
|
||||
error?: string
|
||||
}
|
||||
|
||||
let idSeq = 1
|
||||
export function nextId(): number { return idSeq++ }
|
||||
export function seekId(maxId: number): void { idSeq = maxId + 1 }
|
||||
|
||||
export interface HistItem {
|
||||
role: string
|
||||
content: string
|
||||
images?: string[]
|
||||
}
|
||||
|
||||
/** 组装给网关的 messages(system 前缀 + 历史 user/assistant 正文;推理不随历史发送)。
|
||||
* 带 images 的用户消息会发成 OpenAI 视觉格式:content=[{type:text},{type:image_url,...}]。 */
|
||||
export function buildPayloadMessages(
|
||||
system: string,
|
||||
history: HistItem[],
|
||||
): { role: string; content: any }[] {
|
||||
const out: { role: string; content: any }[] = []
|
||||
if (system && system.trim()) out.push({ role: 'system', content: system })
|
||||
for (const m of history) {
|
||||
const imgs = (m.images || []).filter(Boolean)
|
||||
if (!m.content && !imgs.length) continue
|
||||
if (imgs.length) {
|
||||
const parts: any[] = []
|
||||
if (m.content) parts.push({ type: 'text', text: m.content })
|
||||
for (const url of imgs) parts.push({ type: 'image_url', image_url: { url } })
|
||||
out.push({ role: m.role, content: parts })
|
||||
} else {
|
||||
out.push({ role: m.role, content: m.content })
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 分块解析 SSE,回调每个 data 事件。返回被 [DONE] 或流结束决定的结果。 */
|
||||
export async function streamChat(
|
||||
payload: Record<string, any>,
|
||||
onChunk: (chunk: any) => void,
|
||||
signal?: AbortSignal,
|
||||
): Promise<void> {
|
||||
const token = getToken()
|
||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
const resp = await fetch('/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
signal,
|
||||
})
|
||||
if (!resp.ok) {
|
||||
let body: any = null
|
||||
try { body = await resp.json() } catch { /* 不是 JSON */ }
|
||||
const err: any = new Error((body && (body.detail?.message || body.detail)) || `HTTP ${resp.status}`)
|
||||
err.status = resp.status
|
||||
err.body = body
|
||||
throw err
|
||||
}
|
||||
if (!resp.body) return
|
||||
const reader = resp.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let buf = ''
|
||||
for (;;) {
|
||||
const { value, done } = await reader.read()
|
||||
if (done) break
|
||||
buf += decoder.decode(value, { stream: true })
|
||||
let idx
|
||||
while ((idx = buf.indexOf('\n\n')) !== -1) {
|
||||
const frame = buf.slice(0, idx)
|
||||
buf = buf.slice(idx + 2)
|
||||
for (const line of frame.split('\n')) {
|
||||
if (!line.startsWith('data: ')) continue
|
||||
const data = line.slice(6)
|
||||
if (data.trim() === '[DONE]') return
|
||||
let chunk: any
|
||||
try { chunk = JSON.parse(data) } catch { continue }
|
||||
onChunk(chunk)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 非流式:直接拿完整对象。 */
|
||||
export async function chatOnce(payload: Record<string, any>): Promise<any> {
|
||||
const token = getToken()
|
||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
const resp = await fetch('/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
let body: any = null
|
||||
try { body = await resp.json() } catch { /* 忽略 */ }
|
||||
if (!resp.ok) {
|
||||
const err: any = new Error((body && (body.detail?.message || body.detail)) || `HTTP ${resp.status}`)
|
||||
err.status = resp.status
|
||||
err.body = body
|
||||
throw err
|
||||
}
|
||||
return body
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// M6: 生成图片/视频的「下载」。
|
||||
//
|
||||
// 为什么要绕后端一圈(而不是 `<a :href="src" download>`):
|
||||
// 生成产物挂在第三方 CDN 上(如 cos-platform-outputs.agnes-ai.cn),该 CDN
|
||||
// **不返回 CORS 头**,于是浏览器里两条直链下载的路都堵死:
|
||||
// 1) fetch(src) → blob 被跨域拦(拿不到字节,自己造不了 Blob 下载);
|
||||
// 2) `<a href="跨域 URL" download>`:HTML 规范里 download 属性对跨域地址无效 ——
|
||||
// 点下去只会"新标签页打开",不是存文件(手机端最明显)。
|
||||
// 所以走同源的 /v1/media/download,由网关代拉并补 Content-Disposition,
|
||||
// 前端拿 blob 自己触发保存。只有"要不要下载"是前端的事,"能不能拉到"交给后端。
|
||||
|
||||
import { getToken } from '../api'
|
||||
|
||||
/** 服务端代下载端点(与网关同源)。 */
|
||||
const DL_PATH = '/v1/media/download'
|
||||
|
||||
/** 从 Content-Disposition 里取文件名(优先 RFC 5987 的 filename*,它支持中文)。 */
|
||||
export function filenameFromHeader(cd: string): string {
|
||||
if (!cd) return ''
|
||||
const star = /filename\*\s*=\s*UTF-8''([^;]+)/i.exec(cd)
|
||||
if (star && star[1]) {
|
||||
try { return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) } catch { /* 落下面兜底 */ }
|
||||
}
|
||||
const plain = /filename\s*=\s*"([^"]*)"/i.exec(cd) || /filename\s*=\s*([^;]+)/i.exec(cd)
|
||||
return plain && plain[1] ? plain[1].trim() : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* data:URI → Blob(不经过 fetch)。
|
||||
*
|
||||
* 为什么不用 `fetch(dataURI)`:CSP 是 `connect-src 'self'`,data: 不在白名单里,
|
||||
* fetch 会被浏览器直接拦掉(前端只看到「下载失败」)。解码 base64 属于纯计算,
|
||||
* 不触网,也就不受 CSP 约束 —— 顺便离线也能用。
|
||||
*/
|
||||
export function dataUriToBlob(src: string): Blob {
|
||||
const m = /^data:([^,]*),([\s\S]*)$/i.exec(src)
|
||||
if (!m) throw new Error('bad data URI')
|
||||
const header = m[1] || ''
|
||||
const body = m[2] || ''
|
||||
const semi = header.indexOf(';')
|
||||
const mime = (semi === -1 ? header : header.slice(0, semi)) || 'application/octet-stream'
|
||||
if (/;base64/i.test(header)) {
|
||||
const bin = atob(body.replace(/\s+/g, ''))
|
||||
const bytes = new Uint8Array(bin.length)
|
||||
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)
|
||||
return new Blob([bytes], { type: mime })
|
||||
}
|
||||
try {
|
||||
return new Blob([decodeURIComponent(body)], { type: mime })
|
||||
} catch {
|
||||
return new Blob([body], { type: mime }) // 百分号残缺就按原样存,别把下载搞崩
|
||||
}
|
||||
}
|
||||
|
||||
/** data:URI 的 MIME → 扩展名(本地/上游直回 base64 的图走这条路)。 */
|
||||
function dataExt(src: string): string {
|
||||
const m = /^data:([a-z0-9.+/-]+)/i.exec(src)
|
||||
const map: Record<string, string> = {
|
||||
'image/png': '.png', 'image/jpeg': '.jpg', 'image/webp': '.webp', 'image/gif': '.gif',
|
||||
'video/mp4': '.mp4', 'video/webm': '.webm', 'video/quicktime': '.mov',
|
||||
}
|
||||
return (m && map[m[1].toLowerCase()]) || ''
|
||||
}
|
||||
|
||||
/** 兜底文件名:从 URL 末段取(带 query 的地址会退化到 `media-<时间戳>`)。 */
|
||||
function fallbackName(src: string, prefix: string): string {
|
||||
const ext = dataExt(src)
|
||||
if (ext) return `${prefix}-${stamp()}${ext}`
|
||||
const tail = (src.split('?')[0] || '').split('#')[0].split('/').pop() || ''
|
||||
if (tail && /\.[a-z0-9]{2,5}$/i.test(tail)) return tail.slice(-120)
|
||||
return `${prefix}-${stamp()}.bin`
|
||||
}
|
||||
|
||||
/** yyyyMMdd-HHmm(本地时区),用来区分同名下载。 */
|
||||
export function stamp(d = new Date()): string {
|
||||
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())}`
|
||||
}
|
||||
|
||||
/** 用提示词做文件名前缀:先截断再抹掉斜杠等路径成分(避免落盘时被当目录)。 */
|
||||
export function nameFromPrompt(prompt: string, fallback = 'media', max = 24): string {
|
||||
const s = (prompt || '').replace(/[\r\n\t]+/g, ' ').replace(/[\\/:*?"<>|]+/g, ' ').trim()
|
||||
const cut = s.slice(0, max).trim()
|
||||
return cut || fallback
|
||||
}
|
||||
|
||||
/** 触发浏览器保存一个 blob(同源 blob: URL,download 属性一定生效)。 */
|
||||
function saveBlob(blob: Blob, name: string): void {
|
||||
const href = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = name || 'download'
|
||||
a.style.display = 'none'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
// 立刻 revoke 在部分浏览器(Safari/Firefox)会打断尚未开始的保存,延后回收。
|
||||
setTimeout(() => URL.revokeObjectURL(href), 10_000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载一个生成出来的图片/视频。
|
||||
*
|
||||
* @param src 产物地址:http(s)(走后端代拉)或 data:(浏览器内直接存)
|
||||
* @param name 期望文件名(不含后缀也行,后端按 Content-Type 补);
|
||||
* 实际落盘名以服务端 Content-Disposition 为准
|
||||
* @throws Error 带上后端给的人话原因(白名单/失效/超限…),交给调用方弹提示
|
||||
*/
|
||||
export async function downloadMedia(src: string, name = ''): Promise<void> {
|
||||
if (!src) throw new Error('empty media src')
|
||||
|
||||
if (src.startsWith('data:')) {
|
||||
// data URI 不出网、也不该绕后端:本地解码成 blob 直接存(离线也能下载;
|
||||
// 注意不能用 fetch —— CSP 的 connect-src 'self' 会把它拦掉,见 dataUriToBlob)
|
||||
const base = name || `media-${stamp()}`
|
||||
saveBlob(dataUriToBlob(src), base.includes('.') ? base : base + dataExt(src))
|
||||
return
|
||||
}
|
||||
|
||||
const q = new URLSearchParams({ url: src })
|
||||
if (name) q.set('filename', name)
|
||||
const headers: Record<string, string> = {}
|
||||
const token = getToken()
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
|
||||
const resp = await fetch(`${DL_PATH}?${q.toString()}`, { headers })
|
||||
if (!resp.ok) {
|
||||
// 网关错误统一是 {"error":{"message": "..."}}(见 openai_compat_error)
|
||||
let msg = `HTTP ${resp.status}`
|
||||
try {
|
||||
const body = await resp.json()
|
||||
msg = (body && (body.error?.message || body.detail)) || msg
|
||||
} catch { /* 非 JSON(如代理层 502 页面)就用状态码 */ }
|
||||
if (resp.status === 401) {
|
||||
window.dispatchEvent(new Event('gw-auth-expired')) // 会话过期 → 回登录页
|
||||
}
|
||||
throw new Error(msg)
|
||||
}
|
||||
|
||||
const serverName = filenameFromHeader(resp.headers.get('content-disposition') || '')
|
||||
const blob = await resp.blob()
|
||||
saveBlob(blob, serverName || fallbackName(src, name || 'media'))
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// M4: ECharts 按需注册(只引入用到的图表/组件,减小体积)。
|
||||
import * as echarts from 'echarts/core'
|
||||
import { BarChart, LineChart, PieChart } from 'echarts/charts'
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
TitleComponent,
|
||||
DataZoomComponent,
|
||||
GraphicComponent, // 空数据的「暂无数据」提示靠它画(不注册的话 graphic 会被静默丢掉)
|
||||
} from 'echarts/components'
|
||||
import { CanvasRenderer } from 'echarts/renderers'
|
||||
|
||||
echarts.use([
|
||||
BarChart,
|
||||
LineChart,
|
||||
PieChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
TitleComponent,
|
||||
DataZoomComponent,
|
||||
GraphicComponent,
|
||||
CanvasRenderer,
|
||||
])
|
||||
|
||||
export { echarts }
|
||||
export type { EChartsCoreOption } from 'echarts/core'
|
||||
@@ -0,0 +1,10 @@
|
||||
// 功能开关(第二十三轮追加,老板 19:3x)
|
||||
//
|
||||
// 老板原话:「网关配置功能先不要删掉先隐藏起来,这块先不支持页面配置」。
|
||||
// 所以这里**不是删功能**:`views/GatewayConfig.vue`、路由定义、中英文案、后端 `GET|PUT /config`
|
||||
// 全部原样保留,只把下面这个开关关掉 ——
|
||||
// ① 桌面侧栏与手机抽屉不出现「网关配置」入口(`lib/nav.ts`)
|
||||
// ② 设置页那颗「打开配置页」按钮不渲染(`views/Settings.vue`)
|
||||
// ③ 直接手敲 / 地址栏输入 `#/gateway-config` 会被路由守卫送回仪表盘(`router.ts`)
|
||||
// 恢复 = 把这一行改成 `true`,三个入口同时回来(后端接口本来就没停)。
|
||||
export const GATEWAY_CONFIG_ENABLED = true // 老板 2026-09-15 重新开放:整页 YAML 编辑器 + API Key 环境变量管理
|
||||
@@ -0,0 +1,123 @@
|
||||
// 第二十二轮:意见反馈的前端契约层。
|
||||
//
|
||||
// 分工:服务端存「正文 + 缩略图」,原图按需取(见后端 app/feedback.py 的说明)。
|
||||
// 这里只做三件事:提交、取自己的、取全部(admin),以及取某张原图。
|
||||
|
||||
import { api } from '../api'
|
||||
import { PRESETS, assertBodyBudget, pickImage, type PickedMedia } from './upload'
|
||||
|
||||
/** 一条反馈最多几张图(与服务端 MAX_IMAGES 必须一致,改一处就得改两处)。 */
|
||||
export const FEEDBACK_MAX_IMAGES = 3
|
||||
|
||||
/** 处理进度三档,顺序即流程顺序(与服务端 STATUSES 一致)。 */
|
||||
export const FEEDBACK_STATUSES = ['pending', 'doing', 'done'] as const
|
||||
export type FeedbackStatus = (typeof FEEDBACK_STATUSES)[number]
|
||||
/** i18n 后缀:t(`fbStatus.${s}`) */
|
||||
export const FEEDBACK_STATUS_CLASS: Record<FeedbackStatus, string> = {
|
||||
pending: 'o', // 待处理:橙色,需要有人看一眼
|
||||
doing: 'p', // 处理中:主题色
|
||||
done: 'g', // 已处理:绿色
|
||||
}
|
||||
|
||||
export interface FeedbackImage {
|
||||
name: string
|
||||
bytes: number
|
||||
/** 缩略图 data URI(服务端内嵌返回);空串表示没有预览图 */
|
||||
thumb: string
|
||||
type?: string
|
||||
}
|
||||
|
||||
/** 一条处理记录:谁(by)在什么时候(ts)把它从 from 改到 to,留了什么说明(note)。
|
||||
* `from` 为空串表示「提交」那一步(没有前一个状态)。 */
|
||||
export interface FeedbackStep {
|
||||
ts: number
|
||||
from: string
|
||||
to: FeedbackStatus
|
||||
note: string
|
||||
by: string
|
||||
}
|
||||
|
||||
export interface FeedbackItem {
|
||||
id: string
|
||||
account: string
|
||||
content: string
|
||||
/** epoch 秒(与日志/用户页的时间口径一致) */
|
||||
created: number
|
||||
images: FeedbackImage[]
|
||||
/** 处理进度:pending / doing / done */
|
||||
status: FeedbackStatus
|
||||
/** 最新一条处理说明(提交人可见,可为空) */
|
||||
note: string
|
||||
/** 最后一次改状态的时间(epoch 秒) */
|
||||
updated: number
|
||||
/** 处理记录:提交 + 每一次状态变更,old → new,只增不改(服务端最多留 50 条) */
|
||||
history: FeedbackStep[]
|
||||
/** 管理员归档标记:收件箱「归档/取消归档」,不影响提交人视角 */
|
||||
archived?: boolean
|
||||
}
|
||||
|
||||
export interface FeedbackDraft {
|
||||
content: string
|
||||
images: PickedMedia[]
|
||||
}
|
||||
|
||||
/** 图片 → data URI(自动压缩到反馈档位)。缩略图由 pickImage 一并生成(256px,列表够用)。 */
|
||||
export function pickFeedbackImage(file: File): Promise<PickedMedia> {
|
||||
return pickImage(file, PRESETS.feedback)
|
||||
}
|
||||
|
||||
export async function submitFeedback(draft: FeedbackDraft): Promise<FeedbackItem> {
|
||||
const images = draft.images.map((m) => ({ uri: m.uri, thumb: m.thumb, name: m.name }))
|
||||
// 提交前的整包预算:宁可在这里给一句人话,也不要让浏览器吃到 Nginx 的 413
|
||||
assertBodyBudget([draft.content, ...images.flatMap((i) => [i.uri, i.thumb])])
|
||||
const r = await api('/feedback', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ content: draft.content, images }),
|
||||
})
|
||||
return r.item as FeedbackItem
|
||||
}
|
||||
|
||||
export async function myFeedback(): Promise<FeedbackItem[]> {
|
||||
const r = await api('/feedback/mine')
|
||||
return (r.items || []) as FeedbackItem[]
|
||||
}
|
||||
|
||||
export async function allFeedback(): Promise<FeedbackItem[]> {
|
||||
const r = await api('/feedback')
|
||||
return (r.items || []) as FeedbackItem[]
|
||||
}
|
||||
|
||||
/** 管理员更新处理进度(status + 可选处理说明);提交人会看到同样的状态。 */
|
||||
export async function updateFeedback(
|
||||
fid: string, status: FeedbackStatus, note: string,
|
||||
): Promise<FeedbackItem> {
|
||||
const r = await api(`/feedback/${encodeURIComponent(fid)}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ status, note }),
|
||||
})
|
||||
return r.item as FeedbackItem
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回自己提交的反馈(连服务端的图片文件一起删)。
|
||||
* 只对「待处理」的单子有用 —— 管理员一动手(处理中/已处理)服务端会 400。
|
||||
*/
|
||||
export async function withdrawFeedback(fid: string): Promise<void> {
|
||||
await api(`/feedback/${encodeURIComponent(fid)}`, { method: 'DELETE' })
|
||||
}
|
||||
export async function archiveFeedback(fid: string, archived: boolean): Promise<FeedbackItem> {
|
||||
const r = await api(`/feedback/${encodeURIComponent(fid)}/archive`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ archived }),
|
||||
})
|
||||
return r.item as FeedbackItem
|
||||
}
|
||||
export async function adminDeleteFeedback(fid: string): Promise<void> {
|
||||
await api(`/feedback/${encodeURIComponent(fid)}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
/** 取某条反馈第 idx 张原图(返回 data URI;权限由服务端判:本人或 admin)。 */
|
||||
export async function feedbackImage(fid: string, idx: number): Promise<string> {
|
||||
const r = await api(`/feedback/media/${encodeURIComponent(fid)}/${idx}`)
|
||||
return String(r.uri || '')
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// 服务端历史(图像 / 视频 / 对话)读写封装。
|
||||
//
|
||||
// 为什么要这一层:三类历史原先只存在浏览器里,图像/视频在 localStorage、对话在
|
||||
// sessionStorage —— 换设备看不见、关标签页就丢,而且 `setItem` 抛异常(配额写满)
|
||||
// 被 `catch {}` 静默吞掉,用户看到的就是"我生成过的东西没了"。
|
||||
// 现在以服务端 data/history.json 为准(按账号隔离、按 id upsert),本地只留一份缓存。
|
||||
//
|
||||
// 约定:**所有失败都要冒泡给调用方去提示**,不再静默丢数据。
|
||||
import { api } from '../api'
|
||||
|
||||
export type HistoryKind = 'chat' | 'images' | 'videos'
|
||||
|
||||
/** 拉取本账号某类别的历史;后端不可用时返回 null(调用方回落到本地缓存)。 */
|
||||
export async function pullHistory(kind: HistoryKind): Promise<any[] | null> {
|
||||
try {
|
||||
const j = await api(`/history/${kind}`)
|
||||
return Array.isArray(j.items) ? j.items : []
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** 按 id upsert 提交(整份或增量都行);返回 false 表示没存上,调用方要提示。 */
|
||||
export async function pushHistory(kind: HistoryKind, items: any[]): Promise<boolean> {
|
||||
try {
|
||||
await api(`/history/${kind}`, { method: 'POST', body: JSON.stringify({ items }) })
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteHistoryItem(kind: HistoryKind, id: string | number): Promise<boolean> {
|
||||
try {
|
||||
await api(`/history/${kind}/${encodeURIComponent(String(id))}`, { method: 'DELETE' })
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearHistory(kind: HistoryKind): Promise<boolean> {
|
||||
try {
|
||||
await api(`/history/${kind}`, { method: 'DELETE' })
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** 给没有 id 的旧本地数据补一个稳定 id(迁移用,别让 upsert 把它们当新条目反复插)。 */
|
||||
export function ensureIds(items: any[], prefix: string): any[] {
|
||||
return items.map((it, i) => (it && it.id !== undefined && it.id !== null
|
||||
? it
|
||||
: { ...it, id: `${prefix}-${i}-${it?.ts ?? it?.started ?? it?.created ?? Date.now()}` }))
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// M2/M5: Markdown 渲染 + 代码高亮 + XSS 消毒。
|
||||
// 模型输出是不可信内容,必须经 DOMPurify 消毒后再 v-html 注入。
|
||||
// M5: highlight.js 由「全量 import」改为 core + 按需注册语言,主包体积显著下降。
|
||||
|
||||
import { Marked } from 'marked'
|
||||
import { markedHighlight } from 'marked-highlight'
|
||||
import hljs from 'highlight.js/lib/core'
|
||||
import DOMPurify from 'dompurify'
|
||||
import python from 'highlight.js/lib/languages/python'
|
||||
import javascript from 'highlight.js/lib/languages/javascript'
|
||||
import typescript from 'highlight.js/lib/languages/typescript'
|
||||
import bash from 'highlight.js/lib/languages/bash'
|
||||
import json from 'highlight.js/lib/languages/json'
|
||||
import xml from 'highlight.js/lib/languages/xml'
|
||||
import css from 'highlight.js/lib/languages/css'
|
||||
import markdown from 'highlight.js/lib/languages/markdown'
|
||||
import sql from 'highlight.js/lib/languages/sql'
|
||||
import yaml from 'highlight.js/lib/languages/yaml'
|
||||
import rust from 'highlight.js/lib/languages/rust'
|
||||
import go from 'highlight.js/lib/languages/go'
|
||||
import java from 'highlight.js/lib/languages/java'
|
||||
import cpp from 'highlight.js/lib/languages/cpp'
|
||||
import c from 'highlight.js/lib/languages/c'
|
||||
|
||||
const langs: Record<string, any> = {
|
||||
python, javascript, typescript, bash, json, xml, css, markdown, sql, yaml, rust, go, java, cpp, c,
|
||||
}
|
||||
for (const [name, reg] of Object.entries(langs)) hljs.registerLanguage(name, reg)
|
||||
|
||||
const md = new Marked(
|
||||
markedHighlight({
|
||||
langPrefix: 'hljs language-',
|
||||
highlight(code: string, lang: string) {
|
||||
const l = lang && hljs.getLanguage(lang) ? lang : 'plaintext'
|
||||
return hljs.highlight(code, { language: l }).value
|
||||
},
|
||||
}),
|
||||
{ gfm: true, breaks: true },
|
||||
)
|
||||
|
||||
/** 把 markdown 渲染成已消毒的 HTML(安全地用于 v-html)。 */
|
||||
export function renderMarkdown(src: string): string {
|
||||
return DOMPurify.sanitize(md.parse(src || '') as string)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// M3: 媒体(图像/视频)通用工具。
|
||||
|
||||
/** 从图像 data 项里解析可显示的 src(url / base64 / data:URI 均可)。 */
|
||||
export function imageSrc(item: any): string {
|
||||
if (!item) return ''
|
||||
if (item.url) return item.url
|
||||
if (item.b64_json) return 'data:image/png;base64,' + item.b64_json
|
||||
if (item.data_url) return item.data_url
|
||||
if (typeof item.data === 'string') {
|
||||
if (item.data.startsWith('data:')) return item.data
|
||||
return 'data:image/png;base64,' + item.data
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function looksLikeVideo(s: string): boolean {
|
||||
return /\.(mp4|webm|ogg|m3u8|mov)(\?|#|$)/i.test(s)
|
||||
}
|
||||
|
||||
/** 从视频轮询返回的 raw 对象里尽量找出视频播放地址(按常见键优先,再递归兜底)。 */
|
||||
export function findVideoUrl(obj: any): string {
|
||||
if (!obj) return ''
|
||||
if (typeof obj === 'string') return looksLikeVideo(obj) ? obj : ''
|
||||
if (Array.isArray(obj)) {
|
||||
for (const o of obj) { const u = findVideoUrl(o); if (u) return u }
|
||||
return ''
|
||||
}
|
||||
if (typeof obj === 'object') {
|
||||
for (const k of ['video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
|
||||
if (k in obj) { const u = findVideoUrl(obj[k]); if (u) return u }
|
||||
}
|
||||
for (const v of Object.values(obj)) { const u = findVideoUrl(v); if (u) return u }
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 状态文案归类(completed/succeeded=成功;failed/failed=失败;其余为等待)。 */
|
||||
export function videoStatusKind(s: string): 'done' | 'fail' | 'pending' {
|
||||
if (!s) return 'pending'
|
||||
const t = String(s).toLowerCase()
|
||||
if (['completed', 'succeeded', 'success'].includes(t)) return 'done'
|
||||
if (['failed', 'fail', 'error'].includes(t)) return 'fail'
|
||||
return 'pending'
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// 导航结构单一来源:桌面侧栏、手机抽屉、手机底部 Tab 都从这里取,
|
||||
// 避免菜单项加一个地方漏一个地方。分组顺序与设计稿 v2 一致。
|
||||
|
||||
import { GATEWAY_CONFIG_ENABLED } from './features'
|
||||
|
||||
export interface NavItem {
|
||||
path: string
|
||||
/** i18n key 后缀:t(`nav.menu${key}`) */
|
||||
key: string
|
||||
/** Icon.vue 里的图标名 */
|
||||
icon: string
|
||||
}
|
||||
|
||||
export interface NavGroup {
|
||||
id: string
|
||||
items: NavItem[]
|
||||
}
|
||||
|
||||
/** 桌面侧栏 / 手机抽屉的完整菜单(按功能分组,组间一条分隔线)。 */
|
||||
export function navGroups(isAdmin: boolean): NavGroup[] {
|
||||
const groups: NavGroup[] = [
|
||||
{
|
||||
id: 'core',
|
||||
items: [
|
||||
{ path: '/dashboard', key: 'dashboard', icon: 'dash' },
|
||||
{ path: '/chat', key: 'chat', icon: 'chat' },
|
||||
{ path: '/images', key: 'images', icon: 'img' },
|
||||
{ path: '/videos', key: 'videos', icon: 'vid' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'ops',
|
||||
items: [
|
||||
{ path: '/models', key: 'models', icon: 'model' },
|
||||
{ path: '/metrics', key: 'metrics', icon: 'metric' },
|
||||
{ path: '/keys', key: 'keys', icon: 'key' },
|
||||
],
|
||||
},
|
||||
]
|
||||
const sys: NavItem[] = []
|
||||
// 第二十二轮定稿:管理员只处理反馈(「用户反馈」),不提意见 —— 所以这两项互斥。
|
||||
if (isAdmin) sys.push({ path: '/users', key: 'users', icon: 'users' })
|
||||
if (isAdmin) sys.push({ path: '/feedback-inbox', key: 'feedbackinbox', icon: 'inbox' })
|
||||
// 第二十三轮追加:老板要求「网关配置先不要删掉、先隐藏起来,这块先不支持页面配置」→
|
||||
// 入口由 `lib/features.ts` 的开关统一控制(页面与路由都还在,只是不挂出来)。
|
||||
if (isAdmin && GATEWAY_CONFIG_ENABLED) sys.push({ path: '/gateway-config', key: 'gatewaycfg', icon: 'sliders' })
|
||||
sys.push({ path: '/logs', key: 'logs', icon: 'log' })
|
||||
if (!isAdmin) sys.push({ path: '/feedback', key: 'feedback', icon: 'bulb' })
|
||||
sys.push({ path: '/settings', key: 'settings', icon: 'set' })
|
||||
groups.push({ id: 'sys', items: sys })
|
||||
return groups
|
||||
}
|
||||
|
||||
/** 手机底部 Tab:四个主功能 + 「更多」(抽屉里是完整菜单)。 */
|
||||
export const MOBILE_TABS: NavItem[] = [
|
||||
{ path: '/dashboard', key: 'dashboard', icon: 'dash' },
|
||||
{ path: '/chat', key: 'chat', icon: 'chat' },
|
||||
{ path: '/images', key: 'images', icon: 'img' },
|
||||
{ path: '/videos', key: 'videos', icon: 'vid' },
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
// 设置页工具层 —— 对话默认参数,统一读写 localStorage。
|
||||
// 注:主题(A/B/C + 跟随系统)已独立到 lib/theme.ts;这里只管参数。
|
||||
|
||||
export interface ChatDefaults {
|
||||
model?: string
|
||||
temperature?: number
|
||||
top_p?: number
|
||||
max_tokens?: number | null
|
||||
stream?: boolean
|
||||
system?: string
|
||||
}
|
||||
|
||||
const DEFAULTS_KEY = 'gw_chat_defaults'
|
||||
|
||||
export function getChatDefaults(): ChatDefaults {
|
||||
try {
|
||||
const raw = localStorage.getItem(DEFAULTS_KEY)
|
||||
return raw ? (JSON.parse(raw) as ChatDefaults) : {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function setChatDefaults(d: ChatDefaults): void {
|
||||
localStorage.setItem(DEFAULTS_KEY, JSON.stringify(d))
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// 主题管理(前端重设计 v2)。
|
||||
//
|
||||
// 口径:一套结构 + 三套 token。切主题只改 <html data-theme>,页面代码零改动。
|
||||
// A 深空蓝(深色)· B 素白蓝紫(浅色,默认)· C 暖砂墨绿(浅色暖调)
|
||||
//
|
||||
// 为什么还要切 <html class="dark">:
|
||||
// Element Plus 的弹层/表单深度配色由 dark/css-vars.css(html.dark)驱动,
|
||||
// A 是深色皮肤,必须同时打开这个开关;B/C 关掉。
|
||||
// 两者不冲突 —— 具体的 --el-* 值在 style.css 里由 :root[data-theme] 覆盖。
|
||||
//
|
||||
// 「跟随系统深色模式」:系统切深色时自动用 A,切回浅色时用用户选的主题。
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
export type ThemeId = 'A' | 'B' | 'C'
|
||||
|
||||
export const THEME_IDS: ThemeId[] = ['A', 'B', 'C']
|
||||
/** 默认皮肤:B 素白蓝紫(老板拍板) */
|
||||
export const DEFAULT_THEME: ThemeId = 'B'
|
||||
|
||||
const THEME_KEY = 'gw_theme_v2'
|
||||
const FOLLOW_KEY = 'gw_follow_system'
|
||||
const LEGACY_KEY = 'gw_theme' // 旧版只存 light / dark
|
||||
|
||||
const DARK_QUERY = '(prefers-color-scheme: dark)'
|
||||
|
||||
function readThemeId(): ThemeId {
|
||||
try {
|
||||
const v = localStorage.getItem(THEME_KEY)
|
||||
if (v === 'A' || v === 'B' || v === 'C') return v
|
||||
// 老用户的偏好迁移:深色 → A,浅色 → B(新默认)
|
||||
const legacy = localStorage.getItem(LEGACY_KEY)
|
||||
if (legacy === 'dark') return 'A'
|
||||
return DEFAULT_THEME
|
||||
} catch {
|
||||
return DEFAULT_THEME
|
||||
}
|
||||
}
|
||||
|
||||
function readFollow(): boolean {
|
||||
try {
|
||||
return localStorage.getItem(FOLLOW_KEY) === '1'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function systemPrefersDark(): boolean {
|
||||
if (typeof window === 'undefined' || !window.matchMedia) return false
|
||||
return window.matchMedia(DARK_QUERY).matches
|
||||
}
|
||||
|
||||
// 模块级单例:顶栏调色盘、设置页主题卡、手机「更多」抽屉三处共用同一份状态
|
||||
const themeId = ref<ThemeId>(readThemeId())
|
||||
const followSystem = ref<boolean>(readFollow())
|
||||
const systemDark = ref<boolean>(systemPrefersDark())
|
||||
|
||||
/** 实际生效的皮肤(跟随系统时可能是 A) */
|
||||
const resolved = computed<ThemeId>(() => (followSystem.value && systemDark.value ? 'A' : themeId.value))
|
||||
|
||||
/** 把当前皮肤写进 <html>:data-theme 喂自定义 token,dark class 喂 Element Plus */
|
||||
function apply(): void {
|
||||
const id = resolved.value
|
||||
const root = document.documentElement
|
||||
root.setAttribute('data-theme', id)
|
||||
root.classList.toggle('dark', id === 'A')
|
||||
}
|
||||
|
||||
let started = false
|
||||
/** 在 mount 前调用一次:立即上色 + 监听系统深浅色变化(避免闪白/闪黑)。 */
|
||||
export function initTheme(): void {
|
||||
try {
|
||||
apply()
|
||||
} catch { /* 忽略 */ }
|
||||
if (started || typeof window === 'undefined' || !window.matchMedia) return
|
||||
started = true
|
||||
const mql = window.matchMedia(DARK_QUERY)
|
||||
const onChange = (e: MediaQueryListEvent) => {
|
||||
systemDark.value = e.matches
|
||||
apply()
|
||||
}
|
||||
if (typeof mql.addEventListener === 'function') mql.addEventListener('change', onChange)
|
||||
else mql.addListener(onChange)
|
||||
}
|
||||
|
||||
export function getThemeId(): ThemeId {
|
||||
return themeId.value
|
||||
}
|
||||
|
||||
export function setThemeId(id: ThemeId): void {
|
||||
themeId.value = id
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, id)
|
||||
} catch { /* 忽略 */ }
|
||||
apply()
|
||||
}
|
||||
|
||||
export function isFollowSystem(): boolean {
|
||||
return followSystem.value
|
||||
}
|
||||
|
||||
export function setFollowSystem(on: boolean): void {
|
||||
followSystem.value = on
|
||||
try {
|
||||
localStorage.setItem(FOLLOW_KEY, on ? '1' : '0')
|
||||
} catch { /* 忽略 */ }
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 组件里用的响应式主题状态。 */
|
||||
export function useTheme() {
|
||||
return {
|
||||
theme: computed(() => themeId.value),
|
||||
resolved,
|
||||
followSystem: computed(() => followSystem.value),
|
||||
setTheme: setThemeId,
|
||||
setFollowSystem,
|
||||
}
|
||||
}
|
||||
|
||||
// 名称/说明走 i18n(key 见 locales/zh.ts · theme.nameA 等):换语言时皮肤名跟着变,
|
||||
// 这里只留「结构色值」——那些是设计常量,不该被翻译。
|
||||
export const THEME_META: Record<ThemeId, { nameKey: string; descKey: string; side: string; canvas: string; accent: string }> = {
|
||||
B: { nameKey: 'theme.nameB', descKey: 'theme.descB', side: '#FFFFFF', canvas: '#F4F6FB', accent: '#4F63F5' },
|
||||
A: { nameKey: 'theme.nameA', descKey: 'theme.descA', side: '#121B2C', canvas: '#0A101E', accent: '#35D0BA' },
|
||||
C: { nameKey: 'theme.nameC', descKey: 'theme.descC', side: '#FFFFFF', canvas: '#F8F4EF', accent: '#0E7C6B' },
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 移动端适配的单一断点来源。
|
||||
//
|
||||
// 为什么用 matchMedia 而不是监听 resize 比 innerWidth:
|
||||
// 平板转屏、桌面浏览器缩放都能可靠触发,且与 style.css 里的
|
||||
// @media (max-width: 768px) 天然对齐 —— 样式断点交给 CSS,
|
||||
// 「侧栏 vs 抽屉」这类**结构**切换才需要 JS。改断点时两处必须一起改。
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
|
||||
export const MOBILE_MAX = 768
|
||||
const QUERY = `(max-width: ${MOBILE_MAX}px)`
|
||||
|
||||
/** 响应式「是否窄屏」。组件卸载时自动摘掉监听。 */
|
||||
export function useIsMobile() {
|
||||
const isMobile = ref(typeof window !== 'undefined' && !!window.matchMedia
|
||||
? window.matchMedia(QUERY).matches
|
||||
: false)
|
||||
|
||||
if (typeof window === 'undefined' || !window.matchMedia) return { isMobile }
|
||||
|
||||
const mql = window.matchMedia(QUERY)
|
||||
const onChange = (e: MediaQueryListEvent) => { isMobile.value = e.matches }
|
||||
if (typeof mql.addEventListener === 'function') {
|
||||
mql.addEventListener('change', onChange)
|
||||
onUnmounted(() => mql.removeEventListener('change', onChange))
|
||||
} else {
|
||||
// Safari < 14 只有已废弃的 addListener
|
||||
const legacy = mql as unknown as { addListener(cb: (e: MediaQueryListEvent) => void): void; removeListener(cb: (e: MediaQueryListEvent) => void): void }
|
||||
legacy.addListener(onChange)
|
||||
onUnmounted(() => legacy.removeListener(onChange))
|
||||
}
|
||||
return { isMobile }
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
// 第十三轮: 页面端「上传图片 / 音频 → data URI」工具。
|
||||
//
|
||||
// 为什么不上传到服务端再拿公网 URL?
|
||||
// Agnes 要求素材能被它公开访问,但实测它同样接受 `data:image/png;base64,...` /
|
||||
// `data:audio/wav;base64,...`(图像生成、视频 keyframe/reference、对话视觉三条路径都跑通过)。
|
||||
// 浏览器端直接转 data URI 是最短路径:不落盘、不占公网带宽、也不用新增上传端点与临时文件清理。
|
||||
//
|
||||
// 但**必须压缩**:网关注入体上限 2MB(server.max_body_size),Nginx 也是 client_max_body_size 2m,
|
||||
// 而 base64 会把体积再放大 4/3。手机随手拍的 3~5MB 照片直接转 base64 只会换来一个 413。
|
||||
// 所以这里按用途分级压缩 + 逐级降档,并在提交前做「整包体积」预算检查。
|
||||
|
||||
/** 网关 Nginx / 应用层的请求体上限(字节),留一点余量给 prompt 与 JSON 结构。 */
|
||||
export const BODY_BUDGET = 1_700_000
|
||||
|
||||
export interface MediaPreset {
|
||||
/** 长边上限(像素) */
|
||||
maxSide: number
|
||||
/** JPEG 质量 */
|
||||
quality: number
|
||||
/** 单件 data URI 目标上限(字节) */
|
||||
maxBytes: number
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 各用途的压缩档位。数值来自实测:1024px/q0.82 的普通照片约 150~300KB(base64 后 ×1.37)。 */
|
||||
export const PRESETS: Record<string, MediaPreset> = {
|
||||
// 对话视觉:给模型看的,1024px 足够(再大也只会烧 token)
|
||||
chat: { maxSide: 1024, quality: 0.8, maxBytes: 500_000, label: '对话附图' },
|
||||
// 图生图 / 多图合成:保留构图细节
|
||||
ref: { maxSide: 1024, quality: 0.85, maxBytes: 500_000, label: '参考图' },
|
||||
// 视频首/尾帧:画面直接进视频,给到 1280px
|
||||
frame: { maxSide: 1280, quality: 0.85, maxBytes: 450_000, label: '首/尾帧' },
|
||||
// 视频参考图:最多 5 张,单件必须小(5 × 300KB ≈ 1.5MB,逼近 2MB 上限)
|
||||
videoRef: { maxSide: 1024, quality: 0.8, maxBytes: 300_000, label: '视频参考图' },
|
||||
// 视频参考音频:无浏览器端压缩手段,只能卡体积(最多 3 段)
|
||||
audio: { maxSide: 0, quality: 0, maxBytes: 420_000, label: '参考音频' },
|
||||
// 第二十二轮 意见反馈附图:一条最多 3 张,管理员要在电脑上看清细节,给到 1280px;
|
||||
// 但整包(3 张 + 缩略图)必须落在网关/Nginx 的 2MB 上限内,所以单张卡 400KB。
|
||||
feedback: { maxSide: 1280, quality: 0.8, maxBytes: 400_000, label: '反馈图片' },
|
||||
}
|
||||
|
||||
export interface PickedMedia {
|
||||
/** 原始文件名(用于卡片/标签展示) */
|
||||
name: string
|
||||
kind: 'image' | 'audio'
|
||||
/** 直接塞进请求体的 data URI */
|
||||
uri: string
|
||||
/** 压成缩略图后的 data URI(对话历史只存这个,避免把历史文件撑爆) */
|
||||
thumb: string
|
||||
/** data URI 的字节数(base64 长度换算) */
|
||||
bytes: number
|
||||
/** 压缩后的像素尺寸(图片才有) */
|
||||
width?: number
|
||||
height?: number
|
||||
/** 是否做过有损压缩(用于提示用户"已压缩") */
|
||||
compressed: boolean
|
||||
}
|
||||
|
||||
const AUDIO_EXT = ['mp3', 'wav', 'm4a', 'aac', 'ogg', 'oga', 'flac', 'opus', 'webm']
|
||||
|
||||
/** base64 data URI 的实际字节数(4 个 base64 字符 = 3 字节)。 */
|
||||
export function dataUriBytes(uri: string): number {
|
||||
const i = uri.indexOf(',')
|
||||
if (i < 0) return uri.length
|
||||
const b64 = uri.slice(i + 1)
|
||||
const pad = b64.endsWith('==') ? 2 : b64.endsWith('=') ? 1 : 0
|
||||
return Math.max(0, Math.floor((b64.length * 3) / 4) - pad)
|
||||
}
|
||||
|
||||
export function formatBytes(n: number): string {
|
||||
if (n < 1024) return `${n}B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)}KB`
|
||||
return `${(n / 1024 / 1024).toFixed(2)}MB`
|
||||
}
|
||||
|
||||
function extOf(name: string): string {
|
||||
return (name.split('.').pop() || '').toLowerCase()
|
||||
}
|
||||
|
||||
export function isAudioFile(f: File): boolean {
|
||||
return (f.type || '').startsWith('audio/') || AUDIO_EXT.includes(extOf(f.name))
|
||||
}
|
||||
|
||||
export function isImageFile(f: File): boolean {
|
||||
if ((f.type || '').startsWith('image/')) return true
|
||||
return ['png', 'jpg', 'jpeg', 'webp', 'gif', 'bmp'].includes(extOf(f.name))
|
||||
}
|
||||
|
||||
function readAsDataUri(f: Blob): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fr = new FileReader()
|
||||
fr.onerror = () => reject(new Error('读取文件失败'))
|
||||
fr.onload = () => resolve(String(fr.result || ''))
|
||||
fr.readAsDataURL(f)
|
||||
})
|
||||
}
|
||||
|
||||
async function loadBitmap(file: File): Promise<{ w: number; h: number; draw: CanvasImageSource; dispose: () => void }> {
|
||||
// 优先 createImageBitmap(快、不占 DOM);老浏览器回落到 <img> + objectURL
|
||||
if (typeof createImageBitmap === 'function') {
|
||||
try {
|
||||
const bmp = await createImageBitmap(file)
|
||||
return { w: bmp.width, h: bmp.height, draw: bmp, dispose: () => bmp.close && bmp.close() }
|
||||
} catch { /* 落到 <img> 分支(部分浏览器对某些格式不支持) */ }
|
||||
}
|
||||
const url = URL.createObjectURL(file)
|
||||
try {
|
||||
const img = await new Promise<HTMLImageElement>((resolve, reject) => {
|
||||
const el = new Image()
|
||||
el.onload = () => resolve(el)
|
||||
el.onerror = () => reject(new Error('图片解码失败(格式不支持?)'))
|
||||
el.src = url
|
||||
})
|
||||
return {
|
||||
w: img.naturalWidth, h: img.naturalHeight, draw: img,
|
||||
dispose: () => URL.revokeObjectURL(url),
|
||||
}
|
||||
} catch (e) {
|
||||
URL.revokeObjectURL(url)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
async function encodeCanvas(file: File, maxSide: number, quality: number): Promise<{
|
||||
uri: string; width: number; height: number
|
||||
}> {
|
||||
const src = await loadBitmap(file)
|
||||
try {
|
||||
const scale = Math.min(1, maxSide / Math.max(src.w || 1, src.h || 1))
|
||||
const w = Math.max(1, Math.round((src.w || 1) * scale))
|
||||
const h = Math.max(1, Math.round((src.h || 1) * scale))
|
||||
const cv = document.createElement('canvas')
|
||||
cv.width = w
|
||||
cv.height = h
|
||||
const ctx = cv.getContext('2d')
|
||||
if (!ctx) throw new Error('浏览器不支持 Canvas 2D,无法压缩图片')
|
||||
// 白底:PNG 透明区转 JPEG 会变黑,铺一层白更接近原图观感
|
||||
ctx.fillStyle = '#ffffff'
|
||||
ctx.fillRect(0, 0, w, h)
|
||||
ctx.drawImage(src.draw, 0, 0, w, h)
|
||||
return { uri: cv.toDataURL('image/jpeg', quality), width: w, height: h }
|
||||
} finally {
|
||||
src.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
/** 生成缩略图(对话历史、列表预览用)。失败时回落到原图,不阻断主流程。 */
|
||||
export async function makeThumb(dataUri: string, maxSide = 256, quality = 0.6): Promise<string> {
|
||||
try {
|
||||
const blob = await (await fetch(dataUri)).blob()
|
||||
const file = new File([blob], 'thumb.jpg', { type: blob.type || 'image/jpeg' })
|
||||
return (await encodeCanvas(file, maxSide, quality)).uri
|
||||
} catch {
|
||||
return dataUri
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片 → data URI(自动压缩到预设档位内)。
|
||||
*
|
||||
* 策略:文件本来就不大且是无损格式 → 原样用;否则画布重编码,并按
|
||||
* 「原档 → 0.75×边长 → 0.5×边长」逐级降档,直到落进 maxBytes 预算。
|
||||
*/
|
||||
export async function pickImage(file: File, preset: MediaPreset): Promise<PickedMedia> {
|
||||
if (!isImageFile(file)) throw new Error(`${file.name} 不是图片文件`)
|
||||
const raw = await readAsDataUri(file)
|
||||
// 小体积 PNG/WEBP 直接原样用(避免无谓的有损压缩,也保住透明通道)
|
||||
if (raw.length <= preset.maxBytes && /png|webp|gif|bmp/i.test(file.type || extOf(file.name))) {
|
||||
return {
|
||||
name: file.name, kind: 'image', uri: raw, thumb: await makeThumb(raw),
|
||||
bytes: raw.length, compressed: false,
|
||||
}
|
||||
}
|
||||
const tries: Array<[number, number]> = [
|
||||
[preset.maxSide, preset.quality],
|
||||
[Math.round(preset.maxSide * 0.75), Math.max(0.5, preset.quality - 0.1)],
|
||||
[Math.round(preset.maxSide * 0.5), 0.6],
|
||||
[Math.round(preset.maxSide * 0.35), 0.5],
|
||||
]
|
||||
let last = ''
|
||||
for (const [side, q] of tries) {
|
||||
const enc = await encodeCanvas(file, side, q)
|
||||
last = enc.uri
|
||||
if (enc.uri.length <= preset.maxBytes) {
|
||||
return {
|
||||
name: file.name, kind: 'image', uri: enc.uri, thumb: await makeThumb(enc.uri),
|
||||
bytes: enc.uri.length, width: enc.width, height: enc.height, compressed: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`${file.name} 压缩后仍有 ${formatBytes(dataUriBytes(last))},超过 ${preset.label} 单件上限 ${formatBytes(preset.maxBytes)}`)
|
||||
}
|
||||
|
||||
/** 音频 → data URI(浏览器端无法重编码,只做体积与格式校验)。 */
|
||||
export async function pickAudio(file: File, preset: MediaPreset = PRESETS.audio): Promise<PickedMedia> {
|
||||
if (!isAudioFile(file)) throw new Error(`${file.name} 不是音频文件(支持 ${AUDIO_EXT.join('/')})`)
|
||||
if (file.size > preset.maxBytes) {
|
||||
throw new Error(`${file.name} 有 ${formatBytes(file.size)},超过参考音频上限 ${formatBytes(preset.maxBytes)}(请裁剪或压缩后再传)`)
|
||||
}
|
||||
const uri = await readAsDataUri(file)
|
||||
return { name: file.name, kind: 'audio', uri, thumb: '', bytes: uri.length, compressed: false }
|
||||
}
|
||||
|
||||
/** 按类型自动选择解析方式。 */
|
||||
export async function pickMedia(file: File, preset: MediaPreset): Promise<PickedMedia> {
|
||||
return isAudioFile(file) ? pickAudio(file, PRESETS.audio) : pickImage(file, preset)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交前的整包预算检查:素材 + 提示词必须落在网关/Nginx 的请求体上限内。
|
||||
* 抛出可读错误(页面直接展示),而不是让浏览器拿到一个 413。
|
||||
*/
|
||||
export function assertBodyBudget(parts: Array<string | undefined>, extraBytes = 0): void {
|
||||
const total = parts.reduce((n, p) => n + (p ? p.length : 0), 0) + extraBytes
|
||||
if (total > BODY_BUDGET) {
|
||||
throw new Error(
|
||||
`本次请求体约 ${formatBytes(total)},超过网关上送上限(约 ${formatBytes(BODY_BUDGET)})。` +
|
||||
'请减少素材数量,或换体积更小的图片/音频。',
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,781 @@
|
||||
// English locale resource
|
||||
export default {
|
||||
nav: {
|
||||
title: 'API Gateway',
|
||||
connected: 'Connected to 127.0.0.1:8808',
|
||||
disconnected: 'Connection error',
|
||||
menudashboard: 'Dashboard',
|
||||
menuchat: 'Chat',
|
||||
menuimages: 'Images',
|
||||
menuvideos: 'Videos',
|
||||
menumodels: 'Models & Providers',
|
||||
menumetrics: 'Metrics',
|
||||
menukeys: 'API Keys',
|
||||
menuusers: 'Users',
|
||||
menulogs: 'Logs',
|
||||
menufeedback: 'Feedback',
|
||||
menufeedbackinbox: 'User feedback',
|
||||
menusettings: 'Settings',
|
||||
control: 'Console',
|
||||
more: 'More',
|
||||
subdashboard: 'Gateway overview · refreshed every 8s',
|
||||
subchat: 'Vision-ready · route wjd picks the fastest provider',
|
||||
subimages: 'Params on the left, history on the right · downloads proxied by the gateway',
|
||||
subvideos: '720P · 4–12s · async polling',
|
||||
submodels: 'Providers / models / route chains',
|
||||
submetrics: 'Usage & cost · isolated per account',
|
||||
subkeys: 'Up to 3 per account · stored in plaintext, copyable anytime',
|
||||
subusers: 'Accounts & roles · admin can inspect others’ logs and assets',
|
||||
sublogs: 'Isolated per account · expand for request / response details',
|
||||
subfeedback: 'Something off? Tell us · images welcome',
|
||||
subfeedbackinbox: 'Feedback from every account · images included',
|
||||
subgatewaycfg: 'Every config key, editable · applied on save',
|
||||
menugatewaycfg: 'Gateway config',
|
||||
subsettings: 'Appearance / generation defaults / security / gateway',
|
||||
},
|
||||
theme: {
|
||||
choose: 'Appearance',
|
||||
followSystem: 'Follow system dark mode',
|
||||
followShort: 'System',
|
||||
applied: 'Theme switched',
|
||||
// Skin names / blurbs (mirror of zh.ts)
|
||||
nameA: 'A · Deep Space Blue',
|
||||
descA: 'Dark base + teal, easy on the eyes at night',
|
||||
nameB: 'B · Ivory Indigo',
|
||||
descB: 'Light base with white cards, clearest in daylight',
|
||||
nameC: 'C · Warm Sand Green',
|
||||
descC: 'Warm off-white + deep green, calm and steady',
|
||||
},
|
||||
top: {
|
||||
refresh: 'Refresh this page',
|
||||
},
|
||||
common: {
|
||||
all: 'All',
|
||||
export: 'Export',
|
||||
refresh: 'Refresh',
|
||||
admin: 'admin',
|
||||
logout: 'Sign out',
|
||||
yes: 'Yes',
|
||||
no: 'No',
|
||||
none: '—',
|
||||
empty: '(empty)',
|
||||
ok: 'OK',
|
||||
fail: 'FAIL',
|
||||
copy: 'Copy',
|
||||
copyOk: 'Copied',
|
||||
copyFail: 'Copy failed — select the text manually',
|
||||
save: 'Save',
|
||||
delete: 'Delete',
|
||||
reset: 'Reset',
|
||||
search: 'Search',
|
||||
confirm: 'Confirm',
|
||||
cancel: 'Cancel',
|
||||
},
|
||||
login: {
|
||||
title: 'API Gateway Console',
|
||||
userPlaceholder: 'Username',
|
||||
passPlaceholder: 'Password',
|
||||
btn: 'Sign in',
|
||||
errEmpty: 'Please enter account and password',
|
||||
err401: 'Incorrect username or password',
|
||||
err429: 'Too many attempts, rate-limited. Please try again later',
|
||||
err403: 'Sign-in denied (account disabled or invalid role)',
|
||||
errConn: 'Cannot reach gateway — is it running on 8808?',
|
||||
success: 'Signed in',
|
||||
},
|
||||
dashboard: {
|
||||
modelCount: 'Models',
|
||||
providers: 'Providers',
|
||||
routes: 'Route aliases',
|
||||
fallback: 'Fallbacks',
|
||||
inflight: 'In-flight',
|
||||
callsMix: 'Calls ok/fail',
|
||||
provShare: 'Provider success share',
|
||||
latency: 'Model latency P50 / P95 (s)',
|
||||
providerStatus: 'Provider status',
|
||||
mediaCircuit: 'Media circuit',
|
||||
circuit: 'Circuit',
|
||||
modelCountShort: 'Models',
|
||||
keySet: 'Key set',
|
||||
routeAlias: 'Route aliases',
|
||||
name: 'Name',
|
||||
modelChain: 'Model chain',
|
||||
gatewayInfo: 'Gateway info',
|
||||
running: 'Running',
|
||||
uptime: 'Uptime',
|
||||
gwVersion: 'Gateway version',
|
||||
concurrency: 'In-flight {cur} / peak {peak}',
|
||||
latTitle: 'Model latency P50 / P95 (s)',
|
||||
circ_closed: 'CLOSED',
|
||||
circ_half_open: 'HALF_OPEN',
|
||||
circ_open: 'OPEN',
|
||||
circ_not_tracked: 'Not tracked',
|
||||
noData: 'No data',
|
||||
requests: 'Total requests',
|
||||
successRate: 'Success rate',
|
||||
avgLatency: 'Avg latency',
|
||||
fallbackShort: 'Fallbacks',
|
||||
noteOkFail: 'ok {ok} · fail {fail}',
|
||||
noteFail: '{n} failed',
|
||||
noteP95: 'highest P95 {v}s',
|
||||
noteInflight: '{n} in flight',
|
||||
modelCalls: 'Calls by model',
|
||||
colModel: 'Model',
|
||||
colCalls: 'Calls',
|
||||
colLatency: 'Avg latency',
|
||||
colRate: 'Success rate',
|
||||
noModels: 'No calls recorded yet',
|
||||
share: 'Share',
|
||||
live: 'Live',
|
||||
routeChain: 'Availability + speed first',
|
||||
},
|
||||
metrics: {
|
||||
uptime: 'Uptime',
|
||||
inflight: 'In-flight/peak',
|
||||
fallback: 'Fallbacks',
|
||||
promptTokens: 'Prompt tokens',
|
||||
completionTokens: 'Completion tokens',
|
||||
callsTotal: 'Total calls (ok/fail)',
|
||||
modelCalls: 'Calls per model (success / fail)',
|
||||
provShare: 'Provider success share',
|
||||
routeVsProvider: 'Route vs provider (success / fail / fallback)',
|
||||
latency: 'Model latency P50 / P95 (s)',
|
||||
success: 'Success',
|
||||
fail: 'Fail',
|
||||
fallback2: 'Fallback',
|
||||
ok: 'ok',
|
||||
none: 'None',
|
||||
circuitStatus: 'Circuit breaker status',
|
||||
provider: 'Provider',
|
||||
state: 'State',
|
||||
recentFailures: 'Recent failures',
|
||||
window: 'Window',
|
||||
threshold: 'Threshold',
|
||||
cooldown: 'Cooldown(s)',
|
||||
probing: 'Probing',
|
||||
stateClosed: 'CLOSED',
|
||||
stateHalf: 'HALF_OPEN',
|
||||
stateOpen: 'OPEN',
|
||||
loadErr: 'Failed to load metrics',
|
||||
requests: 'Total requests',
|
||||
failCount: 'Failures',
|
||||
tokenUsage: 'Token usage',
|
||||
tokenNote: 'in {p} / out {c}',
|
||||
inflightPeak: 'In flight / peak',
|
||||
failRateNote: 'failure rate {v}%',
|
||||
snapshot: 'Live snapshot',
|
||||
circuitCard: 'Circuit breakers',
|
||||
},
|
||||
logs: {
|
||||
all: 'All',
|
||||
chat: 'Chat',
|
||||
image: 'Image',
|
||||
video: 'Video',
|
||||
autoRefresh: 'Auto-refresh',
|
||||
method: 'Method',
|
||||
result: 'Result',
|
||||
success: 'Success',
|
||||
fail: 'Fail',
|
||||
searchPlaceholder: 'Search model/provider/path/request/response',
|
||||
count: '{n} entries',
|
||||
clearFilter: 'Clear filter',
|
||||
time: 'Time',
|
||||
path: 'Path',
|
||||
modelProvider: 'Model / provider',
|
||||
reqContent: 'Request',
|
||||
respContent: 'Response',
|
||||
empty: 'No logs',
|
||||
emptyFiltered: 'No entries match the current filters ({n} loaded — clear other filters or the keyword)',
|
||||
media: 'Download',
|
||||
request: 'Request',
|
||||
polls: 'Polls ({n})',
|
||||
response: 'Response',
|
||||
error: 'Error',
|
||||
rid: 'rid',
|
||||
caller: 'Caller',
|
||||
reqModel: 'Requested model',
|
||||
served: 'Served model',
|
||||
provider: 'Provider',
|
||||
streaming: 'Streaming',
|
||||
loadErr: 'Failed to load logs',
|
||||
},
|
||||
users: {
|
||||
viewLogs: 'View logs',
|
||||
viewActivity: 'Activity',
|
||||
tabLogs: 'Call logs',
|
||||
tabImages: 'Images',
|
||||
tabVideos: 'Videos',
|
||||
noData: 'No records',
|
||||
// Admin downloads this account's generated images / videos (proxied by the gateway)
|
||||
dl: 'Download',
|
||||
dlOk: 'Download started',
|
||||
dlFail: 'Download failed: {msg}',
|
||||
dlNoSrc: 'This record has no downloadable URL yet',
|
||||
},
|
||||
chat: {
|
||||
newChat: 'New chat',
|
||||
session: 'Conversation',
|
||||
thisConv: 'This conversation',
|
||||
model: 'Model',
|
||||
elapsed: 'Elapsed',
|
||||
msgsN: '{n} msgs',
|
||||
regenerate: 'Regenerate',
|
||||
copyAll: 'Copy all',
|
||||
tempShort: 'Temp',
|
||||
maxShort: 'Max',
|
||||
systemShort: 'System',
|
||||
visionReady: 'Vision ready · images supported',
|
||||
visionOff: 'This model does not accept images',
|
||||
chainLabel: '{id} ({chain})',
|
||||
emptyChain: 'empty',
|
||||
phDefault: 'Default',
|
||||
phOptional: 'Optional',
|
||||
totalTokens: 'Total {n}',
|
||||
uploadedImage: 'Uploaded image',
|
||||
reasoningTag: 'Reasoning',
|
||||
routeGroup: 'Routes (auto fallback)',
|
||||
textModels: 'Text models',
|
||||
params: 'Parameters',
|
||||
clear: 'Clear',
|
||||
generating: 'Generating…',
|
||||
empty: 'Start a conversation with the gateway (any text model or route wjd)',
|
||||
fallback: 'Fallback · by {provider}',
|
||||
servedBy: 'by {provider}',
|
||||
requestedTo: 'requested {req} → served {served}',
|
||||
reasoning: 'Reasoning',
|
||||
thinking: 'Thinking…',
|
||||
emptyResp: '(empty response)',
|
||||
youError: 'Error: {msg}',
|
||||
placeholder: 'Type a message, Enter to send, Shift+Enter for newline',
|
||||
imgUpload: 'Upload image',
|
||||
imgUrlBtn: 'Image URL',
|
||||
imgPh: 'Paste an image URL, Enter to add',
|
||||
imgAdd: 'Add',
|
||||
imgMax: 'At most {n} images per message',
|
||||
imgPickErr: 'Image processing failed: {msg}',
|
||||
visionWarn: 'Model {model} does not accept image input — images will be ignored or rejected. Switch to a vision-capable model.',
|
||||
useVision: 'Switch to {model}',
|
||||
waiting: 'Awaiting input…',
|
||||
send: 'Send',
|
||||
stop: 'Stop',
|
||||
stopped: 'Stopped',
|
||||
temp: 'Temperature',
|
||||
topP: 'top_p',
|
||||
maxTokens: 'max_tokens (empty = default)',
|
||||
streaming: 'Streaming output',
|
||||
system: 'System prompt (prepended to each conversation)',
|
||||
loadModelsErr: 'Failed to load models: {msg}',
|
||||
},
|
||||
images: {
|
||||
historyTitle: 'History',
|
||||
historySub: '{n} images',
|
||||
refsLabel: 'Reference images',
|
||||
title: 'Image generation',
|
||||
model: 'Image model',
|
||||
size: 'Size',
|
||||
ratio: 'Ratio',
|
||||
refsUpload: 'Upload reference',
|
||||
refsUrlBtn: 'Reference URL',
|
||||
refsHint: '(empty = text-to-image; uploaded images are compressed in-browser, uploads and URLs can be mixed)',
|
||||
refsMax: 'At most {n} reference images',
|
||||
refPickErr: 'Image processing failed: {msg}',
|
||||
refsPH: 'Image-to-image / multi-image: image URLs or data:, one per line (empty = text-to-image)',
|
||||
count: 'Count',
|
||||
countTip: 'The upstream API returns 1 image per call; multiple images are generated one by one',
|
||||
genProgress: 'Generating {i}/{n}',
|
||||
partialFail: 'Generated {done}, image #{i} failed: {msg}',
|
||||
refsUsed: '{n} reference image(s)',
|
||||
emptyResp: 'The upstream returned no image',
|
||||
placeholder: 'Describe the image to generate (style / subject / composition)',
|
||||
servedBy: 'Generated by {provider}',
|
||||
clear: 'Clear history',
|
||||
confirmClear: 'Clear all {n} image record(s)? They are also deleted server-side (other devices lose them too). This cannot be undone.',
|
||||
generate: 'Generate',
|
||||
promptRow: 'Prompt',
|
||||
imgLoadErr: 'Image failed to load',
|
||||
dl: 'Download',
|
||||
dlOk: 'Download started',
|
||||
dlFail: 'Download failed: {msg}',
|
||||
dlNoSrc: 'This image has no downloadable URL',
|
||||
empty: 'Generated images appear here',
|
||||
loadErr: 'Failed to generate image',
|
||||
},
|
||||
videos: {
|
||||
taskTitle: 'Tasks',
|
||||
fixed: 'Fixed',
|
||||
title: 'Video generation',
|
||||
model: 'Video model',
|
||||
mode: 'Scenario',
|
||||
modeText: 'Text to video',
|
||||
modeKeyframe: 'Keyframe (img2video)',
|
||||
modeReference: 'Reference img/audio',
|
||||
firstFrame: 'First frame',
|
||||
lastFrame: 'Last frame',
|
||||
upload: 'Upload image',
|
||||
uploadImg: 'Upload reference',
|
||||
uploadAudio: 'Upload audio',
|
||||
useUrl: 'Use URL',
|
||||
urlPH: 'or paste an image URL',
|
||||
uploadTip: 'Uploaded material is compressed to a data URI in the browser and sent directly (no public URL needed)',
|
||||
pickErr: 'Failed to process material: {msg}',
|
||||
refMax: 'At most {n} reference images',
|
||||
audMax: 'At most {n} reference audios',
|
||||
count5: '{n}/5 selected',
|
||||
count3: '{n}/3 selected',
|
||||
media: 'Media',
|
||||
seed: 'Seed',
|
||||
seedPH: 'empty = random',
|
||||
keyframeTip: 'Give at least one of first/last frame — upload or paste a URL (first = opening shot, last = closing shot)',
|
||||
refImagesPH: 'Reference image URLs, one per line (max 5)',
|
||||
refAudiosPH: 'Reference audio URLs, one per line (max 3)',
|
||||
referenceTip: 'In the prompt, <Picture N> / <Audio N> refer to the Nth material',
|
||||
placeholderRef: 'Describe the video and camera move (use <Picture 1> / <Audio 1> for reference materials)',
|
||||
needFrame: 'Keyframe mode needs at least one uploaded image or image URL',
|
||||
needRef: 'Reference mode needs at least one image or audio (upload or URL)',
|
||||
duration: 'Duration (s)',
|
||||
aspect: 'Aspect',
|
||||
quality: 'Quality',
|
||||
placeholder: 'Describe the video content and camera movement',
|
||||
async: 'Submit async (return now, poll later)',
|
||||
taskCount: 'Tasks {n}',
|
||||
clear: 'Clear finished',
|
||||
confirmClear: 'Clear {n} finished video task(s)? Records and video links are also deleted server-side. This cannot be undone.',
|
||||
generate: 'Generate video',
|
||||
status: 'Status',
|
||||
task: 'Task',
|
||||
service: 'Service',
|
||||
promptRow: 'Prompt',
|
||||
elapsed: 'Elapsed',
|
||||
subElapsed: '{n}s elapsed',
|
||||
subWait: 'waiting {n}s',
|
||||
raw: 'Raw response',
|
||||
empty: 'Submitted video tasks appear here',
|
||||
failText: 'Generation failed',
|
||||
doneText: 'Done',
|
||||
doingText: 'Generating…',
|
||||
doneMsg: 'Video ready',
|
||||
dl: 'Download video',
|
||||
dlOk: 'Download started',
|
||||
dlFail: 'Download failed: {msg}',
|
||||
dlNoSrc: 'This task has no downloadable video yet',
|
||||
submitMsg: 'Submitted task {id}',
|
||||
loadErr: 'Failed to load videos',
|
||||
},
|
||||
models: {
|
||||
routeAliasTitle: 'Route aliases (auto fallback chain)',
|
||||
modelListTitle: 'Model list',
|
||||
name: 'Name',
|
||||
chainLabel: 'Model chain (tried in order, auto fallback on failure)',
|
||||
providerCount: 'Providers',
|
||||
id: 'Model ID',
|
||||
type: 'Type',
|
||||
provider: 'Provider',
|
||||
keySet: 'Key set',
|
||||
text: 'Text',
|
||||
image: 'Image',
|
||||
video: 'Video',
|
||||
route: 'Route',
|
||||
model: 'Models',
|
||||
textModels: 'Text models',
|
||||
imageModels: 'Image models',
|
||||
videoModels: 'Video models',
|
||||
routes: 'Route aliases',
|
||||
providers: 'Providers',
|
||||
loadErr: 'Failed to load models',
|
||||
capability: 'Capability',
|
||||
visionTag: 'Vision',
|
||||
allTextModels: 'All text models',
|
||||
providerCard: 'Providers',
|
||||
keyOk: 'Key configured',
|
||||
keyMissing: 'Key missing',
|
||||
routeCount: '{n} routes',
|
||||
chainCount: '{n} models',
|
||||
providerCount2: '{n} providers',
|
||||
noRoute: 'No route alias configured',
|
||||
speedtest: 'Test speed',
|
||||
testing: 'Probing latency of every text model…',
|
||||
testingShort: 'Testing…',
|
||||
testOne: 'Test this model',
|
||||
latency: 'Latency',
|
||||
failed: 'Failed',
|
||||
speedtestDone: 'Speed test done, {n} models',
|
||||
speedtestFail: 'Speed test failed',
|
||||
},
|
||||
history: {
|
||||
saveFail: 'History could not be saved to the gateway (it may be lost on refresh) — check your session or network',
|
||||
offline: 'History API unreachable — showing local browser cache only',
|
||||
},
|
||||
settings: {
|
||||
keyUnlimited: 'Unlimited',
|
||||
connInfo: 'Connection',
|
||||
gwAddress: 'Gateway URL',
|
||||
gwVersion: 'Gateway version',
|
||||
loginUser: 'User',
|
||||
sessionLen: 'Session duration',
|
||||
hours: '{n} hours',
|
||||
language: 'Language',
|
||||
langTip: 'Switch interface language (saved locally)',
|
||||
theme: 'Appearance',
|
||||
appearance: 'Appearance & language',
|
||||
themeSub: 'B is the default; switch to A / C anytime',
|
||||
current: 'Current',
|
||||
switch: 'Switch',
|
||||
followSystem: 'Follow system dark mode',
|
||||
followSub: 'Use theme A automatically when the system goes dark',
|
||||
langSub: 'Full Chinese / English coverage',
|
||||
myKeys: 'My API keys',
|
||||
myKeysSub: 'Create / copy / delete, up to 3 per account',
|
||||
manage: 'Manage',
|
||||
gwCard: 'Gateway info',
|
||||
account: 'Account',
|
||||
logoutTip: 'Signing out ends this session; log in again with account and password.',
|
||||
logoutBtn: 'Sign out',
|
||||
chatDefaults: 'Chat default parameters',
|
||||
defsTip: 'Used as defaults for a new chat (already-adjusted params are untouched).',
|
||||
defaultModel: 'Default model / route',
|
||||
temperature: 'Temperature',
|
||||
topP: 'top_p',
|
||||
maxTokens: 'max_tokens (empty = gateway default)',
|
||||
streaming: 'Streaming output',
|
||||
system: 'System prompt',
|
||||
save: 'Save defaults',
|
||||
saveOk: 'Defaults saved — applied to new chats',
|
||||
resetOk: 'Restored to defaults',
|
||||
providerStatus: 'Provider status',
|
||||
modelsCount: 'Models',
|
||||
userManagement: 'Account management (admin)',
|
||||
gwConfigBtn: 'Open',
|
||||
gwConfigSub: 'Tune gateway / providers / routes / pricing — applied on save',
|
||||
gwConfig: 'Gateway config (admin)',
|
||||
userCol: 'User',
|
||||
roleCol: 'Role',
|
||||
accountDeleted: 'Account {name} deleted (sessions and API keys revoked)',
|
||||
revokeKeys: 'Revoke all keys',
|
||||
revokeKeysOk: 'Revoked {n} API key(s) of {name}',
|
||||
resetPwOk: 'Password of {name} reset to the username; {n} session(s) kicked out',
|
||||
confirmDeleteUser: 'Delete account {name}? Its sessions and API keys stop working immediately. This cannot be undone.',
|
||||
confirmResetPw: 'Reset the password of {name} to its username? Active sessions of that account will be signed out.',
|
||||
confirmRevokeKeys: 'Revoke every API key of {name}? Callers must create new keys to keep using the gateway.',
|
||||
userPwOptional: 'Initial password (empty = same as username)',
|
||||
confirm: 'Confirm',
|
||||
confirmDeleteKey: 'Delete this API key? Clients using it get 401 immediately and need a new key.',
|
||||
usersTip: 'Create accounts / reset passwords / disable or enable / delete (admin only)',
|
||||
userCreated: 'Created',
|
||||
// Round 24: admin can disable / enable an account
|
||||
userDisabled: 'Disabled',
|
||||
userDisabledAt: 'Disabled at {ts}',
|
||||
disableUser: 'Disable',
|
||||
enableUser: 'Enable',
|
||||
confirmDisableUser: 'Disable account {name}? It can no longer sign in, its API keys stop working immediately (keys are kept and work again once re-enabled), and its signed-in sessions are kicked out.',
|
||||
userDisabledOk: 'Account {name} disabled ({n} session(s) kicked out, API keys suspended)',
|
||||
userEnabledOk: 'Account {name} enabled — old password and API keys work again',
|
||||
namesRule: 'Username must be alphanumeric; default password = username',
|
||||
changePw: 'Change password',
|
||||
newPw: 'New password (min 4 chars)',
|
||||
pwTip: 'You are signed in — just set a new password, no current password needed. All sessions are revoked and you will sign in again with the new one.',
|
||||
pwNeedNew: 'Please enter a new password',
|
||||
pwChanged: 'Password updated — please sign in again',
|
||||
keyLabel: 'Label (optional)',
|
||||
keyHint: 'Key prefix',
|
||||
keyCreated: 'Created',
|
||||
createKey: 'Create API Key',
|
||||
keyCol: 'API key',
|
||||
keyLimitFull: 'Limit reached',
|
||||
keyLegacyNoEcho: '(created before plaintext echo — cannot be shown again)',
|
||||
noKey: 'You have no API Key — create one to use as a Bearer credential externally',
|
||||
userMgmt: 'Account management (admin)',
|
||||
newUserName: 'New username (alphanumeric)',
|
||||
newUserTip: 'Create account; default password = username',
|
||||
createUser: 'Create account',
|
||||
keyCount: 'Keys',
|
||||
resetPw: 'Reset password',
|
||||
loadErr: 'Failed to load settings',
|
||||
},
|
||||
apidoc: {
|
||||
copyCurl: 'Copy curl example',
|
||||
viewDoc: 'View API docs',
|
||||
title: 'API usage guide',
|
||||
intro: 'Use the API Key above as the Bearer credential to call the gateway (OpenAI compatible). API keys can only call models; creating keys / changing passwords / managing accounts require a web session — a key hitting admin endpoints gets 403.',
|
||||
baseTitle: 'Basics',
|
||||
baseUrl: 'Base URL',
|
||||
auth: 'Auth',
|
||||
authVal: 'Header: Authorization: Bearer <your API Key>',
|
||||
modelPick: 'Model selection',
|
||||
modelPickVal: 'model: wjd = route alias (auto-fallback by availability + speed, recommended); or a concrete model id to bypass fallback',
|
||||
ctype: 'Request format',
|
||||
ctypeVal: 'application/json; chat supports SSE streaming (stream: true)',
|
||||
endpoints: 'Endpoints',
|
||||
colMethod: 'Method',
|
||||
colPath: 'Path',
|
||||
colDesc: 'Description',
|
||||
epModels: 'Models and routes (with a vision flag)',
|
||||
epChat: 'Chat completions (OpenAI compatible, streaming + image input)',
|
||||
epImages: 'Image generation / image-to-image (n must be 1; call repeatedly for more)',
|
||||
epVideoCreate: 'Video generation (async, returns video_id immediately)',
|
||||
epVideoPoll: 'Poll a video task (every ~5s; returns throttled when upstream rate-limits)',
|
||||
epHistory: 'Read your own history (images / videos / chats)',
|
||||
epLogs: 'Your own call log',
|
||||
epMetrics: 'Metrics snapshot (incl. circuit breaker states)',
|
||||
epHealth: 'Health check (version / provider status)',
|
||||
exChat: 'Example · chat',
|
||||
exImg: 'Example · image generation',
|
||||
exVideo: 'Example · video generation + polling',
|
||||
exPy: 'Example · Python (OpenAI SDK compatible)',
|
||||
// Comments / sample payloads inside the code samples (mirror of zh.ts)
|
||||
sampleChat: 'Hello, introduce yourself',
|
||||
sampleImg: 'Neon city street at night',
|
||||
sampleVideo: 'Slow camera push-in',
|
||||
sampleStep1: 'submit a task (async, returns video_id immediately)',
|
||||
sampleStep2: 'poll every 5s (a throttled reply means wait, then retry)',
|
||||
notes: 'Notes',
|
||||
noteVision: 'For image input use a vision model (agnes-3.0-flash, marked "Vision" in the list); with the wjd alias the gateway puts vision models first.',
|
||||
noteN1: 'Image n must be 1 (upstream limit) — call once per image; n≠1 is rejected with a clean 400.',
|
||||
noteVideo: 'Video seconds: 4–12 only; size is fixed at 720P; 6 aspect ratios (21:9/16:9/4:3/1:1/3:4/9:16); mode=text / keyframe / reference.',
|
||||
notePoll: 'Do not poll faster than 5s (upstream answers 429 "too frequent"; the gateway returns throttled so you can back off).',
|
||||
noteMedia: 'Assets (reference images / first-last frames / audio / chat images) accept data:image/...;base64,... or a public URL; data URIs avoid exposing the file, but keep each request body under 2MB.',
|
||||
noteKey: 'If a key leaks, delete it here (401 immediately) or revoke all keys of the account from the Users page.',
|
||||
noteAudit: 'Every call is logged per account on the Logs page (you see yours; admins can inspect each account from the Users page).',
|
||||
copyBase: 'Copy URL',
|
||||
copyCmd: 'Copy',
|
||||
},
|
||||
// Round 22: feedback (member submit + progress) / inbox (admin: all + update progress)
|
||||
fbStatus: {
|
||||
pending: 'Pending',
|
||||
doing: 'In progress',
|
||||
done: 'Resolved',
|
||||
},
|
||||
feedback: {
|
||||
write: 'Write your feedback',
|
||||
placeholder: 'What feels clunky, what feature you want, what is unclear — anything goes',
|
||||
attach: 'Add image',
|
||||
imagesHint: 'Up to {n} · compressed before upload',
|
||||
remove: 'Remove',
|
||||
needContent: 'Write something before submitting',
|
||||
submit: 'Submit',
|
||||
submitted: 'Got it — thanks for the feedback!',
|
||||
mine: 'My submissions',
|
||||
mineSub: 'Track progress here after submitting',
|
||||
empty: 'No feedback submitted yet',
|
||||
statusAll: 'All statuses',
|
||||
|
||||
revoke: 'Withdraw',
|
||||
revokeTitle: 'Withdraw this feedback?',
|
||||
revokeBody: 'Withdrawing deletes "{n}" permanently — once an admin starts handling it you can no longer withdraw.',
|
||||
revoked: 'Withdrawn',
|
||||
},
|
||||
// Handling log (timeline): submission + every admin action
|
||||
fbLog: {
|
||||
title: 'Handling log',
|
||||
submitted: 'submitted',
|
||||
more: 'Show all {n} entries',
|
||||
less: 'Collapse',
|
||||
},
|
||||
inbox: {
|
||||
all: 'All accounts',
|
||||
allStatus: 'All statuses',
|
||||
kw: 'Search content / account',
|
||||
empty: 'No feedback yet',
|
||||
emptyFiltered: 'Loaded {n} items, none match the current filter',
|
||||
count: '{n} total',
|
||||
account: 'Account',
|
||||
status: 'Status',
|
||||
handle: 'Update',
|
||||
archAll: 'All',
|
||||
archActive: 'Active only',
|
||||
archOnly: 'Archived only',
|
||||
archived: 'Archived',
|
||||
archive: 'Archive',
|
||||
unarchive: 'Unarchive',
|
||||
delete: 'Delete',
|
||||
deleteConfirm: 'Permanently delete this feedback and all its images — cannot be undone. Delete?',
|
||||
deleted: 'Deleted',
|
||||
archOk: 'Archived',
|
||||
unarchOk: 'Unarchived',
|
||||
|
||||
dialogTitle: 'Update this feedback',
|
||||
noteLabel: 'Note (visible to the submitter)',
|
||||
notePlaceholder: 'e.g. Reproduced the export button, shipping next release',
|
||||
save: 'Save',
|
||||
saved: 'Progress updated',
|
||||
preview: 'View full size',
|
||||
noPreview: 'No preview — click to load the original',
|
||||
loading: 'Loading…',
|
||||
loadFail: 'Failed to load image',
|
||||
imgCount: '{n} image(s)',
|
||||
},
|
||||
// Round 23: gateway config (admin edits every key of data/gateway.yaml from the UI)
|
||||
gc: {
|
||||
file: 'Gateway config file',
|
||||
fileSub: 'Admin only · applied on save',
|
||||
path: 'File',
|
||||
restartKeys: 'These need a process restart',
|
||||
otherKeys: 'Everything else',
|
||||
otherKeysTip: 'Read per request — effective immediately after saving (no restart, no reload wait)',
|
||||
saveTip: 'Saving rewrites the whole config file from this page (the old file is backed up as .bak first); secrets are never sent to the browser — only whether they are set.',
|
||||
viewYaml: 'View config file',
|
||||
save: 'Save & apply',
|
||||
saved: 'Saved and applied',
|
||||
discard: 'Discard changes',
|
||||
editorTitle: 'Config file (gateway.yaml)',
|
||||
editorSub: 'Edit the full YAML; click Save to apply',
|
||||
exportCfg: 'Export config',
|
||||
importCfg: 'Import config',
|
||||
importCfgOk: 'Config imported into editor — click Save to apply',
|
||||
envTitle: 'API key env vars',
|
||||
envSub: 'Stored in data/.env; hidden by default, show / copy / edit',
|
||||
envExport: 'Export vars',
|
||||
envImport: 'Import vars',
|
||||
envImportErr: 'Import vars failed',
|
||||
envEmpty: 'No provider uses token_env',
|
||||
envSet: 'Set',
|
||||
envMissing: 'Missing',
|
||||
envShow: 'Show',
|
||||
envHide: 'Hide',
|
||||
envCopy: 'Copy',
|
||||
envCopied: 'Copied',
|
||||
envSaved: 'Saved to env & applied',
|
||||
saveOk: 'Saved and applied',
|
||||
restartPill: 'Restart required',
|
||||
restartSaved: 'Changed restart-needed keys: {keys} — take effect after restart',
|
||||
backup: 'Backup',
|
||||
restore: 'Restore',
|
||||
backupOk: 'Backup exported (config + API keys)',
|
||||
restoreConfirm: 'This will overwrite the current config and {envs} API-key env vars. Restore?',
|
||||
restoreGo: 'Restore',
|
||||
cancel: 'Cancel',
|
||||
restoreOk: 'Config & API keys restored',
|
||||
restoreInvalid: 'Invalid backup file',
|
||||
|
||||
errTitle: 'Save failed — nothing was changed',
|
||||
needRestart: 'restart',
|
||||
restartApplied: 'Saved. These need an api-gateway restart to take effect: {keys}',
|
||||
savedRestart: 'Saved and applied',
|
||||
addItem: 'Add',
|
||||
addModel: 'Add model',
|
||||
addProvider: 'Add provider',
|
||||
addRoute: 'Add route alias',
|
||||
addPrice: 'Add pricing',
|
||||
delete: 'Delete',
|
||||
delProvider: 'Delete provider',
|
||||
delRoute: 'Delete route',
|
||||
delConfirm: 'Delete "{name}"? It takes effect once you save.',
|
||||
needKey: 'Provider key cannot be empty',
|
||||
needRoute: 'Route alias cannot be empty',
|
||||
dupKey: '"{name}" is duplicated — please rename',
|
||||
newProvider: '(new provider)',
|
||||
newRoute: '(new alias)',
|
||||
unlimited: 'empty = unlimited',
|
||||
useServerTimeout: 'empty = server.timeout',
|
||||
mediaEmpty: 'empty = unsupported',
|
||||
modelId: 'model id',
|
||||
modelDisplay: 'display name',
|
||||
hdrKey: 'header',
|
||||
hdrVal: 'value',
|
||||
tokenSet: 'key configured',
|
||||
tokenEnvMissing: 'env var not set',
|
||||
tokenKeep: 'empty = keep current',
|
||||
tokenEmpty: 'empty = none',
|
||||
jump: 'Jump to',
|
||||
tabServer: 'Server & security',
|
||||
tabServerSub: 'Binding, timeout/retry, rate limits, CORS, session TTL and other runtime switches',
|
||||
tabProviders: 'Providers & models',
|
||||
tabProvidersSub: 'Key source, base URL, image/video endpoints and the model list per provider',
|
||||
tabRoutes: 'Routes & circuit',
|
||||
tabRoutesSub: 'Route aliases with their fallback chains (order = priority) plus the circuit breaker',
|
||||
tabLog: 'Logs & pricing',
|
||||
tabLogSub: 'Log level/format/capacity plus model pricing (CNY per million tokens)',
|
||||
tabDownload: 'Download proxy',
|
||||
tabDownloadSub: 'CDN hosts allowed for the download proxy and the per-file size limit',
|
||||
circuit: 'Provider circuit breaker',
|
||||
h_circuit: 'A provider that fails to the threshold within the window is skipped for the cooldown; fallback takes over',
|
||||
f_c_enabled: 'Enable circuit breaker',
|
||||
f_c_failure_threshold: 'Failure threshold',
|
||||
f_c_cooldown: 'Cooldown (s)',
|
||||
f_c_window: 'Window (s)',
|
||||
h_c_enabled: 'Off = never skip a failing provider (fallback still works)',
|
||||
h_c_failure_threshold: 'Opens the circuit once failures reach this count in the window',
|
||||
h_c_cooldown: 'While open the provider is skipped; it half-opens automatically after the cooldown',
|
||||
h_c_window: 'Counts failures inside the window (not necessarily consecutive)',
|
||||
f_host: 'Bind address',
|
||||
h_host: '127.0.0.1 keeps it local/reverse-proxy only; 0.0.0.0 exposes the port (auth still always on)',
|
||||
f_port: 'Port',
|
||||
h_port: 'Production uses 8808 and Nginx points at it — change the proxy too',
|
||||
f_timeout: 'Upstream timeout (s)',
|
||||
h_timeout: 'Per upstream request; a route-level timeout overrides it',
|
||||
f_retry: 'Retries for direct model id',
|
||||
h_retry: 'Retries (incl. first try) when calling a real model id instead of a route alias',
|
||||
f_health_auth: 'Require auth on /health',
|
||||
// vue-i18n parses {...} as a placeholder: literal braces must be written {'{'} / {'}'},
|
||||
// otherwise the whole message fails to compile (and the UI using it renders nothing).
|
||||
// Double quotes: this message needs the {'{'} literal-brace form (braces are vue-i18n placeholders)
|
||||
h_health_auth: "Off = /health only returns {'{'}\"status\":\"ok\"{'}'} for probes, no dashboard data",
|
||||
f_hot_reload: 'Config hot reload',
|
||||
h_hot_reload: 'Reloads hand-edited files by mtime; saving from this page is always immediate',
|
||||
f_hot_reload_interval: 'Hot reload interval (s)',
|
||||
h_hot_reload_interval: 'Lower = picks up hand edits sooner, higher = less IO',
|
||||
f_metrics_enabled: 'Record metrics',
|
||||
h_metrics_enabled: 'Off = /metrics and dashboard counters stop updating (calls still work)',
|
||||
f_rate_limit_rps: 'Global QPS per account',
|
||||
h_rate_limit_rps: 'Empty = unlimited (provider/route level limits are configured separately)',
|
||||
f_max_body_size: 'Max request body (bytes)',
|
||||
h_max_body_size: '~2MB = 2000000; keep it generous if you send images',
|
||||
f_cors_origins: 'CORS allowed origins',
|
||||
h_cors_origins: '"*" lets any website drive this gateway from a browser (spending your quota); use trusted domains in production',
|
||||
f_graceful_shutdown: 'Graceful shutdown wait (s)',
|
||||
h_graceful_shutdown: 'Seconds to wait for in-flight requests after a stop signal',
|
||||
f_batch_max_concurrency: '/batch max concurrency',
|
||||
h_batch_max_concurrency: 'Larger client values are clamped to this',
|
||||
f_batch_max_items: '/batch max items',
|
||||
h_batch_max_items: 'Beyond this → 400',
|
||||
f_webhook_allow_private: 'Allow private webhook callbacks',
|
||||
h_webhook_allow_private: 'SSRF guard, off by default; enables 192.168./10./loopback callback URLs',
|
||||
f_docs_enabled: 'Expose /docs',
|
||||
h_docs_enabled: 'FastAPI built-in API docs — off by default (it lists your endpoints)',
|
||||
f_auth_fail_limit_per_min: 'Auth failures per minute',
|
||||
h_auth_fail_limit_per_min: 'Per source IP; beyond this → 429 (brute-force guard)',
|
||||
f_session_ttl_minutes: 'Web session TTL (minutes)',
|
||||
h_session_ttl_minutes: 'Login session lifetime, default 1440 = 24h; affects new logins only',
|
||||
pKey: 'Internal key',
|
||||
h_pKey: 'Identifier in config (also the /health provider key); renaming creates a new one',
|
||||
pName: 'Display name',
|
||||
pBaseUrl: 'Base URL',
|
||||
pTokenEnv: 'Key env var',
|
||||
h_pTokenEnv: 'The secret lives in .env; put the variable name here (e.g. AGNES_API_KEY) instead of plaintext',
|
||||
pToken: 'Plaintext key',
|
||||
h_pToken: 'Only if you do not use an env var; after saving it is never echoed back',
|
||||
pRateLimit: 'Provider QPS limit',
|
||||
h_pRateLimit: 'Empty = unlimited (shared by all models of this provider)',
|
||||
pHeaders: 'Extra headers',
|
||||
h_pHeaders: 'Some providers need specific headers (auth/version); leave empty if not',
|
||||
pMedia: 'Image / video endpoints',
|
||||
h_pMedia: 'Only for non-standard endpoints (Agnes uses its own paths); all empty = no image/video',
|
||||
pModels: 'Models',
|
||||
h_pModels: 'Model ids must match upstream; vision = accepts image input (preferred for image chats)',
|
||||
mVision: 'vision',
|
||||
routeHint: 'A route alias is a virtual model name (e.g. wjd): models are tried top-down and only a full failure returns 502. Order = priority.',
|
||||
rName: 'Alias',
|
||||
h_rName: 'Pass this as "model" when calling',
|
||||
rTimeout: 'Per-model timeout (s)',
|
||||
h_rTimeout: 'How long a single model may take before switching to the next one',
|
||||
rRetry: 'Per-model retries',
|
||||
h_rRetry: 'Retries before moving on (incl. first try); 1 = switch immediately',
|
||||
rRate: 'Route QPS limit',
|
||||
h_rRate: 'Empty = unlimited',
|
||||
rModels: 'Fallback chain',
|
||||
h_rModels: 'Tried top-down; available ids come from the providers above',
|
||||
f_o_log_level: 'Log level',
|
||||
h_o_log_level: 'DEBUG is noisy; INFO is fine for production',
|
||||
f_o_log_json: 'Structured JSON logs',
|
||||
h_o_log_json: 'Enable for ELK / CloudWatch; plain text is nicer for humans',
|
||||
f_o_access_log_maxlen: 'Access log capacity',
|
||||
h_o_access_log_maxlen: 'Upper bound of "loaded N entries" on the logs page (in-memory ring buffer)',
|
||||
pricing: 'Model pricing',
|
||||
h_pricing: 'CNY per million tokens, used for estimated_cost_cny; unset = omitted (calls unaffected)',
|
||||
priceIn: 'Input price',
|
||||
priceOut: 'Output price',
|
||||
dlHosts: 'Allowed download hosts',
|
||||
h_dlHosts: 'Artifact CDN domains (incl. subdomains); empty = download proxy disabled. Add an entry when the CDN changes',
|
||||
f_max_bytes: 'Max file size (bytes)',
|
||||
h_max_bytes: 'Default 67108864 = 64MB',
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,787 @@
|
||||
// 中文文案资源
|
||||
export default {
|
||||
nav: {
|
||||
title: 'API 网关',
|
||||
connected: '已连接 127.0.0.1:8808',
|
||||
disconnected: '连接异常',
|
||||
menudashboard: '仪表盘',
|
||||
menuchat: '对话',
|
||||
menuimages: '图像',
|
||||
menuvideos: '视频',
|
||||
menumodels: '模型与供应商',
|
||||
menumetrics: '指标',
|
||||
menukeys: 'API 密钥',
|
||||
menuusers: '用户管理',
|
||||
menulogs: '日志',
|
||||
menufeedback: '意见反馈',
|
||||
menufeedbackinbox: '用户反馈',
|
||||
menusettings: '设置',
|
||||
control: '控制台',
|
||||
more: '更多',
|
||||
subdashboard: '网关运行概况 · 数据每 8 秒刷新',
|
||||
subchat: '支持附图视觉 · 路由 wjd 自动选路',
|
||||
subimages: '参数在左 · 历史在右 · 下载走网关代拉',
|
||||
subvideos: '720P · 时长 4–12 秒 · 异步轮询',
|
||||
submodels: '供应商 / 模型 / 路由链',
|
||||
submetrics: '用量与成本 · 按账号隔离',
|
||||
subkeys: '每个账号最多 3 把 · 明文保存,可反复复制',
|
||||
subusers: '账号与权限 · 管理员可查他人日志与资产',
|
||||
sublogs: '按账号隔离 · 展开可看请求 / 响应摘要',
|
||||
subfeedback: '用完觉得哪里别扭?直接说 · 可附图',
|
||||
subfeedbackinbox: '全部账号提交的意见 · 含图片',
|
||||
subgatewaycfg: '配置文件可视化 · 保存即生效',
|
||||
menugatewaycfg: '网关配置',
|
||||
subsettings: '外观 / 生成默认值 / 安全 / 网关参数',
|
||||
},
|
||||
theme: {
|
||||
choose: '主题外观',
|
||||
followSystem: '跟随系统深色模式',
|
||||
followShort: '跟随系统',
|
||||
applied: '主题已切换',
|
||||
// 三套皮肤的名字与一句话说明(THEME_META 只存 key,换语言时跟着变)
|
||||
nameA: 'A · 深空蓝',
|
||||
descA: '深色底 + 青绿,夜里护眼',
|
||||
nameB: 'B · 素白蓝紫',
|
||||
descB: '浅底白卡,白天最清楚',
|
||||
nameC: 'C · 暖砂墨绿',
|
||||
descC: '暖白底 + 墨绿,温和稳重',
|
||||
},
|
||||
top: {
|
||||
refresh: '刷新当前页',
|
||||
},
|
||||
common: {
|
||||
all: '全部',
|
||||
export: '导出',
|
||||
refresh: '刷新',
|
||||
admin: '管理员',
|
||||
logout: '退出登录',
|
||||
yes: '是',
|
||||
no: '否',
|
||||
none: '—',
|
||||
empty: '(空)',
|
||||
ok: 'OK',
|
||||
fail: 'FAIL',
|
||||
copy: '复制',
|
||||
copyOk: '已复制',
|
||||
copyFail: '复制失败,请手动选中复制',
|
||||
save: '保存',
|
||||
delete: '删除',
|
||||
reset: '恢复默认',
|
||||
search: '查询',
|
||||
confirm: '确认',
|
||||
cancel: '取消',
|
||||
},
|
||||
login: {
|
||||
title: 'API 网关管理台',
|
||||
userPlaceholder: '用户名',
|
||||
passPlaceholder: '密码',
|
||||
btn: '登录',
|
||||
errEmpty: '请输入账号和密码',
|
||||
err401: '账号或密码错误',
|
||||
err429: '尝试次数过多,已触发限流,请稍后再试',
|
||||
err403: '登录被拒绝(账号被禁用或角色异常)',
|
||||
errConn: '无法连接网关,请检查服务是否在 8808 运行',
|
||||
success: '登录成功',
|
||||
},
|
||||
dashboard: {
|
||||
modelCount: '模型数',
|
||||
providers: '供应商',
|
||||
routes: '路由别名',
|
||||
fallback: '成功降级',
|
||||
inflight: '当前并发',
|
||||
callsMix: '调用 ok/fail',
|
||||
provShare: '供应商成功调用份额',
|
||||
latency: '模型延迟 P50 / P95(s)',
|
||||
providerStatus: '供应商状态',
|
||||
mediaCircuit: '媒体熔断',
|
||||
circuit: '熔断',
|
||||
modelCountShort: '模型数',
|
||||
keySet: '已配 Key',
|
||||
routeAlias: '路由别名',
|
||||
name: '名称',
|
||||
modelChain: '模型链',
|
||||
gatewayInfo: '网关信息',
|
||||
running: '运行中',
|
||||
uptime: '已运行',
|
||||
gwVersion: '网关版本',
|
||||
concurrency: '当前并发 in-flight {cur} / 峰值 {peak}',
|
||||
latTitle: '模型延迟 P50 / P95(s)',
|
||||
circ_closed: '正常',
|
||||
circ_half_open: '半开',
|
||||
circ_open: '熔断',
|
||||
circ_not_tracked: '未跟踪',
|
||||
noData: '暂无数据',
|
||||
requests: '请求总数',
|
||||
successRate: '成功率',
|
||||
avgLatency: '平均延迟',
|
||||
fallbackShort: '成功降级',
|
||||
noteOkFail: 'ok {ok} · fail {fail}',
|
||||
noteFail: '失败 {n} 次',
|
||||
noteP95: 'P95 最高 {v}s',
|
||||
noteInflight: '当前并发 {n}',
|
||||
modelCalls: '各模型调用',
|
||||
colModel: '模型',
|
||||
colCalls: '调用',
|
||||
colLatency: '平均延迟',
|
||||
colRate: '成功率',
|
||||
noModels: '暂无调用记录',
|
||||
share: '份额',
|
||||
live: '实时',
|
||||
routeChain: '可用性 + 速度优先链',
|
||||
},
|
||||
metrics: {
|
||||
uptime: '已运行',
|
||||
inflight: '在途/峰值',
|
||||
fallback: '成功降级',
|
||||
promptTokens: 'Prompt tokens',
|
||||
completionTokens: 'Completion tokens',
|
||||
callsTotal: '总调用(ok/fail)',
|
||||
modelCalls: '各模型调用(成功 / 失败)',
|
||||
provShare: '供应商成功调用份额',
|
||||
routeVsProvider: '路由 vs 供应商调用(成功 / 失败 / 降级)',
|
||||
latency: '模型延迟 P50 / P95(秒)',
|
||||
success: '成功',
|
||||
fail: '失败',
|
||||
fallback2: '降级',
|
||||
ok: 'ok',
|
||||
none: '暂无',
|
||||
circuitStatus: '熔断器状态',
|
||||
provider: '供应商',
|
||||
state: '状态',
|
||||
recentFailures: '近期失败',
|
||||
window: '窗口(件)',
|
||||
threshold: '阈值',
|
||||
cooldown: '熔断冷却(s)',
|
||||
probing: '探测中',
|
||||
stateClosed: 'CLOSED',
|
||||
stateHalf: 'HALF_OPEN',
|
||||
stateOpen: 'OPEN',
|
||||
loadErr: '加载指标失败',
|
||||
requests: '请求总数',
|
||||
failCount: '失败数',
|
||||
tokenUsage: 'Token 用量',
|
||||
tokenNote: '入 {p} / 出 {c}',
|
||||
inflightPeak: '在途 / 峰值',
|
||||
failRateNote: '失败率 {v}%',
|
||||
snapshot: '实时快照',
|
||||
circuitCard: '熔断器',
|
||||
},
|
||||
logs: {
|
||||
all: '全部',
|
||||
chat: '对话',
|
||||
image: '图像',
|
||||
video: '视频',
|
||||
autoRefresh: '自动刷新',
|
||||
method: '方法',
|
||||
result: '结果',
|
||||
success: '成功',
|
||||
fail: '失败',
|
||||
searchPlaceholder: '搜索模型/供应商/路径/请求/响应',
|
||||
count: '共 {n} 条',
|
||||
clearFilter: '清空筛选',
|
||||
time: '时间',
|
||||
path: '路径',
|
||||
modelProvider: '模型 / 供应商',
|
||||
reqContent: '请求内容',
|
||||
respContent: '响应内容',
|
||||
empty: '暂无日志',
|
||||
emptyFiltered: '当前筛选下没有记录(已加载 {n} 条,别的筛选条件或关键词还开着)',
|
||||
media: '下载',
|
||||
request: '请求内容',
|
||||
response: '响应内容',
|
||||
polls: '轮询记录({n} 次)',
|
||||
error: '错误',
|
||||
rid: 'rid',
|
||||
caller: '调用方',
|
||||
reqModel: '请求模型',
|
||||
served: '实际模型',
|
||||
provider: '供应商',
|
||||
streaming: '流式',
|
||||
loadErr: '加载日志失败',
|
||||
},
|
||||
users: {
|
||||
viewLogs: '查看日志',
|
||||
viewActivity: '查看活动',
|
||||
tabLogs: '调用日志',
|
||||
tabImages: '图像资产',
|
||||
tabVideos: '视频资产',
|
||||
noData: '暂无记录',
|
||||
// 管理员在资产页下载该账号生成的图/视频(走后端 /v1/media/download 代拉)
|
||||
dl: '下载',
|
||||
dlOk: '已开始下载',
|
||||
dlFail: '下载失败:{msg}',
|
||||
dlNoSrc: '这条记录还没有可下载的地址',
|
||||
},
|
||||
chat: {
|
||||
newChat: '新建对话',
|
||||
session: '会话',
|
||||
thisConv: '本条对话',
|
||||
model: '模型',
|
||||
elapsed: '耗时',
|
||||
msgsN: '{n} 条',
|
||||
regenerate: '重新生成',
|
||||
copyAll: '复制全文',
|
||||
tempShort: '温度',
|
||||
maxShort: '最大',
|
||||
systemShort: '系统提示',
|
||||
visionReady: '视觉能力已就绪 · 可附图',
|
||||
visionOff: '当前模型不支持图像输入',
|
||||
chainLabel: '{id}({chain})',
|
||||
emptyChain: '空',
|
||||
phDefault: '默认',
|
||||
phOptional: '可选',
|
||||
totalTokens: '共 {n}',
|
||||
uploadedImage: '已上传图片',
|
||||
reasoningTag: '推理',
|
||||
routeGroup: '路由(自动降级)',
|
||||
textModels: '文本模型',
|
||||
params: '参数',
|
||||
clear: '清空',
|
||||
generating: '正在生成…',
|
||||
empty: '开始与网关对话(可选任意文本模型或路由 wjd)',
|
||||
fallback: '降级 · 由 {provider} 响应',
|
||||
servedBy: '由 {provider} 响应',
|
||||
requestedTo: '请求 {req} → 实际 {served}',
|
||||
reasoning: '推理过程(reasoning)',
|
||||
thinking: '思考中…',
|
||||
emptyResp: '(空响应)',
|
||||
youError: '出错了:{msg}',
|
||||
placeholder: '输入消息,Enter 发送,Shift+Enter 换行',
|
||||
imgUpload: '上传图片',
|
||||
imgUrlBtn: '图片 URL',
|
||||
imgPh: '粘贴图片 URL,回车添加',
|
||||
imgAdd: '添加',
|
||||
imgMax: '一条消息最多 {n} 张图片',
|
||||
imgPickErr: '图片处理失败:{msg}',
|
||||
visionWarn: '当前模型 {model} 不支持图像输入,图片会被忽略或直接报错 —— 请换用带视觉能力的模型。',
|
||||
useVision: '改用 {model}',
|
||||
waiting: '等待输入…',
|
||||
send: '发送',
|
||||
stop: '停止',
|
||||
stopped: '已停止',
|
||||
temp: '温度 temperature',
|
||||
topP: 'top_p',
|
||||
maxTokens: 'max_tokens(留空则用默认)',
|
||||
streaming: '流式输出',
|
||||
system: '系统提示词(每条会话开头注入)',
|
||||
loadModelsErr: '加载模型列表失败:{msg}',
|
||||
},
|
||||
images: {
|
||||
historyTitle: '生成历史',
|
||||
historySub: '{n} 张',
|
||||
refsLabel: '参考图',
|
||||
title: '图像生成',
|
||||
model: '图像模型',
|
||||
size: '尺寸',
|
||||
ratio: '比例',
|
||||
refsUpload: '上传参考图',
|
||||
refsUrlBtn: '参考图 URL',
|
||||
refsHint: '(留空 = 纯文生图;上传的图片会在浏览器内自动压缩,上传/URL 可混用)',
|
||||
refsMax: '参考图最多 {n} 张',
|
||||
refPickErr: '图片处理失败:{msg}',
|
||||
refsPH: '图生图 / 多图合成:图片 URL 或 data:,每行一个(留空 = 纯文生图)',
|
||||
count: '张数',
|
||||
countTip: '上游一次只出 1 张,这里会逐张调用',
|
||||
genProgress: '正在逐张生成 {i}/{n}',
|
||||
partialFail: '已生成 {done} 张,第 {i} 张失败:{msg}',
|
||||
refsUsed: '{n} 张参考图',
|
||||
emptyResp: '上游没有返回图片',
|
||||
placeholder: '描述想生成的图像(可给风格/主体/构图)',
|
||||
servedBy: '由 {provider} 生成',
|
||||
clear: '清空历史',
|
||||
confirmClear: '清空全部 {n} 张图像记录?会同时从服务端删除(其他设备同步消失),不可恢复。',
|
||||
generate: '生成',
|
||||
promptRow: '提示词',
|
||||
imgLoadErr: '图加载失败',
|
||||
dl: '下载',
|
||||
dlOk: '已开始下载',
|
||||
dlFail: '下载失败:{msg}',
|
||||
dlNoSrc: '这张图没有可下载的地址',
|
||||
empty: '生成的图像会显示在这里',
|
||||
loadErr: '加载图像失败',
|
||||
},
|
||||
videos: {
|
||||
taskTitle: '任务列表',
|
||||
fixed: '固定',
|
||||
title: '视频生成',
|
||||
model: '视频模型',
|
||||
mode: '场景',
|
||||
modeText: '文生视频',
|
||||
modeKeyframe: '首尾帧(图生视频)',
|
||||
modeReference: '参考图/音频',
|
||||
firstFrame: '首帧',
|
||||
lastFrame: '尾帧',
|
||||
upload: '上传图片',
|
||||
uploadImg: '上传参考图',
|
||||
uploadAudio: '上传参考音频',
|
||||
useUrl: '用 URL',
|
||||
urlPH: '或粘贴图片 URL',
|
||||
uploadTip: '上传的素材会在浏览器内压缩为 data URI 直传上游(无需公网可访问的 URL)',
|
||||
pickErr: '素材处理失败:{msg}',
|
||||
refMax: '参考图最多 {n} 张',
|
||||
audMax: '参考音频最多 {n} 段',
|
||||
count5: '已选 {n}/5',
|
||||
count3: '已选 {n}/3',
|
||||
media: '素材',
|
||||
seed: '种子',
|
||||
seedPH: '留空随机',
|
||||
keyframeTip: '首帧/尾帧至少给一个:上传图片或粘贴 URL 都行(首帧=起始画面,尾帧=结束画面)',
|
||||
refImagesPH: '参考图片 URL,每行一个(最多 5 张)',
|
||||
refAudiosPH: '参考音频 URL,每行一个(最多 3 段)',
|
||||
referenceTip: '提示词里可用 <Picture N> / <Audio N> 指代第 N 个素材',
|
||||
placeholderRef: '描述要生成的视频画面与运镜(可用 <Picture 1> / <Audio 1> 指代第 1 个参考素材)',
|
||||
needFrame: '首尾帧模式需要至少上传一张图片或填一个图片 URL',
|
||||
needRef: '参考模式需要至少一张图片或一段音频(可上传或填 URL)',
|
||||
duration: '时长(s)',
|
||||
aspect: '比例',
|
||||
quality: '清晰度',
|
||||
placeholder: '描述要生成的视频画面与运镜',
|
||||
async: '异步提交(立即返回,后台轮询)',
|
||||
taskCount: '任务 {n}',
|
||||
clear: '清除已完成',
|
||||
confirmClear: '清除 {n} 个已完成的视频任务?记录与视频链接会同时从服务端删除,不可恢复。',
|
||||
generate: '生成视频',
|
||||
status: '状态',
|
||||
task: '任务',
|
||||
service: '服务',
|
||||
elapsed: '耗时',
|
||||
subElapsed: '耗时 {n}s',
|
||||
subWait: '已等待 {n}s',
|
||||
promptRow: '提示词',
|
||||
raw: '原始返回',
|
||||
empty: '生成或提交的视频任务会显示在这里',
|
||||
failText: '生成失败',
|
||||
doneText: '已生成',
|
||||
doingText: '生成中…',
|
||||
doneMsg: '视频已生成',
|
||||
dl: '下载视频',
|
||||
dlOk: '已开始下载',
|
||||
dlFail: '下载失败:{msg}',
|
||||
dlNoSrc: '这个任务还没有可下载的视频',
|
||||
submitMsg: '已提交任务 {id}',
|
||||
loadErr: '加载视频失败',
|
||||
},
|
||||
models: {
|
||||
routeAliasTitle: '路由别名(自动降级链)',
|
||||
modelListTitle: '模型清单',
|
||||
name: '名称',
|
||||
chainLabel: '模型链(依次尝试,失败自动降级)',
|
||||
providerCount: '供应商数',
|
||||
id: '模型 ID',
|
||||
type: '类型',
|
||||
provider: '供应商',
|
||||
keySet: 'Key 已配',
|
||||
text: '文本',
|
||||
image: '图像',
|
||||
video: '视频',
|
||||
route: '路由',
|
||||
model: '模型',
|
||||
textModels: '文本模型',
|
||||
imageModels: '图像模型',
|
||||
videoModels: '视频模型',
|
||||
routes: '路由别名',
|
||||
providers: '供应商',
|
||||
loadErr: '加载模型失败',
|
||||
capability: '能力',
|
||||
visionTag: '视觉',
|
||||
allTextModels: '全部文本模型',
|
||||
providerCard: '供应商',
|
||||
keyOk: 'Key 已配置',
|
||||
keyMissing: 'Key 未配置',
|
||||
routeCount: '{n} 条路由',
|
||||
chainCount: '{n} 个模型',
|
||||
providerCount2: '{n} 家供应商',
|
||||
noRoute: '没有配置路由别名',
|
||||
speedtest: '一键测速',
|
||||
testing: '正在测试全部文本模型延迟…',
|
||||
testingShort: '测速中…',
|
||||
testOne: '单独测速',
|
||||
latency: '延迟',
|
||||
failed: '失败',
|
||||
speedtestDone: '测速完成,共 {n} 个模型',
|
||||
speedtestFail: '测速失败',
|
||||
},
|
||||
history: {
|
||||
saveFail: '历史未能保存到服务端(刷新后可能丢失),请检查登录状态或网络',
|
||||
offline: '连不上服务端历史接口,暂时只用本机缓存显示',
|
||||
},
|
||||
settings: {
|
||||
keyUnlimited: '不限',
|
||||
connInfo: '连接信息',
|
||||
gwAddress: '网关地址',
|
||||
gwVersion: '网关版本',
|
||||
loginUser: '登录用户',
|
||||
sessionLen: '会话长度',
|
||||
hours: '{n} 小时',
|
||||
language: '语言 / Language',
|
||||
langTip: '界面语言切换,本地保存',
|
||||
theme: '主题外观',
|
||||
appearance: '外观与语言',
|
||||
themeSub: '默认 B,可随时切 A / C',
|
||||
current: '当前',
|
||||
switch: '切换',
|
||||
followSystem: '跟随系统深色模式',
|
||||
followSub: '系统切深色时自动用 A',
|
||||
langSub: '中英完整覆盖',
|
||||
myKeys: '我的 API Key',
|
||||
myKeysSub: '创建 / 复制 / 删除,每个账号最多 3 把',
|
||||
manage: '去管理',
|
||||
gwCard: '网关信息',
|
||||
account: '账号',
|
||||
logoutTip: '退出后需用账号密码重新登录。',
|
||||
logoutBtn: '退出登录',
|
||||
chatDefaults: '对话默认参数',
|
||||
defsTip: '作为对话页初始值(本会话已改动的参数不受影响)。',
|
||||
defaultModel: '默认模型 / 路由',
|
||||
temperature: '温度 temperature',
|
||||
topP: 'top_p',
|
||||
maxTokens: 'max_tokens(留空用网关默认)',
|
||||
streaming: '流式输出',
|
||||
system: '系统提示词',
|
||||
save: '保存默认参数',
|
||||
saveOk: '默认参数已保存,新会话生效',
|
||||
resetOk: '已恢复默认',
|
||||
providerStatus: '供应商状态',
|
||||
modelsCount: '模型数',
|
||||
userManagement: '账号管理(管理员)',
|
||||
gwConfigBtn: '去配置',
|
||||
gwConfigSub: '改网关参数 / 供应商 / 路由 / 定价 —— 保存即生效',
|
||||
gwConfig: '网关配置(管理员)',
|
||||
userCol: '账号',
|
||||
roleCol: '角色',
|
||||
accountDeleted: '账号 {name} 已删除(会话与 API Key 一并吊销)',
|
||||
revokeKeys: '吊销全部 Key',
|
||||
revokeKeysOk: '已吊销 {name} 的 {n} 把 API Key',
|
||||
resetPwOk: '{name} 密码已重置为账号名,踢掉会话 {n} 个',
|
||||
confirmDeleteUser: '删除账号 {name}?其全部登录会话与 API Key 会立即失效,不可恢复。',
|
||||
confirmResetPw: '把 {name} 的密码重置为账号名?该账号已登录的会话会被踢掉。',
|
||||
confirmRevokeKeys: '吊销 {name} 的全部 API Key?外部调用方需重新创建 Key 才能继续调用。',
|
||||
userPwOptional: '初始密码(留空=与账号名相同)',
|
||||
confirm: '确认',
|
||||
confirmDeleteKey: '删除这把 API Key?用它调用的客户端会立刻 401,需重新创建。',
|
||||
usersTip: '创建账号 / 重置密码 / 停用启用 / 删除(admin 专属)',
|
||||
userCreated: '创建时间',
|
||||
// 第二十四轮:管理员停用 / 启用账号
|
||||
userDisabled: '已停用',
|
||||
userDisabledAt: '停用于 {ts}',
|
||||
disableUser: '停用',
|
||||
enableUser: '启用',
|
||||
confirmDisableUser: '停用账号 {name}?停用后该账号无法登录,名下 API Key 立即失效(Key 不会被删除,重新启用即恢复),已登录的会话会被踢掉。',
|
||||
userDisabledOk: '账号 {name} 已停用(踢掉会话 {n} 个,API Key 已失效)',
|
||||
userEnabledOk: '账号 {name} 已启用,可以用原密码登录、原 API Key 继续调用',
|
||||
namesRule: '账号名仅字母数字,默认密码=账号名',
|
||||
changePw: '修改密码',
|
||||
newPw: '新密码(至少 4 位)',
|
||||
pwTip: '已登录状态直接设新密码,不用再输当前密码;改完所有会话失效,需用新密码重新登录。',
|
||||
pwNeedNew: '请输入新密码',
|
||||
pwChanged: '密码已更新,请用新密码重新登录',
|
||||
keyLabel: '标签(可选)',
|
||||
keyHint: 'Key 前缀',
|
||||
keyCreated: '创建时间',
|
||||
createKey: '创建 API Key',
|
||||
keyCol: 'API Key',
|
||||
keyLimitFull: '已达上限',
|
||||
keyLegacyNoEcho: '(该 Key 早于明文回显功能,无法再显示)',
|
||||
noKey: '你还没有 API Key —— 创建后可当作外部调用的 Bearer 凭证',
|
||||
userMgmt: '账号管理(管理员)',
|
||||
newUserName: '新账号名(字母数字)',
|
||||
newUserTip: '创建账号,默认密码 = 账号名',
|
||||
createUser: '创建账号',
|
||||
keyCount: 'Key 数',
|
||||
resetPw: '重置密码',
|
||||
loadErr: '加载设置失败',
|
||||
},
|
||||
apidoc: {
|
||||
copyCurl: '复制 curl 示例',
|
||||
viewDoc: '查看接口文档',
|
||||
title: 'API 调用说明',
|
||||
intro: '用上面的 API Key 当作 Bearer 凭证调用网关(OpenAI 兼容)。API Key 只能调用模型;建 Key / 改密 / 管账号必须用网页登录,Key 调管理接口会 403。',
|
||||
baseTitle: '基础信息',
|
||||
baseUrl: '接口地址',
|
||||
auth: '鉴权',
|
||||
authVal: '请求头 Authorization: Bearer <你的 API Key>',
|
||||
modelPick: '模型选择',
|
||||
modelPickVal: 'model 填 wjd = 路由别名(按「可用 + 速度」自动降级,推荐);也可填具体模型 id 直连,不被降级影响',
|
||||
ctype: '请求格式',
|
||||
ctypeVal: 'application/json;对话支持 SSE 流式(stream: true)',
|
||||
endpoints: '常用端点',
|
||||
colMethod: '方法',
|
||||
colPath: '路径',
|
||||
colDesc: '说明',
|
||||
epModels: '模型与路由列表(含视觉能力标记)',
|
||||
epChat: '对话补全(OpenAI 兼容,支持流式与图片输入)',
|
||||
epImages: '图像生成 / 图生图(n 必须为 1,多张请多次调用)',
|
||||
epVideoCreate: '视频生成(异步,立即返回 video_id)',
|
||||
epVideoPoll: '查询视频任务(建议每 5s 一次;被上游限流时返回 throttled)',
|
||||
epHistory: '读取本人历史(图像 / 视频 / 对话)',
|
||||
epLogs: '本人调用日志',
|
||||
epMetrics: '指标快照(含熔断器状态)',
|
||||
epHealth: '健康检查(版本 / 供应商状态)',
|
||||
exChat: '示例 · 对话',
|
||||
exImg: '示例 · 图像生成',
|
||||
exVideo: '示例 · 视频生成 + 轮询',
|
||||
exPy: '示例 · Python(OpenAI SDK 兼容)',
|
||||
// 示例代码里的注释与示例文案(整段照抄时也该是当前语言)
|
||||
sampleChat: '你好,介绍一下你自己',
|
||||
sampleImg: '霓虹夜景的城市街道',
|
||||
sampleVideo: '镜头缓慢推进',
|
||||
sampleStep1: '提交任务(异步,立即返回 video_id)',
|
||||
sampleStep2: '每 5s 轮询一次(被限流会回 throttled,等一下再问)',
|
||||
notes: '注意事项',
|
||||
noteVision: '带图对话请用支持视觉的模型(agnes-3.0-flash,列表里标「视觉」);填路由别名 wjd 时网关会自动把视觉模型排到链首。',
|
||||
noteN1: '图像 n 只能为 1(上游限制),要几张就调几次;n≠1 会被网关直接 400 拦下。',
|
||||
noteVideo: '视频 seconds 只支持 4–12,size 固定 720P,比例 6 种(21:9/16:9/4:3/1:1/3:4/9:16);mode=text 文生视频 / keyframe 首尾帧 / reference 参考图·音频。',
|
||||
notePoll: '轮询别快于 5s(上游会回 429「查询过于频繁」,网关会以 throttled 提示退避)。',
|
||||
noteMedia: '素材(参考图 / 首尾帧 / 参考音频 / 对话附图)可直接传 data:image/...;base64,... 或公网 URL;data URI 不必暴露素材,但单次请求体需 < 2MB。',
|
||||
noteKey: 'Key 泄漏时到本页删除(立即 401),或用「用户管理」页一键吊销该账号全部 Key。',
|
||||
noteAudit: '所有调用按账号记入「日志」页(仅本人可见;admin 可在用户管理页看各账号)。',
|
||||
copyBase: '复制地址',
|
||||
copyCmd: '复制',
|
||||
},
|
||||
// 第二十二轮:意见反馈(普通账号提交 + 看进度)/ 用户反馈(管理员看全部 + 改进度)
|
||||
fbStatus: {
|
||||
pending: '待处理',
|
||||
doing: '处理中',
|
||||
done: '已处理',
|
||||
},
|
||||
feedback: {
|
||||
write: '写下你的意见或建议',
|
||||
placeholder: '哪里不好用、想要什么功能、哪里看不懂 —— 都可以说',
|
||||
attach: '添加图片',
|
||||
imagesHint: '最多 {n} 张 · 提交前自动压缩',
|
||||
remove: '移除',
|
||||
needContent: '请先写点内容再提交',
|
||||
submit: '提交反馈',
|
||||
submitted: '收到了,感谢反馈!',
|
||||
mine: '我提交过的',
|
||||
mineSub: '提交后在这里看处理进度',
|
||||
empty: '还没提交过反馈',
|
||||
statusAll: '全部状态',
|
||||
|
||||
revoke: '撤回',
|
||||
revokeTitle: '撤回这条反馈?',
|
||||
revokeBody: '撤回后这条反馈「{n}」会被删除、不能恢复(管理员已开始处理的单子撤不了)。',
|
||||
revoked: '已撤回',
|
||||
},
|
||||
// 处理记录(时间线):提交 + 管理员的每一次动作
|
||||
fbLog: {
|
||||
title: '处理记录',
|
||||
submitted: '提交',
|
||||
more: '展开全部 {n} 条',
|
||||
less: '收起',
|
||||
},
|
||||
inbox: {
|
||||
all: '全部账号',
|
||||
allStatus: '全部进度',
|
||||
kw: '搜内容 / 账号',
|
||||
empty: '还没有收到反馈',
|
||||
emptyFiltered: '已加载 {n} 条,但都不匹配当前筛选',
|
||||
count: '共 {n} 条',
|
||||
account: '账号',
|
||||
status: '进度',
|
||||
handle: '处理',
|
||||
archAll: '全部',
|
||||
archActive: '仅未归档',
|
||||
archOnly: '仅已归档',
|
||||
archived: '已归档',
|
||||
archive: '归档',
|
||||
unarchive: '取消归档',
|
||||
delete: '删除',
|
||||
deleteConfirm: '永久删除这条反馈(含其全部图片),不可恢复。确定删除?',
|
||||
deleted: '已删除',
|
||||
archOk: '已归档',
|
||||
unarchOk: '已取消归档',
|
||||
|
||||
dialogTitle: '处理这条反馈',
|
||||
noteLabel: '处理说明(提交人可见)',
|
||||
notePlaceholder: '例如:已定位到导出按钮,下个版本修',
|
||||
save: '保存',
|
||||
saved: '进度已更新',
|
||||
preview: '查看大图',
|
||||
noPreview: '无预览图,点击加载原图',
|
||||
loading: '加载中…',
|
||||
loadFail: '图片加载失败',
|
||||
imgCount: '{n} 张图',
|
||||
},
|
||||
// 第二十三轮:网关配置(管理员把 data/gateway.yaml 的每一项都搬上了页面)
|
||||
gc: {
|
||||
file: '网关配置文件',
|
||||
fileSub: '管理员专属 · 保存即生效',
|
||||
path: '文件位置',
|
||||
restartKeys: '这几项改了要重启进程',
|
||||
otherKeys: '其余所有项',
|
||||
otherKeysTip: '每请求读取,保存后立刻生效(无需重启、无需等热重载)',
|
||||
saveTip: '保存会用页面上的值重写整个配置文件(旧文件先备份为 .bak,可回滚);密钥只显示"配没配",不会回显到浏览器。',
|
||||
viewYaml: '查看配置文件',
|
||||
save: '保存并生效',
|
||||
saved: '已保存并生效',
|
||||
discard: '放弃改动并重载',
|
||||
editorTitle: '配置文件内容(gateway.yaml)',
|
||||
editorSub: '直接编辑完整 YAML,点「保存」即应用',
|
||||
exportCfg: '导出配置',
|
||||
importCfg: '导入配置',
|
||||
importCfgOk: '配置已导入编辑器,确认无误后点「保存」应用',
|
||||
envTitle: 'API Key 环境变量',
|
||||
envSub: '存于 data/.env;默认隐藏,可显示、复制、修改',
|
||||
envExport: '导出变量',
|
||||
envImport: '导入变量',
|
||||
envImportErr: '变量导入失败',
|
||||
envEmpty: '暂无使用 token_env 的供应商',
|
||||
envSet: '已配置',
|
||||
envMissing: '未配置',
|
||||
envShow: '显示',
|
||||
envHide: '隐藏',
|
||||
envCopy: '复制',
|
||||
envCopied: '已复制',
|
||||
envSaved: '已保存到环境变量并生效',
|
||||
saveOk: '已保存并生效',
|
||||
restartPill: '需重启服务',
|
||||
restartSaved: '本次改动了需重启才能生效的项:{keys},重启后生效',
|
||||
backup: '备份配置',
|
||||
restore: '恢复配置',
|
||||
backupOk: '已导出备份(配置 + API Key)',
|
||||
restoreConfirm: '将用备份覆盖当前配置文件与 {envs} 个 API Key 环境变量,确定恢复?',
|
||||
restoreGo: '恢复',
|
||||
cancel: '取消',
|
||||
restoreOk: '已恢复配置与 API Key',
|
||||
restoreInvalid: '备份文件无效',
|
||||
|
||||
errTitle: '保存失败,配置未被改动',
|
||||
needRestart: '需重启',
|
||||
restartApplied: '已保存。这几项要重启 api-gateway 才生效:{keys}',
|
||||
savedRestart: '已保存并生效',
|
||||
addItem: '添加',
|
||||
addModel: '添加模型',
|
||||
addProvider: '添加供应商',
|
||||
addRoute: '添加路由别名',
|
||||
addPrice: '添加定价',
|
||||
delete: '删除',
|
||||
delProvider: '删除供应商',
|
||||
delRoute: '删除路由',
|
||||
delConfirm: '删除「{name}」?保存后才真正写盘生效。',
|
||||
needKey: '供应商的 key 不能为空',
|
||||
needRoute: '路由别名的名字不能为空',
|
||||
dupKey: '「{name}」重复了,请改一个名字',
|
||||
newProvider: '(新供应商)',
|
||||
newRoute: '(新路由别名)',
|
||||
unlimited: '留空 = 不限',
|
||||
useServerTimeout: '留空 = 用 server.timeout',
|
||||
mediaEmpty: '留空 = 不支持',
|
||||
modelId: '模型 id',
|
||||
modelDisplay: '显示名',
|
||||
hdrKey: '请求头',
|
||||
hdrVal: '值',
|
||||
tokenSet: '已配置密钥',
|
||||
tokenEnvMissing: '环境变量未设置',
|
||||
tokenKeep: '留空 = 不修改(当前已配置)',
|
||||
tokenEmpty: '留空 = 不设置',
|
||||
jump: '跳到',
|
||||
tabServer: '服务与安全',
|
||||
tabServerSub: '监听、超时/重试、限流、CORS、会话时长等运行开关',
|
||||
tabProviders: '供应商与模型',
|
||||
tabProvidersSub: '供应商密钥来源、接口地址、图像/视频端点、模型清单',
|
||||
tabRoutes: '路由与熔断',
|
||||
tabRoutesSub: '路由别名与 fallback 模型链(顺序 = 优先级)+ 供应商熔断',
|
||||
tabLog: '日志与定价',
|
||||
tabLogSub: '日志级别/格式/容量 + 模型定价(人民币 / 百万 token)',
|
||||
tabDownload: '下载代理',
|
||||
tabDownloadSub: '允许网关代下载的 CDN 域名与单文件上限',
|
||||
circuit: '供应商熔断',
|
||||
h_circuit: '某供应商窗口内失败到阈值就熔断冷却,期间跳过它让 fallback 顶上',
|
||||
f_c_enabled: '启用熔断',
|
||||
f_c_failure_threshold: '触发阈值(次)',
|
||||
f_c_cooldown: '熔断冷却(秒)',
|
||||
f_c_window: '统计窗口(秒)',
|
||||
h_c_enabled: '关掉 = 失败也不跳过(fallback 照常工作)',
|
||||
h_c_failure_threshold: '窗口内失败到该次数就熔断',
|
||||
h_c_cooldown: '熔断期间直接跳过该供应商,冷却结束后自动半开试探',
|
||||
h_c_window: '按"窗口内失败次数"计数(不是连续失败)',
|
||||
// ── server 段(键名与 gateway.yaml 一致,页面标签 = f_<key>)──
|
||||
f_host: '监听地址',
|
||||
h_host: '127.0.0.1 只对本机/反代开放;改成 0.0.0.0 会对外暴露端口(鉴权仍恒定开启)',
|
||||
f_port: '监听端口',
|
||||
h_port: '生产用 8808,且 Nginx 反代指向它 —— 改了要同步改反代',
|
||||
f_timeout: '上游超时(秒)',
|
||||
h_timeout: '单次上游请求超时;路由自身写了 timeout 的以路由为准',
|
||||
f_retry: '直连模型重试次数',
|
||||
h_retry: '直接用模型 id(不走路由别名)时的重试次数,含首次',
|
||||
f_health_auth: '/health 需要鉴权',
|
||||
// 注意:vue-i18n 把 {...} 当占位符,花括号要么写成 {'{'} / {'}'},要么整条编译不过 ——
|
||||
// 编译不过的表现是"用到这条文案的整块界面不渲染",不报在文案上(踩过一次,见 check:i18n)。
|
||||
// 用双引号是因为这条文案里有 {'{'} 这种字面量花括号写法(花括号是 vue-i18n 的占位符语法)
|
||||
h_health_auth: "关着时 /health 只回 {'{'}\"status\":\"ok\"{'}'}(供探活),不回看板数据",
|
||||
f_hot_reload: '配置热重载',
|
||||
h_hot_reload: '按 mtime 自动重载手改的文件;页面上保存本来就是即时生效,与此无关',
|
||||
f_hot_reload_interval: '热重载检查间隔(秒)',
|
||||
h_hot_reload_interval: '越小改文件越快被发现,越大越省 IO',
|
||||
f_metrics_enabled: '记录调用指标',
|
||||
h_metrics_enabled: '关掉后 /metrics 与看板计数停更(不影响调用)',
|
||||
f_rate_limit_rps: '全局单账号 QPS 上限',
|
||||
h_rate_limit_rps: '留空 = 不限(供应商级、路由级限流见各自配置)',
|
||||
f_max_body_size: '请求体上限(字节)',
|
||||
h_max_body_size: '约 2MB = 2000000;带图对话别调太小',
|
||||
f_cors_origins: 'CORS 允许来源',
|
||||
h_cors_origins: '填 * 表示任意站点都能跨域调本网关(会消耗你的额度),生产建议换成可信域名',
|
||||
f_graceful_shutdown: '优雅关闭等待(秒)',
|
||||
h_graceful_shutdown: '收到停止信号后等在途请求的秒数',
|
||||
f_batch_max_concurrency: '/batch 并发上限',
|
||||
h_batch_max_concurrency: '客户端传更大的值会被钳到这里',
|
||||
f_batch_max_items: '/batch 单次条目上限',
|
||||
h_batch_max_items: '超出直接 400',
|
||||
f_webhook_allow_private: '允许视频回调指向内网',
|
||||
h_webhook_allow_private: 'SSRF 防护开关,默认关;开了才能回调 192.168./10./回环地址',
|
||||
f_docs_enabled: '开放 /docs 文档',
|
||||
h_docs_enabled: 'FastAPI 自带的接口文档,安全默认关(会暴露接口清单)',
|
||||
f_auth_fail_limit_per_min: '鉴权失败限流(次/分)',
|
||||
h_auth_fail_limit_per_min: '同一来源 IP 每分钟鉴权失败超过该值 → 429,防暴力枚举',
|
||||
f_session_ttl_minutes: '网页会话时长(分钟)',
|
||||
h_session_ttl_minutes: '登录签发的会话有效期,默认 1440 = 24 小时;只影响新登录',
|
||||
// ── 供应商 ──
|
||||
pKey: '内部键名',
|
||||
h_pKey: '配置里的标识(也是 /health 里的 provider key),改名等于新增一个',
|
||||
pName: '显示名',
|
||||
pBaseUrl: '接口地址 base_url',
|
||||
pTokenEnv: '密钥环境变量',
|
||||
h_pTokenEnv: '密钥存在 .env 里,这里填变量名(如 AGNES_API_KEY),不把明文写进配置',
|
||||
pToken: '明文密钥',
|
||||
h_pToken: '没有用环境变量时才填;保存后只回报"已配置",不会再回显',
|
||||
pRateLimit: '本供应商 QPS 上限',
|
||||
h_pRateLimit: '留空 = 不限(供应商维度,所有模型共享)',
|
||||
pHeaders: '额外请求头',
|
||||
h_pHeaders: '少数供应商要带特定头(如自定义鉴权/版本头),没有就留空',
|
||||
pMedia: '图像 / 视频端点',
|
||||
h_pMedia: '非标准端点的供应商才填(Agnes 是自有路径);全留空 = 该供应商不支持图像/视频',
|
||||
pModels: '模型清单',
|
||||
h_pModels: '模型 id 必须与上游一致;vision = 支持图像输入(带图对话会优先选它)',
|
||||
mVision: '视觉',
|
||||
// ── 路由 ──
|
||||
routeHint: '路由别名是给调用方用的"虚拟模型名"(如 wjd):按下面顺序逐个尝试,全失败才 502。数组顺序 = 优先级。',
|
||||
rName: '别名',
|
||||
h_rName: '调用时 model 填这个名字',
|
||||
rTimeout: '单模型超时(秒)',
|
||||
h_rTimeout: '某个模型多久没出结果就切下一个,避免整链挂死',
|
||||
rRetry: '单模型重试次数',
|
||||
h_rRetry: '切下一个之前的重试次数(含首次);想让链路快速切换就填 1',
|
||||
rRate: '本路由 QPS 上限',
|
||||
h_rRate: '留空 = 不限',
|
||||
rModels: 'fallback 模型链',
|
||||
h_rModels: '从上到下依次尝试;可用模型来自上面的供应商清单',
|
||||
// ── 可观测性 ──
|
||||
f_o_log_level: '日志级别',
|
||||
h_o_log_level: 'DEBUG 最啰嗦,生产 INFO 够用',
|
||||
f_o_log_json: '结构化 JSON 日志',
|
||||
h_o_log_json: '接 ELK / CloudWatch 时开;人看还是普通格式舒服',
|
||||
f_o_access_log_maxlen: '访问日志条数上限',
|
||||
h_o_access_log_maxlen: '日志页「已加载 N 条」的上限(内存环形缓冲)',
|
||||
pricing: '模型定价',
|
||||
h_pricing: '人民币 / 百万 token,用于返回 estimated_cost_cny;不填则该项不返回(不影响调用)',
|
||||
priceIn: '输入价',
|
||||
priceOut: '输出价',
|
||||
// ── 定价 ──
|
||||
// ── 下载代理 ──
|
||||
dlHosts: '允许代下载的域名',
|
||||
h_dlHosts: '产物 CDN 域名(含子域);留空 = 整个下载代理关闭。换了 CDN 就往这里加一条',
|
||||
f_max_bytes: '单文件上限(字节)',
|
||||
h_max_bytes: '默认 67108864 = 64MB',
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css' // 深色变量基座(A 皮肤用)
|
||||
import 'highlight.js/styles/github.css'
|
||||
import * as ElementIcons from '@element-plus/icons-vue'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { initTheme } from './lib/theme'
|
||||
import i18n from './i18n'
|
||||
import './style.css'
|
||||
|
||||
initTheme() // mount 前应用主题(data-theme + dark class),避免闪色
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.use(i18n) // 多语言
|
||||
for (const [name, comp] of Object.entries(ElementIcons)) {
|
||||
app.component(name as string, comp as any)
|
||||
}
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,47 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { useSessionStore } from './store/session'
|
||||
import { GATEWAY_CONFIG_ENABLED } from './lib/features'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{ path: '/login', name: 'login', component: () => import('./views/Login.vue'), meta: { public: true } },
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('./layouts/MainLayout.vue'),
|
||||
children: [
|
||||
{ path: '', redirect: '/dashboard' },
|
||||
{ path: 'dashboard', name: 'dashboard', component: () => import('./views/Dashboard.vue'), meta: { title: '仪表盘' } },
|
||||
{ path: 'chat', name: 'chat', component: () => import('./views/Chat.vue'), meta: { title: '对话' } },
|
||||
{ path: 'images', name: 'images', component: () => import('./views/Images.vue'), meta: { title: '图像' } },
|
||||
{ path: 'videos', name: 'videos', component: () => import('./views/Videos.vue'), meta: { title: '视频' } },
|
||||
{ path: 'models', name: 'models', component: () => import('./views/Models.vue'), meta: { title: '模型与供应商' } },
|
||||
{ path: 'metrics', name: 'metrics', component: () => import('./views/Metrics.vue'), meta: { title: '指标' } },
|
||||
{ path: 'keys', name: 'keys', component: () => import('./views/ApiKeys.vue'), meta: { title: 'API 密钥' } },
|
||||
{ path: 'users', name: 'users', component: () => import('./views/Users.vue'), meta: { title: '用户管理', admin: true } },
|
||||
{ path: 'feedback-inbox', name: 'feedbackinbox', component: () => import('./views/FeedbackInbox.vue'), meta: { title: '用户反馈', admin: true } },
|
||||
{ path: 'feedback', name: 'feedback', component: () => import('./views/Feedback.vue'), meta: { title: '意见反馈', memberOnly: true } },
|
||||
{ path: 'gateway-config', name: 'gatewaycfg', component: () => import('./views/GatewayConfig.vue'), meta: { title: '网关配置', admin: true } },
|
||||
{ path: 'logs', name: 'logs', component: () => import('./views/Logs.vue'), meta: { title: '日志' } },
|
||||
{ path: 'settings', name: 'settings', component: () => import('./views/Settings.vue'), meta: { title: '设置' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const s = useSessionStore()
|
||||
if (!to.meta.public && !s.isAuthed) return '/login'
|
||||
if (to.path === '/login' && s.isAuthed) return '/dashboard'
|
||||
// 仅管理员的页面(用户管理):普通账号手敲地址也别进去 ——
|
||||
// 侧栏/抽屉里本来就不显示,进去只会看到一个 403 空表和「创建账号」按钮。
|
||||
if (to.meta.admin && !s.isAdmin) return '/dashboard'
|
||||
// 反向同理(第二十二轮):管理员只处理、不提意见反馈,手敲 /feedback 也送回收件箱。
|
||||
if (to.meta.memberOnly && s.isAdmin) return '/feedback-inbox'
|
||||
// 第二十三轮追加:网关配置页暂时隐藏(老板「不删、先藏起来」)→ 手敲地址也送回仪表盘。
|
||||
// 路由与组件都留着,把 `lib/features.ts` 的开关打开即恢复。
|
||||
if (to.name === 'gatewaycfg' && !GATEWAY_CONFIG_ENABLED) return '/dashboard'
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,36 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { login, setToken, clearToken, TOKEN_KEY, USER_KEY, ROLE_KEY } from '../api'
|
||||
|
||||
export const useSessionStore = defineStore('session', {
|
||||
state: () => ({
|
||||
token: localStorage.getItem(TOKEN_KEY) || '',
|
||||
user: localStorage.getItem(USER_KEY) || '',
|
||||
role: localStorage.getItem(ROLE_KEY) || '',
|
||||
version: '' as string,
|
||||
expiresIn: 0 as number,
|
||||
}),
|
||||
getters: {
|
||||
isAuthed: (s) => !!s.token,
|
||||
isAdmin: (s) => s.role === 'admin',
|
||||
},
|
||||
actions: {
|
||||
async login(username: string, password: string) {
|
||||
const j = await login(username, password)
|
||||
this.token = j.access_token
|
||||
this.user = j.user || ''
|
||||
this.role = j.role || ''
|
||||
this.version = j.gateway_version || ''
|
||||
this.expiresIn = j.expires_in || 0
|
||||
setToken(this.token, this.user, this.role)
|
||||
},
|
||||
async logout() {
|
||||
try {
|
||||
if (this.token) await fetch('/auth/logout', { method: 'POST', headers: { Authorization: `Bearer ${this.token}` } })
|
||||
} catch { /* 忽略 */ }
|
||||
this.token = ''
|
||||
this.user = ''
|
||||
this.role = ''
|
||||
clearToken()
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,682 @@
|
||||
/* ══════════════════════════════════════════════════════════════════════
|
||||
产品样式总入口(前端重设计 v2)
|
||||
──────────────────────────────────────────────────────────────────────
|
||||
结构:一套结构 + 三套 token(A 深空蓝 / B 素白蓝紫 / C 暖砂墨绿)。
|
||||
切主题只改 <html data-theme="A|B|C">,页面代码零改动。
|
||||
|
||||
为什么用 :root[data-theme="X"] 而不是 html[data-theme="X"]:
|
||||
Element Plus 的 dark/css-vars.css 用的是 html.dark(特异性 0,1,1),
|
||||
而 :root[data-theme] 是伪类 + 属性选择器(0,2,0),稳赢,不靠引入顺序。
|
||||
|
||||
为什么 Element Plus 变量也在这里桥接:
|
||||
页面里继续用 el-button / el-input / el-table 等组件(交互逻辑不动),
|
||||
把 --el-* 指到我们的 token 上,组件就自动吃主题色 —— 不用给每个组件
|
||||
写一遍覆盖样式。
|
||||
══════════════════════════════════════════════════════════════════════ */
|
||||
|
||||
:root {
|
||||
--rail-w: 224px;
|
||||
--radius-s: 8px;
|
||||
--radius: 12px;
|
||||
--radius-l: 16px;
|
||||
--gap: 14px;
|
||||
--font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
|
||||
"Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
|
||||
|
||||
/* 与组件无关的基础尺码(Element Plus 组件尺寸/圆角也在这里统一) */
|
||||
--el-font-family: var(--font);
|
||||
--el-font-size-base: 13px;
|
||||
--el-border-radius-base: 10px;
|
||||
--el-border-radius-small: 8px;
|
||||
--el-border-radius-round: 999px;
|
||||
--el-component-size: 34px;
|
||||
--el-component-size-small: 30px;
|
||||
--el-component-size-large: 44px;
|
||||
--el-transition-duration: .18s;
|
||||
}
|
||||
|
||||
/* ── A 深空蓝:深色底 + 青绿点缀,护眼、数据页有「驾驶舱」感 ── */
|
||||
:root[data-theme="A"] {
|
||||
--bg: #0A101E;
|
||||
--bg-2: #070C16;
|
||||
--surface: #121B2C;
|
||||
--surface-2: #172238;
|
||||
--line: rgba(255, 255, 255, .09);
|
||||
--line-2: rgba(255, 255, 255, .055);
|
||||
--text: #E9EFFA;
|
||||
--muted: #8CA0BE;
|
||||
--muted-2: #63748F;
|
||||
--primary: #35D0BA;
|
||||
--primary-ink: #05261F;
|
||||
--primary-soft: rgba(53, 208, 186, .13);
|
||||
--ok: #34D399; --warn: #FBBF24; --err: #F87171;
|
||||
--ok-soft: rgba(52, 211, 153, .14); --warn-soft: rgba(251, 191, 36, .14); --err-soft: rgba(248, 113, 113, .14);
|
||||
--shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 14px 34px rgba(0, 0, 0, .34);
|
||||
--chart-a: #35D0BA; --chart-b: #6E8CFF;
|
||||
--chip: rgba(255, 255, 255, .06);
|
||||
|
||||
/* Element Plus 桥接(深色) */
|
||||
color-scheme: dark;
|
||||
--el-color-primary: var(--primary);
|
||||
--el-color-primary-light-3: #4FD6C2;
|
||||
--el-color-primary-light-5: #74DFD0;
|
||||
--el-color-primary-light-7: #A3EAE0;
|
||||
--el-color-primary-light-8: #BCEFE8;
|
||||
--el-color-primary-light-9: #D5F4F0;
|
||||
--el-color-primary-dark-2: #2AB8A4;
|
||||
--el-color-success: var(--ok);
|
||||
--el-color-success-light-9: var(--ok-soft);
|
||||
--el-color-warning: var(--warn);
|
||||
--el-color-warning-light-9: var(--warn-soft);
|
||||
--el-color-danger: var(--err);
|
||||
--el-color-danger-light-9: var(--err-soft);
|
||||
--el-color-error: var(--err);
|
||||
--el-color-error-light-9: var(--err-soft);
|
||||
--el-color-info: var(--muted);
|
||||
--el-color-info-light-9: var(--chip);
|
||||
--el-bg-color: var(--surface);
|
||||
--el-bg-color-page: var(--bg);
|
||||
--el-bg-color-overlay: var(--surface-2);
|
||||
--el-text-color-primary: var(--text);
|
||||
--el-text-color-regular: var(--text);
|
||||
--el-text-color-secondary: var(--muted);
|
||||
--el-text-color-placeholder: var(--muted-2);
|
||||
--el-text-color-disabled: var(--muted-2);
|
||||
--el-border-color: var(--line);
|
||||
--el-border-color-light: var(--line);
|
||||
--el-border-color-lighter: var(--line-2);
|
||||
--el-border-color-extra-light: var(--line-2);
|
||||
--el-border-color-dark: var(--line);
|
||||
--el-border-color-darker: var(--line);
|
||||
--el-fill-color: var(--chip);
|
||||
--el-fill-color-light: var(--chip);
|
||||
--el-fill-color-lighter: var(--chip);
|
||||
--el-fill-color-extra-light: var(--chip);
|
||||
--el-fill-color-blank: var(--surface);
|
||||
--el-fill-color-dark: var(--surface-2);
|
||||
--el-fill-color-darker: var(--surface-2);
|
||||
--el-disabled-bg-color: var(--chip);
|
||||
--el-disabled-text-color: var(--muted-2);
|
||||
--el-disabled-border-color: var(--line);
|
||||
--el-box-shadow-light: var(--shadow);
|
||||
--el-box-shadow: var(--shadow);
|
||||
--el-mask-color: rgba(7, 12, 22, .72);
|
||||
--el-mask-color-extra-light: rgba(7, 12, 22, .3);
|
||||
--el-table-bg-color: transparent;
|
||||
--el-table-tr-bg-color: transparent;
|
||||
--el-table-header-bg-color: transparent;
|
||||
--el-table-border-color: var(--line-2);
|
||||
--el-table-row-hover-bg-color: var(--surface-2);
|
||||
--el-table-header-text-color: var(--muted-2);
|
||||
--el-table-text-color: var(--text);
|
||||
}
|
||||
|
||||
/* ── B 素白蓝紫:浅底、白卡、柔和阴影,白天/户外可读性最好(默认)── */
|
||||
:root,
|
||||
:root[data-theme="B"] {
|
||||
--bg: #F4F6FB;
|
||||
--bg-2: #EAEEF7;
|
||||
--surface: #FFFFFF;
|
||||
--surface-2: #FAFBFE;
|
||||
--line: #E5EAF4;
|
||||
--line-2: #EFF2F9;
|
||||
--text: #16203A;
|
||||
--muted: #6B7891;
|
||||
--muted-2: #98A3B7;
|
||||
--primary: #4F63F5;
|
||||
--primary-ink: #FFFFFF;
|
||||
--primary-soft: #EEF1FE;
|
||||
--ok: #15A34A; --warn: #D97706; --err: #DC2626;
|
||||
--ok-soft: #E9F7EE; --warn-soft: #FDF3E4; --err-soft: #FDECEC;
|
||||
--shadow: 0 1px 2px rgba(20, 32, 64, .05), 0 10px 26px rgba(20, 32, 64, .07);
|
||||
--chart-a: #4F63F5; --chart-b: #35B8C9;
|
||||
--chip: #F1F4FA;
|
||||
|
||||
color-scheme: light;
|
||||
--el-color-primary: var(--primary);
|
||||
--el-color-primary-light-3: #6C7CF7;
|
||||
--el-color-primary-light-5: #939FF9;
|
||||
--el-color-primary-light-7: #BAC2FB;
|
||||
--el-color-primary-light-8: #CDD3FC;
|
||||
--el-color-primary-light-9: var(--primary-soft);
|
||||
--el-color-primary-dark-2: #4050E0;
|
||||
--el-color-success: var(--ok);
|
||||
--el-color-success-light-9: var(--ok-soft);
|
||||
--el-color-warning: var(--warn);
|
||||
--el-color-warning-light-9: var(--warn-soft);
|
||||
--el-color-danger: var(--err);
|
||||
--el-color-danger-light-9: var(--err-soft);
|
||||
--el-color-error: var(--err);
|
||||
--el-color-error-light-9: var(--err-soft);
|
||||
--el-color-info: var(--muted);
|
||||
--el-color-info-light-9: var(--chip);
|
||||
--el-bg-color: var(--surface);
|
||||
--el-bg-color-page: var(--bg);
|
||||
--el-bg-color-overlay: var(--surface);
|
||||
--el-text-color-primary: var(--text);
|
||||
--el-text-color-regular: var(--text);
|
||||
--el-text-color-secondary: var(--muted);
|
||||
--el-text-color-placeholder: var(--muted-2);
|
||||
--el-text-color-disabled: var(--muted-2);
|
||||
--el-border-color: var(--line);
|
||||
--el-border-color-light: var(--line);
|
||||
--el-border-color-lighter: var(--line-2);
|
||||
--el-border-color-extra-light: var(--line-2);
|
||||
--el-border-color-dark: var(--line);
|
||||
--el-border-color-darker: var(--line);
|
||||
--el-fill-color: var(--chip);
|
||||
--el-fill-color-light: var(--chip);
|
||||
--el-fill-color-lighter: var(--chip);
|
||||
--el-fill-color-extra-light: var(--chip);
|
||||
--el-fill-color-blank: var(--surface);
|
||||
--el-fill-color-dark: var(--chip);
|
||||
--el-fill-color-darker: var(--chip);
|
||||
--el-disabled-bg-color: var(--chip);
|
||||
--el-disabled-text-color: var(--muted-2);
|
||||
--el-disabled-border-color: var(--line);
|
||||
--el-box-shadow-light: var(--shadow);
|
||||
--el-box-shadow: var(--shadow);
|
||||
--el-mask-color: rgba(20, 32, 64, .5);
|
||||
--el-mask-color-extra-light: rgba(20, 32, 64, .16);
|
||||
--el-table-bg-color: transparent;
|
||||
--el-table-tr-bg-color: transparent;
|
||||
--el-table-header-bg-color: transparent;
|
||||
--el-table-border-color: var(--line-2);
|
||||
--el-table-row-hover-bg-color: var(--surface-2);
|
||||
--el-table-header-text-color: var(--muted-2);
|
||||
--el-table-text-color: var(--text);
|
||||
}
|
||||
|
||||
/* ── C 暖砂墨绿:暖白底 + 墨绿主色,像「纸质台账」,柔和、不刺眼 ── */
|
||||
:root[data-theme="C"] {
|
||||
--bg: #F8F4EF;
|
||||
--bg-2: #F1EAE1;
|
||||
--surface: #FFFFFF;
|
||||
--surface-2: #FCFAF7;
|
||||
--line: #EBE2D7;
|
||||
--line-2: #F3ECE3;
|
||||
--text: #2B2320;
|
||||
--muted: #8A7D71;
|
||||
--muted-2: #AFA396;
|
||||
--primary: #0E7C6B;
|
||||
--primary-ink: #FFFFFF;
|
||||
--primary-soft: #E6F3F0;
|
||||
--ok: #3E8E5A; --warn: #B4711A; --err: #B4453C;
|
||||
--ok-soft: #EDF5EE; --warn-soft: #F8F0E2; --err-soft: #F8ECEA;
|
||||
--shadow: 0 1px 2px rgba(70, 55, 40, .05), 0 10px 24px rgba(70, 55, 40, .07);
|
||||
--chart-a: #0E7C6B; --chart-b: #C98A3C;
|
||||
--chip: #F4EEE7;
|
||||
|
||||
color-scheme: light;
|
||||
--el-color-primary: var(--primary);
|
||||
--el-color-primary-light-3: #2A8F80;
|
||||
--el-color-primary-light-5: #52A79A;
|
||||
--el-color-primary-light-7: #85C3BA;
|
||||
--el-color-primary-light-8: #9DCFC8;
|
||||
--el-color-primary-light-9: var(--primary-soft);
|
||||
--el-color-primary-dark-2: #0B6456;
|
||||
--el-color-success: var(--ok);
|
||||
--el-color-success-light-9: var(--ok-soft);
|
||||
--el-color-warning: var(--warn);
|
||||
--el-color-warning-light-9: var(--warn-soft);
|
||||
--el-color-danger: var(--err);
|
||||
--el-color-danger-light-9: var(--err-soft);
|
||||
--el-color-error: var(--err);
|
||||
--el-color-error-light-9: var(--err-soft);
|
||||
--el-color-info: var(--muted);
|
||||
--el-color-info-light-9: var(--chip);
|
||||
--el-bg-color: var(--surface);
|
||||
--el-bg-color-page: var(--bg);
|
||||
--el-bg-color-overlay: var(--surface);
|
||||
--el-text-color-primary: var(--text);
|
||||
--el-text-color-regular: var(--text);
|
||||
--el-text-color-secondary: var(--muted);
|
||||
--el-text-color-placeholder: var(--muted-2);
|
||||
--el-text-color-disabled: var(--muted-2);
|
||||
--el-border-color: var(--line);
|
||||
--el-border-color-light: var(--line);
|
||||
--el-border-color-lighter: var(--line-2);
|
||||
--el-border-color-extra-light: var(--line-2);
|
||||
--el-border-color-dark: var(--line);
|
||||
--el-border-color-darker: var(--line);
|
||||
--el-fill-color: var(--chip);
|
||||
--el-fill-color-light: var(--chip);
|
||||
--el-fill-color-lighter: var(--chip);
|
||||
--el-fill-color-extra-light: var(--chip);
|
||||
--el-fill-color-blank: var(--surface);
|
||||
--el-fill-color-dark: var(--chip);
|
||||
--el-fill-color-darker: var(--chip);
|
||||
--el-disabled-bg-color: var(--chip);
|
||||
--el-disabled-text-color: var(--muted-2);
|
||||
--el-disabled-border-color: var(--line);
|
||||
--el-box-shadow-light: var(--shadow);
|
||||
--el-box-shadow: var(--shadow);
|
||||
--el-mask-color: rgba(43, 35, 32, .5);
|
||||
--el-mask-color-extra-light: rgba(43, 35, 32, .16);
|
||||
--el-table-bg-color: transparent;
|
||||
--el-table-tr-bg-color: transparent;
|
||||
--el-table-header-bg-color: transparent;
|
||||
--el-table-border-color: var(--line-2);
|
||||
--el-table-row-hover-bg-color: var(--surface-2);
|
||||
--el-table-header-text-color: var(--muted-2);
|
||||
--el-table-text-color: var(--text);
|
||||
}
|
||||
|
||||
/* ── 基础 ───────────────────────────────────────────────────────────── */
|
||||
html, body, #app { height: 100%; margin: 0; }
|
||||
body {
|
||||
font-family: var(--font);
|
||||
color: var(--text);
|
||||
background: var(--bg-2);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
transition: background .18s ease, color .18s ease;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
/* 细滚动条:默认那根在深色主题下太扎眼 */
|
||||
*::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||
*::-webkit-scrollbar-track { background: transparent; }
|
||||
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
|
||||
*::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }
|
||||
|
||||
/* ── 外壳:桌面端侧栏 + 主区 ────────────────────────────────────────── */
|
||||
.app {
|
||||
height: 100vh; height: 100dvh;
|
||||
display: flex; overflow: hidden; background: var(--bg);
|
||||
}
|
||||
.rail {
|
||||
width: var(--rail-w); flex: none; background: var(--surface);
|
||||
border-right: 1px solid var(--line); padding: 16px 12px;
|
||||
display: flex; flex-direction: column;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
|
||||
.logo {
|
||||
width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
|
||||
color: var(--primary-ink); display: grid; place-items: center; flex: none;
|
||||
}
|
||||
.brand b { font-size: 15px; display: block; line-height: 1.25; }
|
||||
.brand span { font-size: 11px; color: var(--muted-2); }
|
||||
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
|
||||
.nav-i {
|
||||
display: flex; align-items: center; gap: 10px; padding: 9px 10px;
|
||||
border-radius: 10px; color: var(--muted); font-size: 13.5px;
|
||||
cursor: pointer; text-decoration: none; transition: background .15s, color .15s;
|
||||
}
|
||||
.nav-i:hover { background: var(--chip); color: var(--text); }
|
||||
.nav-i.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
|
||||
.nav-i svg { flex: none; }
|
||||
.nav-sep { height: 1px; background: var(--line-2); margin: 10px 8px; }
|
||||
.rail-foot { margin-top: auto; font-size: 11px; color: var(--muted-2); padding: 8px 10px; }
|
||||
|
||||
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
||||
.top {
|
||||
height: 62px; flex: none; display: flex; align-items: center; gap: 12px;
|
||||
padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--surface);
|
||||
}
|
||||
.top h2 { margin: 0; font-size: 17px; }
|
||||
.top .crumb { font-size: 12px; color: var(--muted-2); }
|
||||
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
|
||||
.host {
|
||||
display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
|
||||
background: var(--chip); padding: 6px 10px; border-radius: 999px;
|
||||
}
|
||||
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); flex: none; }
|
||||
.dot.ok { background: var(--ok); }
|
||||
.dot.bad { background: var(--err); }
|
||||
.icon-btn {
|
||||
width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
|
||||
background: var(--surface); display: grid; place-items: center; color: var(--muted);
|
||||
cursor: pointer; flex: none; transition: background .15s, color .15s;
|
||||
}
|
||||
.icon-btn:hover { background: var(--chip); color: var(--text); }
|
||||
.user {
|
||||
display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
|
||||
border-radius: 999px; background: var(--chip); cursor: pointer; flex: none;
|
||||
}
|
||||
.user span { font-size: 12.5px; color: var(--muted); }
|
||||
.avatar {
|
||||
width: 26px; height: 26px; border-radius: 50%; background: var(--primary);
|
||||
color: var(--primary-ink); display: grid; place-items: center;
|
||||
font-size: 12px; font-weight: 700; flex: none;
|
||||
}
|
||||
.avatar.lg { width: 32px; height: 32px; font-size: 13px; }
|
||||
.avatar.alt { background: var(--chart-b); color: #fff; }
|
||||
|
||||
.gw-body { flex: 1; min-height: 0; overflow: auto; }
|
||||
.page { padding: 16px 20px; }
|
||||
/* 全高页(对话 / 图像 / 视频):自己不滚,由内部区域滚 */
|
||||
.page-fill {
|
||||
padding: 16px 20px; height: 100%; min-height: 0;
|
||||
display: flex; flex-direction: column;
|
||||
}
|
||||
|
||||
/* ── 卡片 / KPI ─────────────────────────────────────────────────────── */
|
||||
.card {
|
||||
background: var(--surface); border: 1px solid var(--line);
|
||||
border-radius: var(--radius); padding: 14px; min-width: 0;
|
||||
}
|
||||
.card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
|
||||
.card-h b { font-size: 13.5px; }
|
||||
.card-h .sub { font-size: 11.5px; color: var(--muted-2); }
|
||||
.legend { margin-left: auto; display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); }
|
||||
.legend i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; margin-right: 5px; }
|
||||
.pager { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12px; color: var(--muted); }
|
||||
|
||||
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
|
||||
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; min-width: 0; }
|
||||
.kpi .k { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
|
||||
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 7px; font-variant-numeric: tabular-nums; letter-spacing: -.4px; }
|
||||
.kpi .f { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 11.5px; color: var(--muted-2); }
|
||||
.delta { font-size: 11.5px; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
|
||||
.delta.up { color: var(--ok); background: var(--ok-soft); }
|
||||
.delta.down { color: var(--err); background: var(--err-soft); }
|
||||
.delta.flat { color: var(--muted); background: var(--chip); }
|
||||
.spark { display: flex; align-items: flex-end; gap: 3px; height: 24px; margin-left: auto; }
|
||||
.spark i { width: 4px; border-radius: 2px; background: var(--primary); opacity: .32; display: block; }
|
||||
.spark i.hi { opacity: .9; }
|
||||
|
||||
.grid2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: var(--gap); margin-top: var(--gap); }
|
||||
.grid3 { display: grid; grid-template-columns: 1.35fr 1fr; gap: var(--gap); margin-top: var(--gap); }
|
||||
.grid-eq { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-top: var(--gap); }
|
||||
|
||||
/* 供应商状态 / 路由链这类「名称 + 条 + 状态」的竖排列表 */
|
||||
.pv { display: flex; flex-direction: column; gap: 9px; }
|
||||
.pv-i { display: flex; align-items: center; gap: 10px; font-size: 12.5px; min-width: 0; }
|
||||
.pv-i .nm { width: 78px; color: var(--text); }
|
||||
.pv-i .st { margin-left: auto; }
|
||||
/* 第十八轮: 进度条改名为 .meter —— .bar 太通用,与 Chat 输入区的按钮行 class="bar"
|
||||
撞名:本规则的 height:5px + overflow:hidden 把整行按钮(发送/模型选择/token 计数)
|
||||
裁得只剩 9px 高、内容全不可见(桌面+手机都中招)。 */
|
||||
.meter { height: 5px; border-radius: 3px; background: var(--chip); overflow: hidden; }
|
||||
.meter i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
|
||||
|
||||
.pill { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
|
||||
.pill.ok { color: var(--ok); background: var(--ok-soft); }
|
||||
.pill.warn { color: var(--warn); background: var(--warn-soft); }
|
||||
.pill.err { color: var(--err); background: var(--err-soft); }
|
||||
.pill.mute { color: var(--muted); background: var(--chip); }
|
||||
.badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; flex: none; }
|
||||
.badge.g { color: var(--ok); background: var(--ok-soft); }
|
||||
.badge.o { color: var(--warn); background: var(--warn-soft); }
|
||||
.badge.r { color: var(--err); background: var(--err-soft); }
|
||||
.badge.m { color: var(--muted); background: var(--chip); }
|
||||
/* 第二十二轮 反馈处理进度:处理中用主题色(p),待处理/已处理复用 o / g */
|
||||
.badge.p { color: var(--primary); background: var(--primary-soft); }
|
||||
.chip-sel {
|
||||
border: 1px solid var(--line); border-radius: 9px; padding: 7px 11px;
|
||||
font-size: 12.5px; color: var(--muted); background: var(--surface);
|
||||
display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
|
||||
}
|
||||
.chip-sel.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 600; }
|
||||
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; letter-spacing: .2px; }
|
||||
|
||||
/* ── 设置 / 用户页共用的行式布局与主题卡 ────────────────────────────── */
|
||||
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
|
||||
.set-row {
|
||||
display: flex; align-items: center; gap: 12px; padding: 10px 0;
|
||||
border-bottom: 1px solid var(--line-2); font-size: 13px; min-width: 0;
|
||||
}
|
||||
.set-row:last-child { border-bottom: 0; }
|
||||
/* 第十八轮: 标签不再参与收缩。此前 .rt{flex:none} 把整行让给右侧控件,而 .lb 会被压到
|
||||
13px 宽 —— 「供应商状态」逐字竖排,右边的第三个 pill 还溢出卡片(1024×768 实测)。 */
|
||||
.set-row > .lb { color: var(--text); flex: 0 0 auto; }
|
||||
/* 系统提示词那种整行输入(`<div class="lb flex-1">`)仍要能吃满剩余宽度 */
|
||||
.set-row > .lb.flex-1 { flex: 1 1 auto; min-width: 0; }
|
||||
.set-row .sub { font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }
|
||||
/* 右侧区:默认按内容宽(按钮/开关不被拉伸),放不下时先收缩再换行 ——
|
||||
多个状态标签自己折到下一行,而不是把左边标签挤没、自己溢出卡片。 */
|
||||
.set-row .rt {
|
||||
margin-left: auto; display: flex; align-items: center; gap: 8px;
|
||||
flex: 0 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end;
|
||||
}
|
||||
.theme-card {
|
||||
display: flex; align-items: center; gap: 11px; border: 1px solid var(--line);
|
||||
border-radius: 12px; padding: 10px; margin-bottom: 8px; cursor: pointer;
|
||||
transition: border-color .15s, background .15s;
|
||||
}
|
||||
.theme-card:hover { border-color: var(--muted-2); }
|
||||
.theme-card.on { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.theme-card b { font-size: 13px; }
|
||||
.theme-prev {
|
||||
width: 56px; height: 40px; border-radius: 9px; border: 1px solid var(--line);
|
||||
display: flex; overflow: hidden; flex: none;
|
||||
}
|
||||
.theme-prev .l { width: 36%; display: block; }
|
||||
.theme-prev .r { flex: 1; padding: 5px; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
|
||||
.theme-prev .r i { height: 5px; border-radius: 3px; display: block; }
|
||||
|
||||
/* 关于条:一行式信息,窄屏自动换行 */
|
||||
.about-line { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
|
||||
|
||||
/* ── 表单控件(设计稿的 .ctl:只读展示态;可输入的仍用 el-input)───────── */
|
||||
.field { flex: 1; min-width: 0; }
|
||||
.field > label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
|
||||
.form-row { display: flex; gap: 10px; }
|
||||
.ctl {
|
||||
min-height: 34px; border: 1px solid var(--line); border-radius: 10px;
|
||||
background: var(--surface-2); display: flex; align-items: center;
|
||||
padding: 0 10px; font-size: 12.5px; color: var(--text);
|
||||
}
|
||||
.ctl.area { min-height: 76px; align-items: flex-start; padding: 9px 10px; line-height: 1.5; }
|
||||
|
||||
/* ── 对话页 ─────────────────────────────────────────────────────────── */
|
||||
.chat-layout {
|
||||
display: grid; grid-template-columns: 236px 1fr; gap: var(--gap); height: 100%; min-height: 0;
|
||||
/* 第十九轮:grid 的行必须显式钉住。默认 grid-template-rows: auto 会让这一行按**内容**撑高
|
||||
(消息一多,行高就长到几千 px),而 .chat-main / .chat-card 的 height:100% 又反过来跟着这个
|
||||
行高走 —— 结果是整页(.gw-body)被撑成可滚、消息区自己永远不滚、输入框被推到几千 px 之下,
|
||||
想发下一条得先滚到底。minmax(0, 1fr) = 行高吃容器给的确定高度,超出的部分交给内部滚动。 */
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
}
|
||||
.conv {
|
||||
padding: 8px 9px; border-radius: 10px; font-size: 13px; color: var(--muted);
|
||||
cursor: pointer; transition: background .15s, color .15s;
|
||||
}
|
||||
.conv:hover { background: var(--chip); }
|
||||
.conv.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
|
||||
.conv small { display: block; font-size: 11px; color: var(--muted-2); margin-top: 3px; font-weight: 400; }
|
||||
.msgs {
|
||||
display: flex; flex-direction: column; gap: 11px; overflow-y: auto;
|
||||
min-height: 0; padding-right: 2px;
|
||||
}
|
||||
.msg {
|
||||
max-width: 74%; padding: 10px 13px; border-radius: 14px;
|
||||
font-size: 13px; line-height: 1.65; overflow-wrap: anywhere;
|
||||
}
|
||||
.msg.me { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 5px; }
|
||||
.msg.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
|
||||
.msg .meta { font-size: 11px; opacity: .72; margin-top: 6px; }
|
||||
.msg .attach { display: flex; gap: 6px; margin-bottom: 7px; flex-wrap: wrap; }
|
||||
.msg .attach i {
|
||||
width: 46px; height: 46px; border-radius: 8px; display: block;
|
||||
background: linear-gradient(135deg, var(--primary-soft), var(--chip)); border: 1px solid var(--line);
|
||||
}
|
||||
.composer { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: var(--surface); }
|
||||
.composer .in { font-size: 13px; color: var(--muted-2); padding: 2px 2px 10px; }
|
||||
.composer .bar { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line-2); padding-top: 9px; }
|
||||
|
||||
/* ── 图像 / 视频页:左参数、右结果 ──────────────────────────────────── */
|
||||
.img-layout { display: grid; grid-template-columns: 320px 1fr; gap: var(--gap); height: 100%; min-height: 0; }
|
||||
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
|
||||
.th { border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--surface-2); }
|
||||
.th .ph {
|
||||
height: 96px; display: grid; place-items: center; color: var(--muted-2); font-size: 11px;
|
||||
background: linear-gradient(135deg, var(--primary-soft), var(--chip));
|
||||
}
|
||||
.th .meta { padding: 7px 8px; }
|
||||
.th .meta b { font-size: 11.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.th .meta span { font-size: 10.5px; color: var(--muted-2); }
|
||||
.pg {
|
||||
min-width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
|
||||
border: 1px solid var(--line); cursor: pointer; color: var(--muted);
|
||||
}
|
||||
.pg.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
|
||||
/* 场景卡两列(原本三列):参数列只有 ~289px 宽,三列时每格仅 91px,
|
||||
「首尾帧(图生视频)」在格内必然折成两行;两列每格 140px、标签单行。 */
|
||||
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
|
||||
.mode {
|
||||
border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px;
|
||||
text-align: center; font-size: 12px; color: var(--muted); cursor: pointer;
|
||||
}
|
||||
.mode.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
|
||||
.vid-card {
|
||||
display: flex; gap: 12px; padding: 11px; border: 1px solid var(--line);
|
||||
border-radius: var(--radius); background: var(--surface); margin-bottom: 9px;
|
||||
}
|
||||
.vid-thumb {
|
||||
/* 第十九轮:128×76 → 148×84(16:9),和右侧压到 3 行的信息高度对齐,
|
||||
缩略图用 align-items:center 垂直居中,卡片左下方不再留一块空白 */
|
||||
width: 148px; height: 84px; border-radius: 9px; flex: none; display: grid; place-items: center;
|
||||
background: linear-gradient(135deg, var(--primary-soft), var(--chip)); color: var(--muted-2);
|
||||
}
|
||||
.progress { height: 6px; border-radius: 4px; background: var(--chip); overflow: hidden; margin: 8px 0 6px; }
|
||||
.progress i { display: block; height: 100%; border-radius: 4px; background: var(--primary); }
|
||||
|
||||
/* ── 密钥 / 用户管理 ────────────────────────────────────────────────── */
|
||||
.key-row {
|
||||
display: flex; align-items: center; gap: 10px; padding: 11px 12px;
|
||||
border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); margin-bottom: 8px;
|
||||
}
|
||||
.expand-row {
|
||||
background: var(--surface-2); border: 1px solid var(--line);
|
||||
border-radius: 10px; padding: 12px; margin: 6px 0 10px;
|
||||
}
|
||||
|
||||
/* ── 日志 ───────────────────────────────────────────────────────────── */
|
||||
.filters { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
|
||||
.log-row {
|
||||
display: flex; align-items: center; gap: 10px; padding: 8px 0;
|
||||
border-bottom: 1px solid var(--line-2); font-size: 12.5px;
|
||||
}
|
||||
.log-row .ts { color: var(--muted-2); font-variant-numeric: tabular-nums; width: 62px; flex: none; }
|
||||
.log-detail {
|
||||
background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
|
||||
padding: 11px 12px; margin: 6px 0 10px; font-size: 12px; line-height: 1.65; color: var(--muted);
|
||||
}
|
||||
.log-detail b { color: var(--text); }
|
||||
|
||||
.muted { color: var(--muted); }
|
||||
.muted-2 { color: var(--muted-2); }
|
||||
.hint { font-size: 11.5px; color: var(--muted-2); }
|
||||
.flex-1 { flex: 1; min-width: 0; }
|
||||
.mb { margin-bottom: var(--gap); }
|
||||
.nowrap { white-space: nowrap; }
|
||||
.sep { height: 1px; background: var(--line-2); margin: 12px 0 10px; }
|
||||
.about-card { margin-top: var(--gap); padding: 12px 16px; }
|
||||
|
||||
/* ── 手机端外壳 ─────────────────────────────────────────────────────── */
|
||||
.m-top {
|
||||
flex: none; height: 52px; display: flex; align-items: center; gap: 10px;
|
||||
padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.m-top .ic {
|
||||
width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
|
||||
color: var(--muted); cursor: pointer; flex: none;
|
||||
}
|
||||
.m-top h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
|
||||
.tabbar {
|
||||
flex: none; background: var(--surface); border-top: 1px solid var(--line);
|
||||
display: flex; padding-bottom: env(safe-area-inset-bottom, 0);
|
||||
}
|
||||
.tabbar div {
|
||||
flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||
gap: 3px; font-size: 10.5px; color: var(--muted-2); padding: 9px 0; cursor: pointer;
|
||||
}
|
||||
.tabbar div.on { color: var(--primary); font-weight: 600; }
|
||||
.m-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
|
||||
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; }
|
||||
.seg span { flex: 1; text-align: center; font-size: 12.5px; padding: 7px 0; border-radius: 8px; color: var(--muted); cursor: pointer; }
|
||||
.seg span.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .07); }
|
||||
.m-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.m-kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; }
|
||||
.m-kpi .k { font-size: 11.5px; color: var(--muted); }
|
||||
.m-kpi .v { font-size: 19px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
|
||||
.m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
|
||||
/* 抽屉导航(el-drawer teleport 到 body,样式写在全局层) */
|
||||
.nav-drawer .el-drawer__body { padding: 0; overflow: hidden; background: var(--surface); }
|
||||
.nav-drawer .el-drawer { background: var(--surface); }
|
||||
|
||||
/* ── Element Plus 收口:圆角/阴影/表格/弹层跟随主题 ─────────────────── */
|
||||
.el-card, .el-dialog, .el-drawer, .el-popper, .el-dropdown-menu, .el-message-box {
|
||||
border-radius: var(--radius) !important;
|
||||
}
|
||||
.el-dialog, .el-message-box, .el-drawer { background: var(--surface); }
|
||||
.el-button { font-weight: 500; }
|
||||
.el-button--primary { font-weight: 600; }
|
||||
.el-table { --el-table-border-color: var(--line-2); background: transparent; }
|
||||
.el-table th.el-table__cell { background: transparent; font-weight: 500; }
|
||||
.el-table .cell { line-height: 1.55; }
|
||||
.el-tabs__item { color: var(--muted); }
|
||||
.el-tabs__item.is-active { color: var(--primary); }
|
||||
.el-alert { border-radius: var(--radius); }
|
||||
.el-tag { border-radius: 999px; }
|
||||
.el-input__wrapper, .el-textarea__inner, .el-select__wrapper { background: var(--surface); }
|
||||
.el-input__wrapper.is-focus, .el-select__wrapper.is-focused { box-shadow: 0 0 0 1px var(--primary) inset !important; }
|
||||
|
||||
/* 小按钮 / 状态标签文案不折行(参考图「上传/URL」在窄列被挤成两行的问题) */
|
||||
.pill, .badge, .chip-sel, .nav-i span, .tabbar div { white-space: nowrap; }
|
||||
|
||||
/* ── 窄屏:只做全局兜底,结构切换(侧栏 → 抽屉 + 底部 Tab)在 JS 里 ────
|
||||
断点须与 src/lib/ui.ts 的 MOBILE_MAX=768 保持一致。 */
|
||||
@media (max-width: 768px) {
|
||||
.page { padding: 12px 14px; }
|
||||
.page-fill { padding: 12px 14px; }
|
||||
.kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.kpi .v { font-size: 19px; }
|
||||
.grid2, .grid3, .grid-eq { grid-template-columns: 1fr; }
|
||||
.top { padding: 0 12px; }
|
||||
|
||||
/* 对话 / 媒体页在窄屏改为单列;会话列表(.chat-side)收进顶部下拉,不再占屏 */
|
||||
.chat-layout, .img-layout { grid-template-columns: 1fr; }
|
||||
.chat-side { display: none; }
|
||||
.thumbs { grid-template-columns: 1fr 1fr; }
|
||||
.msg { max-width: 88%; }
|
||||
.vid-thumb { width: 108px; height: 61px; }
|
||||
.set-grid { grid-template-columns: 1fr; }
|
||||
.log-row .ts { width: 52px; }
|
||||
|
||||
/* 防 iPhone 聚焦缩放:输入框字号 < 16px 会触发自动放大且不缩回 */
|
||||
.el-input__inner,
|
||||
.el-textarea__inner,
|
||||
.el-select__input,
|
||||
.el-input-number .el-input__inner { font-size: 16px; }
|
||||
|
||||
/* inline 表单自己收缩到父容器内(别用 calc(100vw - Npx) 猜宽度) */
|
||||
.el-form--inline { display: flex; flex-wrap: wrap; column-gap: 12px; }
|
||||
.el-form--inline .el-form-item { display: flex; max-width: 100%; margin-right: 0; margin-bottom: 8px; }
|
||||
.el-form--inline .el-form-item__label { padding-right: 6px; flex: none; }
|
||||
.el-form--inline .el-form-item__content { min-width: 0; }
|
||||
|
||||
.toolbar, .row-flex, .op-row { flex-wrap: wrap; }
|
||||
.row-flex { gap: 8px; }
|
||||
.row-flex .el-input, .row-flex .el-select { flex: 1 1 180px; min-width: 0; }
|
||||
.form-row { flex-wrap: wrap; }
|
||||
|
||||
/* 卡片头(标题 + 计数 + 右侧控件):窄屏下右侧控件整行下移。
|
||||
否则「账号 / 我的 API Key」这种标题会被搜索框和按钮挤成一字一列。 */
|
||||
.card-h { flex-wrap: wrap; row-gap: 8px; }
|
||||
.card-h > b { flex: none; }
|
||||
.card-h .sub { flex: 1 1 auto; min-width: 0; }
|
||||
.card-h .pager, .card-h .legend { margin-left: 0; flex: 1 1 100%; }
|
||||
.card-h .pager .el-input, .card-h .pager .el-input-number { flex: 1 1 auto; min-width: 0; }
|
||||
|
||||
/* 设置页的行式布局:右侧内容(如「供应商状态」多个标签)自己换行,
|
||||
别整块撑出容器被裁掉(.rt 默认 flex: none 会保持自然宽度)。 */
|
||||
.set-row .rt { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
|
||||
|
||||
.el-table { font-size: 12px; }
|
||||
.el-table .cell { word-break: break-word; }
|
||||
.el-dialog { width: 92% !important; max-width: 560px; }
|
||||
.el-message-box { width: 92% !important; max-width: 420px; }
|
||||
.el-button { touch-action: manipulation; }
|
||||
/* 第十八轮: 触控目标 —— small 按钮(导出/清空/重新生成/复制全文…)原为 24px 高,
|
||||
低于 44px 的可点建议值,手机上容易点空;34px 是"明显变大、又不炸排版"的折中。 */
|
||||
.el-button--small { min-height: 34px; }
|
||||
.el-button--small.is-text, .el-button--small.is-link { min-height: 34px; }
|
||||
/* 第十八轮: 手机端小字号抬一档(底部 Tab / 缩略图副标题原 10.5px,读起来发虚) */
|
||||
.tabbar div { font-size: 11.5px; }
|
||||
.th .meta span { font-size: 11.5px; }
|
||||
img, video, canvas, svg { max-width: 100%; }
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.myKeys') }}</b>
|
||||
<span class="sub">{{ keys.length }} / {{ limit === null ? '∞' : limit }}</span>
|
||||
<div class="pager">
|
||||
<!-- 标签输入留在页头:创建时仍可给 Key 起名(行为与旧版一致) -->
|
||||
<el-input
|
||||
v-model="label"
|
||||
size="small"
|
||||
class="label-inp"
|
||||
:placeholder="t('settings.keyLabel')"
|
||||
clearable
|
||||
@keyup.enter="create"
|
||||
/>
|
||||
<el-tooltip :disabled="!atLimit" :content="t('settings.keyLimitFull')">
|
||||
<span>
|
||||
<el-button type="primary" size="small" :loading="creating" :disabled="atLimit" @click="create">
|
||||
<Icon name="plus" :size="14" />
|
||||
<span>{{ atLimit ? t('settings.createKey') + '(' + t('settings.keyLimitFull') + ')' : t('settings.createKey') }}</span>
|
||||
</el-button>
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第八轮补: 后端在 GET /auth/apikeys 里回 key_limit,前端据此提前禁用按钮 ——
|
||||
到顶了就别再发那个必然 400 的请求,提示也走人话而不是错误码。 -->
|
||||
<div v-if="atLimit" class="warn-bar">
|
||||
<Icon name="bell" :size="15" />
|
||||
<span>{{ t('settings.keyLimitFull') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="keys.length">
|
||||
<div v-for="k in keys" :key="k.id" class="key-row">
|
||||
<div class="flex-1">
|
||||
<div class="key-t">
|
||||
<b>{{ k.label || t('common.none') }}</b>
|
||||
</div>
|
||||
<div class="code key-val">
|
||||
<span v-if="k.key">{{ k.key }}</span>
|
||||
<span v-else class="muted-2">{{ k.hint }}…… {{ t('settings.keyLegacyNoEcho') }}</span>
|
||||
</div>
|
||||
<div class="hint key-meta">{{ t('settings.keyCreated') }} · {{ fmtTs(k.created) }}</div>
|
||||
</div>
|
||||
<div class="key-acts">
|
||||
<el-button size="small" :disabled="!k.key" @click="copyKey(k.key)">
|
||||
<Icon name="copy" :size="13" />
|
||||
<span>{{ t('common.copy') }}</span>
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" plain @click="remove(k.id)">
|
||||
<Icon name="trash" :size="13" />
|
||||
<span>{{ t('common.delete') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else :description="t('settings.noKey')" :image-size="80" />
|
||||
|
||||
<div class="sep" />
|
||||
|
||||
<!-- 调用方式:Key 页面直接给一份调用说明,别让人去翻 README -->
|
||||
<div class="card-h">
|
||||
<b>{{ t('apidoc.title') }}</b>
|
||||
<span class="sub">{{ base }}</span>
|
||||
</div>
|
||||
|
||||
<div class="log-detail">
|
||||
<div>
|
||||
<b>{{ t('apidoc.baseUrl') }}</b>
|
||||
<span class="code">{{ base }}</span>
|
||||
<el-button text type="primary" size="small" @click="copy(base)">
|
||||
<Icon name="copy" :size="12" />
|
||||
<span>{{ t('apidoc.copyBase') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
<div><b>{{ t('apidoc.auth') }}</b> <span class="code">{{ t('apidoc.authVal') }}</span></div>
|
||||
<div><b>{{ t('apidoc.modelPick') }}</b> <span>{{ t('apidoc.modelPickVal') }}</span></div>
|
||||
<div><b>{{ t('apidoc.ctype') }}</b> <span>{{ t('apidoc.ctypeVal') }}</span></div>
|
||||
</div>
|
||||
|
||||
<div class="call-acts">
|
||||
<el-button size="small" @click="copy(examples[0].code)">
|
||||
<Icon name="copy" :size="13" />
|
||||
<span>{{ t('apidoc.copyCmd') }} curl</span>
|
||||
</el-button>
|
||||
<el-button size="small" @click="scrollDoc">
|
||||
<Icon name="chevD" :size="13" />
|
||||
<span>{{ t('apidoc.title') }}</span>
|
||||
</el-button>
|
||||
<span class="hint call-note">{{ t('apidoc.intro') }}</span>
|
||||
</div>
|
||||
|
||||
<div ref="docRef" class="doc">
|
||||
<div class="sub-title">{{ t('apidoc.endpoints') }}</div>
|
||||
<el-table :data="endpoints" size="small">
|
||||
<el-table-column prop="method" :label="t('apidoc.colMethod')" width="80">
|
||||
<template #default="{ row }">
|
||||
<span class="badge m">{{ row.method }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('apidoc.colPath')" min-width="230">
|
||||
<template #default="{ row }"><span class="code">{{ row.path }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="desc" :label="t('apidoc.colDesc')" min-width="280" />
|
||||
</el-table>
|
||||
|
||||
<div v-for="ex in examples" :key="ex.title" class="ex">
|
||||
<div class="sub-title">
|
||||
{{ ex.title }}
|
||||
<el-button text type="primary" size="small" @click="copy(ex.code)">
|
||||
<Icon name="copy" :size="12" />
|
||||
<span>{{ t('apidoc.copyCmd') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
<pre class="code pre">{{ ex.code }}</pre>
|
||||
</div>
|
||||
|
||||
<div class="sub-title">{{ t('apidoc.notes') }}</div>
|
||||
<ul class="notes">
|
||||
<li v-for="(n, i) in notes" :key="i">{{ n }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { api } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
const keys = ref<any[]>([])
|
||||
const label = ref('')
|
||||
const creating = ref(false)
|
||||
const limit = ref<number | null>(null) // null = 不限(admin)
|
||||
const base = window.location.origin
|
||||
|
||||
// 端点表:与 app/main.py 的真实路由一一对应(别写成 README 里才有的东西)
|
||||
const endpoints = computed(() => [
|
||||
{ method: 'GET', path: '/v1/models', desc: t('apidoc.epModels') },
|
||||
{ method: 'POST', path: '/v1/chat/completions', desc: t('apidoc.epChat') },
|
||||
{ method: 'POST', path: '/v1/images/generations', desc: t('apidoc.epImages') },
|
||||
{ method: 'POST', path: '/v1/videos', desc: t('apidoc.epVideoCreate') },
|
||||
{ method: 'GET', path: '/v1/videos/{video_id}?model=...', desc: t('apidoc.epVideoPoll') },
|
||||
{ method: 'GET', path: '/history/{kind}', desc: t('apidoc.epHistory') },
|
||||
{ method: 'GET', path: '/logs', desc: t('apidoc.epLogs') },
|
||||
{ method: 'GET', path: '/metrics', desc: t('apidoc.epMetrics') },
|
||||
{ method: 'GET', path: '/health', desc: t('apidoc.epHealth') },
|
||||
])
|
||||
|
||||
const notes = computed(() => [
|
||||
t('apidoc.noteVision'), t('apidoc.noteN1'), t('apidoc.noteVideo'),
|
||||
t('apidoc.notePoll'), t('apidoc.noteMedia'), t('apidoc.noteKey'), t('apidoc.noteAudit'),
|
||||
])
|
||||
|
||||
// 示例里的 Key 用占位符 $GW_KEY(不把真 Key 渲染进文档;本页的 Key 明文只在上方列表里回显)
|
||||
const examples = computed(() => {
|
||||
const H = `-H "Authorization: Bearer $GW_KEY" -H "Content-Type: application/json"`
|
||||
return [
|
||||
// 示例里的注释与示例文案也走 i18n:英文界面下照抄示例不会看到中文
|
||||
{ title: t('apidoc.exChat'), code:
|
||||
`curl ${base}/v1/chat/completions \\
|
||||
${H} \\
|
||||
-d '{"model":"wjd","messages":[{"role":"user","content":"${t('apidoc.sampleChat')}"}]}'` },
|
||||
{ title: t('apidoc.exImg'), code:
|
||||
`curl ${base}/v1/images/generations \\
|
||||
${H} \\
|
||||
-d '{"model":"agnes-image-2.5-flash","prompt":"${t('apidoc.sampleImg')}","size":"1K","ratio":"16:9","n":1}'` },
|
||||
{ title: t('apidoc.exVideo'), code:
|
||||
`# 1) ${t('apidoc.sampleStep1')}
|
||||
curl ${base}/v1/videos \\
|
||||
${H} \\
|
||||
-d '{"model":"agnes-video-2.5-flash","prompt":"${t('apidoc.sampleVideo')}","mode":"text","seconds":"5","size":"720P","aspect_ratio":"16:9"}'
|
||||
# → {"video_id":"task_xxx","status":"pending"}
|
||||
|
||||
# 2) ${t('apidoc.sampleStep2')}
|
||||
curl "${base}/v1/videos/task_xxx?model=agnes-video-2.5-flash" \\
|
||||
-H "Authorization: Bearer $GW_KEY"` },
|
||||
{ title: t('apidoc.exPy'), code:
|
||||
`from openai import OpenAI
|
||||
|
||||
c = OpenAI(base_url="${base}/v1", api_key="wjd-xxxxxxxx")
|
||||
r = c.chat.completions.create(model="wjd", messages=[{"role": "user", "content": "${t('apidoc.sampleChat')}"}])
|
||||
print(r.choices[0].message.content)` },
|
||||
]
|
||||
})
|
||||
|
||||
// 「查看接口文档」:滚动到同卡片下方的端点 / 示例 / 注意事项(文档始终可见,不做折叠)
|
||||
const docRef = ref<HTMLElement | null>(null)
|
||||
function scrollDoc() {
|
||||
docRef.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
|
||||
async function copy(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
ElMessage.success(t('common.copyOk'))
|
||||
} catch { ElMessage.warning(t('common.copyFail')) }
|
||||
}
|
||||
|
||||
const atLimit = computed(() => limit.value !== null && keys.value.length >= limit.value)
|
||||
|
||||
function fmtTs(ts: number): string {
|
||||
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())}`
|
||||
}
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const j = await api('/auth/apikeys')
|
||||
keys.value = j.keys || []
|
||||
limit.value = j.key_limit ?? null
|
||||
} catch (e: any) { ElMessage.error(e?.body?.detail || e?.message || String(e)) }
|
||||
}
|
||||
|
||||
async function create() {
|
||||
if (atLimit.value) { ElMessage.warning(t('settings.keyLimitFull')); return }
|
||||
creating.value = true
|
||||
try {
|
||||
await api('/auth/apikeys', { method: 'POST', body: JSON.stringify({ label: label.value.trim() }) })
|
||||
label.value = ''
|
||||
await load()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.body?.detail || String(e?.message || e))
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id: string) {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('settings.confirmDeleteKey'), t('settings.confirm'), { type: 'warning' })
|
||||
} catch { return }
|
||||
try {
|
||||
await api(`/auth/apikeys/${id}`, { method: 'DELETE' })
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(e?.body?.detail || String(e?.message || e)) }
|
||||
}
|
||||
|
||||
async function copyKey(k: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(k)
|
||||
ElMessage.success(t('common.copyOk'))
|
||||
} catch { ElMessage.warning(t('common.copyFail')) }
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.label-inp { width: 190px; }
|
||||
.warn-bar {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
background: var(--warn-soft); color: var(--warn);
|
||||
border-radius: 10px; padding: 9px 12px; font-size: 12px; margin-bottom: 12px;
|
||||
}
|
||||
.key-t { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
||||
.key-val { margin-top: 5px; color: var(--muted); word-break: break-all; }
|
||||
.key-meta { margin-top: 4px; }
|
||||
.key-acts { display: flex; gap: 7px; flex: none; }
|
||||
.key-acts .gw-icon, .call-acts .gw-icon { margin-right: 5px; }
|
||||
.log-detail > div { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
|
||||
.log-detail > div + div { margin-top: 4px; }
|
||||
.call-acts { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
|
||||
.call-note { margin-left: auto; max-width: 54%; text-align: right; line-height: 1.6; }
|
||||
.sub-title { display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 13px; margin: 14px 0 8px; }
|
||||
.pre {
|
||||
background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
|
||||
padding: 10px 12px; border-radius: 10px; margin: 0; font-size: 12px; line-height: 1.6;
|
||||
overflow-x: auto; white-space: pre;
|
||||
}
|
||||
.ex { margin-bottom: 4px; }
|
||||
.notes { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.9; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.label-inp { width: 100%; }
|
||||
.key-row { flex-wrap: wrap; }
|
||||
.call-note { margin-left: 0; max-width: 100%; text-align: left; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,822 @@
|
||||
<template>
|
||||
<div class="page-fill">
|
||||
<div class="chat-layout">
|
||||
<!-- 左栏:会话。窄屏由 style.css 隐藏(.chat-side),改用右栏顶部的会话下拉 -->
|
||||
<aside class="chat-side">
|
||||
<div class="card side-in">
|
||||
<el-button type="primary" class="new-conv" :disabled="streaming" @click="clearConversation">
|
||||
<Icon name="plus" :size="14" />
|
||||
<span>{{ t('chat.newChat') }}</span>
|
||||
</el-button>
|
||||
|
||||
<!-- 会话列表:当前这条(服务端 history/chat 的 current 条目)加 .on -->
|
||||
<div class="conv-list">
|
||||
<div v-for="c in conversations" :key="c.id" class="conv" :class="{ on: c.id === activeConvId }">
|
||||
{{ c.title }}
|
||||
<small>{{ c.time }} · {{ t('chat.msgsN', { n: c.n }) }}</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sep" />
|
||||
|
||||
<div class="card-h">
|
||||
<b>{{ t('chat.thisConv') }}</b>
|
||||
</div>
|
||||
<div class="pv conv-info">
|
||||
<div class="pv-i">
|
||||
<span class="nm">{{ t('chat.model') }}</span>
|
||||
<span class="st code">{{ params.model }}</span>
|
||||
</div>
|
||||
<div class="pv-i">
|
||||
<span class="nm">Tokens</span>
|
||||
<span class="st">{{ totalTokens }}</span>
|
||||
</div>
|
||||
<div class="pv-i">
|
||||
<span class="nm">{{ t('chat.elapsed') }}</span>
|
||||
<span class="st">{{ elapsedText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="side-ops">
|
||||
<el-button class="op" size="small" :disabled="!messages.length" @click="exportConv">
|
||||
<Icon name="dl" :size="13" />
|
||||
<span>{{ t('common.export') }}</span>
|
||||
</el-button>
|
||||
<el-button class="op" size="small" :disabled="streaming || !messages.length" @click="clearConversation">
|
||||
<Icon name="trash" :size="13" />
|
||||
<span>{{ t('chat.clear') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- 右栏:参数胶囊 + 消息 + 输入区 -->
|
||||
<section class="chat-main">
|
||||
<div class="chat-top">
|
||||
<!-- 窄屏没有左栏,会话切换收在这里(只有一条会话时不显示) -->
|
||||
<el-select
|
||||
v-if="isMobile && conversations.length > 1"
|
||||
v-model="activeConvId"
|
||||
size="small"
|
||||
class="conv-sel"
|
||||
:placeholder="t('chat.session')"
|
||||
>
|
||||
<el-option v-for="c in conversations" :key="c.id" :value="c.id" :label="c.title" />
|
||||
</el-select>
|
||||
|
||||
<span class="chip-sel" :class="{ on: params.stream }" @click="paramsOpen = true">
|
||||
<Icon name="bolt" :size="13" />{{ t('chat.streaming') }}
|
||||
</span>
|
||||
<span class="chip-sel" @click="paramsOpen = true">{{ t('chat.tempShort') }} {{ params.temperature }}</span>
|
||||
<span class="chip-sel" @click="paramsOpen = true">
|
||||
{{ t('chat.maxShort') }} {{ params.max_tokens ?? t('common.none') }}
|
||||
</span>
|
||||
<span class="chip-sel" :class="{ on: !!params.system.trim() }" @click="paramsOpen = true">
|
||||
{{ t('chat.systemShort') }}
|
||||
</span>
|
||||
|
||||
<span v-if="streaming" class="stream-badge">{{ t('chat.generating') }}</span>
|
||||
<span class="vision-hint" :class="{ off: !visionOk }">
|
||||
{{ visionOk ? t('chat.visionReady') : t('chat.visionOff') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="card chat-card">
|
||||
<div class="card-h">
|
||||
<b>{{ convTitle }}</b>
|
||||
<span class="sub">{{ t('chat.msgsN', { n: messages.length }) }}<template v-if="lastAt"> · {{ fmtClock(lastAt) }}</template></span>
|
||||
<div class="pager">
|
||||
<el-button size="small" :disabled="streaming || !lastUser" @click="regenerate">
|
||||
<Icon name="refresh" :size="13" />
|
||||
<span>{{ t('chat.regenerate') }}</span>
|
||||
</el-button>
|
||||
<el-button size="small" :disabled="!messages.length" @click="copyAll">
|
||||
<Icon name="copy" :size="13" />
|
||||
<span>{{ t('chat.copyAll') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref="scrollEl" class="msgs" @scroll="onScroll">
|
||||
<div v-if="messages.length === 0" class="empty">
|
||||
<Icon name="chat" :size="34" />
|
||||
<div class="empty-t">{{ t('chat.empty') }}</div>
|
||||
</div>
|
||||
|
||||
<div v-for="msg in messages" :key="msg.id" class="msg" :class="msg.role === 'user' ? 'me' : 'ai'">
|
||||
<!-- 助手:降级/服务信息 -->
|
||||
<div v-if="msg.role === 'assistant' && msg.meta" class="resp-meta">
|
||||
<el-tag size="small" :type="msg.meta.fallback ? 'warning' : 'success'" effect="light">
|
||||
<template v-if="msg.meta.fallback">{{ t('chat.fallback', { provider: msg.meta.provider }) }}</template><template v-else>{{ t('chat.servedBy', { provider: msg.meta.provider }) }}</template>
|
||||
</el-tag>
|
||||
<span class="meta-txt">
|
||||
<template v-if="msg.meta.fallback">{{ t('chat.requestedTo', { req: msg.meta.requested, served: msg.meta.served }) }}</template>
|
||||
<template v-else>{{ msg.meta.served }}</template>
|
||||
</span>
|
||||
<span v-if="msg.usage || msg.cost != null" class="meta-txt">
|
||||
· {{ msg.cost != null ? `¥${msg.cost}` : '' }}
|
||||
<template v-if="msg.usage">{{ tokensText(msg.usage) }}</template>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 助手:推理折叠 -->
|
||||
<el-collapse v-if="msg.role === 'assistant' && msg.reasoning" class="reasoning">
|
||||
<el-collapse-item :title="t('chat.reasoning')" name="r">
|
||||
<div class="reasoning-md">{{ msg.reasoning }}</div>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
|
||||
<!-- 附图缩略(用户消息) -->
|
||||
<div v-if="msg.images && msg.images.length" class="attach">
|
||||
<el-image v-for="(u, k) in msg.images" :key="k" :src="u" fit="cover"
|
||||
:title="msg.imgNames && msg.imgNames[k]"
|
||||
:preview-src-list="msg.images" :initial-index="k" preview-teleported />
|
||||
</div>
|
||||
|
||||
<template v-if="msg.role === 'user'">
|
||||
<div v-if="msg.content" class="plain">{{ msg.content }}</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div v-if="msg.content" class="md" v-html="renderMarkdown(msg.content)"></div>
|
||||
<div v-else-if="!msg.error && !msg.reasoning" class="placeholder">{{ msg.streaming ? t('chat.thinking') : t('chat.emptyResp') }}</div>
|
||||
</template>
|
||||
<span v-if="msg.streaming && !msg.error" class="cursor">▍</span>
|
||||
|
||||
<div v-if="metaText(msg)" class="meta">{{ metaText(msg) }}</div>
|
||||
|
||||
<div v-if="msg.error" class="err">
|
||||
<el-alert :title="t('chat.youError', { msg: msg.error })" type="error" :closable="false" show-icon />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 输入区 -->
|
||||
<div class="composer">
|
||||
<div class="in">
|
||||
<!-- 第十三轮: 视觉对话 —— 附图(上传的图片在浏览器内压缩成 data URI;也支持粘 URL) -->
|
||||
<div v-if="pending.length" class="img-bar">
|
||||
<el-tag v-for="(im, i) in pending" :key="i" closable type="info" size="small" class="img-chip"
|
||||
:title="im.uri" @close="pending.splice(i, 1)">{{ im.name }}</el-tag>
|
||||
</div>
|
||||
<div v-if="showImg" class="img-row">
|
||||
<el-input v-model="imgUrl" size="small" :placeholder="t('chat.imgPh')" @keyup.enter="addImg">
|
||||
<template #append><el-button @click="addImg">{{ t('chat.imgAdd') }}</el-button></template>
|
||||
</el-input>
|
||||
</div>
|
||||
<!-- 带图但所选模型没有视觉能力时提前说清楚(否则上游要么忽略图片、要么报参数错误) -->
|
||||
<el-alert v-if="pending.length && !visionOk" type="warning" show-icon :closable="false" class="vision-warn"
|
||||
:title="t('chat.visionWarn', { model: params.model })">
|
||||
<template #default>
|
||||
<el-button v-if="firstVisionModel" size="small" text type="primary" @click="useVisionModel">
|
||||
{{ t('chat.useVision', { model: firstVisionModel }) }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-alert>
|
||||
|
||||
<el-input
|
||||
v-model="text"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
resize="none"
|
||||
:placeholder="t('chat.placeholder')"
|
||||
:disabled="streaming"
|
||||
@keydown="onKeydown"
|
||||
@focus="onInputFocus"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="bar">
|
||||
<el-tooltip :content="t('chat.imgUpload')" placement="top">
|
||||
<el-button text size="small" :disabled="streaming" @click="pickImages">
|
||||
<Icon name="clip" :size="16" />
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="t('chat.imgUrlBtn')" placement="top">
|
||||
<el-button text size="small" @click="showImg = !showImg">
|
||||
<Icon name="link" :size="16" />
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<input ref="fileEl" type="file" accept="image/*" multiple class="hide-file" @change="onFiles" />
|
||||
|
||||
<el-select v-model="params.model" class="model-sel" size="small" :disabled="streaming" filterable :placeholder="t('chat.routeGroup')">
|
||||
<el-option-group :label="t('chat.routeGroup')">
|
||||
<el-option v-for="r in routes" :key="r.id" :value="r.id" :label="chainLabel(r)">
|
||||
<span class="opt">
|
||||
<span>{{ chainLabel(r) }}</span>
|
||||
<Icon v-if="r.vision" name="eye" :size="13" />
|
||||
</span>
|
||||
</el-option>
|
||||
</el-option-group>
|
||||
<el-option-group :label="t('chat.textModels')">
|
||||
<el-option v-for="m in textModels" :key="m.id" :value="m.id" :label="modelLabel(m)">
|
||||
<span class="opt">
|
||||
<span>{{ modelLabel(m) }}</span>
|
||||
<Icon v-if="m.vision" name="eye" :size="13" />
|
||||
</span>
|
||||
</el-option>
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
|
||||
<span v-if="!streaming && !text.trim()" class="hint">{{ t('chat.waiting') }}</span>
|
||||
<span class="tok">{{ totalTokens }} Tokens</span>
|
||||
|
||||
<el-button v-if="!streaming" type="primary" size="small" :disabled="!text.trim() && !pending.length" @click="send">
|
||||
<Icon name="send" :size="14" />
|
||||
<span>{{ t('chat.send') }}</span>
|
||||
</el-button>
|
||||
<el-button v-else type="danger" plain size="small" @click="stop">
|
||||
<Icon name="stop" :size="14" />
|
||||
<span>{{ t('chat.stop') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- 参数抽屉:窄屏按屏宽百分比,避免 330px 在小屏上顶到边 -->
|
||||
<el-drawer v-model="paramsOpen" :title="t('chat.params')" :size="isMobile ? '86%' : '330px'" :close-on-click-modal="true">
|
||||
<div class="param">
|
||||
<div class="plabel">{{ t('chat.temp') }}</div>
|
||||
<el-slider v-model="params.temperature" :min="0" :max="2" :step="0.05" show-input />
|
||||
</div>
|
||||
<div class="param">
|
||||
<div class="plabel">{{ t('chat.topP') }}</div>
|
||||
<el-slider v-model="params.top_p" :min="0" :max="1" :step="0.05" show-input />
|
||||
</div>
|
||||
<div class="param">
|
||||
<div class="plabel">{{ t('chat.maxTokens') }}</div>
|
||||
<el-input-number v-model="params.max_tokens" :min="1" :max="200000" :placeholder="t('chat.phDefault')" clearable style="width: 100%" />
|
||||
</div>
|
||||
<div class="param">
|
||||
<div class="plabel">{{ t('chat.streaming') }}</div>
|
||||
<el-switch v-model="params.stream" :active-text="t('common.yes')" :inactive-text="t('common.no')" />
|
||||
</div>
|
||||
<div class="param">
|
||||
<div class="plabel">{{ t('chat.system') }}</div>
|
||||
<el-input v-model="params.system" type="textarea" :rows="4" resize="none" :placeholder="t('chat.phOptional')" />
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { api } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { renderMarkdown } from '../lib/markdown'
|
||||
import { streamChat, chatOnce, buildPayloadMessages, nextId, seekId, type ChatMessage } from '../lib/chat'
|
||||
import { getChatDefaults } from '../lib/settings'
|
||||
import { pullHistory, pushHistory } from '../lib/history'
|
||||
import { stamp } from '../lib/download'
|
||||
import { useIsMobile } from '../lib/ui'
|
||||
import { pickImage, PRESETS, assertBodyBudget } from '../lib/upload'
|
||||
|
||||
const { isMobile } = useIsMobile()
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
// ── 模型选项 ──
|
||||
const routes = ref<any[]>([])
|
||||
const textModels = ref<any[]>([])
|
||||
async function loadModels() {
|
||||
try {
|
||||
const j = await api('/v1/models')
|
||||
const data: any[] = j.data || []
|
||||
routes.value = data.filter((x) => x.type === 'route')
|
||||
textModels.value = data.filter((x) => x.type !== 'route')
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
ElMessage.error(t('chat.loadModelsErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
function chainLabel(r: any) {
|
||||
const chain = (r.models || []).join(' → ')
|
||||
// 括号样式(全角/半角)也交给 i18n:英文里用半角更自然
|
||||
return t('chat.chainLabel', { id: r.id, chain: chain || t('chat.emptyChain') })
|
||||
}
|
||||
|
||||
// ── 视觉能力(第十三轮)──
|
||||
// 网关 /v1/models 会回 vision 字段(Agnes 3.0 Flash = true,其余文本模型默认 false)。
|
||||
// 带图请求走路由别名时网关会把视觉模型排到链首;选了**不支持视觉的真实模型**时
|
||||
// 这里提前告警并提供一键切换,避免"发了图但模型根本没看"。
|
||||
const visionModels = computed(() =>
|
||||
textModels.value.filter((m) => m.vision).map((m) => m.id))
|
||||
const visionOk = computed(() => {
|
||||
const m = routes.value.find((r) => r.id === params.model)
|
||||
if (m) return !!m.vision || !!(m.models || []).some((id: string) => visionModels.value.includes(id))
|
||||
const t2 = textModels.value.find((x) => x.id === params.model)
|
||||
return !!t2?.vision
|
||||
})
|
||||
const firstVisionModel = computed(() => visionModels.value[0] || '')
|
||||
function useVisionModel() {
|
||||
if (firstVisionModel.value) params.model = firstVisionModel.value
|
||||
}
|
||||
function modelLabel(m: any) {
|
||||
return `${m.id} · ${m.provider_name}`
|
||||
}
|
||||
|
||||
// ── 参数与状态 ──
|
||||
const params = reactive({
|
||||
model: 'wjd',
|
||||
temperature: 0.7,
|
||||
top_p: 1,
|
||||
max_tokens: null as number | null,
|
||||
stream: true,
|
||||
system: '',
|
||||
})
|
||||
const paramsOpen = ref(false)
|
||||
const streaming = ref(false)
|
||||
const messages = ref<ChatMessage[]>([])
|
||||
const text = ref('')
|
||||
// 第十三轮: 视觉对话 —— 待发送消息附带的图片(上传的图片在浏览器内压成 data URI;也支持粘 URL)
|
||||
interface PendingImg { uri: string; name: string; thumb: string }
|
||||
const pending = ref<PendingImg[]>([])
|
||||
const showImg = ref(false)
|
||||
const imgUrl = ref('')
|
||||
const fileEl = ref<HTMLInputElement | null>(null)
|
||||
const MAX_CHAT_IMGS = 4
|
||||
|
||||
function pickImages() {
|
||||
fileEl.value?.click()
|
||||
}
|
||||
function resetFileInput() {
|
||||
if (fileEl.value) fileEl.value.value = ''
|
||||
}
|
||||
function basename(u: string): string {
|
||||
if (u.startsWith('data:')) return t('chat.uploadedImage')
|
||||
try { return decodeURIComponent((u.split('/').pop() || u)).slice(0, 24) } catch { return u.slice(0, 24) }
|
||||
}
|
||||
async function onFiles(ev: Event) {
|
||||
const input = ev.target as HTMLInputElement
|
||||
const files = Array.from(input.files || [])
|
||||
for (const f of files) {
|
||||
if (pending.value.length >= MAX_CHAT_IMGS) {
|
||||
ElMessage.warning(t('chat.imgMax', { n: MAX_CHAT_IMGS })); break
|
||||
}
|
||||
try {
|
||||
// 选图就不再只看 URL:浏览器内直接压缩成 data URI(上游实测可用)
|
||||
const m = await pickImage(f, PRESETS.chat)
|
||||
pending.value.push({ uri: m.uri, name: m.name, thumb: m.thumb })
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('chat.imgPickErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
resetFileInput()
|
||||
}
|
||||
function addImg() {
|
||||
const u = (imgUrl.value || '').trim()
|
||||
if (u && !pending.value.some((x) => x.uri === u)) {
|
||||
pending.value.push({ uri: u, name: basename(u), thumb: '' })
|
||||
}
|
||||
imgUrl.value = ''
|
||||
}
|
||||
const scrollEl = ref<any>(null)
|
||||
const userScrolled = ref(false)
|
||||
let abortCtrl: AbortController | null = null
|
||||
|
||||
const SKEY = 'gw_chat_history'
|
||||
// 写失败只提示一次,避免每次流式收尾都弹一遍
|
||||
let warned = false
|
||||
|
||||
async function persist() {
|
||||
// 第十三轮: 上传的图片是 data URI(几百 KB),而服务端对话条目上限 512KB —— 直接存会被
|
||||
// 截断成坏 base64(图片显示不出来、后续带图请求还会报错)。所以落历史时**只存缩略图**,
|
||||
// 原图仅保留在本次会话内存里(发送用的仍是原图)。URL 图片不受影响,原样保存。
|
||||
const slim = messages.value.map((m) => ({
|
||||
id: m.id, role: m.role, content: m.content,
|
||||
images: (m.images || []).map((u, i) => (u.startsWith('data:') && m.imgThumbs?.[i] ? m.imgThumbs[i] : u)),
|
||||
imgNames: m.imgNames || [],
|
||||
reasoning: m.reasoning || '', meta: m.meta || null, usage: m.usage || null,
|
||||
cost: m.cost ?? null, error: m.error || '',
|
||||
}))
|
||||
const state = { params: { ...params, model: params.model }, messages: slim }
|
||||
try {
|
||||
sessionStorage.setItem(SKEY, JSON.stringify(state)) // 本地留一份当缓存/离线兜底
|
||||
} catch { /* 配额满就只靠服务端 */ }
|
||||
// 对话原先只存 sessionStorage,关标签页即丢;现在同步到服务端(按账号)
|
||||
if (!(await pushHistory('chat', [{ id: 'current', ...state }]))) {
|
||||
if (!warned) { warned = true; ElMessage.warning(t('history.saveFail')) }
|
||||
}
|
||||
}
|
||||
function applyDefaults(defs: any) {
|
||||
if (defs.model) params.model = defs.model
|
||||
if (typeof defs.temperature === 'number') params.temperature = defs.temperature
|
||||
if (typeof defs.top_p === 'number') params.top_p = defs.top_p
|
||||
if (defs.max_tokens != null) params.max_tokens = defs.max_tokens
|
||||
if (typeof defs.stream === 'boolean') params.stream = defs.stream
|
||||
if (defs.system != null) params.system = defs.system
|
||||
}
|
||||
|
||||
function applyChat(j: any) {
|
||||
if (j?.params?.model) Object.assign(params, j.params)
|
||||
if (Array.isArray(j?.messages)) {
|
||||
let maxId = 0
|
||||
for (const m of j.messages) if (m.id > maxId) maxId = m.id
|
||||
seekId(maxId)
|
||||
messages.value = j.messages.map((m: any) => ({
|
||||
id: nextId(), role: m.role, content: m.content || '', images: m.images && m.images.length ? m.images : undefined,
|
||||
// 历史里的 data URI 已是被缩小的缩略图(见 persist),回填到 imgThumbs 让再次保存/展示一致
|
||||
imgNames: m.imgNames || [],
|
||||
imgThumbs: (m.images || []).map((u: string) => (u && u.startsWith('data:') ? u : '')),
|
||||
reasoning: m.reasoning || '', meta: m.meta || null,
|
||||
usage: m.usage || null, cost: m.cost ?? null, error: m.error || '',
|
||||
streaming: false,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
async function restore() {
|
||||
// M5: 无会话历史时,用设置页保存的默认参数做初始值。
|
||||
const defs = getChatDefaults()
|
||||
const remote = await pullHistory('chat')
|
||||
if (remote && remote.length) {
|
||||
applyChat(remote.find((x: any) => x.id === 'current') || remote[0])
|
||||
return
|
||||
}
|
||||
let raw: string | null = null
|
||||
try { raw = sessionStorage.getItem(SKEY) } catch { raw = null }
|
||||
if (!raw) { applyDefaults(defs); return }
|
||||
try {
|
||||
const j = JSON.parse(raw)
|
||||
applyChat(j)
|
||||
// 首次:把浏览器里的旧对话搬上服务端,之后就跟设备无关了
|
||||
if (remote) await pushHistory('chat', [{ id: 'current', ...j }])
|
||||
} catch { applyDefaults(defs) }
|
||||
}
|
||||
|
||||
const tokensText = (u: any) =>
|
||||
[u.prompt_tokens != null ? `↑${u.prompt_tokens}` : '', u.completion_tokens != null ? `↓${u.completion_tokens}` : '']
|
||||
.filter(Boolean).join(' ') || t('chat.totalTokens', { n: u.total_tokens ?? 0 })
|
||||
|
||||
function scrollToBottom() {
|
||||
if (userScrolled.value) return
|
||||
// 第十九轮:必须等 DOM 更新完再滚。watch 默认 flush:'pre',回调跑在渲染之前,
|
||||
// 读到的 scrollHeight 还是旧的 —— 打开长会话时会停在第 1 条(要一路往下拉)。
|
||||
nextTick(() => {
|
||||
const el = scrollEl.value
|
||||
if (el) el.scrollTop = el.scrollHeight
|
||||
})
|
||||
}
|
||||
function onScroll() {
|
||||
const el = scrollEl.value
|
||||
if (!el) return
|
||||
userScrolled.value = el.scrollHeight - el.scrollTop - el.clientHeight > 60
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
// 输入法组词中的回车**不算**「发送」:中文 IME 确认候选词、手机软键盘的「换行/完成」
|
||||
// 都会抛 Enter keydown,此前会把半截话直接发出去。
|
||||
// keyCode 229 = 老浏览器/安卓键盘没有 isComposing 时的等价信号。Shift+Enter 仍是换行。
|
||||
const composing = e.isComposing || e.keyCode === 229
|
||||
if (e.key === 'Enter' && !e.shiftKey && !composing) {
|
||||
e.preventDefault()
|
||||
send()
|
||||
}
|
||||
}
|
||||
|
||||
/** iOS 软键盘不会压缩 100dvh,输入框可能被键盘盖住:等键盘弹起后再滚一次。 */
|
||||
function onInputFocus() {
|
||||
setTimeout(() => {
|
||||
const el = document.activeElement as HTMLElement | null
|
||||
el?.scrollIntoView({ block: 'nearest' })
|
||||
}, 320)
|
||||
}
|
||||
|
||||
// ── 展示用:本条对话的时间 / 耗时 / token 合计 ──
|
||||
// 只在组件内记(stamps 不落历史、不改接口也不进会话存储),刷新后历史消息没有时间戳,
|
||||
// 对应字段就不显示,而不是编一个值。
|
||||
const stamps = ref<Record<number, { at: number; ms?: number }>>({})
|
||||
function markStart(id: number) { stamps.value[id] = { at: Date.now() } }
|
||||
function markEnd(id: number) {
|
||||
const s = stamps.value[id]
|
||||
if (s && s.ms == null) s.ms = Date.now() - s.at
|
||||
}
|
||||
const pad2 = (n: number) => String(n).padStart(2, '0')
|
||||
function fmtClock(ms: number) {
|
||||
const d = new Date(ms)
|
||||
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`
|
||||
}
|
||||
function fmtStamp(ms: number) {
|
||||
const d = new Date(ms)
|
||||
const now = new Date()
|
||||
const sameDay = d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate()
|
||||
return sameDay
|
||||
? `${pad2(d.getHours())}:${pad2(d.getMinutes())}`
|
||||
: `${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`
|
||||
}
|
||||
function metaText(m: ChatMessage): string {
|
||||
const s = stamps.value[m.id]
|
||||
const parts: string[] = []
|
||||
if (s) parts.push(fmtClock(s.at))
|
||||
if (m.role === 'assistant') {
|
||||
if (m.meta?.served) parts.push(m.meta.served)
|
||||
if (s && s.ms != null) parts.push((s.ms / 1000).toFixed(1) + 's')
|
||||
if (m.usage) parts.push(tokensText(m.usage))
|
||||
}
|
||||
return parts.join(' · ')
|
||||
}
|
||||
const lastAt = computed(() => {
|
||||
for (let i = messages.value.length - 1; i >= 0; i--) {
|
||||
const s = stamps.value[messages.value[i].id]
|
||||
if (s) return s.at
|
||||
}
|
||||
return 0
|
||||
})
|
||||
const convTitle = computed(() => {
|
||||
const u = messages.value.find((m) => m.role === 'user' && m.content.trim())
|
||||
const s = (u?.content || '').replace(/\s+/g, ' ').trim()
|
||||
return s ? (s.length > 18 ? s.slice(0, 18) + '…' : s) : t('chat.newChat')
|
||||
})
|
||||
// 与服务端 history/chat 里当前那条同 id(多会话尚未实现,列表暂时只有这一条)
|
||||
const activeConvId = ref('current')
|
||||
const conversations = computed(() => [{
|
||||
id: activeConvId.value,
|
||||
title: convTitle.value,
|
||||
n: messages.value.length,
|
||||
time: lastAt.value ? fmtStamp(lastAt.value) : t('common.none'),
|
||||
}])
|
||||
const totalTokens = computed(() => {
|
||||
let sum = 0
|
||||
let seen = false
|
||||
for (const m of messages.value) {
|
||||
const u = m.usage
|
||||
if (!u) continue
|
||||
const v = u.total_tokens ?? ((u.prompt_tokens || 0) + (u.completion_tokens || 0))
|
||||
if (typeof v === 'number') { sum += v; seen = true }
|
||||
}
|
||||
return seen ? String(sum) : '—'
|
||||
})
|
||||
const elapsedText = computed(() => {
|
||||
let ms = 0
|
||||
for (const m of messages.value) {
|
||||
const s = stamps.value[m.id]
|
||||
if (s && s.ms) ms += s.ms
|
||||
}
|
||||
return ms ? (ms / 1000).toFixed(1) + 's' : '—'
|
||||
})
|
||||
|
||||
// ── 发送/流式 ──
|
||||
function buildPayload() {
|
||||
const history = messages.value.map((m) => ({ role: m.role, content: m.content, images: m.images }))
|
||||
return {
|
||||
model: params.model,
|
||||
messages: buildPayloadMessages(params.system, history),
|
||||
temperature: params.temperature,
|
||||
top_p: params.top_p,
|
||||
max_tokens: params.max_tokens ?? undefined,
|
||||
stream: params.stream,
|
||||
}
|
||||
}
|
||||
|
||||
async function send() {
|
||||
const input = text.value.trim()
|
||||
if ((!input && !pending.value.length) || streaming.value) return
|
||||
const picked = pending.value.slice()
|
||||
// 整包体积兜底:素材(data URI)+ 正文必须落在网关请求体上限内,否则会拿 413
|
||||
try {
|
||||
assertBodyBudget(picked.map((p) => p.uri), input.length + 512)
|
||||
} catch (e: any) {
|
||||
ElMessage.error((e && e.message) || String(e))
|
||||
return
|
||||
}
|
||||
const userMsg: ChatMessage = {
|
||||
id: nextId(), role: 'user', content: input,
|
||||
images: picked.length ? picked.map((p) => p.uri) : undefined,
|
||||
imgNames: picked.length ? picked.map((p) => p.name) : undefined,
|
||||
imgThumbs: picked.length ? picked.map((p) => p.thumb || p.uri) : undefined,
|
||||
}
|
||||
markStart(userMsg.id)
|
||||
messages.value.push(userMsg)
|
||||
text.value = ''
|
||||
pending.value = []
|
||||
showImg.value = false
|
||||
imgUrl.value = ''
|
||||
userScrolled.value = false
|
||||
scrollToBottom()
|
||||
|
||||
if (params.stream) await runStream(input)
|
||||
else await runOnce(input)
|
||||
}
|
||||
|
||||
async function runOnce(input: string) {
|
||||
const reply: ChatMessage = { id: nextId(), role: 'assistant', content: '', streaming: true }
|
||||
markStart(reply.id)
|
||||
messages.value.push(reply)
|
||||
persist()
|
||||
try {
|
||||
const j = await chatOnce(buildPayload())
|
||||
if (j && j.choices && j.choices[0]) {
|
||||
reply.content = (j.choices[0].message && j.choices[0].message.content) || ''
|
||||
} else {
|
||||
reply.content = j?.content || ''
|
||||
}
|
||||
reply.usage = j?.usage || undefined
|
||||
reply.cost = j?.estimated_cost_cny ?? undefined
|
||||
if (j?.route || j?.provider) {
|
||||
reply.meta = {
|
||||
served: j.served_model || j.model || params.model,
|
||||
provider: j.provider_name || j.provider,
|
||||
requested: j.model || params.model,
|
||||
fallback: !!(j.route && j.route.fallback_used),
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
reply.error = e?.message || String(e)
|
||||
} finally {
|
||||
reply.streaming = false
|
||||
markEnd(reply.id)
|
||||
persist(); scrollToBottom()
|
||||
}
|
||||
}
|
||||
|
||||
async function runStream(_input: string) {
|
||||
const reply: ChatMessage = { id: nextId(), role: 'assistant', content: '', reasoning: '', streaming: true }
|
||||
markStart(reply.id)
|
||||
messages.value.push(reply)
|
||||
streaming.value = true
|
||||
abortCtrl = new AbortController()
|
||||
persist(); scrollToBottom()
|
||||
|
||||
const handle = (chunk: any) => {
|
||||
if (chunk.error) { reply.error = chunk.error; return }
|
||||
// 网关元信息帧(首次出现 served/provider 时记录)
|
||||
if (chunk.served_model || chunk.provider) {
|
||||
reply.meta = {
|
||||
served: chunk.served_model || chunk.model || params.model,
|
||||
provider: chunk.provider_name || chunk.provider,
|
||||
requested: chunk.model || params.model,
|
||||
fallback: !!(chunk.route && chunk.route.fallback_used),
|
||||
}
|
||||
}
|
||||
if (chunk.usage && !chunk.choices?.length) {
|
||||
reply.usage = chunk.usage
|
||||
if (chunk.estimated_cost_cny != null) reply.cost = chunk.estimated_cost_cny
|
||||
}
|
||||
const delta = chunk.choices && chunk.choices[0] && chunk.choices[0].delta
|
||||
if (delta) {
|
||||
if (delta.reasoning_content) reply.reasoning = (reply.reasoning || '') + delta.reasoning_content
|
||||
if (delta.content != null) reply.content += delta.content
|
||||
}
|
||||
scrollToBottom()
|
||||
}
|
||||
|
||||
const fin = () => { reply.streaming = false; streaming.value = false; markEnd(reply.id); persist(); scrollToBottom() }
|
||||
|
||||
try {
|
||||
await streamChat(buildPayload(), handle, abortCtrl.signal)
|
||||
} catch (e: any) {
|
||||
if (e && e.name === 'AbortError') {
|
||||
reply.error = reply.error || t('chat.stopped')
|
||||
} else {
|
||||
reply.error = e?.message || String(e)
|
||||
}
|
||||
} finally {
|
||||
fin()
|
||||
}
|
||||
}
|
||||
|
||||
function stop() {
|
||||
if (abortCtrl) abortCtrl.abort()
|
||||
}
|
||||
|
||||
function clearConversation() {
|
||||
messages.value = []
|
||||
persist()
|
||||
}
|
||||
|
||||
// ── 重跑 / 复制 / 导出(都走已有数据与已有接口,不新增接口也不改存储键)──
|
||||
const lastUser = computed(() => {
|
||||
for (let i = messages.value.length - 1; i >= 0; i--) {
|
||||
if (messages.value[i].role === 'user') return messages.value[i]
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
async function regenerate() {
|
||||
const u = lastUser.value
|
||||
if (!u || streaming.value) return
|
||||
// 丢掉最后一条用户消息之后的内容,再用同一段输入重跑(与 send() 同一条路径、同一份参数)
|
||||
const idx = messages.value.lastIndexOf(u)
|
||||
messages.value = messages.value.slice(0, idx)
|
||||
userScrolled.value = false
|
||||
scrollToBottom()
|
||||
if (params.stream) await runStream(u.content)
|
||||
else await runOnce(u.content)
|
||||
}
|
||||
|
||||
async function copyAll() {
|
||||
const body = messages.value.map((m) => `[${m.role}] ${m.content}`).join('\n\n')
|
||||
try {
|
||||
await navigator.clipboard.writeText(body)
|
||||
ElMessage.success(t('common.copyOk'))
|
||||
} catch { ElMessage.warning(t('common.copyFail')) }
|
||||
}
|
||||
|
||||
function exportConv() {
|
||||
const body = messages.value
|
||||
.map((m) => `## ${m.role}\n\n${m.content}${m.reasoning ? `\n\n<details>${t('chat.reasoningTag')}</details>\n\n${m.reasoning}` : ''}`)
|
||||
.join('\n\n')
|
||||
const href = URL.createObjectURL(new Blob([body], { type: 'text/markdown;charset=utf-8' }))
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = `chat-${stamp()}.md`
|
||||
a.style.display = 'none'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
// 立刻 revoke 会打断部分浏览器尚未开始的保存,延后回收
|
||||
setTimeout(() => URL.revokeObjectURL(href), 10_000)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
restore()
|
||||
loadModels()
|
||||
})
|
||||
onUnmounted(() => { if (abortCtrl) abortCtrl.abort() })
|
||||
|
||||
// 内容变化时自动滚动到底部(跟随流式输出)
|
||||
watch(messages, scrollToBottom, { deep: true })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* ── 两栏骨架 ── */
|
||||
/* 第十九轮:min-height:0 是关键 —— 不加它,flex/grid 子项的 min-height 默认取内容高度,
|
||||
里面的 .msgs(overflow-y:auto)就永远撑得开、滚不动,整页只能一路往下拉。 */
|
||||
.chat-main { min-width: 0; display: flex; flex-direction: column; gap: var(--gap); height: 100%; min-height: 0; }
|
||||
|
||||
/* ── 左栏 ── */
|
||||
.side-in { display: flex; flex-direction: column; gap: 8px; height: 100%; padding: 12px; }
|
||||
.new-conv { width: 100%; }
|
||||
.conv-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; min-height: 0; }
|
||||
.conv { cursor: pointer; }
|
||||
.conv-info .nm { width: auto; color: var(--muted); }
|
||||
.side-ops { margin-top: auto; display: flex; gap: 7px; }
|
||||
.side-ops .op { flex: 1; }
|
||||
|
||||
/* ── 顶部参数胶囊 ── */
|
||||
.chat-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.chat-top .chip-sel { cursor: pointer; }
|
||||
.conv-sel { width: 170px; flex: none; }
|
||||
.stream-badge { font-size: 12.5px; color: var(--warn); }
|
||||
.vision-hint { margin-left: auto; font-size: 12px; color: var(--muted); }
|
||||
.vision-hint.off { color: var(--warn); }
|
||||
|
||||
/* ── 消息卡 ── */
|
||||
.chat-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
||||
.chat-card .msgs { flex: 1; min-height: 0; }
|
||||
.empty { margin: auto; text-align: center; color: var(--muted); }
|
||||
.empty-t { margin-top: 10px; font-size: 13px; }
|
||||
|
||||
.resp-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
|
||||
.meta-txt { color: var(--muted); font-size: 12px; }
|
||||
.reasoning { margin-bottom: 6px; border: 1px dashed var(--warn); border-radius: 6px; }
|
||||
.reasoning :deep(.el-collapse-item__header) { font-size: 13px; color: var(--warn); background: transparent; }
|
||||
.reasoning-md {
|
||||
white-space: pre-wrap; color: var(--muted); font-size: 12.5px;
|
||||
max-height: 240px; overflow-y: auto; background: var(--surface); padding: 6px; border-radius: 4px;
|
||||
}
|
||||
.attach :deep(.el-image) {
|
||||
width: 46px; height: 46px; border-radius: 8px; overflow: hidden;
|
||||
border: 1px solid var(--line); flex: none;
|
||||
}
|
||||
.plain { white-space: pre-wrap; }
|
||||
.placeholder { color: var(--muted-2); font-style: italic; }
|
||||
.cursor { display: inline-block; width: 2px; height: 16px; background: currentColor; vertical-align: text-bottom; animation: blink .8s infinite; }
|
||||
@keyframes blink { 50% { opacity: 0; } }
|
||||
.err { margin-top: 6px; }
|
||||
|
||||
.md :deep(pre) { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow-x: auto; font-size: 13px; }
|
||||
.md :deep(code) { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
||||
.md :deep(h1), .md :deep(h2), .md :deep(h3) { margin: 8px 0; }
|
||||
.md :deep(table) { border-collapse: collapse; }
|
||||
.md :deep(td), .md :deep(th) { border: 1px solid var(--line); padding: 4px 8px; }
|
||||
|
||||
/* ── 输入区 ── */
|
||||
.composer .in { padding-bottom: 8px; }
|
||||
.composer .bar { flex-wrap: wrap; }
|
||||
.img-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
|
||||
.img-row { margin-bottom: 6px; }
|
||||
.img-chip { max-width: 180px; }
|
||||
.hide-file { display: none; }
|
||||
.vision-warn { margin-bottom: 6px; }
|
||||
.model-sel { flex: 1 1 150px; min-width: 110px; max-width: 230px; }
|
||||
.opt { display: flex; align-items: center; gap: 6px; }
|
||||
.tok { margin-left: auto; font-size: 11.5px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ── 参数抽屉 ── */
|
||||
.param { margin-bottom: 18px; }
|
||||
.plabel { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
|
||||
|
||||
/* ── 窄屏 ── */
|
||||
@media (max-width: 768px) {
|
||||
.vision-hint { margin-left: 0; width: 100%; }
|
||||
.model-sel { max-width: none; }
|
||||
/* 底部预留 iPhone 安全区(Home 指示条),否则「发送」按钮会被手势条压住一半 */
|
||||
.composer { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,293 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="mb" />
|
||||
|
||||
<!-- KPI:全部来自 /metrics + /health 的真实计数,没有可得的时序就不画趋势条 -->
|
||||
<div class="kpis">
|
||||
<div v-for="c in cards" :key="c.k" class="kpi">
|
||||
<div class="k">{{ c.k }}</div>
|
||||
<div class="v">{{ c.v }}</div>
|
||||
<div class="f"><span class="muted-2">{{ c.note }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid2">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('dashboard.latency') }}</b>
|
||||
<span class="sub">P50 / P95</span>
|
||||
<div class="legend">
|
||||
<span><i style="background: var(--chart-a)" />P50</span>
|
||||
<span><i style="background: var(--chart-b)" />P95</span>
|
||||
</div>
|
||||
</div>
|
||||
<EChart :option="latOpt" height="228px" />
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('dashboard.providerStatus') }}</b>
|
||||
<span class="sub">{{ t('dashboard.circuit') }}</span>
|
||||
</div>
|
||||
<div class="pv">
|
||||
<div v-for="p in providerRows" :key="p.name" class="pv-i">
|
||||
<span class="nm">{{ p.name }}</span>
|
||||
<span class="meter" style="width: 70px"><i :style="{ width: p.ratio + '%' }" /></span>
|
||||
<span class="st"><span class="pill" :class="p.cls">{{ p.text }}</span></span>
|
||||
</div>
|
||||
<div v-if="!providerRows.length" class="hint">{{ t('dashboard.noData') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="sep" />
|
||||
|
||||
<div class="card-h" style="margin-bottom: 8px">
|
||||
<b>{{ t('dashboard.routeAlias') }}</b>
|
||||
<span class="sub">{{ t('dashboard.routeChain') }}</span>
|
||||
</div>
|
||||
<div class="pv" style="gap: 7px">
|
||||
<div v-for="(r, i) in routeRows" :key="r.name" class="pv-i" style="font-size: 12px">
|
||||
<span class="pill mute">{{ i + 1 }}</span>
|
||||
<span class="code flex-1">{{ r.name }}</span>
|
||||
<span class="st muted-2 nowrap">{{ r.short }}</span>
|
||||
</div>
|
||||
<div v-if="!routeRows.length" class="hint">{{ t('dashboard.noData') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid3">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('dashboard.modelCalls') }}</b>
|
||||
<span class="sub">{{ t('dashboard.live') }}</span>
|
||||
</div>
|
||||
<el-table :data="callRows" size="small" v-loading="loading" :show-header="true">
|
||||
<el-table-column prop="model" :label="t('dashboard.colModel')" min-width="170">
|
||||
<template #default="{ row }">
|
||||
<span class="code">{{ row.model }}</span>
|
||||
<div class="hint">{{ row.provider }}</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="calls" :label="t('dashboard.colCalls')" width="80" />
|
||||
<el-table-column prop="latency" :label="t('dashboard.colLatency')" width="96" />
|
||||
<el-table-column :label="t('dashboard.colRate')" width="92">
|
||||
<template #default="{ row }">
|
||||
<span class="pill" :class="row.rateCls">{{ row.rate }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-if="!callRows.length && !loading" class="hint" style="padding: 8px 0">{{ t('dashboard.noModels') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('dashboard.provShare') }}</b>
|
||||
<span class="sub">{{ t('dashboard.share') }}</span>
|
||||
</div>
|
||||
<EChart :option="provOpt" height="228px" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card about-card">
|
||||
<div class="about-line">
|
||||
<b>{{ t('dashboard.gatewayInfo') }} · v{{ health.version || '-' }}</b>
|
||||
<span>{{ t('dashboard.running') }}</span>
|
||||
<span>{{ t('dashboard.uptime') }} {{ uptimeText }}</span>
|
||||
<span>{{ t('dashboard.inflight') }} {{ health.in_flight ?? '-' }} / {{ health.in_flight_peak ?? '-' }}</span>
|
||||
<span>{{ t('dashboard.fallback') }} {{ health.fallback_total ?? 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { api } from '../api'
|
||||
import EChart from '../components/EChart.vue'
|
||||
import { categoryAxis, chartTheme, emptyTip, grid, legend, pieLabel, pieLabelLine, pieRadius, pieCenter, pieData, valueAxis } from '../lib/charts'
|
||||
import type { EChartsCoreOption } from '../lib/echarts'
|
||||
import { useTheme } from '../lib/theme'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const { resolved } = useTheme() // 主题变化时重算图表配色
|
||||
const health = ref<any>({})
|
||||
const metrics = ref<any>({})
|
||||
const models = ref<any>({})
|
||||
const routes = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const err = ref('')
|
||||
|
||||
const textModels = ref<Record<string, string>>({})
|
||||
|
||||
function sum(list: any[], key: string): number {
|
||||
// 熔断返回的是 ProviderStat 对象,键缺失时按 0 处理
|
||||
return list.reduce((acc, x) => acc + (Number(x && x[key]) || 0), 0)
|
||||
}
|
||||
const calls = computed(() => metrics.value.calls || {})
|
||||
const totalOk = computed(() => sum(Object.values(calls.value) as any[], 'ok'))
|
||||
const totalFail = computed(() => sum(Object.values(calls.value) as any[], 'fail'))
|
||||
const total = computed(() => totalOk.value + totalFail.value)
|
||||
const rate = computed(() => (total.value ? (totalOk.value / total.value) * 100 : 100))
|
||||
|
||||
const latency = computed<any>(() => metrics.value.latency || {})
|
||||
const avgP50 = computed(() => {
|
||||
const vals = Object.values(latency.value) as any[]
|
||||
if (!vals.length) return 0
|
||||
return vals.reduce((a, x) => a + (Number(x?.p50) || 0), 0) / vals.length
|
||||
})
|
||||
const maxP95 = computed(() => {
|
||||
const vals = Object.values(latency.value) as any[]
|
||||
return vals.reduce((a, x) => Math.max(a, Number(x?.p95) || 0), 0)
|
||||
})
|
||||
|
||||
const cards = computed(() => {
|
||||
void resolved.value // 触发依赖,主题切换时 KPI 也重算(颜色走 CSS,无需改值)
|
||||
return [
|
||||
{ k: t('dashboard.requests'), v: total.value, note: t('dashboard.noteOkFail', { ok: totalOk.value, fail: totalFail.value }) },
|
||||
{ k: t('dashboard.successRate'), v: rate.value.toFixed(1) + '%', note: t('dashboard.noteFail', { n: totalFail.value }) },
|
||||
{ k: t('dashboard.avgLatency'), v: avgP50.value.toFixed(2) + 's', note: t('dashboard.noteP95', { v: maxP95.value.toFixed(2) }) },
|
||||
{ k: t('dashboard.fallbackShort'), v: health.value.fallback_total ?? 0, note: t('dashboard.noteInflight', { n: health.value.in_flight ?? 0 }) },
|
||||
]
|
||||
})
|
||||
|
||||
const providerRows = computed(() => {
|
||||
const p = health.value.providers || {}
|
||||
return Object.keys(p).map((k) => {
|
||||
const c = String(p[k].circuit || '').toUpperCase()
|
||||
const cls = c === 'CLOSED' ? 'ok' : c === 'HALF_OPEN' ? 'warn' : c === 'OPEN' ? 'err' : 'mute'
|
||||
const calls2 = metrics.value?.providers?.[k] || {}
|
||||
const ok = Number(calls2.ok) || 0
|
||||
const fail = Number(calls2.fail) || 0
|
||||
const tot = ok + fail
|
||||
return {
|
||||
name: p[k].name,
|
||||
cls,
|
||||
text: t(`dashboard.circ_${String(p[k].circuit || '').toLowerCase() || ''}`),
|
||||
ratio: tot ? Math.max(6, Math.round((ok / tot) * 100)) : 6,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const routeRows = computed(() => {
|
||||
const m = models.value
|
||||
return routes.value.map((r: any) => {
|
||||
const chain: string[] = (m[r.id] || []).map((x: any) => (typeof x === 'string' ? x : x.id || x.name))
|
||||
return { name: r.id, short: chain.length ? t('models.chainCount', { n: chain.length }) : '—' }
|
||||
})
|
||||
})
|
||||
|
||||
const callRows = computed(() => {
|
||||
const c = calls.value
|
||||
return Object.keys(c)
|
||||
.map((m) => {
|
||||
const ok = Number(c[m]?.ok) || 0
|
||||
const fail = Number(c[m]?.fail) || 0
|
||||
const tot = ok + fail
|
||||
const r = tot ? (ok / tot) * 100 : 100
|
||||
const p50 = latency.value[m]?.p50
|
||||
return {
|
||||
model: m,
|
||||
provider: textModels.value[m] || '—',
|
||||
calls: tot,
|
||||
latency: p50 != null ? Number(p50).toFixed(2) + 's' : '—',
|
||||
rate: r.toFixed(1) + '%',
|
||||
rateCls: r >= 99 ? 'ok' : r >= 90 ? 'warn' : 'err',
|
||||
_tot: tot,
|
||||
}
|
||||
})
|
||||
.sort((a, b) => b._tot - a._tot)
|
||||
.slice(0, 8)
|
||||
})
|
||||
|
||||
const latOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const c = chartTheme()
|
||||
const l = latency.value
|
||||
const ms = Object.keys(l).slice(0, 10)
|
||||
const p50 = ms.map((m) => l[m]?.p50 ?? 0)
|
||||
const p95 = ms.map((m) => l[m]?.p95 ?? 0)
|
||||
return {
|
||||
tooltip: { trigger: 'axis', valueFormatter: (v: any) => `${typeof v === 'number' ? v.toFixed(3) : v}s` },
|
||||
legend: legend(['P50', 'P95']),
|
||||
grid,
|
||||
graphic: emptyTip([p50, p95], t('dashboard.noData')),
|
||||
xAxis: categoryAxis(ms),
|
||||
yAxis: valueAxis('s'),
|
||||
series: [
|
||||
{ name: 'P50', type: 'bar', data: p50, itemStyle: { color: c.a, borderRadius: [4, 4, 0, 0] } },
|
||||
{ name: 'P95', type: 'bar', data: p95, itemStyle: { color: c.b, borderRadius: [4, 4, 0, 0] } },
|
||||
],
|
||||
} as EChartsCoreOption
|
||||
})
|
||||
|
||||
const provOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const p = metrics.value.providers || {}
|
||||
const items = Object.keys(p).map((k) => ({ name: k, value: p[k]?.ok || 0 })).filter((x) => x.value > 0)
|
||||
return {
|
||||
tooltip: { trigger: 'item' },
|
||||
series: [{
|
||||
type: 'pie', radius: pieRadius, center: pieCenter, minAngle: 6, labelLine: pieLabelLine,
|
||||
data: pieData(items, t('dashboard.noData')), label: pieLabel(), itemStyle: { borderRadius: 4 },
|
||||
}],
|
||||
}
|
||||
})
|
||||
|
||||
// 运行时间实时跳动:/health 是 5s 一拉,直接用返回值会「5 秒跳一格」。
|
||||
const uptimeAt = ref(Date.now())
|
||||
const nowTick = ref(Date.now())
|
||||
const uptimeText = computed(() => {
|
||||
const u = health.value.uptime_seconds
|
||||
if (u == null) return '-'
|
||||
void nowTick.value
|
||||
const live = u + Math.max(0, (nowTick.value - uptimeAt.value) / 1000)
|
||||
const h = Math.floor(live / 3600), m = Math.floor((live % 3600) / 60), s = Math.floor(live % 60)
|
||||
return `${h}h ${m}m ${s}s`
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
err.value = ''
|
||||
try {
|
||||
health.value = await api('/health')
|
||||
uptimeAt.value = Date.now()
|
||||
try { metrics.value = await api('/metrics') } catch { /* 指标可选 */ }
|
||||
try {
|
||||
const um = await api('/v1/models')
|
||||
const data = um.data || []
|
||||
routes.value = data.filter((x: any) => x.type === 'route')
|
||||
const map: Record<string, string> = {}
|
||||
for (const x of data) if (x.type !== 'route') map[x.id] = x.provider_name || ''
|
||||
textModels.value = map
|
||||
const list = data.filter((x: any) => x.type === 'route')
|
||||
const m: Record<string, any> = {}
|
||||
for (const r of list) m[r.id] = r.models || []
|
||||
models.value = m
|
||||
} catch { /* 模型列表可选 */ }
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
err.value = t('settings.loadErr') + ': ' + ((e && e.message) || String(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
let tickTimer: any = null
|
||||
onMounted(() => {
|
||||
load()
|
||||
timer = setInterval(load, 8000)
|
||||
tickTimer = setInterval(() => { nowTick.value = Date.now() }, 1000)
|
||||
})
|
||||
onUnmounted(() => { clearInterval(timer); clearInterval(tickTimer) })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.kpi .v { color: var(--text); }
|
||||
.sep { height: 1px; background: var(--line-2); margin: 12px 0 10px; }
|
||||
.about-card { margin-top: var(--gap); padding: 12px 16px; }
|
||||
.about-line b { color: var(--text); }
|
||||
</style>
|
||||
@@ -0,0 +1,251 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<!-- 第二十二轮:意见反馈(普通账号 / 管理员都能提)。
|
||||
左「写」右「我提交过的」在桌面并排,窄屏自动上下堆叠。 -->
|
||||
<div class="fb-wrap">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('nav.menufeedback') }}</b>
|
||||
<span class="sub">{{ t('feedback.imagesHint', { n: FEEDBACK_MAX_IMAGES }) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>{{ t('feedback.write') }}</label>
|
||||
<el-input
|
||||
v-model="content"
|
||||
type="textarea"
|
||||
:rows="7"
|
||||
:maxlength="2000"
|
||||
show-word-limit
|
||||
resize="none"
|
||||
:placeholder="t('feedback.placeholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="fb-picks">
|
||||
<div v-for="(m, i) in picks" :key="i" class="fb-pick">
|
||||
<img :src="m.thumb || m.uri" :alt="m.name" />
|
||||
<button class="fb-del" type="button" :title="t('feedback.remove')" @click="remove(i)">
|
||||
<Icon name="x" :size="12" />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
v-if="picks.length < FEEDBACK_MAX_IMAGES"
|
||||
class="fb-add"
|
||||
type="button"
|
||||
:title="t('feedback.attach')"
|
||||
@click="fileEl?.click()"
|
||||
>
|
||||
<Icon name="plus" :size="18" />
|
||||
<span>{{ t('feedback.attach') }}</span>
|
||||
</button>
|
||||
<input ref="fileEl" class="fb-file" type="file" accept="image/*" multiple @change="onPick" />
|
||||
</div>
|
||||
|
||||
<div class="fb-actions">
|
||||
<el-button type="primary" :loading="sending" :disabled="!content.trim()" @click="submit">
|
||||
{{ t('feedback.submit') }}
|
||||
</el-button>
|
||||
<span v-if="picks.length" class="hint">{{ t('inbox.imgCount', { n: picks.length }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('feedback.mine') }}</b>
|
||||
<span class="sub">{{ t('feedback.mineSub') }}</span>
|
||||
<div class="pager">
|
||||
<el-button size="small" text :disabled="loading" @click="load()">
|
||||
<Icon name="refresh" :size="13" />
|
||||
<span>{{ t('common.refresh') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="fb-filter">
|
||||
<el-select v-model="mineStatus" size="small" class="sel-mine">
|
||||
<el-option :label="t('feedback.statusAll')" value="" />
|
||||
<el-option v-for="st in FEEDBACK_STATUSES" :key="st" :value="st" :label="t(`fbStatus.${st}`)" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<div v-if="!mineView.length" class="hint">{{ t('feedback.empty') }}</div>
|
||||
<div v-else class="fb-list">
|
||||
<div v-for="it in mineView" :key="it.id" class="fb-item">
|
||||
<div class="fb-meta">
|
||||
<span class="ts">{{ fmtTs(it.created) }}</span>
|
||||
<!-- 处理进度:提交人看得到,管理员在「用户反馈」里推进 -->
|
||||
<span class="badge" :class="FEEDBACK_STATUS_CLASS[it.status] || 'm'">
|
||||
{{ t(`fbStatus.${it.status}`) }}
|
||||
</span>
|
||||
<span v-if="it.images?.length" class="pill mute">{{ t('inbox.imgCount', { n: it.images.length }) }}</span>
|
||||
<span v-if="it.status === 'pending'" class="spacer" />
|
||||
<!-- 只有还停在「待处理」的单子能撤:管理员一动就不给了(服务端也把着关) -->
|
||||
<el-button
|
||||
v-if="it.status === 'pending'"
|
||||
size="small" text type="danger"
|
||||
:loading="revoking === it.id"
|
||||
@click="revoke(it)"
|
||||
>{{ t('feedback.revoke') }}</el-button>
|
||||
</div>
|
||||
<div class="fb-text">{{ it.content }}</div>
|
||||
<FeedbackImages :item="it" />
|
||||
<!-- 处理记录:提交 + 管理员的每一次动作(含说明与是谁处理的) -->
|
||||
<FeedbackTimeline :item="it" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import FeedbackImages from '../components/FeedbackImages.vue'
|
||||
import FeedbackTimeline from '../components/FeedbackTimeline.vue'
|
||||
import {
|
||||
FEEDBACK_MAX_IMAGES, FEEDBACK_STATUSES, FEEDBACK_STATUS_CLASS, myFeedback, pickFeedbackImage,
|
||||
submitFeedback, withdrawFeedback, type FeedbackItem,
|
||||
} from '../lib/feedback'
|
||||
import type { PickedMedia } from '../lib/upload'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const content = ref('')
|
||||
const picks = ref<PickedMedia[]>([])
|
||||
const mine = ref<FeedbackItem[]>([])
|
||||
const sending = ref(false)
|
||||
const loading = ref(false)
|
||||
const mineStatus = ref('') // 「我提交过的」状态过滤:''=全部
|
||||
const mineView = computed(() =>
|
||||
mineStatus.value ? mine.value.filter((it) => it.status === mineStatus.value) : mine.value,
|
||||
)
|
||||
const revoking = ref('') // 正在撤回的那条 id(按钮 loading 用)
|
||||
const fileEl = ref<HTMLInputElement | null>(null)
|
||||
|
||||
function fmtTs(ts: number): string {
|
||||
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())}`
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
mine.value = await myFeedback()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onPick(ev: Event) {
|
||||
const el = ev.target as HTMLInputElement
|
||||
const files = Array.from(el.files || [])
|
||||
el.value = '' // 先清空:同一个文件再选一次也要能触发 change
|
||||
for (const f of files) {
|
||||
if (picks.value.length >= FEEDBACK_MAX_IMAGES) {
|
||||
ElMessage.warning(t('feedback.imagesHint', { n: FEEDBACK_MAX_IMAGES }))
|
||||
break
|
||||
}
|
||||
try {
|
||||
// pickImage 内部已生成缩略图(256px,列表 84px 显示够用),随包一起上送:
|
||||
// 服务端 JSON 只存它,列表页因此不用再逐张取原图。
|
||||
picks.value.push(await pickFeedbackImage(f))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function remove(i: number) {
|
||||
picks.value.splice(i, 1)
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!content.value.trim()) {
|
||||
ElMessage.warning(t('feedback.needContent'))
|
||||
return
|
||||
}
|
||||
sending.value = true
|
||||
try {
|
||||
await submitFeedback({ content: content.value, images: picks.value })
|
||||
content.value = ''
|
||||
picks.value = []
|
||||
ElMessage.success(t('feedback.submitted'))
|
||||
await load()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 撤回=真删,所以必须二次确认(与图像「清空历史」同一条规矩)。
|
||||
// 前端只在 pending 时给按钮,但服务端才是权威:管理员可能刚好在你点开确认框时动手,
|
||||
// 那种情况下 DELETE 会回 400,这里把服务端的话直接展示出来,别假装成功。
|
||||
async function revoke(it: FeedbackItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('feedback.revokeBody', { n: it.content.slice(0, 40) }), t('feedback.revokeTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('feedback.revoke'),
|
||||
cancelButtonText: t('common.cancel'),
|
||||
})
|
||||
} catch { return }
|
||||
revoking.value = it.id
|
||||
try {
|
||||
await withdrawFeedback(it.id)
|
||||
mine.value = mine.value.filter((x) => x.id !== it.id)
|
||||
ElMessage.success(t('feedback.revoked'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
await load() // 状态可能已被管理员改掉,拉一次以真实状态为准
|
||||
} finally {
|
||||
revoking.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fb-wrap { display: grid; grid-template-columns: 1.15fr 1fr; gap: var(--gap); align-items: start; }
|
||||
@media (max-width: 900px) { .fb-wrap { grid-template-columns: 1fr; } }
|
||||
.fb-picks { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
|
||||
.fb-pick { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
|
||||
.fb-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.fb-del {
|
||||
position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0;
|
||||
display: grid; place-items: center; border: 0; border-radius: 7px; cursor: pointer;
|
||||
background: rgba(0, 0, 0, .55); color: #fff;
|
||||
}
|
||||
.fb-add {
|
||||
width: 84px; height: 84px; border: 1px dashed var(--line); border-radius: 10px;
|
||||
background: var(--surface-2); color: var(--muted); cursor: pointer;
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
|
||||
font-size: 11px; padding: 0 4px; text-align: center;
|
||||
}
|
||||
.fb-add:hover { border-color: var(--primary); color: var(--primary); }
|
||||
.fb-file { display: none; }
|
||||
.fb-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
|
||||
.fb-list { display: flex; flex-direction: column; }
|
||||
.fb-item {
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.fb-item:last-child { margin-bottom: 0; }
|
||||
.fb-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.fb-meta .spacer { flex: 1; }
|
||||
.fb-meta .ts { font-size: 11.5px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
|
||||
.fb-filter { display: flex; margin: 2px 0 6px; }
|
||||
.sel-mine { width: 128px; }
|
||||
.fb-text { margin-top: 6px; font-size: 12.5px; line-height: 1.62; white-space: pre-wrap; word-break: break-word; }
|
||||
</style>
|
||||
@@ -0,0 +1,264 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<!-- 第二十二轮:用户反馈(admin 专属)—— 全部账号提交的意见,含图片。 -->
|
||||
<div class="filters">
|
||||
<el-select v-model="account" :placeholder="t('inbox.account')" clearable size="small" class="sel-acct">
|
||||
<el-option :label="t('inbox.all')" value="" />
|
||||
<el-option v-for="a in accounts" :key="a" :value="a" :label="a" />
|
||||
</el-select>
|
||||
<el-select v-model="status" :placeholder="t('inbox.status')" clearable size="small" class="sel-st">
|
||||
<el-option :label="t('inbox.allStatus')" value="" />
|
||||
<el-option v-for="s in FEEDBACK_STATUSES" :key="s" :value="s" :label="t(`fbStatus.${s}`)" />
|
||||
</el-select>
|
||||
<el-select v-model="arch" size="small" class="sel-arch">
|
||||
<el-option :label="t('inbox.archActive')" value="active" />
|
||||
<el-option :label="t('inbox.archOnly')" value="arch" />
|
||||
<el-option :label="t('inbox.archAll')" value="" />
|
||||
</el-select>
|
||||
<el-input v-model="kw" size="small" :placeholder="t('inbox.kw')" clearable class="kw-in">
|
||||
<template #append><el-button @click="apply">{{ t('common.search') }}</el-button></template>
|
||||
</el-input>
|
||||
<span class="spacer" />
|
||||
<el-button v-if="filtered.length !== items.length" size="small" text @click="clear">{{ t('logs.clearFilter') }}</el-button>
|
||||
<el-button size="small" :disabled="loading" @click="load()">
|
||||
<Icon name="refresh" :size="13" />
|
||||
<span>{{ t('common.refresh') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('nav.menufeedbackinbox') }}</b>
|
||||
<span class="sub">{{ t('inbox.count', { n: filtered.length }) }}</span>
|
||||
<div class="pager">
|
||||
<span v-if="filtered.length > PAGE_SIZE" class="pg" :class="{ dis: page <= 1 }" @click="go(page - 1)">
|
||||
<Icon name="chev" :size="12" class="flip" />
|
||||
</span>
|
||||
<span v-if="filtered.length > PAGE_SIZE" class="hint">{{ page }} / {{ pages }}</span>
|
||||
<span v-if="filtered.length > PAGE_SIZE" class="pg" :class="{ dis: page >= pages }" @click="go(page + 1)">
|
||||
<Icon name="chev" :size="12" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-loading="loading" class="fb-list">
|
||||
<div v-if="!filtered.length" class="hint">
|
||||
<span>{{ items.length ? t('inbox.emptyFiltered', { n: items.length }) : t('inbox.empty') }}</span>
|
||||
<el-button v-if="items.length" size="small" text @click="clear">{{ t('logs.clearFilter') }}</el-button>
|
||||
</div>
|
||||
|
||||
<div v-for="it in paged" :key="it.id" class="fb-item">
|
||||
<div class="fb-meta">
|
||||
<span class="ts">{{ fmtTs(it.created) }}</span>
|
||||
<span class="badge m">{{ it.account }}</span>
|
||||
<span class="badge" :class="FEEDBACK_STATUS_CLASS[it.status] || 'm'">{{ t(`fbStatus.${it.status}`) }}</span>
|
||||
<span v-if="it.images?.length" class="pill mute">
|
||||
<Icon name="img" :size="11" />
|
||||
{{ t('inbox.imgCount', { n: it.images.length }) }}
|
||||
</span>
|
||||
<span v-if="it.archived" class="badge m">{{ t('inbox.archived') }}</span>
|
||||
<span class="spacer" />
|
||||
<el-button size="small" @click="openHandle(it)">{{ t('inbox.handle') }}</el-button>
|
||||
<el-button size="small" text :loading="busy === it.id" @click="toggleArchive(it)">
|
||||
{{ it.archived ? t('inbox.unarchive') : t('inbox.archive') }}
|
||||
</el-button>
|
||||
<el-button size="small" text type="danger" @click="remove(it)">{{ t('inbox.delete') }}</el-button>
|
||||
</div>
|
||||
<div class="fb-text">{{ it.content }}</div>
|
||||
<FeedbackImages :item="it" />
|
||||
<!-- 处理记录:谁在什么时候把它推到哪一档、留了什么说明,逐条可查 -->
|
||||
<FeedbackTimeline :item="it" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 处理:改进度 + 给提交人留一句话(提交人在「我提交过的」里看到) -->
|
||||
<el-dialog v-model="handleShow" :title="t('inbox.dialogTitle')" width="min(520px, 92vw)">
|
||||
<div class="field">
|
||||
<label>{{ t('inbox.status') }}</label>
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio-button v-for="s in FEEDBACK_STATUSES" :key="s" :value="s">
|
||||
{{ t(`fbStatus.${s}`) }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<div class="field mt">
|
||||
<label>{{ t('inbox.noteLabel') }}</label>
|
||||
<el-input
|
||||
v-model="form.note"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:maxlength="500"
|
||||
show-word-limit
|
||||
resize="none"
|
||||
:placeholder="t('inbox.notePlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="handleShow = false">{{ t('common.cancel') }}</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="save">{{ t('inbox.save') }}</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import FeedbackImages from '../components/FeedbackImages.vue'
|
||||
import FeedbackTimeline from '../components/FeedbackTimeline.vue'
|
||||
import { allFeedback, updateFeedback, archiveFeedback, adminDeleteFeedback, FEEDBACK_STATUSES, FEEDBACK_STATUS_CLASS, type FeedbackItem } from '../lib/feedback'
|
||||
|
||||
const { t } = useI18n()
|
||||
const PAGE_SIZE = 10
|
||||
|
||||
const items = ref<FeedbackItem[]>([])
|
||||
const loading = ref(false)
|
||||
const account = ref('')
|
||||
const status = ref('')
|
||||
const kw = ref('')
|
||||
const applied = ref('')
|
||||
const page = ref(1)
|
||||
const arch = ref<'active' | 'arch' | ''>('active')
|
||||
const busy = ref('')
|
||||
|
||||
// 处理弹窗
|
||||
const handleShow = ref(false)
|
||||
const saving = ref(false)
|
||||
const form = ref<{ id: string; status: FeedbackItem['status']; note: string }>({ id: '', status: 'pending', note: '' })
|
||||
|
||||
function openHandle(it: FeedbackItem) {
|
||||
form.value = { id: it.id, status: it.status, note: it.note || '' }
|
||||
handleShow.value = true
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving.value = true
|
||||
try {
|
||||
const updated = await updateFeedback(form.value.id, form.value.status, form.value.note)
|
||||
// 就地替换:不整表重拉,筛选/页码/滚动位置都不动
|
||||
const i = items.value.findIndex((x) => x.id === updated.id)
|
||||
if (i >= 0) items.value[i] = updated
|
||||
handleShow.value = false
|
||||
ElMessage.success(t('inbox.saved'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleArchive(it: FeedbackItem) {
|
||||
busy.value = it.id
|
||||
try {
|
||||
const updated = await archiveFeedback(it.id, !it.archived)
|
||||
const i = items.value.findIndex((x) => x.id === updated.id)
|
||||
if (i >= 0) items.value[i] = updated
|
||||
ElMessage.success(updated.archived ? t('inbox.archOk') : t('inbox.unarchOk'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
async function remove(it: FeedbackItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('inbox.deleteConfirm'), t('inbox.delete'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('inbox.delete'),
|
||||
cancelButtonText: t('common.cancel'),
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await adminDeleteFeedback(it.id)
|
||||
items.value = items.value.filter((x) => x.id !== it.id)
|
||||
ElMessage.success(t('inbox.deleted'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
/** 账号下拉直接由数据里出现过的账号生成 —— 不给服务端再加一个"谁提过反馈"的接口。 */
|
||||
const accounts = computed(() => {
|
||||
const set = new Set<string>()
|
||||
items.value.forEach((it) => it.account && set.add(it.account))
|
||||
return Array.from(set).sort()
|
||||
})
|
||||
|
||||
const filtered = computed(() => {
|
||||
const k = applied.value.trim().toLowerCase()
|
||||
return items.value.filter((it) => {
|
||||
if (account.value && it.account !== account.value) return false
|
||||
if (status.value && it.status !== status.value) return false
|
||||
if (arch.value === 'active' && it.archived) return false
|
||||
if (arch.value === 'arch' && !it.archived) return false
|
||||
if (!k) return true
|
||||
return it.content.toLowerCase().includes(k) || it.account.toLowerCase().includes(k)
|
||||
})
|
||||
})
|
||||
|
||||
const pages = computed(() => Math.max(1, Math.ceil(filtered.value.length / PAGE_SIZE)))
|
||||
const paged = computed(() => filtered.value.slice((page.value - 1) * PAGE_SIZE, page.value * PAGE_SIZE))
|
||||
|
||||
// 任何筛选变化都回第一页,免得停在一个已经空的页码上
|
||||
watch([filtered, account, status], () => { if (page.value > pages.value) page.value = 1 })
|
||||
|
||||
function apply() { applied.value = kw.value; page.value = 1 }
|
||||
function clear() { kw.value = ''; applied.value = ''; account.value = ''; status.value = ''; arch.value = 'active'; page.value = 1 }
|
||||
function go(p: number) { page.value = Math.min(Math.max(1, p), pages.value) }
|
||||
|
||||
function fmtTs(ts: number): string {
|
||||
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())}`
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
items.value = await allFeedback()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || String(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.sel-acct { width: 150px; }
|
||||
.sel-st { width: 128px; }
|
||||
.sel-arch { width: 128px; }
|
||||
.kw-in { width: 210px; }
|
||||
.filters .spacer { flex: 1; }
|
||||
.fb-list { min-height: 60px; }
|
||||
.fb-item {
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.fb-item:last-child { margin-bottom: 0; }
|
||||
.fb-meta { display: flex; align-items: center; gap: 8px; }
|
||||
.fb-meta .ts { font-size: 11.5px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
|
||||
.fb-meta .pill { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.fb-text { margin-top: 6px; font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
|
||||
.field { margin-bottom: 12px; }
|
||||
.field.mt { margin-top: 4px; }
|
||||
.field label { display: block; margin-bottom: 6px; font-size: 12.5px; color: var(--muted); }
|
||||
.pg.dis { opacity: .35; cursor: default; }
|
||||
.flip { transform: rotate(180deg); }
|
||||
@media (max-width: 768px) {
|
||||
.sel-acct { width: 132px; }
|
||||
.sel-st { width: 112px; }
|
||||
.kw-in { width: 100%; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,274 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-alert v-if="err" class="mb" type="error" show-icon :closable="false"
|
||||
:title="t('gc.errTitle')" :description="err" />
|
||||
|
||||
<!-- 文件信息 -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('gc.file') }}</b>
|
||||
<span class="sub">{{ t('gc.fileSub') }}</span>
|
||||
<span class="flex-1" />
|
||||
<el-button size="small" :loading="loading" @click="load">{{ t('common.refresh') }}</el-button>
|
||||
</div>
|
||||
<div class="set-row"><div class="lb">{{ t('gc.path') }}</div><div class="rt code">{{ meta.path || '—' }}</div></div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('gc.restartKeys') }}</div>
|
||||
<div class="rt wrap">
|
||||
<span v-for="k in meta.restart_keys || []" :key="k" class="pill warn code">{{ k }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- YAML 全文编辑器 -->
|
||||
<div class="card mt">
|
||||
<div class="card-h">
|
||||
<b>{{ t('gc.editorTitle') }}</b>
|
||||
<span class="sub">{{ t('gc.editorSub') }}</span>
|
||||
<span class="flex-1" />
|
||||
<el-button size="small" @click="backupCfg">{{ t('gc.backup') }}</el-button>
|
||||
<el-button size="small" plain @click="pickRestore">{{ t('gc.restore') }}</el-button>
|
||||
<el-button type="primary" size="small" :loading="saving" @click="saveYaml">{{ t('gc.save') }}</el-button>
|
||||
<span v-if="restartPending.length" class="pill warn restart-pill">{{ t('gc.restartPill') }}</span>
|
||||
</div>
|
||||
<input ref="restoreInput" type="file" accept=".json" class="hidden" @change="onRestoreFile" />
|
||||
|
||||
<textarea v-model="yamlText" class="editor" spellcheck="false"></textarea>
|
||||
|
||||
<div class="hint">{{ t('gc.saveTip') }}</div>
|
||||
<el-alert v-if="savedOk" class="mt" type="success" :closable="false" :title="t('gc.saveOk')" />
|
||||
<el-alert v-if="restartPending.length" class="mt" type="info" show-icon :closable="false"
|
||||
:title="t('gc.restartSaved', { keys: restartPending.join('、') })" />
|
||||
<el-alert v-for="(w, i) in warns" :key="i" class="mt" type="warning" :closable="false" :title="w" />
|
||||
</div>
|
||||
|
||||
<!-- API Key 环境变量 -->
|
||||
<div class="card mt">
|
||||
<div class="card-h">
|
||||
<b>{{ t('gc.envTitle') }}</b>
|
||||
<span class="sub">{{ t('gc.envSub') }}</span>
|
||||
<span class="flex-1" />
|
||||
</div>
|
||||
<div v-if="!envKeys.length" class="hint">{{ t('gc.envEmpty') }}</div>
|
||||
<div v-for="e in envKeys" :key="e.env" class="set-row">
|
||||
<div class="lb flex-1">
|
||||
<span class="code">{{ e.env }}</span>
|
||||
<span class="pill" :class="e.set ? 'ok' : 'err'">{{ e.set ? t('gc.envSet') : t('gc.envMissing') }}</span>
|
||||
<div class="sub">{{ e.provider_name || e.provider }}</div>
|
||||
</div>
|
||||
<div class="rt env-rt">
|
||||
<el-input v-model="e.value" size="small" :type="e.show ? 'text' : 'password'" class="env-in" />
|
||||
<el-button size="small" text @click="e.show = !e.show">{{ t(e.show ? 'gc.envHide' : 'gc.envShow') }}</el-button>
|
||||
<el-button size="small" text :disabled="!e.value" @click="copyEnv(e)">{{ t('gc.envCopy') }}</el-button>
|
||||
<el-button size="small" type="primary" plain :loading="savingEnv" @click="saveEnv(e)">{{ t('gc.save') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { api } from '../api'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const savingEnv = ref(false)
|
||||
const err = ref('')
|
||||
const warns = ref<string[]>([])
|
||||
const savedOk = ref(false)
|
||||
const restartPending = ref<string[]>([])
|
||||
const meta = ref<any>({})
|
||||
const yamlText = ref('')
|
||||
const restoreInput = ref<HTMLInputElement | null>(null)
|
||||
interface EnvRow { env: string; provider: string; provider_name: string; set: boolean; value: string; show: boolean }
|
||||
const envKeys = ref<EnvRow[]>([])
|
||||
|
||||
function copyText(text: string): boolean {
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(text)
|
||||
return true
|
||||
}
|
||||
} catch { /* fall through */ }
|
||||
const ta = document.createElement('textarea')
|
||||
ta.value = text
|
||||
document.body.appendChild(ta)
|
||||
ta.select()
|
||||
try { document.execCommand('copy') } catch { /* ignore */ }
|
||||
document.body.removeChild(ta)
|
||||
return true
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
err.value = ''
|
||||
savedOk.value = false
|
||||
restartPending.value = []
|
||||
try {
|
||||
const body = await api('/config')
|
||||
meta.value = body.meta || {}
|
||||
yamlText.value = body.yaml || ''
|
||||
const envs = (body.env || {}) as Record<string, any>
|
||||
envKeys.value = Object.keys(envs).map((env) => ({
|
||||
env,
|
||||
provider: envs[env].provider || '—',
|
||||
provider_name: envs[env].provider_name || '',
|
||||
set: !!envs[env].set,
|
||||
value: envs[env].value || '',
|
||||
show: false,
|
||||
}))
|
||||
warns.value = (body.meta?.warnings || []).concat(body.meta?.route_warnings || [])
|
||||
} catch (e: any) {
|
||||
err.value = (e?.body?.detail || e?.message || String(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function saveYaml() {
|
||||
err.value = ''
|
||||
savedOk.value = false
|
||||
saving.value = true
|
||||
try {
|
||||
const r = await api('/config', { method: 'PUT', body: JSON.stringify({ yaml: yamlText.value }) })
|
||||
restartPending.value = r.restart_required || []
|
||||
warns.value = r.warnings || []
|
||||
savedOk.value = true
|
||||
ElMessage.success(t('gc.saveOk'))
|
||||
} catch (e: any) {
|
||||
const d = e?.body?.detail
|
||||
err.value = typeof d === 'string' ? d : (d ? JSON.stringify(d) : (e?.message || String(e)))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function backupCfg() {
|
||||
const envs: Record<string, string> = {}
|
||||
for (const e of envKeys.value) envs[e.env] = e.value
|
||||
const data = { kind: 'api-gateway-backup', version: 1, config: yamlText.value, envs }
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
|
||||
const a = document.createElement('a')
|
||||
a.href = URL.createObjectURL(blob)
|
||||
a.download = 'gateway-backup.json'
|
||||
a.click()
|
||||
URL.revokeObjectURL(a.href)
|
||||
ElMessage.success(t('gc.backupOk'))
|
||||
}
|
||||
function pickRestore() { restoreInput.value?.click() }
|
||||
function onRestoreFile(ev: Event) {
|
||||
const f = (ev.target as HTMLInputElement).files?.[0]
|
||||
if (!f) return
|
||||
const r = new FileReader()
|
||||
r.onload = () => {
|
||||
try {
|
||||
const parsed = JSON.parse(String(r.result || '{}'))
|
||||
const cfg = typeof parsed?.config === 'string' ? parsed.config : ''
|
||||
const rawEnvs = parsed && parsed.envs && typeof parsed.envs === 'object' ? parsed.envs : {}
|
||||
const envs: Record<string, string> = {}
|
||||
for (const [k, v] of Object.entries(rawEnvs as any)) envs[k] = String(v)
|
||||
if (!cfg.trim()) throw new Error('no config')
|
||||
ElMessageBox.confirm(
|
||||
t('gc.restoreConfirm', { envs: Object.keys(envs).length }),
|
||||
t('gc.restore'),
|
||||
{ type: 'warning', confirmButtonText: t('gc.restoreGo'), cancelButtonText: t('gc.cancel') },
|
||||
).then(async () => { await applyRestore(cfg, envs) }).catch(() => { /* 取消 */ })
|
||||
} catch (e: any) {
|
||||
err.value = t('gc.restoreInvalid') + ': ' + String(e && e.message || e || '')
|
||||
}
|
||||
}
|
||||
r.readAsText(f)
|
||||
;(ev.target as HTMLInputElement).value = ''
|
||||
}
|
||||
async function applyRestore(cfg: string, envs: Record<string, string>) {
|
||||
err.value = ''
|
||||
saving.value = true
|
||||
try {
|
||||
const j = await api('/config', { method: 'PUT', body: JSON.stringify({ yaml: cfg }) })
|
||||
if (Object.keys(envs).length) await applyEnv(envs)
|
||||
restartPending.value = j.restart_required || []
|
||||
savedOk.value = true
|
||||
ElMessage.success(t('gc.restoreOk'))
|
||||
await load()
|
||||
} catch (e: any) {
|
||||
const d = e?.body?.detail
|
||||
err.value = typeof d === 'string' ? d : (d ? JSON.stringify(d) : (e?.message || String(e)))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function applyEnv(map: Record<string, string>) {
|
||||
savingEnv.value = true
|
||||
try {
|
||||
const j = await api('/config/env', { method: 'POST', body: JSON.stringify({ envs: map }) })
|
||||
const envs = (j.envs || {}) as Record<string, any>
|
||||
envKeys.value = Object.keys(envs).map((env) => ({
|
||||
env,
|
||||
provider: envs[env].provider || '—',
|
||||
provider_name: envs[env].provider_name || '',
|
||||
set: !!envs[env].set,
|
||||
value: envs[env].value || '',
|
||||
show: false,
|
||||
}))
|
||||
} catch (e: any) {
|
||||
const d = e?.body?.detail
|
||||
throw new Error(typeof d === 'string' ? d : (d ? JSON.stringify(d) : (e?.message || String(e))))
|
||||
} finally {
|
||||
savingEnv.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function copyEnv(e: EnvRow) {
|
||||
if (!e.value) return
|
||||
copyText(e.value)
|
||||
ElMessage.success(t('gc.envCopied'))
|
||||
}
|
||||
async function saveEnv(e: EnvRow) {
|
||||
err.value = ''
|
||||
try {
|
||||
await applyEnv({ [e.env]: e.value })
|
||||
ElMessage.success(t('gc.envSaved'))
|
||||
} catch (e2: any) {
|
||||
err.value = e2?.message || String(e2)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mt { margin-top: var(--gap); }
|
||||
.wrap { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
|
||||
.hidden { display: none; }
|
||||
.hint { font-size: 11.5px; color: var(--muted-2); margin: 6px 0 2px; }
|
||||
.restart-pill { margin-left: 6px; }
|
||||
.editor {
|
||||
width: 100%;
|
||||
min-height: 58vh;
|
||||
box-sizing: border-box;
|
||||
resize: vertical;
|
||||
background: var(--chip);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: pre;
|
||||
}
|
||||
.editor:focus { outline: none; border-color: var(--primary); }
|
||||
.env-rt { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
||||
.env-in { flex: 0 0 260px; }
|
||||
.op-row { display: flex; gap: 8px; margin-top: 14px; }
|
||||
@media (max-width: 720px) {
|
||||
.env-rt { flex-wrap: wrap; }
|
||||
.env-in { flex: 1 1 100%; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,402 @@
|
||||
<template>
|
||||
<div class="page-fill">
|
||||
<div class="img-layout">
|
||||
<!-- 左:参数(固定 320px;窄屏自动落到上方单列) -->
|
||||
<div class="card param-card">
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('images.model') }}</label>
|
||||
<el-select v-model="model" filterable class="fill">
|
||||
<el-option v-for="m in models" :key="m.id" :value="m.id" :label="`${m.id} · ${m.provider_name}`" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<div class="form-row mb-field">
|
||||
<div class="field">
|
||||
<label>{{ t('images.size') }}</label>
|
||||
<el-select v-model="size" class="fill">
|
||||
<el-option v-for="s in sizes" :key="s" :value="s" :label="s" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t('images.ratio') }}</label>
|
||||
<el-select v-model="ratio" class="fill">
|
||||
<el-option v-for="r in ratios" :key="r" :value="r" :label="r" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="field field-narrow">
|
||||
<label>{{ t('images.count') }}</label>
|
||||
<!-- 第十三轮:上游接口一次只出 1 张(n>1 会被 400),这里改成"逐张生成"。
|
||||
第十八轮:controls-position="right" —— 两侧加减按钮各占 ~32px,92px 的窄列里
|
||||
内部 input 只剩 8px(数字看不见);挪到右侧后数字区约 50px。 -->
|
||||
<el-input-number v-model="count" :min="1" :max="4" controls-position="right" class="fill" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('images.promptRow') }}</label>
|
||||
<el-input
|
||||
v-model="prompt"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
resize="none"
|
||||
:placeholder="t('images.placeholder')"
|
||||
:disabled="loading"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('images.refsLabel') }}</label>
|
||||
<!-- 第十三轮:图生图 / 多图合成 —— 支持直接上传(浏览器内压成 data URI),也支持粘 URL -->
|
||||
<div class="ref-btns">
|
||||
<el-button size="small" :disabled="loading" @click="pickRefs">
|
||||
<Icon name="up" :size="14" />{{ t('images.refsUpload') }}
|
||||
</el-button>
|
||||
<el-button size="small" @click="showRefUrl = !showRefUrl">
|
||||
<Icon name="link" :size="14" />{{ t('images.refsUrlBtn') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="hint ref-hint">{{ t('images.refsHint') }}</div>
|
||||
<input ref="fileEl" type="file" accept="image/*" multiple class="hide-file" @change="onRefFiles" />
|
||||
<div v-if="refs.length" class="ref-thumbs">
|
||||
<div v-for="(r, i) in refs" :key="i" class="ref-thumb" :title="`${r.name} · ${formatBytes(dataUriBytes(r.uri))}`">
|
||||
<img :src="r.thumb || r.uri" alt="" />
|
||||
<span class="rm" @click="refs.splice(i, 1)"><Icon name="x" :size="11" /></span>
|
||||
<span class="rn">{{ r.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-input
|
||||
v-if="showRefUrl"
|
||||
v-model="refUrls"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
resize="none"
|
||||
:placeholder="t('images.refsPH')"
|
||||
:disabled="loading"
|
||||
class="ref-urls"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="param-foot">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="err-alert" />
|
||||
<el-button type="primary" class="go-btn" :loading="loading" :disabled="!prompt.trim()" @click="generate">
|
||||
<Icon name="img" :size="15" />{{ t('images.generate') }}
|
||||
</el-button>
|
||||
<div class="go-tip hint">
|
||||
<span v-if="loading && count > 1">{{ t('images.genProgress', { i: progress, n: count }) }}</span>
|
||||
<span v-else-if="providerName">{{ t('images.servedBy', { provider: providerName }) }}</span>
|
||||
<span v-else>{{ t('images.countTip') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右:结果(卡片自己撑满,滚动只发生在缩略图区) -->
|
||||
<div class="card result-card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('images.historyTitle') }}</b>
|
||||
<span class="sub">{{ t('images.historySub', { n: images.length }) }}</span>
|
||||
<div class="pager">
|
||||
<template v-if="images.length">
|
||||
<span class="pg" :class="{ off: page <= 1 }" @click="goPage(page - 1)"><Icon name="chev" :size="13" class="flip" /></span>
|
||||
<span v-for="p in pageCount" :key="p" class="pg" :class="{ on: p === page }" @click="goPage(p)">{{ p }}</span>
|
||||
<span class="pg" :class="{ off: page >= pageCount }" @click="goPage(page + 1)"><Icon name="chev" :size="13" /></span>
|
||||
</template>
|
||||
<el-button size="small" class="nowrap" :disabled="!images.length" @click="clearAll">{{ t('images.clear') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 逐张生成中:先占位,出图后自动落到下面网格 -->
|
||||
<div v-if="loading" class="thumbs">
|
||||
<div v-for="i in count" :key="i" class="th">
|
||||
<div class="ph shimmer" />
|
||||
<div class="meta"><b> </b><span> </span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="images.length" class="thumbs">
|
||||
<div v-for="row in pageImages" :key="row.img.id || row.i" class="th">
|
||||
<div class="ph">
|
||||
<el-image
|
||||
:src="row.img.src"
|
||||
fit="cover"
|
||||
class="thumb"
|
||||
:preview-src-list="images.map((x: any) => x.src)"
|
||||
:initial-index="row.i"
|
||||
preview-teleported
|
||||
>
|
||||
<template #error><span class="hint">{{ t('images.imgLoadErr') }}</span></template>
|
||||
</el-image>
|
||||
</div>
|
||||
<!-- 第十七轮: 下载。产物在跨域 CDN 上(不带 CORS 头),直链下载不生效,
|
||||
走 lib/download.ts 里的后端代拉;按钮放在图下方(不做缩略图上的悬浮圆形图标,
|
||||
手机端两列时也不会挤变形)。 -->
|
||||
<div class="meta">
|
||||
<b :title="row.img.prompt">{{ row.img.prompt || t('images.promptRow') }}</b>
|
||||
<span>
|
||||
{{ row.img.served }}<template v-if="row.img.ms"> · {{ row.img.ms }}</template>
|
||||
<template v-if="row.img.refs"> · {{ t('images.refsUsed', { n: row.img.refs }) }}</template>
|
||||
</span>
|
||||
<el-button size="small" class="th-btn" :loading="dlId === (row.img.id || row.i)" @click="dlImg(row.img, row.i)">
|
||||
<Icon name="dl" :size="14" />{{ t('images.dl') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-empty v-else :description="t('images.empty')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { api } from '../api'
|
||||
import { imageSrc } from '../lib/media'
|
||||
import { downloadMedia, nameFromPrompt, stamp } from '../lib/download'
|
||||
import { pullHistory, pushHistory, clearHistory, ensureIds } from '../lib/history'
|
||||
import { pickImage, PRESETS, dataUriBytes, formatBytes, assertBodyBudget } from '../lib/upload'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const models = ref<any[]>([])
|
||||
const model = ref('')
|
||||
const sizes = ['1K', '2K', '3K', '4K']
|
||||
const ratios = ['1:1', '3:4', '4:3', '16:9', '9:16', '2:3', '3:2', '21:9']
|
||||
const size = ref('1K')
|
||||
const ratio = ref('1:1')
|
||||
const count = ref(1) // 逐张生成:每张一次请求(上游 n 必须为 1)
|
||||
const prompt = ref('')
|
||||
// 参考图(图生图 / 多图合成):上传的走 data URI,URL 的直接透传,两类可混用
|
||||
const refs = ref<any[]>([])
|
||||
const refUrls = ref('')
|
||||
const showRefUrl = ref(false)
|
||||
const fileEl = ref<HTMLInputElement | null>(null)
|
||||
const MAX_REFS = 5
|
||||
const loading = ref(false)
|
||||
const progress = ref(0)
|
||||
const err = ref('')
|
||||
const images = ref<any[]>([])
|
||||
const SKEY = 'gw_image_history' // 只当本地缓存,真正的历史在服务端
|
||||
function cacheLocal() {
|
||||
try { localStorage.setItem(SKEY, JSON.stringify({ prompt: prompt.value, list: images.value })) } catch { /* 缓存写不进无所谓 */ }
|
||||
}
|
||||
async function save() {
|
||||
cacheLocal()
|
||||
// 写服务端失败必须吭声 —— 以前是 catch 掉静默丢历史,正是「图像还在、视频没了」的根因
|
||||
if (!(await pushHistory('images', images.value))) ElMessage.warning(t('history.saveFail'))
|
||||
}
|
||||
async function load() {
|
||||
let local: any = null
|
||||
try { local = JSON.parse(localStorage.getItem(SKEY) || 'null') } catch { local = null }
|
||||
const remote = await pullHistory('images')
|
||||
if (remote === null) {
|
||||
if (local && Array.isArray(local.list)) images.value = ensureIds(local.list, 'img')
|
||||
ElMessage.warning(t('history.offline'))
|
||||
return
|
||||
}
|
||||
if (remote.length) {
|
||||
images.value = remote
|
||||
} else if (local && Array.isArray(local.list) && local.list.length) {
|
||||
images.value = ensureIds(local.list, 'img') // 首次:把浏览器里的旧历史搬上服务端
|
||||
await pushHistory('images', images.value)
|
||||
} else {
|
||||
images.value = []
|
||||
}
|
||||
if (local && typeof local.prompt === 'string' && local.prompt && !prompt.value) prompt.value = local.prompt
|
||||
cacheLocal()
|
||||
}
|
||||
async function clearAll() {
|
||||
if (!images.value.length) return
|
||||
// 老板要求(连同视频页的「清除已完成」):真删之前必须二次确认 —— 服务端删了不可恢复。
|
||||
try {
|
||||
await ElMessageBox.confirm(t('images.confirmClear', { n: images.value.length }), t('common.confirm'),
|
||||
{ type: 'warning', confirmButtonText: t('common.delete'), cancelButtonText: t('common.cancel') })
|
||||
} catch { return }
|
||||
images.value = []
|
||||
cacheLocal()
|
||||
if (!(await clearHistory('images'))) ElMessage.warning(t('history.saveFail'))
|
||||
}
|
||||
|
||||
async function loadModels() {
|
||||
try {
|
||||
const j = await api('/v1/models')
|
||||
const all = (j.data || []).filter((x: any) => x.type === 'image')
|
||||
models.value = all
|
||||
if (all.length && !model.value) model.value = all[0].id
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
ElMessage.error(t('images.loadErr') + ':' + ((e && e.message) || e))
|
||||
}
|
||||
}
|
||||
|
||||
function pickRefs() {
|
||||
fileEl.value?.click()
|
||||
}
|
||||
async function onRefFiles(ev: Event) {
|
||||
const input = ev.target as HTMLInputElement
|
||||
for (const f of Array.from(input.files || [])) {
|
||||
if (refs.value.length >= MAX_REFS) { ElMessage.warning(t('images.refsMax', { n: MAX_REFS })); break }
|
||||
try {
|
||||
refs.value.push(await pickImage(f, PRESETS.ref))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('images.refPickErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
if (input) input.value = ''
|
||||
}
|
||||
/** 上传的 data URI + 手填的 URL,按顺序合成 extra_body.image 的入参 */
|
||||
function refList(): string[] {
|
||||
const urls = refUrls.value.split(/\r?\n/).map((x) => x.trim()).filter(Boolean)
|
||||
return [...refs.value.map((r) => r.uri), ...urls]
|
||||
}
|
||||
|
||||
const providerName = ref('')
|
||||
async function generate() {
|
||||
if (!prompt.value.trim() || loading.value) return
|
||||
const list = refList()
|
||||
try {
|
||||
// 素材 + 正文的整包体积要落在网关/Nginx 的请求体上限内(否则 413)
|
||||
assertBodyBudget([...list, prompt.value], 1200)
|
||||
} catch (e: any) {
|
||||
err.value = (e && e.message) || String(e)
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
err.value = ''
|
||||
const total = Math.max(1, Math.min(4, count.value))
|
||||
let done = 0
|
||||
try {
|
||||
for (let i = 1; i <= total; i++) {
|
||||
progress.value = i
|
||||
const t0 = performance.now()
|
||||
// 上游图像接口的 n 必须为 1:多张就在这里逐张调用,每张出来就上屏(进度可见)
|
||||
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: ratio.value, n: 1 }
|
||||
if (list.length) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
|
||||
const j = await api('/v1/images/generations', { method: 'POST', body: JSON.stringify(body) })
|
||||
const ms = (performance.now() - t0) | 0
|
||||
providerName.value = j.provider_name || j.provider || ''
|
||||
const items = (j.data || []).map((d: any, k: number) => ({
|
||||
id: `img-${Date.now()}-${i}-${k}`,
|
||||
ts: Date.now(),
|
||||
src: imageSrc(d),
|
||||
served: j.served_model || model.value,
|
||||
ms: `${ms}ms`,
|
||||
prompt: prompt.value.trim(),
|
||||
refs: list.length || undefined, // 记录本次用了多少张参考图
|
||||
})).filter((x: any) => x.src)
|
||||
if (!items.length) throw new Error(t('images.emptyResp'))
|
||||
done += items.length
|
||||
images.value = [...items, ...images.value]
|
||||
await save()
|
||||
}
|
||||
} catch (e: any) {
|
||||
// 逐张生成时中途失败:已生成的要留住,并说清是第几张断的
|
||||
const detail = (e?.body?.detail) || e?.message || String(e)
|
||||
err.value = done
|
||||
? t('images.partialFail', { done, i: Math.min(progress.value, total), msg: detail })
|
||||
: detail
|
||||
} finally {
|
||||
loading.value = false
|
||||
progress.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
// ── 结果区翻页(纯展示:不裁剪数据,只决定当前渲染哪一页)──
|
||||
const PAGE_SIZE = 6
|
||||
const page = ref(1)
|
||||
const pageCount = computed(() => Math.max(1, Math.ceil(images.value.length / PAGE_SIZE)))
|
||||
const pageImages = computed(() => images.value
|
||||
.slice((page.value - 1) * PAGE_SIZE, page.value * PAGE_SIZE)
|
||||
.map((img, k) => ({ img, i: (page.value - 1) * PAGE_SIZE + k })))
|
||||
function goPage(p: number) {
|
||||
if (p < 1 || p > pageCount.value) return
|
||||
page.value = p
|
||||
}
|
||||
// 新图永远插在最前面(逐张生成也是),历史整体换掉时回到第一页
|
||||
watch(images, () => { page.value = 1 })
|
||||
|
||||
onMounted(() => { load(); loadModels() })
|
||||
|
||||
// ── 第十七轮: 单张下载 ──
|
||||
// 文件名用「提示词前缀 + 时间戳」,后端会按 Content-Type 补 .png/.jpg 并以
|
||||
// Content-Disposition 回传(前端以服务端给的名字落盘,见 lib/download.ts)。
|
||||
const dlId = ref<any>(null)
|
||||
async function dlImg(img: any, i: number) {
|
||||
if (!img?.src) { ElMessage.error(t('images.dlNoSrc')); return }
|
||||
dlId.value = img.id || i
|
||||
try {
|
||||
await downloadMedia(img.src, `${nameFromPrompt(img.prompt, 'image')}-${stamp()}`)
|
||||
ElMessage.success(t('images.dlOk'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('images.dlFail', { msg: e?.message || String(e) }))
|
||||
} finally {
|
||||
dlId.value = null
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 撑满高度的两栏:左参数卡、右结果卡;滚动只发生在各自内部 */
|
||||
.param-card { display: flex; flex-direction: column; overflow-y: auto; }
|
||||
.result-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
||||
.result-card .thumbs { flex: 1; min-height: 0; overflow-y: auto; align-content: start; }
|
||||
|
||||
.mb-field { margin-bottom: 10px; }
|
||||
/* .field 天生是 flex:1(给 .form-row 横向用的)—— 在竖排卡片里必须收回,
|
||||
否则每个字段会纵向撑开,控件之间留下大片空白 */
|
||||
.param-card > .field { flex: none; }
|
||||
.fill { width: 100%; }
|
||||
/* 第十八轮: 92px 太窄(加减按钮吃掉大半),给到 108px 还要保证数字区不被压缩 */
|
||||
.field-narrow { flex: 0 0 108px; }
|
||||
.field-narrow :deep(.el-input__inner) { min-width: 30px; }
|
||||
.ref-btns { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
/* 参考图「上传 / URL」两个按钮文案不折行(窄列里被挤成两行是旧版的老毛病) */
|
||||
.ref-btns :deep(.el-button) { white-space: nowrap; }
|
||||
.ref-hint { margin-top: 6px; line-height: 1.5; }
|
||||
.ref-urls { margin-top: 6px; }
|
||||
.hide-file { display: none; }
|
||||
.ref-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
|
||||
.ref-thumb { position: relative; width: 68px; }
|
||||
.ref-thumb img { width: 68px; height: 68px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
|
||||
.ref-thumb .rn { display: block; font-size: 11px; color: var(--muted-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.ref-thumb .rm {
|
||||
position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
|
||||
display: grid; place-items: center; border-radius: 50%; cursor: pointer;
|
||||
background: var(--surface); border: 1px solid var(--line); color: var(--err);
|
||||
}
|
||||
|
||||
.param-foot { margin-top: auto; padding-top: 4px; }
|
||||
.err-alert { margin-bottom: 8px; }
|
||||
.go-btn { width: 100%; }
|
||||
.go-tip { margin-top: 8px; text-align: center; line-height: 1.5; }
|
||||
|
||||
.pager { gap: 4px; }
|
||||
.pg { cursor: pointer; }
|
||||
.pg.off { opacity: .45; cursor: default; }
|
||||
.flip { transform: rotate(180deg); }
|
||||
.pager :deep(.el-button) { margin-left: 6px; }
|
||||
|
||||
/* 缩略卡:图在上、标题与下载按钮在下(不做缩略图上的悬浮圆形图标) */
|
||||
.th .ph { position: relative; }
|
||||
.thumb { width: 100%; height: 100%; display: block; }
|
||||
.th .meta b { color: var(--text); }
|
||||
.th-btn { width: 100%; margin-top: 8px; }
|
||||
.shimmer { height: 96px; background: linear-gradient(90deg, var(--chip) 25%, var(--surface-2) 37%, var(--chip) 63%); background-size: 400% 100%; animation: ph 1.4s infinite; }
|
||||
@keyframes ph { 0% { background-position: 100% 0 } 100% { background-position: -100% 0 } }
|
||||
|
||||
/* 窄屏:单列后整页滚动,两个卡片都恢复自然高度 */
|
||||
@media (max-width: 768px) {
|
||||
/* 窄屏单列后不再需要「撑满一屏」,改由 .gw-body 整页滚动 */
|
||||
.page-fill { height: auto; }
|
||||
.img-layout { height: auto; }
|
||||
.param-card { overflow: visible; }
|
||||
.result-card { flex: none; }
|
||||
.result-card .thumbs { overflow: visible; }
|
||||
.card-h { flex-wrap: wrap; }
|
||||
.th-btn { margin-top: 7px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,211 @@
|
||||
<template>
|
||||
<!-- 登录页(第四次重做,方案一「极简白卡」,老板 2026-09-13 拍板):
|
||||
浅底 + 单列居中白卡,靠留白、柔光和极淡的几何纹理撑气质。
|
||||
与上一版的区别:去掉「顶部通栏背景图 + 左品牌区 + 右表单」的分栏卡片结构
|
||||
(老板认为不好看),也去掉自绘 SVG 背景图 —— 现在整页装饰全是 CSS 图层(见下方样式)。
|
||||
内容仍只有:logo + 品牌标题 + 用户名/密码 + 登录按钮。 -->
|
||||
<div class="login-wrap">
|
||||
<!-- 装饰层(从下到上:底色 → 柔光 → 卡片背后光雾 → 点阵肌理 → 右下同心环),
|
||||
全部 pointer-events:none,不参与交互、不引任何外链资源 -->
|
||||
<div class="wash" aria-hidden="true" />
|
||||
<div class="aurora" aria-hidden="true" />
|
||||
<div class="dots" aria-hidden="true" />
|
||||
<div class="rings" aria-hidden="true"><i /><i /><i /></div>
|
||||
|
||||
<!-- 中英切换:页面右上角白玻璃胶囊(桌面 / 窄屏同一套配色,靠 surface token 自动适配三主题) -->
|
||||
<el-dropdown class="lang-top" @command="onLang">
|
||||
<span class="lang">{{ locale === 'en' ? 'EN' : '中' }}</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh" :disabled="locale === 'zh'">中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en" :disabled="locale === 'en'">English</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
|
||||
<main class="card">
|
||||
<span class="logo"><Icon name="bolt" :size="22" /></span>
|
||||
<h1>{{ t('login.title') }}</h1>
|
||||
|
||||
<el-alert v-if="err" :title="err" type="error" class="login-err" show-icon :closable="false" />
|
||||
|
||||
<form @submit.prevent="doLogin">
|
||||
<div class="field">
|
||||
<label>{{ t('login.userPlaceholder') }}</label>
|
||||
<el-input v-model="username" size="large" autocomplete="username" @keyup.enter="doLogin" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t('login.passPlaceholder') }}</label>
|
||||
<el-input
|
||||
v-model="password"
|
||||
type="password"
|
||||
size="large"
|
||||
show-password
|
||||
autocomplete="current-password"
|
||||
@keyup.enter="doLogin"
|
||||
/>
|
||||
</div>
|
||||
<el-button type="primary" size="large" class="submit" :loading="loading" native-type="submit">
|
||||
{{ t('login.btn') }}
|
||||
</el-button>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useSessionStore } from '../store/session'
|
||||
import { setLocale } from '../i18n'
|
||||
import Icon from '../components/Icon.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const store = useSessionStore()
|
||||
const { t, locale } = useI18n()
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const loading = ref(false)
|
||||
const err = ref('')
|
||||
|
||||
function onLang(l: string) { setLocale(l as any) }
|
||||
|
||||
async function doLogin() {
|
||||
err.value = ''
|
||||
if (!username.value.trim() || !password.value) { err.value = t('login.errEmpty'); return }
|
||||
loading.value = true
|
||||
try {
|
||||
await store.login(username.value.trim(), password.value)
|
||||
ElMessage.success(t('login.success'))
|
||||
router.push('/dashboard')
|
||||
} catch (e: any) {
|
||||
err.value = authErr(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function authErr(e: any): string {
|
||||
if (e && e.status === 401) return t('login.err401')
|
||||
if (e && e.status === 429) return t('login.err429')
|
||||
// 403:服务端带得出明确原因(第二十四轮的「账号已被停用,请联系管理员」就走这条),
|
||||
// 优先显示原文 —— 比页面这句笼统的「账号被禁用或角色异常」有用得多;拿不到才退回文案。
|
||||
if (e && e.status === 403) return String(e?.message || '') || t('login.err403')
|
||||
if (e && e.message) return String(e.message)
|
||||
return t('login.errConn')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 颜色口径:能用 token 的地方一律用 token(上面这套装饰层因此能在 A/B/C 三主题下自动换色);
|
||||
需要"半透明的主题色"时用 color-mix(in srgb, var(--x) N%, transparent),不再写死
|
||||
rgba(79,99,245,…) 这种只对单一主题成立的常量。color-mix 在 Chrome 111+ / Safari 16.2+
|
||||
可用,不支持时该层退化为透明(少一层柔光,不影响可读性与布局)。 */
|
||||
.login-wrap {
|
||||
min-height: 100vh; min-height: 100dvh;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
padding: 40px 24px; background: var(--bg); position: relative;
|
||||
}
|
||||
|
||||
/* ① 柔光:左上主色、右下青调,让纯色底有体积感(不抢卡片,所以透明度很低) */
|
||||
.wash {
|
||||
position: fixed; inset: 0; pointer-events: none; background:
|
||||
radial-gradient(58% 48% at 8% -6%, color-mix(in srgb, var(--primary) 13%, transparent), transparent 62%),
|
||||
radial-gradient(46% 42% at 100% 108%, color-mix(in srgb, var(--chart-b) 12%, transparent), transparent 64%);
|
||||
}
|
||||
/* ② 卡片背后的一团主色光雾:白卡浮在光雾上才有厚度(挪掉不丑,只是页面会显平) */
|
||||
.aurora {
|
||||
position: fixed; left: 50%; top: 47%; width: 920px; height: 560px;
|
||||
transform: translate(-50%, -50%); pointer-events: none; filter: blur(14px);
|
||||
background: radial-gradient(50% 50% at 50% 50%, color-mix(in srgb, var(--primary) 17%, transparent), transparent 72%);
|
||||
}
|
||||
/* ③ 点阵肌理:只在左上角渐显(mask 化开),几乎察觉不到但页面不发死 */
|
||||
.dots {
|
||||
position: fixed; inset: 0; pointer-events: none;
|
||||
background-image: radial-gradient(color-mix(in srgb, var(--text) 16%, transparent) 1px, transparent 1px);
|
||||
background-size: 24px 24px;
|
||||
-webkit-mask-image: radial-gradient(52% 46% at 14% 8%, #000, transparent 72%);
|
||||
mask-image: radial-gradient(52% 46% at 14% 8%, #000, transparent 72%);
|
||||
}
|
||||
/* ④ 右下同心环:三个同心细线圆,越外越淡,给卡片一个视觉落点 */
|
||||
.rings i { position: fixed; border-radius: 50%; pointer-events: none; border: 1px solid color-mix(in srgb, var(--primary) 14%, transparent); }
|
||||
.rings i:nth-child(1) { width: 340px; height: 340px; right: -110px; bottom: -120px; }
|
||||
.rings i:nth-child(2) { width: 540px; height: 540px; right: -210px; bottom: -220px; border-color: color-mix(in srgb, var(--primary) 10%, transparent); }
|
||||
.rings i:nth-child(3) { width: 760px; height: 760px; right: -320px; bottom: -330px; border-color: color-mix(in srgb, var(--chart-b) 10%, transparent); }
|
||||
|
||||
/* 右上角中英切换:白玻璃胶囊(窄屏同款,颜色全走 token) */
|
||||
.lang-top { display: block; position: fixed; top: 24px; right: 26px; z-index: 5; }
|
||||
.lang {
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
min-width: 46px; padding: 6px 14px; border-radius: 999px; cursor: pointer; outline: none;
|
||||
background: color-mix(in srgb, var(--surface) 74%, transparent);
|
||||
border: 1px solid var(--line); color: var(--muted); font-size: 12.5px; line-height: 1.4;
|
||||
box-shadow: 0 2px 8px color-mix(in srgb, var(--text) 8%, transparent);
|
||||
backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
/* 卡片:两层阴影(token 的基础层 + 一层更深的落地层),压在柔光/光雾上要能跳出来 */
|
||||
.card {
|
||||
position: relative; z-index: 2; width: 440px; max-width: 100%;
|
||||
background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
|
||||
padding: 42px 40px 40px;
|
||||
box-shadow: var(--shadow), 0 24px 50px -26px rgba(0, 0, 0, .28);
|
||||
}
|
||||
.logo {
|
||||
width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
|
||||
color: var(--primary-ink);
|
||||
/* 主色自身上下渐变:A/C 主题换了主色,这块自动跟着换(不用为每套主题写死色值) */
|
||||
background: linear-gradient(142deg,
|
||||
color-mix(in srgb, var(--primary) 84%, #fff), var(--primary) 55%,
|
||||
color-mix(in srgb, var(--primary) 82%, #000));
|
||||
box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--primary) 62%, transparent);
|
||||
}
|
||||
.card h1 { margin: 20px 0 28px; font-size: 21px; font-weight: 650; letter-spacing: .1px; color: var(--text); }
|
||||
.login-err { margin-bottom: 16px; border-radius: 12px; }
|
||||
.field { margin-bottom: 16px; }
|
||||
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
|
||||
|
||||
/* 输入框:Element Plus 的 wrapper 本身就是「1px 内阴影当边框」,所以覆盖它而不是加 border,
|
||||
否则会出现双边框。填充式(chip 底)比描边式更松弛,也更好压住圆角。 */
|
||||
.field :deep(.el-input__wrapper) {
|
||||
height: 48px; padding: 0 15px; border-radius: 12px; background: var(--chip);
|
||||
box-shadow: 0 0 0 1px var(--line) inset;
|
||||
transition: background .16s, box-shadow .16s;
|
||||
}
|
||||
.field :deep(.el-input__wrapper:hover) {
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 34%, var(--line)) inset;
|
||||
}
|
||||
/* 聚焦态必须带 !important:全局 style.css 里有一条
|
||||
`.el-input__wrapper.is-focus { box-shadow: 0 0 0 1px var(--primary) inset !important }`
|
||||
(给全站输入框统一"细边"聚焦样式),不用 !important 的话这里的「1px 主色 + 3.5px 柔光」
|
||||
双环会被它整条盖掉,只剩 1px 细边。作用域仍只限登录页,不影响其它页面。 */
|
||||
.field :deep(.el-input__wrapper.is-focus) {
|
||||
background: var(--surface);
|
||||
box-shadow: 0 0 0 1px var(--primary) inset, 0 0 0 3.5px var(--primary-soft) !important;
|
||||
}
|
||||
.field :deep(.el-input__inner) { font-size: 14.5px; color: var(--text); }
|
||||
.field :deep(.el-input__inner::placeholder) { color: var(--muted-2); }
|
||||
|
||||
.submit {
|
||||
width: 100%; height: 48px; margin-top: 12px; border-radius: 12px;
|
||||
font-size: 15px; font-weight: 600;
|
||||
box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--primary) 75%, transparent);
|
||||
}
|
||||
|
||||
/* 手机端:卡片化整为零 —— 去掉卡片的底/边/影,表单直接在页面柔光底上居中,
|
||||
下方同心环缩一档(窄屏里 760px 的环几乎全在屏幕外,留着只是白算)
|
||||
(旧版那套「顶部色块 + 上浮卡片 + 接缝」的结构整段删掉了) */
|
||||
@media (max-width: 600px) {
|
||||
.login-wrap { align-items: stretch; padding: 0; }
|
||||
.card {
|
||||
width: 100%; border: 0; border-radius: 0; box-shadow: none; background: transparent;
|
||||
padding: 104px 22px 40px; display: flex; flex-direction: column; justify-content: center;
|
||||
}
|
||||
.rings i:nth-child(1) { width: 260px; height: 260px; right: -130px; bottom: -90px; }
|
||||
.rings i:nth-child(2) { width: 400px; height: 400px; right: -200px; bottom: -160px; }
|
||||
.rings i:nth-child(3) { display: none; }
|
||||
.lang-top { top: 18px; right: 18px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<!-- 筛选行:类型胶囊 + 原有筛选控件 + 刷新/导出 -->
|
||||
<div class="filters">
|
||||
<!-- 第十九轮:类型胶囊与「失败」互斥(原来两个维度叠加,「失败」亮着时点类型只剩空列表,
|
||||
看起来像筛选坏了);并给每个胶囊带上条数,点完立刻能看到生效与是否有该类型记录。 -->
|
||||
<span class="chip-sel" :class="{ on: kind === '' && result !== 'fail' }" @click="pickKind('')">
|
||||
{{ t('logs.all') }}<i class="cn">{{ entries.length }}</i>
|
||||
</span>
|
||||
<span class="chip-sel" :class="{ on: kind === 'chat' }" @click="pickKind('chat')">
|
||||
{{ t('logs.chat') }}<i class="cn">{{ kindCounts.chat }}</i>
|
||||
</span>
|
||||
<span class="chip-sel" :class="{ on: kind === 'image' }" @click="pickKind('image')">
|
||||
{{ t('logs.image') }}<i class="cn">{{ kindCounts.image }}</i>
|
||||
</span>
|
||||
<span class="chip-sel" :class="{ on: kind === 'video' }" @click="pickKind('video')">
|
||||
{{ t('logs.video') }}<i class="cn">{{ kindCounts.video }}</i>
|
||||
</span>
|
||||
<span class="chip-sel" :class="{ on: result === 'fail' }" @click="pickKind('fail')">
|
||||
{{ t('logs.fail') }}<i class="cn">{{ kindCounts.fail }}</i>
|
||||
</span>
|
||||
|
||||
<el-select v-model="method" :placeholder="t('logs.method')" clearable size="small" class="sel-method">
|
||||
<el-option v-for="m in ['GET', 'POST', 'OPTIONS', 'DELETE']" :key="m" :value="m" :label="m" />
|
||||
</el-select>
|
||||
<el-select v-model="result" :placeholder="t('logs.result')" clearable size="small" class="sel-result">
|
||||
<el-option value="ok" :label="t('logs.success')" />
|
||||
<el-option value="fail" :label="t('logs.fail')" />
|
||||
</el-select>
|
||||
<el-input v-model="kw" size="small" :placeholder="t('logs.searchPlaceholder')" clearable class="kw-in" @keyup.enter="applyFilter">
|
||||
<template #append><el-button @click="applyFilter">{{ t('common.search') }}</el-button></template>
|
||||
</el-input>
|
||||
<el-switch v-model="auto" size="small" :active-text="t('logs.autoRefresh')" />
|
||||
|
||||
<span class="spacer" />
|
||||
<el-button size="small" text @click="clear">{{ t('logs.clearFilter') }}</el-button>
|
||||
<el-button size="small" :disabled="loading" @click="load()">
|
||||
<Icon name="refresh" :size="13" />
|
||||
<span>{{ t('common.refresh') }}</span>
|
||||
</el-button>
|
||||
<el-button size="small" :disabled="!filtered.length" @click="exportLogs">
|
||||
<Icon name="dl" :size="13" />
|
||||
<span>{{ t('common.export') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('nav.menulogs') }}</b>
|
||||
<span class="sub">{{ t('logs.count', { n: filtered.length }) }}</span>
|
||||
<div class="pager">
|
||||
<span class="pill" :class="rateCls">{{ t('logs.success') }} {{ okRate }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="log-list" v-loading="loading">
|
||||
<div v-if="!filtered.length" class="hint">
|
||||
<span>{{ entries.length ? t('logs.emptyFiltered', { n: entries.length }) : t('logs.empty') }}</span>
|
||||
<el-button v-if="entries.length" size="small" text @click="clear">{{ t('logs.clearFilter') }}</el-button>
|
||||
</div>
|
||||
|
||||
<div v-for="row in filtered" :key="rowKey(row)">
|
||||
<div class="log-row" @click="toggle(row)">
|
||||
<span class="ts">{{ fmtTime(row.ts) }}</span>
|
||||
<span class="badge m">{{ kindLabel(row) }}</span>
|
||||
<span class="badge" :class="statusCls(row)">{{ statusText(row) }}</span>
|
||||
<span class="code path">{{ row.method }} {{ row.path }}</span>
|
||||
<span class="badge m" v-if="row.stream">{{ t('logs.streaming') }}</span>
|
||||
<span class="nowrap model">{{ row.served || row.model || '—' }}<span v-if="row.provider" class="muted-2"> @ {{ row.provider }}</span></span>
|
||||
<span class="muted note" :title="noteFull(row)">{{ noteText(row) }}</span>
|
||||
<Icon :name="isOpen(row) ? 'chevD' : 'chev'" :size="14" />
|
||||
</div>
|
||||
|
||||
<div v-if="isOpen(row)" class="log-detail">
|
||||
<p class="kv">
|
||||
<b>{{ t('logs.rid') }}</b> <span class="code">{{ row.rid || '—' }}</span>
|
||||
<b>{{ t('logs.caller') }}</b> <span class="code">{{ row.caller || '—' }}</span>
|
||||
<b>{{ t('logs.reqModel') }}</b> <span class="code">{{ row.model || '—' }}</span>
|
||||
<b>{{ t('logs.served') }}</b> <span class="code">{{ row.served || '—' }}</span>
|
||||
<b>{{ t('logs.provider') }}</b> <span class="code">{{ row.provider || '—' }}</span>
|
||||
<b>{{ t('logs.streaming') }}</b> <span class="code">{{ row.stream ? 'SSE' : t('common.no') }}</span>
|
||||
</p>
|
||||
<div class="detail-block"><label>{{ t('logs.request') }}</label><pre>{{ row.body || '—' }}</pre></div>
|
||||
<div class="detail-block"><label>{{ t('logs.response') }}</label><pre>{{ row.response || '—' }}</pre></div>
|
||||
<div class="detail-block" v-if="row.polls && row.polls.length">
|
||||
<label>{{ t('logs.polls', { n: row.polls.length }) }}</label>
|
||||
<el-timeline class="poll-timeline">
|
||||
<el-timeline-item v-for="(p, i) in row.polls" :key="i"
|
||||
:type="p.ok === false ? 'danger' : p.status === 'completed' || p.status === 'success' ? 'success' : p.status === 'failed' ? 'danger' : 'info'"
|
||||
:timestamp="fmtTime(p.ts)" placement="top" size="small">
|
||||
<div class="poll-line">
|
||||
<span class="code">{{ p.status || '—' }}</span>
|
||||
<span v-if="p.progress != null" class="sub"> · {{ p.progress }}%</span>
|
||||
<span v-if="p.error" class="err-text"> · {{ short(p.error) }}</span>
|
||||
</div>
|
||||
<pre v-if="p.raw" class="poll-raw">{{ p.raw }}</pre>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</div>
|
||||
<div class="detail-block" v-if="!row.ok"><label>{{ t('logs.error') }}</label><pre class="err-pre">{{ row.error || '—' }}</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { api } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { stamp } from '../lib/download'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const entries = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const auto = ref(true)
|
||||
const method = ref('')
|
||||
const result = ref('')
|
||||
const kw = ref('')
|
||||
// 第十九轮真凶:这里原来是普通 `let appliedKw = ''`,不是 ref —— 它不参与响应式追踪,
|
||||
// 改完之后 `filtered` 这个 computed 不会重算,只能等下一次数据变化(自动刷新 5s 一轮)
|
||||
// 才顺带把关键词应用上。表现就是「输了关键词点搜索,列表纹丝不动 / 过几秒自己又变了」。
|
||||
// 类型胶囊用的是 ref(kind),所以只有关键词这一路看着像坏了。
|
||||
const appliedKw = ref('')
|
||||
// 已展开的行 key:自动刷新会整体替换数据数组。改成自绘行之后展开态直接由这个 key 集合推导,
|
||||
// 刷新后(只要这行还在)详情不会每 5s 被收回去。
|
||||
const expandedKeys = ref<string[]>([])
|
||||
const expandedSet = computed(() => new Set(expandedKeys.value))
|
||||
const rowKey = (row: any): string => row.rid || `${row.method}:${row.path}:${row.ts}`
|
||||
function isOpen(row: any): boolean {
|
||||
return expandedSet.value.has(rowKey(row))
|
||||
}
|
||||
function toggle(row: any) {
|
||||
const k = rowKey(row)
|
||||
expandedKeys.value = expandedKeys.value.includes(k)
|
||||
? expandedKeys.value.filter((x) => x !== k)
|
||||
: [...expandedKeys.value, k]
|
||||
}
|
||||
|
||||
// 视频快照是否已经有结论(有结论就不再主动追轮询)
|
||||
const pollDone = (pl: any) => /completed|success|succeeded|failed|error/i.test(String(pl?.status))
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
// 先对上一条数据里「仍展开、且没生成完」的视频行主动轮询一次(幂等 GET):
|
||||
// 让正在看日志详情的老板也能实时看到轮询进度 —— 否则只有开着视频页才有快照。
|
||||
// 先轮询再取 /logs,本次刷新立刻就能看到新快照,不会慢一拍。
|
||||
const keys = expandedSet.value
|
||||
for (const e of entries.value) {
|
||||
if (!e.video_id || !keys.has(rowKey(e))) continue
|
||||
const pl = e.polls && e.polls.length ? e.polls[e.polls.length - 1] : null
|
||||
if (pl && pollDone(pl)) continue
|
||||
try {
|
||||
await api(`/v1/videos/${encodeURIComponent(e.video_id)}?model=${encodeURIComponent(e.served || e.model || '')}`)
|
||||
} catch { /* 轮询失败不打断刷新;后端会记为该次的失败快照 */ }
|
||||
}
|
||||
const j = await api('/logs?n=200')
|
||||
entries.value = j.entries || []
|
||||
// 只保留仍存在的已展开行:行被顶出窗口/被删则对应 key 一并清掉
|
||||
const alive = new Set(entries.value.map(rowKey))
|
||||
expandedKeys.value = expandedKeys.value.filter((k) => alive.has(k))
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
} finally { loading.value = false }
|
||||
}
|
||||
|
||||
// ── 类型筛选(全部 / 对话 / 图像 / 视频 / 失败)──
|
||||
// 「失败」直接复用原有的 result 筛选,不另立一份状态;其余按日志路径归类,纯前端过滤。
|
||||
type Kind = '' | 'chat' | 'image' | 'video'
|
||||
const kind = ref<Kind>('')
|
||||
// 第十九轮:优先用后端给的 row.kind(权威),老条目没这个字段才退回按路径猜。
|
||||
// 之前只看路径字符串,一旦以后端点改名/换前缀,筛选就会静默失效。
|
||||
function kindOf(row: any): Kind {
|
||||
const k = String(row.kind || '')
|
||||
if (k === 'chat' || k === 'image' || k === 'video') return k
|
||||
if (k === 'media') return '' // 媒体代拉(下载):不属于三类生成调用,只在「全部」里出现
|
||||
const p = String(row.path || '')
|
||||
if (p.includes('/images')) return 'image'
|
||||
if (p.includes('/videos')) return 'video'
|
||||
if (p.includes('/chat')) return 'chat'
|
||||
return ''
|
||||
}
|
||||
// 每个胶囊上的条数:直接告诉老板「这一类有几条」,筛完变空时也就不会再以为筛选没生效
|
||||
const kindCounts = computed(() => {
|
||||
const c: Record<string, number> = { chat: 0, image: 0, video: 0, fail: 0 }
|
||||
for (const e of entries.value) {
|
||||
const k = kindOf(e)
|
||||
if (k) c[k] += 1
|
||||
if (!e.ok) c.fail += 1
|
||||
}
|
||||
return c
|
||||
})
|
||||
function pickKind(k: '' | Kind | 'fail') {
|
||||
if (k === '') { kind.value = ''; result.value = ''; return }
|
||||
if (k === 'fail') {
|
||||
// 互斥:点「失败」就清掉类型,点类型就清掉「失败」(否则 类型=视频 + 结果=失败
|
||||
// 两个胶囊同时亮着、列表却是空的,看着就像筛选坏了)。要叠加筛选仍可用「结果」下拉。
|
||||
result.value = result.value === 'fail' ? '' : 'fail'
|
||||
if (result.value) kind.value = ''
|
||||
return
|
||||
}
|
||||
kind.value = kind.value === k ? '' : k
|
||||
if (kind.value) result.value = ''
|
||||
}
|
||||
function kindLabel(row: any): string {
|
||||
const k = kindOf(row)
|
||||
if (k === 'chat') return t('logs.chat')
|
||||
if (k === 'image') return t('logs.image')
|
||||
if (k === 'video') return t('logs.video')
|
||||
if (row.kind === 'media') return t('logs.media') // 下载:比裸显示 GET 更说明问题
|
||||
return row.method || '—'
|
||||
}
|
||||
// 视频还没出结果 → 用 warn 色提示「生成中」
|
||||
function videoBusy(row: any): boolean {
|
||||
if (!row.video_id) return false
|
||||
const pl = row.polls && row.polls.length ? row.polls[row.polls.length - 1] : null
|
||||
return !pl || !pollDone(pl)
|
||||
}
|
||||
function statusCls(row: any): string {
|
||||
if (!row.ok) return 'r'
|
||||
return videoBusy(row) ? 'o' : 'g'
|
||||
}
|
||||
function statusText(row: any): string {
|
||||
if (!row.ok) return t('common.fail')
|
||||
return videoBusy(row) ? t('videos.doingText') : t('common.ok')
|
||||
}
|
||||
|
||||
const filtered = computed(() => {
|
||||
let list = entries.value
|
||||
if (method.value) list = list.filter((e) => e.method === method.value)
|
||||
if (result.value) list = list.filter((e) => e.ok === (result.value === 'ok'))
|
||||
if (kind.value) list = list.filter((e) => kindOf(e) === kind.value)
|
||||
if (appliedKw.value) {
|
||||
const k = appliedKw.value.toLowerCase()
|
||||
list = list.filter((e) => [e.model, e.served, e.provider, e.path, e.body, e.response, e.error]
|
||||
.some((v) => v && String(v).toLowerCase().includes(k)))
|
||||
}
|
||||
return list
|
||||
})
|
||||
function applyFilter() { appliedKw.value = (kw.value || '').trim() }
|
||||
// 第十九轮:关键词改成「边打边筛」。原来只有点「搜索」或回车才赋值,而且那个变量还不是响应式的,
|
||||
// 输完看着列表没变,很容易和这次报的「筛选不生效」混在一起;行数最多 200 条,实时过滤开销可忽略。
|
||||
// 搜索按钮和回车保留(点一下等于强制重算,对习惯动作无害)。
|
||||
watch(kw, () => { appliedKw.value = (kw.value || '').trim() })
|
||||
function clear() { method.value = ''; result.value = ''; kw.value = ''; appliedKw.value = ''; kind.value = '' }
|
||||
|
||||
const okRate = computed(() => {
|
||||
const n = filtered.value.length
|
||||
if (!n) return '0.0'
|
||||
const ok = filtered.value.filter((e) => e.ok).length
|
||||
return ((ok / n) * 100).toFixed(1)
|
||||
})
|
||||
const rateCls = computed(() => {
|
||||
const n = filtered.value.length
|
||||
if (!n) return 'mute'
|
||||
const r = Number(okRate.value)
|
||||
return r >= 99 ? 'ok' : r >= 90 ? 'warn' : 'err'
|
||||
})
|
||||
|
||||
function fmtTime(ts: number) {
|
||||
if (!ts) return '-'
|
||||
const d = new Date(ts * 1000)
|
||||
const pad = (x: number) => String(x).padStart(2, '0')
|
||||
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
}
|
||||
|
||||
const short = (x: any, n = 120) => {
|
||||
const t = String(x ?? '')
|
||||
return t.length > n ? t.slice(0, n) + '…' : t
|
||||
}
|
||||
function noteFull(row: any): string {
|
||||
return String((row.ok ? row.response : row.error || row.response) || row.body || '')
|
||||
}
|
||||
function noteText(row: any): string {
|
||||
const s = noteFull(row)
|
||||
return s ? short(s) : '—'
|
||||
}
|
||||
|
||||
/** 日志导出:把当前筛选结果存成 JSON(纯前端,不新增接口)。 */
|
||||
function exportLogs() {
|
||||
const body = JSON.stringify(filtered.value, null, 2)
|
||||
const href = URL.createObjectURL(new Blob([body], { type: 'application/json;charset=utf-8' }))
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = `logs-${stamp()}.json`
|
||||
a.style.display = 'none'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(href), 10_000)
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
onMounted(() => { load(); timer = setInterval(() => { if (auto.value) load() }, 5000) })
|
||||
onUnmounted(() => clearInterval(timer))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filters .spacer { flex: 1; }
|
||||
.sel-method { width: 118px; }
|
||||
.sel-result { width: 108px; }
|
||||
/* 搜索框:桌面 280px,窄屏靠 max-width 收到工具条宽度(父级是 flex 容器,100% 有效) */
|
||||
.kw-in { width: 280px; max-width: 100%; }
|
||||
|
||||
.log-list { max-height: 68vh; overflow-y: auto; }
|
||||
.log-row { cursor: pointer; }
|
||||
.log-row:hover { background: var(--surface-2); }
|
||||
.log-row .path { flex: none; color: var(--muted); }
|
||||
.log-row .model { flex: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
|
||||
.log-row .note { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.log-row :deep(.gw-icon) { color: var(--muted-2); flex: none; }
|
||||
|
||||
.kv { margin: 0 0 8px; display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.detail-block { margin-bottom: 8px; }
|
||||
.detail-block label { display: block; color: var(--muted-2); font-size: 11px; margin-bottom: 2px; }
|
||||
.detail-block pre {
|
||||
margin: 0; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line);
|
||||
border-radius: 6px; white-space: pre-wrap; word-break: break-all;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
|
||||
max-height: 240px; overflow: auto; color: var(--text);
|
||||
}
|
||||
.err-pre { color: var(--err); }
|
||||
.poll-timeline { padding: 4px 2px; max-height: 260px; overflow: auto; }
|
||||
.poll-line { font-size: 12px; }
|
||||
.poll-raw {
|
||||
margin-top: 2px; font-size: 11px; max-height: 90px; overflow: auto;
|
||||
background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
|
||||
white-space: pre-wrap; word-break: break-all;
|
||||
}
|
||||
.sub { font-size: 11.5px; color: var(--muted-2); }
|
||||
.err-text { color: var(--err); font-size: 12px; }
|
||||
|
||||
/* 类型胶囊上的条数:小一号、淡一档;胶囊选中时跟着主色走(.on 已给 font-weight) */
|
||||
.chip-sel .cn {
|
||||
font-style: normal; font-size: 11px; font-variant-numeric: tabular-nums;
|
||||
padding: 0 5px; border-radius: 6px; background: var(--chip); color: var(--muted-2);
|
||||
}
|
||||
.chip-sel.on .cn { background: var(--primary); color: #fff; }
|
||||
/* 筛选后为空:给出「原始有多少条」并直接给一个清空筛选的出口 */
|
||||
.hint { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.filters .kw-in { width: 100%; }
|
||||
.log-row { flex-wrap: wrap; }
|
||||
.log-row .path { order: 9; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.log-row .note { white-space: normal; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,262 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="mb" />
|
||||
|
||||
<!-- KPI:全部来自 /metrics 当前快照。网关没有历史时序接口,
|
||||
所以这里不画趋势条、也不给「近 7 天」这类假的时间筛选。 -->
|
||||
<div class="kpis">
|
||||
<div v-for="c in cards" :key="c.k" class="kpi">
|
||||
<div class="k">{{ c.k }}</div>
|
||||
<div class="v">{{ c.v }}</div>
|
||||
<div class="f"><span class="muted-2">{{ c.note }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-eq">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('metrics.modelCalls') }}</b>
|
||||
<span class="sub">{{ t('metrics.snapshot') }}</span>
|
||||
<div class="legend">
|
||||
<span><i style="background: var(--ok)" />{{ t('metrics.success') }}</span>
|
||||
<span><i style="background: var(--err)" />{{ t('metrics.fail') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<EChart :option="callsOpt" height="250px" />
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('metrics.provShare') }}</b>
|
||||
<span class="sub">{{ t('metrics.snapshot') }}</span>
|
||||
</div>
|
||||
<EChart :option="provOpt" height="250px" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-eq">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('metrics.routeVsProvider') }}</b>
|
||||
<span class="sub">{{ t('metrics.snapshot') }}</span>
|
||||
<div class="legend">
|
||||
<span><i style="background: var(--chart-a)" />ok</span>
|
||||
<span><i style="background: var(--err)" />fail</span>
|
||||
<span><i style="background: var(--warn)" />fallback</span>
|
||||
</div>
|
||||
</div>
|
||||
<EChart :option="routeOpt" height="250px" />
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('metrics.latency') }}</b>
|
||||
<span class="sub">P50 / P95</span>
|
||||
<div class="legend">
|
||||
<span><i style="background: var(--chart-a)" />P50</span>
|
||||
<span><i style="background: var(--chart-b)" />P95</span>
|
||||
</div>
|
||||
</div>
|
||||
<EChart :option="latOpt" height="250px" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: var(--gap)">
|
||||
<div class="card-h">
|
||||
<b>{{ t('metrics.circuitStatus') }}</b>
|
||||
<span class="sub">{{ t('metrics.circuitCard') }}</span>
|
||||
</div>
|
||||
<el-table :data="circuits" size="small" v-loading="loading">
|
||||
<el-table-column prop="provider" :label="t('metrics.provider')" min-width="140" />
|
||||
<el-table-column :label="t('metrics.state')" width="120">
|
||||
<template #default="{ row }">
|
||||
<span class="pill" :class="stateCls(row.state)">{{ row.state }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="recent_failures" :label="t('metrics.recentFailures')" width="100" />
|
||||
<el-table-column prop="window_size" :label="t('metrics.window')" width="90" />
|
||||
<el-table-column prop="threshold" :label="t('metrics.threshold')" width="90" />
|
||||
<el-table-column prop="cooldown_seconds" :label="t('metrics.cooldown')" width="110" />
|
||||
<el-table-column :label="t('metrics.probing')" width="90">
|
||||
<template #default="{ row }">
|
||||
<Icon v-if="row.probing" name="refresh" :size="14" />
|
||||
<span v-else class="muted-2">{{ t('common.no') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<div class="card about-card">
|
||||
<div class="about-line">
|
||||
<b>{{ t('metrics.snapshot') }}</b>
|
||||
<span>{{ t('metrics.uptime') }} {{ fmtUptime }}</span>
|
||||
<span>{{ t('metrics.fallback') }} {{ data.fallback_total ?? 0 }}</span>
|
||||
<span>{{ t('metrics.inflight') }} {{ data.in_flight ?? 0 }} / {{ data.in_flight_peak ?? 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import EChart from '../components/EChart.vue'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { categoryAxis, chartTheme, emptyTip, grid, legend, pieLabel, pieLabelLine, pieRadius, pieCenter, pieData, valueAxis } from '../lib/charts'
|
||||
import type { EChartsCoreOption } from '../lib/echarts'
|
||||
import { useTheme } from '../lib/theme'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const { resolved } = useTheme()
|
||||
const data = ref<any>({})
|
||||
const loading = ref(false)
|
||||
const err = ref('')
|
||||
// 运行时间的实时基准:uptimeAt = 上次拿到 /metrics 的时刻,nowTick = 本地每秒心跳。
|
||||
const uptimeAt = ref(Date.now())
|
||||
const nowTick = ref(Date.now())
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
err.value = ''
|
||||
try {
|
||||
data.value = await api('/metrics')
|
||||
uptimeAt.value = Date.now()
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
err.value = e?.message || String(e)
|
||||
} finally { loading.value = false }
|
||||
}
|
||||
|
||||
const fmtUptime = computed(() => {
|
||||
const u = data.value.uptime_seconds
|
||||
if (u == null) return '-'
|
||||
// 运行时间要实时走:/metrics 是 8s 一拉,直接用返回值会「8 秒跳一格」。
|
||||
// 这里以拿到值的那一刻为基准本地每秒累加,秒针是连续走的。
|
||||
void nowTick.value
|
||||
const live = u + Math.max(0, (nowTick.value - uptimeAt.value) / 1000)
|
||||
const d = Math.floor(live / 86400); const h = Math.floor((live % 86400) / 3600)
|
||||
const mo = Math.floor((live % 3600) / 60); const s = Math.floor(live % 60)
|
||||
return d ? `${d}d ${h}h ${mo}m ${s}s` : h ? `${h}h ${mo}m ${s}s` : `${mo}m ${s}s`
|
||||
})
|
||||
|
||||
const totals = computed(() => {
|
||||
const c = data.value.calls || {}
|
||||
let ok = 0, fail = 0
|
||||
for (const m of Object.values(c) as any[]) { ok += m?.ok || 0; fail += m?.fail || 0 }
|
||||
return { ok, fail, all: ok + fail }
|
||||
})
|
||||
|
||||
const cards = computed(() => {
|
||||
void resolved.value
|
||||
const tk = data.value.tokens || {}
|
||||
const { ok, fail, all } = totals.value
|
||||
const rate = all ? (fail / all) * 100 : 0
|
||||
return [
|
||||
{ k: t('metrics.requests'), v: all, note: t('dashboard.noteOkFail', { ok, fail }) },
|
||||
{ k: t('metrics.failCount'), v: fail, note: t('metrics.failRateNote', { v: rate.toFixed(1) }) },
|
||||
{ k: t('metrics.tokenUsage'), v: (tk.prompt || 0) + (tk.completion || 0), note: t('metrics.tokenNote', { p: tk.prompt ?? 0, c: tk.completion ?? 0 }) },
|
||||
{ k: t('metrics.inflightPeak'), v: `${data.value.in_flight ?? 0} / ${data.value.in_flight_peak ?? 0}`, note: t('metrics.fallback') + ' ' + (data.value.fallback_total ?? 0) },
|
||||
]
|
||||
})
|
||||
|
||||
const callsOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const c = chartTheme()
|
||||
const calls = data.value.calls || {}
|
||||
const models = Object.keys(calls)
|
||||
const ok = models.map((m) => calls[m]?.ok || 0)
|
||||
const fail = models.map((m) => calls[m]?.fail || 0)
|
||||
return {
|
||||
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
|
||||
legend: legend([t('metrics.success'), t('metrics.fail')]),
|
||||
grid,
|
||||
graphic: emptyTip([ok, fail], t('metrics.none')),
|
||||
xAxis: categoryAxis(models),
|
||||
yAxis: valueAxis('', 1),
|
||||
series: [
|
||||
{ name: t('metrics.success'), type: 'bar', stack: 'c', itemStyle: { color: c.ok }, data: ok },
|
||||
{ name: t('metrics.fail'), type: 'bar', stack: 'c', itemStyle: { color: c.err }, data: fail },
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
const provOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const p = data.value.providers || {}
|
||||
const items = Object.keys(p).map((k) => ({ name: k, value: p[k]?.ok || 0 })).filter((x) => x.value > 0)
|
||||
return {
|
||||
tooltip: { trigger: 'item' },
|
||||
series: [{
|
||||
type: 'pie', radius: pieRadius, center: pieCenter, minAngle: 6, labelLine: pieLabelLine,
|
||||
data: pieData(items, t('metrics.none')), label: pieLabel(), itemStyle: { borderRadius: 4 },
|
||||
}],
|
||||
}
|
||||
})
|
||||
|
||||
const routeOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const c = chartTheme()
|
||||
const r = data.value.routes || {}
|
||||
const ks = Object.keys(r)
|
||||
const names = ks.length ? ks : ['wjd']
|
||||
const get = (k: string, f: string) => (r[k] || {})[f] || 0
|
||||
const ok = names.map((n) => get(n, 'ok'))
|
||||
const fail = names.map((n) => get(n, 'fail'))
|
||||
const fallback = names.map((n) => get(n, 'fallback'))
|
||||
return {
|
||||
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
|
||||
legend: legend(['ok', 'fail', 'fallback']),
|
||||
grid,
|
||||
graphic: emptyTip([ok, fail, fallback], t('metrics.none')),
|
||||
xAxis: categoryAxis(names, 10),
|
||||
yAxis: valueAxis('', 1),
|
||||
series: [
|
||||
{ name: 'ok', type: 'bar', stack: 'r', data: ok, itemStyle: { color: c.a } },
|
||||
{ name: 'fail', type: 'bar', stack: 'r', data: fail, itemStyle: { color: c.err } },
|
||||
{ name: 'fallback', type: 'bar', stack: 'r', data: fallback, itemStyle: { color: c.warn } },
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
const latOpt = computed<EChartsCoreOption>(() => {
|
||||
void resolved.value
|
||||
const c = chartTheme()
|
||||
const l = data.value.latency || {}
|
||||
const models = Object.keys(l)
|
||||
const p50 = models.map((m) => l[m]?.p50 ?? 0)
|
||||
const p95 = models.map((m) => l[m]?.p95 ?? 0)
|
||||
return {
|
||||
tooltip: { trigger: 'axis', valueFormatter: (v: any) => `${typeof v === 'number' ? v.toFixed(3) : v}s` },
|
||||
legend: legend(['P50', 'P95']),
|
||||
grid,
|
||||
graphic: emptyTip([p50, p95], t('metrics.none')),
|
||||
xAxis: categoryAxis(models),
|
||||
yAxis: valueAxis('s'),
|
||||
series: [
|
||||
{ name: 'P50', type: 'bar', data: p50, itemStyle: { color: c.a, borderRadius: [4, 4, 0, 0] } },
|
||||
{ name: 'P95', type: 'bar', data: p95, itemStyle: { color: c.b, borderRadius: [4, 4, 0, 0] } },
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
const circuits = computed(() => data.value.circuits || [])
|
||||
function stateCls(s: string) {
|
||||
const v = String(s || '').toUpperCase()
|
||||
return v === 'CLOSED' ? 'ok' : v === 'HALF_OPEN' ? 'warn' : 'err'
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
let tickTimer: any = null
|
||||
onMounted(() => {
|
||||
load()
|
||||
timer = setInterval(load, 8000)
|
||||
tickTimer = setInterval(() => { nowTick.value = Date.now() }, 1000)
|
||||
})
|
||||
onUnmounted(() => { clearInterval(timer); clearInterval(tickTimer) })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.about-card { margin-top: var(--gap); padding: 12px 16px; }
|
||||
.about-line b { color: var(--text); }
|
||||
</style>
|
||||
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="mb" />
|
||||
|
||||
<div class="kpis">
|
||||
<div v-for="c in cards" :key="c.k" class="kpi">
|
||||
<div class="k">{{ c.k }}</div>
|
||||
<div class="v">{{ c.v }}</div>
|
||||
<div class="f"><span class="muted-2">{{ c.note }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid2">
|
||||
<!-- 路由链:只读展示(排序策略在后端,页面不写盘) -->
|
||||
<!-- 路由别名 + 全部文本模型延迟(一键测速填充) -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('models.routeAliasTitle') }}</b>
|
||||
</div>
|
||||
|
||||
<div v-for="r in routeRows" :key="r.name" class="route-block">
|
||||
<div class="route-head">
|
||||
<span class="code route-name">{{ r.name }}</span>
|
||||
<span style="flex:1"></span>
|
||||
<el-button size="small" :loading="latTesting" @click="runSpeedtest()">
|
||||
{{ latTesting ? t('models.testingShort') : t('models.speedtest') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!routeRows.length" class="hint">{{ t('models.noRoute') }}</div>
|
||||
|
||||
<div class="lat-head">
|
||||
<span class="muted-2 hint">{{ t('models.allTextModels') }}</span>
|
||||
<span style="flex:1"></span>
|
||||
<span class="muted-2 hint">{{ t('models.latency') }}</span>
|
||||
</div>
|
||||
<div v-for="m in textModelRows" :key="m.id" class="st-item">
|
||||
<div class="st-row">
|
||||
<Icon v-if="m.vision" name="eye" :size="12" class="vision" />
|
||||
<span class="code">{{ m.id }}</span>
|
||||
<span class="muted-2 st-prov">{{ m.provider }}</span>
|
||||
<span style="flex:1"></span>
|
||||
<span class="pill st-lat" :class="latCls(m.id)">
|
||||
<span v-if="m.id === latCurrentId" class="st-spin" aria-hidden="true"></span>
|
||||
<span v-else>{{ latText(m.id) }}</span>
|
||||
</span>
|
||||
<button class="st-one" :disabled="latTesting || !!latCurrentId"
|
||||
:title="t('models.testOne')" :aria-label="t('models.testOne')" @click="retestOne(m.id)">
|
||||
<Icon name="bolt" :size="13" />
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="latErr(m.id)" class="st-err">
|
||||
<Icon name="ban" :size="13" class="st-err-ico" />
|
||||
<span class="st-err-txt">{{ latErr(m.id) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!textModelRows.length" class="hint">{{ t('common.empty') }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 供应商:状态取 /health 的熔断器,Key 是否配置取同一份数据 -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('models.providerCard') }}</b>
|
||||
<span class="sub">{{ t('models.providerCount2', { n: providerRows.length }) }}</span>
|
||||
</div>
|
||||
<div v-for="p in providerRows" :key="p.name" class="prov">
|
||||
<div class="prov-top">
|
||||
<b>{{ p.name }}</b>
|
||||
<span class="pill" :class="p.cls">{{ p.text }}</span>
|
||||
</div>
|
||||
<div class="prov-meta">
|
||||
<span class="muted-2">{{ p.models }} {{ t('models.model') }}</span>
|
||||
<span class="pill" :class="p.keySet ? 'ok' : 'err'">
|
||||
{{ p.keySet ? t('models.keyOk') : t('models.keyMissing') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!providerRows.length" class="hint">{{ t('common.empty') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: var(--gap)">
|
||||
<div class="card-h">
|
||||
<b>{{ t('models.modelListTitle') }}</b>
|
||||
<span class="sub">{{ t('models.capability') }}</span>
|
||||
<div class="pager">
|
||||
<span class="pill mute">{{ t('models.routeCount', { n: routeRows.length }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="modelRows" size="small" v-loading="loading">
|
||||
<el-table-column :label="t('models.id')" min-width="200">
|
||||
<template #default="{ row }"><span class="code">{{ row.id }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('models.type')" width="100">
|
||||
<template #default="{ row }"><span class="pill" :class="typeCls(row.type)">{{ t(typeKey(row.type)) }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('models.provider')" min-width="150">
|
||||
<template #default="{ row }">{{ row.provider_name || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('models.capability')" width="120">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.vision" class="pill ok cap">
|
||||
<Icon name="eye" :size="12" />{{ t('models.visionTag') }}
|
||||
</span>
|
||||
<span v-else class="muted-2">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('models.keySet')" width="120">
|
||||
<template #default="{ row }">
|
||||
<span class="pill" :class="row.key_set ? 'ok' : 'err'">
|
||||
{{ row.key_set ? t('common.yes') : t('common.no') }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { api } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const items = ref<any[]>([])
|
||||
const health = ref<any>({})
|
||||
const loading = ref(false)
|
||||
const err = ref('')
|
||||
|
||||
const typeKeyMap: Record<string, string> = { text: 'models.text', image: 'models.image', video: 'models.video', route: 'models.route' }
|
||||
const typeClsMap: Record<string, string> = { text: 'mute', image: 'warn', video: 'warn', route: 'ok' }
|
||||
function typeKey(ty: string) { return typeKeyMap[ty] || ty }
|
||||
function typeCls(ty: string) { return typeClsMap[ty] || 'mute' }
|
||||
|
||||
const latTesting = ref(false)
|
||||
const latCurrentId = ref('') // 当前正在测的模型 id:该行延迟位显示加载图标
|
||||
const latByModel = ref<Record<string, { ok: boolean; latency_ms: number | null; error: string }>>({})
|
||||
async function runSpeedtest() {
|
||||
if (latTesting.value) return
|
||||
// 逐个测速:按列表顺序,测一个立刻显示那一行、再测下一个;当前测的行显示加载图标。
|
||||
// 串行天然不会把免费额度瞬间打满(并发时免费档供应商容易 429)。
|
||||
const ids = textModelRows.value.map((m) => m.id)
|
||||
latByModel.value = {}
|
||||
latTesting.value = true
|
||||
for (const id of ids) {
|
||||
latCurrentId.value = id
|
||||
let row: { ok: boolean; latency_ms: number | null; error: string }
|
||||
try {
|
||||
const j = await api('/v1/models/speedtest', { method: 'POST', body: JSON.stringify({ model: id }) })
|
||||
const r: any[] = (j && j.results) || []
|
||||
const hit = r[0]
|
||||
row = hit
|
||||
? { ok: !!hit.ok, latency_ms: hit.latency_ms ?? null, error: hit.error || '' }
|
||||
: { ok: false, latency_ms: null, error: t('models.speedtestFail') }
|
||||
} catch (e: any) {
|
||||
// 单个模型出错不中断整轮,标记失败后继续下一个
|
||||
row = { ok: false, latency_ms: null, error: (e && e.message) || String(e) }
|
||||
}
|
||||
latByModel.value = { ...latByModel.value, [id]: row } // 响应式替换 → 该行即时更新
|
||||
}
|
||||
latCurrentId.value = ''
|
||||
latTesting.value = false
|
||||
ElMessage.success(t('models.speedtestDone', { n: ids.length }))
|
||||
}
|
||||
// 单个模型重新测速(失败行旁的「重新测速」按钮):只重测这一个,复用当前行加载图标
|
||||
async function retestOne(id: string) {
|
||||
if (latTesting.value || latCurrentId.value) return // 整轮测速中 / 已有单测在跑 → 忽略,避免打架
|
||||
latCurrentId.value = id
|
||||
try {
|
||||
const j = await api('/v1/models/speedtest', { method: 'POST', body: JSON.stringify({ model: id }) })
|
||||
const r: any[] = (j && j.results) || []
|
||||
const hit = r[0]
|
||||
const row = hit
|
||||
? { ok: !!hit.ok, latency_ms: hit.latency_ms ?? null, error: hit.error || '' }
|
||||
: { ok: false, latency_ms: null, error: t('models.speedtestFail') }
|
||||
latByModel.value = { ...latByModel.value, [id]: row }
|
||||
} catch (e: any) {
|
||||
latByModel.value = { ...latByModel.value, [id]: { ok: false, latency_ms: null, error: (e && e.message) || String(e) } }
|
||||
} finally {
|
||||
latCurrentId.value = ''
|
||||
}
|
||||
}
|
||||
function latText(id: string): string {
|
||||
const row = latByModel.value[id]
|
||||
if (row) {
|
||||
if (row.ok) return row.latency_ms != null ? row.latency_ms + ' ms' : t('models.failed')
|
||||
return t('models.failed') // 完整错误在下方 st-err 整行展示,这里只留短标记
|
||||
}
|
||||
return '—' // 未轮到 / 空闲(当前正在测的行由模板的加载图标分支显示,不走这里)
|
||||
}
|
||||
function latErr(id: string): string {
|
||||
const row = latByModel.value[id]
|
||||
return row && !row.ok ? (row.error || '') : ''
|
||||
}
|
||||
function latCls(id: string): string {
|
||||
const row = latByModel.value[id]
|
||||
return row ? (row.ok ? 'ok' : 'err') : 'mute'
|
||||
}
|
||||
|
||||
const routes = computed(() => items.value.filter((x) => x.type === 'route'))
|
||||
const models = computed(() => items.value.filter((x) => x.type !== 'route'))
|
||||
|
||||
const providerOf = computed(() => {
|
||||
const m: Record<string, string> = {}
|
||||
for (const x of models.value) m[x.id] = x.provider_name || '—'
|
||||
return m
|
||||
})
|
||||
const visionOf = computed(() => {
|
||||
const m: Record<string, boolean> = {}
|
||||
for (const x of models.value) m[x.id] = !!x.vision
|
||||
return m
|
||||
})
|
||||
|
||||
const routeRows = computed(() =>
|
||||
routes.value.map((r) => {
|
||||
const chain: string[] = r.models || []
|
||||
return {
|
||||
name: r.id,
|
||||
models: chain.map((id) => ({ id, provider: providerOf.value[id] || '—', vision: visionOf.value[id] })),
|
||||
providerCount: new Set(chain.map((id) => providerOf.value[id] || '—')).size,
|
||||
}
|
||||
}),
|
||||
)
|
||||
const textModelRows = computed(() =>
|
||||
models.value.filter((x) => x.type === 'text').map((m) => ({
|
||||
id: m.id,
|
||||
provider: m.provider_name || '—',
|
||||
vision: !!m.vision,
|
||||
})),
|
||||
)
|
||||
|
||||
const keySet = computed(() => {
|
||||
const ks: Record<string, boolean> = {}
|
||||
for (const p of Object.values(health.value.providers || {}) as any) ks[p.name] = !!p.api_key_set
|
||||
return ks
|
||||
})
|
||||
const modelRows = computed(() => models.value.map((m) => ({ ...m, key_set: keySet.value[m.provider_name] })))
|
||||
|
||||
const providerRows = computed(() => {
|
||||
const p = health.value.providers || {}
|
||||
return Object.keys(p).map((k) => {
|
||||
const c = String(p[k].circuit || '').toUpperCase()
|
||||
return {
|
||||
name: p[k].name,
|
||||
models: p[k].models,
|
||||
keySet: !!p[k].api_key_set,
|
||||
cls: c === 'CLOSED' ? 'ok' : c === 'HALF_OPEN' ? 'warn' : c === 'OPEN' ? 'err' : 'mute',
|
||||
text: t(`dashboard.circ_${String(p[k].circuit || '').toLowerCase() || ''}`),
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const cards = computed(() => [
|
||||
{ k: t('models.model'), v: models.value.length, note: t('models.providerCount2', { n: providerRows.value.length }) },
|
||||
{ k: t('models.textModels'), v: models.value.filter((m) => m.type === 'text').length, note: t('models.visionTag') + ' · ' + models.value.filter((m) => m.vision).length },
|
||||
{ k: t('models.imageModels'), v: models.value.filter((m) => m.type === 'image').length, note: t('images.title') },
|
||||
{ k: t('models.routes'), v: routes.value.length, note: t('models.routeAliasTitle') },
|
||||
])
|
||||
|
||||
onMounted(async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const j = await api('/v1/models')
|
||||
items.value = j.data || []
|
||||
try { health.value = await api('/health') } catch { /* 可选 */ }
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
err.value = t('models.loadErr') + ': ' + ((e && e.message) || String(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.route-block { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
|
||||
.route-block:last-child { border-bottom: 0; }
|
||||
.route-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
|
||||
.route-name { font-weight: 700; color: var(--text); font-size: 13px; }
|
||||
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
|
||||
.chain-item { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.arrow { color: var(--muted-2); }
|
||||
.vision { color: var(--primary); }
|
||||
.prov { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
|
||||
.prov:last-child { border-bottom: 0; }
|
||||
.prov-top { display: flex; align-items: center; gap: 8px; }
|
||||
.prov-top b { font-size: 13px; }
|
||||
.prov-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; }
|
||||
.cap { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.st { margin-top: 8px; border-top: 1px dashed var(--line-2); padding-top: 6px; }
|
||||
.st-item { padding: 4px 0; }
|
||||
.st-item + .st-item { border-top: 1px dashed var(--line); }
|
||||
.st-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
|
||||
.st-err {
|
||||
display: flex; align-items: flex-start; gap: 6px;
|
||||
margin: 4px 2px 2px; padding: 6px 8px;
|
||||
border-radius: 8px;
|
||||
background: var(--err-soft);
|
||||
color: var(--err);
|
||||
font-size: 11.5px; line-height: 1.55;
|
||||
overflow-wrap: anywhere; /* 长错误(JSON / 无空格串)也能自动换行不溢出 */
|
||||
word-break: break-word;
|
||||
}
|
||||
.st-err-ico { flex: none; margin-top: 1px; color: var(--err); }
|
||||
.st-err-txt { flex: 1; min-width: 0; }
|
||||
/* 每个模型行右侧的「单独测速」图标按钮 */
|
||||
.st-one {
|
||||
flex: none; display: inline-flex; align-items: center; justify-content: center;
|
||||
width: 24px; height: 24px; padding: 0; margin-left: 2px;
|
||||
border: 1px solid var(--line); background: transparent; color: var(--muted);
|
||||
border-radius: 8px; cursor: pointer; transition: color .15s, border-color .15s, background .15s;
|
||||
}
|
||||
.st-one:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
|
||||
.st-one:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
/* 当前正在测的模型行:延迟位显示一个旋转加载图标 */
|
||||
.st-spin {
|
||||
display: inline-block; width: 12px; height: 12px; vertical-align: middle;
|
||||
border: 2px solid var(--line); border-top-color: var(--primary);
|
||||
border-radius: 50%; animation: st-spin 0.7s linear infinite;
|
||||
}
|
||||
@keyframes st-spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .st-spin { animation-duration: 1.6s; } }
|
||||
.st-title { font-weight: 600; color: var(--text); }
|
||||
.st-prov { flex: 1; }
|
||||
.st-lat { min-width: 88px; text-align: center; }
|
||||
.st-loading { font-style: italic; }
|
||||
.lat-head { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
|
||||
</style>
|
||||
@@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="card">
|
||||
<div class="ph-title">「{{ title }}」页面</div>
|
||||
<div class="ph-sub">该功能在后续里程碑开发(M2 对话 / M3 媒体 / M4 指标日志 等)。</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
const route = useRoute()
|
||||
const title = computed(() => (route.meta.title as string) || '')
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ph-title { font-size: 18px; font-weight: 600; }
|
||||
.ph-sub { color: var(--muted); margin-top: 8px; }
|
||||
</style>
|
||||
@@ -0,0 +1,324 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="mb" />
|
||||
|
||||
<div class="set-grid">
|
||||
<!-- 外观与语言:三张主题卡 + 跟随系统 + 语言 -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.appearance') }}</b>
|
||||
<span class="sub">{{ t('settings.themeSub') }}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="id in THEME_IDS"
|
||||
:key="id"
|
||||
class="theme-card"
|
||||
:class="{ on: theme === id }"
|
||||
@click="pickTheme(id)"
|
||||
>
|
||||
<div class="theme-prev">
|
||||
<span class="l" :style="{ background: THEME_META[id].side, borderRight: '1px solid var(--line)' }" />
|
||||
<span class="r" :style="{ background: THEME_META[id].canvas }">
|
||||
<i :style="{ background: THEME_META[id].accent, width: '70%' }" />
|
||||
<i :style="{ background: THEME_META[id].accent, opacity: .35 }" />
|
||||
<i :style="{ background: THEME_META[id].accent, opacity: .2, width: '60%' }" />
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<b>{{ t(THEME_META[id].nameKey) }}</b>
|
||||
<div class="hint">{{ t(THEME_META[id].descKey) }}</div>
|
||||
</div>
|
||||
<span v-if="theme === id" class="pill ok">{{ t('settings.current') }}</span>
|
||||
<span v-else class="chip-sel">{{ t('settings.switch') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div>
|
||||
<div class="lb">{{ t('settings.followSystem') }}</div>
|
||||
<div class="sub">{{ t('settings.followSub') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-switch :model-value="followSystem" @change="onFollow" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div>
|
||||
<div class="lb">{{ t('settings.language') }}</div>
|
||||
<div class="sub">{{ t('settings.langSub') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-radio-group :model-value="locale" size="small" @change="onLocale">
|
||||
<el-radio-button value="zh">中文</el-radio-button>
|
||||
<el-radio-button value="en">English</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 生成默认值:新建对话时的初始参数(Chat.vue 读同一份 localStorage) -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.chatDefaults') }}</b>
|
||||
<span class="sub">{{ t('settings.defsTip') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.defaultModel') }}</div>
|
||||
<div class="rt">
|
||||
<el-select v-model="defs.model" size="small" clearable :placeholder="t('chat.routeGroup')" style="width: 210px">
|
||||
<el-option v-for="m in textModels" :key="m" :label="m" :value="m" />
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.temperature') }}</div>
|
||||
<div class="rt">
|
||||
<el-input-number v-model="defs.temperature" size="small" :min="0" :max="2" :step="0.1" controls-position="right" style="width: 130px" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.topP') }}</div>
|
||||
<div class="rt">
|
||||
<el-input-number v-model="defs.top_p" size="small" :min="0" :max="1" :step="0.05" controls-position="right" style="width: 130px" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.maxTokens') }}</div>
|
||||
<div class="rt">
|
||||
<el-input-number v-model="defs.max_tokens" size="small" :min="1" :max="200000" :step="256" controls-position="right" style="width: 150px" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.streaming') }}</div>
|
||||
<div class="rt">
|
||||
<el-switch v-model="defs.stream" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row" style="align-items: flex-start">
|
||||
<div class="lb flex-1">
|
||||
{{ t('settings.system') }}
|
||||
<el-input v-model="defs.system" type="textarea" :rows="2" class="mt-8" :placeholder="t('chat.system')" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="op-row">
|
||||
<el-button type="primary" size="small" :loading="savingDefs" @click="saveDefs">{{ t('settings.save') }}</el-button>
|
||||
<el-button size="small" @click="resetDefs">{{ t('common.reset') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-grid mt">
|
||||
<!-- 账号与安全 -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.account') }}</b>
|
||||
<span class="sub">{{ store.user }}<template v-if="store.isAdmin"> · {{ t('common.admin') }}</template></span>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div class="flex-1">
|
||||
<div class="lb">{{ t('settings.changePw') }}</div>
|
||||
<div class="sub">{{ t('settings.pwTip') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-input
|
||||
v-model="pw.new"
|
||||
type="password"
|
||||
show-password
|
||||
size="small"
|
||||
style="width: 150px"
|
||||
:placeholder="t('settings.newPw')"
|
||||
@keyup.enter="savePw"
|
||||
/>
|
||||
<el-button type="primary" size="small" :loading="pw.saving" @click="savePw">{{ t('common.save') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div class="flex-1">
|
||||
<div class="lb">{{ t('settings.myKeys') }}</div>
|
||||
<div class="sub">{{ t('settings.myKeysSub') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-button size="small" @click="router.push('/keys')">{{ t('settings.manage') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-row">
|
||||
<div class="flex-1">
|
||||
<div class="lb">{{ t('common.logout') }}</div>
|
||||
<div class="sub">{{ t('settings.logoutTip') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-button size="small" type="danger" plain @click="doLogout">{{ t('settings.logoutBtn') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网关信息:只读快照。真要改网关参数走「网关配置」页(管理员,第二十三轮)。 -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.gwCard') }}</b>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.gwAddress') }}</div>
|
||||
<div class="rt code">{{ base }}</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.gwVersion') }}</div>
|
||||
<div class="rt">v{{ health.version || '-' }}</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('settings.sessionLen') }}</div>
|
||||
<div class="rt">{{ store.expiresIn ? t('settings.hours', { n: Math.round(store.expiresIn / 3600) }) : '—' }}</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('dashboard.inflight') }}</div>
|
||||
<div class="rt">{{ health.in_flight ?? '-' }} / {{ health.in_flight_peak ?? '-' }}</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lb">{{ t('dashboard.fallback') }}</div>
|
||||
<div class="rt">{{ health.fallback_total ?? 0 }}</div>
|
||||
</div>
|
||||
<div class="set-row" style="align-items: flex-start">
|
||||
<div class="lb">{{ t('settings.providerStatus') }}</div>
|
||||
<div class="rt" style="flex-wrap: wrap; justify-content: flex-end">
|
||||
<span v-for="p in providerRows" :key="p.name" class="pill" :class="p.cls">{{ p.name }} · {{ p.text }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二十三轮:管理员从这里跳去改配置(普通账号看不到这个入口);
|
||||
卡片本身也受 `GATEWAY_CONFIG_ENABLED` 管(老板要求暂时隐藏整块配置页)。 -->
|
||||
<div v-if="store.isAdmin && GATEWAY_CONFIG_ENABLED" class="set-row">
|
||||
<div class="flex-1">
|
||||
<div class="lb">{{ t('settings.gwConfig') }}</div>
|
||||
<div class="sub">{{ t('settings.gwConfigSub') }}</div>
|
||||
</div>
|
||||
<div class="rt">
|
||||
<el-button size="small" @click="router.push('/gateway-config')">{{ t('settings.gwConfigBtn') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { GATEWAY_CONFIG_ENABLED } from '../lib/features'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { computed } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { api } from '../api'
|
||||
import { useSessionStore } from '../store/session'
|
||||
import { setLocale } from '../i18n'
|
||||
import { getChatDefaults, setChatDefaults, type ChatDefaults } from '../lib/settings'
|
||||
import { useTheme, THEME_IDS, THEME_META, type ThemeId } from '../lib/theme'
|
||||
|
||||
const router = useRouter()
|
||||
const store = useSessionStore()
|
||||
const base = window.location.origin
|
||||
const health = ref<any>({})
|
||||
const err = ref('')
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const { theme, followSystem, setTheme, setFollowSystem } = useTheme()
|
||||
|
||||
const TEXT_MODELS = ['wjd', 'agnes-3.0-flash', 'ark-code-latest', 'qwen3.8-flash']
|
||||
const textModels = ref<string[]>(TEXT_MODELS)
|
||||
|
||||
function pickTheme(id: ThemeId) {
|
||||
setTheme(id)
|
||||
ElMessage.success(t('theme.applied') + ' · ' + t(THEME_META[id].nameKey))
|
||||
}
|
||||
function onFollow(v: string | number | boolean) { setFollowSystem(!!v) }
|
||||
function onLocale(l: string) { setLocale(l as 'zh' | 'en') }
|
||||
|
||||
// ── 生成默认值 ──────────────────────────────────────────────
|
||||
const defs = reactive<ChatDefaults>({ temperature: 0.7, top_p: 1, max_tokens: null, stream: true, system: '' })
|
||||
const savingDefs = ref(false)
|
||||
|
||||
function loadDefs() {
|
||||
const d = getChatDefaults()
|
||||
defs.model = d.model ?? 'wjd'
|
||||
defs.temperature = d.temperature ?? 0.7
|
||||
defs.top_p = d.top_p ?? 1
|
||||
defs.max_tokens = d.max_tokens ?? null
|
||||
defs.stream = d.stream !== false
|
||||
defs.system = d.system ?? ''
|
||||
}
|
||||
function saveDefs() {
|
||||
savingDefs.value = true
|
||||
try {
|
||||
setChatDefaults({ ...defs })
|
||||
ElMessage.success(t('settings.saveOk'))
|
||||
} finally {
|
||||
savingDefs.value = false
|
||||
}
|
||||
}
|
||||
function resetDefs() {
|
||||
setChatDefaults({})
|
||||
loadDefs()
|
||||
ElMessage.success(t('settings.resetOk'))
|
||||
}
|
||||
|
||||
// ── 账号 ────────────────────────────────────────────────────
|
||||
const pw = reactive({ new: '', saving: false })
|
||||
|
||||
// 已登录会话直接设新密码(老板要求免输旧密码),改完所有会话失效
|
||||
async function savePw() {
|
||||
if (!pw.new) { ElMessage.warning(t('settings.pwNeedNew')); return }
|
||||
pw.saving = true
|
||||
try {
|
||||
await api('/auth/password', { method: 'POST', body: JSON.stringify({ new_password: pw.new }) })
|
||||
ElMessage.success(t('settings.pwChanged'))
|
||||
pw.new = ''
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.body?.detail || (e && e.message) || String(e))
|
||||
} finally {
|
||||
pw.saving = false
|
||||
}
|
||||
}
|
||||
|
||||
async function doLogout() {
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
const providerRows = computed(() => {
|
||||
const p = health.value.providers || {}
|
||||
return Object.keys(p).map((k) => {
|
||||
const c = String(p[k].circuit || '').toUpperCase()
|
||||
const cls = c === 'CLOSED' ? 'ok' : c === 'HALF_OPEN' ? 'warn' : c === 'OPEN' ? 'err' : 'mute'
|
||||
return { name: p[k].name, cls, text: t(`dashboard.circ_${String(p[k].circuit || '').toLowerCase() || ''}`) }
|
||||
})
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
loadDefs()
|
||||
try {
|
||||
health.value = await api('/health')
|
||||
// 默认模型下拉用真实模型列表(拿不到就退回内置候选)
|
||||
try {
|
||||
const um = await api('/v1/models')
|
||||
const list = (um.data || []).filter((x: any) => x.type !== 'route').map((x: any) => x.id)
|
||||
if (list.length) textModels.value = ['wjd', ...list]
|
||||
} catch { /* 模型列表可选 */ }
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
err.value = t('settings.loadErr') + ': ' + ((e && e.message) || String(e))
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mt { margin-top: var(--gap); }
|
||||
.mt-8 { margin-top: 8px; }
|
||||
.op-row { display: flex; gap: 8px; margin-top: 14px; }
|
||||
</style>
|
||||
@@ -0,0 +1,446 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('settings.account') }}</b>
|
||||
<span class="sub">{{ users.length }} · {{ t('nav.subusers') }}</span>
|
||||
<div class="pager">
|
||||
<el-input v-model="q" size="small" class="search-inp" clearable :placeholder="t('common.search')">
|
||||
<template #prefix><Icon name="search" :size="14" /></template>
|
||||
</el-input>
|
||||
<el-button type="primary" size="small" @click="showCreate = true">
|
||||
<Icon name="plus" :size="14" />
|
||||
<span>{{ t('settings.createUser') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-if="users.length"
|
||||
:data="shown"
|
||||
size="default"
|
||||
row-key="name"
|
||||
:row-class-name="rowClass"
|
||||
:expand-row-keys="expanded"
|
||||
:empty-text="t('users.noData')"
|
||||
@expand-change="onExpand"
|
||||
>
|
||||
<el-table-column type="expand">
|
||||
<template #default="{ row }">
|
||||
<!-- 第十一轮 #2:admin 在此看该账号的调用日志 + 生成的图像/视频资产 -->
|
||||
<div class="expand-row" v-loading="act(row.name).loading">
|
||||
<el-tabs v-model="act(row.name).tab">
|
||||
<el-tab-pane :label="t('users.tabLogs')" name="logs">
|
||||
<el-table :data="act(row.name).logs" size="small" max-height="360"
|
||||
:empty-text="t('users.noData')">
|
||||
<el-table-column :label="t('logs.time')" width="92">
|
||||
<template #default="{ row: e }"><span class="code">{{ fmtClock(e.ts) }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('logs.result')" width="66">
|
||||
<template #default="{ row: e }">
|
||||
<el-tag :type="e.ok ? 'success' : 'danger'" size="small">{{ e.ok ? t('common.ok') : t('common.fail') }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('logs.path')" min-width="160">
|
||||
<template #default="{ row: e }"><span class="code">{{ e.method }} {{ e.path }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('logs.modelProvider')" min-width="140">
|
||||
<template #default="{ row: e }">
|
||||
<span class="code">{{ e.served || e.model || '—' }}</span>
|
||||
<span v-if="e.provider" class="at-prov">@ {{ e.provider }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('logs.respContent')" min-width="220">
|
||||
<template #default="{ row: e }">
|
||||
<span v-if="e.response" class="ellip" :title="e.response">{{ e.response }}</span>
|
||||
<span v-else-if="!e.ok" class="err-text ellip" :title="e.error">{{ e.error || '—' }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane :label="`${t('users.tabImages')} (${act(row.name).images.length})`" name="images">
|
||||
<div v-if="act(row.name).images.length" class="asset-grid">
|
||||
<div v-for="im in act(row.name).images" :key="im.id" class="asset-cell">
|
||||
<el-image :src="im.src" fit="cover" class="asset-thumb"
|
||||
:preview-src-list="act(row.name).images.map((x: any) => x.src).filter(Boolean)" :initial-index="0" preview-teleported />
|
||||
<div class="asset-cap ellip3" :title="im.prompt">{{ im.prompt || '—' }}</div>
|
||||
<div class="asset-meta code ellip">{{ im.served || im.model || '' }} · {{ fmtClock((im.ts || 0) / 1000) }}</div>
|
||||
<!-- 管理员代下载他人资产:产物在跨域 CDN 上,直链 <a download> 不生效,
|
||||
统一走后端 /v1/media/download 代拉,与图像/视频页同一个 lib/download.ts。 -->
|
||||
<el-button size="small" class="asset-dl"
|
||||
:loading="dlKey === 'i-' + im.id"
|
||||
@click="dlAsset(im.src, im.prompt, 'image', 'i-' + im.id)">
|
||||
<Icon name="dl" :size="14" />{{ t('users.dl') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else :image-size="60" :description="t('users.noData')" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane :label="`${t('users.tabVideos')} (${act(row.name).videos.length})`" name="videos">
|
||||
<div v-if="act(row.name).videos.length" class="asset-grid">
|
||||
<div v-for="vk in act(row.name).videos" :key="vk.id" class="asset-cell">
|
||||
<video v-if="vk.src" :src="vk.src" class="asset-thumb" controls preload="metadata" />
|
||||
<div v-else class="asset-thumb video-ph">
|
||||
<el-tag :type="vk.kind === 'fail' ? 'danger' : vk.kind === 'done' ? 'success' : 'info'" size="small">{{ vk.status || vk.kind }}</el-tag>
|
||||
</div>
|
||||
<div class="asset-cap ellip3" :title="vk.prompt">{{ vk.prompt || '—' }}</div>
|
||||
<div class="asset-meta code ellip">{{ vk.model || '' }} · {{ vk.elapsed ? vk.elapsed + 's' : '' }}</div>
|
||||
<el-button v-if="vk.src" size="small" class="asset-dl"
|
||||
:loading="dlKey === 'v-' + vk.id"
|
||||
@click="dlAsset(vk.src, vk.prompt, 'video', 'v-' + vk.id)">
|
||||
<Icon name="dl" :size="14" />{{ t('users.dl') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else :image-size="60" :description="t('users.noData')" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column :label="t('settings.userCol')" :min-width="isMobile ? 120 : 150">
|
||||
<template #default="{ row }">
|
||||
<div class="acc">
|
||||
<span class="avatar" :class="{ alt: row.name !== store.user }">{{ initial(row.name) }}</span>
|
||||
<span class="acc-nm">{{ row.name }}</span>
|
||||
<!-- 第二十四轮: 停用状态贴在账号名后(桌面/手机都看得见),悬停显示停用时间 -->
|
||||
<span v-if="row.disabled" class="pill warn" :title="row.disabled_at ? t('settings.userDisabledAt', { ts: fmtTs(row.disabled_at) }) : ''">
|
||||
{{ t('settings.userDisabled') }}
|
||||
</span>
|
||||
</div>
|
||||
<!-- 第十八轮: 手机上把「角色 / Key 数 / 创建时间」三列收进账号单元格,
|
||||
否则五列总宽 937px 在 390 屏上必须横滑,操作列根本看不到。 -->
|
||||
<div v-if="isMobile" class="acc-sub">
|
||||
<span class="pill" :class="row.role === 'admin' ? 'ok' : 'mute'">{{ row.role }}</span>
|
||||
<span class="nowrap muted">{{ row.api_key_count }} / {{ keyLimitText(row.role) }} {{ t('settings.keyCount') }}</span>
|
||||
<span v-if="atKeyLimit(row)" class="pill warn">{{ t('settings.keyLimitFull') }}</span>
|
||||
<span class="nowrap muted">{{ fmtTs(row.created) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="!isMobile" :label="t('settings.roleCol')" width="104">
|
||||
<template #default="{ row }">
|
||||
<span class="pill" :class="row.role === 'admin' ? 'ok' : 'mute'">{{ row.role }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<!-- Key 数:admin 不限,普通账号与后端 MAX_KEYS_PER_MEMBER 一致(3 把) -->
|
||||
<el-table-column v-if="!isMobile" :label="t('settings.keyCount')" width="136">
|
||||
<template #default="{ row }">
|
||||
<span class="nowrap">{{ row.api_key_count }} / {{ keyLimitText(row.role) }}</span>
|
||||
<span v-if="atKeyLimit(row)" class="pill warn">{{ t('settings.keyLimitFull') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="!isMobile" :label="t('settings.userCreated')" width="150">
|
||||
<template #default="{ row }"><span class="nowrap muted">{{ fmtTs(row.created) }}</span></template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column :min-width="isMobile ? 152 : 320" align="right">
|
||||
<!-- 第十八轮: 手机上操作列改图标按钮(文字版四颗要 ~320px,必然被挤出屏外) -->
|
||||
<template #default="{ row }">
|
||||
<div v-if="isMobile" class="ops">
|
||||
<el-tooltip :content="t('settings.resetPw')" placement="top">
|
||||
<el-button text type="primary" size="small" @click="resetPw(row.name)"><Icon name="key" :size="16" /></el-button>
|
||||
</el-tooltip>
|
||||
<!-- 管理员账号不可停用(唯一管理员被停用就没人能进管理页),故 admin 不给这颗按钮 -->
|
||||
<el-tooltip v-if="row.role !== 'admin'" :content="row.disabled ? t('settings.enableUser') : t('settings.disableUser')" placement="top">
|
||||
<el-button text :type="row.disabled ? 'success' : 'warning'" size="small" @click="toggleDisabled(row)">
|
||||
<Icon :name="row.disabled ? 'play' : 'ban'" :size="16" />
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="t('users.viewActivity')" placement="top">
|
||||
<el-button text size="small" @click="toggleActivity(row)"><Icon name="log" :size="16" /></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="t('settings.revokeKeys')" placement="top">
|
||||
<el-button text type="warning" size="small" :disabled="!row.api_key_count" @click="revokeKeys(row.name)"><Icon name="stop" :size="16" /></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip v-if="row.name !== store.user" :content="t('common.delete')" placement="top">
|
||||
<el-button text type="danger" size="small" @click="remove(row.name)"><Icon name="trash" :size="16" /></el-button>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<template v-else>
|
||||
<el-button text type="primary" size="small" @click="resetPw(row.name)">{{ t('settings.resetPw') }}</el-button>
|
||||
<!-- 第二十四轮: 停用/启用。停用后该账号不能登录、名下 API Key 一并失效,
|
||||
所以停用要二次确认;启用是无风险操作,点了就生效 -->
|
||||
<el-button v-if="row.role !== 'admin'" text :type="row.disabled ? 'success' : 'warning'" size="small"
|
||||
@click="toggleDisabled(row)">
|
||||
{{ row.disabled ? t('settings.enableUser') : t('settings.disableUser') }}
|
||||
</el-button>
|
||||
<el-button text size="small" @click="toggleActivity(row)">{{ t('users.viewActivity') }}</el-button>
|
||||
<el-button text type="warning" size="small" :disabled="!row.api_key_count" @click="revokeKeys(row.name)">
|
||||
{{ t('settings.revokeKeys') }}
|
||||
</el-button>
|
||||
<el-button v-if="row.name !== store.user" text type="danger" size="small" @click="remove(row.name)">
|
||||
{{ t('common.delete') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-empty v-else :description="t('common.none')" :image-size="80" />
|
||||
</div>
|
||||
|
||||
<!-- 新建账号:账号名 + 可选初始密码(与旧版行内输入等价,只是收进弹层) -->
|
||||
<el-dialog v-model="showCreate" :title="t('settings.createUser')" width="420px">
|
||||
<div class="field">
|
||||
<label>{{ t('settings.newUserName') }}</label>
|
||||
<el-input v-model="newUser" :placeholder="t('settings.newUserName')" clearable @keyup.enter="create" />
|
||||
</div>
|
||||
<div class="field dialog-f2">
|
||||
<label>{{ t('settings.userPwOptional') }}</label>
|
||||
<el-input v-model="newPw" type="password" show-password clearable
|
||||
:placeholder="t('settings.userPwOptional')" @keyup.enter="create" />
|
||||
</div>
|
||||
<div class="hint">{{ t('settings.newUserTip') }}</div>
|
||||
<template #footer>
|
||||
<el-button size="small" @click="showCreate = false">{{ t('common.cancel') }}</el-button>
|
||||
<el-button type="primary" size="small" :loading="creating" @click="create">{{ t('settings.createUser') }}</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { api, errText } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { downloadMedia, nameFromPrompt, stamp } from '../lib/download'
|
||||
import { useIsMobile } from '../lib/ui'
|
||||
import { useSessionStore } from '../store/session'
|
||||
|
||||
const { t } = useI18n()
|
||||
const store = useSessionStore()
|
||||
// 第十八轮: 窄屏把「角色/Key 数/创建时间」三列折进账号单元格、操作列改图标按钮,
|
||||
// 目的是让这张表在 390 宽下不用横滑(此前列总宽 937px,操作列在屏外)。
|
||||
const { isMobile } = useIsMobile()
|
||||
const users = ref<any[]>([])
|
||||
const newUser = ref('')
|
||||
const newPw = ref('')
|
||||
const creating = ref(false)
|
||||
const showCreate = ref(false)
|
||||
const q = ref('')
|
||||
|
||||
// 与 app/users.py 的 MAX_KEYS_PER_MEMBER / key_limit_for_role 对齐,仅用于展示 n / 3
|
||||
const MEMBER_KEY_LIMIT = 3
|
||||
|
||||
// 停用的账号整行压暗一点(一眼能看出哪些不能用了),但内容照常可读 —— 不是隐藏
|
||||
function rowClass({ row }: any): string {
|
||||
return row?.disabled ? 'row-off' : ''
|
||||
}
|
||||
|
||||
function keyLimitText(role: string): string {
|
||||
return role === 'admin' ? '∞' : String(MEMBER_KEY_LIMIT)
|
||||
}
|
||||
function atKeyLimit(row: any): boolean {
|
||||
return row.role !== 'admin' && Number(row.api_key_count || 0) >= MEMBER_KEY_LIMIT
|
||||
}
|
||||
function initial(name: string): string {
|
||||
return String(name || '?').slice(0, 1).toUpperCase()
|
||||
}
|
||||
|
||||
// ── 资产下载(管理员代下载他人生成的图/视频)──
|
||||
// 与图像页/视频页同一条路:产物在跨域 CDN 上(无 CORS 头、<a download> 对跨域无效),
|
||||
// 所以走后端 /v1/media/download 代拉再落盘;文件名用「提示词前缀 + 时间戳」。
|
||||
const dlKey = ref<string>('')
|
||||
async function dlAsset(src: string, prompt: string, kind: 'image' | 'video', key: string) {
|
||||
if (!src) { ElMessage.error(t('users.dlNoSrc')); return }
|
||||
dlKey.value = key
|
||||
try {
|
||||
await downloadMedia(src, `${nameFromPrompt(prompt, kind)}-${stamp()}`)
|
||||
ElMessage.success(t('users.dlOk'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('users.dlFail', { msg: e?.message || String(e) }))
|
||||
} finally {
|
||||
dlKey.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索只过滤本页已加载的账号列表(不发新请求)
|
||||
const shown = computed(() => {
|
||||
const s = q.value.trim().toLowerCase()
|
||||
if (!s) return users.value
|
||||
return users.value.filter((u) => String(u.name || '').toLowerCase().includes(s))
|
||||
})
|
||||
|
||||
// 每个账号的活动数据(日志 + 图像 + 视频),展开时懒加载一次
|
||||
type Activity = { loading: boolean; loaded: boolean; tab: string; logs: any[]; images: any[]; videos: any[] }
|
||||
const activity = reactive<Record<string, Activity>>({})
|
||||
function act(name: string): Activity {
|
||||
if (!activity[name]) {
|
||||
activity[name] = { loading: false, loaded: false, tab: 'logs', logs: [], images: [], videos: [] }
|
||||
}
|
||||
return activity[name]
|
||||
}
|
||||
const expanded = ref<string[]>([])
|
||||
|
||||
function fmtTs(ts: number): string {
|
||||
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())}`
|
||||
}
|
||||
function fmtClock(ts: number): string {
|
||||
if (!ts) return '—'
|
||||
const d = new Date(ts * 1000)
|
||||
const p = (n: number) => String(n).padStart(2, '0')
|
||||
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
|
||||
}
|
||||
|
||||
function err(e: any) {
|
||||
return errText(e) // 统一从 {error:{message}} / {detail} 两种信封里取原因(见 api.ts)
|
||||
}
|
||||
|
||||
async function ask(text: string) {
|
||||
try {
|
||||
await ElMessageBox.confirm(text, t('settings.confirm'), { type: 'warning' })
|
||||
return true
|
||||
} catch { return false }
|
||||
}
|
||||
|
||||
async function loadActivity(name: string) {
|
||||
const a = act(name)
|
||||
if (a.loaded) return
|
||||
a.loading = true
|
||||
try {
|
||||
const [lg, im, vd] = await Promise.all([
|
||||
api(`/auth/users/${encodeURIComponent(name)}/logs?n=200`),
|
||||
api(`/auth/users/${encodeURIComponent(name)}/history/images`),
|
||||
api(`/auth/users/${encodeURIComponent(name)}/history/videos`),
|
||||
])
|
||||
a.logs = lg.entries || []
|
||||
a.images = im.items || []
|
||||
a.videos = vd.items || []
|
||||
a.loaded = true
|
||||
} catch (e: any) {
|
||||
ElMessage.error(err(e))
|
||||
} finally { a.loading = false }
|
||||
}
|
||||
|
||||
async function onExpand(row: any, expandedRows: any) {
|
||||
const isOpen = Array.isArray(expandedRows) ? expandedRows.includes(row) : !!expandedRows
|
||||
expanded.value = isOpen ? [row.name] : expanded.value.filter((k) => k !== row.name)
|
||||
if (isOpen) await loadActivity(row.name)
|
||||
}
|
||||
|
||||
// 行内「查看活动」按钮:复用同一个展开回调(展开态仍由 expanded 驱动)
|
||||
function toggleActivity(row: any) {
|
||||
onExpand(row, !expanded.value.includes(row.name))
|
||||
}
|
||||
|
||||
async function load() {
|
||||
try { users.value = (await api('/auth/users')).users || [] } catch (e: any) { ElMessage.error(err(e)) }
|
||||
}
|
||||
|
||||
async function create() {
|
||||
const name = newUser.value.trim()
|
||||
if (!name) return
|
||||
creating.value = true
|
||||
try {
|
||||
const body: any = { username: name }
|
||||
if (newPw.value) body.password = newPw.value
|
||||
await api('/auth/users', { method: 'POST', body: JSON.stringify(body) })
|
||||
ElMessage.success(t('settings.createUser') + ': ' + name)
|
||||
newUser.value = ''
|
||||
newPw.value = ''
|
||||
showCreate.value = false
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(err(e)) }
|
||||
finally { creating.value = false }
|
||||
}
|
||||
|
||||
async function resetPw(name: string) {
|
||||
if (!await ask(t('settings.confirmResetPw', { name }))) return
|
||||
try {
|
||||
const j = await api(`/auth/users/${name}/password`, { method: 'POST', body: JSON.stringify({}) })
|
||||
ElMessage.success(t('settings.resetPwOk', { name, n: j.revoked_sessions ?? 0 }))
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(err(e)) }
|
||||
}
|
||||
|
||||
// 第二十四轮: 停用 / 启用账号(PUT /auth/users/{name}/disabled)
|
||||
// 停用后该账号 ①不能登录(密码正确也拒,服务端回 403 说明原因);②名下 API Key 立即失效
|
||||
// (Key 记录不删,重新启用即恢复);③已登录会话被立即踢掉。故停用要二次确认。
|
||||
async function toggleDisabled(row: any) {
|
||||
const name = String(row.name)
|
||||
const off = !row.disabled // off=true 表示本次要「停用」
|
||||
if (off && !await ask(t('settings.confirmDisableUser', { name }))) return
|
||||
try {
|
||||
const j = await api(`/auth/users/${encodeURIComponent(name)}/disabled`, {
|
||||
method: 'PUT', body: JSON.stringify({ disabled: off }),
|
||||
})
|
||||
if (j.disabled) ElMessage.success(t('settings.userDisabledOk', { name, n: j.revoked_sessions ?? 0 }))
|
||||
else ElMessage.success(t('settings.userEnabledOk', { name }))
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(err(e)) }
|
||||
}
|
||||
|
||||
async function revokeKeys(name: string) {
|
||||
if (!await ask(t('settings.confirmRevokeKeys', { name }))) return
|
||||
try {
|
||||
const j = await api(`/auth/users/${name}/apikeys`, { method: 'DELETE' })
|
||||
ElMessage.success(t('settings.revokeKeysOk', { name, n: j.revoked_keys ?? 0 }))
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(err(e)) }
|
||||
}
|
||||
|
||||
async function remove(name: string) {
|
||||
if (!await ask(t('settings.confirmDeleteUser', { name }))) return
|
||||
try {
|
||||
const j = await api(`/auth/users/${name}`, { method: 'DELETE' })
|
||||
ElMessage.success(t('settings.accountDeleted', { name, n: j.revoked_sessions ?? 0 }))
|
||||
delete activity[name]
|
||||
await load()
|
||||
} catch (e: any) { ElMessage.error(err(e)) }
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-inp { width: 180px; }
|
||||
.acc { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.acc-nm { color: var(--text); }
|
||||
/* 第二十四轮: 停用账号的名字压暗(状态靠旁边的「已停用」胶囊点明) */
|
||||
.row-off :deep(.acc-nm) { color: var(--muted-2); }
|
||||
/* 第十八轮: 手机端账号单元格的第二行(角色 / Key 数 / 创建时间) */
|
||||
.acc-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; font-size: 11.5px; }
|
||||
/* 手机端操作列:图标按钮一行排开,去掉 Element 相邻按钮的 12px 左边距。
|
||||
第二十四轮加「停用/启用」后这里变成 5 颗图标 —— 留 flex-wrap:万一某台机器上按钮宽
|
||||
超出操作列(152px)就换行,绝不让表格被撑宽、把操作列挤出屏外(第十八轮的老毛病)。 */
|
||||
.ops { display: flex; align-items: center; gap: 2px; row-gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
|
||||
.ops :deep(.el-button + .el-button) { margin-left: 0; }
|
||||
.ops :deep(.el-button) { padding: 6px; }
|
||||
.at-prov { color: var(--muted-2); margin-left: 4px; font-size: 11px; }
|
||||
.err-text { color: var(--err); }
|
||||
.ellip { display: inline-block; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
|
||||
.ellip3 {
|
||||
font-size: 12px; color: var(--text); line-height: 1.4;
|
||||
display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
|
||||
overflow: hidden; word-break: break-all;
|
||||
}
|
||||
.asset-grid { display: flex; flex-wrap: wrap; gap: 12px; }
|
||||
.asset-cell { width: 150px; }
|
||||
.asset-thumb {
|
||||
width: 150px; height: 110px; border-radius: 8px; display: block;
|
||||
background: var(--chip); border: 1px solid var(--line); object-fit: cover;
|
||||
}
|
||||
.video-ph { display: flex; align-items: center; justify-content: center; }
|
||||
.asset-cap { margin-top: 4px; }
|
||||
.asset-meta { color: var(--muted-2); margin-top: 2px; }
|
||||
/* 下载按钮放卡片底部整行(与图像/视频页一致),不做缩略图上的浮层:手机端不会挤变形 */
|
||||
.asset-dl { width: 100%; margin-top: 6px; }
|
||||
.dialog-f2 { margin-top: 12px; }
|
||||
.dialog-f2 + .hint { margin-top: 10px; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.search-inp { width: 100%; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,720 @@
|
||||
<template>
|
||||
<div class="page-fill">
|
||||
<div class="img-layout">
|
||||
<!-- 左:参数(固定 320px;窄屏自动落到上方单列) -->
|
||||
<div class="card param-card">
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('videos.model') }}</label>
|
||||
<el-select v-model="model" filterable class="fill">
|
||||
<el-option v-for="m in models" :key="m.id" :value="m.id" :label="`${m.id} · ${m.provider_name}`" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('videos.mode') }}</label>
|
||||
<div class="modes">
|
||||
<div class="mode" :class="{ on: mode === 'text' }" @click="mode = 'text'">
|
||||
{{ t('videos.modeText') }}<span class="mode-sub">text</span>
|
||||
</div>
|
||||
<div class="mode" :class="{ on: mode === 'keyframe' }" @click="mode = 'keyframe'">
|
||||
{{ t('videos.modeKeyframe') }}<span class="mode-sub">keyframe</span>
|
||||
</div>
|
||||
<div class="mode" :class="{ on: mode === 'reference' }" @click="mode = 'reference'">
|
||||
{{ t('videos.modeReference') }}<span class="mode-sub">reference</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row mb-field">
|
||||
<div class="field">
|
||||
<label>{{ t('videos.duration') }}</label>
|
||||
<!-- Agnes Video 2.5 Flash 文档: seconds 支持 "4"~"12"(3s 会被拒),默认 5 -->
|
||||
<el-select v-model="seconds" class="fill">
|
||||
<el-option v-for="s in durationOptions" :key="s" :value="String(s)" :label="`${s}s`" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t('videos.quality') }}</label>
|
||||
<!-- Flash 固定 720P(文档「size 仅支持字符串 720P」,其它值 HTTP 400)—— 只读展示 -->
|
||||
<div class="ctl dim">720P<span class="dim-tag">{{ t('videos.fixed') }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row mb-field">
|
||||
<div class="field">
|
||||
<label>{{ t('videos.aspect') }}</label>
|
||||
<el-select v-model="aspect" class="fill">
|
||||
<el-option v-for="a in ['21:9', '16:9', '4:3', '1:1', '3:4', '9:16']" :key="a" :value="a" :label="a" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t('videos.seed') }}</label>
|
||||
<el-input-number v-model="seed" :min="0" :max="4294967295" :controls="false"
|
||||
:placeholder="t('videos.seedPH')" class="fill" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('videos.promptRow') }}</label>
|
||||
<el-input v-model="prompt" type="textarea" :rows="3" resize="none" :placeholder="promptPlaceholder" :disabled="creating" />
|
||||
</div>
|
||||
|
||||
<!-- 第十三轮:首尾帧 / 参考素材 —— 支持直接上传(浏览器内压缩成 data URI),也支持粘 URL -->
|
||||
<div v-if="mode === 'keyframe'" class="field mb-field">
|
||||
<label>{{ t('videos.modeKeyframe') }}</label>
|
||||
<input ref="frameEl" type="file" accept="image/*" class="hide-file" @change="onFrameFiles" />
|
||||
|
||||
<div class="slot-row">
|
||||
<span class="slot-lb">{{ t('videos.firstFrame') }}</span>
|
||||
<el-button size="small" :disabled="creating" @click="pickFrame('first')">
|
||||
<Icon name="up" :size="14" />{{ t('videos.upload') }}
|
||||
</el-button>
|
||||
<el-input v-model="firstUrl" size="small" :placeholder="t('videos.urlPH')" clearable class="slot-u" />
|
||||
</div>
|
||||
<div v-if="firstSlot" class="slot-file" :title="firstSlot.name">
|
||||
<img :src="firstSlot.thumb || firstSlot.uri" alt="" />
|
||||
<span class="slot-name">{{ firstSlot.name }}</span>
|
||||
<span class="rm" @click="firstSlot = null"><Icon name="x" :size="11" /></span>
|
||||
</div>
|
||||
|
||||
<div class="slot-row">
|
||||
<span class="slot-lb">{{ t('videos.lastFrame') }}</span>
|
||||
<el-button size="small" :disabled="creating" @click="pickFrame('last')">
|
||||
<Icon name="up" :size="14" />{{ t('videos.upload') }}
|
||||
</el-button>
|
||||
<el-input v-model="lastUrl" size="small" :placeholder="t('videos.urlPH')" clearable class="slot-u" />
|
||||
</div>
|
||||
<div v-if="lastSlot" class="slot-file" :title="lastSlot.name">
|
||||
<img :src="lastSlot.thumb || lastSlot.uri" alt="" />
|
||||
<span class="slot-name">{{ lastSlot.name }}</span>
|
||||
<span class="rm" @click="lastSlot = null"><Icon name="x" :size="11" /></span>
|
||||
</div>
|
||||
|
||||
<div class="hint tip">{{ t('videos.keyframeTip') }}</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="mode === 'reference'" class="field mb-field">
|
||||
<label>{{ t('videos.modeReference') }}</label>
|
||||
<input ref="refImgEl" type="file" accept="image/*" multiple class="hide-file" @change="onRefImages" />
|
||||
<input ref="refAudEl" type="file" :accept="audioAccept" multiple class="hide-file" @change="onRefAudios" />
|
||||
|
||||
<div class="ref-btns">
|
||||
<el-button size="small" :disabled="creating" @click="refImgEl?.click()">
|
||||
<Icon name="up" :size="14" />{{ t('videos.uploadImg') }}
|
||||
</el-button>
|
||||
<el-button size="small" @click="showRefImgUrl = !showRefImgUrl">
|
||||
<Icon name="link" :size="14" />{{ t('videos.useUrl') }}
|
||||
</el-button>
|
||||
<span class="hint nowrap">{{ t('videos.count5', { n: refImgs.length }) }}</span>
|
||||
</div>
|
||||
<div v-if="refImgs.length" class="ref-thumbs">
|
||||
<div v-for="(r, i) in refImgs" :key="i" class="ref-thumb" :title="`${r.name} · ${formatBytes(dataUriBytes(r.uri))}`">
|
||||
<img :src="r.thumb || r.uri" alt="" />
|
||||
<span class="rm" @click="refImgs.splice(i, 1)"><Icon name="x" :size="11" /></span>
|
||||
<span class="rn">{{ i + 1 }}. {{ r.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-input v-if="showRefImgUrl" v-model="refImgUrls" type="textarea" :rows="2" resize="none"
|
||||
:placeholder="t('videos.refImagesPH')" :disabled="creating" class="ref-urls" />
|
||||
|
||||
<div class="ref-btns mt6">
|
||||
<el-button size="small" :disabled="creating" @click="refAudEl?.click()">
|
||||
<Icon name="up" :size="14" />{{ t('videos.uploadAudio') }}
|
||||
</el-button>
|
||||
<el-button size="small" @click="showRefAudUrl = !showRefAudUrl">
|
||||
<Icon name="link" :size="14" />{{ t('videos.useUrl') }}
|
||||
</el-button>
|
||||
<span class="hint nowrap">{{ t('videos.count3', { n: refAuds.length }) }}</span>
|
||||
</div>
|
||||
<div v-if="refAuds.length" class="ref-thumbs">
|
||||
<div v-for="(a, i) in refAuds" :key="i" class="ref-aud" :title="a.name">
|
||||
<Icon name="clip" :size="14" class="au-ico" />
|
||||
<span class="rn">{{ i + 1 }}. {{ a.name }} · {{ formatBytes(a.bytes) }}</span>
|
||||
<span class="rm" @click="refAuds.splice(i, 1)"><Icon name="x" :size="11" /></span>
|
||||
</div>
|
||||
</div>
|
||||
<el-input v-if="showRefAudUrl" v-model="refAudUrls" type="textarea" :rows="2" resize="none"
|
||||
:placeholder="t('videos.refAudiosPH')" :disabled="creating" class="ref-urls" />
|
||||
|
||||
<div class="hint tip">{{ t('videos.referenceTip') }}</div>
|
||||
<div class="hint tip">{{ t('videos.uploadTip') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="field async-row">
|
||||
<el-checkbox v-model="stream" :disabled="creating">{{ t('videos.async') }}</el-checkbox>
|
||||
</div>
|
||||
|
||||
<div class="param-foot">
|
||||
<el-alert v-if="err" :title="err" type="error" show-icon :closable="false" class="err-alert" />
|
||||
<el-button type="primary" class="go-btn" :loading="creating" :disabled="!prompt.trim()" @click="create">
|
||||
<Icon name="vid" :size="15" />{{ t('videos.generate') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右:任务列表(卡片自己撑满,滚动只发生在任务区) -->
|
||||
<div class="card result-card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('videos.taskTitle') }}</b>
|
||||
<span class="sub">{{ t('videos.taskCount', { n: tasks.length }) }}</span>
|
||||
<div class="pager">
|
||||
<span class="chip-sel" :class="{ on: filter === 'all' }" @click="filter = 'all'">{{ t('common.all') }}</span>
|
||||
<span class="chip-sel" :class="{ on: filter === 'doing' }" @click="filter = 'doing'">{{ t('videos.doingText') }}</span>
|
||||
<span class="chip-sel" :class="{ on: filter === 'done' }" @click="filter = 'done'">{{ t('videos.doneText') }}</span>
|
||||
<el-button size="small" class="nowrap" :disabled="!doneCount" @click="clearDone">{{ t('videos.clear') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="task-list">
|
||||
<!-- 第十九轮版式:左 16:9 缩略图 + 右三行紧凑信息(标题/状态 · 摘要行 · 任务号+操作)。
|
||||
原来是「小缩略图 + 5 行 key/value + 折叠栏 + 单占一行的按钮」,卡片被撑到 228px,
|
||||
缩略图下面空出 140px,看着散;状态还在胶囊(上游英文 completed)和正文(已生成)里说了两遍。 -->
|
||||
<div v-for="tk in shownTasks" :key="tk.id" class="vid-card" :class="'k-' + tk.kind">
|
||||
<div class="vid-thumb">
|
||||
<video v-if="tk.src" :src="tk.src" controls preload="metadata" class="vid-el" :poster="tk.poster || undefined"></video>
|
||||
<span v-else-if="tk.kind === 'pending'" class="spinner"></span>
|
||||
<Icon v-else :name="tk.kind === 'fail' ? 'x' : 'play'" :size="22" />
|
||||
</div>
|
||||
|
||||
<div class="vid-body">
|
||||
<div class="vid-head">
|
||||
<b class="t" :title="tk.prompt">{{ tk.prompt || tk.video_id }}</b>
|
||||
<span class="pill" :class="pillCls(tk.kind)">{{ stateShort(tk) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 摘要行:服务 · 耗时/等待 · 场景 挤成一行;失败时这里就是失败原因(原来藏在折叠里) -->
|
||||
<div class="s" :class="{ 's-err': tk.kind === 'fail' }" :title="tk.kind === 'fail' ? (tk.error || '') : ''">
|
||||
{{ subLine(tk) }}
|
||||
</div>
|
||||
<div v-if="tk.refs" class="s refs" :title="tk.refs">{{ tk.refs }}</div>
|
||||
|
||||
<!-- 进度条只在「生成中」出现:已完成的满格绿条 / 失败的红条像一条卡片分隔线,纯噪声 -->
|
||||
<div v-if="tk.kind === 'pending'" class="progress"><i class="bar-wait" /></div>
|
||||
|
||||
<div class="vid-foot">
|
||||
<span class="vid-k">{{ t('videos.task') }}</span>
|
||||
<span class="vid-id code" :title="tk.video_id">{{ tk.video_id }}</span>
|
||||
<div class="acts">
|
||||
<!-- 第十七轮: 下载。产物在跨域 CDN(不带 CORS 头)上,直链 <a download> 不生效,
|
||||
统一走后端 /v1/media/download 代拉,见 lib/download.ts。 -->
|
||||
<el-button v-if="tk.src" size="small" :loading="dlId === (tk.id ?? tk.video_id)" @click="dlVideo(tk)">
|
||||
<Icon name="dl" :size="14" />{{ t('videos.dl') }}
|
||||
</el-button>
|
||||
<!-- 「原始返回」改成内联按钮(原 el-collapse 独占一行还多一道边框),展开就在卡片底部 -->
|
||||
<el-button v-if="tk.error || tk.rawtext" size="small" text @click="toggleRaw(tk.id)">
|
||||
{{ t('videos.raw') }}<Icon :name="rawOpen(tk.id) ? 'chevD' : 'chev'" :size="14" />
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<pre v-if="rawOpen(tk.id)" class="raw-text">{{ tk.error || tk.rawtext }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-empty v-if="!shownTasks.length" :description="t('videos.empty')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { api } from '../api'
|
||||
import { findVideoUrl, videoStatusKind } from '../lib/media'
|
||||
import { downloadMedia, nameFromPrompt, stamp } from '../lib/download'
|
||||
import { pullHistory, pushHistory, deleteHistoryItem, ensureIds } from '../lib/history'
|
||||
import { pickImage, pickAudio, PRESETS, dataUriBytes, formatBytes, assertBodyBudget } from '../lib/upload'
|
||||
|
||||
interface VTask {
|
||||
id: number
|
||||
video_id: string
|
||||
model: string
|
||||
provider: string
|
||||
status: string
|
||||
kind: 'pending' | 'done' | 'fail'
|
||||
src: string
|
||||
poster: string
|
||||
started: number
|
||||
prompt?: string
|
||||
elapsed?: number
|
||||
mode?: string
|
||||
refs?: string // 素材摘要(文件名,不放 data URI —— 历史单条只有 16KB)
|
||||
retryAt?: number // 上游轮询被限流时,到这个时间点前不再问(避免撞 429)
|
||||
error?: string
|
||||
rawtext: string
|
||||
}
|
||||
|
||||
interface Slot { uri: string; name: string; thumb: string; bytes: number }
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const models = ref<any[]>([])
|
||||
const model = ref('')
|
||||
const prompt = ref('')
|
||||
const seconds = ref('5')
|
||||
const aspect = ref('16:9')
|
||||
const quality = ref('720P')
|
||||
const seed = ref<number | null>(null)
|
||||
// 第十一轮 #3:场景模式与对应素材
|
||||
const mode = ref<'text' | 'keyframe' | 'reference'>('text')
|
||||
const frameEl = ref<HTMLInputElement | null>(null)
|
||||
const refImgEl = ref<HTMLInputElement | null>(null)
|
||||
const refAudEl = ref<HTMLInputElement | null>(null)
|
||||
let frameTarget: 'first' | 'last' = 'first'
|
||||
const firstSlot = ref<Slot | null>(null)
|
||||
const lastSlot = ref<Slot | null>(null)
|
||||
const firstUrl = ref('')
|
||||
const lastUrl = ref('')
|
||||
const refImgs = ref<Slot[]>([]) // 参考图(最多 5,文档 images ≤ 5)
|
||||
const refAuds = ref<Slot[]>([]) // 参考音频(最多 3,文档 audios ≤ 3)
|
||||
const refImgUrls = ref('') // 每行一个 URL / data:
|
||||
const refAudUrls = ref('')
|
||||
const showRefImgUrl = ref(false)
|
||||
const showRefAudUrl = ref(false)
|
||||
const audioAccept = 'audio/*,.mp3,.wav,.m4a,.aac,.ogg,.flac,.opus'
|
||||
const durationOptions = [4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||
const stream = ref(true) // 异步提交,后台轮询
|
||||
const creating = ref(false)
|
||||
const err = ref('')
|
||||
const tasks = ref<VTask[]>([])
|
||||
// 已完成(含失败)的任务数:决定「清除已完成」是否可点 —— 没东西可清时按钮直接置灰,
|
||||
// 免得点了弹一个「确定要清除 0 个吗」的框。
|
||||
const doneCount = computed(() => tasks.value.filter((t) => t.kind !== 'pending').length)
|
||||
|
||||
// 任务列表筛选(纯展示:轮询与统计仍然针对全部任务,不裁剪原数组)
|
||||
const filter = ref<'all' | 'doing' | 'done'>('all')
|
||||
const shownTasks = computed(() => tasks.value.filter((tk) =>
|
||||
filter.value === 'all' ? true : filter.value === 'doing' ? tk.kind === 'pending' : tk.kind !== 'pending'))
|
||||
|
||||
// 把多行文本切成非空 URL 数组
|
||||
function toList(s: string): string[] {
|
||||
return (s || '').split(/\r?\n/).map((x) => x.trim()).filter(Boolean)
|
||||
}
|
||||
const promptPlaceholder = computed(() =>
|
||||
mode.value === 'reference' ? t('videos.placeholderRef') : t('videos.placeholder'))
|
||||
|
||||
const SKEY = 'gw_video_tasks' // 本地只当缓存,历史以服务端为准
|
||||
|
||||
function cacheLocal() {
|
||||
try { localStorage.setItem(SKEY, JSON.stringify(tasks.value)) } catch { /* 缓存写不进无所谓 */ }
|
||||
}
|
||||
async function save() {
|
||||
cacheLocal()
|
||||
// 视频任务原先因为 rawtext 太大把 localStorage 配额撑满、写失败又被静默吞掉 —— 这里必须报出来
|
||||
if (!(await pushHistory('videos', tasks.value))) ElMessage.warning(t('history.saveFail'))
|
||||
}
|
||||
async function load() {
|
||||
let local: VTask[] = []
|
||||
try {
|
||||
const j = JSON.parse(localStorage.getItem(SKEY) || '[]')
|
||||
if (Array.isArray(j)) local = j as VTask[]
|
||||
} catch { local = [] }
|
||||
const remote = await pullHistory('videos')
|
||||
if (remote === null) {
|
||||
tasks.value = local.map((t) => ({ ...t, kind: videoStatusKind(t.status) }))
|
||||
ElMessage.warning(t('history.offline'))
|
||||
return
|
||||
}
|
||||
if (remote.length) {
|
||||
tasks.value = remote.map((t: any) => ({ ...t, kind: videoStatusKind(t.status) }))
|
||||
} else if (local.length) {
|
||||
tasks.value = ensureIds(local, 'vid').map((t: any) => ({ ...t, kind: videoStatusKind(t.status) }))
|
||||
await pushHistory('videos', tasks.value) // 首次:把浏览器里的旧任务搬上服务端
|
||||
} else {
|
||||
tasks.value = []
|
||||
}
|
||||
cacheLocal()
|
||||
}
|
||||
|
||||
async function loadModels() {
|
||||
try {
|
||||
const j = await api('/v1/models')
|
||||
const all = (j.data || []).filter((x: any) => x.type === 'video')
|
||||
models.value = all
|
||||
if (all.length && !model.value) model.value = all[0].id
|
||||
} catch (e: any) {
|
||||
if (e && e.status === 401) { router.push('/login'); return }
|
||||
ElMessage.error(t('videos.loadErr') + ':' + ((e && e.message) || e))
|
||||
}
|
||||
}
|
||||
|
||||
// 卡片状态文案。注意参数别叫 t —— 那会遮蔽 i18n 的 t(),videos.failText 分支会当场抛错。
|
||||
// 第十九轮:胶囊里只放短状态(原来直接显示上游的 completed / failed 英文原样,
|
||||
// 而正文里又写一遍「已生成」,同一件事说两遍;失败原因挪到摘要行,仍可见)
|
||||
const stateShort = (tk: VTask) =>
|
||||
tk.kind === 'fail' ? t('videos.failText') : tk.kind === 'done' ? t('videos.doneText') : t('videos.doingText')
|
||||
|
||||
// 「生成中」已等待了多久(started 是毫秒时间戳;轮询每次刷新会重算)
|
||||
const waitSec = (tk: VTask) => (tk.started ? Math.max(0, Math.round((Date.now() - tk.started) / 1000)) : 0)
|
||||
|
||||
// 摘要行:服务 · 耗时/等待 · 场景,一行说完;失败时整行就是失败原因
|
||||
function subLine(tk: VTask): string {
|
||||
if (tk.kind === 'fail') return tk.error || t('videos.failText')
|
||||
const parts: string[] = []
|
||||
if (tk.provider) parts.push(tk.provider)
|
||||
if (tk.kind === 'done' && tk.elapsed) parts.push(t('videos.subElapsed', { n: tk.elapsed }))
|
||||
if (tk.kind === 'pending') { const w = waitSec(tk); if (w) parts.push(t('videos.subWait', { n: w })) }
|
||||
if (tk.mode) parts.push(modeLabel(tk.mode))
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
// 「原始返回」的展开态(内联按钮切换,替代原来的 el-collapse)
|
||||
const rawIds = ref<number[]>([])
|
||||
const rawOpen = (id: number) => rawIds.value.includes(id)
|
||||
function toggleRaw(id: number) {
|
||||
rawIds.value = rawIds.value.includes(id) ? rawIds.value.filter((x) => x !== id) : [...rawIds.value, id]
|
||||
}
|
||||
|
||||
const pillCls = (k: string) => (k === 'done' ? 'ok' : k === 'fail' ? 'err' : 'warn')
|
||||
|
||||
const modeLabel = (m: string) =>
|
||||
m === 'keyframe' ? t('videos.modeKeyframe') : m === 'reference' ? t('videos.modeReference') : t('videos.modeText')
|
||||
|
||||
// ── 素材上传(第十三轮)──
|
||||
function pickFrame(which: 'first' | 'last') {
|
||||
frameTarget = which
|
||||
frameEl.value?.click()
|
||||
}
|
||||
async function onFrameFiles(ev: Event) {
|
||||
const input = ev.target as HTMLInputElement
|
||||
const f = (input.files || [])[0]
|
||||
if (f) {
|
||||
try {
|
||||
// 首/尾帧会给到 1280px(画面直接进视频,比参考图要求更高)
|
||||
const m = await pickImage(f, PRESETS.frame)
|
||||
if (frameTarget === 'first') firstSlot.value = m
|
||||
else lastSlot.value = m
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('videos.pickErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
if (input) input.value = ''
|
||||
}
|
||||
async function onRefImages(ev: Event) {
|
||||
const input = ev.target as HTMLInputElement
|
||||
for (const f of Array.from(input.files || [])) {
|
||||
if (refImgs.value.length >= 5) { ElMessage.warning(t('videos.refMax', { n: 5 })); break }
|
||||
try {
|
||||
refImgs.value.push(await pickImage(f, PRESETS.videoRef))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('videos.pickErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
if (input) input.value = ''
|
||||
}
|
||||
async function onRefAudios(ev: Event) {
|
||||
const input = ev.target as HTMLInputElement
|
||||
for (const f of Array.from(input.files || [])) {
|
||||
if (refAuds.value.length >= 3) { ElMessage.warning(t('videos.audMax', { n: 3 })); break }
|
||||
try {
|
||||
refAuds.value.push(await pickAudio(f))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('videos.pickErr', { msg: (e && e.message) || e }))
|
||||
}
|
||||
}
|
||||
if (input) input.value = ''
|
||||
}
|
||||
/** 上传的 data URI 与手填 URL 合成上游字段(首/尾帧取其一:上传优先) */
|
||||
const firstFrame = computed(() => (firstSlot.value?.uri || firstUrl.value).trim())
|
||||
const lastFrame = computed(() => (lastSlot.value?.uri || lastUrl.value).trim())
|
||||
const imageList = computed(() => [...refImgs.value.map((r) => r.uri), ...toList(refImgUrls.value)])
|
||||
const audioList = computed(() => [...refAuds.value.map((r) => r.uri), ...toList(refAudUrls.value)])
|
||||
/** 卡片上展示的素材摘要(只存名字/数量,data URI 不进历史) */
|
||||
function mediaSummary(): string {
|
||||
if (mode.value === 'keyframe') {
|
||||
const names: string[] = []
|
||||
if (firstSlot.value) names.push(`首帧:${firstSlot.value.name}`)
|
||||
else if (firstUrl.value.trim()) names.push('首帧:URL')
|
||||
if (lastSlot.value) names.push(`尾帧:${lastSlot.value.name}`)
|
||||
else if (lastUrl.value.trim()) names.push('尾帧:URL')
|
||||
return names.join(' / ')
|
||||
}
|
||||
if (mode.value === 'reference') {
|
||||
const names: string[] = []
|
||||
refImgs.value.forEach((r, i) => names.push(`图${i + 1}:${r.name}`))
|
||||
if (toList(refImgUrls.value).length) names.push(`图URL×${toList(refImgUrls.value).length}`)
|
||||
refAuds.value.forEach((r, i) => names.push(`音${i + 1}:${r.name}`))
|
||||
if (toList(refAudUrls.value).length) names.push(`音URL×${toList(refAudUrls.value).length}`)
|
||||
return names.join(' / ')
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
async function create() {
|
||||
if (!prompt.value.trim() || creating.value) return
|
||||
// 第十一轮 #3:按模式做前端轻校验(后端也会挡,这里提前给反馈)
|
||||
if (mode.value === 'keyframe' && !firstFrame.value && !lastFrame.value) {
|
||||
err.value = t('videos.needFrame'); return
|
||||
}
|
||||
if (mode.value === 'reference' && !imageList.value.length && !audioList.value.length) {
|
||||
err.value = t('videos.needRef'); return
|
||||
}
|
||||
// 整包体积(素材 data URI + 正文)必须落在网关请求体上限内
|
||||
try {
|
||||
assertBodyBudget([prompt.value, firstFrame.value, lastFrame.value, ...imageList.value, ...audioList.value], 1200)
|
||||
} catch (e: any) {
|
||||
err.value = (e && e.message) || String(e); return
|
||||
}
|
||||
creating.value = true
|
||||
err.value = ''
|
||||
const t0 = Date.now()
|
||||
const summary = mediaSummary()
|
||||
try {
|
||||
const body: any = {
|
||||
model: model.value,
|
||||
prompt: prompt.value,
|
||||
seconds: seconds.value,
|
||||
size: quality.value,
|
||||
aspect_ratio: aspect.value,
|
||||
mode: mode.value,
|
||||
}
|
||||
if (seed.value != null) body.seed = seed.value
|
||||
if (mode.value === 'keyframe') {
|
||||
if (firstFrame.value) body.first_frame = firstFrame.value
|
||||
if (lastFrame.value) body.last_frame = lastFrame.value
|
||||
} else if (mode.value === 'reference') {
|
||||
if (imageList.value.length) body.images = imageList.value
|
||||
if (audioList.value.length) body.audios = audioList.value
|
||||
}
|
||||
if (!stream.value) body.wait = true // 同步等结果
|
||||
const j = await api('/v1/videos', { method: 'POST', body: JSON.stringify(body) })
|
||||
const task: VTask = {
|
||||
id: Date.now() + Math.random(), video_id: j.video_id || `unknown-${Date.now()}`,
|
||||
model: model.value, provider: j.provider_name || j.provider || '',
|
||||
status: j.status || 'submitted', kind: videoStatusKind(j.status || 'submitted'),
|
||||
src: '', poster: '', started: t0, rawtext: '',
|
||||
mode: mode.value,
|
||||
refs: summary || undefined,
|
||||
prompt: prompt.value.trim(), // 卡片下面要能回看当时填的提示词
|
||||
}
|
||||
if (j.final) {
|
||||
// 同步等待已返回最终 raw
|
||||
task.src = findVideoUrl(j.final)
|
||||
task.rawtext = JSON.stringify(j.final, null, 2)
|
||||
if (task.src) task.kind = 'done'
|
||||
}
|
||||
tasks.value.unshift(task)
|
||||
save()
|
||||
if (task.kind === 'done') {
|
||||
ElMessage.success(t('videos.doneMsg'))
|
||||
} else if (stream.value) {
|
||||
ElMessage.success(t('videos.submitMsg', { id: task.video_id }))
|
||||
}
|
||||
} catch (e: any) {
|
||||
// 第九轮: 优先展示后端给的人话(如「上游拒绝请求:size 必须是 720P 之一」)
|
||||
err.value = (e?.body?.detail) || e?.message || String(e)
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 轮询所有 pending 任务
|
||||
// 间隔保持 5s(不按文档建议的 1~2s):实测上游 /agnesapi 在 3s 一次的频率下就会
|
||||
// 回 429「查询过于频繁」,网关已把 429 折成 throttled(不报错、不计熔断),
|
||||
// 这里再退避一点,避免多个任务同时轮询把额度打满。
|
||||
async function poll() {
|
||||
const now = Date.now()
|
||||
for (const tk of tasks.value) {
|
||||
if (tk.kind !== 'pending') continue
|
||||
if (!tk.video_id || tk.video_id.startsWith('unknown')) continue
|
||||
if (tk.retryAt && tk.retryAt > now) continue
|
||||
try {
|
||||
const j = await api(`/v1/videos/${encodeURIComponent(tk.video_id)}?model=${encodeURIComponent(tk.model)}`)
|
||||
if (j && j.throttled) {
|
||||
// 上游限流:任务还在跑,这次只是没问到 —— 不算失败,也别把卡片显示成出错
|
||||
const wait = Number(j.retry_after) || 3
|
||||
tk.retryAt = Date.now() + wait * 1000
|
||||
continue
|
||||
}
|
||||
const st = j.status || 'pending'
|
||||
tk.status = st
|
||||
const k = videoStatusKind(st)
|
||||
if (k === 'done') {
|
||||
tk.src = findVideoUrl(j.raw)
|
||||
tk.rawtext = JSON.stringify(j.raw, null, 2)
|
||||
tk.elapsed = ((Date.now() - tk.started) / 1000) | 0
|
||||
} else if (k === 'fail') {
|
||||
tk.error = JSON.stringify(j.raw || j).slice(0, 300)
|
||||
}
|
||||
if (tk.src) tk.kind = 'done'
|
||||
else if (k === 'fail') tk.kind = 'fail'
|
||||
save()
|
||||
} catch (e: any) {
|
||||
// 任务暂不存在/仍提交中:不打断轮询,仅记住错误供展示
|
||||
tk.error = (e && e.message) || String(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function clearDone() {
|
||||
const gone = tasks.value.filter((t) => t.kind !== 'pending')
|
||||
if (!gone.length) return
|
||||
// 老板要求:清除已完成要二次确认 —— 这是服务端真删(不可逆),点错就没了。
|
||||
try {
|
||||
await ElMessageBox.confirm(t('videos.confirmClear', { n: gone.length }), t('common.confirm'),
|
||||
{ type: 'warning', confirmButtonText: t('common.delete'), cancelButtonText: t('common.cancel') })
|
||||
} catch { return }
|
||||
tasks.value = tasks.value.filter((t) => t.kind === 'pending')
|
||||
cacheLocal()
|
||||
// 逐条按 id 删,别整份覆盖(覆盖会把另一台设备刚生成的也抹掉)
|
||||
for (const tk of gone) {
|
||||
if (!(await deleteHistoryItem('videos', tk.id))) ElMessage.warning(t('history.saveFail'))
|
||||
}
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
onMounted(() => {
|
||||
load()
|
||||
loadModels()
|
||||
timer = setInterval(poll, 5000)
|
||||
})
|
||||
|
||||
// ── 第十七轮: 下载已生成的视频 ──
|
||||
// CDN 不给 CORS 头,所以由后端代拉(/v1/media/download)再落盘;文件名取
|
||||
// 「提示词前缀 + 时间戳」,后缀由后端按 Content-Type 补(默认 .mp4)。
|
||||
const dlId = ref<any>(null)
|
||||
async function dlVideo(tk: VTask) {
|
||||
if (!tk?.src) { ElMessage.error(t('videos.dlNoSrc')); return }
|
||||
dlId.value = tk.id ?? tk.video_id
|
||||
try {
|
||||
await downloadMedia(tk.src, `${nameFromPrompt(tk.prompt || '', 'video')}-${stamp()}`)
|
||||
ElMessage.success(t('videos.dlOk'))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(t('videos.dlFail', { msg: e?.message || String(e) }))
|
||||
} finally {
|
||||
dlId.value = null
|
||||
}
|
||||
}
|
||||
onUnmounted(() => clearInterval(timer))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 撑满高度的两栏:左参数卡、右任务卡;滚动只发生在各自内部 */
|
||||
.param-card { display: flex; flex-direction: column; overflow-y: auto; }
|
||||
.result-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
||||
.task-list { flex: 1; min-height: 0; overflow-y: auto; }
|
||||
|
||||
.mb-field { margin-bottom: 10px; }
|
||||
/* .field 天生是 flex:1(给 .form-row 横向用的)—— 在竖排卡片里必须收回,
|
||||
否则每个字段会纵向撑开,控件之间留下大片空白 */
|
||||
.param-card > .field { flex: none; }
|
||||
.fill { width: 100%; }
|
||||
.mt6 { margin-top: 8px; }
|
||||
.mode-sub { display: block; font-size: 10px; line-height: 1.3; color: var(--muted-2); margin-top: 1px; }
|
||||
.mode.on .mode-sub { color: var(--primary); opacity: .75; }
|
||||
/* 分辨率只读展示:半透明 + 「固定」说明 */
|
||||
.ctl.dim { opacity: .6; }
|
||||
.dim-tag { margin-left: auto; font-size: 11px; }
|
||||
.async-row { margin-top: 2px; }
|
||||
|
||||
.ref-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
/* 「上传 / 用 URL」文案不折行(窄列里被挤成两行是旧版的老毛病) */
|
||||
.ref-btns :deep(.el-button) { white-space: nowrap; }
|
||||
.hide-file { display: none; }
|
||||
.ref-urls { margin-top: 6px; }
|
||||
.ref-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
|
||||
.ref-thumb { position: relative; width: 68px; }
|
||||
.ref-thumb img { width: 68px; height: 68px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
|
||||
.ref-thumb .rn { display: block; font-size: 11px; color: var(--muted-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.ref-aud {
|
||||
position: relative; display: flex; align-items: center; gap: 6px; padding: 4px 22px 4px 8px;
|
||||
border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2);
|
||||
}
|
||||
.ref-aud .au-ico { color: var(--muted-2); }
|
||||
.ref-aud .rn { font-size: 12px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
.rm {
|
||||
position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
|
||||
display: grid; place-items: center; border-radius: 50%; cursor: pointer;
|
||||
background: var(--surface); border: 1px solid var(--line); color: var(--err);
|
||||
}
|
||||
.ref-aud .rm { top: 50%; right: 2px; transform: translateY(-50%); }
|
||||
|
||||
.slot-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
|
||||
.slot-lb { flex: 0 0 60px; font-size: 12px; color: var(--muted); }
|
||||
.slot-u { flex: 1 1 150px; min-width: 140px; }
|
||||
.slot-row :deep(.el-button) { white-space: nowrap; }
|
||||
.slot-file {
|
||||
position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 2px 6px;
|
||||
border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); margin-bottom: 8px;
|
||||
}
|
||||
.slot-file img { width: 30px; height: 30px; object-fit: cover; border-radius: 4px; display: block; }
|
||||
.slot-name { font-size: 12px; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tip { margin-top: 6px; line-height: 1.5; }
|
||||
|
||||
.param-foot { margin-top: auto; padding-top: 8px; }
|
||||
.err-alert { margin-bottom: 8px; }
|
||||
.go-btn { width: 100%; }
|
||||
|
||||
.pager { gap: 6px; flex-wrap: wrap; }
|
||||
.chip-sel { cursor: pointer; }
|
||||
.pager :deep(.el-button) { margin-left: 6px; }
|
||||
|
||||
/* 任务卡:缩略占位 + 右侧标题 / 状态 / 摘要 / 操作 */
|
||||
/* 第十九轮:卡片改成「缩略图垂直居中 + 右侧三行信息」的紧凑版式。
|
||||
信息压到 3 行(原来 5 行 key/value + 折叠栏 + 独占一行的按钮 = 228px 高的卡片,
|
||||
缩略图下方空 140px)。 */
|
||||
.vid-card { align-items: center; }
|
||||
.vid-card.k-fail { border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
|
||||
.vid-card .vid-thumb { overflow: hidden; }
|
||||
.vid-el { width: 100%; height: 100%; object-fit: contain; background: var(--surface-2); }
|
||||
.spinner {
|
||||
width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--primary);
|
||||
border-radius: 50%; animation: rot .8s linear infinite;
|
||||
}
|
||||
@keyframes rot { to { transform: rotate(360deg); } }
|
||||
.vid-body { flex: 1; min-width: 0; }
|
||||
.vid-head { display: flex; align-items: center; gap: 8px; }
|
||||
.vid-head .t {
|
||||
font-size: 13px; font-weight: 600; color: var(--text); min-width: 0;
|
||||
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
||||
}
|
||||
.vid-head .pill { margin-left: auto; }
|
||||
/* 摘要行:一行放不下就省略(原来换成 5 行 key/value,卡片高度翻倍) */
|
||||
.vid-card .s {
|
||||
font-size: 11.5px; color: var(--muted-2); margin-top: 3px;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.vid-card .s.refs { color: var(--muted); }
|
||||
.vid-card .s.s-err { color: var(--err); }
|
||||
.progress { height: 5px; }
|
||||
.bar-wait { width: 38%; background: var(--primary); animation: wait 1.4s ease-in-out infinite; }@keyframes wait { 0%, 100% { opacity: .35 } 50% { opacity: 1 } }
|
||||
/* 底部一行:任务号 + 操作按钮;窄屏放不下时按钮自动换到下一行 */
|
||||
.vid-foot { display: flex; align-items: center; gap: 8px; margin-top: 7px; flex-wrap: wrap; }
|
||||
.vid-k { color: var(--muted-2); flex: none; font-size: 12px; }
|
||||
.vid-id { color: var(--muted); flex: 1 1 auto; min-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.raw-text {
|
||||
white-space: pre-wrap; font-size: 11px; color: var(--muted); max-height: 160px; overflow-y: auto;
|
||||
background: var(--surface-2); padding: 6px; border-radius: 4px; border: 1px solid var(--line);
|
||||
margin: 7px 0 0;
|
||||
}
|
||||
.acts { display: flex; flex-wrap: wrap; gap: 7px; margin-left: auto; }
|
||||
.acts :deep(.el-button) { margin-left: 0; }
|
||||
|
||||
/* 窄屏:单列后整页滚动,两个卡片都恢复自然高度 */
|
||||
@media (max-width: 768px) {
|
||||
/* 窄屏单列后不再需要「撑满一屏」,改由 .gw-body 整页滚动 */
|
||||
.page-fill { height: auto; }
|
||||
.img-layout { height: auto; }
|
||||
.param-card { overflow: visible; }
|
||||
.result-card { flex: none; }
|
||||
.task-list { overflow: visible; }
|
||||
.card-h { flex-wrap: wrap; }
|
||||
.slot-lb { flex: 0 0 52px; }
|
||||
/* 第十八轮: 场景卡副标题原 10px,手机上太小(与底部 Tab 一起抬到 11.5px) */
|
||||
.mode-sub { font-size: 11.5px; }
|
||||
/* 第十九轮:窄屏下按钮会换到第二行,卡片本来就比 61px 的缩略图高一截,
|
||||
缩略图改为撑满卡片高度 + cover 裁切(与图像页缩略图 fit=cover 一致),
|
||||
左侧不再悬着一张 61px 高的小图、上下各空 45px。 */
|
||||
.vid-card .vid-thumb { align-self: stretch; height: auto; min-height: 61px; }
|
||||
.vid-el { object-fit: cover; }
|
||||
/* 场景卡的两列布局已上移到 style.css 的 .modes(原为「窄屏两列、桌面三列」,
|
||||
改后桌面也是两列 —— 桌面参数列只有 ~289px,三列每格 91px 放不下长标签)。 */
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// base 用 /web/:构建产物由网关挂载在同一源 /web 下,与 /v1 /auth /health 同源。
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
base: '/web/',
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
// 本地开发时把网关候选透到 8808
|
||||
'/v1': 'http://127.0.0.1:8808',
|
||||
'/auth': 'http://127.0.0.1:8808',
|
||||
'/health': 'http://127.0.0.1:8808',
|
||||
'/healthz': 'http://127.0.0.1:8808',
|
||||
'/metrics': 'http://127.0.0.1:8808',
|
||||
'/logs': 'http://127.0.0.1:8808',
|
||||
'/models': 'http://127.0.0.1:8808',
|
||||
// 第十八轮补: 此前缺 /history —— 本地开发时历史接口落到 vite 自己身上 404,
|
||||
// 页面弹「连不上服务端历史接口,暂时只用本机缓存显示」,看着像后端坏了。
|
||||
'/history': 'http://127.0.0.1:8808',
|
||||
// 第二十二轮: 意见反馈四个接口 —— 同样别让本地开发时落到 vite 自己身上
|
||||
// (表现为页面报「Unexpected token '<'」,看着像后端崩了,实则是拿到了 index.html)。
|
||||
'/feedback': 'http://127.0.0.1:8808',
|
||||
},
|
||||
},
|
||||
build: {
|
||||
// M5: 剩余超 500kB 的都是独立 vendor chunk(element-plus / echarts),缓存友好,
|
||||
// gzip 后约 340kB / 202kB。根因是 element-plus 全量引入,按需引入留作后续。
|
||||
chunkSizeWarningLimit: 1500,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// M5: 拆 vendor chunk,避免 element-plus/echarts/marked 打进单个入口超大 chunk。
|
||||
manualChunks: {
|
||||
'vendor-vue': ['vue', 'vue-router', 'pinia'],
|
||||
'vendor-element': ['element-plus', '@element-plus/icons-vue'],
|
||||
'vendor-echarts': ['echarts'],
|
||||
'vendor-markdown': ['marked', 'marked-highlight', 'dompurify', 'highlight.js'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user