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/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 @@