feat: element plus UI组件库
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
041bb73b9a
commit
5f6fbcd76f
30 files changed
+3621
-1327
No files matched your search
@@ -0,0 +1,23 @@
|
||||
## 改动说明
|
||||
|
||||
<!-- 这次改了什么、为什么改。 -->
|
||||
|
||||
## 管理端界面
|
||||
|
||||
这次改动如果碰到管理控制台、知识库配置,或已经换成 Element Plus 的页面,按 `docs/ui/ELEMENT_MIGRATION.md` §6 核对。没改界面就删掉下面的清单。
|
||||
|
||||
- [ ] 只在该页入口引入 Element 样式和 `element-trial.css`,并用 `ElConfigProvider` 包住。
|
||||
- [ ] 列表骨架符合规范 §3,左右 32px 对齐,只有一层卡片。
|
||||
- [ ] 按钮符合规范 §4.1,没有 `size="small"` 和默认按钮混在一行。
|
||||
- [ ] 表格状态是 `ElTag`,单元格没有 `text-xs` / `text-sm` / `text-muted`。
|
||||
- [ ] 筛选框没有被拉成整行,空选项不是「请选择」。
|
||||
- [ ] 弹窗宽度只有 480px 或 680px,短表单不是整屏抽屉。
|
||||
- [ ] 加载遮罩只等列表请求,数据出来后遮罩消失。
|
||||
- [ ] 删除确认与本页其他确认框是同一种。
|
||||
- [ ] 四种语言下按钮、表头、空状态、分页都能读通。
|
||||
- [ ] `html.dark` 下边框、表头、弹窗底色跟着变量变。
|
||||
- [ ] `frontend` 下 `npx vue-tsc -b --pretty false` 通过。
|
||||
|
||||
## 测试
|
||||
|
||||
<!-- 怎么验证。 -->
|
||||
Vendored
+16
@@ -353,6 +353,22 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Frontend Lint') {
|
||||
when {
|
||||
expression { env.FRONTEND_CHANGED == 'true' }
|
||||
}
|
||||
steps {
|
||||
echo '[Frontend Lint] FRONTEND_CHANGED=true,执行 npm run lint(Element 规则当前为 off)'
|
||||
sh '''
|
||||
set -e
|
||||
docker run --rm \
|
||||
-v "${WORKSPACE}:/repo" \
|
||||
-w /repo \
|
||||
node:22-alpine sh -c "chmod +x scripts/ci_frontend_lint.sh && ./scripts/ci_frontend_lint.sh"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
// stage('Frontend Build (CI)') {
|
||||
// when {
|
||||
// expression { env.FRONTEND_CHANGED == 'true' }
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
| [features/](features/README.md) | **业务域**落地手册(部署、Dify、API、运维;**产品原型随域同目录**) |
|
||||
| [platform/](platform/README.md) | **平台级**设计与跨域原型(Agent 注册、进度底座、Runtime Context) |
|
||||
| [convention/](convention/) | 开发规范(提交、错误处理、环境变量、发布流程等) |
|
||||
| [ui/](ui/ELEMENT_MIGRATION.md) | 界面规范([设计系统](ui/DESIGN_SYSTEM.md)、[编码准则](ui/UI_CODING_GUIDELINES.md)、[Element 迁移](ui/ELEMENT_MIGRATION.md)) |
|
||||
| [skills/](skills/README.md) | Cursor Agent Skills 团队说明([i18n](skills/add-i18n-keys-skill.md)、[发布说明](skills/release-notes-skill.md)) |
|
||||
| [openapi/](openapi/) | Dify / 集成 OpenAPI 契约 |
|
||||
| [dify/](dify/) | Dify 集成说明 |
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
# Element Plus 迁移规范
|
||||
|
||||
> **用途**:管理端页面从手写 Tailwind 控件换成 Element Plus 时的唯一操作说明。后续每换一页,按本文做,不要再单页发明一套间距、字号或按钮写法。
|
||||
> **适用**:管理控制台里已经或即将换成 Element 的列表、筛选、表格、表单弹窗。
|
||||
> **不适用**:对话、文档画布、冻结列宽表(订单交期回复、发货审核等)。这些仍走 [UI_CODING_GUIDELINES.md](./UI_CODING_GUIDELINES.md),不要在同一块界面里混用两套按钮和输入框。
|
||||
> **试点**:用户管理、应用配置、知识库分组。列表和短弹窗已按本文收过。应用配置的创建/编辑表单内部还没换完,见 §8。新页面以本文为准。
|
||||
|
||||
旧页面在换完之前,继续遵守 [UI_CODING_GUIDELINES.md](./UI_CODING_GUIDELINES.md)。换到 Element 的那一块,以本文为准。
|
||||
|
||||
---
|
||||
|
||||
## 1. 接入方式
|
||||
|
||||
按页面接入,不在 `main.ts` 里 `app.use(ElementPlus)`,也不要全局注册全部组件。
|
||||
|
||||
每个改为 Element 的页面(或该页专用弹窗)需要:
|
||||
|
||||
1. 按名字导入用到的组件,例如 `ElButton`、`ElTable`、`ElDialog`。
|
||||
2. 引入样式(页面入口引一次即可,弹窗跟页面走,不必再引):
|
||||
|
||||
```ts
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
```
|
||||
|
||||
3. 用 `useElementProvider()` 取出 `elementLocale`,页面根上包 `ElConfigProvider`。亮暗靠现有 `html.dark` 加上面的暗色变量文件,不要在组件里再切一套主题算法。
|
||||
4. 使用 `v-loading` 时,在 `<script setup>` 里写 `const vLoading = ElLoading.directive`。
|
||||
5. 文案继续用现有 i18n key。新增文案必须同时补齐 zh-CN / zh-TW / en / th。
|
||||
6. 图标用 `@element-plus/icons-vue`,放进 `ElButton` 的 `icon` 属性。不要再把 `lucide-vue-next` 的图标塞进 Element 按钮。
|
||||
|
||||
`element-trial.css` 是管理端 Element 的公共皮肤,只放变量和与 Tailwind 共存的修正。某一页的列宽、筛选框宽度不要写进这个文件。
|
||||
|
||||
---
|
||||
|
||||
## 2. 先写入变量,再换页面
|
||||
|
||||
下面这些变量已经写在 `frontend/src/features/admin/styles/element-trial.css` 的 `:root, html.dark` 里。Element 暗色表在 `html.dark` 上另有一份默认值,所以必须和亮色写在一起,后引入的文件才能盖过它。页面不要再各写一套字号和颜色。
|
||||
|
||||
| 变量 | 对齐到 | 用途 |
|
||||
| --- | --- | --- |
|
||||
| `--el-font-family` | 已设为 PingFang SC / Microsoft YaHei | 控件字体 |
|
||||
| `--el-color-primary` | 已设为 `#0284c7` | 主按钮、链接、聚焦边框 |
|
||||
| `--el-font-size-large` | `18px`(现有 `.section-title`) | 页标题若改用 Element 排版时使用 |
|
||||
| `--el-font-size-base` | `14px` | 正文、按钮、输入框、表格单元格 |
|
||||
| `--el-font-size-small` | `13px` | 次要说明、统计 |
|
||||
| `--el-font-size-extra-small` | `12px` | 标签、辅助提示 |
|
||||
| `--el-text-color-primary` | `var(--text-primary)` | 标题、强调 |
|
||||
| `--el-text-color-regular` | `var(--text-secondary)` | 正文 |
|
||||
| `--el-text-color-secondary` | `var(--text-muted)` | 说明、表头、统计 |
|
||||
| `--el-text-color-placeholder` | `var(--text-muted)` | 占位符 |
|
||||
| `--el-border-color` | `var(--border-default)` | 输入框、分割线 |
|
||||
| `--el-border-color-light` / `--el-border-color-lighter` | `var(--border-subtle)` | 表格线、弱分割 |
|
||||
| `--el-bg-color` | `var(--bg-surface)` | 弹窗、表格底 |
|
||||
| `--el-fill-color-light` | `var(--bg-surface-soft)` | 表头底 |
|
||||
| `--el-border-radius-base` | `8px` | 按钮、输入框、标签 |
|
||||
| `--el-component-size` | `32px` | 默认按钮、输入框、下拉的高度 |
|
||||
|
||||
页面里禁止再用 `text-xs`、`text-sm`、`text-[13px]`、`font-semibold`、`text-primary`、`text-muted` 去改 Element 控件内部或表格单元格的字号和颜色。单元格需要强调时,用 Element 的字重变量或标签,不要回到 Tailwind 字号。
|
||||
|
||||
暗色只改上述变量在 `html.dark` 下的取值。不要写 `dark:` 工具类。
|
||||
|
||||
---
|
||||
|
||||
## 3. 列表页骨架(只有这一套)
|
||||
|
||||
```text
|
||||
section.admin-table-section 一张圆角卡片,页面上只此一层
|
||||
标题栏 section-title + section-desc + 右侧 ElSpace 按钮
|
||||
筛选条 一行控件,底部分隔线
|
||||
ElTable 表头用 Element 灰底,左右内边距与标题栏一致
|
||||
分页 右对齐,上边一条分隔线
|
||||
```
|
||||
|
||||
约定:
|
||||
|
||||
- 标题用 `.section-title`,说明用 `.section-desc`。不要在知识库这种页面单独写 `text-xl font-bold`。
|
||||
- 左右内边距统一 `32px`(标题、筛选、表格首列/末列、分页同一条边)。
|
||||
- 筛选和表格之间用一条 `var(--el-border-color-lighter)` 分隔。表头保留 Element 浅灰底,作为第二层分界。不要再在卡片里套一张卡片。
|
||||
- 统计数字放在筛选行右侧,不要单独占一行贴在表头上。
|
||||
- 分页用 `ElPagination`,`layout="total, sizes, prev, pager, next"`,`background`。页码和每页条数绑定现有的页码状态,不要另写一套 `PaginationBar`。
|
||||
|
||||
---
|
||||
|
||||
## 4. 组件怎么用
|
||||
|
||||
### 4.1 按钮
|
||||
|
||||
| 位置 | 写法 |
|
||||
| --- | --- |
|
||||
| 页头主操作(新建、创建) | `ElButton type="primary"`,带 `icon` |
|
||||
| 页头次操作(刷新、设置、跳转) | 默认 `ElButton`,带 `icon` |
|
||||
| 行内编辑、查看 | `ElButton link type="primary"` |
|
||||
| 行内删除 | `ElButton link type="danger"` |
|
||||
| 弹窗取消 | 默认 `ElButton` |
|
||||
| 弹窗确定 | `ElButton type="primary"`,提交中加 `:loading` |
|
||||
|
||||
同一工具栏里不要出现 `size="small"` 的实心按钮和默认高度按钮混排。行内有文字就用链接按钮,不要再做小图标方钮。没有文字、只能放图标时,必须带 i18n 的 `title`。
|
||||
|
||||
危险操作不要用绿色、蓝色按钮。测试、启用这类状态按钮用 `ElTag` 表达状态,操作本身仍按上表。
|
||||
|
||||
### 4.2 表格
|
||||
|
||||
- 必须设 `row-key`。
|
||||
- 空数据用 `:empty-text`,文案用已有 i18n key。
|
||||
- 状态列一律 `ElTag effect="light"`。启用 `success`,停用 `info`,警告 `warning`。不要自绘圆点,不要用 `bg-green-500` 这类 Tailwind 色。
|
||||
- 表头背景、边框色走 §2 的变量,单页不要再覆盖 `--el-table-header-bg-color`。
|
||||
- 列用 `min-width`。操作列固定 `width`,`align="right"`。
|
||||
- 服务端排序用 `sortable="custom"`,在现有的排序函数里改页码并重新请求。不要表格本地排一遍、接口再排一遍。
|
||||
- 头像不要用默认 `ElAvatar`(会变成灰色)。用户头像继续用现有品牌渐变圆标。
|
||||
|
||||
### 4.3 筛选
|
||||
|
||||
- `ElInput`、`ElSelect` 默认 `width: 100%`。必须放在限定宽度的容器里,搜索框约 `16rem`,下拉按最长文案定宽(约 `11rem`),靠左排,禁止用 `1fr` 把搜索框拉满整行。
|
||||
- 「全部 / 所有部门」这类空条件用 `placeholder` 表达。`ElSelect` 的值不要用空字符串,空着时传 `undefined`,清空后写回 `''`。否则会显示 Element 默认的「请选择」。
|
||||
- 少量互斥筛选(全部 / 有文档 / 空分组)用 `ElRadioGroup` + `ElRadioButton`,选项值用业务枚举,不要用 `label` 当值。
|
||||
- 窗口变窄时换行,不要每个控件各占一整行。
|
||||
|
||||
### 4.4 弹窗和表单
|
||||
|
||||
- 用 `ElDialog`,`align-center`,`append-to-body`,`:close-on-click-modal="false"`。
|
||||
- 短表单(大约 4 个字段以内)宽度 `480px`,一列。字段多或本来就是两列的,宽度 `680px`。不要用整屏高的抽屉装两个字段。
|
||||
- `ElForm` 使用 `label-position="top"`。
|
||||
- 标题用 `ElDialog` 的 `title`。说明放在对应 `ElFormItem` 里,字号走 §2,不要写 `text-xs text-muted`。
|
||||
- 多行文本用 `ElInput type="textarea"`,行数按内容来,一般 4 行。不要把 `.el-textarea__inner` 的边框清掉,那一层就是输入框的边框。
|
||||
- 提交按钮使用 `:loading`,防止重复提交。提交过程中不允许点遮罩关闭。
|
||||
- 只有从屏幕侧边滑出、且内容确实很长时才用 `ElDrawer`。创建、编辑这种短表单用对话框。
|
||||
|
||||
### 4.5 反馈
|
||||
|
||||
- `v-loading` 只盖住表格,并且只等列表自己的请求。目录、用户、排程等弹窗依赖放到列表返回之后再拉,不能让遮罩一直盖住已经画出来的行。
|
||||
- 删除、不可逆操作统一用 `ElMessageBox.confirm`,按钮文案和提示用现有 i18n。同一页不要同时留着 `DeleteConfirmDialog` 和 `ElMessageBox`。旧确认框在改该页时一起换掉。
|
||||
- 操作成功或失败用 `useMessage()`。需要留在页面上的结果才用 `ElAlert`。
|
||||
|
||||
### 4.6 语言
|
||||
|
||||
`useElementProvider` 已映射 zh-CN、zh-TW、en、th。新页面把 `elementLocale` 传给 `ElConfigProvider`,不要在某个弹窗里写死 `zh-cn`。
|
||||
|
||||
---
|
||||
|
||||
## 5. 不要这样做
|
||||
|
||||
- 不要在 `main.ts` 全量注册 Element。
|
||||
- 不要在同一工具栏里混用 `.btn-primary` 和 `ElButton`。
|
||||
- 不要用 `!important` 压 Tailwind。Element 是静态 CSS,用更具体的选择器。单行输入框内部的蓝竖线,只重置 `.el-input__inner`,见 `element-trial.css`。
|
||||
- 不要改全局 `svg { display }`。按钮图标的横向排列只写在 `element-trial.css` 的 `.el-button` 上。
|
||||
- 不要新增第二套组件库,也不要在已换 Element 的页面里再手写一套输入框样式。
|
||||
- 不要为了换皮去改接口、分页协议和权限判断。
|
||||
|
||||
---
|
||||
|
||||
## 6. 单页检查清单
|
||||
|
||||
换完一页,逐项核对:
|
||||
|
||||
- [ ] 只在该页入口引入 Element 样式和 `element-trial.css`,并用 `ElConfigProvider` 包住。
|
||||
- [ ] 列表骨架符合 §3,左右 32px 对齐,只有一层卡片。
|
||||
- [ ] 按钮符合 §4.1,没有 `size="small"` 和默认按钮混在一行。
|
||||
- [ ] 表格状态是 `ElTag`,单元格没有 `text-xs` / `text-sm` / `text-muted`。
|
||||
- [ ] 筛选框没有被拉成整行,空选项不是「请选择」。
|
||||
- [ ] 弹窗宽度只有 480px 或 680px,短表单不是整屏抽屉。
|
||||
- [ ] 加载遮罩只等列表请求,数据出来后遮罩消失。
|
||||
- [ ] 删除确认与本页其他确认框是同一种。
|
||||
- [ ] 四种语言下按钮、表头、空状态、分页都能读通。
|
||||
- [ ] `html.dark` 下边框、表头、弹窗底色跟着变量变。
|
||||
- [ ] `frontend` 下 `npx vue-tsc -b --pretty false` 通过。
|
||||
|
||||
改管理端界面时,把这份清单写进合并请求描述。模板在 [`.gitee/PULL_REQUEST_TEMPLATE.md`](../../.gitee/PULL_REQUEST_TEMPLATE.md)。ESLint 规则仍是关闭的,间距、弹窗宽度和暗色要靠这份清单看。
|
||||
|
||||
---
|
||||
|
||||
## 7. 和 Tailwind 共存时已经踩过的问题
|
||||
|
||||
| 现象 | 原因 | 处理 |
|
||||
| --- | --- | --- |
|
||||
| 按钮里图标和文字分成两行 | Tailwind preflight 把 `svg` 设成 `display: block` | 只在 `.el-button` 上改为横向 flex,已写在 `element-trial.css` |
|
||||
| 搜索框聚焦时内部多两条蓝竖线 | `@tailwindcss/forms` 给内部 `input` 加了边框 | 只重置 `.el-input__inner` 的边框和阴影 |
|
||||
| 多行输入框看起来没有边框 | 上一行修正误伤了 `.el-textarea__inner` | 文本域保留 Element 的内阴影边框 |
|
||||
| 筛选框每个占满一行 | `ElInput` / `ElSelect` 默认 `width: 100%` | 外层限定宽度,靠左排列 |
|
||||
| 下拉显示「请选择」 | 空字符串不是合法选项值 | 空值用 `undefined`,清空写回 `''`,文案放 `placeholder` |
|
||||
| 列表已经出来,页面仍一直转圈 | `v-loading` 绑在整页,要等用户、排程等全部返回 | 遮罩只绑列表请求 |
|
||||
| 头像变成灰色 | `ElAvatar` 默认底色 | 继续用品牌渐变圆标 |
|
||||
|
||||
---
|
||||
|
||||
## 8. 试点页和本规范的差距
|
||||
|
||||
新页面不要复制这些差距。改到对应页时收口。
|
||||
|
||||
| 页面 | 状态 |
|
||||
| --- | --- |
|
||||
| 用户管理 | 列表、筛选、三个业务弹窗、删除和改角色确认已按 §3、§4 对齐。筛选宽度和两列表单写在页面里。 |
|
||||
| 知识库分组 | 列表骨架、行内链接按钮、删除确认、创建分组、Dify 设置和健康检查已对齐。 |
|
||||
| 应用配置 | 列表、状态标签、测试弹窗、授权弹窗和删除确认已对齐。创建/编辑弹窗外壳是 680px `ElDialog`,内部字段仍是 `input-field` 和 lucide 图标。下一步只改这个弹窗内部,不要连带改保存接口。 |
|
||||
|
||||
---
|
||||
|
||||
## 9. 检测规则
|
||||
|
||||
ESLint 已经装在 `frontend`,配置是 `frontend/eslint.config.js`,规则是 `frontend/eslint-rules/no-legacy-admin-controls.js`。规则名 `hxops/no-legacy-admin-controls`,**当前严重级别是 `off`**。`npm run build` 和提交钩子不跑它。
|
||||
|
||||
`frontend/` 有改动时,Jenkins 阶段 `Frontend Lint` 会执行 `scripts/ci_frontend_lint.sh`(`npm ci` 然后 `npm run lint`)。规则仍是 `off`,这一阶段现在应当通过。生产构建阶段仍是注释掉的,lint 不在 `npm run build` 里面。
|
||||
|
||||
手动查看时,在 `frontend` 目录执行:
|
||||
|
||||
```bash
|
||||
npm run lint
|
||||
```
|
||||
|
||||
规则关闭时,这条命令应通过,不会因为历史 `<button>` 失败。
|
||||
|
||||
### 9.1 查什么
|
||||
|
||||
启用之后,检查这些文件的**全文**(不只是本次 diff):
|
||||
|
||||
- `frontend/src/features/admin/**/*.vue`
|
||||
- `frontend/src/features/kb/components/KbAdminPanel.vue`
|
||||
- `frontend/src/features/kb/components/KbGroupDrawer.vue`
|
||||
|
||||
命中下面任一写法就失败:
|
||||
|
||||
- `<button>`、`<input>`、`<select>`、`<textarea>`
|
||||
- 样式类 `btn-primary`、`btn-secondary`、`btn-ghost`、`btn-danger`、`input-field`、`select-field`
|
||||
- 从 `lucide-vue-next` 引入图标
|
||||
|
||||
对话、文档画布、冻结列表格不在上述路径里,不会被这条规则扫到。`DeleteConfirmDialog` 在 `shared/components`,也不在范围内;那个组件按自己的迁移任务换。
|
||||
|
||||
### 9.2 后期如何启用
|
||||
|
||||
等上述路径里的页面都已按本文换成 Element,再打开规则。提前打开会把尚未迁移的管理页全部判失败。
|
||||
|
||||
1. 打开 `frontend/eslint.config.js`,把 `hxops/no-legacy-admin-controls` 从 `'off'` 改为 `'error'`。
|
||||
2. 在 `frontend` 执行 `npm run lint`,修到通过。
|
||||
3. 把 `npm run lint` 接到 CI。仍然不要写进 `npm run build`,构建和风格检查分开。
|
||||
4. 若以后有新的管理端 Vue 不在 §9.1 的路径里,把路径补进 `eslint.config.js` 的 `files`。禁止列表以规则文件为准,不要在文档和脚本里各写一份不同的类名。
|
||||
5. 同时启用编辑器规则:打开 `.cursor/rules/element-admin-ui.mdc`,按文件里的说明加上 `globs`。现在这份规则没有 `globs`,并且 `alwaysApply` 是 false,不会在打开管理端文件时自动套用。
|
||||
|
||||
启用后是整文件检查。已迁移文件里再补原生按钮也会失败,不需要再维护「只查新增行」的名单。
|
||||
|
||||
---
|
||||
|
||||
## 10. 建议的切换顺序
|
||||
|
||||
1. §2 的变量已写入 `element-trial.css`。换下一页之前,在暗色下打开一张已换页面,看按钮、表格和弹窗是否跟着令牌变。
|
||||
2. 三个试点的列表和短弹窗已按 §6 收过。还剩应用配置创建/编辑表单内部,换完它再进下一页。
|
||||
3. 之后每个管理端列表按 §6 的清单换,一页一次。合并请求用 `.gitee/PULL_REQUEST_TEMPLATE.md` 里的清单。换完再开下一页。
|
||||
4. §9.1 路径里的页面都换完后,按 §9.2 把 ESLint 规则改成 `error` 并接到 CI。
|
||||
5. 对话、文档画布、冻结列表格不在本顺序里。
|
||||
@@ -3,6 +3,7 @@
|
||||
> **用途**:新功能、改版、修 UI 时必读。给 AI 写需求时,可将本文 **§0 Prompt 片段** 与 **§1 铁律** 一并粘贴进任务说明。
|
||||
> **架构详解**:见 [DESIGN_SYSTEM.md](./DESIGN_SYSTEM.md)。
|
||||
> **样式实现**:`frontend/src/styles/tokens.css`、`utilities.css`、`components-ds.css`、`style.css`。
|
||||
> **管理端换 Element Plus**:正在迁移的列表和弹窗以 [ELEMENT_MIGRATION.md](./ELEMENT_MIGRATION.md) 为准。未迁移的页面仍用本文的按钮和输入框。同一块界面不要混用两套。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* frontend/eslint-rules/no-legacy-admin-controls.js
|
||||
* 用途:管理端 Vue 里禁止再写原生表单控件、旧按钮样式和 lucide 图标。
|
||||
* 依赖:vue-eslint-parser 提供的 VElement、VAttribute,以及脚本里的 ImportDeclaration。
|
||||
* 逻辑:由 eslint.config.js 以 hxops/no-legacy-admin-controls 挂上。当前严重级别为 off。
|
||||
* 改为 error 的步骤见 docs/ui/ELEMENT_MIGRATION.md §9。
|
||||
*/
|
||||
|
||||
const LEGACY_TAGS = new Set(['button', 'input', 'select', 'textarea']);
|
||||
const LEGACY_CLASSES = [
|
||||
'btn-primary',
|
||||
'btn-secondary',
|
||||
'btn-ghost',
|
||||
'btn-danger',
|
||||
'input-field',
|
||||
'select-field',
|
||||
];
|
||||
|
||||
/**
|
||||
* 判断属性是不是 class 或 :class。
|
||||
* 核心逻辑:静态 class 的 key 是 VIdentifier;绑定 class 的 key 是 VDirectiveKey,参数名才是 class。
|
||||
* @param key vue-eslint-parser 的属性键节点
|
||||
* @returns 是 class 绑定则为 true
|
||||
*/
|
||||
function isClassAttribute(key) {
|
||||
if (key?.type === 'VIdentifier') return key.name === 'class';
|
||||
return key?.type === 'VDirectiveKey' && key.argument?.name === 'class';
|
||||
}
|
||||
|
||||
/** @type {import('eslint').Rule.RuleModule} */
|
||||
const rule = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: '管理端界面使用 Element Plus,不再新增原生控件和旧样式类',
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
tag: '管理端请使用 Element Plus,不要新增 <{{name}}>。见 docs/ui/ELEMENT_MIGRATION.md。',
|
||||
klass: '管理端请使用 Element Plus,不要新增样式类 {{name}}。见 docs/ui/ELEMENT_MIGRATION.md。',
|
||||
lucide: '管理端按钮图标请使用 @element-plus/icons-vue,不要新增 lucide-vue-next。',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
const templateVisitor = {
|
||||
VElement(node) {
|
||||
const name = node.rawName || node.name;
|
||||
if (!LEGACY_TAGS.has(name)) return;
|
||||
context.report({ node, messageId: 'tag', data: { name } });
|
||||
},
|
||||
VAttribute(node) {
|
||||
if (!isClassAttribute(node.key)) return;
|
||||
const raw = context.sourceCode.getText(node);
|
||||
for (const name of LEGACY_CLASSES) {
|
||||
if (!raw.includes(name)) continue;
|
||||
context.report({ node, messageId: 'klass', data: { name } });
|
||||
}
|
||||
},
|
||||
};
|
||||
const scriptVisitor = {
|
||||
ImportDeclaration(node) {
|
||||
if (node.source?.value !== 'lucide-vue-next') return;
|
||||
context.report({ node, messageId: 'lucide' });
|
||||
},
|
||||
};
|
||||
|
||||
// 模板节点不会出现在脚本的遍历里,必须交给 vue-eslint-parser 分开访问。
|
||||
const defineTemplateBodyVisitor = context.sourceCode.parserServices?.defineTemplateBodyVisitor;
|
||||
if (typeof defineTemplateBodyVisitor === 'function') {
|
||||
return defineTemplateBodyVisitor(templateVisitor, scriptVisitor);
|
||||
}
|
||||
return scriptVisitor;
|
||||
},
|
||||
};
|
||||
|
||||
export default rule;
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* frontend/eslint.config.js
|
||||
* 用途:前端 ESLint 配置。目前只挂管理端 Element 迁移规则,且严重级别为 off。
|
||||
* 依赖:vue-eslint-parser、typescript-eslint、eslint-rules/no-legacy-admin-controls.js。
|
||||
* 逻辑:npm run lint 会加载本文件,但不会因为历史原生控件失败。
|
||||
* 启用步骤见 docs/ui/ELEMENT_MIGRATION.md §9。不要把 lint 接进 npm run build。
|
||||
*/
|
||||
import vueParser from 'vue-eslint-parser';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import noLegacyAdminControls from './eslint-rules/no-legacy-admin-controls.js';
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: ['dist/**', 'node_modules/**', 'coverage/**'],
|
||||
},
|
||||
{
|
||||
files: [
|
||||
'src/features/admin/**/*.vue',
|
||||
'src/features/kb/components/KbAdminPanel.vue',
|
||||
'src/features/kb/components/KbGroupDrawer.vue',
|
||||
],
|
||||
languageOptions: {
|
||||
parser: vueParser,
|
||||
parserOptions: {
|
||||
parser: tseslint.parser,
|
||||
extraFileExtensions: ['.vue'],
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
hxops: {
|
||||
rules: {
|
||||
'no-legacy-admin-controls': noLegacyAdminControls,
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
// 启用时改为 'error'。步骤见 docs/ui/ELEMENT_MIGRATION.md §9。
|
||||
'hxops/no-legacy-admin-controls': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
Generated
+1461
-4
File diff suppressed because it is too large.
Load diff
@@ -7,15 +7,18 @@
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint .",
|
||||
"test:unit": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@tailwindcss/forms": "^0.5.11",
|
||||
"@tailwindcss/typography": "^0.5.19",
|
||||
"@vue-office/docx": "^1.6.3",
|
||||
"@vue-office/excel": "^1.7.14",
|
||||
"@vue-office/pdf": "^1.6.5",
|
||||
"cron-parser": "^5.5.0",
|
||||
"element-plus": "^2.14.7",
|
||||
"highlight.js": "^11.11.1",
|
||||
"html2pdf.js": "^0.14.0",
|
||||
"lucide-vue-next": "^0.575.0",
|
||||
@@ -37,12 +40,16 @@
|
||||
"@vue/test-utils": "^2.4.11",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"autoprefixer": "^10.4.24",
|
||||
"eslint": "^10.12.0",
|
||||
"eslint-plugin-vue": "^10.11.1",
|
||||
"jsdom": "^29.1.1",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.71.2",
|
||||
"vite": "^8.0.0-beta.13",
|
||||
"vitest": "^4.1.8",
|
||||
"vue-eslint-parser": "^10.4.1",
|
||||
"vue-tsc": "^3.1.5"
|
||||
},
|
||||
"overrides": {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* features/admin/composables/useElementProvider.ts
|
||||
* 用途:管理端 Element Plus 试点的界面语言。
|
||||
* 依赖:element-plus locale、vue-i18n。
|
||||
* 逻辑:UsersPage、AgentsPage、KbAdminPanel 把 elementLocale 传给 ElConfigProvider;亮暗靠 html.dark 与 Element 暗色变量,不在这里重复切换。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import zhTw from 'element-plus/es/locale/lang/zh-tw';
|
||||
import en from 'element-plus/es/locale/lang/en';
|
||||
import th from 'element-plus/es/locale/lang/th';
|
||||
|
||||
const ELEMENT_LOCALES = {
|
||||
'zh-CN': zhCn,
|
||||
'zh-TW': zhTw,
|
||||
en,
|
||||
th,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 取当前界面语言对应的 Element Plus 语言包。
|
||||
* 核心逻辑:未知语言回退简体中文。
|
||||
* @returns elementLocale,随 vue-i18n 语言变化
|
||||
*/
|
||||
export function useElementProvider() {
|
||||
const { locale } = useI18n();
|
||||
|
||||
const elementLocale = computed(() => {
|
||||
const key = locale.value as keyof typeof ELEMENT_LOCALES;
|
||||
return ELEMENT_LOCALES[key] ?? zhCn;
|
||||
});
|
||||
|
||||
return { elementLocale };
|
||||
}
|
||||
@@ -2,22 +2,35 @@
|
||||
* features/admin/modules/agents/AgentsPage.vue
|
||||
*
|
||||
* 用途:管理控制台的应用管理页,提供应用列表、创建/编辑弹窗、测试与授权入口。
|
||||
* 依赖:useAgentsAdmin 业务编排、AgentFormModal/AgentTestModal/AgentPermissionModal 弹窗。
|
||||
* 逻辑:页面加载后拉取应用/用户/排程数据;权限组启用后隐藏按人授权按钮。
|
||||
* 依赖:useAgentsAdmin 业务编排、Element Plus 表格与按钮、AgentFormModal/AgentTestModal/AgentPermissionModal 弹窗。
|
||||
* 逻辑:页面加载后先展示应用列表;目录、用户和排程在后台补齐。权限组启用后隐藏按人授权按钮。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted } from 'vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Bot, Plus, SquarePen, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { Plus } from '@element-plus/icons-vue';
|
||||
import {
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElEmpty,
|
||||
ElLoading,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import AgentFormModal from './components/AgentFormModal.vue';
|
||||
import AgentPermissionModal from './components/AgentPermissionModal.vue';
|
||||
import AgentTestModal from './components/AgentTestModal.vue';
|
||||
import { useAgentsAdmin } from './composables/useAgentsAdmin';
|
||||
import { useAgentsTableColumnResize } from './composables/useAgentsTableColumnResize';
|
||||
import type { AgentRow } from '@/features/admin/types/agent.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const {
|
||||
agents,
|
||||
@@ -44,8 +57,7 @@ const {
|
||||
permissionAgent,
|
||||
permissionUserIds,
|
||||
rolesConfigured,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
rolesChecked,
|
||||
loadAll,
|
||||
resetForm,
|
||||
selectAgent,
|
||||
@@ -63,23 +75,8 @@ const {
|
||||
openPermissionModal,
|
||||
togglePermissionUser,
|
||||
savePermissions,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
} = useAgentsAdmin();
|
||||
|
||||
const {
|
||||
columnWidths,
|
||||
tableMinWidth,
|
||||
startColumnResize,
|
||||
resetColumnWidths,
|
||||
} = useAgentsTableColumnResize();
|
||||
|
||||
const tableHeaderColumns = computed(() => [
|
||||
{ key: 'name', label: t('admin.agent.headers.name'), align: 'left' as const },
|
||||
{ key: 'status', label: t('admin.agent.headers.status'), align: 'left' as const },
|
||||
{ key: 'actions', label: t('admin.agent.headers.actions'), align: 'right' as const },
|
||||
]);
|
||||
|
||||
/* 列表仅展示名称、状态和操作;类型/聚合/配置仍由编辑弹窗维护。 */
|
||||
const formatAgentCode = (agent: AgentRow) => agent.agent_code || 'generic';
|
||||
|
||||
@@ -153,6 +150,23 @@ const openEditDialog = (agent: Parameters<typeof selectAgent>[0]): void => {
|
||||
showFormDialog.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 点击表格行时打开编辑弹窗。
|
||||
* 核心逻辑:Element 行对象按 id 找回完整应用,避免把表格行类型直接交给 selectAgent。
|
||||
*/
|
||||
const onRowClick = (row: { id?: number }): void => {
|
||||
const agent = agents.value.find((item) => item.id === row.id);
|
||||
if (agent) openEditDialog(agent);
|
||||
};
|
||||
|
||||
/**
|
||||
* 当前选中应用的行样式。
|
||||
* 核心逻辑:编辑弹窗打开前,用 selectedAgentId 给对应行加上浅底。
|
||||
*/
|
||||
const agentRowClass = ({ row }: { row: AgentRow }): string => (
|
||||
selectedAgentId.value === row.id ? 'agents-row-selected' : ''
|
||||
);
|
||||
|
||||
/**
|
||||
* 保存应用表单,成功后关闭弹窗。
|
||||
* 核心逻辑:submitAgent 会处理校验、接口调用和列表刷新;仅在返回 true 时收起弹窗。
|
||||
@@ -168,134 +182,73 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section class="admin-table-section min-h-64">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.agent.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDialog">
|
||||
{{ t('admin.agent.new') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.agent.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-primary" @click="openCreateDialog">
|
||||
<Plus class="w-5 h-5" />
|
||||
<span class="font-medium">{{ t('admin.agent.new') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<div v-if="agents.length === 0" class="admin-table-empty">
|
||||
<Bot class="w-12 h-12 mx-auto text-muted mb-3" />
|
||||
<p class="text-lg text-secondary">{{ t('admin.agent.noAgents') }}</p>
|
||||
</div>
|
||||
<table
|
||||
v-else
|
||||
class="admin-table agent-list-table table-fixed w-full"
|
||||
:style="{ minWidth: `${tableMinWidth}px` }"
|
||||
>
|
||||
<colgroup>
|
||||
<col
|
||||
v-for="(width, index) in columnWidths"
|
||||
:key="`col-${index}`"
|
||||
:style="{ width: `${width}px` }"
|
||||
/>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
v-for="(column, index) in tableHeaderColumns"
|
||||
:key="column.key"
|
||||
class="relative px-4 py-3 text-xs"
|
||||
:class="column.align === 'right' ? 'text-right' : 'text-left'"
|
||||
>
|
||||
<span class="truncate pr-2">{{ column.label }}</span>
|
||||
<button
|
||||
v-if="index < tableHeaderColumns.length - 1"
|
||||
type="button"
|
||||
class="agent-col-resize-handle"
|
||||
:title="t('admin.agent.resizeColumn')"
|
||||
@mousedown.prevent="startColumnResize(index, $event)"
|
||||
@dblclick.prevent="resetColumnWidths"
|
||||
/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="group cursor-pointer"
|
||||
:class="{ 'bg-blue-50/50': selectedAgentId === agent.id }"
|
||||
@click="openEditDialog(agent)"
|
||||
<ElEmpty v-if="!isLoading && agents.length === 0" :description="t('admin.agent.noAgents')" />
|
||||
<ElTable
|
||||
v-else
|
||||
v-loading="isLoading"
|
||||
:data="agents"
|
||||
row-key="id"
|
||||
class="agents-element-table hx-admin-table"
|
||||
:row-class-name="agentRowClass"
|
||||
@row-click="onRowClick"
|
||||
>
|
||||
<ElTableColumn :label="t('admin.agent.headers.name')" min-width="280">
|
||||
<template #default="{ row }">
|
||||
<p class="truncate" :title="(row as AgentRow).name">
|
||||
{{ (row as AgentRow).name }}
|
||||
</p>
|
||||
<p
|
||||
v-if="(row as AgentRow).description"
|
||||
class="truncate hx-element-hint"
|
||||
:title="(row as AgentRow).description"
|
||||
>
|
||||
{{ (row as AgentRow).description }}
|
||||
</p>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.agent.headers.status')" width="140">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="(row as AgentRow).is_active ? 'success' : 'info'" effect="light">
|
||||
{{ (row as AgentRow).is_active ? t('admin.status.active') : t('admin.status.disabled') }}
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.agent.headers.actions')" min-width="280" align="right">
|
||||
<template #default="{ row }">
|
||||
<div class="inline-flex items-center justify-end" @click.stop>
|
||||
<ElButton link type="primary" @click="openEditDialog(row as AgentRow)">
|
||||
{{ t('admin.edit') }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="rolesChecked && !rolesConfigured"
|
||||
link
|
||||
type="primary"
|
||||
@click="openPermissionModal(row as AgentRow)"
|
||||
>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p class="truncate text-sm font-semibold text-primary" :title="agent.name">{{ agent.name }}</p>
|
||||
<p
|
||||
v-if="agent.description"
|
||||
class="truncate text-xs text-muted"
|
||||
:title="agent.description"
|
||||
>
|
||||
{{ agent.description }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<span
|
||||
class="inline-flex w-fit items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium"
|
||||
:class="agent.is_active ? 'border-green-100 bg-green-50 text-green-700' : 'border-default bg-surface-soft text-secondary'"
|
||||
>
|
||||
<span class="h-1.5 w-1.5 shrink-0 rounded-full" :class="agent.is_active ? 'bg-green-500' : 'bg-surface-strong'" />
|
||||
{{ agent.is_active ? t('admin.status.active') : t('admin.status.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle text-right">
|
||||
<div class="inline-flex items-center justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap rounded-lg bg-blue-50 px-3 py-2 text-sm font-medium text-blue-600 transition-all hover:bg-blue-100"
|
||||
:title="t('admin.edit')"
|
||||
@click.stop="openEditDialog(agent)"
|
||||
>
|
||||
<SquarePen class="w-4 h-4 shrink-0" />
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!rolesConfigured"
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center p-2 text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-lg transition-all"
|
||||
:title="t('admin.agent.manageAccess')"
|
||||
@click.stop="openPermissionModal(agent)"
|
||||
>
|
||||
<Users class="w-5 h-5 shrink-0" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center whitespace-nowrap p-2 text-emerald-600 bg-emerald-50 hover:bg-emerald-100 rounded-lg transition-all"
|
||||
:title="t('admin.agent.test')"
|
||||
@click.stop="openTestModal(agent)"
|
||||
>
|
||||
{{ t('admin.agent.test') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center p-2 text-muted hover:text-red-600 hover:bg-red-50 rounded-lg transition-all"
|
||||
:title="t('admin.agent.delete')"
|
||||
@click.stop="deleteAgent(agent.id)"
|
||||
>
|
||||
<Trash2 class="w-5 h-5 shrink-0" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
{{ t('admin.agent.manageAccess') }}
|
||||
</ElButton>
|
||||
<ElButton link type="primary" @click="openTestModal(row as AgentRow)">
|
||||
{{ t('admin.agent.test') }}
|
||||
</ElButton>
|
||||
<ElButton link type="danger" @click="deleteAgent((row as AgentRow).id)">
|
||||
{{ t('admin.agent.delete') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<AgentTestModal
|
||||
:visible="showTestModal"
|
||||
@@ -342,45 +295,16 @@ onMounted(() => {
|
||||
@save="savePermissions"
|
||||
@toggle-user="togglePermissionUser"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
@cancel="closeDeleteConfirm"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-list-table {
|
||||
table-layout: fixed;
|
||||
.agents-element-table :deep(.agents-row-selected) {
|
||||
--el-table-tr-bg-color: color-mix(in srgb, #0284c7 8%, transparent);
|
||||
}
|
||||
|
||||
.agent-list-cell {
|
||||
display: flex;
|
||||
min-height: 2.5rem;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.agent-col-resize-handle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 1;
|
||||
width: 8px;
|
||||
height: 100%;
|
||||
cursor: col-resize;
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.agent-col-resize-handle:hover,
|
||||
.agent-col-resize-handle:active {
|
||||
background-color: color-mix(in srgb, var(--border-default) 65%, transparent);
|
||||
.agents-element-table :deep(.el-table__row) {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@@ -2,14 +2,15 @@
|
||||
* features/admin/modules/agents/components/AgentFormModal.vue
|
||||
*
|
||||
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息(含启用状态)、Dify/Iframe 配置和常见问题表单。
|
||||
* 依赖:agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form(含 is_active),并通过事件通知关闭、保存、增删常见问题。
|
||||
* 依赖:element-plus 对话框、agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;外壳是 680px 对话框。表单内部字段仍沿用原有输入控件。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { ChevronDown, FileDown, FolderTree, Plus, Search, Trash2, X } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog } from 'element-plus';
|
||||
import type { AgentFormState, AgentGuideSummary, AgentRow } from '@/features/admin/types/agent.types';
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
import type { AgentTypeCatalogEntry, IntentRouteOption } from '../composables/useAgentsAdminRegistry';
|
||||
@@ -252,22 +253,28 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
.map((_, optionIndex) => String.fromCharCode(97 + optionIndex));
|
||||
question.answer = validAnswerIds.includes(question.answer) ? question.answer : (validAnswerIds[0] || 'a');
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭应用编辑弹窗。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 px-4 py-6 backdrop-blur-sm">
|
||||
<div class="flex max-h-[92vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl border border-default bg-surface shadow-2xl">
|
||||
<div class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
|
||||
<div>
|
||||
<h3 class="section-title">{{ isEditing ? t('admin.agent.edit') : t('admin.agent.create') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="overflow-y-auto px-6 py-6">
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="isEditing ? t('admin.agent.edit') : t('admin.agent.create')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="section-desc">{{ t('admin.agent.subtitle') }}</p>
|
||||
<div class="agent-form-body">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.name') }}</label>
|
||||
@@ -890,17 +897,20 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
:requires-schedule-task="requiresScheduleTask"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col-reverse gap-3 border-t border-default px-6 py-4 sm:flex-row sm:items-center sm:justify-end">
|
||||
<button type="button" class="btn-secondary" @click="emit('close')">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary btn-lg disabled:opacity-60" :disabled="isSaving" @click="emit('save')">
|
||||
<Plus v-if="!isEditing" class="w-5 h-5" />
|
||||
{{ isEditing ? t('admin.update') : t('admin.add') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">
|
||||
{{ isEditing ? t('admin.update') : t('admin.add') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-form-body {
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentPermissionModal.vue
|
||||
*
|
||||
* 为指定 Agent 批量勾选可访问用户的权限弹窗。
|
||||
* 用途:为指定应用勾选可访问用户。
|
||||
* 依赖:element-plus、admin.types、agent.types。
|
||||
* 逻辑:AgentsPage 传入用户和已选 id;勾选变化交给父组件 togglePermissionUser。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElCheckbox, ElDialog } from 'element-plus';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type { AgentRow } from '@/features/admin/types/agent.types';
|
||||
|
||||
@@ -24,71 +25,68 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗。点遮罩或右上角关闭时 Element 会把打开状态写成 false。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible && agent" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[90vh] animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle flex justify-between items-center">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.perm.agentModal.title') }}</h3>
|
||||
<p class="text-sm text-muted">
|
||||
{{ t('admin.perm.agentModal.agent') }}
|
||||
<span class="font-medium text-blue-600">{{ agent.name }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds rounded-full" @click="emit('close')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-8">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="flex items-center gap-3 p-3 rounded-xl border transition-all cursor-pointer"
|
||||
:class="selectedUserIds.includes(user.id) ? 'border-blue-200 bg-blue-50/50' : 'border-default hover-surface-soft'"
|
||||
@click="emit('toggleUser', user.id)"
|
||||
>
|
||||
<div
|
||||
class="w-5 h-5 rounded border flex items-center justify-center transition-colors"
|
||||
:class="selectedUserIds.includes(user.id) ? 'bg-blue-600 border-blue-600' : 'bg-surface border-default'"
|
||||
>
|
||||
<svg
|
||||
v-if="selectedUserIds.includes(user.id)"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-3.5 w-3.5 text-white"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-medium text-primary text-sm">{{ user.username }}</div>
|
||||
<div class="text-xs text-muted">{{ user.real_name || user.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isSaving"
|
||||
class="btn-primary disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
@click="emit('save')"
|
||||
<ElDialog
|
||||
:model-value="visible && !!agent"
|
||||
:title="t('admin.perm.agentModal.title')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<template v-if="agent">
|
||||
<p class="section-desc">{{ t('admin.perm.agentModal.agent') }}{{ agent.name }}</p>
|
||||
<div class="agent-perm-list">
|
||||
<ElCheckbox
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
:model-value="selectedUserIds.includes(user.id)"
|
||||
@change="emit('toggleUser', user.id)"
|
||||
>
|
||||
<div v-if="isSaving" class="animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent" />
|
||||
{{ t('admin.perm.agentModal.save') }}
|
||||
</button>
|
||||
<span>{{ user.username }}</span>
|
||||
<span class="hx-element-hint">{{ user.real_name || user.email }}</span>
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">
|
||||
{{ t('admin.perm.agentModal.save') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-perm-list {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px 16px;
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.agent-perm-list :deep(.el-checkbox) {
|
||||
align-items: flex-start;
|
||||
height: auto;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.agent-perm-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentTestModal.vue
|
||||
*
|
||||
* Agent 连通性测试弹窗:展示请求 URL、输出信息与分析结果。
|
||||
* 用途:应用连通性测试弹窗,展示请求地址、输出和分析结果。
|
||||
* 依赖:element-plus、agent.types。
|
||||
* 逻辑:AgentsPage 传入当前应用和测试结果;重新测试由父组件发起。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog } from 'element-plus';
|
||||
import type { AgentRow, AgentTestResult } from '@/features/admin/types/agent.types';
|
||||
|
||||
defineProps<{
|
||||
@@ -21,62 +22,98 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗。点遮罩或右上角关闭时 Element 会把打开状态写成 false。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible && agent" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-3xl max-h-[90vh] animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle flex justify-between items-start">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.agent.testModalTitle') }}</h3>
|
||||
<p class="section-desc mt-1">
|
||||
{{ t('admin.agent.testModalAgent') }}:
|
||||
<span class="font-medium text-blue-600">{{ agent.name }}</span>
|
||||
</p>
|
||||
<ElDialog
|
||||
:model-value="visible && !!agent"
|
||||
:title="t('admin.agent.testModalTitle')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<template v-if="agent">
|
||||
<p class="section-desc">
|
||||
{{ t('admin.agent.testModalAgent') }}:{{ agent.name }}
|
||||
</p>
|
||||
<div class="agent-test-body">
|
||||
<div class="agent-test-toolbar">
|
||||
<span v-if="result?.tested_at" class="hx-element-hint">{{ t('admin.agent.testedAt') }}:{{ result.tested_at }}</span>
|
||||
<ElButton type="primary" :loading="isTesting" @click="emit('retest')">
|
||||
{{ t('admin.agent.retest') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds rounded-full" @click="emit('close')">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-8 space-y-5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="text-sm text-secondary">
|
||||
<span v-if="result?.tested_at">{{ t('admin.agent.testedAt') }}:{{ result.tested_at }}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isTesting"
|
||||
class="btn-primary btn-sm disabled:opacity-50"
|
||||
@click="emit('retest')"
|
||||
>
|
||||
{{ isTesting ? t('admin.agent.testing') : t('admin.agent.retest') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="isTesting" class="text-sm text-muted">{{ t('admin.agent.testingInProgress') }}</div>
|
||||
|
||||
<p v-if="isTesting" class="hx-element-hint">{{ t('admin.agent.testingInProgress') }}</p>
|
||||
<template v-if="result">
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.requestUrl') }}</div>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.requestUrl') }}</div>
|
||||
<div class="admin-code-block">{{ result.request_url || '-' }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.outputInfo') }}</div>
|
||||
<pre class="admin-code-block max-h-64 overflow-y-auto whitespace-pre-wrap">{{ result.output_info || '-' }}</pre>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.outputInfo') }}</div>
|
||||
<pre class="admin-code-block agent-test-output">{{ result.output_info || '-' }}</pre>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.analysis') }}</div>
|
||||
<div
|
||||
class="p-3 rounded-lg border text-sm"
|
||||
:class="result.success ? 'bg-green-50 border-green-200 text-green-800' : 'bg-red-50 border-red-200 text-red-800'"
|
||||
>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.analysis') }}</div>
|
||||
<div class="agent-test-analysis" :class="result.success ? 'is-ok' : 'is-fail'">
|
||||
{{ result.analysis }}
|
||||
<span v-if="result.http_status">(HTTP {{ result.http_status }})</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-test-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.agent-test-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.agent-test-output {
|
||||
max-height: 16rem;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.agent-test-analysis {
|
||||
padding: 12px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
}
|
||||
|
||||
.agent-test-analysis.is-ok {
|
||||
color: var(--el-color-success);
|
||||
border-color: var(--el-color-success-light-5);
|
||||
background: var(--el-color-success-light-9);
|
||||
}
|
||||
|
||||
.agent-test-analysis.is-fail {
|
||||
color: var(--el-color-danger);
|
||||
border-color: var(--el-color-danger-light-5);
|
||||
background: var(--el-color-danger-light-9);
|
||||
}
|
||||
</style>
|
||||
@@ -4,10 +4,12 @@
|
||||
* Agent 管理模块的业务逻辑:列表 CRUD、连通性测试、权限分配。
|
||||
* 从原 AdminView.vue 的 agents 相关 script 抽取,供 AgentsPage 使用。
|
||||
* 权限组启用后拒绝打开按人授权弹窗,提示改到应用权限页的角色包。
|
||||
* 删除确认使用 Element MessageBox。
|
||||
*/
|
||||
|
||||
import { ref, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
createAdminAgent,
|
||||
deleteAdminAgent,
|
||||
@@ -238,6 +240,7 @@ export function useAgentsAdmin() {
|
||||
const contentProfileOptions = ref<AdminContentProfileOption[]>([]);
|
||||
const users = ref<AdminUserRow[]>([]);
|
||||
const rolesConfigured = ref(false);
|
||||
const rolesChecked = ref(false);
|
||||
const scheduleTasks = ref<ScheduleTask[]>([]);
|
||||
const trainingExamPdfGuides = ref<AgentGuideSummary[]>([]);
|
||||
const isLoading = ref(true);
|
||||
@@ -256,9 +259,6 @@ export function useAgentsAdmin() {
|
||||
const permissionAgent = ref<AgentRow | null>(null);
|
||||
const permissionUserIds = ref<number[]>([]);
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
const activeUsers = () => users.value.filter((u) => u.status !== 'pending');
|
||||
|
||||
@@ -336,6 +336,8 @@ export function useAgentsAdmin() {
|
||||
} catch (e) {
|
||||
console.error('Error loading permission roles:', e);
|
||||
rolesConfigured.value = false;
|
||||
} finally {
|
||||
rolesChecked.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,18 +366,25 @@ export function useAgentsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 进入页面时先拉应用列表,再在后台补齐编辑弹窗要用的目录、用户和排程。
|
||||
* 核心逻辑:加载遮罩只等应用列表。权限组、用户、排程和目录在后台拉取,未返回时不盖住表格。
|
||||
*/
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await Promise.all([
|
||||
try {
|
||||
await loadAgents();
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
void Promise.all([
|
||||
loadRegistrySchema(),
|
||||
loadIntentRouteOptions(),
|
||||
loadContentProfileOptions(),
|
||||
loadAgents(),
|
||||
loadUsers(),
|
||||
loadRolesConfigured(),
|
||||
loadScheduleTasks(),
|
||||
]);
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const resetForm = (): void => {
|
||||
@@ -405,27 +414,26 @@ export function useAgentsAdmin() {
|
||||
void loadTrainingExamPdfGuides(agent.id);
|
||||
};
|
||||
|
||||
const openDeleteConfirm = (
|
||||
/**
|
||||
* 用 Element 确认框询问后再执行删除。
|
||||
* 核心逻辑:取消时 MessageBox 会 reject,这里吞掉,不调用 action。
|
||||
* @param message - 确认文案
|
||||
* @param action - 用户点确定后执行的删除
|
||||
*/
|
||||
const openDeleteConfirm = async (
|
||||
message: string,
|
||||
action: () => Promise<void> | void,
|
||||
): void => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = action;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmAction = null;
|
||||
};
|
||||
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
if (!deleteConfirmAction) return;
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await deleteConfirmAction();
|
||||
} finally {
|
||||
closeDeleteConfirm();
|
||||
await ElMessageBox.confirm(message, t('common.deleteDialog.defaultTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -613,7 +621,7 @@ export function useAgentsAdmin() {
|
||||
};
|
||||
|
||||
const deleteAgent = async (id: number): Promise<void> => {
|
||||
openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
|
||||
await openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
|
||||
try {
|
||||
await deleteAdminAgent(id);
|
||||
await loadAgents();
|
||||
@@ -723,6 +731,7 @@ export function useAgentsAdmin() {
|
||||
contentProfileOptions,
|
||||
users,
|
||||
rolesConfigured,
|
||||
rolesChecked,
|
||||
scheduleTasks,
|
||||
trainingExamPdfGuides,
|
||||
activeUsers,
|
||||
@@ -739,8 +748,6 @@ export function useAgentsAdmin() {
|
||||
showPermissionModal,
|
||||
permissionAgent,
|
||||
permissionUserIds,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
resetForm,
|
||||
selectAgent,
|
||||
@@ -758,7 +765,5 @@ export function useAgentsAdmin() {
|
||||
openPermissionModal,
|
||||
togglePermissionUser,
|
||||
savePermissions,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
};
|
||||
}
|
||||
@@ -1,24 +1,43 @@
|
||||
/**
|
||||
* features/admin/modules/users/UsersPage.vue
|
||||
* 用途:用户管理独立页面(服务端筛选分页、用户/部门列排序、批量操作)。
|
||||
* 依赖:useUsersAdmin、SortableTableHeader、PaginationBar、用户相关 Modal、adminRoleLabel、getUserAvatarLabel。
|
||||
* 逻辑:路由 /admin/users;列表经 listAdminUsersPage 按页拉取;权限组启用后只选角色、关闭按人授权。
|
||||
* 依赖:useUsersAdmin、useElementProvider、element-plus、用户相关 Modal、adminRoleLabel、getUserAvatarLabel。
|
||||
* 逻辑:路由 /admin/users;本页是 Element Plus 试点,筛选、表格、分页、工具栏和三个业务弹窗走组件库。
|
||||
* 删除和改角色用 Element 确认框。列表经 listAdminUsersPage 按页拉取。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Edit, Plus, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import SortableTableHeader from '@/shared/components/SortableTableHeader.vue';
|
||||
import { Delete, Edit, Plus, User } from '@element-plus/icons-vue';
|
||||
import {
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElInput,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElPagination,
|
||||
ElSelect,
|
||||
ElSpace,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import { adminRoleLabel } from '@/features/admin/utils/roleLabel';
|
||||
import { getUserAvatarLabel } from '@/shared/utils/user-avatar';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import BatchEditUserModal from './components/BatchEditUserModal.vue';
|
||||
import BatchPermissionModal from './components/BatchPermissionModal.vue';
|
||||
import UserFormModal from './components/UserFormModal.vue';
|
||||
import { useUsersAdmin } from './composables/useUsersAdmin';
|
||||
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
|
||||
const {
|
||||
agents,
|
||||
@@ -31,290 +50,273 @@ const {
|
||||
userFilters,
|
||||
sortKey,
|
||||
sortDir,
|
||||
// hideRejected,
|
||||
selectedUserIds,
|
||||
users,
|
||||
usersTotal,
|
||||
userPage,
|
||||
userPageSize,
|
||||
userPageSizeOptions,
|
||||
usersPages,
|
||||
allPaginatedUsersSelected,
|
||||
showUserModal,
|
||||
editingUser,
|
||||
showBatchEditModal,
|
||||
batchEditForm,
|
||||
showBatchPermissionModal,
|
||||
batchPermissionForm,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
showRoleConfirm,
|
||||
roleConfirmMessage,
|
||||
loadAll,
|
||||
toggleSort,
|
||||
applyServerSort,
|
||||
openCreateUserModal,
|
||||
openEditUserModal,
|
||||
saveUser,
|
||||
// cleanRejectedUsers,
|
||||
batchDeleteUsers,
|
||||
toggleUserSelection,
|
||||
toggleAllUsers,
|
||||
openBatchEditModal,
|
||||
openBatchPermissionModal,
|
||||
submitBatchEdit,
|
||||
submitBatchPermission,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
confirmRoleChange,
|
||||
closeRoleConfirm,
|
||||
} = useUsersAdmin();
|
||||
|
||||
const pageSizes = computed(() => [...userPageSizeOptions]);
|
||||
|
||||
const defaultSort = computed(() => ({
|
||||
prop: sortKey.value || 'username',
|
||||
order: sortDir.value === 'desc' ? 'descending' as const : 'ascending' as const,
|
||||
}));
|
||||
|
||||
/**
|
||||
* 把 Element 表格的勾选结果写回已选用户 id。
|
||||
* @param rows - 当前保留的选中行
|
||||
*/
|
||||
function onSelectionChange(rows: AdminUserRow[]): void {
|
||||
selectedUserIds.value = rows.map((row) => row.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门筛选。清空时写回空字符串,列表接口仍按「全部部门」查询。
|
||||
* @param value - 选中的部门名;清空为 undefined
|
||||
*/
|
||||
function onDepartmentChange(value: string | undefined): void {
|
||||
userFilters.value.department = value ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 Element 表头排序交给服务端查询。
|
||||
* 核心逻辑:取消排序时保持当前方向;有效排序走 applyServerSort 并回到第一页。
|
||||
* @param payload.prop - 列字段
|
||||
* @param payload.order - ascending、descending 或空
|
||||
*/
|
||||
function onSortChange(payload: { prop: string | null; order: string | null }): void {
|
||||
const field = payload.prop;
|
||||
if ((field === 'username' || field === 'department') && payload.order) {
|
||||
applyServerSort(field, payload.order === 'descending' ? 'desc' : 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开编辑弹窗。表格插槽行类型较宽,这里收成用户行。
|
||||
* @param row - 当前表格行
|
||||
*/
|
||||
function editUser(row: AdminUserRow): void {
|
||||
openEditUserModal(row);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.user.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.user.subtitle') }}</p>
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section v-loading="isLoading" class="admin-table-section min-h-64">
|
||||
<template v-if="!isLoading">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.user.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.user.subtitle') }}</p>
|
||||
</div>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
@click="batchDeleteUsers"
|
||||
>
|
||||
{{ t('admin.user.batchDelete') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton v-if="selectedUserIds.length > 0" :icon="Edit" @click="openBatchEditModal">
|
||||
{{ t('admin.user.batchEdit') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="selectedUserIds.length > 0 && !rolesConfigured"
|
||||
:icon="User"
|
||||
@click="openBatchPermissionModal"
|
||||
>
|
||||
{{ t('admin.user.batchPermission') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateUserModal">
|
||||
{{ t('admin.user.addUser') }}
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<!-- 暂隐藏:清理已拒绝
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-red-50 text-red-600 rounded-xl hover:bg-red-100 transition-all border border-red-200 text-sm font-medium"
|
||||
@click="cleanRejectedUsers"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.cleanRejected') }}</span>
|
||||
</button>
|
||||
-->
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-red-600 text-white rounded-xl hover:bg-red-700 transition-all shadow-lg shadow-red-200 active:scale-95 text-sm font-medium"
|
||||
@click="batchDeleteUsers"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchDelete') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-xl hover:bg-indigo-700 transition-all shadow-lg shadow-indigo-200 active:scale-95 text-sm font-medium"
|
||||
@click="openBatchEditModal"
|
||||
>
|
||||
<Edit class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchEdit') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0 && !rolesConfigured"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-all shadow-lg shadow-purple-200 active:scale-95 text-sm font-medium"
|
||||
@click="openBatchPermissionModal"
|
||||
>
|
||||
<Users class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchPermission') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
||||
@click="openCreateUserModal"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span class="font-medium">{{ t('admin.user.addUser') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-filters--inline gap-3">
|
||||
<input v-model="userFilters.username" :placeholder="t('admin.user.filterUsername')" class="admin-table-filter-input w-40" />
|
||||
<input v-model="userFilters.real_name" :placeholder="t('admin.user.filterRealName')" class="admin-table-filter-input w-44" />
|
||||
<select v-model="userFilters.department" class="admin-table-filter-input w-40">
|
||||
<option value="">{{ t('admin.user.allDepts') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
<!-- 暂隐藏:隐藏已拒绝
|
||||
<div class="flex items-center gap-2">
|
||||
<input id="hideRejectedUsers" v-model="hideRejected" type="checkbox" class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 border-default" />
|
||||
<label for="hideRejectedUsers" class="text-sm text-secondary select-none">{{ t('admin.user.hideRejected') }}</label>
|
||||
<div class="users-element-filters">
|
||||
<ElInput
|
||||
v-model="userFilters.username"
|
||||
clearable
|
||||
class="users-filter-username"
|
||||
:placeholder="t('admin.user.filterUsername')"
|
||||
/>
|
||||
<ElInput
|
||||
v-model="userFilters.real_name"
|
||||
clearable
|
||||
class="users-filter-name"
|
||||
:placeholder="t('admin.user.filterRealName')"
|
||||
/>
|
||||
<ElSelect
|
||||
:model-value="userFilters.department || undefined"
|
||||
class="users-filter-dept"
|
||||
clearable
|
||||
:placeholder="t('admin.user.allDepts')"
|
||||
@update:model-value="onDepartmentChange"
|
||||
>
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap relative">
|
||||
<div
|
||||
v-if="isListLoading"
|
||||
class="absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-surface/60"
|
||||
<ElTable
|
||||
v-loading="isListLoading"
|
||||
class="hx-admin-table"
|
||||
:data="users"
|
||||
row-key="id"
|
||||
:default-sort="defaultSort"
|
||||
:empty-text="t('admin.user.noUsers')"
|
||||
@selection-change="onSelectionChange"
|
||||
@sort-change="onSortChange"
|
||||
>
|
||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 w-12 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
||||
:checked="allPaginatedUsersSelected"
|
||||
@change="toggleAllUsers(users)"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">
|
||||
<SortableTableHeader
|
||||
column-key="username"
|
||||
:label="t('admin.user.headers.user')"
|
||||
:active-key="sortKey"
|
||||
:direction="sortDir"
|
||||
@sort="toggleSort"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.fields.realName') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">
|
||||
<SortableTableHeader
|
||||
column-key="department"
|
||||
:label="t('admin.user.headers.dept')"
|
||||
:active-key="sortKey"
|
||||
:direction="sortDir"
|
||||
@sort="toggleSort"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.role') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs">{{ t('admin.user.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="usersTotal === 0 && !isListLoading">
|
||||
<td colspan="6" class="px-6 admin-table-empty">{{ t('admin.user.noUsers') }}</td>
|
||||
</tr>
|
||||
<tr v-for="user in users" :key="user.id" class="group">
|
||||
<td class="px-6 py-4 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
||||
:checked="selectedUserIds.includes(user.id)"
|
||||
@change="toggleUserSelection(user.id)"
|
||||
/>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center">
|
||||
<div class="h-9 w-9 rounded-full bg-gradient-to-br from-brand-500 to-indigo-600 text-white flex items-center justify-center text-xs font-bold shadow-sm">
|
||||
{{ getUserAvatarLabel(user) }}
|
||||
</div>
|
||||
<div class="ml-3 text-sm font-medium text-primary">{{ user.username }}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-primary">{{ user.real_name || '-' }}</td>
|
||||
<td class="px-6 py-4 text-sm text-muted">{{ user.department || '-' }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<span
|
||||
class="px-2.5 py-0.5 rounded-full text-xs font-medium border"
|
||||
:class="user.is_platform_admin
|
||||
? 'bg-purple-50 text-purple-700 border-purple-100'
|
||||
: 'bg-blue-50 text-blue-700 border-blue-100'"
|
||||
>
|
||||
{{ adminRoleLabel(t, user.role, user.role_name) }}
|
||||
<ElTableColumn type="selection" width="64" reserve-selection />
|
||||
<ElTableColumn prop="username" :label="t('admin.user.headers.user')" sortable="custom" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<span class="inline-flex items-center gap-3">
|
||||
<span class="users-avatar">
|
||||
{{ getUserAvatarLabel(row) }}
|
||||
</span>
|
||||
<div
|
||||
v-if="user.feature_permissions?.training_hr_manage || user.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="mt-2 flex flex-wrap gap-1.5"
|
||||
>
|
||||
<span
|
||||
v-if="user.feature_permissions?.training_hr_manage"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.user.fields.trainingHrManage') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="user.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.permRoles.features.maintenance_ledger_write') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<button
|
||||
type="button"
|
||||
class="text-brand-600 hover:text-brand-900 font-medium text-xs px-3 py-1.5 rounded-lg hover:bg-brand-50 transition-colors"
|
||||
@click="openEditUserModal(user)"
|
||||
>
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<span>{{ row.username }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="real_name" :label="t('admin.user.fields.realName')" min-width="120">
|
||||
<template #default="{ row }">{{ row.real_name || '-' }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="department" :label="t('admin.user.headers.dept')" sortable="custom" min-width="140">
|
||||
<template #default="{ row }">{{ row.department || '-' }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.user.headers.role')" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="row.is_platform_admin ? 'warning' : 'primary'" effect="light">
|
||||
{{ adminRoleLabel(t, row.role, row.role_name) }}
|
||||
</ElTag>
|
||||
<div
|
||||
v-if="row.feature_permissions?.training_hr_manage || row.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="mt-2 flex flex-wrap gap-1.5"
|
||||
>
|
||||
<ElTag v-if="row.feature_permissions?.training_hr_manage" size="small">
|
||||
{{ t('admin.user.fields.trainingHrManage') }}
|
||||
</ElTag>
|
||||
<ElTag v-if="row.feature_permissions?.['maintenance.ledger_write']" size="small">
|
||||
{{ t('admin.permRoles.features.maintenance_ledger_write') }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.user.headers.actions')" width="100" align="right">
|
||||
<template #default="{ row }">
|
||||
<ElButton link type="primary" @click="editUser(row as AdminUserRow)">{{ t('admin.edit') }}</ElButton>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<div class="px-4 pb-4 pt-2">
|
||||
<PaginationBar
|
||||
v-model:page="userPage"
|
||||
v-model:page-size="userPageSize"
|
||||
:total="usersTotal"
|
||||
:pages="usersPages"
|
||||
:page-size-options="[...userPageSizeOptions]"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<div class="hx-admin-pager">
|
||||
<ElPagination
|
||||
v-model:current-page="userPage"
|
||||
v-model:page-size="userPageSize"
|
||||
:total="usersTotal"
|
||||
:page-sizes="pageSizes"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
background
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<UserFormModal
|
||||
:visible="showUserModal"
|
||||
:form="editingUser"
|
||||
:agents="agents"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:is-saving="isSaving"
|
||||
@close="showUserModal = false"
|
||||
@save="saveUser"
|
||||
/>
|
||||
<UserFormModal
|
||||
:visible="showUserModal"
|
||||
:form="editingUser"
|
||||
:agents="agents"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:is-saving="isSaving"
|
||||
@close="showUserModal = false"
|
||||
@save="saveUser"
|
||||
/>
|
||||
|
||||
<BatchEditUserModal
|
||||
:visible="showBatchEditModal"
|
||||
:form="batchEditForm"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchEditModal = false"
|
||||
@save="submitBatchEdit"
|
||||
/>
|
||||
<BatchEditUserModal
|
||||
:visible="showBatchEditModal"
|
||||
:form="batchEditForm"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchEditModal = false"
|
||||
@save="submitBatchEdit"
|
||||
/>
|
||||
|
||||
<BatchPermissionModal
|
||||
:visible="showBatchPermissionModal"
|
||||
:form="batchPermissionForm"
|
||||
:agents="agents"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchPermissionModal = false"
|
||||
@save="submitBatchPermission"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
@cancel="closeDeleteConfirm"
|
||||
/>
|
||||
<DeleteConfirmDialog
|
||||
v-model="showRoleConfirm"
|
||||
:title="t('admin.permRoles.userRoleConfirmTitle')"
|
||||
:message="roleConfirmMessage"
|
||||
:confirm-text="t('admin.save')"
|
||||
confirm-tone="primary"
|
||||
:confirm-loading="isSaving"
|
||||
@confirm="confirmRoleChange"
|
||||
@cancel="closeRoleConfirm"
|
||||
/>
|
||||
</section>
|
||||
<BatchPermissionModal
|
||||
:visible="showBatchPermissionModal"
|
||||
:form="batchPermissionForm"
|
||||
:agents="agents"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchPermissionModal = false"
|
||||
@save="submitBatchPermission"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.users-element-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px 32px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.el-input),
|
||||
.users-element-filters :deep(.el-select) {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.users-filter-username) {
|
||||
width: 10rem;
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.users-filter-name),
|
||||
.users-element-filters :deep(.users-filter-dept) {
|
||||
width: 11rem;
|
||||
}
|
||||
|
||||
.users-avatar {
|
||||
display: flex;
|
||||
height: 2.25rem;
|
||||
width: 2.25rem;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 9999px;
|
||||
background-image: linear-gradient(to bottom right, #0ea5e9, #4f46e5);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -1,17 +1,19 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/BatchEditUserModal.vue
|
||||
* 用途:批量编辑用户部门/角色/状态弹窗。权限组启用后角色下拉读权限组列表。
|
||||
* 依赖:admin.types、permissionRole.types、user.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未选字段表示保持不变。
|
||||
* 依赖:element-plus、admin.types、permissionRole.types、user.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未选字段表示保持不变。本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog, ElForm, ElFormItem, ElOption, ElSelect } from 'element-plus';
|
||||
import type { AdminDepartmentRow } from '@/features/admin/types/admin.types';
|
||||
import type { PermissionRoleRow } from '@/features/admin/types/permissionRole.types';
|
||||
import type { BatchEditForm } from '@/features/admin/types/user.types';
|
||||
import { LEGACY_ROLE_OPTIONS } from '@/features/admin/utils/roleLabel';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
form: BatchEditForm;
|
||||
departments: AdminDepartmentRow[];
|
||||
@@ -23,55 +25,61 @@ defineProps<{
|
||||
|
||||
const emit = defineEmits<{ close: []; save: [] }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 角色下拉,首项为保持不变。
|
||||
*/
|
||||
const roleOptions = computed(() => {
|
||||
const keep = { value: '', label: t('admin.batchEdit.fields.keepUnchanged') };
|
||||
if (props.rolesConfigured) {
|
||||
return [keep, ...props.roles.map((role) => ({ value: role.code, label: role.name }))];
|
||||
}
|
||||
return [keep, ...LEGACY_ROLE_OPTIONS.map((option) => ({ value: option.code, label: t(option.i18nKey) }))];
|
||||
});
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-md animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle">
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.batchEdit.title') }}</h3>
|
||||
<p class="text-sm text-muted">{{ t('admin.batchEdit.selected', { count: selectedCount }) }}</p>
|
||||
</div>
|
||||
<div class="p-8 space-y-4">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.dept') }}</label>
|
||||
<select v-model="form.department" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.role') }}</label>
|
||||
<select v-if="rolesConfigured" v-model="form.role" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option v-for="role in roles" :key="role.code" :value="role.code">{{ role.name }}</option>
|
||||
</select>
|
||||
<select v-else v-model="form.role" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option
|
||||
v-for="option in LEGACY_ROLE_OPTIONS"
|
||||
:key="option.code"
|
||||
:value="option.code"
|
||||
>
|
||||
{{ t(option.i18nKey) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.status') }}</label>
|
||||
<select v-model="form.status" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option value="active">{{ t('admin.status.active') }}</option>
|
||||
<option value="disabled">{{ t('admin.status.disabled') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-50" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.batchEdit.update') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="t('admin.batchEdit.title')"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="hx-element-hint">{{ t('admin.batchEdit.selected', { count: selectedCount }) }}</p>
|
||||
<ElForm label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.dept')">
|
||||
<ElSelect v-model="form.department" class="w-full">
|
||||
<ElOption :label="t('admin.batchEdit.fields.keepUnchanged')" value="" />
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.role')">
|
||||
<ElSelect v-model="form.role" class="w-full">
|
||||
<ElOption v-for="option in roleOptions" :key="option.value || 'keep'" :label="option.label" :value="option.value" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.status')">
|
||||
<ElSelect v-model="form.status" class="w-full">
|
||||
<ElOption :label="t('admin.batchEdit.fields.keepUnchanged')" value="" />
|
||||
<ElOption :label="t('admin.status.active')" value="active" />
|
||||
<ElOption :label="t('admin.status.disabled')" value="disabled" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.batchEdit.update') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
@@ -1,9 +1,21 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/BatchPermissionModal.vue
|
||||
* 批量分配/移除用户 Agent 权限弹窗。
|
||||
* 用途:批量分配、移除或覆盖用户 Agent 权限。
|
||||
* 依赖:element-plus、admin.types、user.types。
|
||||
* 逻辑:UsersPage 传入已选人数与 Agent 列表;动作为 add / remove / set。本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElRadio,
|
||||
ElRadioGroup,
|
||||
} from 'element-plus';
|
||||
import type { AdminAgentOption } from '@/features/admin/types/admin.types';
|
||||
import type { BatchPermissionForm } from '@/features/admin/types/user.types';
|
||||
|
||||
@@ -17,54 +29,46 @@ defineProps<{
|
||||
|
||||
const emit = defineEmits<{ close: []; save: [] }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-lg animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle">
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.perm.batchModal.title') }}</h3>
|
||||
<p class="text-sm text-muted">{{ t('admin.perm.batchModal.selected', { count: selectedCount }) }}</p>
|
||||
</div>
|
||||
<div class="p-8 space-y-6">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.perm.batchModal.action') }}</label>
|
||||
<div class="flex gap-4">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="add" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.add') }}</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="remove" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.remove') }}</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="set" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.set') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.perm.batchModal.selectAgents') }}</label>
|
||||
<div class="grid grid-cols-2 gap-3 max-h-60 overflow-y-auto p-1">
|
||||
<label
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="flex items-center gap-2 p-3 border border-default rounded-lg cursor-pointer hover-surface-soft transition-colors"
|
||||
:class="form.agent_ids.includes(agent.id) ? 'border-blue-500 bg-blue-50' : ''"
|
||||
>
|
||||
<input v-model="form.agent_ids" type="checkbox" :value="agent.id" class="w-4 h-4 text-blue-600 rounded focus:ring-blue-500" />
|
||||
<span class="text-sm font-medium text-secondary">{{ agent.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-50" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.perm.batchModal.apply') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="t('admin.perm.batchModal.title')"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="hx-element-hint">{{ t('admin.perm.batchModal.selected', { count: selectedCount }) }}</p>
|
||||
<ElForm label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.perm.batchModal.action')">
|
||||
<ElRadioGroup v-model="form.action">
|
||||
<ElRadio value="add">{{ t('admin.perm.batchModal.add') }}</ElRadio>
|
||||
<ElRadio value="remove">{{ t('admin.perm.batchModal.remove') }}</ElRadio>
|
||||
<ElRadio value="set">{{ t('admin.perm.batchModal.set') }}</ElRadio>
|
||||
</ElRadioGroup>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.perm.batchModal.selectAgents')">
|
||||
<ElCheckboxGroup v-model="form.agent_ids" class="grid max-h-60 grid-cols-2 gap-2 overflow-y-auto">
|
||||
<ElCheckbox v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }}
|
||||
</ElCheckbox>
|
||||
</ElCheckboxGroup>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.perm.batchModal.apply') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
@@ -1,17 +1,30 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/UserFormModal.vue
|
||||
* 用途:创建/编辑用户弹窗。权限组启用后只选角色,不再按人勾应用或功能权限。
|
||||
* 依赖:admin.types、user.types、permissionRole.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未种子权限组时保留历史 Agent / 培训 HR 勾选,角色下拉用旧枚举。
|
||||
* 依赖:element-plus、admin.types、user.types、permissionRole.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未种子权限组时保留历史 Agent / 功能权限勾选,角色下拉用旧枚举。
|
||||
* 本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
} from 'element-plus';
|
||||
import type { AdminAgentOption, AdminDepartmentRow } from '@/features/admin/types/admin.types';
|
||||
import type { PermissionRoleRow } from '@/features/admin/types/permissionRole.types';
|
||||
import type { UserFormState } from '@/features/admin/types/user.types';
|
||||
import { LEGACY_ROLE_OPTIONS } from '@/features/admin/utils/roleLabel';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
form: UserFormState;
|
||||
agents: AdminAgentOption[];
|
||||
@@ -24,150 +37,142 @@ defineProps<{
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
save: [];
|
||||
'update:form': [UserFormState];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 角色下拉。已配置权限组时用组名称,否则用历史角色枚举。
|
||||
*/
|
||||
const roleOptions = computed(() => {
|
||||
if (props.rolesConfigured) {
|
||||
return props.roles.map((role) => ({ value: role.code, label: role.name }));
|
||||
}
|
||||
return LEGACY_ROLE_OPTIONS.map((option) => ({ value: option.code, label: t(option.i18nKey) }));
|
||||
});
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门选择。清空时写回空字符串,表示不指定部门。
|
||||
* @param value - 选中的部门名;清空为 undefined
|
||||
*/
|
||||
function onDepartmentChange(value: string | undefined): void {
|
||||
props.form.department = value ?? '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in">
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[92vh] scale-100">
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle">
|
||||
<h3 class="section-title">{{ form.id ? t('admin.user.editUser') : t('admin.user.createUser') }}</h3>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-5 overflow-y-auto">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.realName') }}
|
||||
</label>
|
||||
<input v-model="form.real_name" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.employeeId') }}
|
||||
</label>
|
||||
<input v-model="form.employee_id" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.phone') }}
|
||||
</label>
|
||||
<input v-model="form.phone_number" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div v-if="!rolesConfigured" class="space-y-1.5 col-span-1 md:col-span-2">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.user.fields.allowedAgents') }}</label>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3 mt-2">
|
||||
<label
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="flex items-center gap-2 p-3 border border-default rounded-lg cursor-pointer hover-surface-soft transition-colors"
|
||||
:class="form.agent_ids.includes(agent.id) ? 'border-blue-500 bg-blue-50' : ''"
|
||||
>
|
||||
<input v-model="form.agent_ids" type="checkbox" :value="agent.id" class="w-4 h-4 text-blue-600 rounded focus:ring-blue-500" />
|
||||
<span class="text-sm font-medium text-secondary">{{ agent.name }}</span>
|
||||
</label>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="form.id ? t('admin.user.editUser') : t('admin.user.createUser')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<div class="max-h-[65vh] overflow-y-auto pr-1">
|
||||
<ElForm class="users-element-form" label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.user.fields.realName')" :required="!form.id">
|
||||
<ElInput v-model="form.real_name" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.employeeId')" :required="!form.id">
|
||||
<ElInput v-model="form.employee_id" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.phone')" :required="!form.id">
|
||||
<ElInput v-model="form.phone_number" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.username')" :required="!form.id">
|
||||
<ElInput v-model="form.username" :disabled="!!form.id" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.email')" :required="!form.id">
|
||||
<ElInput v-model="form.email" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.department')">
|
||||
<ElSelect
|
||||
:model-value="form.department || undefined"
|
||||
class="w-full"
|
||||
clearable
|
||||
:placeholder="t('admin.user.allDepts')"
|
||||
@update:model-value="onDepartmentChange"
|
||||
>
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="!rolesConfigured" class="users-form-span" :label="t('admin.user.fields.allowedAgents')">
|
||||
<ElCheckboxGroup v-model="form.agent_ids">
|
||||
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<ElCheckbox v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }}
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
</ElCheckboxGroup>
|
||||
<p v-if="agents.length === 0" class="hx-element-hint">{{ t('admin.user.fields.noAgents') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem class="users-form-span" :label="t('admin.user.fields.role')" required>
|
||||
<ElSelect v-model="form.role" class="w-full">
|
||||
<ElOption v-for="option in roleOptions" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</ElSelect>
|
||||
<p v-if="rolesConfigured" class="hx-element-hint">{{ t('admin.permRoles.userFormHint') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="!rolesConfigured" class="users-form-span" :label="t('admin.user.fields.featurePermissions')">
|
||||
<div class="flex flex-col gap-3">
|
||||
<ElCheckbox v-model="form.feature_permissions.training_hr_manage">
|
||||
<span class="block">{{ t('admin.user.fields.trainingHrManage') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.trainingHrManageHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['contract_payment.access']">
|
||||
<span class="block">{{ t('admin.user.fields.contractPaymentAccess') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.contractPaymentAccessHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['order_delivery_reply.manage']">
|
||||
<span class="block">{{ t('admin.user.fields.orderDeliveryReplyManage') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.orderDeliveryReplyManageHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['order_delivery_reply.access']">
|
||||
<span class="block">{{ t('admin.user.fields.orderDeliveryReplyAccess') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.orderDeliveryReplyAccessHint') }}</span>
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
<p v-if="agents.length === 0" class="text-sm text-muted italic">{{ t('admin.user.fields.noAgents') }}</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.username') }}
|
||||
</label>
|
||||
<input v-model="form.username" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" :disabled="!!form.id" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.email') }}
|
||||
</label>
|
||||
<input v-model="form.email" type="email" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.user.fields.department') }}</label>
|
||||
<select v-model="form.department" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option value="">{{ t('admin.user.allDepts') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.role') }}
|
||||
</label>
|
||||
<select v-if="rolesConfigured" v-model="form.role" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option v-for="role in roles" :key="role.code" :value="role.code">{{ role.name }}</option>
|
||||
</select>
|
||||
<select v-else v-model="form.role" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option
|
||||
v-for="option in LEGACY_ROLE_OPTIONS"
|
||||
:key="option.code"
|
||||
:value="option.code"
|
||||
>
|
||||
{{ t(option.i18nKey) }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="rolesConfigured" class="text-xs text-muted">{{ t('admin.permRoles.userFormHint') }}</p>
|
||||
</div>
|
||||
<div v-if="!rolesConfigured" class="space-y-2 rounded-2xl border border-default bg-surface px-4 py-4">
|
||||
<div class="text-xs font-semibold uppercase tracking-wider text-muted">{{ t('admin.user.fields.featurePermissions') }}</div>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions.training_hr_manage"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.trainingHrManage') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.trainingHrManageHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['contract_payment.access']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.contractPaymentAccess') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.contractPaymentAccessHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['order_delivery_reply.manage']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.orderDeliveryReplyManage') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.orderDeliveryReplyManageHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['order_delivery_reply.access']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.orderDeliveryReplyAccess') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.orderDeliveryReplyAccessHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.password') }}
|
||||
<span v-if="form.id" class="text-muted font-normal lowercase">{{ t('admin.user.fields.passwordHint') }}</span>
|
||||
</label>
|
||||
<input v-model="form.password" type="password" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-70" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem class="users-form-span" :label="t('admin.user.fields.password')" :required="!form.id">
|
||||
<ElInput v-model="form.password" type="password" show-password />
|
||||
<p v-if="form.id" class="hx-element-hint">{{ t('admin.user.fields.passwordHint') }}</p>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.save') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.users-element-form {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
column-gap: 16px;
|
||||
}
|
||||
|
||||
.users-element-form :deep(.el-form-item) {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.users-element-form :deep(.users-form-span) {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.users-element-form {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,10 +3,12 @@
|
||||
* 用途:用户管理模块业务逻辑(CRUD、服务端筛选分页、用户/部门列排序、批量操作)。
|
||||
* 依赖:admin.api、useMessage、useTableSort、permissionRole.types。
|
||||
* 逻辑:UsersPage 调用本 composable;列表经 listAdminUsersPage 按页拉取,排序参数随请求下发。
|
||||
* 权限组启用后创建用户预填默认角色,改角色须确认;批量按人授权入口关闭。
|
||||
* 权限组启用后创建用户预填默认角色;删除和改角色用 Element 确认框。批量按人授权入口关闭。
|
||||
* Element Plus 表格通过 applyServerSort 写入列排序。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
batchDeleteAdminUsers,
|
||||
batchUpdateAdminPermissions,
|
||||
@@ -68,10 +70,6 @@ export function useUsersAdmin() {
|
||||
const showUserModal = ref(false);
|
||||
const editingUser = ref<UserFormState>(createEmptyUserForm());
|
||||
const originalUserRole = ref('user');
|
||||
const showRoleConfirm = ref(false);
|
||||
const roleConfirmMessage = ref('');
|
||||
let pendingUserSave: (() => Promise<void>) | null = null;
|
||||
let pendingBatchSave: (() => Promise<void>) | null = null;
|
||||
|
||||
const showBatchEditModal = ref(false);
|
||||
const batchEditForm = ref<BatchEditForm>({ department: '', role: '', status: '' });
|
||||
@@ -79,9 +77,6 @@ export function useUsersAdmin() {
|
||||
const showBatchPermissionModal = ref(false);
|
||||
const batchPermissionForm = ref<BatchPermissionForm>({ agent_ids: [], action: 'add' });
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
/** 当前页是否已全部选中 */
|
||||
const allPaginatedUsersSelected = computed(
|
||||
@@ -194,25 +189,41 @@ export function useUsersAdmin() {
|
||||
}, 300);
|
||||
}, { deep: true });
|
||||
|
||||
const openDeleteConfirm = (message: string, action: () => Promise<void> | void): void => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = action;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmAction = null;
|
||||
/**
|
||||
* 用 Element 确认框询问后再执行删除。
|
||||
* 核心逻辑:取消时 MessageBox 会 reject,这里吞掉,不调用 action。
|
||||
* @param message - 确认文案
|
||||
* @param action - 用户点确定后执行的删除
|
||||
*/
|
||||
const openDeleteConfirm = async (message: string, action: () => Promise<void> | void): Promise<void> => {
|
||||
try {
|
||||
await ElMessageBox.confirm(message, t('common.deleteDialog.defaultTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
/**
|
||||
* 执行待确认的删除操作。
|
||||
* 核心逻辑:先快照 action 并立即关闭弹窗,再 await 删除与刷新,避免异步完成前弹窗无法关闭。
|
||||
* 用 Element 确认框询问改角色,确定后执行保存。
|
||||
* 核心逻辑:与删除确认同一组件,避免一页两种确认框。取消则不保存。
|
||||
* @param message - 角色变更说明
|
||||
* @param action - 用户点确定后提交
|
||||
*/
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
const action = deleteConfirmAction;
|
||||
closeDeleteConfirm();
|
||||
if (!action) return;
|
||||
const confirmRoleThen = async (message: string, action: () => Promise<void>): Promise<void> => {
|
||||
try {
|
||||
await ElMessageBox.confirm(message, t('admin.permRoles.userRoleConfirmTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('admin.save'),
|
||||
cancelButtonText: t('admin.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
@@ -296,11 +307,10 @@ export function useUsersAdmin() {
|
||||
: nextRole !== originalUserRole.value;
|
||||
const touchesAdmin = isAdminRoleCode(nextRole) || isAdminRoleCode(originalUserRole.value);
|
||||
if (roleChanged) {
|
||||
roleConfirmMessage.value = touchesAdmin
|
||||
const message = touchesAdmin
|
||||
? t('admin.permRoles.userAdminConfirm')
|
||||
: t('admin.permRoles.userRoleConfirm', { role: nextRole });
|
||||
pendingUserSave = persistUser;
|
||||
showRoleConfirm.value = true;
|
||||
await confirmRoleThen(message, persistUser);
|
||||
return;
|
||||
}
|
||||
await persistUser();
|
||||
@@ -348,28 +358,6 @@ export function useUsersAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 确认改角色(含管理员)后再提交。
|
||||
*/
|
||||
const confirmRoleChange = async (): Promise<void> => {
|
||||
const userSave = pendingUserSave;
|
||||
const batchSave = pendingBatchSave;
|
||||
pendingUserSave = null;
|
||||
pendingBatchSave = null;
|
||||
showRoleConfirm.value = false;
|
||||
if (userSave) {
|
||||
await userSave();
|
||||
return;
|
||||
}
|
||||
if (batchSave) await batchSave();
|
||||
};
|
||||
|
||||
const closeRoleConfirm = (): void => {
|
||||
pendingUserSave = null;
|
||||
pendingBatchSave = null;
|
||||
showRoleConfirm.value = false;
|
||||
};
|
||||
|
||||
const cleanRejectedUsers = async (): Promise<void> => {
|
||||
openDeleteConfirm(t('admin.user.confirmClean'), async () => {
|
||||
try {
|
||||
@@ -446,11 +434,10 @@ export function useUsersAdmin() {
|
||||
return;
|
||||
}
|
||||
if (data.role) {
|
||||
roleConfirmMessage.value = isAdminRoleCode(data.role)
|
||||
const message = isAdminRoleCode(data.role)
|
||||
? t('admin.permRoles.userAdminConfirm')
|
||||
: t('admin.permRoles.batchRoleConfirm');
|
||||
pendingBatchSave = () => persistBatchEdit(data);
|
||||
showRoleConfirm.value = true;
|
||||
await confirmRoleThen(message, () => persistBatchEdit(data));
|
||||
return;
|
||||
}
|
||||
await persistBatchEdit(data);
|
||||
@@ -504,6 +491,19 @@ export function useUsersAdmin() {
|
||||
scheduleLoadUsers(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* 按指定列和方向重新查询第一页。
|
||||
* 核心逻辑:方向未变时不请求;变更后回到第一页再拉取。
|
||||
* @param key - username 或 department,与后端 sort_by 白名单一致
|
||||
* @param dir - asc 或 desc
|
||||
*/
|
||||
const applyServerSort = (key: UserSortKey, dir: 'asc' | 'desc'): void => {
|
||||
if (sortKey.value === key && sortDir.value === dir) return;
|
||||
sortKey.value = key;
|
||||
sortDir.value = dir;
|
||||
scheduleLoadUsers(true);
|
||||
};
|
||||
|
||||
return {
|
||||
users,
|
||||
agents,
|
||||
@@ -530,12 +530,9 @@ export function useUsersAdmin() {
|
||||
batchEditForm,
|
||||
showBatchPermissionModal,
|
||||
batchPermissionForm,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
showRoleConfirm,
|
||||
roleConfirmMessage,
|
||||
loadAll,
|
||||
toggleSort,
|
||||
applyServerSort,
|
||||
openCreateUserModal,
|
||||
openEditUserModal,
|
||||
saveUser,
|
||||
@@ -547,9 +544,5 @@ export function useUsersAdmin() {
|
||||
openBatchPermissionModal,
|
||||
submitBatchEdit,
|
||||
submitBatchPermission,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
confirmRoleChange,
|
||||
closeRoleConfirm,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* features/admin/styles/element-trial.css
|
||||
* 用途:管理端 Element Plus 的字体、字号、颜色、圆角、控件高度,以及和 Tailwind 共存的修正。
|
||||
* 依赖:tokens.css 的 --text-* / --bg-* / --border-*,element-plus 暗色变量,Tailwind preflight。
|
||||
* 逻辑:由 UsersPage、AgentsPage、KbAdminPanel 在暗色 CSS 之后引入,所以 html.dark 能盖过 Element 默认暗色。
|
||||
* 字号和颜色以本文变量为准。页面不要再用 text-sm / text-muted 改表格和按钮。
|
||||
*/
|
||||
|
||||
:root,
|
||||
html.dark {
|
||||
--el-color-primary: #0284c7;
|
||||
--el-color-primary-light-3: #4da3d6;
|
||||
--el-color-primary-light-5: #81c2e3;
|
||||
--el-color-primary-light-7: #b4daf0;
|
||||
--el-color-primary-light-8: #cde6f4;
|
||||
--el-color-primary-light-9: #e6f3fa;
|
||||
--el-color-primary-dark-2: #0269a0;
|
||||
--el-font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
|
||||
--el-font-size-extra-large: 20px;
|
||||
--el-font-size-large: 18px;
|
||||
--el-font-size-medium: 16px;
|
||||
--el-font-size-base: 14px;
|
||||
--el-font-size-small: 13px;
|
||||
--el-font-size-extra-small: 12px;
|
||||
--el-text-color-primary: var(--text-primary);
|
||||
--el-text-color-regular: var(--text-secondary);
|
||||
--el-text-color-secondary: var(--text-muted);
|
||||
--el-text-color-placeholder: var(--text-muted);
|
||||
--el-text-color-disabled: var(--text-muted);
|
||||
--el-border-color: var(--border-default);
|
||||
--el-border-color-light: var(--border-subtle);
|
||||
--el-border-color-lighter: var(--border-subtle);
|
||||
--el-bg-color: var(--bg-surface);
|
||||
--el-bg-color-overlay: var(--bg-surface);
|
||||
--el-fill-color-blank: var(--bg-surface);
|
||||
--el-fill-color-light: var(--bg-surface-soft);
|
||||
--el-border-radius-base: 8px;
|
||||
--el-component-size: 32px;
|
||||
}
|
||||
|
||||
.el-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.el-button .el-icon,
|
||||
.el-button svg {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* Tailwind forms 会给单行输入框内部的 input 加边框。聚焦时左右两边会多出两条蓝线。
|
||||
多行输入框的边框就画在 .el-textarea__inner 上,不能一起清掉。 */
|
||||
.el-input__inner,
|
||||
.el-select__input,
|
||||
.el-range-input,
|
||||
.el-input__inner:hover,
|
||||
.el-select__input:hover,
|
||||
.el-range-input:hover,
|
||||
.el-input__inner:focus,
|
||||
.el-select__input:focus,
|
||||
.el-range-input:focus {
|
||||
border: 0;
|
||||
outline: none;
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
.el-textarea__inner {
|
||||
background-color: var(--el-input-bg-color, var(--el-fill-color-blank));
|
||||
box-shadow: 0 0 0 1px var(--el-input-border-color, var(--el-border-color)) inset;
|
||||
}
|
||||
|
||||
.el-textarea__inner:hover {
|
||||
box-shadow: 0 0 0 1px var(--el-input-hover-border-color, var(--el-border-color-hover)) inset;
|
||||
}
|
||||
|
||||
.el-textarea__inner:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 1px var(--el-input-focus-border-color, var(--el-color-primary)) inset;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
/* 列表首尾列与页头 32px 对齐;分页贴在表格下方 */
|
||||
.hx-admin-table .el-table__cell:first-child .cell {
|
||||
padding-left: 32px;
|
||||
}
|
||||
|
||||
.hx-admin-table .el-table__cell:last-child .cell {
|
||||
padding-right: 32px;
|
||||
}
|
||||
|
||||
.hx-admin-pager {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 12px 32px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
/* 表单里的补充说明,字号和颜色走 Element 变量 */
|
||||
.hx-element-hint {
|
||||
margin-top: 4px;
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
line-height: 1.4;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
@@ -1,16 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/kb/components/DifyHealthDialog.vue
|
||||
* 知识库 Dify 健康检查弹窗。
|
||||
* 用途:展示知识库 Dify 连通性和本地同步计数。
|
||||
* 依赖:Element Plus、kb.api 的健康检查接口。
|
||||
* 逻辑:KbAdminPanel 打开本弹窗后拉取健康数据,失败时把文案交给父组件。结果用 Element 描述列表展示,不再套统计卡片。
|
||||
*/
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElAlert, ElButton, ElDescriptions, ElDescriptionsItem, ElDialog, ElLoading, ElTag } from 'element-plus';
|
||||
import { getKbDifyHealth, type KbDifyHealth } from '../api/kb.api';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; error: [message: string] }>();
|
||||
const { t } = useI18n();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const loading = ref(false);
|
||||
const payload = ref<KbDifyHealth | null>(null);
|
||||
@@ -30,54 +34,90 @@ watch(() => props.open, (open) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="dialog-overlay" @click="close">
|
||||
<div class="dialog-panel max-w-4xl p-6" @click.stop>
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title text-xl">{{ t('kbDifyHealth.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('kbDifyHealth.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button type="button" class="btn-secondary btn-sm" @click="loadHealth">
|
||||
{{ t('common.refresh') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="close">
|
||||
{{ t('common.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="py-16 text-center text-sm text-muted">{{ t('kbDifyHealth.loading') }}</div>
|
||||
<div v-else-if="payload" class="mt-6 grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">Dify API</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.api.reachable ? t('kbDifyHealth.reachable') : t('kbDifyHealth.unreachable') }}</div>
|
||||
<div class="mt-2 break-all text-xs text-muted">{{ payload.dify_base_url || t('kbDifyHealth.notConfigured') }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.datasetCount') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.api.dataset_count ?? '--' }}</div>
|
||||
<div class="mt-2 text-xs text-muted">{{ t('kbDifyHealth.configured') }}{{ payload.dify_api_configured ? t('common.yes') : t('common.no') }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.boundGroups') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.dataset_bound_groups }}</div>
|
||||
<div class="mt-2 text-xs text-muted">{{ t('kbDifyHealth.localSyncRecords') }}{{ payload.local_sync_health.sync_records }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.syncingVersions') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.syncing_versions }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.syncedVersions') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.synced_versions }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.pendingSyncJobs') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.pending_sync_jobs }}</div>
|
||||
<div v-if="payload.api.error" class="mt-2 text-xs text-rose-500">{{ payload.api.error }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
:title="t('kbDifyHealth.title')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="(value) => { if (!value) close(); }"
|
||||
>
|
||||
<p class="section-desc">{{ t('kbDifyHealth.subtitle') }}</p>
|
||||
<div v-loading="loading" class="dify-health-body">
|
||||
<template v-if="payload">
|
||||
<ElAlert
|
||||
v-if="payload.api.error"
|
||||
class="dify-health-alert"
|
||||
:title="payload.api.error"
|
||||
type="error"
|
||||
show-icon
|
||||
:closable="false"
|
||||
/>
|
||||
<ElDescriptions :column="1" border label-width="148px">
|
||||
<ElDescriptionsItem label="Dify API">
|
||||
<div class="dify-health-status">
|
||||
<ElTag :type="payload.api.reachable ? 'success' : 'danger'" effect="light">
|
||||
{{ payload.api.reachable ? t('kbDifyHealth.reachable') : t('kbDifyHealth.unreachable') }}
|
||||
</ElTag>
|
||||
<span class="hx-element-hint dify-health-url">{{ payload.dify_base_url || t('kbDifyHealth.notConfigured') }}</span>
|
||||
</div>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.datasetCount')">
|
||||
{{ payload.api.dataset_count ?? '--' }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.configured')">
|
||||
{{ payload.dify_api_configured ? t('common.yes') : t('common.no') }}
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
<ElDescriptions class="dify-health-sync" :column="2" border label-width="148px">
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.boundGroups')">
|
||||
{{ payload.local_sync_health.dataset_bound_groups }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.localSyncRecords')">
|
||||
{{ payload.local_sync_health.sync_records }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.syncingVersions')">
|
||||
{{ payload.local_sync_health.syncing_versions }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.syncedVersions')">
|
||||
{{ payload.local_sync_health.synced_versions }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.pendingSyncJobs')" :span="2">
|
||||
{{ payload.local_sync_health.pending_sync_jobs }}
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton :loading="loading" @click="loadHealth">{{ t('common.refresh') }}</ElButton>
|
||||
<ElButton type="primary" @click="close">{{ t('common.close') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dify-health-body {
|
||||
min-height: 8rem;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.dify-health-alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.dify-health-status {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
}
|
||||
|
||||
.dify-health-url {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.dify-health-sync {
|
||||
margin-top: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -2,17 +2,34 @@
|
||||
/**
|
||||
* features/kb/components/DifySettingsDialog.vue
|
||||
* 用途:提供知识库 Dify 连接及默认同步参数的查看、编辑和保存界面。
|
||||
* 依赖:Vue 响应式 API、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。
|
||||
* 依赖:Vue 响应式 API、Element Plus、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。表单按连接、检索、分段三块排,密钥默认遮挡;开关行按左标题、开关、右标题、数字四列对齐。
|
||||
*/
|
||||
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { reactive, ref, useId, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
} from 'element-plus';
|
||||
import { getKbDifySettings, updateKbDifySettings } from '../api/kb.api';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; saved: [message: string]; error: [message: string] }>();
|
||||
const { t } = useI18n();
|
||||
const vLoading = ElLoading.directive;
|
||||
const rerankLabelId = useId();
|
||||
const topKLabelId = useId();
|
||||
const scoreSwitchLabelId = useId();
|
||||
const scoreValueLabelId = useId();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
@@ -108,94 +125,243 @@ watch(() => props.open, (open) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="dialog-overlay" @click="close">
|
||||
<div class="dialog-panel max-w-3xl max-h-[92vh] overflow-y-auto" @click.stop>
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title">{{ t('kbDifySettings.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="close">
|
||||
{{ t('common.close') }}
|
||||
</button>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="(value) => { if (!value) close(); }"
|
||||
>
|
||||
<template #header="{ titleId, titleClass }">
|
||||
<div class="dify-settings-heading">
|
||||
<span :id="titleId" :class="titleClass">{{ t('kbDifySettings.title') }}</span>
|
||||
<p class="dify-settings-subtitle">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<div v-loading="loading" class="dify-settings-body">
|
||||
<ElForm v-if="!loading" class="dify-settings-form" label-position="top" :model="form">
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.connection') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-stack">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.baseUrl')">
|
||||
<ElInput v-model="form.DIFY_API_BASE" placeholder="https://api.dify.ai/v1" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.apiKey')">
|
||||
<ElInput v-model="form.DIFY_API_KEY" type="password" show-password autocomplete="off" placeholder="app-..." />
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div v-if="loading" class="px-5 sm:px-8 py-16 text-center text-sm text-muted">{{ t('kbDifySettings.loading') }}</div>
|
||||
<div v-else class="px-5 sm:px-8 py-5 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.baseUrl') }}</span>
|
||||
<input v-model="form.DIFY_API_BASE" class="input-field text-sm" placeholder="https://api.dify.ai/v1" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.apiKey') }}</span>
|
||||
<input v-model="form.DIFY_API_KEY" class="input-field text-sm" placeholder="app-..." />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.permission') }}</span>
|
||||
<select v-model="form.KB_DIFY_PERMISSION" class="input-field text-sm">
|
||||
<option value="only_me">{{ t('kbDifySettings.options.permission.onlyMe') }}</option>
|
||||
<option value="all_team_members">{{ t('kbDifySettings.options.permission.allTeamMembers') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.indexingTechnique') }}</span>
|
||||
<select v-model="form.KB_DIFY_INDEXING_TECHNIQUE" class="input-field text-sm">
|
||||
<option value="high_quality">{{ t('kbDifySettings.options.indexingTechnique.highQuality') }}</option>
|
||||
<option value="economy">{{ t('kbDifySettings.options.indexingTechnique.economy') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.searchMethod') }}</span>
|
||||
<select v-model="form.KB_DIFY_SEARCH_METHOD" class="input-field text-sm">
|
||||
<option value="semantic_search">{{ t('kbDifySettings.options.searchMethod.semanticSearch') }}</option>
|
||||
<option value="hybrid_search">{{ t('kbDifySettings.options.searchMethod.hybridSearch') }}</option>
|
||||
<option value="full_text_search">{{ t('kbDifySettings.options.searchMethod.fullTextSearch') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.documentForm') }}</span>
|
||||
<select v-model="form.KB_DIFY_DOC_FORM" class="input-field text-sm">
|
||||
<option value="text_model">{{ t('kbDifySettings.options.documentForm.textModel') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_RERANKING_ENABLE" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_TOP_K" type="number" min="1" max="10" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SCORE_THRESHOLD" type="number" min="0" max="1" step="0.01" class="input-field text-sm" :disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokens') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokensExcel') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentChunkOverlap') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" type="number" min="0" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
</div>
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.retrieval') }}</p>
|
||||
<div class="dify-settings-panel">
|
||||
<div class="dify-settings-grid">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.permission')">
|
||||
<ElSelect v-model="form.KB_DIFY_PERMISSION">
|
||||
<ElOption value="only_me" :label="t('kbDifySettings.options.permission.onlyMe')" />
|
||||
<ElOption value="all_team_members" :label="t('kbDifySettings.options.permission.allTeamMembers')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.indexingTechnique')">
|
||||
<ElSelect v-model="form.KB_DIFY_INDEXING_TECHNIQUE">
|
||||
<ElOption value="high_quality" :label="t('kbDifySettings.options.indexingTechnique.highQuality')" />
|
||||
<ElOption value="economy" :label="t('kbDifySettings.options.indexingTechnique.economy')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.searchMethod')">
|
||||
<ElSelect v-model="form.KB_DIFY_SEARCH_METHOD">
|
||||
<ElOption value="semantic_search" :label="t('kbDifySettings.options.searchMethod.semanticSearch')" />
|
||||
<ElOption value="hybrid_search" :label="t('kbDifySettings.options.searchMethod.hybridSearch')" />
|
||||
<ElOption value="full_text_search" :label="t('kbDifySettings.options.searchMethod.fullTextSearch')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.documentForm')">
|
||||
<ElSelect v-model="form.KB_DIFY_DOC_FORM">
|
||||
<ElOption value="text_model" :label="t('kbDifySettings.options.documentForm.textModel')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="close">
|
||||
{{ t('common.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary" :disabled="saving" @click="save">
|
||||
{{ saving ? t('kbDifySettings.saving') : t('kbDifySettings.save') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="dify-settings-switch-grid">
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="rerankLabelId">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_RERANKING_ENABLE" :aria-labelledby="rerankLabelId" />
|
||||
<span :id="topKLabelId">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_TOP_K"
|
||||
:min="1"
|
||||
:max="10"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
:aria-labelledby="topKLabelId"
|
||||
/>
|
||||
</div>
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="scoreSwitchLabelId">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" :aria-labelledby="scoreSwitchLabelId" />
|
||||
<span :id="scoreValueLabelId">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_SCORE_THRESHOLD"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
:disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED"
|
||||
:aria-labelledby="scoreValueLabelId"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.chunking') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-segments">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokens')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokensExcel')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentChunkOverlap')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" :min="0" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.tokens') }}</p>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="close">{{ t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="saving" @click="save">{{ t('kbDifySettings.save') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dify-settings-heading {
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
.dify-settings-subtitle {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.dify-settings-body {
|
||||
min-height: 8rem;
|
||||
}
|
||||
|
||||
.dify-settings-section + .dify-settings-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-section-title {
|
||||
margin: 0 0 8px;
|
||||
color: var(--el-text-color-primary);
|
||||
font-size: var(--el-font-size-base);
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-panel {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
}
|
||||
|
||||
.dify-settings-stack,
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
display: grid;
|
||||
gap: 12px 16px;
|
||||
}
|
||||
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item__label) {
|
||||
margin-bottom: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-select),
|
||||
.dify-settings-stack :deep(.el-input),
|
||||
.dify-settings-segments :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dify-settings-segments :deep(.el-form-item__content) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.dify-settings-hint {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto max-content 8.5rem;
|
||||
column-gap: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row {
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
grid-column: 1 / -1;
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
color: var(--el-text-color-regular);
|
||||
font-size: var(--el-font-size-base);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-input-number .el-input__inner) {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 8.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid,
|
||||
.dify-settings-switch-row {
|
||||
grid-template-columns: 1fr;
|
||||
row-gap: 8px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,28 +2,33 @@
|
||||
/**
|
||||
* features/kb/components/KbAdminPanel.vue
|
||||
* 知识库配置面板(治理面:分组、Dify)。
|
||||
* 依赖:kb.api、DifySettingsDialog、DifyHealthDialog、DeleteConfirmDialog、Vue I18n。
|
||||
* 逻辑:管理控制台加载知识库分组;分组列表在主表格过滤排序,新增/编辑通过右侧抽屉提交。
|
||||
* 依赖:kb.api、Element Plus、DifySettingsDialog、DifyHealthDialog、Vue I18n。
|
||||
* 逻辑:管理控制台加载知识库分组;列表、表头排序、文档数筛选、分页和删除确认用 Element。排序和筛选都作用在全量数据上,再分页。新增/编辑走 KbGroupDrawer。
|
||||
*/
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CircleCheck, Plus, Search, Setting, Tools } from '@element-plus/icons-vue';
|
||||
import {
|
||||
Activity,
|
||||
Pencil,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Search,
|
||||
Settings,
|
||||
Trash2,
|
||||
Wrench,
|
||||
} from 'lucide-vue-next';
|
||||
ElAlert,
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElInput,
|
||||
ElLoading,
|
||||
ElMessageBox,
|
||||
ElPagination,
|
||||
ElSpace,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import KbGroupDrawer, { type KbGroupFormValue } from './KbGroupDrawer.vue';
|
||||
import DifyHealthDialog from './DifyHealthDialog.vue';
|
||||
import DifySettingsDialog from './DifySettingsDialog.vue';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { WORKSPACE_PATHS } from '@/features/workspace/constants/routes';
|
||||
import {
|
||||
createKbGroup,
|
||||
@@ -35,35 +40,42 @@ import {
|
||||
import { formatDateTime } from '../utils/kb-display.utils';
|
||||
|
||||
type GroupFilterMode = 'all' | 'withDocs' | 'empty';
|
||||
type GroupSortMode = 'updatedDesc' | 'updatedAsc' | 'docsDesc' | 'docsAsc' | 'nameAsc';
|
||||
type GroupSortKey = 'name' | 'document_count' | 'updated_at';
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const groups = ref<KbGroup[]>([]);
|
||||
const isSubmitting = ref(false);
|
||||
const isDeleting = ref(false);
|
||||
const isRefreshing = ref(false);
|
||||
const isRefreshing = ref(true);
|
||||
const editingGroupId = ref<number | null>(null);
|
||||
const form = ref<KbGroupFormValue>({ name: '', description: '' });
|
||||
const feedback = ref('');
|
||||
const feedbackType = ref<'success' | 'error' | ''>('');
|
||||
const settingsDialogOpen = ref(false);
|
||||
const healthDialogOpen = ref(false);
|
||||
const deleteDialogOpen = ref(false);
|
||||
const drawerOpen = ref(false);
|
||||
const deletingGroup = ref<KbGroup | null>(null);
|
||||
const searchKeyword = ref('');
|
||||
const filterMode = ref<GroupFilterMode>('all');
|
||||
const sortMode = ref<GroupSortMode>('updatedDesc');
|
||||
const sortKey = ref<GroupSortKey | ''>('updated_at');
|
||||
const sortDir = ref<'asc' | 'desc' | ''>('desc');
|
||||
const currentPage = ref(1);
|
||||
const pageSize = ref(20);
|
||||
|
||||
const filterOptions: GroupFilterMode[] = ['all', 'withDocs', 'empty'];
|
||||
const sortOptions: GroupSortMode[] = ['updatedDesc', 'updatedAsc', 'docsDesc', 'docsAsc', 'nameAsc'];
|
||||
const pageSizeOptions = [10, 20, 50, 100];
|
||||
|
||||
const totalDocuments = computed(() => groups.value.reduce((total, group) => total + (group.document_count ?? 0), 0));
|
||||
/**
|
||||
* 文档数表头筛选项。
|
||||
* 核心逻辑:不放「全部」;Element 筛选面板的重置会清空条件,等同于全部。
|
||||
*/
|
||||
const documentFilters = computed(() => [
|
||||
{ text: t('kbAdmin.filters.withDocs'), value: 'withDocs' },
|
||||
{ text: t('kbAdmin.filters.empty'), value: 'empty' },
|
||||
]);
|
||||
|
||||
const filteredGroups = computed(() => {
|
||||
const keyword = searchKeyword.value.trim().toLowerCase();
|
||||
const matched = groups.value.filter((group) => {
|
||||
@@ -77,16 +89,17 @@ const filteredGroups = computed(() => {
|
||||
return matchesKeyword && matchesFilter;
|
||||
});
|
||||
|
||||
if (!sortKey.value || !sortDir.value) return matched;
|
||||
return [...matched].sort((a, b) => {
|
||||
const docsA = a.document_count ?? 0;
|
||||
const docsB = b.document_count ?? 0;
|
||||
const updatedA = Date.parse(a.updated_at || '') || 0;
|
||||
const updatedB = Date.parse(b.updated_at || '') || 0;
|
||||
if (sortMode.value === 'updatedAsc') return updatedA - updatedB;
|
||||
if (sortMode.value === 'docsDesc') return docsB - docsA;
|
||||
if (sortMode.value === 'docsAsc') return docsA - docsB;
|
||||
if (sortMode.value === 'nameAsc') return a.name.localeCompare(b.name, undefined, { numeric: true });
|
||||
return updatedB - updatedA;
|
||||
let result = 0;
|
||||
if (sortKey.value === 'name') {
|
||||
result = a.name.localeCompare(b.name, undefined, { numeric: true });
|
||||
} else if (sortKey.value === 'document_count') {
|
||||
result = (a.document_count ?? 0) - (b.document_count ?? 0);
|
||||
} else {
|
||||
result = (Date.parse(a.updated_at || '') || 0) - (Date.parse(b.updated_at || '') || 0);
|
||||
}
|
||||
return sortDir.value === 'asc' ? result : -result;
|
||||
});
|
||||
});
|
||||
const pagedGroups = computed(() => {
|
||||
@@ -94,19 +107,33 @@ const pagedGroups = computed(() => {
|
||||
return filteredGroups.value.slice(start, start + pageSize.value);
|
||||
});
|
||||
|
||||
/**
|
||||
* 表格空状态文案。
|
||||
* 核心逻辑:一个分组都没有时提示去创建;有分组但筛选后为空时提示调整条件。
|
||||
*/
|
||||
const tableEmptyText = computed(() => (
|
||||
groups.value.length === 0 ? t('kbAdmin.groupsEmpty') : t('kbAdmin.filters.emptyResult')
|
||||
));
|
||||
|
||||
/** 格式化分组更新时间,避免管理台表格直接暴露后端 ISO 时间字符串。 */
|
||||
const formatGroupUpdatedAt = (value?: string | null) => formatDateTime(value);
|
||||
|
||||
/** 加载知识库治理页的分组数据,供页面初始渲染和操作后刷新复用。 */
|
||||
/**
|
||||
* 加载知识库治理页的分组数据,供页面初始渲染和操作后刷新复用。
|
||||
* 核心逻辑:只等分组列表;失败写入页面提示,并用 finally 关掉表格加载态。
|
||||
*/
|
||||
const loadData = async () => {
|
||||
isRefreshing.value = true;
|
||||
const groupsResult = await getKbGroupsSafe();
|
||||
if (groupsResult.ok) groups.value = groupsResult.data;
|
||||
else {
|
||||
feedback.value = groupsResult.error || t('kbAdmin.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
try {
|
||||
const groupsResult = await getKbGroupsSafe();
|
||||
if (groupsResult.ok) groups.value = groupsResult.data;
|
||||
else {
|
||||
feedback.value = groupsResult.error || t('kbAdmin.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false;
|
||||
}
|
||||
isRefreshing.value = false;
|
||||
};
|
||||
|
||||
/** 重置分组表单到新建状态,关闭抽屉或切换新建时清空当前编辑对象。 */
|
||||
@@ -162,17 +189,27 @@ const handleSubmitGroup = async () => {
|
||||
await loadData();
|
||||
};
|
||||
|
||||
/** 打开分组删除确认弹窗,确认前不直接调用删除接口。 */
|
||||
const handleDeleteGroup = (group: KbGroup) => {
|
||||
deletingGroup.value = group;
|
||||
deleteDialogOpen.value = true;
|
||||
};
|
||||
|
||||
/** 确认删除当前选中的分组,并在成功后同步刷新列表与编辑表单状态。 */
|
||||
const handleDeleteGroupConfirm = async () => {
|
||||
if (!deletingGroup.value) return;
|
||||
/**
|
||||
* 确认后删除分组,并刷新列表。
|
||||
* 核心逻辑:Element 确认框取消会 reject,这里直接返回,不调用删除接口。
|
||||
* @param group - 待删除的分组
|
||||
*/
|
||||
const handleDeleteGroup = async (group: KbGroup) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
t('kbAdmin.deleteDialog.message', { name: group.name }),
|
||||
t('kbAdmin.deleteDialog.title'),
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
},
|
||||
);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
isDeleting.value = true;
|
||||
const result = await deleteKbGroup(deletingGroup.value.id);
|
||||
const result = await deleteKbGroup(group.id);
|
||||
isDeleting.value = false;
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || t('kbAdmin.msg.deleteFailed');
|
||||
@@ -180,15 +217,46 @@ const handleDeleteGroupConfirm = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editingGroupId.value === deletingGroup.value.id) closeDrawer();
|
||||
if (editingGroupId.value === group.id) closeDrawer();
|
||||
feedback.value = t('kbAdmin.msg.deleted');
|
||||
feedbackType.value = 'success';
|
||||
deleteDialogOpen.value = false;
|
||||
deletingGroup.value = null;
|
||||
await loadData();
|
||||
};
|
||||
|
||||
watch([searchKeyword, filterMode, sortMode, pageSize], () => {
|
||||
/**
|
||||
* 按文档数表头筛选全部分组,并回到第一页。
|
||||
* 核心逻辑:筛选发生在分页之前。未选或重置时显示全部;单选时只留有文档或空分组。
|
||||
* @param filters - Element 按 column-key 给出的已选值
|
||||
*/
|
||||
function onFilterChange(filters: Record<string, string[]>): void {
|
||||
const selected = filters.document_count ?? [];
|
||||
if (selected.length === 1 && (selected[0] === 'withDocs' || selected[0] === 'empty')) {
|
||||
filterMode.value = selected[0];
|
||||
} else {
|
||||
filterMode.value = 'all';
|
||||
}
|
||||
currentPage.value = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按表头把筛选后的全部分组重排,并回到第一页。
|
||||
* 核心逻辑:排序发生在分页之前,所以翻页后顺序不变。第三次点击表头时 Element 清空排序,列表回到接口原顺序。
|
||||
* @param payload.prop - 列字段
|
||||
* @param payload.order - ascending、descending 或空
|
||||
*/
|
||||
function onSortChange(payload: { prop: string | null; order: string | null }): void {
|
||||
const field = payload.prop;
|
||||
if ((field === 'name' || field === 'document_count' || field === 'updated_at') && payload.order) {
|
||||
sortKey.value = field;
|
||||
sortDir.value = payload.order === 'ascending' ? 'asc' : 'desc';
|
||||
} else {
|
||||
sortKey.value = '';
|
||||
sortDir.value = '';
|
||||
}
|
||||
currentPage.value = 1;
|
||||
}
|
||||
|
||||
watch([searchKeyword, pageSize], () => {
|
||||
currentPage.value = 1;
|
||||
});
|
||||
|
||||
@@ -200,142 +268,98 @@ defineExpose({ loadData });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="animate-fade-in-up">
|
||||
<div class="kb-admin-header">
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section class="admin-table-section">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="text-xl font-bold text-primary">{{ t('kbAdmin.groupsTitle') }}</h2>
|
||||
<h2 class="section-title">{{ t('kbAdmin.groupsTitle') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('kbAdmin.groupManageSubtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex w-full shrink-0 flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:justify-end">
|
||||
<div class="kb-admin-toolbar" role="toolbar" :aria-label="t('kbAdmin.toolbar')">
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="settingsDialogOpen = true" :title="t('kbAdmin.difySettings')">
|
||||
<Settings class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.difySettings') }}</span>
|
||||
</button>
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="healthDialogOpen = true" :title="t('kbAdmin.healthCheck')">
|
||||
<Activity class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.healthCheck') }}</span>
|
||||
</button>
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="loadData" :title="t('common.refresh')">
|
||||
<RefreshCw class="h-4 w-4 shrink-0" :class="{ 'animate-spin': isRefreshing }" />
|
||||
<span class="whitespace-nowrap">{{ t('common.refresh') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="router.push(WORKSPACE_PATHS.knowledgeBase)">
|
||||
<Wrench class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.goWorkspace') }}</span>
|
||||
</button>
|
||||
<button type="button" class="btn-primary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="openCreateDrawer">
|
||||
<Plus class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.form.create') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<ElSpace wrap>
|
||||
<ElButton :icon="Setting" @click="settingsDialogOpen = true">{{ t('kbAdmin.difySettings') }}</ElButton>
|
||||
<ElButton :icon="CircleCheck" @click="healthDialogOpen = true">{{ t('kbAdmin.healthCheck') }}</ElButton>
|
||||
<ElButton :icon="Tools" @click="router.push(WORKSPACE_PATHS.knowledgeBase)">{{ t('kbAdmin.goWorkspace') }}</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDrawer">{{ t('kbAdmin.form.create') }}</ElButton>
|
||||
</ElSpace>
|
||||
</div>
|
||||
|
||||
<div class="kb-admin-body">
|
||||
<section class="admin-table-section">
|
||||
<div class="admin-table-filters flex flex-col gap-4">
|
||||
<div class="grid grid-cols-1 gap-3 lg:grid-cols-[minmax(16rem,1fr)_auto_minmax(11rem,14rem)] lg:items-center">
|
||||
<label class="relative min-w-0">
|
||||
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
|
||||
<input v-model="searchKeyword" class="input-field w-full pl-9" :placeholder="t('kbAdmin.filters.searchPlaceholder')" />
|
||||
</label>
|
||||
<div class="inline-flex w-full overflow-hidden rounded-xl border border-default bg-surface lg:w-auto">
|
||||
<button
|
||||
v-for="option in filterOptions"
|
||||
:key="option"
|
||||
type="button"
|
||||
class="min-w-0 flex-1 whitespace-nowrap px-4 py-2.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover:text-primary lg:flex-none"
|
||||
:class="{ 'bg-brand-50 text-brand-700': filterMode === option }"
|
||||
@click="filterMode = option"
|
||||
>
|
||||
{{ t(`kbAdmin.filters.${option}`) }}
|
||||
</button>
|
||||
</div>
|
||||
<select v-model="sortMode" class="select-field w-full">
|
||||
<option v-for="option in sortOptions" :key="option" :value="option">
|
||||
{{ t(`kbAdmin.sort.${option}`) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-xs text-muted">
|
||||
<span>{{ t('kbAdmin.stats.groups', { count: groups.length }) }}</span>
|
||||
<span>{{ t('kbAdmin.stats.documents', { count: totalDocuments }) }}</span>
|
||||
<span>{{ t('kbAdmin.stats.visible', { count: filteredGroups.length }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="feedback" class="mx-6 mt-4 rounded-xl border px-4 py-3 text-sm" :class="feedbackType === 'error' ? 'border-rose-200 bg-rose-50 text-rose-600' : 'border-emerald-200 bg-emerald-50 text-emerald-700'">
|
||||
{{ feedback }}
|
||||
</p>
|
||||
|
||||
<div v-if="groups.length === 0" class="admin-table-empty">{{ t('kbAdmin.groupsEmpty') }}</div>
|
||||
<div v-else-if="filteredGroups.length === 0" class="admin-table-empty">{{ t('kbAdmin.filters.emptyResult') }}</div>
|
||||
<div v-else>
|
||||
<div class="admin-table-wrap hidden md:block">
|
||||
<table class="admin-table table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-[20%] px-6 py-3 text-xs">{{ t('kbAdmin.table.name') }}</th>
|
||||
<th class="w-[30%] px-6 py-3 text-xs">{{ t('kbAdmin.table.description') }}</th>
|
||||
<th class="w-[12%] px-6 py-3 text-xs">{{ t('kbAdmin.table.documents') }}</th>
|
||||
<th class="w-[26%] px-6 py-3 text-xs">{{ t('kbAdmin.table.updatedAt') }}</th>
|
||||
<th class="w-[12%] px-6 py-3 text-right text-xs">{{ t('kbAdmin.table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="group in pagedGroups" :key="group.id">
|
||||
<td class="px-6 py-4 align-middle"><div class="truncate font-semibold text-primary" :title="group.name">{{ group.name }}</div></td>
|
||||
<td class="px-6 py-4 align-middle text-sm text-muted">
|
||||
<div class="truncate" :title="group.description || t('kbAdmin.noDescription')">
|
||||
{{ group.description || t('kbAdmin.noDescription') }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 align-middle"><span class="kb-admin-badge whitespace-nowrap">{{ group.document_count ?? 0 }}</span></td>
|
||||
<td class="px-6 py-4 align-middle text-sm text-muted"><div class="truncate" :title="formatGroupUpdatedAt(group.updated_at)">{{ formatGroupUpdatedAt(group.updated_at) }}</div></td>
|
||||
<td class="px-6 py-4 align-middle">
|
||||
<div class="flex justify-end gap-1.5">
|
||||
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
|
||||
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600 hover:bg-rose-50" @click="handleDeleteGroup(group)" :disabled="isDeleting" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 p-4 md:hidden">
|
||||
<article v-for="group in pagedGroups" :key="group.id" class="kb-admin-card">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<h3 class="font-semibold text-primary">{{ group.name }}</h3>
|
||||
<p class="mt-1 line-clamp-2 text-sm text-muted" :title="group.description || t('kbAdmin.noDescription')">{{ group.description || t('kbAdmin.noDescription') }}</p>
|
||||
</div>
|
||||
<span class="kb-admin-badge">{{ group.document_count ?? 0 }}</span>
|
||||
</div>
|
||||
<div class="mt-3 flex items-center justify-between gap-3">
|
||||
<span class="text-xs text-muted">{{ formatGroupUpdatedAt(group.updated_at) }}</span>
|
||||
<div class="flex gap-1.5">
|
||||
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
|
||||
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600" @click="handleDeleteGroup(group)" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-default px-6 py-4">
|
||||
<PaginationBar
|
||||
v-model:page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:total="filteredGroups.length"
|
||||
:page-size-options="pageSizeOptions"
|
||||
<div class="kb-admin-filters">
|
||||
<div class="kb-element-filters">
|
||||
<ElInput
|
||||
v-model="searchKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
:placeholder="t('kbAdmin.filters.searchPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<ElAlert
|
||||
v-if="feedback"
|
||||
class="kb-admin-alert"
|
||||
:title="feedback"
|
||||
:type="feedbackType === 'error' ? 'error' : 'success'"
|
||||
show-icon
|
||||
closable
|
||||
@close="feedback = ''"
|
||||
/>
|
||||
|
||||
<ElTable
|
||||
v-loading="isRefreshing"
|
||||
class="hx-admin-table"
|
||||
:data="pagedGroups"
|
||||
row-key="id"
|
||||
:default-sort="{ prop: 'updated_at', order: 'descending' }"
|
||||
:empty-text="tableEmptyText"
|
||||
@sort-change="onSortChange"
|
||||
@filter-change="onFilterChange"
|
||||
>
|
||||
<ElTableColumn prop="name" :label="t('kbAdmin.table.name')" min-width="160" sortable="custom">
|
||||
<template #default="{ row }">
|
||||
<div class="truncate" :title="(row as KbGroup).name">{{ (row as KbGroup).name }}</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('kbAdmin.table.description')" min-width="220">
|
||||
<template #default="{ row }">
|
||||
<div class="truncate hx-element-hint" :title="(row as KbGroup).description || t('kbAdmin.noDescription')">
|
||||
{{ (row as KbGroup).description || t('kbAdmin.noDescription') }}
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="document_count"
|
||||
column-key="document_count"
|
||||
:label="t('kbAdmin.table.documents')"
|
||||
width="160"
|
||||
sortable="custom"
|
||||
:filters="documentFilters"
|
||||
:filter-multiple="false"
|
||||
>
|
||||
<template #default="{ row }">{{ (row as KbGroup).document_count ?? 0 }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="updated_at" :label="t('kbAdmin.table.updatedAt')" min-width="180" sortable="custom">
|
||||
<template #default="{ row }">{{ formatGroupUpdatedAt((row as KbGroup).updated_at) }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('kbAdmin.table.actions')" width="160" align="right">
|
||||
<template #default="{ row }">
|
||||
<ElButton link type="primary" @click="openEditDrawer(row as KbGroup)">{{ t('common.edit') }}</ElButton>
|
||||
<ElButton link type="danger" :disabled="isDeleting" @click="handleDeleteGroup(row as KbGroup)">
|
||||
{{ t('common.delete') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<div v-if="filteredGroups.length > 0" class="hx-admin-pager">
|
||||
<ElPagination
|
||||
v-model:current-page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:total="filteredGroups.length"
|
||||
:page-sizes="pageSizeOptions"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
background
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<KbGroupDrawer
|
||||
v-model:form="form"
|
||||
@@ -348,5 +372,32 @@ defineExpose({ loadData });
|
||||
|
||||
<DifySettingsDialog :open="settingsDialogOpen" @close="settingsDialogOpen = false" @saved="(message) => { feedback = message; feedbackType = 'success'; void loadData(); }" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
|
||||
<DifyHealthDialog :open="healthDialogOpen" @close="healthDialogOpen = false" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
|
||||
<DeleteConfirmDialog v-model="deleteDialogOpen" :title="t('kbAdmin.deleteDialog.title')" :message="t('kbAdmin.deleteDialog.message', { name: deletingGroup?.name || '' })" :confirm-loading="isDeleting" @confirm="handleDeleteGroupConfirm" @cancel="() => { deleteDialogOpen = false; deletingGroup = null; }" />
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-admin-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px 24px;
|
||||
padding: 16px 32px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.kb-admin-alert {
|
||||
margin: 16px 32px 0;
|
||||
}
|
||||
|
||||
.kb-element-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.kb-element-filters :deep(.el-input) {
|
||||
width: 16rem;
|
||||
flex: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,14 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/kb/components/KbGroupDrawer.vue
|
||||
* 知识库分组新建/编辑抽屉表单。
|
||||
* 依赖:Vue I18n、lucide-vue-next、父级 KbAdminPanel 传入的表单状态。
|
||||
* 逻辑:只负责抽屉展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
|
||||
* 知识库分组新建/编辑弹窗。
|
||||
* 依赖:Element Plus 对话框与表单、Vue I18n、父级 KbAdminPanel 传入的表单状态。
|
||||
* 逻辑:只负责弹窗展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
|
||||
* 字段只有名称和描述,用随内容增高的对话框,避免整屏抽屉留下大块空白。
|
||||
*/
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { FolderPlus, X } from 'lucide-vue-next';
|
||||
import { FolderAdd } from '@element-plus/icons-vue';
|
||||
import { ElButton, ElDialog, ElForm, ElFormItem, ElInput } from 'element-plus';
|
||||
|
||||
export interface KbGroupFormValue {
|
||||
name: string;
|
||||
@@ -37,7 +39,11 @@ const submitText = computed(() => {
|
||||
return props.mode === 'edit' ? t('kbAdmin.form.saveChanges') : t('kbAdmin.form.create');
|
||||
});
|
||||
|
||||
/** 更新指定表单字段,并将完整表单值同步回父组件。 */
|
||||
/**
|
||||
* 更新指定表单字段,并将完整表单值同步回父组件。
|
||||
* @param field - 要改的字段,只能是名称或描述
|
||||
* @param value - 输入框当前文本
|
||||
*/
|
||||
const updateField = (field: keyof KbGroupFormValue, value: string) => {
|
||||
emit('update:form', {
|
||||
...props.form,
|
||||
@@ -47,81 +53,53 @@ const updateField = (field: keyof KbGroupFormValue, value: string) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="kb-admin-drawer">
|
||||
<div v-if="open" class="fixed inset-0 z-[100] bg-overlay backdrop-blur-sm" @click.self="emit('close')">
|
||||
<aside class="ml-auto flex h-full w-full max-w-[440px] flex-col border-l border-default bg-surface shadow-elevated">
|
||||
<header class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<p class="section-desc mt-1">{{ formDescription }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')" :title="t('common.close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div class="flex-1 space-y-5 overflow-y-auto px-6 py-5">
|
||||
<div>
|
||||
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupName') }}</label>
|
||||
<input
|
||||
:value="form.name"
|
||||
class="input-field"
|
||||
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
|
||||
@input="updateField('name', ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupDesc') }}</label>
|
||||
<textarea
|
||||
:value="form.description"
|
||||
rows="8"
|
||||
class="input-field"
|
||||
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
|
||||
@input="updateField('description', ($event.target as HTMLTextAreaElement).value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="flex justify-end gap-2 border-t border-default px-6 py-4">
|
||||
<button type="button" class="btn-secondary inline-flex items-center gap-1.5 px-4 py-2 text-sm" @click="emit('close')">
|
||||
<X class="h-4 w-4 shrink-0" />
|
||||
{{ t('common.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary inline-flex items-center gap-1.5 px-5 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="submitting"
|
||||
@click="emit('submit')"
|
||||
>
|
||||
<FolderPlus v-if="!submitting" class="h-4 w-4 shrink-0" />
|
||||
{{ submitText }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="!submitting"
|
||||
:close-on-press-escape="!submitting"
|
||||
:show-close="!submitting"
|
||||
@close="emit('close')"
|
||||
>
|
||||
<template #header>
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">{{ formDescription }}</p>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<ElForm class="kb-group-form" label-position="top" @submit.prevent="emit('submit')">
|
||||
<ElFormItem :label="t('kbAdmin.form.groupName')">
|
||||
<ElInput
|
||||
:model-value="form.name"
|
||||
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
|
||||
@update:model-value="updateField('name', String($event))"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbAdmin.form.groupDesc')">
|
||||
<ElInput
|
||||
:model-value="form.description"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
|
||||
@update:model-value="updateField('description', String($event))"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<template #footer>
|
||||
<ElButton :disabled="submitting" @click="emit('close')">{{ t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :icon="FolderAdd" :loading="submitting" @click="emit('submit')">
|
||||
{{ submitText }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-admin-drawer-enter-active,
|
||||
.kb-admin-drawer-leave-active {
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-active aside,
|
||||
.kb-admin-drawer-leave-active aside {
|
||||
transition: transform 0.18s ease;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-from,
|
||||
.kb-admin-drawer-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-from aside,
|
||||
.kb-admin-drawer-leave-to aside {
|
||||
transform: translateX(100%);
|
||||
.kb-group-form :deep(.el-form-item:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -2,12 +2,21 @@
|
||||
"kbDifySettings": {
|
||||
"title": "Dify Settings",
|
||||
"subtitle": "Manage Dify connection and default sync parameters for the knowledge base module.",
|
||||
"sections": {
|
||||
"connection": "Connection",
|
||||
"retrieval": "Retrieval",
|
||||
"chunking": "Chunking"
|
||||
},
|
||||
"hints": {
|
||||
"maxTokens": "Max tokens",
|
||||
"tokens": "Tokens"
|
||||
},
|
||||
"loading": "Loading settings...",
|
||||
"save": "Save Settings",
|
||||
"saving": "Saving...",
|
||||
"fields": {
|
||||
"baseUrl": "Dify Base URL",
|
||||
"apiKey": "Dify API Key",
|
||||
"baseUrl": "Base URL",
|
||||
"apiKey": "API key",
|
||||
"permission": "Visibility permission",
|
||||
"indexingTechnique": "Indexing mode",
|
||||
"searchMethod": "Search Method",
|
||||
@@ -16,9 +25,9 @@
|
||||
"topK": "Result count (Top K)",
|
||||
"scoreThresholdEnabled": "Enable score threshold",
|
||||
"scoreThreshold": "Score threshold",
|
||||
"segmentMaxTokens": "Maximum tokens per segment (documents)",
|
||||
"segmentMaxTokensExcel": "Maximum tokens per segment (Excel/CSV)",
|
||||
"segmentChunkOverlap": "Overlapping tokens per segment"
|
||||
"segmentMaxTokens": "Documents",
|
||||
"segmentMaxTokensExcel": "Excel/CSV",
|
||||
"segmentChunkOverlap": "Overlap"
|
||||
},
|
||||
"options": {
|
||||
"permission": {
|
||||
@@ -52,9 +61,9 @@
|
||||
"unreachable": "Unreachable",
|
||||
"notConfigured": "Not configured",
|
||||
"datasetCount": "Dataset Count",
|
||||
"configured": "Configured: ",
|
||||
"configured": "Configured",
|
||||
"boundGroups": "Bound Groups",
|
||||
"localSyncRecords": "Local Sync Records: ",
|
||||
"localSyncRecords": "Local sync records",
|
||||
"syncingVersions": "Syncing Versions",
|
||||
"syncedVersions": "Synced Versions",
|
||||
"pendingSyncJobs": "Pending Sync Jobs",
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
"kbDifySettings": {
|
||||
"title": "ตั้งค่า Dify",
|
||||
"subtitle": "จัดการการเชื่อมต่อ Dify และค่าซิงค์เริ่มต้นของโมดูลคลังความรู้",
|
||||
"sections": {
|
||||
"connection": "การเชื่อมต่อ",
|
||||
"retrieval": "การค้นหา",
|
||||
"chunking": "การแบ่งส่วน"
|
||||
},
|
||||
"hints": {
|
||||
"maxTokens": "โทเค็นสูงสุด",
|
||||
"tokens": "โทเค็น"
|
||||
},
|
||||
"loading": "กำลังโหลดการตั้งค่า...",
|
||||
"save": "บันทึกการตั้งค่า",
|
||||
"saving": "กำลังบันทึก...",
|
||||
"fields": {
|
||||
"baseUrl": "URL พื้นฐานของ Dify",
|
||||
"apiKey": "คีย์ API ของ Dify",
|
||||
"baseUrl": "URL พื้นฐาน",
|
||||
"apiKey": "คีย์ API",
|
||||
"permission": "สิทธิ์การเข้าถึง",
|
||||
"indexingTechnique": "โหมดการทำดัชนี",
|
||||
"searchMethod": "วิธีการค้นหา",
|
||||
@@ -16,9 +25,9 @@
|
||||
"topK": "จำนวนผลลัพธ์ (Top K)",
|
||||
"scoreThresholdEnabled": "เปิดใช้เกณฑ์คะแนน",
|
||||
"scoreThreshold": "เกณฑ์คะแนน",
|
||||
"segmentMaxTokens": "โทเค็นสูงสุดต่อส่วน (เอกสารทั่วไป)",
|
||||
"segmentMaxTokensExcel": "โทเค็นสูงสุดต่อส่วน (Excel/CSV)",
|
||||
"segmentChunkOverlap": "จำนวนโทเค็นที่ซ้อนทับระหว่างส่วน"
|
||||
"segmentMaxTokens": "เอกสารทั่วไป",
|
||||
"segmentMaxTokensExcel": "Excel/CSV",
|
||||
"segmentChunkOverlap": "ส่วนซ้อน"
|
||||
},
|
||||
"options": {
|
||||
"permission": {
|
||||
@@ -52,9 +61,9 @@
|
||||
"unreachable": "เข้าถึงไม่ได้",
|
||||
"notConfigured": "ยังไม่ตั้งค่า",
|
||||
"datasetCount": "จำนวน Dataset",
|
||||
"configured": "ตั้งค่าแล้ว: ",
|
||||
"configured": "ตั้งค่าแล้ว",
|
||||
"boundGroups": "กลุ่มที่ผูกแล้ว",
|
||||
"localSyncRecords": "บันทึกซิงค์ภายใน: ",
|
||||
"localSyncRecords": "บันทึกซิงค์ภายใน",
|
||||
"syncingVersions": "เวอร์ชันที่กำลังซิงค์",
|
||||
"syncedVersions": "เวอร์ชันที่ซิงค์แล้ว",
|
||||
"pendingSyncJobs": "งานซิงค์ที่รออยู่",
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
"kbDifySettings": {
|
||||
"title": "Dify 设置",
|
||||
"subtitle": "管理知识库模块使用的 Dify 连接和默认同步参数。",
|
||||
"sections": {
|
||||
"connection": "连接",
|
||||
"retrieval": "检索",
|
||||
"chunking": "分段"
|
||||
},
|
||||
"hints": {
|
||||
"maxTokens": "最大 Token",
|
||||
"tokens": "Token"
|
||||
},
|
||||
"loading": "正在加载设置...",
|
||||
"save": "保存设置",
|
||||
"saving": "保存中...",
|
||||
"fields": {
|
||||
"baseUrl": "Dify 基础 URL",
|
||||
"apiKey": "Dify API 密钥",
|
||||
"baseUrl": "基础 URL",
|
||||
"apiKey": "API 密钥",
|
||||
"permission": "可见权限",
|
||||
"indexingTechnique": "索引模式",
|
||||
"searchMethod": "检索方式",
|
||||
@@ -16,9 +25,9 @@
|
||||
"topK": "返回片段数(Top K)",
|
||||
"scoreThresholdEnabled": "启用相似度阈值",
|
||||
"scoreThreshold": "相似度阈值",
|
||||
"segmentMaxTokens": "普通文档分段最大 Token 数",
|
||||
"segmentMaxTokensExcel": "Excel/CSV 分段最大 Token 数",
|
||||
"segmentChunkOverlap": "分段重叠 Token 数"
|
||||
"segmentMaxTokens": "普通文档",
|
||||
"segmentMaxTokensExcel": "Excel/CSV",
|
||||
"segmentChunkOverlap": "重叠"
|
||||
},
|
||||
"options": {
|
||||
"permission": {
|
||||
@@ -52,9 +61,9 @@
|
||||
"unreachable": "不可访问",
|
||||
"notConfigured": "未配置",
|
||||
"datasetCount": "Dataset 数量",
|
||||
"configured": "配置完成:",
|
||||
"configured": "配置完成",
|
||||
"boundGroups": "已绑定分组",
|
||||
"localSyncRecords": "本地同步记录:",
|
||||
"localSyncRecords": "本地同步记录",
|
||||
"syncingVersions": "同步中版本",
|
||||
"syncedVersions": "已同步版本",
|
||||
"pendingSyncJobs": "待同步任务",
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
"kbDifySettings": {
|
||||
"title": "Dify 設定",
|
||||
"subtitle": "管理知識庫模組使用的 Dify 連線和預設同步參數。",
|
||||
"sections": {
|
||||
"connection": "連線",
|
||||
"retrieval": "檢索",
|
||||
"chunking": "分段"
|
||||
},
|
||||
"hints": {
|
||||
"maxTokens": "最大 Token",
|
||||
"tokens": "Token"
|
||||
},
|
||||
"loading": "正在載入設定...",
|
||||
"save": "儲存設定",
|
||||
"saving": "儲存中...",
|
||||
"fields": {
|
||||
"baseUrl": "Dify 基礎 URL",
|
||||
"apiKey": "Dify API 金鑰",
|
||||
"baseUrl": "基礎 URL",
|
||||
"apiKey": "API 金鑰",
|
||||
"permission": "可見權限",
|
||||
"indexingTechnique": "索引模式",
|
||||
"searchMethod": "檢索方式",
|
||||
@@ -16,9 +25,9 @@
|
||||
"topK": "返回片段數(Top K)",
|
||||
"scoreThresholdEnabled": "啟用相似度閾值",
|
||||
"scoreThreshold": "相似度閾值",
|
||||
"segmentMaxTokens": "一般文件分段最大 Token 數",
|
||||
"segmentMaxTokensExcel": "Excel/CSV 分段最大 Token 數",
|
||||
"segmentChunkOverlap": "分段重疊 Token 數"
|
||||
"segmentMaxTokens": "一般文件",
|
||||
"segmentMaxTokensExcel": "Excel/CSV",
|
||||
"segmentChunkOverlap": "重疊"
|
||||
},
|
||||
"options": {
|
||||
"permission": {
|
||||
@@ -52,9 +61,9 @@
|
||||
"unreachable": "不可訪問",
|
||||
"notConfigured": "未配置",
|
||||
"datasetCount": "Dataset 數量",
|
||||
"configured": "配置完成:",
|
||||
"configured": "配置完成",
|
||||
"boundGroups": "已綁定分組",
|
||||
"localSyncRecords": "本地同步記錄:",
|
||||
"localSyncRecords": "本地同步記錄",
|
||||
"syncingVersions": "同步中版本",
|
||||
"syncedVersions": "已同步版本",
|
||||
"pendingSyncJobs": "待同步任務",
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Jenkins 前端风格检查。只跑 npm run lint,不跑 build。
|
||||
# Element 规则当前是 off,本脚本应通过。启用方式见 docs/ui/ELEMENT_MIGRATION.md §9.2。
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
FRONTEND_DIR="${ROOT_DIR}/frontend"
|
||||
|
||||
if [[ ! -f "${FRONTEND_DIR}/package.json" ]]; then
|
||||
echo "[ci-frontend-lint] missing ${FRONTEND_DIR}/package.json"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${FRONTEND_DIR}"
|
||||
echo "[ci-frontend-lint] npm ci"
|
||||
npm ci
|
||||
echo "[ci-frontend-lint] npm run lint"
|
||||
npm run lint
|
||||
echo "[ci-frontend-lint] OK"
|
||||
Reference in new issue
Block a user