Files
ai_academy/frontend/vite.training-preview.config.ts
runny 242dd7e1a6 feat(training): 企业培训迭代:核验权限收窄、课程发布状态与培训中心改版
需求域:
- 需求导入修复内/外培训与外部讲师落库;按模板标题年入库(年-月一致)
- 核验确认收窄为「需求归属部门+经理职称角色」,越权提示联系部门经理
- 确认转月计划后自动推送讲师/课长维护;导入后自动推送部门经理核验(站内+企微)

课程域:
- 课程管理发布状态字段(迁移000154)+发布/下线;培训中心「和信课程」目录
- 需求讲师改选后回写课程管理;确认同步带出适合人员/课件/试题
- 月计划详情课件/试题更换(上传/知识库选择/题库换绑)回写课程管理,
  无关联条目的存量计划自动创建课程条目

模板与表单:
- 教育训练需求表:适合人员/内-外培训口径;部门联动课程下拉;
  适合人员/讲师按所选课程自动带出;在线提报课程下拉(本部门)自动带出分类/讲师/适合人员

页面与权限:
- 培训中心页签重组(和信课程/我的培训/我的考试),移除线上/线下页签
- 数据驾驶舱迁侧栏(职称角色之下);职称角色迁至更多工具配置中心之后
- 配置中心/职称角色对经理开放;页签「职称角色」更名「角色权限」
- 修复年度下拉空白(TDesign options 需对象数组)、月计划列表地点兜底

其他: 培训预览端口修正与 dev:training 脚本;tmp-extract-duckdb 加入 gitignore
2026-11-19 01:49:17 +08:00

73 lines
3.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 培训工作台本地预览配置:在主配置基础上用中间件 mock /api/v1/training/*,
// 供 training-preview.html 无后端渲染培训面板(仅本地验证用,不影响构建)。
import { fileURLToPath, URL } from 'node:url'
import { readFileSync } from 'node:fs'
import { defineConfig, mergeConfig, type Plugin } from 'vite'
import baseConfig from './vite.config'
import { resolveTrainingMock } from './src/test-utils/trainingMockApi'
// 模板二进制:harness 下用仓库内置资产文件模拟后端下载接口
const TEMPLATE_FILES: Record<string, { file: URL; type: string }> = {
demand_collection: {
file: new URL('../internal/assets/trainingtemplates/demand_collection.xlsx', import.meta.url),
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
question_bank: {
file: new URL('../internal/assets/trainingtemplates/question_bank.xlsx', import.meta.url),
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
}
// 拦截培训域接口,返回与后端一致的 { success, data } 封包
function trainingPreviewMockApi(): Plugin {
return {
name: 'training-preview-mock-api',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const raw = req.url || ''
const path = raw.split('?')[0]
// 拦截培训域与知识库文档列表(课程管理「从知识库选择课件」演示数据)
if (path.startsWith('/api/v1/training/') || path.startsWith('/api/v1/knowledge-bases/')) {
// 模板文件下载:直接回真实 Excel 二进制
const fileMatch = path.match(/^\/api\/v1\/training\/templates\/(demand_collection|question_bank)\/file$/)
if (req.method === 'GET' && fileMatch) {
const entry = TEMPLATE_FILES[fileMatch[1]]
try {
const buf = readFileSync(fileURLToPath(entry.file))
res.statusCode = 200
res.setHeader('Content-Type', entry.type)
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(fileMatch[1] === 'demand_collection' ? '年度教育培训收集模板.xlsx' : '部门培训课程试题(题库导入版)模板.xlsx')}`)
res.end(buf)
return
} catch {
res.statusCode = 404
res.end(JSON.stringify({ success: false, message: 'template asset missing' }))
return
}
}
const hit = resolveTrainingMock(req.method || 'GET', path)
if (hit) {
res.statusCode = hit.status
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(JSON.stringify(hit.body))
return
}
}
next()
})
},
}
}
// mergeConfig(base, override):第二参优先——mock 插件与端口覆盖必须放在
// baseConfig 之后,否则 server.port 会被 base 的 5173 覆盖,预览落错端口。
export default mergeConfig(
baseConfig,
defineConfig({
plugins: [trainingPreviewMockApi()],
server: {
port: 5175,
},
}),
)