diff --git a/docs/DESIGN_SYSTEM.md b/docs/DESIGN_SYSTEM.md new file mode 100644 index 00000000..2e8e655e --- /dev/null +++ b/docs/DESIGN_SYSTEM.md @@ -0,0 +1,393 @@ +# HXOps 前端三层设计系统方案 + +> 目标:在**明亮 / 暗黑**主题下,页面背景、文字、边框、按钮、卡片、布局间距保持一致;新页面默认符合规范,旧页面按阶段迁移。 + +--- + +## 1. 总体架构 + +``` +┌─────────────────────────────────────────────────────────────┐ +│ L3 布局壳 Layout(PageShell / AppShell / ChatShell) │ +│ 决定:全页结构、顶栏高度、侧栏宽度、主区内边距 │ +├─────────────────────────────────────────────────────────────┤ +│ L2 组件类 Components(.btn / .card / .input-field / …) │ +│ 决定:按钮、表单、卡片、徽章、弹层等可复用 UI 块 │ +├─────────────────────────────────────────────────────────────┤ +│ L1 设计令牌 Tokens(CSS 变量,:root + html.dark) │ +│ 决定:颜色、阴影、圆角基数;亮暗只改变量,不写 dark: │ +└─────────────────────────────────────────────────────────────┘ +``` + +**核心原则** + +| 原则 | 说明 | +|------|------| +| 单一色源 | 页面背景/文字/边框只来自 L1 变量(通过语义 class 引用) | +| 亮暗自动 | 组件与布局**不写** `dark:bg-*`,切换 `html.dark` 即可 | +| 向下约束 | L3 只能用 L2;L2 只能用 L1;禁止页面内 `text-[#hex]` | +| 例外登记 | 登录 Hero 渐变、Agent 图标等允许 `data-surface="marketing"` | + +**与现有代码的关系** + +- 保留:`useTheme`、`ThemeToggleButton`、`tailwind darkMode: 'class'`、`brand` 色阶 +- 演进:逐步减少 `style.css` 中 `html.dark .bg-white !important` 补丁(迁移完成后删除) +- 统一字体:`tailwind.config.js` 的 `sans` 与 `style.css` 的 `html` 字体一致(见 §1.1) + +### 1.1 字体(一次性对齐) + +```js +// tailwind.config.js — 与 style.css 一致 +fontFamily: { + sans: ['"PingFang SC"', '"Microsoft YaHei"', '"Segoe UI"', 'system-ui', 'sans-serif'], +}, +``` + +--- + +## 2. L1 设计令牌(Tokens) + +### 2.1 文件职责 + +| 文件 | 职责 | +|------|------| +| `frontend/src/styles/tokens.css` | 仅定义 `:root` / `html.dark` 变量(从 `style.css` 拆出) | +| `frontend/src/styles/utilities.css` | 语义 utility(`bg-page`、`text-primary` …) | +| `frontend/src/style.css` | `@import` 上述文件 + Tailwind + L2 组件类 | + +### 2.2 语义令牌表(亮 / 暗) + +| 令牌 | 明亮 | 暗黑 | 用途 | +|------|------|------|------| +| `--bg-page` | `#f8fafc` | `#020617` | 全页背景 | +| `--bg-surface` | `#ffffff` | `#0b1220` | 卡片、顶栏、主面板 | +| `--bg-surface-soft` | `#f8fafc` | `#0f172a` | 次级区域、表头、侧栏项 hover 底 | +| `--bg-surface-strong` | `#f1f5f9` | `#1e293b` | 输入框、禁用底、ghost hover | +| `--text-primary` | `#0f172a` | `#f8fafc` | 标题、强调正文 | +| `--text-secondary` | `#334155` | `#cbd5e1` | 正文 | +| `--text-muted` | `#64748b` | `#94a3b8` | 说明、占位、次要标签 | +| `--border-default` | `#e2e8f0` | `#334155` | 卡片、分割线、输入框边框 | +| `--border-subtle` | `#f1f5f9` | `#1e293b` | 弱分割 | +| `--overlay-soft` | `rgba(15,23,42,.4)` | `rgba(2,6,23,.72)` | 遮罩 | +| `--shadow-elevated` | 见现 `style.css` | 见现 `style.css` | 浮层、下拉 | +| `--glow-accent` | 见现 `style.css` | 见现 `style.css` | 玻璃面板、强调卡片 | +| `--focus-ring` | `rgba(14,165,233,.35)` | `rgba(56,189,248,.4)` | focus 环 | + +**状态色(新增,供 Message / Badge / 表单校验)** + +| 令牌 | 明亮背景 | 暗黑背景 | 前景 | +|------|----------|----------|------| +| `--status-success-bg` | `#eef8e8` | `rgba(34,197,94,.12)` | `--status-success-fg` | +| `--status-info-bg` | `#eaf4ff` | `rgba(56,189,248,.12)` | `--status-info-fg` | +| `--status-warning-bg` | `#fff8e8` | `rgba(250,204,21,.12)` | `--status-warning-fg` | +| `--status-error-bg` | `#fff1f0` | `rgba(239,68,68,.12)` | `--status-error-fg` | + +品牌色继续使用 Tailwind `brand-50` … `brand-950`(不纳入 CSS 变量,避免重复维护)。 + +### 2.3 语义 Utility(L1 对外 API) + +模板中**只允许**以下类表示「结构色」,禁止 `bg-white dark:bg-slate-900` 等成对写法: + +```css +/* utilities.css — 示例 */ +.bg-page { background-color: var(--bg-page); } +.bg-surface { background-color: var(--bg-surface); } +.bg-surface-soft { background-color: var(--bg-surface-soft); } +.bg-surface-strong{ background-color: var(--bg-surface-strong); } + +.text-primary { color: var(--text-primary); } +.text-secondary { color: var(--text-secondary); } +.text-muted { color: var(--text-muted); } + +.border-default { border-color: var(--border-default); } +.border-subtle { border-color: var(--border-subtle); } + +.shadow-elevated { box-shadow: var(--shadow-elevated); } +``` + +**允许保留的 Tailwind 用法** + +- 布局:`flex`、`grid`、`gap-*`、`p-*`、`max-w-*` +- 品牌:`bg-brand-600`、`text-brand-600`、`ring-brand-500` +- 状态:`.alert-success` 等 L2 类(内部用 `--status-*`) + +### 2.4 Tailwind 扩展(可选,与变量对齐) + +```js +// tailwind.config.js +colors: { + surface: { + page: 'var(--bg-page)', + DEFAULT: 'var(--bg-surface)', + soft: 'var(--bg-surface-soft)', + strong: 'var(--bg-surface-strong)', + }, + content: { + primary: 'var(--text-primary)', + secondary: 'var(--text-secondary)', + muted: 'var(--text-muted)', + }, + line: { + DEFAULT: 'var(--border-default)', + subtle: 'var(--border-subtle)', + }, +}, +``` + +团队二选一:**语义 class**(`bg-page`)或 **Tailwind 别名**(`bg-surface-page`),项目内只选一种,本文档默认 **语义 class**。 + +--- + +## 3. L2 组件类(Components) + +在 `style.css` 的 `@layer components` 中维护;所有组件类**只引用 L1 变量 + brand 色**,不写 `dark:`。 + +### 3.1 按钮 + +| 类名 | 用途 | +|------|------| +| `.btn` | 基类:圆角 `rounded-xl`、过渡、对齐 | +| `.btn-primary` | 主操作:`brand-600` 背景(亮暗共用色阶) | +| `.btn-secondary` | 次要:`bg-surface` + `border-default` | +| `.btn-ghost` | 图标/工具栏 | +| `.btn-danger` | 删除、退出等 | +| `.btn-icon` | 正方形图标按钮(顶栏、侧栏折叠) | + +### 3.2 表单 + +| 类名 | 用途 | +|------|------| +| `.input-field` | 文本输入、textarea(已有,改为变量驱动背景/边框) | +| `.select-field` | `` + +Workspace 未登录、Admin、KB 共用,避免三处各写一套样式。 + +--- + +## 5. 页面迁移对照 + +| 页面 | L3 布局 | L1/L2 改造要点 | +|------|---------|----------------| +| `WorkspaceView` 未登录 | `MarketingShell` | 登录卡用 `.card`;Hero 渐变保留为 `data-surface="marketing"` | +| `WorkspaceView` 已登录 | `AppShell` | `text-[#1b2b49]` → `text-primary`;Agent 卡用 `.card-interactive` | +| `ChatView` | `ChatShell` | 侧栏/主区改语义色;按钮对齐 `.btn-*` | +| `AdminView` | `AppShell` + sidebar slot | `gray-*` → 语义色;表头 `bg-surface-soft` | +| `KbWorkspaceView` | `AppShell` | 与 Admin 卡片圆角/边框一致 | +| `ResetPasswordView` | `MinimalShell` | 已用 `btn-primary`,补 `bg-page` | +| `LevelMessageDialog` | — | `STYLE_MAP` → `.alert-*` | + +--- + +## 6. 实施阶段(建议 4 周,可并行 Review) + +### Phase 0 — 基础设施(1–2 天) + +- [ ] 新增 `tokens.css`、`utilities.css`,从 `style.css` 迁出变量 +- [ ] 补全 `--status-*` 与语义 utility +- [ ] 统一 `tailwind.config.js` 字体 +- [ ] 新增 `.alert-*`、`.app-header` 等 L2 类 +- [ ] 本文档作为 PR Review 检查清单 + +### Phase 1 — 布局壳(2–3 天) + +- [ ] 实现 `AppShell`、`MarketingShell`、`MinimalShell`、`AppHeaderTools` +- [ ] `ResetPasswordView`、`KbWorkspaceView` 接入(改动面小) +- [ ] `LevelMessageDialog` 改用 `.alert-*` + +### Phase 2 — 工作台与管理端(3–5 天) + +- [ ] `WorkspaceView` 已登录区接入 `AppShell` + 语义色 +- [ ] `AdminView` 根布局 + 消灭 `gray-*` / 无暗色 hex +- [ ] 删除已覆盖的 `html.dark` 补丁(分批,每 PR 跑亮/暗目视) + +### Phase 3 — Chat(3–5 天) + +- [ ] `ChatShell` 抽离 +- [ ] composer / 历史列表 L2 类 +- [ ] 减少 ChatView 内 `dark:` 数量目标:**0**(仅保留 markdown/prose 等特殊区) + +### Phase 4 — 收尾与门禁 + +- [ ] ESLint / Stylelint 可选:`no-restricted-syntax` 禁止 `dark:bg-`、`text-[#`(warning 先行) +- [ ] 删除冗余 `html.dark !important` 块 +- [ ] 截图回归:亮/暗 × 桌面/移动 × 5 条主路径 + +--- + +## 7. 开发规范(Review Checklist) + +**必须** + +- [ ] 页面根节点有 `page-shell` 或处于 L3 布局内 +- [ ] 背景/文字/边框使用 L1 语义类,无 `dark:` 颜色对 +- [ ] 按钮/输入/卡片使用 L2 类名 +- [ ] 新弹窗、Message 使用 `.alert-*` 或 `LevelMessageDialog` + +**禁止** + +- [ ] `bg-white`、`bg-gray-50`、`text-slate-800` 等作为**页面结构色**(品牌色除外) +- [ ] `text-[#xxxx]`、`bg-[#xxxx]`(`data-surface="marketing"` 除外) +- [ ] 同一元素 `bg-x dark:bg-y` + +**例外(需注释 `// design-system:exception`)** + +- 登录页品牌渐变、背景图 +- 第三方 iframe、Markdown prose(可用 `@tailwindcss/typography` + 变量覆盖) + +--- + +## 8. 目录结构(目标态) + +``` +frontend/src/ +├── styles/ +│ ├── tokens.css # L1 变量 +│ └── utilities.css # L1 语义 class +├── style.css # Tailwind + L2 components + dark 补丁(逐步缩减) +├── layouts/ +│ ├── AppShell.vue +│ ├── ChatShell.vue +│ ├── MarketingShell.vue +│ ├── MinimalShell.vue +│ └── AppHeaderTools.vue +├── components/ # 业务组件,遵守 L2 +└── views/ # 只写内容与 slot,不写全页骨架色 +``` + +--- + +## 9. 验收标准(Done Definition) + +1. **亮暗切换**:在 Workspace / Chat / Admin / KB 四条路径切换主题,无「白块」「黑字 on 黑底」、无未适配 hex。 +2. **色源唯一**:`rg "dark:(bg|text|border)-" frontend/src/views` 行数较基线下降 ≥ 80%。 +3. **结构一致**:Admin 与 KB 顶栏高度、主区内边距、卡片圆角一致。 +4. **组件复用**:新建表单页只引用 `.input-field` + `.btn-primary`,不复制 Tailwind 串。 + +--- + +## 10. 与当前仓库的对照(基线) + +| 项目 | 现状 | 目标 | +|------|------|------| +| 主题切换 | `useTheme` + `html.dark` | 保持 | +| 色板定义 | `style.css` 变量已有 | 拆文件 + 状态色 + 语义 utility | +| 页面用法 | 大量 `dark:` + slate/gray 混用 | 仅 L1 语义类 | +| 布局 | 每 View 自建 | L3 四种 Shell | +| 补丁 | ~79 条 `html.dark !important` | 迁移后删除 | + +--- + +*文档版本:2026-05-27 · 维护:前端 PR 附带亮/暗截图即视为遵循本规范。* diff --git a/docs/GIT_HOOKS.md b/docs/GIT_HOOKS.md index b1bbb961..cca78853 100644 --- a/docs/GIT_HOOKS.md +++ b/docs/GIT_HOOKS.md @@ -90,10 +90,6 @@ git config core.hooksPath .githooks chmod +x .githooks/pre-commit .githooks/pre-push ``` -### 3.3 方式 C:hxops_menu 菜单 - -在 Git Bash 中运行 `hxops_menu.sh`,选择 **`hook`** 或 **`43`**,确认安装。 - --- ## 4. 验证是否生效 diff --git a/docs/k_Enterprise_AI_Gateway_Architecture_20260222.md b/docs/k_Enterprise_AI_Gateway_Architecture_20260222.md index 593e049d..30a646c6 100644 --- a/docs/k_Enterprise_AI_Gateway_Architecture_20260222.md +++ b/docs/k_Enterprise_AI_Gateway_Architecture_20260222.md @@ -14,29 +14,31 @@ #### 5.2.1 Docker Compose 编排 (`docker-compose.yml`) 我们定义了两个核心服务: 1. **hxops-backend**: - - 基于 `python:3.12-slim` 构建。 - - 运行 Gunicorn + Gevent,监听 5000 端口。 - - 通过 `extra_hosts` 访问宿主机数据库 (`192.168.100.230:5432`)。 + - 基于 `python:3.12-slim` 构建(仓库根 `context` + `backend/Dockerfile`)。 + - 运行 Gunicorn + Gevent;宿主机映射端口见 `docker-compose.yml`(当前为 `5052`)。 + - 通过 `env_file` 加载 `.env.shared` 与 `.env.`(见 `docs/env_loading_priority.md`)。 + - 通过 `extra_hosts` 访问宿主机上的外部数据库等服务。 2. **hxops-frontend**: - - 基于 `nginx:alpine` 构建。 - - 托管 Vue 打包后的 `dist` 目录。 - - 监听 80 端口,映射到宿主机 8888。 - - 配置了反向代理,将 `/api/` 转发至 `hxops-backend:5000`。 + - 多阶段构建:Node 打 `dist`,Nginx 托管静态资源。 + - 容器内 80 端口,宿主机映射为 `8890`(或由前置 `nginx-gateway` 反代)。 + - 将 `/api/` 转发至 `hxops-backend`。 +3. **hxops-kb-worker**(按需): 知识库清洗/同步 worker,与 backend 共用镜像与 env 配置。 ```yaml -# docker-compose.yml 关键片段 +# docker-compose.yml 关键片段(示意) services: hxops-backend: - build: ./backend - environment: - - DATABASE_URL=postgresql://postgres:***@192.168.100.230:5432/hxops_prod + env_file: + - .env.shared + - .env.prod # dev/test/prod 由 COMPOSE_ENV_BASENAME 切换 + ports: + - "5052:5052" extra_hosts: - "host.docker.internal:host-gateway" hxops-frontend: - build: ./frontend ports: - - "8888:80" + - "8890:80" depends_on: - hxops-backend ``` @@ -53,11 +55,14 @@ location /api/ { } ``` -#### 5.2.3 自动化部署脚本 (`scripts/deploy.sh`) -脚本已重写以适配 Docker 流程: -1. **拉取代码**: `git pull origin super`。 -2. **构建与启动**: `docker compose up -d --build --remove-orphans`。 -3. **数据库迁移**: 等待容器启动后,通过 `docker compose exec` 在后端容器内执行 `flask db upgrade`。 +#### 5.2.3 自动化部署脚本 (`scripts/deploy_compose.sh`) +当前标准部署入口(Jenkins 与服务器手工均使用此脚本): +1. **环境选择**: 参数 `dev` / `test` / `prod`,对应 `.env.dev`、`.env.test`、`.env.prod` 与 `.env.shared`。 +2. **增量构建**: 按变更仅重建 `hxops-frontend` / `hxops-backend`(或由 Jenkins 传入镜像标签走预构建模式)。 +3. **数据库迁移**: 在后端容器内执行 `flask --app manage.py db upgrade`。 +4. **健康检查**: 调用 `scripts/healthcheck.sh`。 + +已废弃、不再维护:`scripts/deploy.sh`、根目录 `deploy.sh`、`deploy_docker_rsync.sh` 及 rsync 手工同步脚本。 ### 5.3 部署操作日志 (Operations Log) @@ -81,36 +86,36 @@ location /api/ { # 编排前后端服务及网络 # 文件路径: docker-compose.yml -# 5. 更新部署脚本 -# 适配 Docker 命令 -# 文件路径: scripts/deploy.sh +# 5. 部署脚本(现行) +# 文件路径: scripts/deploy_compose.sh、scripts/healthcheck.sh ``` -#### 5.3.2 代码提交 -将所有配置文件提交至 `super` 分支,作为服务器部署的单一真实源。 +#### 5.3.2 代码提交与 CI +日常通过 Gitee 推送触发 Jenkins;流水线在目标机 `git fetch/checkout` 后执行 `deploy_compose.sh`。 ```bash -git add scripts/deploy.sh docker-compose.yml frontend/nginx.conf backend/Dockerfile frontend/Dockerfile -git commit -m "feat: Implement containerized deployment with frontend/backend separation" -git push origin super +git add scripts/deploy_compose.sh scripts/healthcheck.sh docker-compose.yml \ + frontend/nginx.conf backend/Dockerfile frontend/Dockerfile .env.shared .env.prod +git commit -m "chore: align deployment with compose env profiles" +git push origin ``` ### 5.4 服务器端执行指引 -请管理员登录服务器 (`192.168.100.230`) 执行以下命令完成首次部署: + +**推荐**:由 Jenkins 按分支部署到 dev/test/prod 主机(见仓库根 `Jenkinsfile`)。 + +**手工应急**(SSH 登录目标机,代码已与远端分支一致时): ```bash -# 1. 进入项目目录 -cd /data/ai-platform/hxops +cd /data/ai-platform/hxops # 以实际 DEPLOY_ROOT 为准 -# 2. 赋予脚本执行权限 -chmod +x scripts/deploy.sh +chmod +x scripts/deploy_compose.sh scripts/healthcheck.sh -# 3. 执行部署 -./scripts/deploy.sh +# 示例:生产环境全量重建前后端 +./scripts/deploy_compose.sh prod true true true ``` -预期输出: -- Docker 镜像开始构建(前端及后端)。 -- 容器 `hxops-backend` 和 `hxops-frontend` 启动。 -- 数据库迁移自动执行成功。 -- 访问 `http://192.168.100.230:8888` 即可看到全新的 AI 门户。 +预期结果: +- 按变更构建并启动 `hxops-backend`、`hxops-frontend`(及 worker 若已启用)。 +- `flask db upgrade` 与健康检查通过。 +- 经网关或直连访问前端(例如宿主机 `8890`,或现网 `nginx-gateway` 的 `8881`)。 diff --git a/docs/project_context.md b/docs/project_context.md index 566485f5..4c41fbbf 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -54,7 +54,7 @@ hxops/ │ │ └── i18n.ts # 国际化配置 │ └── vite.config.ts # Vite 配置 ├── scripts/ # 运维与自动化脚本 -│ ├── deploy.sh # 服务器部署脚本 (核心) +│ ├── deploy_compose.sh # Docker Compose 部署(Jenkins / 服务器) │ ├── nginx.conf # Nginx 生产配置 │ └── supervisord.conf # Supervisor 配置 └── docs/ # 项目文档 @@ -83,20 +83,11 @@ hxops/ - 存储用户、应用配置及审计日志。 ### 4.2 CI/CD 工作流 -采用 **本地开发 -> Gitee 托管 -> 服务器拉取** 的流程: +采用 **本地开发 -> Gitee -> Jenkins -> 服务器 `deploy_compose.sh`**: -1. **本地开发 (Local)**: - - 代码修改 -> `git push origin super`。 - - 仓库: `https://gitee.com/justop/hxops.git` - -2. **服务器部署 (Server)**: - - 服务器 IP: `192.168.100.230` - - 执行脚本: `scripts/deploy.sh` - - 自动化步骤: - - 拉取最新代码 (`git pull`). - - 前端构建 (`npm install && npm run build`). - - 后端更新 (`pip install && flask db upgrade`). - - 服务重启 (`supervisorctl restart`). +1. **本地开发**: 改代码后 `git push` 到对应分支(`dev` / `test` / `prod` 等)。 +2. **Jenkins**: 在目标机 `git fetch/checkout` 后执行 `scripts/deploy_compose.sh `,按变更增量重建 `hxops-frontend` / `hxops-backend`,并跑 `flask db upgrade` 与健康检查。 +3. **环境配置**: 仓库根目录 `.env.shared` + `.env.dev|test|prod`(见 `docs/env_loading_priority.md`)。 ## 5. 🗄️ 核心数据模型 (Database Models) @@ -128,12 +119,12 @@ npm run dev ### 服务器运维 ```bash -# 一键部署 -./scripts/deploy.sh +# 与 Jenkins 相同的 Compose 部署(示例:生产) +./scripts/deploy_compose.sh prod true true true + +# 查看容器状态 +docker compose ps # 查看后端日志 -tail -f /opt/hxops/backend/logs/app.log - -# 重启服务 -sudo supervisorctl restart hxops-backend +docker compose logs -f hxops-backend ``` diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 04447b2f..f1939bc7 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -5,7 +5,12 @@ import { watch, onMounted, onBeforeUnmount } from 'vue'; import { useTheme } from './composables/useTheme'; import LevelMessageDialog from './components/LevelMessageDialog.vue'; import { useGlobalMessageDialog } from './composables/useGlobalMessageDialog'; -import { getAuthHeaders, clearAuthUser } from './utils/auth'; +import { useRouter } from 'vue-router'; +import { getAuthHeaders, logoutAuth } from './utils/auth'; + +const router = useRouter(); + +const PUBLIC_PATHS = ['/', '/workspace', '/casdoor-callback', '/reset-password']; const { locale } = useI18n(); const { themePreference, initTheme, setThemePreference } = useTheme(); @@ -58,14 +63,23 @@ watch(themePreference, (newTheme) => { const onUnauthorized = () => { showMessageDialog('error', '认证已过期或无效,请重新登录'); - clearAuthUser(); - if (window.location.pathname !== '/') { - window.location.href = '/'; + logoutAuth(); +}; + +const onLogout = (event: Event) => { + const detail = (event as CustomEvent<{ remote?: boolean }>).detail; + if (detail?.remote) { + showMessageDialog('info', '您已在其他标签页退出登录'); + } + const path = router.currentRoute.value.path; + if (!PUBLIC_PATHS.includes(path)) { + router.push('/workspace'); } }; onMounted(async () => { window.addEventListener('hxops:unauthorized', onUnauthorized as EventListener); + window.addEventListener('hxops:logout', onLogout as EventListener); initTheme(); @@ -90,6 +104,7 @@ onMounted(async () => { onBeforeUnmount(() => { window.removeEventListener('hxops:unauthorized', onUnauthorized as EventListener); + window.removeEventListener('hxops:logout', onLogout as EventListener); }); diff --git a/frontend/src/components/DeleteConfirmDialog.vue b/frontend/src/components/DeleteConfirmDialog.vue index dfb8c18b..12201629 100644 --- a/frontend/src/components/DeleteConfirmDialog.vue +++ b/frontend/src/components/DeleteConfirmDialog.vue @@ -3,9 +3,7 @@ import { computed, onBeforeUnmount, watch } from 'vue'; import { useI18n } from 'vue-i18n'; interface Props { - // 由父组件控制显隐,使用 v-model 统一管理弹框状态。 modelValue: boolean; - // title/message 支持外部按场景透传,不传时走 i18n 默认值。 title?: string; message?: string; confirmText?: string; @@ -39,7 +37,6 @@ const closeDialog = () => { }; const handleCancel = () => { - // 先抛出 cancel 事件,方便父组件做状态回滚,再关闭弹框。 emit('cancel'); closeDialog(); }; @@ -57,7 +54,6 @@ const handleEscKey = (event: KeyboardEvent) => { watch( () => props.modelValue, (visible) => { - // 关键点:弹框打开时监听 ESC,关闭后及时解绑,避免全局事件泄漏。 if (visible) { document.addEventListener('keydown', handleEscKey); return; @@ -77,29 +73,29 @@ onBeforeUnmount(() => {
-
+
- +
-

+

{{ resolvedTitle }}

-

+

{{ resolvedMessage }}

-