diff --git a/.gitee/PULL_REQUEST_TEMPLATE.md b/.gitee/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..b7096080 --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.md @@ -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` 通过。 + +## 测试 + + diff --git a/Jenkinsfile b/Jenkinsfile index 71f4561a..e0402622 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' } diff --git a/docs/README.md b/docs/README.md index 652851e6..de17406a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 集成说明 | diff --git a/docs/platform/README.md b/docs/platform/README.md index 8fa630f4..0f385f99 100644 --- a/docs/platform/README.md +++ b/docs/platform/README.md @@ -12,5 +12,6 @@ | [progress_contract_platform_prototype.html](progress_contract_platform_prototype.html) | 进度契约平台 HTML 原型 | | [enterprise-integration-center-prototype.md](enterprise-integration-center-prototype.md) | 企业集成中心蓝图(完整愿景,含 HTML 原型) | | [integration-connector-framework-design.md](integration-connector-framework-design.md) | Integration Connector Framework 设计(首期最小可行收敛版) | +| [permission-model.md](permission-model.md) | 现网权限说明:角色包、能力键、应用授权、管理后台 | | [role-permission-prototype.md](role-permission-prototype.md) | 可配置角色权限包(一期约定);[可点击原型](role-permission-prototype.html) | | [awaiting-callback-reconciler-design.md](awaiting-callback-reconciler-design.md) | 通用「等待外部回调」对账器设计(三域超时兜底统一;设计草案,P2+ 未实施) | diff --git a/docs/platform/permission-model.md b/docs/platform/permission-model.md new file mode 100644 index 00000000..38cff601 --- /dev/null +++ b/docs/platform/permission-model.md @@ -0,0 +1,140 @@ +# 系统权限说明 + +> **文档路径**:`docs/platform/permission-model.md` +> **用途**:说明现网权限怎么判、有哪些角色包、有哪些能力键,以及哪些业务只认应用授权或平台管理员。 +> **依赖**:`permission_roles`、`permission_role_agents`、`users.role`、`user_agent_permissions`、`User.get_feature_permissions`。 +> **逻辑**:管理端在 `/admin/permissions` 配角色包;运行时登录态下发 `is_platform_admin` / `role_name` / `feature_permissions`。产品交互约定见 [role-permission-prototype.md](role-permission-prototype.md)。能力目录以 `backend/app/services/permission_roles/catalog.py` 为准。 + +--- + +## 怎么判权 + +一个人只绑一个角色。角色包决定能进哪些应用,以及进了应用之后能做哪些事。平台管理员是特例:应用入口默认全开,也能进管理后台。部门不授权。 + +登录后后端下发三样东西,前端路由守卫和后端接口用同一份结果: + +| 字段 | 含义 | +| --- | --- | +| `is_platform_admin` | 是否平台管理员 | +| `role_name` | 角色显示名 | +| `feature_permissions` | 应用内能力键,值为布尔 | + +三层数据: + +| 层 | 存在哪 | 运行时怎么用 | +| --- | --- | --- | +| 角色包 | `users.role` 指向 `permission_roles.code` | 每人一个。改角色,或改该角色的勾选,会立刻重写这个人的应用授权 | +| 应用入口 | `permission_role_agents`,同步到 `user_agent_permissions` | 聊天和工作台按「有没有这个 Agent」放行。平台管理员不写授权行,入口隐式全开 | +| 应用内能力 | 角色包上的 `feature_permissions` | 已经进了应用之后,再卡统计、强制新建、台账维护这类动作 | + +未种子权限组时,只有 `users.role = admin` 算平台管理员,能力键默认全开。种子之后以权限组上的 `is_platform_admin` 为准,不再用 `hr` 这类角色名暗示能力。种子后禁止按人单独加应用(`POST /users/:id/permissions`、批量权限、按 Agent 授权、权限申请批准加应用)。 + +主要代码: + +- 能力目录与种子角色:`backend/app/services/permission_roles/catalog.py` +- 有效权限计算、按角色重写授权:`backend/app/services/permission_roles/service.py` +- 用户侧合并:`User.get_feature_permissions` / `User.is_platform_admin`(`backend/app/models/user.py`) +- 接口装饰器:`@require_admin`、`@require_agent_permission`(`backend/app/core/decorators.py`) +- 前端守卫:`requiresAdmin`、`requiresFeaturePermission`(`frontend/src/app/router/guards.ts`) + +--- + +## 内置角色包 + +| 编码 | 名称 | 默认给什么 | +| --- | --- | --- | +| `user` | 普通用户 | 新建用户默认。只勾通用入口。企业知识库在这个聊天里切换,不单独占一列权限 | +| `rd` | 研发应用 | 通用入口,以及名称含「专利」的应用 | +| `hr` | 培训 HR | 通用入口、培训应用,并打开 `training_hr_manage` | +| `shipping` | 货代专员 | 通用入口、货代应用,并打开 `shipping_notice_force_create` | +| `admin` | 管理员 | 平台管理员。应用隐式全开,全部能力键默认打开,可进 `/admin` | + +`user`、`hr`、`admin` 是系统角色。`rd`、`shipping` 可以再增删应用。管理员也可以在后台另建角色包。 + +--- + +## 应用内能力键 + +角色编辑里能勾的固定能力。平台管理员默认全开;角色包里可以把某一项关掉。键名与 `KNOWN_FEATURE_KEYS` 对齐。 + +### 培训 + +要先勾上内容画像为 `training` 的应用,卡片里才会出现这项。 + +| 键 | 作用 | +| --- | --- | +| `training_hr_manage` | HR 管理:查看统计、筛选记录、导出 Excel。没有这把钥匙只能当学员使用培训 | + +### 货代发货通知 + +绑定 `agent_code=shipping_notice`。 + +| 键 | 作用 | +| --- | --- | +| `shipping_notice_force_create` | 跳过重复拦截,强制新建发货通知 | +| `shipping_notice.audit_sensitive_read` | 查看审计里的 before / after / Diff 正文 | +| `shipping_notice.xfa_split_rule_edit` | 维护字段拆分规则 | +| `shipping_notice.xfa_split_rule_preview` | 预览拆分结果 | +| `shipping_notice.xfa_split_rule_publish` | 审核并发布拆分规则 | + +后三项主要卡在管理后台的货代模板与审计接口上:先要是平台管理员,再要有对应能力键。 + +### 设备维保 + +绑定名称含「维保」或「维修」,或 `agent_code=maintenance` 的应用。 + +| 键 | 作用 | +| --- | --- | +| `maintenance.ledger_write` | 维护设备台账和维修记录。没有则只能查看 | + +### 订单交期回复 + +绑定 `agent_code=order_delivery_reply`。有 `manage` 就视为同时有 `access`。 + +| 键 | 作用 | +| --- | --- | +| `order_delivery_reply.access` | 只读已同步订单和回复结果 | +| `order_delivery_reply.manage` | 生管回复交期、发送通知、手动同步 | + +读接口要求 `access` 或 `manage`;保存、通知、同步要求 `manage`。部门批量发放只给平台管理员。前端订单交期页用 `requiresFeaturePermission=order_delivery_reply.access` 拦截(持有 `manage` 的人后端视为有 access;守卫读的是登录态里的显式布尔值,角色包须两键一并授予)。 + +--- + +## 按应用授权 + +这些业务不进能力目录。角色包勾上对应 Agent 就能看;改数据、同步、发通知再要求平台管理员。 + +聊天主链路(会话、补全、附件)统一走 `@require_agent_permission`:请求带 `agent_id`,用户在该 Agent 的授权名单里,或是平台管理员。 + +| 应用 `agent_code` | 持有该 Agent 能做 | 仅平台管理员 | +| --- | --- | --- | +| `contract_payment` | 查合同付款台账 | 同步 OA、强制覆盖、批量重解析、扫描预警、发送周汇总 | +| `voucher_check` | 查检核任务和发送记录 | 强制重检、通知配置 | +| `equipment_acceptance` | 打开设备验收预警作业面 | 从 E10 同步、修改配置 | +| `in_transit_transfer` | 使用在途调拨接口 | 平台管理员同样放行,没有单独的只读/可写能力键 | + +合同付款不再占用功能权限键。无授权返回业务 403,例如 `CONTRACT_PAYMENT.FORBIDDEN`;管理动作返回 `*.ADMIN_REQUIRED`。 + +--- + +## 管理后台 + +`/admin` 整棵树只认平台管理员。前端路由 `requiresAdmin`,后端 `@require_admin`。模块之间不再拆权限,能进后台就能进这些模块: + +- 总览、用户、部门、应用、权限组 +- 知识库、排程、企业微信、关联服务、平台应用 +- 公告、快捷问题、培训配置、采购合同、集成连接器、报表 +- 货代管理:字段资产、订单 Schema、订单文档模板、客户识别规则、识别任务、库存与连接配置、运行与审计、门禁诊断 + +侧栏「管理控制台」只对 `is_platform_admin` 显示。非平台管理员访问 `/admin` 会被送回应用管理。 + +货代管理页本身是管理员页。读取敏感审计、编辑 / 预览 / 发布拆分规则,还会再查上一节的货代能力键。 + +--- + +## 按数据归属,不按角色勾选 + +| 场景 | 谁可以 | +| --- | --- | +| 收料归档文件下载 | 平台管理员,或该排程任务的通知接收人 | +| 货代门禁恢复 | 读:单据属主、平台管理员,或持有该 Run 所属 Agent 的人。写:单据属主或平台管理员。管理端路由另由 `@require_admin` 保护 | diff --git a/docs/platform/role-permission-prototype.md b/docs/platform/role-permission-prototype.md deleted file mode 100644 index 400f9289..00000000 --- a/docs/platform/role-permission-prototype.md +++ /dev/null @@ -1,47 +0,0 @@ -# 角色权限配置原型 - -> **文档路径**:`docs/platform/role-permission-prototype.md` -> **用途**:可配置角色(权限包)一期产品原型说明;交互稿见同目录 HTML。 -> **依赖**:管理控制台「应用权限」、`permission_roles`、`users.role`、`user_agent_permissions`。 -> **逻辑**:新建用户由管理员选角色(默认普通用户);已有用户可按角色点人数筛选勾选,确定前确认影响。一期已按此实现。可点击稿:[role-permission-prototype.html](role-permission-prototype.html) - ---- - -## 怎么打开 - -用浏览器直接打开 `docs/platform/role-permission-prototype.html`(无需启动前后端)。左侧切换: - -| 屏 | 要看什么 | -| --- | --- | -| **角色配置** | 权限包列表。点「编辑」给该角色勾应用;点蓝色**人数**给该角色加人 | -| **编辑角色** | 列出全部可授权应用;保存前确认会立刻改变该角色下所有人的入口 | -| **用户管理** | **新建用户必须选角色**,默认普通用户;编辑用户改角色也会先确认 | -| **权限核对** | 现行矩阵的只读形态,格子禁用 | -| **现行应用权限** | 对照说明:为什么不再按人打勾 | - -建议演示: - -1. **用户管理 → 新建用户**:角色预填「普通用户」,可改成培训 HR / 研发应用等,非默认角色会再确认。 -2. **新增应用后**:先编辑对应角色勾上该应用 → 再点该角色人数,按部门筛选勾选要进这个角色的人 → **确定后弹出确认**(写清从哪些角色改入)。全选只勾草稿,不要不核对就点确认调整。 - ---- - -## 一期约定(已画进原型) - -1. **角色 = 权限包**:可用应用 + 应用内能力;管理员单独带「可进 /admin」。 -2. **用户只选一个角色**。新建时由管理员指定,默认普通用户;部门不会自动授权。 -3. **普通用户**默认只勾 **通用入口**(企业知识库是该聊天里的库切换,不单独占一列)。 -4. **研发应用** = 通用入口 + 研发侧应用(如专利);本地尚未接入的应用之后勾进本组即可。编码仍为 `rd`。 -5. 角色编辑列出**应用管理中全部启用应用**。有功能权限的应用在卡片内用短标签配置,不另开一排长框。新增应用:勾到需要的角色上,再按需把人改进该角色。 -6. **保存角色立即对已绑该角色的用户生效**,弹窗提示人数,须确认。 -7. **管理员内置**:应用入口隐式全开;人数不可点;选人列表排除管理员。改到/改出管理员须额外确认。 -8. **已有用户批量改角色**:点人数,左部门仅筛选。勾选后确定先出确认框(从来源角色、将失去原权限)。全选不是默认操作。 -9. **取消勾选后确认** = 回到默认普通用户。编辑「普通用户」时取消勾选忽略。 - ---- - -## 一期不做 - -- 一人多角色、按人额外加应用、在核对矩阵上打勾。 -- 部门自动映射角色(部门是组织,角色是权限包;入职/调岗由管理员选或改角色)。 -- 员工自助「申请某个应用」(若保留申请,应改为申请换角色)。 diff --git a/docs/tec.md b/docs/tec.md index 4032c315..4d19004d 100644 --- a/docs/tec.md +++ b/docs/tec.md @@ -5,7 +5,7 @@ - 表:`permission_roles`(code/name/feature_permissions/is_default/is_platform_admin)与 `permission_role_agents`。成员仍写在 `users.role`(加宽至 64)。运行时 Chat/工作台继续读 `user_agent_permissions` 与 `require_agent_permission`(`is_platform_admin` 旁路);非管理员的 Agent 行由角色包全量替换。排程种子 owner 与 RPA 心跳告警管理员兜底改为 join `is_platform_admin`(未种子权限组时回退 `users.role=admin`)。登录态下发 `is_platform_admin` / `role_name` / `feature_permissions`;业务门闩认标记与能力键。未种子时默认能力仅平台管理员全开,不再用 `hr` / `maintenance_manager` 角色名暗示权限(培训 FAQ 的 HR/员工身份、会话 guest、聊天 message.role、保留码 `admin` 除外)。 - 种子:`user` 普通用户、`rd` 研发应用、`hr` 培训 HR、`shipping` 货代专员、`admin` 管理员。不再种子设备维保专员。 - 管理 API:`/api/admin/permission-roles*`(列表、目录、CRUD、成员 preview/apply)。种子后禁止 `POST /users/:id/permissions`、`/permissions/batch`、`/agents/:id/permissions` 与权限申请批准加应用。 -- 前端:`/admin/permissions` 角色配置 + 只读矩阵;用户表单只选角色。能力键与 `User.get_feature_permissions` 对齐。详细约定见 [platform/role-permission-prototype.md](platform/role-permission-prototype.md)。 +- 前端:`/admin/permissions` 角色配置 + 只读矩阵;用户表单只选角色。能力键与 `User.get_feature_permissions` 对齐。权限分层与能力清单见 [platform/permission-model.md](platform/permission-model.md);交互约定见 [platform/role-permission-prototype.md](platform/role-permission-prototype.md)。 - AI 工作台侧栏底部「返回聊天」上方,仅 `is_platform_admin` 渲染「管理控制台」入口(`openAdminPanel` → `/admin`);`/admin` 仍由路由守卫 `requiresAdmin` 拦截非平台管理员。 ## 合同付款预警(2026-08) diff --git a/docs/ui/ELEMENT_MIGRATION.md b/docs/ui/ELEMENT_MIGRATION.md new file mode 100644 index 00000000..71a28932 --- /dev/null +++ b/docs/ui/ELEMENT_MIGRATION.md @@ -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` 时,在 ` diff --git a/frontend/src/features/admin/modules/agents/components/AgentFormModal.vue b/frontend/src/features/admin/modules/agents/components/AgentFormModal.vue index edae52d5..ff4cb499 100644 --- a/frontend/src/features/admin/modules/agents/components/AgentFormModal.vue +++ b/frontend/src/features/admin/modules/agents/components/AgentFormModal.vue @@ -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 对话框。表单内部字段仍沿用原有输入控件。 */ + + diff --git a/frontend/src/features/admin/modules/agents/components/AgentPermissionModal.vue b/frontend/src/features/admin/modules/agents/components/AgentPermissionModal.vue index 2b5d3685..de2ce1a2 100644 --- a/frontend/src/features/admin/modules/agents/components/AgentPermissionModal.vue +++ b/frontend/src/features/admin/modules/agents/components/AgentPermissionModal.vue @@ -1,11 +1,12 @@ /** * features/admin/modules/agents/components/AgentPermissionModal.vue - * - * 为指定 Agent 批量勾选可访问用户的权限弹窗。 + * 用途:为指定应用勾选可访问用户。 + * 依赖:element-plus、admin.types、agent.types。 + * 逻辑:AgentsPage 传入用户和已选 id;勾选变化交给父组件 togglePermissionUser。 */ - + + diff --git a/frontend/src/features/admin/modules/agents/components/AgentTestModal.vue b/frontend/src/features/admin/modules/agents/components/AgentTestModal.vue index 7ef7d6f4..3affcf1d 100644 --- a/frontend/src/features/admin/modules/agents/components/AgentTestModal.vue +++ b/frontend/src/features/admin/modules/agents/components/AgentTestModal.vue @@ -1,11 +1,12 @@ /** * features/admin/modules/agents/components/AgentTestModal.vue - * - * Agent 连通性测试弹窗:展示请求 URL、输出信息与分析结果。 + * 用途:应用连通性测试弹窗,展示请求地址、输出和分析结果。 + * 依赖:element-plus、agent.types。 + * 逻辑:AgentsPage 传入当前应用和测试结果;重新测试由父组件发起。 */ - + + diff --git a/frontend/src/features/admin/modules/agents/composables/useAgentsAdmin.ts b/frontend/src/features/admin/modules/agents/composables/useAgentsAdmin.ts index 0eb5e7a2..ac7bf631 100644 --- a/frontend/src/features/admin/modules/agents/composables/useAgentsAdmin.ts +++ b/frontend/src/features/admin/modules/agents/composables/useAgentsAdmin.ts @@ -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([]); const users = ref([]); const rolesConfigured = ref(false); + const rolesChecked = ref(false); const scheduleTasks = ref([]); const trainingExamPdfGuides = ref([]); const isLoading = ref(true); @@ -256,9 +259,6 @@ export function useAgentsAdmin() { const permissionAgent = ref(null); const permissionUserIds = ref([]); - const showDeleteConfirmDialog = ref(false); - const deleteConfirmMessage = ref(''); - let deleteConfirmAction: (() => Promise | 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 => { 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 => { - deleteConfirmMessage.value = message; - deleteConfirmAction = action; - showDeleteConfirmDialog.value = true; - }; - - const closeDeleteConfirm = (): void => { - showDeleteConfirmDialog.value = false; - deleteConfirmAction = null; - }; - - const confirmDelete = async (): Promise => { - if (!deleteConfirmAction) return; + ): Promise => { 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 => { - 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, }; } diff --git a/frontend/src/features/admin/modules/users/UsersPage.vue b/frontend/src/features/admin/modules/users/UsersPage.vue index 18e152cf..4e3c403b 100644 --- a/frontend/src/features/admin/modules/users/UsersPage.vue +++ b/frontend/src/features/admin/modules/users/UsersPage.vue @@ -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 按页拉取。 */ + + diff --git a/frontend/src/features/admin/modules/users/components/BatchEditUserModal.vue b/frontend/src/features/admin/modules/users/components/BatchEditUserModal.vue index 65ad5bb9..1dd94abe 100644 --- a/frontend/src/features/admin/modules/users/components/BatchEditUserModal.vue +++ b/frontend/src/features/admin/modules/users/components/BatchEditUserModal.vue @@ -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 试点。 */ diff --git a/frontend/src/features/admin/modules/users/components/BatchPermissionModal.vue b/frontend/src/features/admin/modules/users/components/BatchPermissionModal.vue index 79901833..06f9f658 100644 --- a/frontend/src/features/admin/modules/users/components/BatchPermissionModal.vue +++ b/frontend/src/features/admin/modules/users/components/BatchPermissionModal.vue @@ -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 试点。 */ diff --git a/frontend/src/features/admin/modules/users/components/UserFormModal.vue b/frontend/src/features/admin/modules/users/components/UserFormModal.vue index 525b7ab8..62117c80 100644 --- a/frontend/src/features/admin/modules/users/components/UserFormModal.vue +++ b/frontend/src/features/admin/modules/users/components/UserFormModal.vue @@ -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 试点。 */ + + diff --git a/frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts b/frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts index ef412f38..bceab23b 100644 --- a/frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts +++ b/frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts @@ -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(createEmptyUserForm()); const originalUserRole = ref('user'); - const showRoleConfirm = ref(false); - const roleConfirmMessage = ref(''); - let pendingUserSave: (() => Promise) | null = null; - let pendingBatchSave: (() => Promise) | null = null; const showBatchEditModal = ref(false); const batchEditForm = ref({ department: '', role: '', status: '' }); @@ -79,9 +77,6 @@ export function useUsersAdmin() { const showBatchPermissionModal = ref(false); const batchPermissionForm = ref({ agent_ids: [], action: 'add' }); - const showDeleteConfirmDialog = ref(false); - const deleteConfirmMessage = ref(''); - let deleteConfirmAction: (() => Promise | void) | null = null; /** 当前页是否已全部选中 */ const allPaginatedUsersSelected = computed( @@ -194,25 +189,41 @@ export function useUsersAdmin() { }, 300); }, { deep: true }); - const openDeleteConfirm = (message: string, action: () => Promise | 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): Promise => { + 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 => { - const action = deleteConfirmAction; - closeDeleteConfirm(); - if (!action) return; + const confirmRoleThen = async (message: string, action: () => Promise): Promise => { + 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 => { - 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 => { 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, }; } diff --git a/frontend/src/features/admin/styles/element-trial.css b/frontend/src/features/admin/styles/element-trial.css new file mode 100644 index 00000000..bf659079 --- /dev/null +++ b/frontend/src/features/admin/styles/element-trial.css @@ -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); +} diff --git a/frontend/src/features/kb/components/DifyHealthDialog.vue b/frontend/src/features/kb/components/DifyHealthDialog.vue index 07db0375..7c66faf5 100644 --- a/frontend/src/features/kb/components/DifyHealthDialog.vue +++ b/frontend/src/features/kb/components/DifyHealthDialog.vue @@ -1,16 +1,20 @@  + + diff --git a/frontend/src/features/kb/components/DifySettingsDialog.vue b/frontend/src/features/kb/components/DifySettingsDialog.vue index d5f5d604..d642a5a6 100644 --- a/frontend/src/features/kb/components/DifySettingsDialog.vue +++ b/frontend/src/features/kb/components/DifySettingsDialog.vue @@ -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) => { + + diff --git a/frontend/src/features/kb/components/KbAdminPanel.vue b/frontend/src/features/kb/components/KbAdminPanel.vue index 4ee393e1..1cefd037 100644 --- a/frontend/src/features/kb/components/KbAdminPanel.vue +++ b/frontend/src/features/kb/components/KbAdminPanel.vue @@ -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([]); const isSubmitting = ref(false); const isDeleting = ref(false); -const isRefreshing = ref(false); +const isRefreshing = ref(true); const editingGroupId = ref(null); const form = ref({ 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(null); const searchKeyword = ref(''); const filterMode = ref('all'); -const sortMode = ref('updatedDesc'); +const sortKey = ref('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): 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 }); + + diff --git a/frontend/src/features/kb/components/KbGroupDrawer.vue b/frontend/src/features/kb/components/KbGroupDrawer.vue index 5c50922d..d665a9ed 100644 --- a/frontend/src/features/kb/components/KbGroupDrawer.vue +++ b/frontend/src/features/kb/components/KbGroupDrawer.vue @@ -1,14 +1,16 @@