From 8e263a1d7657b6b23cf7d1aeaad707d1b9847adf Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Thu, 21 May 2026 15:14:56 +0800 Subject: [PATCH 1/4] fix: update ui --- docs/GIT_HOOKS.md | 221 ++++++++++++ docs/新人环境搭建与配置文档.md | 20 +- frontend/src/components/kb/KbAdminPanel.vue | 354 +++++++++++++++++++ frontend/src/config.ts | 1 + frontend/src/i18n.ts | 22 +- frontend/src/router/index.ts | 5 +- frontend/src/views/AdminView.vue | 28 +- frontend/src/views/ChatView.vue | 6 +- frontend/src/views/KbAdminView.vue | 360 -------------------- 9 files changed, 617 insertions(+), 400 deletions(-) create mode 100644 docs/GIT_HOOKS.md create mode 100644 frontend/src/components/kb/KbAdminPanel.vue delete mode 100644 frontend/src/views/KbAdminView.vue diff --git a/docs/GIT_HOOKS.md b/docs/GIT_HOOKS.md new file mode 100644 index 00000000..b1bbb961 --- /dev/null +++ b/docs/GIT_HOOKS.md @@ -0,0 +1,221 @@ +# Git Hooks 团队启用指南 + +> 更新时间:2026-05-21 +> 适用对象:全体开发同学 +> 相关脚本:`.githooks/`、`scripts/install_git_hooks.sh`、`scripts/ci_frontend_build.sh` + +团队启用 Git Hook 分两步:**仓库里已有 `.githooks/`(`git pull` 即有)**,**每人本机执行一次安装**。 + +--- + +## 1. 策略概览 + +本地两层 Hook + 远程 Jenkins CI,避免「日常只跑 `npm run dev`、上线 Jenkins `npm run build` 才报错」。 + +| 层级 | 时机 | 谁生效 | 检查内容 | +|------|------|--------|----------| +| **pre-commit** | `git commit` | 已安装 Hook 的本机 | models 须带 migration;暂存 `frontend/` 时跑 `vue-tsc` | +| **pre-push** | `git push` | 已安装 Hook 的本机 | 本次推送含 `frontend/` 变更时跑 `npm run build` | +| **Jenkins CI** | push 触发流水线 | 全员(不装 Hook 也跑) | `npm ci && npm run build`(`scripts/ci_frontend_build.sh`) | + +- Hook **不会**随 `git clone` 自动启用,需每人配置 `core.hooksPath=.githooks`。 +- 没装 Hook 时,主要靠 Jenkins **Frontend Build (CI)** 阶段兜底。 +- 日常开发仍用 `npm run dev`;Hook 只在 commit / push 时额外检查。 + +--- + +## 2. 确认仓库里已有钩子文件 + +在项目根目录(与 `frontend`、`backend` 同级): + +**PowerShell:** + +```powershell +cd D:\path\to\hxops +git pull +dir .githooks +``` + +**Git Bash:** + +```bash +cd /path/to/hxops +git pull +ls -la .githooks +``` + +应能看到: + +- `pre-commit` +- `pre-push` +- `_common.sh` + +若目录不存在,先 `git pull` 到包含这些文件的版本。 + +--- + +## 3. 本机启用(每人、每个 clone 做一次) + +### 3.1 方式 A:安装脚本(推荐) + +在 **Git Bash** 或 **WSL** 中: + +```bash +cd /path/to/hxops +chmod +x scripts/install_git_hooks.sh +./scripts/install_git_hooks.sh +``` + +成功输出示例: + +```text +[hook-install] Installed Git hooks successfully. +[hook-install] pre-commit: models 变更需带 migration;frontend 暂存时跑 vue-tsc +[hook-install] pre-push: 推送含 frontend 变更时跑 npm run build +[hook-install] core.hooksPath=.githooks +``` + +### 3.2 方式 B:PowerShell / CMD + +不跑 bash 脚本时,在仓库根执行: + +```powershell +cd D:\path\to\hxops +git config core.hooksPath .githooks +``` + +若 commit/push 时提示无执行权限,在 Git Bash 中补充: + +```bash +chmod +x .githooks/pre-commit .githooks/pre-push +``` + +### 3.3 方式 C:hxops_menu 菜单 + +在 Git Bash 中运行 `hxops_menu.sh`,选择 **`hook`** 或 **`43`**,确认安装。 + +--- + +## 4. 验证是否生效 + +```powershell +git config --get core.hooksPath +``` + +应输出:`.githooks` + +安装前端依赖(Hook 跑检查前必需): + +```powershell +cd frontend +npm install +``` + +可选自测:暂存一个 `frontend/` 下的小改动后 `git commit`(会触发 `vue-tsc`),测完 `git reset` 即可。 + +--- + +## 5. 装好后会自动做什么 + +### 5.1 pre-commit + +| 条件 | 行为 | +|------|------| +| 暂存了 `backend/app/models.py`,但未暂存 `backend/migrations/versions/*.py` | **拒绝 commit** | +| 暂存路径含 `frontend/` | 运行 `npx vue-tsc -b`(需已有 `node_modules`) | +| 未暂存 `frontend/` | 不跑前端检查 | + +`SKIP_FRONTEND_HOOKS` **不能**跳过 models/migration 检查。 + +### 5.2 pre-push + +| 条件 | 行为 | +|------|------| +| 本次 push 的提交 diff 含 `frontend/` | 运行 `npm run build`(`vue-tsc -b && vite build`) | +| 无 `frontend/` 变更 | 直接通过 | + +### 5.3 Jenkins CI + +- 在 **Detect Changes** 之后、**Deploy** 之前执行。 +- 仅当 `FRONTEND_CHANGED=true` 时在 `node:22-alpine` 容器内执行 `scripts/ci_frontend_build.sh`。 + +--- + +## 6. 团队落地清单(可转发) + +1. **新同事**:`git clone` → `cd frontend && npm install` → 按本文 **§3** 安装 Hook → **§4** 验证。 +2. **老同事**:`git pull` 后若从未装过,补做一次安装。 +3. **换电脑 / 新 clone**:每个新目录都要再装一次(`core.hooksPath` 写在本地 `.git/config`,不随 push 同步)。 +4. **Windows**:建议用 Git for Windows 自带的 Git Bash 执行 commit/push;PowerShell 可用 **§3.2** 仅完成 Hook 路径配置。 + +--- + +## 7. 应急跳过(不要常态化) + +### 7.1 只跳过前端检查 + +migration 规则在 pre-commit 中仍会执行。 + +**Git Bash:** + +```bash +SKIP_FRONTEND_HOOKS=1 git commit -m "your message" +SKIP_FRONTEND_HOOKS=1 git push +``` + +**PowerShell(当前终端会话):** + +```powershell +$env:SKIP_FRONTEND_HOOKS = "1" +git commit -m "your message" +git push +``` + +### 7.2 跳过全部 Hook + +```bash +git commit --no-verify +git push --no-verify +``` + +同时跳过 migration、vue-tsc、build 等所有 Hook。 + +### 7.3 环境变量说明 + +| 变量 | 默认值 | 生效条件 | +|------|--------|----------| +| `SKIP_FRONTEND_HOOKS` | 未设置 | 设为 `1` 时跳过前端 vue-tsc / build | +| `SKIP_GIT_HOOKS` | 未设置 | 设为 `1` 时跳过前端检查(与上一项在前端逻辑等价) | + +仓库内**没有**预置这些变量的配置文件,仅在单次命令前临时设置。 + +--- + +## 8. 常见问题 + +| 现象 | 处理 | +|------|------| +| `dir .githooks` 找不到 | `git pull`;确认在仓库根目录 | +| `missing hook file` | 同上,确保 `.githooks` 已拉取 | +| `frontend/node_modules 不存在` | `cd frontend && npm install` | +| PowerShell 无法执行 `.sh` | 用 **§3.2** 的 `git config`,或改用 Git Bash | +| 装了 Hook 仍不拦截 | 确认 `git config --get core.hooksPath`;是否用了 `--no-verify` | +| 想取消 Hook | `git config --unset core.hooksPath` | + +--- + +## 9. 相关文件 + +| 路径 | 说明 | +|------|------| +| `.githooks/pre-commit` | 提交时检查 | +| `.githooks/pre-push` | 推送时检查 | +| `.githooks/_common.sh` | 共用逻辑 | +| `scripts/install_git_hooks.sh` | 一键安装 | +| `scripts/ci_frontend_build.sh` | Jenkins / 本地 CI 同款 build | +| `Jenkinsfile` | `Frontend Build (CI)` 阶段 | +| `docs/新人环境搭建与配置文档.md` | 新人环境 §4.2 简要说明 | + +--- + +维护建议:调整 Hook 规则或 Jenkins 构建步骤后,请同步更新本文档。 diff --git a/docs/新人环境搭建与配置文档.md b/docs/新人环境搭建与配置文档.md index 504666ba..ba0cc1be 100644 --- a/docs/新人环境搭建与配置文档.md +++ b/docs/新人环境搭建与配置文档.md @@ -65,31 +65,21 @@ cd hxops ### 4.2 安装 Git Hooks(推荐,每人 clone 后执行一次) -仓库根目录的 `.githooks/` 会随代码拉取;**不会自动生效**,需在本机启用: +完整说明见 **[Git Hooks 团队启用指南](./GIT_HOOKS.md)**(策略、安装步骤、验证、跳过方式、常见问题)。 -| Hook | 时机 | 检查内容 | -|------|------|----------| -| `pre-commit` | `git commit` | 改 `models.py` 须同时提交 migration;暂存 `frontend/` 时跑 `vue-tsc` | -| `pre-push` | `git push` | 本次推送含 `frontend/` 变更时跑 `npm run build`(与 Jenkins 部署一致) | - -**Git Bash / WSL:** +快速安装: ```bash -chmod +x scripts/install_git_hooks.sh .githooks/pre-commit .githooks/pre-push +# Git Bash / WSL ./scripts/install_git_hooks.sh ``` -**PowerShell(仅启用钩子目录):** - ```powershell +# PowerShell git config core.hooksPath .githooks ``` -验证:`git config --get core.hooksPath` 应输出 `.githooks`。 - -前置:已执行 `cd frontend && npm install`。应急跳过前端检查:`$env:SKIP_FRONTEND_HOOKS="1"`(bash 为 `SKIP_FRONTEND_HOOKS=1`)。 - -Jenkins 在检测到 `frontend/` 变更时会再跑一遍同款构建(`scripts/ci_frontend_build.sh`),作为 Hook 被跳过时的兜底。 +验证:`git config --get core.hooksPath` → `.githooks`;前置:`cd frontend && npm install`。 ### 4.3 常用 Git 操作示例 diff --git a/frontend/src/components/kb/KbAdminPanel.vue b/frontend/src/components/kb/KbAdminPanel.vue new file mode 100644 index 00000000..677d059a --- /dev/null +++ b/frontend/src/components/kb/KbAdminPanel.vue @@ -0,0 +1,354 @@ + + +