chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

@@ -0,0 +1,128 @@
/**
* 企业培训工作台预览 harness(仅本地视觉验证用,不参与生产路由):
* 复刻 Training.vue 页头与页签切换,覆盖工作台三视图/培训计划/培训课程/
* 题库与考试/配置中心等子页,验证本次改动(模板下载、配置中心改名等)。
* 启动:npx vite --config vite.training-preview.config.ts
*/
import { createApp, computed, ref, h, defineComponent } from 'vue'
import { createPinia } from 'pinia'
import TDesign from 'tdesign-vue-next'
import 'tdesign-vue-next/dist/tdesign.css'
import '@/assets/theme/theme.css'
import '@/assets/theme/tdesign-overrides.less'
import { useAuthStore } from '@/stores/auth'
import WorkbenchPanel from '@/views/training/components/WorkbenchPanel.vue'
import PlanPanel from '@/views/training/components/PlanPanel.vue'
import CoursePanel from '@/views/training/components/CoursePanel.vue'
import StudyPanel from '@/views/training/components/StudyPanel.vue'
import RulePanel from '@/views/training/components/RulePanel.vue'
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
const HARNESS_APP = defineComponent({
setup() {
const authStore = useAuthStore()
authStore.user = {
id: 'u1',
username: '林知夏',
email: 'lin@example.com',
tenant_id: '1',
created_at: '',
updated_at: '',
} as any
// trainee = 普通员工(仅课程/个人成长);hr = 培训运营(含数据驾驶舱)
const preset = ref<'trainee' | 'hr'>('hr')
type WorkbenchView = 'course' | 'growth' | 'dashboard'
const workbenchTab = ref<WorkbenchView>('course')
// 子页:工作台 / 培训计划 / 培训课程 / 学习考试 / 配置中心
const page = ref<'workbench' | 'plan' | 'course' | 'study' | 'rules'>('workbench')
const PAGES = [
{ key: 'workbench', title: '工作台' },
{ key: 'plan', title: '培训计划' },
{ key: 'course', title: '培训课程' },
{ key: 'study', title: '学习考试' },
{ key: 'rules', title: '配置中心' },
] as const
const roles = computed(() => (preset.value === 'hr' ? ['hr'] : ['trainee']))
const canSeeDashboard = computed(() => preset.value === 'hr')
const isWorkbench = computed(() => page.value === 'workbench')
const workbenchTabs = computed(() => {
const list: { key: WorkbenchView; label: string }[] = [
{ key: 'course', label: '课程' },
{ key: 'growth', label: '个人成长' },
]
if (canSeeDashboard.value) list.push({ key: 'dashboard', label: '数据驾驶舱' })
return list
})
const meta = computed(() => {
if (isWorkbench.value) {
if (workbenchTab.value === 'course') return { title: '培训课程', desc: '课程/课件上传后自动转入课件库并智能归档' }
if (workbenchTab.value === 'growth') return { title: '工作台', desc: '个人成长进阶 · 能力模型与成就任务总览' }
return { title: '工作台', desc: '培训运营总览、待办与达成率一览' }
}
const found = PAGES.find((p) => p.key === page.value)
return { title: found?.title || '', desc: '' }
})
const panelFor = (key: typeof page.value) => {
const common = { roles: roles.value, admin: false }
switch (key) {
case 'plan': return h(PlanPanel, common)
case 'course': return h(CoursePanel, common)
case 'study': return h(StudyPanel, common)
case 'rules': return h(RulePanel, common)
default: return h(WorkbenchPanel, { ...common, tab: workbenchTab.value })
}
}
return () => h('div', { class: 'preview-page' }, [
h('div', { class: 'preview-preset' }, [
'角色视角:',
h('button', {
class: ['pv-btn', preset.value === 'trainee' ? 'on' : ''],
onClick: () => (preset.value = 'trainee'),
}, '普通员工'),
h('button', {
class: ['pv-btn', preset.value === 'hr' ? 'on' : ''],
onClick: () => (preset.value = 'hr'),
}, '人事·培训运营'),
h('span', { class: 'pv-divider' }),
'子页:',
...PAGES.map((p) => h('button', {
key: p.key,
class: ['pv-btn', page.value === p.key ? 'on' : ''],
onClick: () => (page.value = p.key),
}, p.title)),
]),
h('header', { class: 'preview-header' }, [
h('div', { class: 'preview-title-row' }, [
h('div', { class: 'preview-title-group' }, [
h('h2', {}, [h(ResourceIcon, { type: 'training', size: 24 }), ` ${meta.value.title}`]),
h('span', { class: 'pv-role-tag' }, preset.value === 'hr' ? '人事 · 培训运营' : '学员'),
]),
isWorkbench.value
? h('nav', { class: 'workbench-switch' },
workbenchTabs.value.map((t) => h('button', {
key: t.key,
type: 'button',
class: ['workbench-switch__tab', workbenchTab.value === t.key ? 'is-active' : ''],
onClick: () => (workbenchTab.value = t.key),
}, t.label)))
: null,
]),
h('p', { class: 'preview-subtitle' }, meta.value.desc),
]),
h('div', { class: 'preview-body' }, [panelFor(page.value)]),
])
},
})
const app = createApp(HARNESS_APP)
app.use(TDesign)
app.use(createPinia())
app.mount('#app')
+222
View File
@@ -0,0 +1,222 @@
/**
* 培训模块预览 harness 的接口 mock 数据与路由(仅 training-preview 本地验证用)。
* vite.training-preview.config.ts 以中间件形式拦截 /api/v1/training/*,
* 返回与后端一致的封包 { success: true, data },让培训面板无后端渲染演示数据。
*/
const NOW = new Date()
const month = (offset: number, day: number) => {
const d = new Date(NOW.getFullYear(), NOW.getMonth() + offset, day, 9, 0, 0)
return d.toISOString()
}
export const TRAINING_MOCK = {
depts: [
{ id: 'dept-a', tenant_id: 1, parent_id: '', name: '冲压车间', code: 'CY', sort: 1 },
{ id: 'dept-b', tenant_id: 1, parent_id: '', name: '技术部', code: 'JS', sort: 2 },
],
courses: [
{
id: 'c1', code: 'TR-001', name: '冲压B车间安全生产教育培训', mode: 'online', type: 'required',
lecturer_id: 'm1', hours: 0.75, credits: 1, exam_enabled: true, dept_ids: ['dept-a'],
post_scope: '全员必修', description: '', material_ids: ['mt1'], tags: ['安全'], status: 'published',
creator_id: '', created_at: month(0, 2), updated_at: month(0, 2),
},
{
id: 'c2', code: 'TR-002', name: '六轴机械手调试培训', mode: 'offline', type: 'required',
lecturer_id: 'm2', hours: 4, credits: 2, exam_enabled: false, dept_ids: ['dept-b'],
post_scope: '技术级以上', description: '', material_ids: [], tags: ['技能'], status: 'published',
creator_id: '', created_at: month(-1, 20), updated_at: month(-1, 20),
},
{
id: 'c3', code: 'TR-003', name: 'TOPGP系统培训', mode: 'online', type: 'elective',
lecturer_id: 'm1', hours: 0.5, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '', description: '', material_ids: [], tags: ['系统'], status: 'published',
creator_id: '', created_at: month(-2, 11), updated_at: month(-2, 11),
},
{
id: 'c4', code: 'TR-004', name: '产品品质培训(冲压)', mode: 'online', type: 'required',
lecturer_id: 'm1', hours: 0.67, credits: 1, exam_enabled: true, dept_ids: ['dept-a'],
post_scope: '品质岗', description: '', material_ids: ['mt2', 'mt3'], tags: ['品质'], status: 'published',
creator_id: '', created_at: month(0, 28), updated_at: month(0, 28),
},
{
id: 'c5', code: 'TR-005', name: '组装安全生产教育训练', mode: 'offline', type: 'required',
lecturer_id: 'm3', hours: 2, credits: 1, exam_enabled: false, dept_ids: ['dept-a'],
post_scope: '全员必修', description: '', material_ids: [], tags: ['安全'], status: 'published',
creator_id: '', created_at: month(0, 5), updated_at: month(0, 5),
},
{
id: 'c6', code: 'TR-006', name: '新员工入职引导', mode: 'online', type: 'required',
lecturer_id: 'm3', hours: 1, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '全员必修', description: '', material_ids: ['mt4'], tags: ['入职'], status: 'published',
creator_id: '', created_at: month(0, 30), updated_at: month(0, 30),
},
// 草稿课程:目录页仅展示已发布课程,此条应被前端过滤
{
id: 'c7', code: 'TR-007', name: '模具保养必修课(草稿)', mode: 'offline', type: 'required',
lecturer_id: 'm2', hours: 2, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '', description: '', material_ids: [], tags: [], status: 'draft',
creator_id: '', created_at: month(0, 1), updated_at: month(0, 1),
},
],
myTasks: [
{ id: 't1', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'me', deadline: month(0, 20), status: 'doing' },
{ id: 't2', course_id: 'c4', course_name: '产品品质培训(冲压)', member_id: 'me', deadline: month(0, 25), status: 'done' },
{ id: 't3', course_id: 'c6', course_name: '新员工入职引导', member_id: 'me', deadline: month(1, 10), status: 'pending' },
],
// 课程学习情况(管理端):课程+学员唯一任务行
courseLearning: [
{ id: 'cl1', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm1', employee_no: '91001', post: '培训运营工程师', dept_name: '设备部', deadline: month(0, 11), status: 'done' },
{ id: 'cl2', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm2', employee_no: '23107', post: '冲压技师', dept_name: '生产一部', deadline: month(0, 11), status: 'pending' },
{ id: 'cl3', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm3', employee_no: '24130', post: '质检员', dept_name: '品质部', deadline: month(0, 11), status: 'doing' },
{ id: 'cl4', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm4', employee_no: '24512', post: '装配技工', dept_name: '生产二部', deadline: month(-1, 20), status: 'overdue' },
],
members: [
{ id: 'm1', tenant_id: 1, user_id: 'u-m1', employee_no: '91001', dept_id: 'dept-a', post: '培训运营工程师', roles: ['hr'], lecturer_rate: 0, status: 'active' },
{ id: 'm2', tenant_id: 1, user_id: 'u-m2', employee_no: '23107', dept_id: 'dept-a', post: '冲压技师', roles: ['trainee'], lecturer_rate: 0, status: 'active' },
{ id: 'm3', tenant_id: 1, user_id: 'u-m3', employee_no: '24130', dept_id: 'dept-b', post: '质检员', roles: ['trainee'], lecturer_rate: 0, status: 'active' },
],
papers: [
{ id: 'p1', session_id: 's1', bank_id: 'b1', name: 'TPM_Bank(A卷)', total_score: 50, pass_score: 30, version: 'A', question_ids: [] },
],
examRecords: [
{ id: 'er1', paper_id: 'p1', session_id: 's1', member_id: 'm1', score: 45, submitted_at: month(0, 4), paper_name: 'TPM_Bank(A卷)', course_name: '冲压B车间安全生产教育培训', total_score: 50, pass_score: 30 },
{ id: 'er2', paper_id: 'p1', session_id: 's1', member_id: 'm2', score: 10, submitted_at: month(0, 4), paper_name: 'TPM_Bank(A卷)', course_name: '冲压B车间安全生产教育培训', total_score: 50, pass_score: 30 },
],
enrollments: [
{ id: 'e1', session_id: 's1', member_id: 'm1', status: 'completed', reason: '' },
{ id: 'e2', session_id: 's1', member_id: 'm2', status: 'enrolled', reason: '' },
{ id: 'e3', session_id: 's1', member_id: 'm3', status: 'enrolled', reason: '' },
],
signRecords: [
{ id: 'sr1', session_id: 's1', member_id: 'm1', signed_at: month(0, 4), channel: 'wecom_scan', distance_m: 12, status: 'normal', abnormal_flags: [], reviewed_by: '' },
{ id: 'sr2', session_id: 's1', member_id: 'm2', signed_at: month(0, 4), channel: 'wecom_scan', distance_m: 30, status: 'late', abnormal_flags: [], reviewed_by: '' },
],
wrongBook: [
{ id: 'w1', question_id: 'q1', stem: '冲压机双手启动按钮的作用是什么?', question_type: 'single', knowledge_point: '安全操作规范', wrong_count: 3, mastered: false },
{ id: 'w2', question_id: 'q2', stem: '模具安装前需确认哪些事项?', question_type: 'multiple', knowledge_point: '模具保养', wrong_count: 1, mastered: false },
],
profile: {
member_id: 'me', name: '林知夏', dept_name: '技术部', points: 3,
avg_score: 45, study_hours: 1.2, course_count: 3,
dimensions: [], competency: 10, pass_line: 75,
},
aiAnalysis: {
scope: 'course',
course_id: 'c1',
course_name: '冲压B车间安全生产教育培训',
stats: {
learning: { total: 4, done: 1, doing: 1, pending: 1, overdue: 1, completion_rate: 25 },
exam: { expected: 4, taken: 2, passed: 1, failed: 1, avg_score: 27.5, pass_rate: 50 },
sign: { expected: 3, signed: 2, late: 1, absent: 1, abnormal: 0 },
wrong_questions: [
{ knowledge_point: '安全操作规范', wrong_count: 3, error_rate: 0.5 },
{ knowledge_point: '模具保养', wrong_count: 1, error_rate: 0.33 },
],
},
analysis: [
'## 总体评价',
'',
'当前课程整体完成率 25%,明显偏低;考试及格率 50%,平均分 27.5 分,掌握情况不理想。',
'',
'## 学习情况',
'',
'- 共 4 项学习任务:已完成 1、学习中 1、待学习 1、**已逾期 1**,需优先催办逾期任务。',
'',
'## 考试情况',
'',
'- 应考 4 人,已考 2 人,及格 1 人;「安全操作规范」知识点错误率达 50%,建议集中补训。',
'',
'## 改进建议',
'',
'1. 对逾期学员逐人催办,并同步课长督办;',
'2. 组织未考学员安排补考,确保应考尽考;',
'3. 针对「安全操作规范」安排一次 30 分钟集中补训并二次考试。',
].join('\n'),
model_name: 'glm-4-plus',
generated_at: '',
},
sessions: [
{ id: 's1', course_id: 'c2', month_plan_id: '', year: NOW.getFullYear(), month: NOW.getMonth() + 1, start_at: month(1, 12), end_at: month(1, 12), location: '3号厂房 · 二楼培训室', online_url: '', capacity: 0, lecturer_id: 'm2', status: 'scheduled' },
{ id: 's2', course_id: 'c2', month_plan_id: '', year: NOW.getFullYear() - 1, month: 12, start_at: month(-2, 8), end_at: month(-2, 8), location: '技术部实训区', online_url: '', capacity: 0, lecturer_id: 'm2', status: 'finished' },
{ id: 's3', course_id: 'c5', month_plan_id: '', year: NOW.getFullYear() - 1, month: 10, start_at: month(-1, 15), end_at: month(-1, 15), location: '一楼展厅', online_url: '', capacity: 0, lecturer_id: 'm3', status: 'finished' },
],
hrDashboard: {
demand_progress: [
{ dept_id: 'dept-a', dept_name: '冲压车间', total: 8, done: 5, percent: 62 },
{ dept_id: 'dept-b', dept_name: '技术部', total: 6, done: 4, percent: 66 },
],
pending_demands: [
{ id: 'd1', course_name: '叉车年度复训', check_status: 'pending' },
{ id: 'd2', course_name: '品质工具(APQP)专题', check_status: 'passed' },
],
course_total: 12,
course_online: 8,
course_offline: 4,
month_completion: { percent: 46, completed: 12, total: 26 },
month_sessions: [{ id: 's1' }, { id: 's9' }],
},
}
// 配置中心 · 导入模板元数据(harness 固定展示内置默认;上传/删除不落库,刷新即还原)
const TEMPLATE_METAS = [
{
template_key: 'demand_collection',
file_name: '教育训练需求表模板.xlsx',
file_size: 7369,
updated_at: '',
updated_by: '',
source: 'default',
},
{
template_key: 'question_bank',
file_name: '部门培训课程试题(题库导入版)模板.xlsx',
file_size: 29405,
updated_at: '',
updated_by: '',
source: 'default',
},
]
// 返回 { matched, body };未匹配返回 null 由 vite 放行
export function resolveTrainingMock(method: string, url: string): { status: number; body: unknown } | null {
const ok = (data: unknown) => ({ status: 200, body: { success: true, data } })
if (!url.startsWith('/api/v1/training/')) return null
// 模板二进制下载由 vite 配置里的中间件直接回文件,不经过本函数
if (url === '/api/v1/training/templates' || url.endsWith('/templates')) {
if (method === 'GET') return ok(TEMPLATE_METAS)
return ok(TEMPLATE_METAS[0])
}
if (method === 'GET') {
if (url.includes('/depts')) return ok(TRAINING_MOCK.depts)
// 学习任务:/learning-tasks/all 为管理端课程学习情况,须先于 /learning-tasks 匹配
if (url.includes('/learning-tasks/all')) return ok(TRAINING_MOCK.courseLearning)
if (url.includes('/learning-tasks')) return ok(TRAINING_MOCK.myTasks)
if (url.includes('/ai-analysis')) {
return ok({ ...TRAINING_MOCK.aiAnalysis, generated_at: new Date().toISOString() })
}
// 考试:/exam-records/my-list、/exam-records/my 须先于 /exam-records 匹配
if (url.includes('/exam-records/my-list')) return ok(TRAINING_MOCK.examRecords)
if (url.includes('/exam-records/my')) return ok({ record: TRAINING_MOCK.examRecords[0], passed: true })
if (url.includes('/exam-records')) return ok(TRAINING_MOCK.examRecords)
if (url.includes('/wrong-book')) return ok(TRAINING_MOCK.wrongBook)
if (url.includes('/profile/me')) return ok(TRAINING_MOCK.profile)
if (url.includes('/enrollments')) return ok(TRAINING_MOCK.enrollments)
if (url.includes('/sign-records')) return ok(TRAINING_MOCK.signRecords)
if (url.includes('/papers')) return ok(TRAINING_MOCK.papers)
if (url.includes('/question-banks')) return ok({ items: [], total: 0 })
// 我的档案(/members/me)须先于成员列表(/members)匹配
if (url.includes('/members/me')) {
return ok({ id: 'me', tenant_id: 1, user_id: 'u1', employee_no: 'A1024', dept_id: 'dept-b', post: '高级产品经理', roles: ['trainee'], lecturer_rate: 0, status: 'active' })
}
if (url.includes('/members')) return ok({ items: TRAINING_MOCK.members, total: TRAINING_MOCK.members.length })
if (url.includes('/dashboards/hr')) return ok(TRAINING_MOCK.hrDashboard)
if (url.includes('/dashboards')) return ok({})
if (url.includes('/courses')) return ok({ items: TRAINING_MOCK.courses, total: TRAINING_MOCK.courses.length })
if (url.includes('/sessions')) return ok(TRAINING_MOCK.sessions)
return ok(null)
}
// POST(快速建课/发布/课件登记)统一回成功
return ok({ id: `c-new-${Date.now()}` })
}
+74
View File
@@ -0,0 +1,74 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import type { TestContext } from 'node:test'
import { runInNewContext } from 'node:vm'
import { compileScript, parse } from '@vue/compiler-sfc'
import * as vue from 'vue'
import ts from 'typescript'
export function change(operation: string, ids: Record<string, string[]> = {}) {
return { operation, area: operation.split('.')[0], ids }
}
export async function flush() {
await new Promise<void>(resolve => setImmediate(resolve))
await vue.nextTick()
}
export function fixture(t: TestContext) {
t.mock.timers.enable({ apis: ['setTimeout'] })
const window = Object.assign(new EventTarget(), { innerHeight: 900, innerWidth: 1200, setTimeout, clearTimeout })
const storage = { getItem: () => null, setItem() {}, removeItem() {} }
const globals = {
window, CustomEvent, setTimeout, clearTimeout, setInterval, clearInterval,
localStorage: storage, sessionStorage: storage,
requestAnimationFrame: (callback: () => void) => setTimeout(callback, 16),
document: { documentElement: { clientHeight: 900 }, querySelector: () => null },
}
function evaluate(source: string, dependencies: Record<string, unknown>, fallback?: (name: string) => unknown) {
const exports: any = {}
runInNewContext(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText, {
exports, console, ...globals,
require(name: string) {
if (name in dependencies) return dependencies[name]
if (fallback) return fallback(name)
throw new Error(`Unexpected dependency: ${name}`)
},
})
return exports
}
const dataChange = evaluate(readFileSync(new URL('../utils/assistantDataChange.ts', import.meta.url), 'utf8'), { vue })
const renderer = vue.createRenderer<object, object>({
createElement: () => ({}), createText: () => ({}), createComment: () => ({}),
insert() {}, remove() {}, setElementText() {}, setText() {}, patchProp() {},
parentNode: () => null, nextSibling: () => null,
})
function mount(component: any, props = {}) {
component.render = () => null
const app = renderer.createApp(component, props)
const vm: any = app.mount({})
let mounted = true
const close = () => { if (mounted) { mounted = false; app.unmount() } }
t.after(close)
return { vm, close }
}
function component(file: URL, dependencies: Record<string, unknown>, props = {}) {
const { descriptor } = parse(readFileSync(file, 'utf8'), { filename: file.pathname })
const script = compileScript(descriptor, { id: 'assistant-refresh-test' }).content
.replace('__expose();', '')
.replace('return __returned__', '__expose(__returned__); return __returned__')
const require = createRequire(file)
const compiled = evaluate(script, {
vue, '@/utils/assistantDataChange': dataChange, ...dependencies,
}, name => {
if (name.endsWith('.vue')) return { default: {} }
if (name.startsWith('.')) return require(name)
assert.fail(`Unexpected component dependency: ${name}`)
})
return mount(compiled.default, props)
}
return { window, evaluate, mount, component, dataChange, emit: dataChange.emitAssistantDataChange }
}