From 71e09d0857deef7b00f54ba759b7fe0cb8d54560 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Thu, 28 May 2026 08:25:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=81=87=E6=9C=9F=E5=A4=A9=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=B0=8F=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/hr_leave_sqlserver.py | 6 +++--- frontend/src/i18n.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/services/hr_leave_sqlserver.py b/backend/app/services/hr_leave_sqlserver.py index 0d2efed2..66a6462a 100644 --- a/backend/app/services/hr_leave_sqlserver.py +++ b/backend/app/services/hr_leave_sqlserver.py @@ -195,11 +195,11 @@ WHERE c002001 = ? return str(value) @classmethod - def _format_quota(cls, value) -> str: + def _format_quota(cls, value, unit: str = "天") -> str: formatted = cls._format_number(value) if formatted == "暂无数据": return formatted - return f"{formatted}天" + return f"{formatted}{unit}" @staticmethod def _resolve_response_year(record: dict | None, requested_year: int | None) -> str: @@ -216,7 +216,7 @@ WHERE c002001 = ? return f"| {index} | {title} | {response_year} | 暂无数据 | 暂无数据 | 暂无数据 |" total = cls._format_quota(record.get('total_hours')) used = cls._format_quota(record.get('used_hours')) - remaining = cls._format_quota(record.get('remaining_hours')) + remaining = cls._format_quota(record.get('remaining_hours'), "小时") return f"| {index} | {title} | {response_year} | {total} | {used} | {remaining} |" @classmethod diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index 2617f146..c341a190 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -1,4 +1,4 @@ -import { createI18n } from 'vue-i18n'; +import { createI18n } from 'vue-i18n'; const messages = { 'en': { From 24f99070a362c009d573f76c52b9099f1f0ff95c Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Thu, 28 May 2026 09:09:52 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=82=B2=E5=84=BF=E5=81=87=E5=A4=A9?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=B0=8F=E6=97=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/hr_leave_sqlserver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/services/hr_leave_sqlserver.py b/backend/app/services/hr_leave_sqlserver.py index 66a6462a..464c863b 100644 --- a/backend/app/services/hr_leave_sqlserver.py +++ b/backend/app/services/hr_leave_sqlserver.py @@ -210,12 +210,12 @@ WHERE c002001 = ? return str(datetime.now().year) @classmethod - def _render_table_row(cls, index: int, title: str, record: dict | None, requested_year: int | None) -> str: + def _render_table_row(cls, index: int, title: str, record: dict | None, requested_year: int | None, quota_unit: str = "天") -> str: response_year = cls._resolve_response_year(record, requested_year) if not record: return f"| {index} | {title} | {response_year} | 暂无数据 | 暂无数据 | 暂无数据 |" - total = cls._format_quota(record.get('total_hours')) - used = cls._format_quota(record.get('used_hours')) + total = cls._format_quota(record.get('total_hours'), quota_unit) + used = cls._format_quota(record.get('used_hours'), quota_unit) remaining = cls._format_quota(record.get('remaining_hours'), "小时") return f"| {index} | {title} | {response_year} | {total} | {used} | {remaining} |" @@ -249,7 +249,7 @@ WHERE c002001 = ? sections.append(cls._render_table_row(index, "年假", annual_record, requested_year)) index += 1 if leave_type in ("childcare", "all"): - sections.append(cls._render_table_row(index, "育儿假", childcare_record, requested_year)) + sections.append(cls._render_table_row(index, "育儿假", childcare_record, requested_year, "小时")) index += 1 sections.extend( From 2721b9d00b50c6d8248b8a91555eae1dd6e2c043 Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Thu, 28 May 2026 10:18:56 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0minio=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/requirements.txt | 1 + backend/worker_kb.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 3c85df56..2cae437b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -35,3 +35,4 @@ lxml==6.0.2 typer==0.17.4 croniter pyyaml +minio>=7.2.0 diff --git a/backend/worker_kb.py b/backend/worker_kb.py index a33d28ff..9e3cbd79 100644 --- a/backend/worker_kb.py +++ b/backend/worker_kb.py @@ -4,12 +4,29 @@ backend/worker_kb.py """ from __future__ import annotations +import logging import os +import sys import time from app import create_app from app.services.knowledge_cleaning.queue_service import process_next_clean_job +_LOG_FORMAT = '%(asctime)s %(levelname)s [kb-worker] %(message)s' +_LOG_DATEFMT = '%Y-%m-%d %H:%M:%S' + + +def _configure_logging() -> logging.Logger: + logger = logging.getLogger('kb-worker') + if logger.handlers: + return logger + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(logging.Formatter(_LOG_FORMAT, datefmt=_LOG_DATEFMT)) + logger.addHandler(handler) + logger.setLevel(logging.INFO) + logger.propagate = False + return logger + def _resolve_config_name() -> str: """Keep the worker aligned with container/runtime environment selection.""" @@ -30,17 +47,18 @@ def _resolve_config_name() -> str: def main(): + log = _configure_logging() app = create_app(_resolve_config_name()) poll_seconds = float(app.config.get('KB_WORKER_POLL_SECONDS', 2)) with app.app_context(): - print(f'[kb-worker] started, poll_seconds={poll_seconds}') + log.info('started, poll_seconds=%s', poll_seconds) while True: processed, message = process_next_clean_job() if not processed: time.sleep(poll_seconds) continue - print(f'[kb-worker] processed job: {message}') + log.info('processed job: %s', message) if __name__ == '__main__': From 858fb91f418569f86450a3b85d439836aee2ae4d Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Thu, 28 May 2026 10:40:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Jenkins=E9=83=A8=E7=BD=B2=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E9=83=A8=E7=BD=B2hxopx-kb-worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 4 ++-- docs/knowledge_base_runtime_deploy.md | 2 +- docs/project_context.md | 2 +- scripts/deploy_compose.sh | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a326614d..d8bf9514 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,8 +62,8 @@ services: hxops-kb-worker: image: ${BACKEND_IMAGE:-hxops-backend:local} build: - context: ./backend - dockerfile: Dockerfile + context: . + dockerfile: backend/Dockerfile args: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} diff --git a/docs/knowledge_base_runtime_deploy.md b/docs/knowledge_base_runtime_deploy.md index 944d77a9..12f86738 100644 --- a/docs/knowledge_base_runtime_deploy.md +++ b/docs/knowledge_base_runtime_deploy.md @@ -106,7 +106,7 @@ docker compose ps 预期: - `hxops-backend` 为 `Up` -- `hxops-kb-worker` 为 `Up` +- `hxops-kb-worker` 为 `Up`(与 backend 共用镜像;Jenkins/`deploy_compose.sh` 在后端变更时会一并重建) - `hxops-frontend` 为 `Up` 若启用了 `kb-redis` profile,则额外确认: diff --git a/docs/project_context.md b/docs/project_context.md index 4c41fbbf..82a2faba 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -86,7 +86,7 @@ hxops/ 采用 **本地开发 -> Gitee -> Jenkins -> 服务器 `deploy_compose.sh`**: 1. **本地开发**: 改代码后 `git push` 到对应分支(`dev` / `test` / `prod` 等)。 -2. **Jenkins**: 在目标机 `git fetch/checkout` 后执行 `scripts/deploy_compose.sh `,按变更增量重建 `hxops-frontend` / `hxops-backend`,并跑 `flask db upgrade` 与健康检查。 +2. **Jenkins**: 在目标机 `git fetch/checkout` 后执行 `scripts/deploy_compose.sh `,按变更增量重建 `hxops-frontend` / `hxops-backend` / `hxops-kb-worker`(后端变更时 worker 与 backend 同镜像一并重建),并跑 `flask db upgrade` 与健康检查。 3. **环境配置**: 仓库根目录 `.env.shared` + `.env.dev|test|prod`(见 `docs/env_loading_priority.md`)。 ## 5. 🗄️ 核心数据模型 (Database Models) diff --git a/scripts/deploy_compose.sh b/scripts/deploy_compose.sh index 0330d98f..0f5e5cef 100644 --- a/scripts/deploy_compose.sh +++ b/scripts/deploy_compose.sh @@ -141,12 +141,13 @@ if [[ "${FRONTEND_CHANGED}" == "true" ]]; then services+=("hxops-frontend") fi if [[ "${BACKEND_CHANGED}" == "true" ]]; then - services+=("hxops-backend") + # 知识库清洗与 backend 共用镜像;仅重建 backend 时 worker 会继续跑旧容器/旧代码 + services+=("hxops-backend" "hxops-kb-worker") fi # 如果只是部署配置变更(如 compose/env/脚本),但前后端代码未改,则两边都更新 if [[ ${#services[@]} -eq 0 && "${DEPLOY_CONFIG_CHANGED}" == "true" ]]; then - services=("hxops-frontend" "hxops-backend") + services=("hxops-frontend" "hxops-backend" "hxops-kb-worker") fi # 无变更则直接跳过,避免无意义重启 From a9753fd10fcef873d8c51bf2c3f6313cfb835f3a Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Thu, 28 May 2026 10:18:56 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Jenkins=E9=83=A8=E7=BD=B2hxopx-kb-worker?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.shared | 1 - backend/app/config.py | 1 + backend/requirements.txt | 1 + backend/worker_kb.py | 50 ++++- docker-compose.yml | 31 ++-- docs/knowledge_base_runtime_deploy.md | 2 +- docs/project_context.md | 2 +- docs/{ => ui}/DESIGN_SYSTEM.md | 27 +++ docs/ui/UI_CODING_GUIDELINES.md | 255 ++++++++++++++++++++++++++ scripts/deploy_compose.sh | 5 +- 10 files changed, 345 insertions(+), 30 deletions(-) rename docs/{ => ui}/DESIGN_SYSTEM.md (93%) create mode 100644 docs/ui/UI_CODING_GUIDELINES.md diff --git a/.env.shared b/.env.shared index 0b47389c..c058df85 100644 --- a/.env.shared +++ b/.env.shared @@ -88,7 +88,6 @@ PLM_ORACLE_PORT=1521 PLM_ORACLE_SID=orcl PLM_ORACLE_USERNAME=PLM PLM_ORACLE_PASSWORD=PLM -ORACLE_CLIENT_LIB_DIR=oracle_client\instantclient_19_30 # SRM SQL Server Configuration SRM_SQLSERVER_HOST=192.168.55.106 diff --git a/backend/app/config.py b/backend/app/config.py index bcc44102..e4c36917 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -180,6 +180,7 @@ class TestingConfig(Config): config = { 'development': DevelopmentConfig, 'test': TestingConfig, + 'testing': TestingConfig, # alias for create_app('testing') in pytest 'production': ProductionConfig, 'default': DevelopmentConfig, } diff --git a/backend/requirements.txt b/backend/requirements.txt index 3c85df56..2cae437b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -35,3 +35,4 @@ lxml==6.0.2 typer==0.17.4 croniter pyyaml +minio>=7.2.0 diff --git a/backend/worker_kb.py b/backend/worker_kb.py index a33d28ff..125112ec 100644 --- a/backend/worker_kb.py +++ b/backend/worker_kb.py @@ -4,43 +4,73 @@ backend/worker_kb.py """ from __future__ import annotations +import logging import os +import sys import time from app import create_app from app.services.knowledge_cleaning.queue_service import process_next_clean_job +_LOG_FORMAT = '%(asctime)s %(levelname)s [kb-worker] %(message)s' +_LOG_DATEFMT = '%Y-%m-%d %H:%M:%S' + + +def _configure_logging() -> logging.Logger: + logger = logging.getLogger('kb-worker') + if logger.handlers: + return logger + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(logging.Formatter(_LOG_FORMAT, datefmt=_LOG_DATEFMT)) + logger.addHandler(handler) + logger.setLevel(logging.INFO) + logger.propagate = False + return logger + def _resolve_config_name() -> str: - """Keep the worker aligned with container/runtime environment selection.""" - explicit = os.getenv('APP_CONFIG') - if explicit: - return explicit.strip().lower() + """Keep the worker aligned with container/runtime environment selection. - flask_env = os.getenv('FLASK_ENV', 'production').strip().lower() + Note: ``FLASK_ENV=test`` / ``ENV_NAME=test`` mean the *test deployment* host + (``.env.test``), not pytest. Use ``production`` so DATABASE_URL from env_file + is honored. ``testing`` is only for in-memory unit tests (``TestingConfig``). + """ + explicit = (os.getenv('APP_CONFIG') or '').strip().lower() + if explicit: + if explicit in ('testing', 'test'): + # Allow explicit pytest-style config only when APP_CONFIG is set; + # never infer this from FLASK_ENV=test on deploy hosts. + return 'test' + return explicit + + env_name = (os.getenv('ENV_NAME') or os.getenv('FLASK_ENV') or 'production').strip().lower() mapping = { 'dev': 'development', 'development': 'development', - 'test': 'testing', - 'testing': 'testing', + # Deploy env files: test/prod hosts use real DB via ProductionConfig + 'test': 'production', + 'env': 'production', 'prod': 'production', 'production': 'production', + # Pytest-only aliases (not used on deploy unless APP_CONFIG forces it) + 'testing': 'test', } - return mapping.get(flask_env, 'production') + return mapping.get(env_name, 'production') def main(): + log = _configure_logging() app = create_app(_resolve_config_name()) poll_seconds = float(app.config.get('KB_WORKER_POLL_SECONDS', 2)) with app.app_context(): - print(f'[kb-worker] started, poll_seconds={poll_seconds}') + log.info('started, poll_seconds=%s', poll_seconds) while True: processed, message = process_next_clean_job() if not processed: time.sleep(poll_seconds) continue - print(f'[kb-worker] processed job: {message}') + log.info('processed job: %s', message) if __name__ == '__main__': diff --git a/docker-compose.yml b/docker-compose.yml index a326614d..7965d80f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,9 +36,9 @@ services: # 数据库连接 (在环境变量中配置) - DATABASE_URL=${DATABASE_URL} - FLASK_APP=${FLASK_APP:-run.py} - - FLASK_ENV=${FLASK_ENV:-production} - - ORACLE_CLIENT_LIB_DIR=${ORACLE_CLIENT_LIB_DIR:-/app/oracle_client/instantclient_19_31} - - LD_LIBRARY_PATH=${ORACLE_CLIENT_LIB_DIR}:/app/oracle_client + - FLASK_ENV=${FLASK_ENV} + - ORACLE_CLIENT_LIB_DIR=${ORACLE_CLIENT_LIB_DIR} + - LD_LIBRARY_PATH=${ORACLE_CLIENT_LIB_DIR} - REDIS_URL=${REDIS_URL:-redis://kb-redis:6379/0} - KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb} - KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker} @@ -62,8 +62,8 @@ services: hxops-kb-worker: image: ${BACKEND_IMAGE:-hxops-backend:local} build: - context: ./backend - dockerfile: Dockerfile + context: . + dockerfile: backend/Dockerfile args: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} @@ -77,16 +77,17 @@ services: - ${COMPOSE_SHARED_ENV_BASENAME:-.env.shared} - ${COMPOSE_ENV_BASENAME:-.env.dev} environment: - DATABASE_URL: - SECRET_KEY: - FLASK_APP: ${FLASK_APP:-run.py} - FLASK_ENV: ${FLASK_ENV:-production} - ORACLE_CLIENT_LIB_DIR: ${ORACLE_CLIENT_LIB_DIR:-/app/oracle_client/instantclient_19_31} - LD_LIBRARY_PATH: ${ORACLE_CLIENT_LIB_DIR}:/app/oracle_client - REDIS_URL: ${REDIS_URL:-redis://kb-redis:6379/0} - KB_STORAGE_ROOT: ${KB_STORAGE_ROOT:-/app/data/kb} - KB_TASK_EXECUTION_MODE: ${KB_TASK_EXECUTION_MODE:-worker} - KB_WORKER_POLL_SECONDS: ${KB_WORKER_POLL_SECONDS:-2} + # 勿写空键 DATABASE_URL:/SECRET_KEY:,会覆盖 env_file 导致 worker 启动即退出 + - DATABASE_URL=${DATABASE_URL} + - SECRET_KEY=${SECRET_KEY} + - FLASK_APP=${FLASK_APP:-run.py} + - FLASK_ENV=${FLASK_ENV} + - ORACLE_CLIENT_LIB_DIR=${ORACLE_CLIENT_LIB_DIR} + - LD_LIBRARY_PATH=${ORACLE_CLIENT_LIB_DIR} + - REDIS_URL=${REDIS_URL:-redis://kb-redis:6379/0} + - KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb} + - KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker} + - KB_WORKER_POLL_SECONDS=${KB_WORKER_POLL_SECONDS:-2} extra_hosts: - "host.docker.internal:host-gateway" volumes: diff --git a/docs/knowledge_base_runtime_deploy.md b/docs/knowledge_base_runtime_deploy.md index 944d77a9..12f86738 100644 --- a/docs/knowledge_base_runtime_deploy.md +++ b/docs/knowledge_base_runtime_deploy.md @@ -106,7 +106,7 @@ docker compose ps 预期: - `hxops-backend` 为 `Up` -- `hxops-kb-worker` 为 `Up` +- `hxops-kb-worker` 为 `Up`(与 backend 共用镜像;Jenkins/`deploy_compose.sh` 在后端变更时会一并重建) - `hxops-frontend` 为 `Up` 若启用了 `kb-redis` profile,则额外确认: diff --git a/docs/project_context.md b/docs/project_context.md index 4c41fbbf..82a2faba 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -86,7 +86,7 @@ hxops/ 采用 **本地开发 -> Gitee -> Jenkins -> 服务器 `deploy_compose.sh`**: 1. **本地开发**: 改代码后 `git push` 到对应分支(`dev` / `test` / `prod` 等)。 -2. **Jenkins**: 在目标机 `git fetch/checkout` 后执行 `scripts/deploy_compose.sh `,按变更增量重建 `hxops-frontend` / `hxops-backend`,并跑 `flask db upgrade` 与健康检查。 +2. **Jenkins**: 在目标机 `git fetch/checkout` 后执行 `scripts/deploy_compose.sh `,按变更增量重建 `hxops-frontend` / `hxops-backend` / `hxops-kb-worker`(后端变更时 worker 与 backend 同镜像一并重建),并跑 `flask db upgrade` 与健康检查。 3. **环境配置**: 仓库根目录 `.env.shared` + `.env.dev|test|prod`(见 `docs/env_loading_priority.md`)。 ## 5. 🗄️ 核心数据模型 (Database Models) diff --git a/docs/DESIGN_SYSTEM.md b/docs/ui/DESIGN_SYSTEM.md similarity index 93% rename from docs/DESIGN_SYSTEM.md rename to docs/ui/DESIGN_SYSTEM.md index 2e8e655e..2de42e06 100644 --- a/docs/DESIGN_SYSTEM.md +++ b/docs/ui/DESIGN_SYSTEM.md @@ -2,6 +2,8 @@ > 目标:在**明亮 / 暗黑**主题下,页面背景、文字、边框、按钮、卡片、布局间距保持一致;新页面默认符合规范,旧页面按阶段迁移。 +> **AI / 日常编码实操准则(铁律、控件选型、Prompt 片段)** → [UI_CODING_GUIDELINES.md](./UI_CODING_GUIDELINES.md) + --- ## 1. 总体架构 @@ -152,6 +154,31 @@ colors: { | `.btn-ghost` | 图标/工具栏 | | `.btn-danger` | 删除、退出等 | | `.btn-icon` | 正方形图标按钮(顶栏、侧栏折叠) | +| `.btn-sm` / `.btn-lg` | 尺寸变体 | +| `.btn-segment` / `.btn-segment--active` | **已废弃**,改用 `segment-item`(见 UI 准则 §3) | + +### 3.1.1 分段切换(单选,非操作按钮) + +| 类名 | 用途 | +|------|------| +| `.segment-control` + `--cols-2/3/4` / `--fit` | 容器布局 | +| `.segment-item` / `.segment-item--active` | 选项(细边框 + brand 选中态) | + +### 3.1.2 顶栏语言 / 主题 + +| 组件或类 | 用途 | +|----------|------| +| `ThemeToggleButton` | 亮暗切换(圆形容器) | +| `LocaleToggleButton` | 语言图标 + 固定四项菜单 | +| `.header-locale-menu` | 语言下拉面板 | + +### 3.1.3 弹窗(通用) + +| 类名 | 用途 | +|------|------| +| `.dialog-overlay` / `.dialog-panel` | 遮罩 + 面板 | +| `.dialog-header` / `.dialog-body` / `.dialog-footer` | 结构分区 | +| `.admin-modal-*` | Admin 专用(与 dialog 二选一,逐步统一) | ### 3.2 表单 diff --git a/docs/ui/UI_CODING_GUIDELINES.md b/docs/ui/UI_CODING_GUIDELINES.md new file mode 100644 index 00000000..242ecb88 --- /dev/null +++ b/docs/ui/UI_CODING_GUIDELINES.md @@ -0,0 +1,255 @@ +# HXOps UI 编码准则(AI / 人工通用) + +> **用途**:新功能、改版、修 UI 时必读。给 AI 写需求时,可将本文 **§0 Prompt 片段** 与 **§1 铁律** 一并粘贴进任务说明。 +> **架构详解**:见 [DESIGN_SYSTEM.md](./DESIGN_SYSTEM.md)。 +> **样式实现**:`frontend/src/styles/tokens.css`、`utilities.css`、`components-ds.css`、`style.css`。 + +--- + +## 0. 给 AI 的任务 Prompt 片段(可直接复制) + +```text +请严格遵循 docs/UI_CODING_GUIDELINES.md: + +1. 颜色只用 L1 语义类(bg-page / bg-surface / text-primary / border-default 等),禁止 dark: 双色、禁止 bg-white/slate/gray 作结构色、禁止 text-[#hex]。 +2. 操作按钮只用 L2:btn-primary / btn-secondary / btn-ghost / btn-danger;禁止手写 rounded-xl border px-4 仿按钮。 +3. 单选切换(主题、语言菜单项、Cron 频率、反馈类型等)用 segment-control + segment-item,禁止用 btn-primary 或原生 select 做切换。 +4. 弹窗用 dialog-overlay + dialog-panel(或 Admin 的 admin-modal-*),禁止 fixed inset-0 bg-black/40 手写遮罩。 +5. 顶栏语言用 LocaleToggleButton;菜单四项固定文案:简体中文 / 繁體中文 / English / ไทย(禁止 t() 翻译菜单标签)。 +6. 主题切换用 ThemeToggleButton(圆形容器);语言图标无外圈,与侧栏底栏图标同风格。 +7. 最小 diff,匹配现有组件;改完 npm run build。 +``` + +--- + +## 1. 铁律(违反即需改) + +### 1.1 必须(MUST) + +| # | 规则 | +|---|------| +| M1 | 结构色只来自 **L1 语义 class** 或 L2 组件(内部已绑变量) | +| M2 | 主题亮暗靠 `html.dark` + CSS 变量,**不写** `dark:bg-*` / `dark:text-*` | +| M3 | 可点击主/次操作 → **`.btn-*`** | +| M4 | 多选一(非提交动作)→ **`.segment-control` + `.segment-item`** | +| M5 | 模态框 → **`.dialog-*`** 或 **`.admin-modal-*`** | +| M6 | 文本框/下拉(表单字段)→ **`.input-field`** / **`.select-field`** | +| M7 | 页面根在 **`page-shell`** 或 L3 布局(`MarketingShell` / `ChatShell` / `MinimalShell`)内 | +| M8 | 语言切换复用 **`LocaleToggleButton`**,选项文案 **固定四种语言名**(见 §5.3) | + +### 1.2 禁止(MUST NOT) + +| # | 规则 | +|---|------| +| X1 | `bg-white`、`bg-gray-*`、`bg-slate-*`、`text-slate-*` 作为页面/卡片/表单**结构色** | +| X2 | `text-[#...]`、`bg-[#...]`(登录营销区 `data-surface="marketing"` 除外,须注释 `design-system:exception`) | +| X3 | 同一元素 `bg-x` + `dark:bg-y` | +| X4 | 用 **`btn-primary` / 粗边框独立块** 做「选中项切换」(那是操作按钮,不是分段控件) | +| X5 | 用 **原生 `` | +| 顶栏切换亮暗 | `ThemeToggleButton` | 手写 moon 按钮无统一尺寸 | +| 通用业务弹窗 | `dialog-overlay` + `dialog-panel` + header/body/footer | `bg-slate-900/40` + 自写圆角盒子 | +| Admin 大表单弹窗 | `admin-modal-overlay` + `admin-modal-panel` | 与 `dialog-*` 混用两套除非迁移中 | +| 删除确认 | `DeleteConfirmDialog` | 自写红色弹窗 | +| 全局提示 | `LevelMessageDialog` / `alert-ds` | 手写 hex 色 alert | + +### 3.1 分段切换(segment-control)视觉约定 + +与个人中心「主题」一致: + +- **未选中**:`border`(1px)+ `bg-surface` + `text-secondary` +- **选中**:`border-brand-500` + `bg-brand-50` + `text-brand-700`(暗色见 `components-ds.css`) +- **禁止**:`border-2`、灰底轨道粘在一起、选中态用实心 `btn-primary` 蓝按钮 + +布局修饰符: + +| 类名 | 场景 | +|------|------| +| `segment-control--cols-2` | 两列等分 | +| `segment-control--cols-3` | 三列等分(主题、反馈类型) | +| `segment-control--cols-4` | 四列;小屏 2 列(Cron) | +| `segment-control--fit` | 工具栏 2 个短标签,宽度随内容 | +| `segment-control--sm` / `--md` | 字号与内边距 | + +--- + +## 4. 颜色与排版 + +### 4.1 语义色(模板中优先) + +- 背景:`bg-page`、`bg-surface`、`bg-surface-soft`、`bg-surface-strong` +- 文字:`text-primary`、`text-secondary`、`text-muted` +- 边框:`border-default`、`border-subtle` +- 遮罩:`bg-overlay`(勿用 `bg-black/40`、`bg-slate-900/40`) + +### 4.2 品牌与状态 + +- 强调操作:`brand-600` / `brand-700`(按钮、链接) +- 成功/警告/错误:优先 L2 `alert-*` 或 `--status-*` 令牌 + +### 4.3 排版 + +- 页面标题:`page-title` 或 `section-title` +- 表单标签:`label-field` +- 区块间距:`section-gap`、`form-stack` + +--- + +## 5. 顶栏与语言/主题 + +### 5.1 登录页 / 营销顶栏(`MarketingShell` #tools) + +```vue + + +``` + +- 主题:**圆形容器** `theme-toggle-btn--inline`(h-8 / md:h-9) +- 语言:**仅图标** `header-locale-btn`,**无外圈**;点击展开 `header-locale-menu` + +### 5.2 Chat 侧栏底栏 + +图标行:`LayoutGrid`(Agent)· 主题(Sun/Moon)· **`LocaleToggleButton variant="sidebar"`** · 反馈 · 工作台 + +- **禁止**在用户头像下拉里再放语言 ``** → 双箭头、高度与主题钮不一致。 +4. **语言菜单 `t()` 翻译** → 切英文后菜单变英文。 +5. **弹窗底部塞配置 checkbox** → 应进 body,footer 仅操作钮。 +6. **PowerShell 批量替换** → 破坏 `:class`、压成单行;改 UI 优先小范围手工 + 构建验证。 + +--- + +## 11. 参考索引 + +| 文件 | 内容 | +|------|------| +| `docs/DESIGN_SYSTEM.md` | 令牌表、阶段迁移、目录结构 | +| `frontend/src/styles/components-ds.css` | L2 权威列表(segment、dialog、admin、chat、header-locale) | +| `frontend/src/components/LocaleToggleButton.vue` | 语言图标 + 固定菜单 | +| `frontend/src/components/ThemeToggleButton.vue` | 主题按钮 | +| `frontend/src/components/GeneralFeedbackDialog.vue` | dialog + segment 示例 | +| `frontend/src/views/WorkspaceView.vue` | 个人中心 `segment-control--cols-3` 主题 | + +--- + +*版本:2026-05-27 · 与仓库实现对齐;变更 L2 时请同步更新 §3、§5。* diff --git a/scripts/deploy_compose.sh b/scripts/deploy_compose.sh index 0330d98f..0f5e5cef 100644 --- a/scripts/deploy_compose.sh +++ b/scripts/deploy_compose.sh @@ -141,12 +141,13 @@ if [[ "${FRONTEND_CHANGED}" == "true" ]]; then services+=("hxops-frontend") fi if [[ "${BACKEND_CHANGED}" == "true" ]]; then - services+=("hxops-backend") + # 知识库清洗与 backend 共用镜像;仅重建 backend 时 worker 会继续跑旧容器/旧代码 + services+=("hxops-backend" "hxops-kb-worker") fi # 如果只是部署配置变更(如 compose/env/脚本),但前后端代码未改,则两边都更新 if [[ ${#services[@]} -eq 0 && "${DEPLOY_CONFIG_CHANGED}" == "true" ]]; then - services=("hxops-frontend" "hxops-backend") + services=("hxops-frontend" "hxops-backend" "hxops-kb-worker") fi # 无变更则直接跳过,避免无意义重启