diff --git a/backend/app/services/training_service.py b/backend/app/services/training_service.py index 4c743a58..8e782082 100644 --- a/backend/app/services/training_service.py +++ b/backend/app/services/training_service.py @@ -85,7 +85,7 @@ def _normalize_exam_mode(value: Any) -> str: return text -def _build_default_safety_progress(safety_stage: str) -> dict[str, str]: +def _build_default_safety_progress(safety_stage: str) -> dict[str, Any]: """ 根据安全培训当前阶段推导三级学习进度。 @@ -94,7 +94,7 @@ def _build_default_safety_progress(safety_stage: str) -> dict[str, str]: Returns: company、department、team 三个级别的状态快照。 """ - progress: dict[str, str] = {key: "pending" for key in SAFETY_LEVEL_KEYS} + progress: dict[str, Any] = {key: "pending" for key in SAFETY_LEVEL_KEYS} if safety_stage == "company": progress["company"] = "active" return progress @@ -128,7 +128,7 @@ def _normalize_safety_stage(value: Any) -> str: return text -def _normalize_safety_progress(value: Any, safety_stage: str) -> dict[str, str]: +def _normalize_safety_progress(value: Any, safety_stage: str) -> dict[str, Any]: """ 规范安全培训三级进度对象。 diff --git a/backend/migrations/versions/1b2c3d4e5f6a_rebuild_shipping_field_governance.py b/backend/migrations/versions/1b2c3d4e5f6a_rebuild_shipping_field_governance.py index aacaa39b..a1460df8 100644 --- a/backend/migrations/versions/1b2c3d4e5f6a_rebuild_shipping_field_governance.py +++ b/backend/migrations/versions/1b2c3d4e5f6a_rebuild_shipping_field_governance.py @@ -1,7 +1,7 @@ """ backend/migrations/versions/1b2c3d4e5f6a_rebuild_shipping_field_governance.py -用途:重建货代字段资产治理——全局标准/扩展字段、Schema 族约束放宽、审计扩展;清空旧配置并种子 57 标准资产。 +用途:重建货代字段资产治理——全局标准/扩展字段、Schema 族约束放宽、审计扩展;清空旧配置并种子 58 标准资产。 依赖:前序 head 0a1b2c3d4e5f;standard_field_registry。 逻辑: upgrade — 软化**历史运行域**硬 FK(Extraction/Run/Snapshot/Artifact/Review 等保留 orphan ID, @@ -230,7 +230,7 @@ def _revert_shipping_order_fields_structure(is_sqlite: bool) -> None: batch.drop_column(column) if not _column_exists('shipping_order_fields', 'schema_id'): batch.add_column(sa.Column('schema_id', sa.Integer(), nullable=True)) - batch.drop_constraint('uq_shipping_order_fields_field_code', type_='unique') + batch.drop_constraint('uq_shipping_order_fields_code_scope', type_='unique') batch.create_unique_constraint( 'uq_shipping_order_fields_schema_code', ['schema_id', 'field_code'], @@ -253,7 +253,7 @@ def _revert_shipping_order_fields_structure(is_sqlite: bool) -> None: op.execute(sa.text('DROP INDEX IF EXISTS ix_shipping_order_fields_scope_status')) op.execute(sa.text('DROP INDEX IF EXISTS ix_shipping_order_fields_asset_kind')) op.execute(sa.text( - 'ALTER TABLE shipping_order_fields DROP CONSTRAINT IF EXISTS uq_shipping_order_fields_field_code' + 'ALTER TABLE shipping_order_fields DROP CONSTRAINT IF EXISTS uq_shipping_order_fields_code_scope' )) op.execute(sa.text( 'ALTER TABLE shipping_order_fields DROP CONSTRAINT IF EXISTS ck_shipping_order_fields_asset_kind' @@ -427,7 +427,10 @@ def upgrade() -> None: batch.add_column(sa.Column('retired_at', sa.DateTime(), nullable=True)) batch.add_column(sa.Column('restored_by_id', sa.Integer(), nullable=True)) batch.add_column(sa.Column('restored_at', sa.DateTime(), nullable=True)) - batch.create_unique_constraint('uq_shipping_order_fields_field_code', ['field_code']) + batch.create_unique_constraint( + 'uq_shipping_order_fields_code_scope', + ['field_code', 'scope'], + ) batch.create_check_constraint( 'ck_shipping_order_fields_category', "field_category IN ('order_header', 'order_line')", @@ -472,7 +475,11 @@ def upgrade() -> None: op.add_column('shipping_order_fields', sa.Column('retired_at', sa.DateTime(), nullable=True)) op.add_column('shipping_order_fields', sa.Column('restored_by_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=True)) op.add_column('shipping_order_fields', sa.Column('restored_at', sa.DateTime(), nullable=True)) - op.create_unique_constraint('uq_shipping_order_fields_field_code', 'shipping_order_fields', ['field_code']) + op.create_unique_constraint( + 'uq_shipping_order_fields_code_scope', + 'shipping_order_fields', + ['field_code', 'scope'], + ) op.create_index('ix_shipping_order_fields_scope_status', 'shipping_order_fields', ['scope', 'status']) op.create_index('ix_shipping_order_fields_asset_kind', 'shipping_order_fields', ['asset_kind']) # 放宽/替换字段分类与采集模式约束:去掉 general_context @@ -515,7 +522,7 @@ def upgrade() -> None: op.alter_column('shipping_order_schema_audit_events', 'schema_id', existing_type=sa.Integer(), nullable=True) op.add_column('shipping_order_schema_audit_events', sa.Column('field_id', sa.String(36), nullable=True)) - # [STEP 5] 种子 57 标准字段 + 空默认族 + # [STEP 5] 种子 58 标准字段 + 空默认族 from app.services.shipping_notice.standard_field_registry import ( DEFAULT_SCHEMA_FAMILY_CODE, DEFAULT_SCHEMA_FAMILY_NAME, diff --git a/backend/tests/test_shipping_field_governance_migration.py b/backend/tests/test_shipping_field_governance_migration.py index 25cae97a..68b864ba 100644 --- a/backend/tests/test_shipping_field_governance_migration.py +++ b/backend/tests/test_shipping_field_governance_migration.py @@ -4,7 +4,7 @@ backend/tests/test_shipping_field_governance_migration.py 用途:验证字段资产治理重建迁移(1b2c3d4e5f6a)在 SQLite 上可升级/降级并种子默认族。 依赖:Alembic Operations、临时内存库、standard_field_registry。 逻辑:构造迁移前 fields(含 schema_id)、schemas、Excel 模板与导出产物对 schema_version 的 FK 依赖图 → -upgrade → 断言无 schema_id、57 标准资产、空默认族、CHECK 约束同步;downgrade → 断言结构回退 +upgrade → 断言无 schema_id、58 标准资产、Header/Line 同名字段可共存、空默认族、CHECK 约束同步;downgrade → 断言结构回退 (schema_id 恢复、asset_kind 消失) 且种子行清空;下游 orphan 引用不阻断迁移。 """ @@ -117,7 +117,7 @@ def _build_pre_migration_schema(metadata: sa.MetaData) -> None: def test_field_governance_rebuild_migration_seeds_global_assets(monkeypatch): - """关键断言:清空旧配置后种子 57 标准资产与 STANDARD_SHIPPING_NOTICE 空族,fields 无 schema_id。""" + """关键断言:清空旧配置后种子 58 标准资产与 STANDARD_SHIPPING_NOTICE 空族,fields 无 schema_id。""" migration = importlib.import_module( 'migrations.versions.1b2c3d4e5f6a_rebuild_shipping_field_governance', ) @@ -183,9 +183,11 @@ def test_field_governance_rebuild_migration_seeds_global_assets(monkeypatch): assert "collection_mode IN ('llm_extraction')" in ck_sql field_rows = connection.execute(sa.text( - "SELECT field_code, asset_kind, status FROM shipping_order_fields" + "SELECT field_code, scope, asset_kind, status FROM shipping_order_fields" )).mappings().all() assert len(field_rows) == len(STANDARD_FIELD_SPECS) == 58 + reservation_rows = [row for row in field_rows if row['field_code'] == 'reservation_id'] + assert {row['scope'] for row in reservation_rows} == {'header', 'line'} assert all(row['asset_kind'] == 'system_standard' for row in field_rows) assert all(row['status'] == 'active' for row in field_rows) assert 'legacy_po' not in {row['field_code'] for row in field_rows} diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 1d13ed73..20433374 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,6 +15,7 @@ "@vue-office/pdf": "^1.6.5", "cron-parser": "^5.5.0", "highlight.js": "^11.11.1", + "html2pdf.js": "^0.14.0", "lucide-vue-next": "^0.575.0", "marked": "^17.0.3", "pdfjs-dist": "^5.6.205", @@ -26,6 +27,7 @@ }, "devDependencies": { "@types/node": "^24.10.1", + "@types/pdfjs-dist": "^2.10.377", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.11", "@vue/tsconfig": "^0.8.1", @@ -135,6 +137,15 @@ "node": ">=6.0.0" } }, + "node_modules/@babel/runtime": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz", + "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/types": { "version": "7.29.7", "resolved": "https://registry.npmmirror.com/@babel/types/-/types-7.29.7.tgz", @@ -1152,6 +1163,36 @@ "undici-types": "~7.18.0" } }, + "node_modules/@types/pako": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/pako/-/pako-2.0.4.tgz", + "integrity": "sha512-VWDCbrLeVXJM9fihYodcLiIv0ku+AlOa/TQ1SvYOaBuyrSKgEcro95LJyIsJ4vSo6BXIxOKxiJAat04CmST9Fw==", + "license": "MIT" + }, + "node_modules/@types/pdfjs-dist": { + "version": "2.10.377", + "resolved": "https://registry.npmjs.org/@types/pdfjs-dist/-/pdfjs-dist-2.10.377.tgz", + "integrity": "sha512-RNBWpazVTkC5aiUIIo6d7ojlL0hJSoeQP1QCvTsVLW6qkNEpTALiI0DNGCYAGDfhbL0r17c/zNPQ15lk948UXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "pdfjs-dist": "*" + } + }, + "node_modules/@types/raf": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.3.tgz", + "integrity": "sha512-c4YAvMedbPZ5tEyxzQdMoOhhJ4RD3rngZIdwC2/qDN3d7JpEhB6fiBRKVY1lg5B7Wk+uPBjn5f39j1/2MY1oOw==", + "license": "MIT", + "optional": true + }, + "node_modules/@types/trusted-types": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", + "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", + "license": "MIT", + "optional": true + }, "node_modules/@vitejs/plugin-vue": { "version": "6.0.8", "resolved": "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-6.0.8.tgz", @@ -1695,6 +1736,15 @@ "dev": true, "license": "MIT" }, + "node_modules/base64-arraybuffer": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz", + "integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/baseline-browser-mapping": { "version": "2.11.0", "resolved": "https://registry.npmmirror.com/baseline-browser-mapping/-/baseline-browser-mapping-2.11.0.tgz", @@ -1825,6 +1875,26 @@ ], "license": "CC-BY-4.0" }, + "node_modules/canvg": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.11.tgz", + "integrity": "sha512-5ON+q7jCTgMp9cjpu4Jo6XbvfYwSB2Ow3kzHKfIyJfaCAOHLbdKPQqGKgfED/R5B+3TFFfe8pegYA+b423SRyA==", + "license": "MIT", + "optional": true, + "dependencies": { + "@babel/runtime": "^7.12.5", + "@types/raf": "^3.4.0", + "core-js": "^3.8.3", + "raf": "^3.4.1", + "regenerator-runtime": "^0.13.7", + "rgbcolor": "^1.0.1", + "stackblur-canvas": "^2.0.0", + "svg-pathdata": "^6.0.3" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/cfb": { "version": "1.2.2", "resolved": "https://registry.npmmirror.com/cfb/-/cfb-1.2.2.tgz", @@ -1955,6 +2025,21 @@ "url": "https://github.com/sponsors/mesqueeb" } }, + "node_modules/core-js": { + "version": "3.50.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.50.0.tgz", + "integrity": "sha512-BRWgOLKkFeCgRudR6zrs8p9XJZcE14grzKMMssoYrk6krtuEZ7MTKPIY5RzOnqsEKIR9kst7wNzphttraT+Yqw==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "engines": { + "node": "*" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/crc-32": { "version": "1.2.2", "resolved": "https://registry.npmmirror.com/crc-32/-/crc-32-1.2.2.tgz", @@ -1994,6 +2079,15 @@ "node": ">= 8" } }, + "node_modules/css-line-break": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz", + "integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==", + "license": "MIT", + "dependencies": { + "utrie": "^1.0.2" + } + }, "node_modules/css-tree": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.2.1.tgz", @@ -2069,6 +2163,15 @@ "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==", "license": "MIT" }, + "node_modules/dompurify": { + "version": "3.4.13", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.13.tgz", + "integrity": "sha512-2vmYIoqjze2d+kakP8S/nS5shfsl587kzwEjcGlTdiksUVgFHnFCsLYDVj/JNqJVOQZGSYBTmuycv0PodwmnMQ==", + "license": "(MPL-2.0 OR Apache-2.0)", + "optionalDependencies": { + "@types/trusted-types": "^2.0.7" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2205,6 +2308,17 @@ "node": ">= 6" } }, + "node_modules/fast-png": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/fast-png/-/fast-png-6.4.0.tgz", + "integrity": "sha512-kAqZq1TlgBjZcLr5mcN6NP5Rv4V2f22z00c3g8vRrwkcqjerx7BEhPbOnWCPqaHUl2XWQBJQvOT/FQhdMT7X/Q==", + "license": "MIT", + "dependencies": { + "@types/pako": "^2.0.3", + "iobuffer": "^5.3.2", + "pako": "^2.1.0" + } + }, "node_modules/fastq": { "version": "1.20.1", "resolved": "https://registry.npmmirror.com/fastq/-/fastq-1.20.1.tgz", @@ -2231,6 +2345,12 @@ } } }, + "node_modules/fflate": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz", + "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==", + "license": "MIT" + }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmmirror.com/fill-range/-/fill-range-7.1.1.tgz", @@ -2380,6 +2500,30 @@ "node": "^20.19.0 || ^22.12.0 || >=24.0.0" } }, + "node_modules/html2canvas": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz", + "integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==", + "license": "MIT", + "dependencies": { + "css-line-break": "^2.1.0", + "text-segmentation": "^1.0.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/html2pdf.js": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/html2pdf.js/-/html2pdf.js-0.14.0.tgz", + "integrity": "sha512-yvNJgE/8yru2UeGflkPdjW8YEY+nDH5X7/2WG4uiuSCwYiCp8PZ8EKNiTAa6HxJ1NjC51fZSIEq6xld5CADKBQ==", + "license": "MIT", + "dependencies": { + "dompurify": "^3.3.1", + "html2canvas": "^1.0.0", + "jspdf": "^4.0.0" + } + }, "node_modules/ini": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", @@ -2387,6 +2531,12 @@ "dev": true, "license": "ISC" }, + "node_modules/iobuffer": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/iobuffer/-/iobuffer-5.4.0.tgz", + "integrity": "sha512-DRebOWuqDvxunfkNJAlc3IzWIPD5xVxwUNbHr7xKB8E6aLJxIPfNX3CoMJghcFjpv6RWQsrcJbghtEwSPoJqMA==", + "license": "MIT" + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmmirror.com/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -2575,6 +2725,23 @@ } } }, + "node_modules/jspdf": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-4.2.1.tgz", + "integrity": "sha512-YyAXyvnmjTbR4bHQRLzex3CuINCDlQnBqoSYyjJwTP2x9jDLuKDzy7aKUl0hgx3uhcl7xzg32agn5vlie6HIlQ==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.28.6", + "fast-png": "^6.2.0", + "fflate": "^0.8.1" + }, + "optionalDependencies": { + "canvg": "^3.0.11", + "core-js": "^3.6.0", + "dompurify": "^3.3.1", + "html2canvas": "^1.0.0-rc.5" + } + }, "node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmmirror.com/lightningcss/-/lightningcss-1.33.0.tgz", @@ -3102,6 +3269,22 @@ "dev": true, "license": "BlueOak-1.0.0" }, + "node_modules/pako": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pako/-/pako-2.2.0.tgz", + "integrity": "sha512-zJq6RP/5q+TO2OpFV3FHzlPnFjmkb7Nc99a5SNjJE+uu/PkpChs+NIZSSzbBoD+6kjiISXjfYdwj1ZRQ81dz/w==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "(MIT AND Zlib)" + }, "node_modules/parse5": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/parse5/-/parse5-8.0.1.tgz", @@ -3201,6 +3384,13 @@ "integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==", "license": "MIT" }, + "node_modules/performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", + "license": "MIT", + "optional": true + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", @@ -3469,6 +3659,16 @@ ], "license": "MIT" }, + "node_modules/raf": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", + "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", + "license": "MIT", + "optional": true, + "dependencies": { + "performance-now": "^2.1.0" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmmirror.com/read-cache/-/read-cache-1.0.0.tgz", @@ -3502,6 +3702,13 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "license": "MIT", + "optional": true + }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", @@ -3549,6 +3756,16 @@ "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", "license": "MIT" }, + "node_modules/rgbcolor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz", + "integrity": "sha512-9aZLIrhRaD97sgVhtJOW6ckOEh6/GnvQtdVNfdZ6s67+3/XwLS9lBcQYzEEhYVeUowN7pRzMLsyGhK2i/xvWbw==", + "license": "MIT OR SEE LICENSE IN FEEL-FREE.md", + "optional": true, + "engines": { + "node": ">= 0.8.15" + } + }, "node_modules/rolldown": { "version": "1.1.5", "resolved": "https://registry.npmmirror.com/rolldown/-/rolldown-1.1.5.tgz", @@ -3712,6 +3929,16 @@ "dev": true, "license": "MIT" }, + "node_modules/stackblur-canvas": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.7.0.tgz", + "integrity": "sha512-yf7OENo23AGJhBriGx0QivY5JP6Y1HbrrDI6WLt6C5auYZXlQrheoY8hD4ibekFKz1HOfE48Ww8kMWMnJD/zcQ==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=0.1.14" + } + }, "node_modules/std-env": { "version": "4.2.0", "resolved": "https://registry.npmmirror.com/std-env/-/std-env-4.2.0.tgz", @@ -3869,6 +4096,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/svg-pathdata": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-6.0.3.tgz", + "integrity": "sha512-qsjeeq5YjBZ5eMdFuUa4ZosMLxgr5RZ+F+Y1OrDhuOCEInRMA3x74XdBtggJcj9kOeInz0WE+LgCPDkZFlBYJw==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", @@ -3926,6 +4163,15 @@ "node": ">=4" } }, + "node_modules/text-segmentation": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz", + "integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==", + "license": "MIT", + "dependencies": { + "utrie": "^1.0.2" + } + }, "node_modules/thenify": { "version": "3.3.1", "resolved": "https://registry.npmmirror.com/thenify/-/thenify-3.3.1.tgz", @@ -4130,6 +4376,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, + "node_modules/utrie": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz", + "integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==", + "license": "MIT", + "dependencies": { + "base64-arraybuffer": "^1.0.2" + } + }, "node_modules/vite": { "version": "8.1.5", "resolved": "https://registry.npmmirror.com/vite/-/vite-8.1.5.tgz", diff --git a/frontend/package.json b/frontend/package.json index f181838e..98b9ffbe 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,6 +17,7 @@ "@vue-office/pdf": "^1.6.5", "cron-parser": "^5.5.0", "highlight.js": "^11.11.1", + "html2pdf.js": "^0.14.0", "lucide-vue-next": "^0.575.0", "marked": "^17.0.3", "pdfjs-dist": "^5.6.205", @@ -28,6 +29,7 @@ }, "devDependencies": { "@types/node": "^24.10.1", + "@types/pdfjs-dist": "^2.10.377", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.11", "@vue/tsconfig": "^0.8.1", diff --git a/frontend/src/features/chat/api/training.api.ts b/frontend/src/features/chat/api/training.api.ts index c08f84d4..5f48f231 100644 --- a/frontend/src/features/chat/api/training.api.ts +++ b/frontend/src/features/chat/api/training.api.ts @@ -205,6 +205,7 @@ function mapTrainingRecord(data: TrainingRecordApi): TrainingRecord { score: progress.score, attempts: progress.attempts, status: progress.status, + answerDetails: progress.answerDetails, }; } diff --git a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue index 902610be..0cd8ea3e 100644 --- a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue +++ b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue @@ -16,12 +16,12 @@ import { ChevronUp, ClipboardCheck, Download, + FileText, PlayCircle, RefreshCcw, ShieldCheck, Target, User, - FileText, Video, Lock, XCircle, @@ -30,6 +30,9 @@ import { useTrainingWorkspace } from '@/features/chat/composables/useTrainingWor import FilePreviewModal from '@/shared/components/FilePreviewModal.vue'; import { useMessage } from '@/shared/composables/useMessage'; import { resolveTrainingExamPdfGuide, type TrainingGuideLike } from '@/features/chat/training/trainingWorkspace.utils'; +import { getMyTrainingConfig } from '@/features/chat/api/training.api'; +import type { TrainingRecord } from '@/features/chat/training/training.types'; +import html2pdf from 'html2pdf.js'; import { getAuthHeaders } from '@/shared/utils/auth'; @@ -98,6 +101,74 @@ const handleVideoEnded = () => { workspace.stopMaterialTimer(); }; +const reportModalVisible = ref(false); +const currentReportRecord = ref(null); +const reportQuestions = ref>({}); +const reportLoading = ref(false); + +const openReport = async (record: TrainingRecord) => { + currentReportRecord.value = record; + reportModalVisible.value = true; + reportLoading.value = true; + try { + const config = await getMyTrainingConfig(record.trainingType || 'onboarding'); + const qMap: Record = {}; + if (config?.resources) { + config.resources.forEach(r => { + if (Array.isArray(r.inlineQuestions)) { + r.inlineQuestions.forEach((q: any) => { + qMap[q.id] = q; + }); + } + }); + } + reportQuestions.value = qMap; + } catch (err) { + console.error('Failed to load config for report', err); + } finally { + reportLoading.value = false; + } +}; + +const closeReport = () => { + reportModalVisible.value = false; + currentReportRecord.value = null; +}; + +const printReport = async () => { + const element = document.getElementById('report-modal-content'); + const report = currentReportRecord.value; + if (!element || !report) return; + const fileName = `${report.name}_${report.trainingType === 'onboarding' ? t('chat.training.hr.filters.typeOnboarding') : report.trainingType === 'safety' ? t('chat.training.hr.filters.typeSafety') : report.trainingType}_考试报告.pdf`; + + const opt = { + margin: [15, 15, 15, 15] as [number, number, number, number], + filename: fileName, + image: { type: 'jpeg' as const, quality: 0.98 }, + html2canvas: { + scale: 2, + useCORS: true, + letterRendering: true, + windowWidth: 794, + scrollX: 0, + scrollY: 0, + }, + pagebreak: { + mode: ['css', 'legacy'] as const, + avoid: ['.report-question', '.report-header-info', '.report-option'] as string[], + }, + jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' as const } + }; + + try { + await html2pdf().set(opt).from(element).save(); + msg.success(t('chat.training.hr.report.downloadSuccess') || 'PDF 下载成功'); + } catch (error) { + console.error('Failed to generate PDF:', error); + msg.error(t('chat.training.hr.report.downloadFailed') || 'PDF 生成失败'); + } +}; + const reportVideoDebugEvent = (event: Event) => { const video = event.target as HTMLVideoElement; // #region debug-point A-E:ios-video-runtime @@ -247,6 +318,36 @@ const isMaterialCompleted = (material: any) => { const currentPreviewVideoUrl = ref(''); +const videoCountdownSeconds = ref(0); +let videoCountdownTimer: ReturnType | null = null; + +const startVideoCountdown = () => { + if (videoCountdownTimer) { + clearInterval(videoCountdownTimer); + videoCountdownTimer = null; + } + const requiredDuration = workspace.currentViewingMaterialRequiredDuration; + if (requiredDuration && requiredDuration > 0) { + videoCountdownSeconds.value = requiredDuration * 60; + videoCountdownTimer = setInterval(() => { + if (videoCountdownSeconds.value > 0) { + videoCountdownSeconds.value--; + } else { + if (videoCountdownTimer) clearInterval(videoCountdownTimer); + } + }, 1000); + } else { + videoCountdownSeconds.value = 0; + } +}; + +const stopVideoCountdown = () => { + if (videoCountdownTimer) { + clearInterval(videoCountdownTimer); + videoCountdownTimer = null; + } +}; + const handleMaterialClick = (material: any) => { const url = material.resource?.fileUrl; if (!url) { @@ -255,18 +356,18 @@ const handleMaterialClick = (material: any) => { } if (material.resource?.fileType === 'video') { + workspace.currentViewingMaterialId = material.id; workspace.showVideoModal = true; currentPreviewVideoUrl.value = url; - // 当点击视频资料时,我们应该记录正在观看的资源ID,以便后续更新进度 - workspace.currentViewingMaterialId = material.id; + startVideoCountdown(); } else { + workspace.currentViewingMaterialId = material.id; previewFile.value = { name: material.title || material.resource?.fileName || '资料预览', url: url, actualExt: material.resource?.fileType, }; showFilePreview.value = true; - workspace.currentViewingMaterialId = material.id; } workspace.startMaterialTimer(material.id); }; @@ -281,6 +382,7 @@ const handlePreviewClose = (val: boolean) => { const handleVideoModalClose = () => { workspace.showVideoModal = false; currentPreviewVideoUrl.value = ''; + stopVideoCountdown(); workspace.stopMaterialTimer(); }; const jumpToExamQuestion = (index: number) => { @@ -858,10 +960,6 @@ const currentSafetyStageText = computed(() => { {{ $t('chat.training.safety.progressHint') }} -
-
{{ $t('chat.training.progressPercent') }}
-
{{ workspace.safetyProgressPercent }}%
-
@@ -1269,11 +1367,13 @@ const currentSafetyStageText = computed(() => { {{ $t('chat.training.hr.columns.joinDate') }} {{ $t('chat.training.hr.columns.completionDate') }} + {{ $t('chat.training.hr.columns.trainingType') }} {{ $t('chat.training.hr.columns.department') }} {{ $t('chat.training.hr.columns.name') }} {{ $t('chat.training.hr.columns.employeeId') }} {{ $t('chat.training.hr.columns.score') }} {{ $t('chat.training.hr.columns.attempts') }} + {{ $t('chat.training.hr.columns.trainingReport') }} {{ $t('chat.training.hr.columns.status') }} @@ -1281,11 +1381,18 @@ const currentSafetyStageText = computed(() => { {{ record.joinDate }} {{ record.completionDate || '--' }} + {{ record.trainingType === 'onboarding' ? $t('chat.training.hr.filters.typeOnboarding') : record.trainingType === 'safety' ? $t('chat.training.hr.filters.typeSafety') : (record.trainingType || '--') }} {{ record.department }} {{ record.name }} {{ record.employeeId }} {{ record.score ?? '--' }} {{ record.attempts }} + + + -- + {
- +
+
+ {{ videoCountdownSeconds }}s +
+ +
+
+ {{ countdownSeconds }}s +