需求域: - 需求导入修复内/外培训与外部讲师落库;按模板标题年入库(年-月一致) - 核验确认收窄为「需求归属部门+经理职称角色」,越权提示联系部门经理 - 确认转月计划后自动推送讲师/课长维护;导入后自动推送部门经理核验(站内+企微) 课程域: - 课程管理发布状态字段(迁移000154)+发布/下线;培训中心「和信课程」目录 - 需求讲师改选后回写课程管理;确认同步带出适合人员/课件/试题 - 月计划详情课件/试题更换(上传/知识库选择/题库换绑)回写课程管理, 无关联条目的存量计划自动创建课程条目 模板与表单: - 教育训练需求表:适合人员/内-外培训口径;部门联动课程下拉; 适合人员/讲师按所选课程自动带出;在线提报课程下拉(本部门)自动带出分类/讲师/适合人员 页面与权限: - 培训中心页签重组(和信课程/我的培训/我的考试),移除线上/线下页签 - 数据驾驶舱迁侧栏(职称角色之下);职称角色迁至更多工具配置中心之后 - 配置中心/职称角色对经理开放;页签「职称角色」更名「角色权限」 - 修复年度下拉空白(TDesign options 需对象数组)、月计划列表地点兜底 其他: 培训预览端口修正与 dev:training 脚本;tmp-extract-duckdb 加入 gitignore
1759 lines
71 KiB
Vue
1759 lines
71 KiB
Vue
<template>
|
||
<div class="course-panel">
|
||
<div class="panel-box">
|
||
<div class="panel-box__header">
|
||
<span class="panel-box__title">月度培训计划</span>
|
||
<div class="panel-box__actions">
|
||
<t-button theme="primary" @click="openCreate('offline')">创建线下计划</t-button>
|
||
<t-button variant="outline" @click="openCreate('online')">创建线上计划</t-button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 查询条件:名称/讲师/培训时间范围/状态。计划列表全量加载(page_size=100),
|
||
企业内部数据量小,过滤在前端本地完成,不新增后端查询参数。 -->
|
||
<div class="course-filters">
|
||
<t-input v-model="filters.keyword" placeholder="按计划名称查询" clearable style="width: 200px" />
|
||
<t-select v-if="!isLecturerOnly" v-model="filters.lecturerId" placeholder="按讲师查询" clearable style="width: 150px">
|
||
<t-option v-for="l in lecturers" :key="l.id" :value="l.id" :label="l.name" />
|
||
</t-select>
|
||
<t-date-range-picker
|
||
v-model="filters.teachRange"
|
||
format="YYYY-MM-DD"
|
||
separator="至"
|
||
clearable
|
||
:placeholder="['按开始日期', '按结束日期']"
|
||
style="width: 260px"
|
||
/>
|
||
<t-select v-model="filters.status" placeholder="按状态查询" clearable style="width: 130px">
|
||
<t-option v-for="opt in STATUS_OPTIONS" :key="opt.value" :value="opt.value" :label="opt.label" />
|
||
</t-select>
|
||
<t-button variant="text" theme="primary" size="small" @click="resetFilters">重置</t-button>
|
||
<span class="course-filter-count">共 {{ filteredCourses.length }} 门</span>
|
||
</div>
|
||
|
||
<t-table :data="filteredCourses" :columns="courseColumns" row-key="id" size="small" :loading="loading">
|
||
<template #plan_code="{ row }">{{ row.plan_code || '-' }}</template>
|
||
<template #name="{ row }">
|
||
<span class="course-name-link clamp-2" title="点击前往培训签到" @click="goSignTab(row)">{{ row.name }}</span>
|
||
</template>
|
||
<template #mode="{ row }">
|
||
<t-tag :theme="row.mode === 'online' ? 'primary' : 'default'" variant="light" size="small" :class="{ 'course-tag-offline': row.mode !== 'online' }">
|
||
{{ row.mode === 'online' ? '线上' : '线下' }}
|
||
</t-tag>
|
||
</template>
|
||
<template #type="{ row }">{{ typeText(row.type) }}</template>
|
||
<template #reporter="{ row }"><span class="clamp-2">{{ row.reporter_dept_name || '-' }}</span></template>
|
||
<template #teachTime="{ row }"><span class="clamp-2">{{ teachTimeText(row) }}</span></template>
|
||
<template #plannedTime="{ row }"><span class="clamp-2">{{ row.planned_time || '-' }}</span></template>
|
||
<template #lecturer="{ row }">{{ lectNameMap[row.lecturer_id] || row.lecturer_name || row.lecturer_external || '-' }}</template>
|
||
<template #location="{ row }"><span class="clamp-2">{{ courseLocation(row) || '-' }}</span></template>
|
||
<template #expected="{ row }">{{ row.actual_count ?? 0 }}/{{ row.expected_count ?? 0 }} 人</template>
|
||
<template #learnStatus="{ row }">
|
||
<t-tag
|
||
:theme="learnStatusTheme(row.learning_status)"
|
||
variant="light" size="small" class="status-link"
|
||
@click="goStudyStatus(row, 'learning')"
|
||
>{{ learnStatusText(row.learning_status) }}</t-tag>
|
||
</template>
|
||
<template #examStatus="{ row }">
|
||
<t-tag
|
||
:theme="examStatusTheme(row.exam_status)"
|
||
variant="light" size="small" class="status-link"
|
||
@click="goStudyStatus(row, 'exam')"
|
||
>{{ examStatusText(row.exam_status) }}</t-tag>
|
||
</template>
|
||
<template #status="{ row }">
|
||
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
||
</template>
|
||
<template #op="{ row }">
|
||
<t-button
|
||
v-if="canManage && row.status !== 'published'"
|
||
variant="text" theme="primary" size="small" :disabled="saving"
|
||
@click="onPublish(row)"
|
||
>发布</t-button>
|
||
<t-button variant="text" size="small" @click="openDetail(row)">详情</t-button>
|
||
<t-button variant="text" size="small" @click="openChangeLogs(row)">记录</t-button>
|
||
<t-button v-if="canManage" variant="text" theme="danger" size="small" @click="onDelete(row)">删除</t-button>
|
||
</template>
|
||
</t-table>
|
||
</div>
|
||
|
||
<!-- 创建计划:课程名称从课程管理选择(带出并锁定课程信息),仅维护授课安排六字段 -->
|
||
<t-dialog v-model:visible="formVisible" :header="form.mode === 'online' ? '创建线上计划' : '创建线下计划'" width="720">
|
||
<t-form label-width="100">
|
||
<t-form-item label="计划编号">
|
||
<t-input value="保存后自动生成" disabled />
|
||
</t-form-item>
|
||
<t-form-item label="课程名称" required>
|
||
<!-- 关联课程管理:从课程管理选择课程,带出类型/形式/讲师/所属部门并锁定(新课程请先在「课程管理」维护) -->
|
||
<t-select
|
||
v-model="form.library_course_id"
|
||
clearable
|
||
filterable
|
||
placeholder="从课程管理选择课程"
|
||
style="width: 100%"
|
||
@change="onLibraryCourseChange"
|
||
>
|
||
<t-option v-for="c in libraryCourses" :key="c.id" :value="c.id" :label="`${c.name}${c.category ? `(${c.category})` : ''}`" />
|
||
</t-select>
|
||
<div class="bank-hint">选择后带出课程信息且不可修改,仅可调整下方授课安排;还没有课程?<a class="template-link" href="javascript:void(0)" @click.prevent="goLibrary">前往「课程管理」新增</a></div>
|
||
</t-form-item>
|
||
<t-form-item label="类型">
|
||
<t-input :value="formTypeDisplay" disabled />
|
||
</t-form-item>
|
||
<t-form-item label="讲师">
|
||
<t-input :value="lecturerDisplay(form.lecturer_id)" disabled placeholder="随课程带出,在「课程管理」中维护" />
|
||
</t-form-item>
|
||
<t-form-item label="所属部门">
|
||
<t-input :value="deptNamesOf(form.dept_ids)" disabled placeholder="随课程带出" />
|
||
</t-form-item>
|
||
<!-- 课程资产侧信息随所选课程带出(000156):只读展示;维护入口见详情弹窗「更换」或课程管理 -->
|
||
<t-form-item label="适合人员">
|
||
<t-input :value="formLibraryCourse?.suitable_members || '-'" disabled placeholder="随所选课程带出" />
|
||
</t-form-item>
|
||
<t-form-item label="课件">
|
||
<t-input :value="formLibraryCourse?.material_name || formLibraryCourse?.file_name || '-'" disabled placeholder="随所选课程带出" />
|
||
</t-form-item>
|
||
<t-form-item label="试题">
|
||
<t-input :value="formCourseBanksText" disabled placeholder="随所选课程带出" />
|
||
</t-form-item>
|
||
<t-form-item label="学时 / 学分">
|
||
<t-input-number v-model="form.hours" :min="0" :step="0.5" :disabled="!form.library_course_id" style="width: 48%" />
|
||
<t-input-number v-model="form.credits" :min="0" :step="0.5" :disabled="!form.library_course_id" style="width: 48%; margin-left: 4%" />
|
||
</t-form-item>
|
||
<t-form-item v-if="form.mode === 'offline'" label="授课时间">
|
||
<!-- format 同时决定输入显示与时间面板列数(只出时:分,不出秒) -->
|
||
<t-date-picker v-model="form.start_at" enable-time-picker format="YYYY-MM-DD HH:mm" style="width: 100%" />
|
||
</t-form-item>
|
||
<t-form-item v-if="form.mode === 'offline'" label="授课地点">
|
||
<t-input v-model="form.location" placeholder="如:3号厂房 · 二楼培训室" />
|
||
</t-form-item>
|
||
<t-form-item v-if="form.mode === 'offline'" label="学员通知">
|
||
<t-select v-model="form.notify_mode" style="width: 100%">
|
||
<t-option value="immediate" label="名单/课件就绪后立即推送" />
|
||
<t-option value="day_before" label="开课前 1 天推送" />
|
||
</t-select>
|
||
<div class="bank-hint">推送内容:上课时间、地点与讲师;课件未上传时不会推送,上传后自动补推。</div>
|
||
</t-form-item>
|
||
<t-form-item v-if="form.mode === 'online'" label="学习期限">
|
||
<t-select v-model="form.deadlineDays" style="width: 100%">
|
||
<t-option :value="7" label="发布后 7 天内完成" />
|
||
<t-option :value="14" label="发布后 14 天内完成" />
|
||
<t-option :value="30" label="发布后 30 天内完成" />
|
||
</t-select>
|
||
</t-form-item>
|
||
<!-- 参加人员:按人员/部门/岗位三种方式选择,保存写入场次学员名单并同步 post_scope -->
|
||
<t-form-item label="参加人员">
|
||
<div style="width: 100%">
|
||
<t-radio-group v-model="formParticipantMode" variant="default-filled" size="small" class="participant-mode">
|
||
<t-radio-button value="member">按人员</t-radio-button>
|
||
<t-radio-button value="dept">按部门</t-radio-button>
|
||
<t-radio-button value="post">按岗位</t-radio-button>
|
||
</t-radio-group>
|
||
<t-select
|
||
v-if="formParticipantMode === 'member'"
|
||
v-model="formParticipantIds"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
placeholder="从员工名册选择参加人员"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="m in members" :key="m.id" :value="m.id" :label="m.user_name || m.employee_no" />
|
||
</t-select>
|
||
<t-select
|
||
v-else-if="formParticipantMode === 'dept'"
|
||
v-model="formParticipantDeptIds"
|
||
multiple
|
||
clearable
|
||
placeholder="选择部门,自动带入部门全部员工"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
|
||
</t-select>
|
||
<t-select
|
||
v-else
|
||
v-model="formParticipantPostIds"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
placeholder="选择岗位,自动带入该岗位全部员工"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="p in postOptions" :key="p" :value="p" :label="p" />
|
||
</t-select>
|
||
<div class="form-hint">
|
||
已选 {{ resolvedFormMembers.length }} 名员工<template v-if="resolvedFormMembers.length">:{{ resolvedFormMembers.map((m) => m.user_name || m.employee_no).join('、') }}</template>;推送与应培人员以本名单为准
|
||
</div>
|
||
</div>
|
||
</t-form-item>
|
||
</t-form>
|
||
<div class="form-hint">发布后将自动生成计划与学员名单(线下计划含签到码),并推送讲师与学员通知;适合人员/课件/试题随所选课程自动带出,详情弹窗可更换(自动同步课程管理),选择课程时自动带出。</div>
|
||
<template #footer>
|
||
<t-button variant="outline" @click="formVisible = false">暂存草稿</t-button>
|
||
<t-button theme="primary" :loading="saving" @click="onSave">保存并发布</t-button>
|
||
</template>
|
||
</t-dialog>
|
||
|
||
<!-- 计划详情:计划编号展示 + 课程名称(课程管理选择,信息锁定) + 六项授课安排维护 -->
|
||
<t-dialog v-model:visible="sessionsVisible" :header="`计划详情 · ${activeCourse?.name || ''}`" width="760" :footer="false">
|
||
<t-form label-width="90" class="detail-form">
|
||
<t-form-item label="计划编号">
|
||
<t-input :value="activeCourse?.plan_code || '-'" disabled />
|
||
</t-form-item>
|
||
<t-form-item label="课程名称">
|
||
<!-- 未关联课程管理的计划可选定课程(选定后信息锁定);已关联直接锁定展示 -->
|
||
<t-select
|
||
v-if="!activeCourse?.library_course_id"
|
||
v-model="editForm.library_course_id"
|
||
:disabled="!canManage"
|
||
clearable
|
||
filterable
|
||
placeholder="从课程管理选择课程(带出课程信息)"
|
||
style="width: 100%"
|
||
@change="onDetailLibraryCourseChange"
|
||
>
|
||
<t-option v-for="c in libraryCourses" :key="c.id" :value="c.id" :label="`${c.name}${c.category ? `(${c.category})` : ''}`" />
|
||
</t-select>
|
||
<t-input v-else :value="editForm.name" disabled />
|
||
</t-form-item>
|
||
<t-form-item label="类型">
|
||
<t-input :value="formTypeDisplay" disabled />
|
||
</t-form-item>
|
||
<t-form-item label="讲师">
|
||
<t-input :value="lecturerDisplay(editForm.lecturer_id)" disabled placeholder="随课程带出" />
|
||
</t-form-item>
|
||
<t-form-item label="所属部门">
|
||
<t-input :value="deptNamesOf(editForm.dept_ids)" disabled placeholder="随课程带出" />
|
||
</t-form-item>
|
||
<t-form-item label="学时 / 学分">
|
||
<t-input-number v-model="editForm.hours" :min="0" :step="0.5" :disabled="!canManage" style="width: 48%" />
|
||
<t-input-number v-model="editForm.credits" :min="0" :step="0.5" :disabled="!canManage" style="width: 48%; margin-left: 4%" />
|
||
</t-form-item>
|
||
<template v-if="editForm.mode === 'offline'">
|
||
<t-form-item label="授课时间">
|
||
<t-date-picker v-model="editForm.start_at" enable-time-picker format="YYYY-MM-DD HH:mm" :disabled="!canManage" style="width: 100%" />
|
||
</t-form-item>
|
||
<t-form-item label="授课地点">
|
||
<t-input v-model="editForm.location" :disabled="!canManage" placeholder="如:3号厂房 · 二楼培训室" />
|
||
</t-form-item>
|
||
<t-form-item label="学员通知">
|
||
<t-select v-model="editForm.notify_mode" :disabled="!canManage" style="width: 100%">
|
||
<t-option value="immediate" label="名单/课件就绪后立即推送" />
|
||
<t-option value="day_before" label="开课前 1 天推送" />
|
||
</t-select>
|
||
</t-form-item>
|
||
</template>
|
||
<t-form-item v-else label="授课时间">
|
||
<t-input value="长期(线上计划随时可学)" disabled />
|
||
</t-form-item>
|
||
<!-- 参加人员与场次学员名单合一:按人员/部门/岗位三种方式选择,保存后写入场次学员名单(计入应到人数) -->
|
||
<t-form-item label="参加人员">
|
||
<div style="width: 100%">
|
||
<t-radio-group v-model="participantMode" variant="default-filled" size="small" class="participant-mode">
|
||
<t-radio-button value="member">按人员</t-radio-button>
|
||
<t-radio-button value="dept">按部门</t-radio-button>
|
||
<t-radio-button value="post">按岗位</t-radio-button>
|
||
</t-radio-group>
|
||
<t-select
|
||
v-if="participantMode === 'member'"
|
||
v-model="demandSync.participantIds"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
:disabled="!canManage"
|
||
placeholder="从员工名册选择参加人员"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="m in members" :key="m.id" :value="m.id" :label="m.user_name || m.employee_no" />
|
||
</t-select>
|
||
<t-select
|
||
v-else-if="participantMode === 'dept'"
|
||
v-model="participantDeptIds"
|
||
multiple
|
||
clearable
|
||
:disabled="!canManage"
|
||
placeholder="选择部门,自动带入部门全部员工"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
|
||
</t-select>
|
||
<t-select
|
||
v-else
|
||
v-model="participantPostIds"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
:disabled="!canManage"
|
||
placeholder="选择岗位,自动带入该岗位全部员工"
|
||
style="width: 100%"
|
||
>
|
||
<t-option v-for="p in postOptions" :key="p" :value="p" :label="p" />
|
||
</t-select>
|
||
<div class="form-hint">
|
||
已选 {{ resolvedParticipantMembers.length }} 名员工<template v-if="resolvedParticipantMembers.length">:{{ resolvedParticipantMembers.map((m) => m.user_name || m.employee_no).join('、') }}</template>;推送与应培人员以本名单为准
|
||
</div>
|
||
</div>
|
||
</t-form-item>
|
||
<!-- 其余同步字段:有值才回显,只读展示 -->
|
||
<t-form-item v-if="activeCourse?.lecturer_external" label="外部讲师">
|
||
<t-input :value="activeCourse.lecturer_external" disabled placeholder="来自需求确认同步" />
|
||
</t-form-item>
|
||
<t-form-item v-if="activeCourse?.train_type" label="内/外培训">
|
||
<t-input :value="activeCourse.train_type" disabled placeholder="来自需求确认同步" />
|
||
</t-form-item>
|
||
<t-form-item v-if="activeCourse?.plant" label="厂区">
|
||
<t-input :value="activeCourse.plant" disabled placeholder="来自需求确认同步" />
|
||
</t-form-item>
|
||
<!-- 课程资产侧信息(000156):随所选课程带出;课件/试题支持更换,更换后回写课程管理对应课程 -->
|
||
<t-form-item label="适合人员">
|
||
<t-input :value="activeLibraryCourse?.suitable_members || '-'" disabled placeholder="随所选课程带出(课程管理维护)" />
|
||
</t-form-item>
|
||
<t-form-item label="课件">
|
||
<div class="asset-row">
|
||
<t-input
|
||
:value="activeLibraryCourse?.material_name || activeLibraryCourse?.file_name || '-'"
|
||
disabled
|
||
placeholder="随所选课程带出(课程管理维护)"
|
||
class="asset-value"
|
||
/>
|
||
<t-button
|
||
v-if="canManage"
|
||
variant="outline" size="small" :loading="assetSaving"
|
||
@click="materialInput?.click()"
|
||
>上传课件</t-button>
|
||
<t-button
|
||
v-if="canManage"
|
||
variant="outline" size="small" :disabled="assetSaving"
|
||
@click="openKbCourseware"
|
||
>知识库</t-button>
|
||
<input
|
||
ref="materialInput"
|
||
type="file"
|
||
class="hidden-file-input"
|
||
@change="onChangeMaterial"
|
||
/>
|
||
</div>
|
||
<div v-if="kbCoursewareVisible" class="asset-relink">
|
||
<t-select
|
||
v-model="kbCoursewareDocId"
|
||
filterable
|
||
clearable
|
||
:loading="kbDocsLoading"
|
||
placeholder="选择「企业培训(课件)」知识库文档作为课件"
|
||
style="flex: 1"
|
||
>
|
||
<t-option v-for="doc in kbCoursewareDocs" :key="doc.id" :value="doc.id" :label="doc.file_name" />
|
||
</t-select>
|
||
<t-button theme="primary" size="small" :loading="assetSaving" :disabled="!kbCoursewareDocId" @click="onAttachKbCourseware">确定</t-button>
|
||
</div>
|
||
</t-form-item>
|
||
<t-form-item label="试题">
|
||
<div class="asset-row">
|
||
<t-input
|
||
:value="courseBanksText"
|
||
disabled
|
||
placeholder="随所选课程带出(课程管理维护)"
|
||
class="asset-value"
|
||
/>
|
||
<t-button
|
||
v-if="canManage"
|
||
variant="outline" size="small" :disabled="assetSaving"
|
||
@click="relinkVisible = !relinkVisible"
|
||
>更换试题</t-button>
|
||
<t-button
|
||
v-if="canManage"
|
||
variant="outline" size="small" :disabled="assetSaving"
|
||
@click="openKbBank"
|
||
>知识库</t-button>
|
||
</div>
|
||
<div v-if="relinkVisible" class="asset-relink">
|
||
<t-select
|
||
v-model="relinkBankId"
|
||
filterable
|
||
clearable
|
||
placeholder="选择题库替换该课程当前试题"
|
||
style="flex: 1"
|
||
>
|
||
<t-option
|
||
v-for="b in allBanks"
|
||
:key="b.id"
|
||
:value="b.id"
|
||
:label="`${b.name}(${b.question_count}题)`"
|
||
/>
|
||
</t-select>
|
||
<t-button theme="primary" size="small" :loading="assetSaving" :disabled="!relinkBankId" @click="onRelinkBank">确认更换</t-button>
|
||
</div>
|
||
<div v-if="kbBankVisible" class="asset-relink">
|
||
<t-select
|
||
v-model="kbBankDocId"
|
||
filterable
|
||
clearable
|
||
:loading="kbDocsLoading"
|
||
placeholder="选择「企业培训(题库)」知识库文档解析建题库"
|
||
style="flex: 1"
|
||
>
|
||
<t-option v-for="doc in kbBankDocs" :key="doc.id" :value="doc.id" :label="doc.file_name" />
|
||
</t-select>
|
||
<t-button theme="primary" size="small" :loading="assetSaving" :disabled="!kbBankDocId" @click="onImportKbBank">确定</t-button>
|
||
</div>
|
||
</t-form-item>
|
||
<t-form-item v-if="activeCourse?.remark" label="备注">
|
||
<t-textarea :value="activeCourse.remark" disabled placeholder="来自需求确认同步" :autosize="{ minRows: 1 }" />
|
||
</t-form-item>
|
||
</t-form>
|
||
|
||
<!-- 保存计划信息:统一提交授课安排六字段(课件与试题在「课程管理」维护) -->
|
||
<div v-if="canManage" class="detail-save-bar">
|
||
<t-button theme="primary" :loading="detailSaving" @click="onSaveDetail">保存计划信息</t-button>
|
||
<span class="form-hint detail-save-hint">提交授课时间/地点/通知方式/参加人员/学时/学分;每次保存自动记录修改版本(列表「记录」查看),授课时间修改将同步最近一场排期,参加人员保存后同步为场次学员名单;课件与试题可在此「更换」,更换后自动同步课程管理</span>
|
||
</div>
|
||
</t-dialog>
|
||
|
||
<!-- 计划修改记录:每次保存的版本与字段级变更明细 -->
|
||
<t-dialog v-model:visible="changeLogsVisible" :header="`计划修改记录 · ${changeLogCourse?.name || ''}`" width="640" :footer="false">
|
||
<t-table :data="changeLogs" :columns="changeLogColumns" row-key="id" size="small" :loading="changeLogsLoading">
|
||
<template #changes="{ row }">
|
||
<div v-for="(c, idx) in row.changes || []" :key="idx" class="change-line">
|
||
{{ c.label }}:{{ c.old || '—' }} → {{ c.new || '—' }}
|
||
</div>
|
||
</template>
|
||
<template #operator="{ row }">{{ operatorName(row.operator_id) }}</template>
|
||
<template #created_at="{ row }">{{ fmtTime(row.created_at) }}</template>
|
||
</t-table>
|
||
<t-empty v-if="!changeLogsLoading && !changeLogs.length" description="暂无修改记录;计划信息每次保存后自动留痕" />
|
||
</t-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { MessagePlugin } from 'tdesign-vue-next'
|
||
import {
|
||
attachCourseLibraryMaterialFromKb,
|
||
deleteCourse,
|
||
getTrainingKnowledgeBases,
|
||
importQuestionBankFromKnowledge,
|
||
linkLibraryCourseQuestionBank,
|
||
listCourseChangeLogs,
|
||
listCourseLibrary,
|
||
listCourses,
|
||
listDepts,
|
||
listLecturers,
|
||
listLibraryCourseQuestionBanks,
|
||
listMaterials,
|
||
listMembers,
|
||
listQuestionBanks,
|
||
listSessions,
|
||
publishCourse,
|
||
saveCourse,
|
||
saveCourseLibraryItem,
|
||
saveSession,
|
||
setEnrollments,
|
||
uploadCourseLibraryMaterial,
|
||
type TrainingCourse,
|
||
type TrainingCourseChangeLog,
|
||
type TrainingCourseSession,
|
||
type TrainingDept,
|
||
type TrainingKnowledgeBases,
|
||
type TrainingLibraryCourse,
|
||
type TrainingLecturerOption,
|
||
type TrainingMember,
|
||
type TrainingQuestionBank,
|
||
unwrap,
|
||
} from '@/api/training'
|
||
import { fmtBeijingTime } from '@/utils/datetime'
|
||
import { apiErrorMessage, get } from '@/utils/request'
|
||
|
||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||
// 课程维护:人事/课长/讲师(roles 已按权限组展开,经理经课长继承自动命中);
|
||
// 纯讲师的课程列表范围由后端按 lecturer_id 强制收窄。
|
||
const canManage = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'lecturer'))
|
||
// 纯讲师视角隐藏「按讲师查询」筛选(列表已固定为自己的课程)
|
||
const isLecturerOnly = computed(() => !canManage.value || (props.roles.includes('lecturer') && !props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'exec')))
|
||
const router = useRouter()
|
||
|
||
// 学习/考试状态列点击 → 学习考试页对应页签(课程学习情况/课程考试情况)并预选该课程
|
||
const goStudyStatus = (row: TrainingCourse, section: 'learning' | 'exam') => {
|
||
router.push({ path: '/platform/training/study', query: { section, courseId: row.id } })
|
||
}
|
||
|
||
// 课程名称点击 → 培训签到页,携带 courseId 自动选中该课程的场次
|
||
const goSignTab = (row: TrainingCourse) => {
|
||
router.push({ path: '/platform/training/sign', query: { courseId: row.id } })
|
||
}
|
||
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
const courses = ref<TrainingCourse[]>([])
|
||
const depts = ref<TrainingDept[]>([])
|
||
const members = ref<TrainingMember[]>([])
|
||
const sessions = ref<TrainingCourseSession[]>([])
|
||
const lecturers = ref<TrainingLecturerOption[]>([])
|
||
// 课程管理条目(课程资产主数据):创建/编辑计划的「课程名称」下拉数据源
|
||
const libraryCourses = ref<TrainingLibraryCourse[]>([])
|
||
// 题库总表(课程资产侧试题,000156):随课程条目挂接,详情/创建弹窗按条目过滤展示
|
||
const allBanks = ref<TrainingQuestionBank[]>([])
|
||
// 随 library_course_id 关联的课程资产(000156):适合人员/课件/试题,
|
||
// 月计划详情仅展示;课件/试题支持更换,更换后回写课程管理对应课程
|
||
const assetSaving = ref(false)
|
||
const courseBanks = ref<TrainingQuestionBank[]>([])
|
||
const banksLoading = ref(false)
|
||
const relinkVisible = ref(false)
|
||
const relinkBankId = ref('')
|
||
const materialInput = ref<HTMLInputElement | null>(null)
|
||
|
||
const libraryCourseOf = (libraryCourseId?: string) =>
|
||
libraryCourseId ? libraryCourses.value.find((c) => c.id === libraryCourseId) : undefined
|
||
// 详情弹窗当前课程 / 创建弹窗所选课程的资产条目
|
||
const activeLibraryCourse = computed(() => libraryCourseOf(editForm.value.library_course_id))
|
||
const formLibraryCourse = computed(() => libraryCourseOf(form.value.library_course_id))
|
||
|
||
const banksTextOf = (libraryCourseId?: string) => {
|
||
const list = allBanks.value.filter((b) => b.library_course_id && b.library_course_id === libraryCourseId)
|
||
return list.length ? list.map((b) => `${b.name}(${b.question_count}题)`).join('、') : '-'
|
||
}
|
||
const courseBanksText = computed(() =>
|
||
courseBanks.value.length
|
||
? courseBanks.value.map((b) => `${b.name}(${b.question_count}题)`).join('、')
|
||
: '-',
|
||
)
|
||
const formCourseBanksText = computed(() => banksTextOf(form.value.library_course_id))
|
||
|
||
// 拉取课程条目当前挂接的题库(详情弹窗打开/换选课程时)
|
||
const loadCourseBanks = async (libraryCourseId?: string) => {
|
||
courseBanks.value = []
|
||
relinkBankId.value = ''
|
||
relinkVisible.value = false
|
||
if (!libraryCourseId) return
|
||
banksLoading.value = true
|
||
try {
|
||
courseBanks.value = (unwrap(await listLibraryCourseQuestionBanks(libraryCourseId)) || []) as TrainingQuestionBank[]
|
||
} catch {
|
||
/* 失败保持空态,展示「-」 */
|
||
} finally {
|
||
banksLoading.value = false
|
||
}
|
||
}
|
||
|
||
// 计划未关联课程管理条目时(000158):按计划名称自动创建课程管理条目(草稿)
|
||
// 并挂接回写,使课件/试题维护入口对存量计划(线下/线上同样适用)可用
|
||
const ensureLibraryCourse = async (): Promise<TrainingLibraryCourse | null> => {
|
||
const existing = activeLibraryCourse.value
|
||
if (existing) return existing
|
||
const row = activeCourse.value
|
||
if (!row) return null
|
||
const name = (editForm.value.name || row.name || '').trim()
|
||
if (!name) {
|
||
MessagePlugin.warning('缺少课程名称,无法维护课件/试题')
|
||
return null
|
||
}
|
||
assetSaving.value = true
|
||
try {
|
||
const created = unwrap(await saveCourseLibraryItem({
|
||
name,
|
||
owner_dept_id: editForm.value.dept_ids?.[0] || '',
|
||
lecturer_id: editForm.value.lecturer_id || '',
|
||
mode: editForm.value.mode === 'online' ? 'online' : 'offline',
|
||
type: editForm.value.type === 'elective' ? 'elective' : 'required',
|
||
hours: editForm.value.hours || 0,
|
||
description: row.description || '',
|
||
})) as TrainingLibraryCourse | null
|
||
if (!created) throw new Error('create library course failed')
|
||
replaceLibraryCourse(created)
|
||
editForm.value.library_course_id = created.id
|
||
// 关联回写计划(全量载荷,避免部分字段被零值覆盖)
|
||
activeCourse.value = { ...row, library_course_id: created.id }
|
||
await saveCourse(detailSavePayload({ ...row, library_course_id: created.id }))
|
||
MessagePlugin.success(`已自动创建课程管理条目「${name}」并挂接该计划,后续课件/试题将同步维护`)
|
||
return created
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '自动创建课程管理条目失败'))
|
||
return null
|
||
} finally {
|
||
assetSaving.value = false
|
||
}
|
||
}
|
||
|
||
// 更换课件(000156):上传文件直接回写课程管理条目(material/file 同步知识库 fail-open)
|
||
const onChangeMaterial = async (e: Event) => {
|
||
const input = e.target as HTMLInputElement
|
||
const file = input.files?.[0]
|
||
input.value = ''
|
||
if (!file) return
|
||
// 无关联条目时自动按计划名称创建(000158),再上传课件
|
||
const lc = await ensureLibraryCourse()
|
||
if (!lc) return
|
||
assetSaving.value = true
|
||
try {
|
||
const fd = new FormData()
|
||
fd.append('file', file)
|
||
const updated = unwrap(await uploadCourseLibraryMaterial(lc.id, fd)) as TrainingLibraryCourse | null
|
||
replaceLibraryCourse(updated)
|
||
MessagePlugin.success(`课件已更换为「${updated?.material_name || updated?.file_name || file.name}」,已同步到课程管理「${lc.name}」`)
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '课件更换失败,请稍后重试'))
|
||
} finally {
|
||
assetSaving.value = false
|
||
}
|
||
}
|
||
|
||
// 更换试题(000156):所选题库整体替换该课程条目的题库,回写课程管理
|
||
const onRelinkBank = async () => {
|
||
const lc = await ensureLibraryCourse()
|
||
if (!lc || !relinkBankId.value) {
|
||
if (lc && !relinkBankId.value) MessagePlugin.warning('请先选择要挂接的题库')
|
||
return
|
||
}
|
||
assetSaving.value = true
|
||
try {
|
||
courseBanks.value = (unwrap(await linkLibraryCourseQuestionBank(lc.id, relinkBankId.value)) || []) as TrainingQuestionBank[]
|
||
// 同步本地题库总表的挂接关系:原挂本课程的解挂,新选中的标记挂接
|
||
const linked = new Set(courseBanks.value.map((b) => b.id))
|
||
allBanks.value = allBanks.value.map((b) => {
|
||
if (b.library_course_id === lc.id) return { ...b, library_course_id: linked.has(b.id) ? b.id : '' }
|
||
if (b.id === relinkBankId.value) return { ...b, library_course_id: lc.id }
|
||
return b
|
||
})
|
||
relinkVisible.value = false
|
||
relinkBankId.value = ''
|
||
MessagePlugin.success('试题已更换,已同步到课程管理对应课程')
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '试题更换失败,请稍后重试'))
|
||
} finally {
|
||
assetSaving.value = false
|
||
}
|
||
}
|
||
|
||
// 课程条目资产更新后替换本地缓存(下拉标签与展示同步刷新)
|
||
const replaceLibraryCourse = (updated?: TrainingLibraryCourse | null) => {
|
||
if (!updated) return
|
||
const idx = libraryCourses.value.findIndex((c) => c.id === updated.id)
|
||
if (idx >= 0) libraryCourses.value.splice(idx, 1, updated)
|
||
else libraryCourses.value = [...libraryCourses.value, updated]
|
||
}
|
||
|
||
// ---- 从知识库选择课件/试题(000158):与课程管理同口径(课件 from-kb 挂载,
|
||
// 试题 KB 文档解析建题库挂课程条目),月计划详情「知识库」入口 ----
|
||
const kbRefs = ref<TrainingKnowledgeBases>({ courseware: null, question_bank: null })
|
||
const kbDocsCache = ref<Record<string, { id: string; file_name: string }[]>>({})
|
||
const kbDocsLoading = ref(false)
|
||
const kbCoursewareVisible = ref(false)
|
||
const kbCoursewareDocId = ref('')
|
||
const kbBankVisible = ref(false)
|
||
const kbBankDocId = ref('')
|
||
|
||
const kbCoursewareDocs = computed(() => kbDocsCache.value[kbRefs.value.courseware?.id || ''] || [])
|
||
const kbBankDocs = computed(() => kbDocsCache.value[kbRefs.value.question_bank?.id || ''] || [])
|
||
|
||
// 知识库文档列表(按 kb id 缓存,惰性加载;与 LibraryPanel 选课件的接口口径一致)
|
||
const loadKbDocs = async (kind: 'courseware' | 'question_bank') => {
|
||
const kb = kbRefs.value[kind]
|
||
if (!kb?.id) return
|
||
if (kbDocsCache.value[kb.id]) return
|
||
kbDocsLoading.value = true
|
||
try {
|
||
const res: any = await get(`/api/v1/knowledge-bases/${encodeURIComponent(kb.id)}/knowledge?page=1&page_size=200`)
|
||
const body = res?.data ?? res
|
||
kbDocsCache.value = {
|
||
...kbDocsCache.value,
|
||
[kb.id]: (Array.isArray(body) ? body : body?.items || []).map((it: any) => ({
|
||
id: String(it.id),
|
||
file_name: it.file_name || it.title || it.id,
|
||
})),
|
||
}
|
||
} catch {
|
||
/* 失败保持空态 */
|
||
} finally {
|
||
kbDocsLoading.value = false
|
||
}
|
||
}
|
||
|
||
const ensureKbRefs = async () => {
|
||
if (kbRefs.value.courseware || kbRefs.value.question_bank) return
|
||
try {
|
||
kbRefs.value = (unwrap(await getTrainingKnowledgeBases()) as TrainingKnowledgeBases) || {
|
||
courseware: null,
|
||
question_bank: null,
|
||
}
|
||
} catch {
|
||
/* 知识库摘要失败:文档列表为空,提示不可选 */
|
||
}
|
||
}
|
||
|
||
const openKbCourseware = async () => {
|
||
kbCoursewareVisible.value = !kbCoursewareVisible.value
|
||
kbBankVisible.value = false
|
||
if (!kbCoursewareVisible.value) return
|
||
await ensureKbRefs()
|
||
await loadKbDocs('courseware')
|
||
}
|
||
|
||
// 从知识库「企业培训(课件)」选文档挂为课件(回写课程管理,与上传同口径)
|
||
const onAttachKbCourseware = async () => {
|
||
const lc = await ensureLibraryCourse()
|
||
const doc = kbCoursewareDocs.value.find((d) => d.id === kbCoursewareDocId.value)
|
||
if (!lc || !doc) {
|
||
if (lc && !doc) MessagePlugin.warning('请先选择知识库课件文档')
|
||
return
|
||
}
|
||
assetSaving.value = true
|
||
try {
|
||
const updated = unwrap(await attachCourseLibraryMaterialFromKb(lc.id, { knowledge_id: doc.id })) as TrainingLibraryCourse | null
|
||
replaceLibraryCourse(updated)
|
||
kbCoursewareVisible.value = false
|
||
kbCoursewareDocId.value = ''
|
||
MessagePlugin.success(`课件已更换为知识库文档「${doc.file_name}」,已同步到课程管理「${lc.name}」`)
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '课件更换失败,请稍后重试'))
|
||
} finally {
|
||
assetSaving.value = false
|
||
}
|
||
}
|
||
|
||
const openKbBank = async () => {
|
||
kbBankVisible.value = !kbBankVisible.value
|
||
kbCoursewareVisible.value = false
|
||
if (!kbBankVisible.value) return
|
||
await ensureKbRefs()
|
||
await loadKbDocs('question_bank')
|
||
}
|
||
|
||
// 从知识库「企业培训(题库)」文档解析建题库并挂当前课程条目(回写课程管理)
|
||
const onImportKbBank = async () => {
|
||
const lc = await ensureLibraryCourse()
|
||
const doc = kbBankDocs.value.find((d) => d.id === kbBankDocId.value)
|
||
if (!lc || !doc) {
|
||
if (lc && !doc) MessagePlugin.warning('请先选择知识库题库文档')
|
||
return
|
||
}
|
||
assetSaving.value = true
|
||
try {
|
||
const bank = unwrap(await importQuestionBankFromKnowledge({
|
||
knowledge_id: doc.id,
|
||
name: doc.file_name.replace(/\.[^.]+$/, ''),
|
||
library_course_id: lc.id,
|
||
})) as TrainingQuestionBank | null
|
||
kbBankVisible.value = false
|
||
kbBankDocId.value = ''
|
||
if (bank) allBanks.value = [bank, ...allBanks.value.filter((b) => b.id !== bank.id)]
|
||
await loadCourseBanks(lc.id)
|
||
MessagePlugin.success(`试题已更换为知识库题库「${bank?.name || doc.file_name}」,已同步到课程管理「${lc.name}」`)
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '试题更换失败,请稍后重试'))
|
||
} finally {
|
||
assetSaving.value = false
|
||
}
|
||
}
|
||
|
||
const formVisible = ref(false)
|
||
const sessionsVisible = ref(false)
|
||
const activeCourse = ref<TrainingCourse | null>(null)
|
||
|
||
// 讲师只读展示:员工名册映射姓名,外部讲师直接显示
|
||
const lecturerDisplay = (lecturerId: string) => {
|
||
if (lecturerId) {
|
||
const byUserId = members.value.find((m) => m.user_id === lecturerId)
|
||
if (byUserId) return byUserId.user_name || byUserId.employee_no
|
||
const byRoster = lecturers.value.find((l) => l.id === lecturerId)
|
||
if (byRoster) return byRoster.name
|
||
return lecturerId
|
||
}
|
||
const row = activeCourse.value
|
||
return row?.lecturer_external || '-'
|
||
}
|
||
// 部门 id 集合 → 名称(随课程管理「所属部门」带出,只读展示)
|
||
const deptNamesOf = (ids: string[] | undefined) => {
|
||
const list = (ids || []).map((id) => depts.value.find((d) => d.id === id)?.name || id).filter(Boolean)
|
||
return list.length ? list.join('、') : '-'
|
||
}
|
||
|
||
// 适用部门「全部」哨兵已随部门选择字段移除(部门随课程管理带出并锁定)
|
||
|
||
// [2026-11 需求] 「适用部门」变化 → 自动同步「参加人员」:
|
||
// 保留手动增选的人员,把旧部门集合自动带入的成员替换为新部门集合的成员
|
||
// (取消部门即移出其人员,新增部门即并入其人员),实际推送与应培名单以「参加人员」为准。
|
||
const syncParticipantsOnDeptChange = (prevDeptIds: string[], nextDeptIds: string[], currentIds: string[]): string[] => {
|
||
const prevSet = new Set(prevDeptIds)
|
||
const nextSet = new Set(nextDeptIds)
|
||
const prevDeptMemberIds = new Set(members.value.filter((m) => prevSet.has(m.dept_id)).map((m) => m.id))
|
||
const nextDeptMemberIds = members.value.filter((m) => nextSet.has(m.dept_id)).map((m) => m.id)
|
||
const kept = currentIds.filter((id) => !prevDeptMemberIds.has(id))
|
||
return [...new Set([...kept, ...nextDeptMemberIds])]
|
||
}
|
||
|
||
// 详情弹窗的课程信息编辑表单(随打开预填,保存走 saveCourse):
|
||
// 课程名称/类型/讲师/所属部门随课程管理锁定只读,仅维护六项授课安排字段
|
||
const detailSaving = ref(false)
|
||
const editForm = ref({
|
||
library_course_id: '',
|
||
name: '',
|
||
mode: 'offline' as 'offline' | 'online',
|
||
type: 'required',
|
||
hours: 2,
|
||
credits: 1,
|
||
lecturer_id: '',
|
||
dept_ids: [] as string[],
|
||
start_at: '',
|
||
location: '',
|
||
notify_mode: 'immediate' as 'immediate' | 'day_before',
|
||
})
|
||
// 类型只读展示(创建弹窗用 form,详情弹窗用 editForm)
|
||
const formTypeDisplay = computed(() => {
|
||
const base = sessionsVisible.value ? editForm.value.type : form.value.type
|
||
return base === 'elective' ? '选修课' : '必修课'
|
||
})
|
||
// 需求确认同步的参加人员(与场次学员名单合一):按人员/部门/岗位三种方式选择,
|
||
// 统一解析为员工 id;initialIds 记录打开时的解析结果,仅在实际变化时才写名单,
|
||
// 避免误清人工维护的名单
|
||
const demandSync = ref({ participantIds: [] as string[], initialIds: [] as string[] })
|
||
const participantMode = ref<'member' | 'dept' | 'post'>('member')
|
||
const participantDeptIds = ref<string[]>([])
|
||
const participantPostIds = ref<string[]>([])
|
||
// 名单「按岗位」选项:名册中的实际岗位去重
|
||
const postOptions = computed(() => [...new Set(members.value.map((m) => m.post).filter(Boolean))])
|
||
// 按当前选择方式(人员/部门/岗位)解析出去重后的参加员工
|
||
const resolvedParticipantMembers = computed<TrainingMember[]>(() => {
|
||
const ids = new Set(demandSync.value.participantIds)
|
||
for (const m of members.value) {
|
||
if (participantDeptIds.value.includes(m.dept_id)) ids.add(m.id)
|
||
if (m.post && participantPostIds.value.includes(m.post)) ids.add(m.id)
|
||
}
|
||
return members.value.filter((m) => ids.has(m.id))
|
||
})
|
||
// 课程修改版本记录(列表「记录」入口打开时拉取)
|
||
const changeLogs = ref<TrainingCourseChangeLog[]>([])
|
||
const changeLogsVisible = ref(false)
|
||
const changeLogsLoading = ref(false)
|
||
const changeLogCourse = ref<TrainingCourse | null>(null)
|
||
|
||
const openChangeLogs = async (row: TrainingCourse) => {
|
||
changeLogCourse.value = row
|
||
changeLogsVisible.value = true
|
||
changeLogsLoading.value = true
|
||
try {
|
||
const res = await listCourseChangeLogs(row.id)
|
||
changeLogs.value = unwrap(res) || []
|
||
} catch {
|
||
changeLogs.value = []
|
||
} finally {
|
||
changeLogsLoading.value = false
|
||
}
|
||
}
|
||
|
||
// 操作人展示:operator_id 为平台用户 id,经名册映射姓名
|
||
const operatorName = (operatorId: string) =>
|
||
members.value.find((m) => m.user_id === operatorId)?.user_name || operatorId.slice(0, 8)
|
||
|
||
const form = ref({
|
||
library_course_id: '',
|
||
name: '',
|
||
mode: 'offline' as 'offline' | 'online',
|
||
type: 'required',
|
||
hours: 2,
|
||
credits: 1,
|
||
start_at: '',
|
||
location: '',
|
||
// 学员开课通知方式(2026-11 推学员): immediate=名单/课件就绪即推(默认)
|
||
notify_mode: 'immediate' as 'immediate' | 'day_before',
|
||
lecturer_id: '',
|
||
deadlineDays: 7,
|
||
dept_ids: [] as string[],
|
||
description: '',
|
||
})
|
||
|
||
// 从课程管理选择课程:带出课程信息(类型/形式/讲师/学时/所属部门/说明)并锁定,
|
||
// 计划侧仅维护授课安排(学时学分/时间/地点/通知/参加人员)
|
||
const onLibraryCourseChange = (libraryCourseId: unknown) => {
|
||
const lc = libraryCourses.value.find((c) => c.id === libraryCourseId)
|
||
form.value.name = lc?.name || ''
|
||
form.value.mode = lc?.mode === 'online' ? 'online' : 'offline'
|
||
form.value.type = lc?.type === 'elective' ? 'elective' : 'required'
|
||
form.value.hours = lc?.hours || form.value.hours
|
||
form.value.lecturer_id = lc?.lecturer_id || ''
|
||
form.value.description = lc?.description || ''
|
||
form.value.dept_ids = lc?.owner_dept_id ? [lc.owner_dept_id] : []
|
||
}
|
||
|
||
// 「前往课程管理」:切到课程管理子页(同页内由 Training 按路由 tab 切换面板)
|
||
const goLibrary = () => {
|
||
formVisible.value = false
|
||
router.push('/platform/training/library')
|
||
}
|
||
|
||
// ---- 创建弹窗:参加人员(与详情弹窗同构,按人员/部门/岗位) ----
|
||
const formParticipantMode = ref<'member' | 'dept' | 'post'>('member')
|
||
const formParticipantIds = ref<string[]>([])
|
||
const formParticipantDeptIds = ref<string[]>([])
|
||
const formParticipantPostIds = ref<string[]>([])
|
||
// 按当前选择方式解析出的参加员工(与详情弹窗 resolvedParticipantMembers 同口径)
|
||
const resolvedFormMembers = computed<TrainingMember[]>(() => {
|
||
const ids = new Set(formParticipantIds.value)
|
||
for (const m of members.value) {
|
||
if (formParticipantDeptIds.value.includes(m.dept_id)) ids.add(m.id)
|
||
if (m.post && formParticipantPostIds.value.includes(m.post)) ids.add(m.id)
|
||
}
|
||
return members.value.filter((m) => ids.has(m.id))
|
||
})
|
||
const resetFormParticipants = () => {
|
||
formParticipantMode.value = 'member'
|
||
formParticipantIds.value = []
|
||
formParticipantDeptIds.value = []
|
||
formParticipantPostIds.value = []
|
||
}
|
||
|
||
// [2026-11 需求] 创建弹窗:「适用部门」变化自动带入/移出部门人员到「参加人员」。
|
||
// 按部门/按岗位的既有选择先固化为具体名单(保留不丢),选择方式切回「按人员」便于增删。
|
||
watch(
|
||
() => form.value.dept_ids,
|
||
(next, prev) => {
|
||
if (!formVisible.value || !next) return
|
||
formParticipantIds.value = syncParticipantsOnDeptChange(prev || [], next, resolvedFormMembers.value.map((m) => m.id))
|
||
formParticipantDeptIds.value = []
|
||
formParticipantPostIds.value = []
|
||
formParticipantMode.value = 'member'
|
||
},
|
||
)
|
||
|
||
// 详情弹窗同理;openDetail 预填表单时抑制一次,避免覆盖按 post_scope 回显的名单
|
||
const suppressDetailDeptWatch = ref(false)
|
||
watch(
|
||
() => editForm.value.dept_ids,
|
||
(next, prev) => {
|
||
if (!sessionsVisible.value || suppressDetailDeptWatch.value || !next) return
|
||
demandSync.value.participantIds = syncParticipantsOnDeptChange(prev || [], next, resolvedParticipantMembers.value.map((m) => m.id))
|
||
participantDeptIds.value = []
|
||
participantPostIds.value = []
|
||
participantMode.value = 'member'
|
||
},
|
||
)
|
||
|
||
const courseColumns = [
|
||
// 左侧列不固定(000154):计划编号/课程名称随横向滚动,状态/操作仍固定右侧
|
||
{ colKey: 'plan_code', title: '计划编号', width: 125 },
|
||
{ colKey: 'name', title: '课程名称', width: 170 },
|
||
{ colKey: 'mode', title: '形式', width: 70 },
|
||
{ colKey: 'type', title: '类型', width: 70 },
|
||
{ colKey: 'hours', title: '学时', width: 60 },
|
||
{ colKey: 'reporter', title: '上报部门', width: 110 },
|
||
{ colKey: 'teachTime', title: '授课时间', width: 130 },
|
||
{ colKey: 'plannedTime', title: '计划培训时间', width: 150 },
|
||
{ colKey: 'lecturer', title: '讲师', width: 100 },
|
||
{ colKey: 'location', title: '地点', width: 110 },
|
||
{ colKey: 'expected', title: '实/应人数', width: 90 },
|
||
{ colKey: 'learnStatus', title: '学习状态', width: 90 },
|
||
{ colKey: 'examStatus', title: '考试状态', width: 90 },
|
||
{ colKey: 'status', title: '状态', width: 80, fixed: 'right' },
|
||
{ colKey: 'op', title: '操作', width: 180, fixed: 'right' },
|
||
]
|
||
|
||
// ---- 查询条件(名称/讲师/培训时间/状态;列表全量加载,本地过滤) ----
|
||
const STATUS_OPTIONS = [
|
||
{ value: 'draft', label: '草稿' },
|
||
{ value: 'pending', label: '待审' },
|
||
{ value: 'published', label: '已发布' },
|
||
{ value: 'archived', label: '已归档' },
|
||
]
|
||
|
||
const filters = ref({
|
||
keyword: '',
|
||
lecturerId: '' as string | '',
|
||
status: '',
|
||
teachRange: [] as string[],
|
||
})
|
||
|
||
const resetFilters = () => {
|
||
filters.value = { keyword: '', lecturerId: '', status: '', teachRange: [] }
|
||
}
|
||
|
||
// 授课时间过滤口径与列展示一致:teach_time(具体时间/期望月份)优先,否则最近场次开始时间,
|
||
// 统一归一为 YYYY-MM-DD 后做字符串范围比较。
|
||
const teachDateValue = (row: TrainingCourse): string | null => {
|
||
if (row.teach_time) {
|
||
if (/^\d{4}-\d{2}$/.test(row.teach_time)) return `${row.teach_time}-01`
|
||
const shown = fmtBeijingTime(row.teach_time)
|
||
return shown ? shown.replaceAll('/', '-').slice(0, 10) : null
|
||
}
|
||
const list = courseSessions.value[row.id] || []
|
||
const nearest = list.find((s) => s.status === 'scheduled' && s.start_at) || list.find((s) => s.start_at) || list[0]
|
||
if (!nearest?.start_at) return null
|
||
const shown = fmtBeijingTime(nearest.start_at)
|
||
return shown ? shown.replaceAll('/', '-').slice(0, 10) : null
|
||
}
|
||
|
||
const filteredCourses = computed(() => {
|
||
const kw = filters.value.keyword.trim().toLowerCase()
|
||
const range = filters.value.teachRange || []
|
||
const from = range[0] ? String(range[0]).slice(0, 10) : ''
|
||
const to = range[1] ? String(range[1]).slice(0, 10) : ''
|
||
return courses.value.filter((row) => {
|
||
if (kw && !(row.name || '').toLowerCase().includes(kw)) return false
|
||
if (filters.value.lecturerId && row.lecturer_id !== filters.value.lecturerId) return false
|
||
if (filters.value.status && row.status !== filters.value.status) return false
|
||
if (from || to) {
|
||
const v = teachDateValue(row)
|
||
if (!v) return false
|
||
if (from && v < from) return false
|
||
if (to && v > to) return false
|
||
}
|
||
return true
|
||
})
|
||
})
|
||
|
||
const statusText = (s: string) => ({ draft: '草稿', pending: '待审', published: '已发布', archived: '已归档' }[s] || s)
|
||
const statusTheme = (s: string) => ({ draft: 'default', pending: 'warning', published: 'success', archived: 'default' }[s] || 'default')
|
||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '待定'
|
||
const typeText = (t: string) => ({ required: '必修', elective: '选修' }[t] || t)
|
||
|
||
// 学习/考试状态列文案与配色(口径与后端聚合一致,点击跳转学习考试页对应页签)
|
||
const learnStatusText = (s: string) => ({ not_started: '未学习', learning: '学习中', learned: '已学习' }[s] || '未学习')
|
||
const learnStatusTheme = (s: string) => ({ learning: 'warning', learned: 'success' }[s] || 'default')
|
||
const examStatusText = (s: string) => ({ not_started: '未考试', taking: '考试中', taken: '已考试' }[s] || '未考试')
|
||
const examStatusTheme = (s: string) => ({ taking: 'warning', taken: 'success' }[s] || 'default')
|
||
|
||
// 展示映射:讲师 id→姓名 / 课程→最近排期地点
|
||
const lectNameMap = computed(() => {
|
||
const m: Record<string, string> = {}
|
||
for (const l of lecturers.value) m[l.id] = l.name
|
||
return m
|
||
})
|
||
|
||
const courseSessions = computed(() => {
|
||
const map: Record<string, TrainingCourseSession[]> = {}
|
||
for (const s of sessions.value) {
|
||
(map[s.course_id] ||= []).push(s)
|
||
}
|
||
return map
|
||
})
|
||
const courseLocation = (row: TrainingCourse) => {
|
||
const list = courseSessions.value[row.id] || []
|
||
const nearest = list.find((s) => s.status === 'scheduled' && s.location) || list.find((s) => s.location) || list[0]
|
||
// 场次未排地点或尚未建场次(如需求确认草稿、参加人员未匹配到员工)时,
|
||
// 回退课程自身地点(来自需求确认同步落库的 course.location)
|
||
return nearest?.location || row.location || ''
|
||
}
|
||
// 授课时间展示:期望月份默认值(YYYY-MM)→「2026/11」;具体时间 → 北京时间无秒;线上课默认「长期」
|
||
const teachTimeText = (row: TrainingCourse) => {
|
||
if (row.mode === 'online') return row.teach_time ? teachTimeDisplay(row.teach_time) : '长期'
|
||
if (row.teach_time) return teachTimeDisplay(row.teach_time)
|
||
const list = courseSessions.value[row.id] || []
|
||
const nearest = list.find((s) => s.status === 'scheduled' && s.start_at) || list.find((s) => s.start_at) || list[0]
|
||
return nearest?.start_at ? fmtTime(nearest.start_at) : '-'
|
||
}
|
||
const teachTimeDisplay = (value: string) => {
|
||
if (/^\d{4}-\d{2}$/.test(value)) return value.replace('-', '/')
|
||
return fmtBeijingTime(value) || value
|
||
}
|
||
|
||
const loadAll = async () => {
|
||
loading.value = true
|
||
try {
|
||
const [c, d, m, l, s, lib, banks] = await Promise.all([
|
||
listCourses({ page_size: 100 }),
|
||
listDepts(),
|
||
listMembers({ page_size: 500 }),
|
||
listLecturers().catch(() => []),
|
||
listSessions({ year: 0, month: 0 }).catch(() => []),
|
||
listCourseLibrary({ page_size: 500 }).catch(() => null),
|
||
listQuestionBanks({ page_size: 200 }).catch(() => null),
|
||
])
|
||
courses.value = unwrap(c)?.items || []
|
||
depts.value = unwrap(d) || []
|
||
members.value = unwrap(m)?.items || []
|
||
lecturers.value = (l && unwrap(l)) || []
|
||
sessions.value = (s && unwrap(s)) || []
|
||
libraryCourses.value = (lib && unwrap(lib)?.items) || []
|
||
allBanks.value = (banks && unwrap(banks)?.items) || []
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
const openCreate = (mode: 'offline' | 'online') => {
|
||
form.value = {
|
||
library_course_id: '', name: '', mode, type: 'required', hours: 2, credits: 1,
|
||
start_at: '', location: '', notify_mode: 'immediate', lecturer_id: '', deadlineDays: 7, dept_ids: [],
|
||
description: '',
|
||
}
|
||
resetFormParticipants()
|
||
formVisible.value = true
|
||
}
|
||
|
||
const onSave = async () => {
|
||
if (!form.value.library_course_id || !form.value.name) {
|
||
MessagePlugin.warning('请从课程管理选择课程(课程名称必选)')
|
||
return
|
||
}
|
||
// 讲师随课程管理锁定:线下计划缺讲师时提示先在课程管理维护
|
||
if (form.value.mode === 'offline' && !form.value.lecturer_id) {
|
||
MessagePlugin.warning('当前课程未指定讲师,请先前往「课程管理」维护讲师后再创建线下计划')
|
||
return
|
||
}
|
||
saving.value = true
|
||
try {
|
||
// 参加人员(与详情弹窗同构):选中员工写 post_scope,落库后同步为场次学员名单
|
||
const selectedMembers = resolvedFormMembers.value
|
||
const postScope = selectedMembers.map((m) => m.user_name || m.employee_no).join('、')
|
||
const res = await saveCourse({
|
||
name: form.value.name,
|
||
mode: form.value.mode,
|
||
type: form.value.type,
|
||
hours: form.value.hours,
|
||
credits: form.value.credits,
|
||
dept_ids: form.value.dept_ids,
|
||
lecturer_id: form.value.lecturer_id || undefined,
|
||
teach_time: teachTimeOf(form.value),
|
||
post_scope: postScope,
|
||
// 课程管理关联(服务端据此带出并锁定课程信息,自动生成计划编号)
|
||
library_course_id: form.value.library_course_id,
|
||
description: form.value.description,
|
||
})
|
||
const course = unwrap(res)
|
||
if (!course) throw new Error('save failed')
|
||
|
||
// 线下课同步创建场次;线上课创建「线上」名单挂靠场次。
|
||
const sessionOpts = {
|
||
mode: form.value.mode,
|
||
lecturerId: form.value.lecturer_id || undefined,
|
||
startAt: form.value.start_at,
|
||
location: form.value.location,
|
||
hours: form.value.hours,
|
||
}
|
||
let rosterSession: TrainingCourseSession | undefined
|
||
if (form.value.mode === 'offline') {
|
||
const sessionRes = await saveSession({
|
||
course_id: course.id,
|
||
start_at: form.value.start_at ? new Date(form.value.start_at).toISOString() : '',
|
||
end_at: form.value.start_at ? new Date(new Date(form.value.start_at).getTime() + form.value.hours * 3600 * 1000).toISOString() : '',
|
||
location: form.value.location,
|
||
capacity: 0,
|
||
lecturer_id: form.value.lecturer_id || undefined,
|
||
// [2026-11 推学员] 学员开课通知方式随排课落库
|
||
notify_mode: form.value.notify_mode,
|
||
})
|
||
rosterSession = unwrap(sessionRes) || undefined
|
||
await refreshSessionCache()
|
||
} else {
|
||
rosterSession = await ensureCourseSession(course.id, sessionOpts)
|
||
}
|
||
// [2026-11 需求] 学员名单以「参加人员」为准:实际推送与应培人员按「参加人员」落名单
|
||
if (selectedMembers.length) {
|
||
const session = rosterSession || await ensureCourseSession(course.id, sessionOpts)
|
||
if (session) await setEnrollments(session.id, selectedMembers.map((m) => m.id))
|
||
}
|
||
await publishCourse(course.id)
|
||
MessagePlugin.success(
|
||
course.plan_code
|
||
? `计划 ${course.plan_code} 已保存并发布,讲师与学员通知已生成`
|
||
: '计划已保存并发布,讲师与学员通知已生成',
|
||
)
|
||
formVisible.value = false
|
||
resetFormParticipants()
|
||
loadAll()
|
||
} catch {
|
||
MessagePlugin.error('保存失败,请稍后重试')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
const onPublish = async (row: TrainingCourse) => {
|
||
// 与后端同口径的前置校验:线上必须有课件,线下必须有讲师
|
||
if (row.mode === 'online') {
|
||
try {
|
||
const res = await listMaterials(row.id)
|
||
if (!(unwrap(res) || []).length) {
|
||
MessagePlugin.warning(`「${row.name}」是线上计划,发布前需先登记课件资料`)
|
||
return
|
||
}
|
||
} catch {
|
||
/* 查询失败时交由后端校验兜底 */
|
||
}
|
||
} else if (!row.lecturer_id) {
|
||
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「详情」中指定讲师`)
|
||
return
|
||
}
|
||
try {
|
||
await publishCourse(row.id)
|
||
MessagePlugin.success('已发布')
|
||
loadAll()
|
||
} catch (e: any) {
|
||
MessagePlugin.error(apiErrorMessage(e, '发布失败'))
|
||
}
|
||
}
|
||
|
||
const onDelete = async (row: TrainingCourse) => {
|
||
if (!window.confirm(`确认删除计划「${row.name}」?`)) return
|
||
try {
|
||
await deleteCourse(row.id)
|
||
MessagePlugin.success('已删除')
|
||
loadAll()
|
||
} catch {
|
||
MessagePlugin.error('删除失败')
|
||
}
|
||
}
|
||
|
||
const openDetail = async (row: TrainingCourse) => {
|
||
activeCourse.value = row
|
||
sessionsVisible.value = true
|
||
// 预填表单触发 dept_ids watcher,先抑制,避免自动带入覆盖 post_scope 回显的名单
|
||
suppressDetailDeptWatch.value = true
|
||
void nextTick(() => (suppressDetailDeptWatch.value = false))
|
||
// 预填课程信息编辑表单(课程名称/类型/讲师/部门随课程管理锁定,仅授课安排可改)
|
||
editForm.value = {
|
||
library_course_id: row.library_course_id || '',
|
||
name: row.name,
|
||
mode: row.mode,
|
||
type: row.type,
|
||
hours: row.hours,
|
||
credits: row.credits,
|
||
lecturer_id: row.lecturer_id || '',
|
||
dept_ids: [...((row.dept_ids as unknown as string[]) || [])],
|
||
start_at: '',
|
||
location: '',
|
||
notify_mode: 'immediate',
|
||
}
|
||
// 课程资产侧信息(000156):适合人员/课件/试题随 library_course_id 展示
|
||
loadCourseBanks(row.library_course_id || '')
|
||
// 授课时间回填:优先课程授课时间(期望月份默认值 YYYY-MM 展开为当月 1 日),否则回退最近场次排期
|
||
const list = courseSessions.value[row.id] || []
|
||
const nearest = list.find((s) => s.status === 'scheduled' && s.start_at) || list.find((s) => s.start_at) || list[0]
|
||
if (row.mode === 'offline' && row.teach_time) {
|
||
editForm.value.start_at = teachTimeToPicker(row.teach_time)
|
||
} else if (nearest) {
|
||
editForm.value.start_at = fmtPicker(nearest.start_at)
|
||
}
|
||
if (nearest) {
|
||
editForm.value.location = nearest.location || ''
|
||
editForm.value.notify_mode = nearest.notify_mode === 'day_before' ? 'day_before' : 'immediate'
|
||
}
|
||
// 需求确认同步值:计划培训时间/授课地点默认带入可编辑的授课时间/授课地点(场次未排期时);
|
||
// 参加人员按姓名匹配员工预选(与场次学员名单合一),选择方式重置为按人员
|
||
const participantNames = (row.post_scope || '').split(/[、,,;;]/).map((s) => s.trim()).filter(Boolean)
|
||
const matchedIds = members.value
|
||
.filter((m) => participantNames.includes(m.user_name || ''))
|
||
.map((m) => m.id)
|
||
// [2026-11 需求] 参加人员为空但已选「适用部门」时,打开即自动带入部门人员
|
||
// (推送与应培名单以「参加人员」为准,带入后可增删)
|
||
const deptIds = (row.dept_ids as unknown as string[]) || []
|
||
const prefillIds = matchedIds.length || participantNames.length
|
||
? matchedIds
|
||
: deptIds.length ? members.value.filter((m) => deptIds.includes(m.dept_id)).map((m) => m.id) : []
|
||
demandSync.value = { participantIds: prefillIds, initialIds: [] }
|
||
participantMode.value = 'member'
|
||
participantDeptIds.value = []
|
||
participantPostIds.value = []
|
||
// 初始解析结果(按人员模式下与预选一致),保存时据此判断选择是否变化
|
||
demandSync.value.initialIds = resolvedParticipantMembers.value.map((m) => m.id)
|
||
if (row.mode === 'offline' && !editForm.value.start_at && row.planned_time) {
|
||
editForm.value.start_at = `${(row.planned_time || '').slice(0, 10)} 00:00`
|
||
}
|
||
if (row.mode === 'offline' && !editForm.value.location && row.location) {
|
||
editForm.value.location = row.location
|
||
}
|
||
// 线上课/无场次课程:懒建名单挂靠场次,使「场次与学员名单」对线上线下都可用
|
||
if (!list.length) {
|
||
await ensureCourseSession(row.id, {
|
||
mode: row.mode,
|
||
lecturerId: row.lecturer_id || undefined,
|
||
location: row.mode === 'online' ? '线上' : '',
|
||
hours: row.hours,
|
||
})
|
||
}
|
||
}
|
||
|
||
// 详情弹窗(未关联课程管理的计划)选定课程:带出课程信息并锁定,
|
||
// 适用部门变化经 watcher 自动同步参加人员名单
|
||
const onDetailLibraryCourseChange = (libraryCourseId: unknown) => {
|
||
const lc = libraryCourses.value.find((c) => c.id === libraryCourseId)
|
||
editForm.value.name = lc?.name || ''
|
||
editForm.value.mode = lc?.mode === 'online' ? 'online' : 'offline'
|
||
editForm.value.type = lc?.type === 'elective' ? 'elective' : 'required'
|
||
editForm.value.hours = lc?.hours || editForm.value.hours
|
||
editForm.value.lecturer_id = lc?.lecturer_id || ''
|
||
editForm.value.dept_ids = lc?.owner_dept_id ? [lc.owner_dept_id] : []
|
||
// 课程资产侧信息随换选刷新(适合人员/课件/试题,000156)
|
||
loadCourseBanks(editForm.value.library_course_id)
|
||
}
|
||
|
||
// t-date-picker(带时间)的回显格式
|
||
const fmtPicker = (iso: string | null) => {
|
||
if (!iso) return ''
|
||
const d = new Date(iso)
|
||
const p = (n: number) => String(n).padStart(2, '0')
|
||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
|
||
}
|
||
|
||
// 月份粒度的授课时间(YYYY-MM,需求期望月份默认值)展开为日期选择器可用的当月 1 日
|
||
const teachTimeToPicker = (value: string) =>
|
||
/^\d{4}-\d{2}$/.test(value) ? `${value}-01 09:00:00` : value
|
||
|
||
// 授课时间入库格式:线下取日期选择器(去秒),线上留空(长期)
|
||
const teachTimeOf = (form: { mode: string; start_at: string }) => {
|
||
if (form.mode !== 'offline' || !form.start_at) return ''
|
||
const parts = form.start_at.split(':')
|
||
return parts.length > 2 ? parts.slice(0, 2).join(':') : form.start_at
|
||
}
|
||
|
||
// 课程修改记录列
|
||
const changeLogColumns = [
|
||
{ colKey: 'changes', title: '变更明细' },
|
||
{ colKey: 'operator', title: '操作人', width: 110 },
|
||
{ colKey: 'created_at', title: '修改时间', width: 170 },
|
||
]
|
||
|
||
// ---- 场次与学员名单(线上线下通用) ----
|
||
|
||
const refreshSessionCache = async () => {
|
||
try {
|
||
const res = await listSessions({ year: 0, month: 0 })
|
||
sessions.value = unwrap(res) || []
|
||
} catch {
|
||
/* 保持旧缓存 */
|
||
}
|
||
}
|
||
|
||
// 确保课程存在可挂学员名单的场次:
|
||
// 线上课默认创建「线上」场次;线下课按时间/地点创建。已有场次直接返回第一场。
|
||
const ensureCourseSession = async (
|
||
courseId: string,
|
||
opts: { mode: string; lecturerId?: string; startAt?: string; location?: string; hours?: number },
|
||
) => {
|
||
const existing = courseSessions.value[courseId] || []
|
||
if (existing.length) return existing[0]
|
||
const offline = opts.mode === 'offline'
|
||
await saveSession({
|
||
course_id: courseId,
|
||
start_at: offline && opts.startAt ? new Date(opts.startAt).toISOString() : '',
|
||
end_at: offline && opts.startAt ? new Date(new Date(opts.startAt).getTime() + (opts.hours || 0) * 3600 * 1000).toISOString() : '',
|
||
location: offline ? (opts.location || '') : '线上',
|
||
capacity: 0,
|
||
lecturer_id: opts.lecturerId || undefined,
|
||
})
|
||
await refreshSessionCache()
|
||
return (courseSessions.value[courseId] || [])[0]
|
||
}
|
||
|
||
// 保存课程信息:基础信息走 saveCourse;线下课的授课时间/地点同步最近一场排期(无则创建);
|
||
// 学员名单以「参加人员」为准同步(适用部门选择时已自动带入,可增删)。
|
||
// 详情保存载荷(000158 抽取复用):UpdateCourse 为全量列更新,未编辑字段必须
|
||
// 回填原值,否则 tags/material_ids 会写 NULL,status/exam_enabled 会被零值覆盖。
|
||
const detailSavePayload = (row: TrainingCourse) => ({
|
||
id: row.id,
|
||
code: row.code,
|
||
name: editForm.value.name,
|
||
mode: editForm.value.mode,
|
||
type: editForm.value.type,
|
||
hours: editForm.value.hours,
|
||
credits: editForm.value.credits,
|
||
exam_enabled: row.exam_enabled,
|
||
dept_ids: editForm.value.dept_ids,
|
||
lecturer_id: editForm.value.lecturer_id || undefined,
|
||
// 参加人员:详情表单可编辑,保存随课程信息落库并同步场次学员名单
|
||
post_scope: resolvedParticipantMembers.value.map((m) => m.user_name || m.employee_no).join('、'),
|
||
description: row.description,
|
||
material_ids: row.material_ids,
|
||
tags: row.tags,
|
||
status: row.status,
|
||
teach_time: teachTimeOf(editForm.value),
|
||
planned_time: row.planned_time || '',
|
||
// 其余需求确认同步字段原样透传(详情表单不编辑,防止保存时被零值覆盖丢失)
|
||
train_type: row.train_type || '',
|
||
plant: row.plant || '',
|
||
location: row.location || '',
|
||
session_count: row.session_count || 0,
|
||
lecturer_external: row.lecturer_external || '',
|
||
remark: row.remark || '',
|
||
// 课程管理关联(未关联的存量计划可在此选定课程;关联后服务端锁定带出字段)
|
||
library_course_id: editForm.value.library_course_id || row.library_course_id || '',
|
||
})
|
||
|
||
const onSaveDetail = async () => {
|
||
const row = activeCourse.value
|
||
if (!row) return
|
||
// 讲师随课程管理锁定:缺失时提示去课程管理维护(发布时后端也会强制校验)
|
||
if (row.mode === 'offline' && !editForm.value.lecturer_id) {
|
||
MessagePlugin.warning('当前课程未指定讲师,请先前往「课程管理」维护讲师')
|
||
return
|
||
}
|
||
detailSaving.value = true
|
||
try {
|
||
// 参加人员名单按解析结果变化同步(见下方 setEnrollments)
|
||
const selectedMembers = resolvedParticipantMembers.value
|
||
const resolvedIds = selectedMembers.map((m) => m.id)
|
||
const rosterChanged =
|
||
resolvedIds.length !== demandSync.value.initialIds.length ||
|
||
resolvedIds.some((id) => !demandSync.value.initialIds.includes(id))
|
||
await saveCourse(detailSavePayload(row))
|
||
const sessionOpts = {
|
||
mode: editForm.value.mode,
|
||
lecturerId: editForm.value.lecturer_id || undefined,
|
||
startAt: editForm.value.start_at,
|
||
location: editForm.value.location,
|
||
hours: editForm.value.hours,
|
||
}
|
||
if (editForm.value.mode === 'offline' && (editForm.value.start_at || editForm.value.location)) {
|
||
const existing = (courseSessions.value[row.id] || [])[0]
|
||
await saveSession({
|
||
id: existing?.id,
|
||
course_id: row.id,
|
||
start_at: editForm.value.start_at ? new Date(editForm.value.start_at).toISOString() : '',
|
||
end_at: editForm.value.start_at ? new Date(new Date(editForm.value.start_at).getTime() + editForm.value.hours * 3600 * 1000).toISOString() : '',
|
||
location: editForm.value.location,
|
||
capacity: existing?.capacity ?? 0,
|
||
lecturer_id: editForm.value.lecturer_id || undefined,
|
||
// [2026-11 推学员] 编辑排课时同步通知方式
|
||
notify_mode: editForm.value.notify_mode,
|
||
})
|
||
await refreshSessionCache()
|
||
} else {
|
||
await ensureCourseSession(row.id, sessionOpts)
|
||
}
|
||
// [2026-11 需求] 学员名单以「参加人员」为准(与场次学员名单合一):
|
||
// 选择有变化即按选中员工覆盖名单(含清空);未变化且有选中时幂等重写,
|
||
// 兜底补齐历史课程空的名单(ReplaceEnrollments 对保留成员不重置状态)
|
||
if (rosterChanged || resolvedIds.length) {
|
||
const session = await ensureCourseSession(row.id, sessionOpts)
|
||
if (session) {
|
||
await setEnrollments(session.id, resolvedIds)
|
||
await refreshSessionCache()
|
||
}
|
||
}
|
||
MessagePlugin.success(
|
||
(row.plan_code ? `计划 ${row.plan_code} 已保存` : '计划信息已保存') +
|
||
(rosterChanged || resolvedIds.length ? ',学员名单已按「参加人员」同步' : ''),
|
||
)
|
||
sessionsVisible.value = false
|
||
loadAll()
|
||
} catch {
|
||
MessagePlugin.error('保存失败,请稍后重试')
|
||
} finally {
|
||
detailSaving.value = false
|
||
}
|
||
}
|
||
|
||
// 「维护课程」直达:工作台「我的课程」讲师卡片携 ?courseId= 跳入,
|
||
// 列表加载完成后自动打开该课的计划详情弹窗(找不到对应计划则停留在列表)。
|
||
// route 做可空防御:预览 harness 等无路由挂载场景不阻断面板渲染。
|
||
const route = useRoute()
|
||
const openDetailFromRoute = () => {
|
||
const id = String(route?.query?.courseId || '')
|
||
if (!id) return
|
||
const row = courses.value.find((c) => c.id === id)
|
||
if (row) openDetail(row)
|
||
}
|
||
onMounted(async () => {
|
||
await loadAll()
|
||
openDetailFromRoute()
|
||
})
|
||
// 已在本页时从工作台再点另一门课(query 变化但组件不重挂载)
|
||
watch(() => route?.query?.courseId, openDetailFromRoute)
|
||
</script>
|
||
|
||
<style lang="less" scoped>
|
||
@import (reference) '../training.less';
|
||
|
||
.panel-box {
|
||
.training-panel-box();
|
||
}
|
||
|
||
.form-hint {
|
||
margin-top: 8px;
|
||
color: var(--td-text-color-placeholder);
|
||
font-size: var(--app-text-sm);
|
||
}
|
||
|
||
// 关联题库:下拉 + 试题模板下载指引
|
||
.bank-field {
|
||
width: 100%;
|
||
}
|
||
|
||
// 课程详情弹窗:信息编辑区与场次区分隔
|
||
.detail-form {
|
||
margin-bottom: 6px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 1px solid var(--td-component-stroke);
|
||
}
|
||
|
||
.detail-section-title {
|
||
margin: 6px 0 8px;
|
||
font-weight: 600;
|
||
font-size: var(--app-text-md);
|
||
}
|
||
|
||
.detail-save-hint {
|
||
margin-top: 0;
|
||
margin-left: 10px;
|
||
}
|
||
|
||
// 关联课件行:形式标签 + 名称 + 知识库同步标记
|
||
.material-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
padding: 6px 0;
|
||
border-bottom: 1px dashed var(--td-component-stroke);
|
||
}
|
||
|
||
.material-name {
|
||
flex: 1;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
font-size: var(--app-text-md);
|
||
}
|
||
|
||
.material-add-bar {
|
||
margin-top: 8px;
|
||
}
|
||
|
||
// 学员名单弹窗:选择方式页签 + 预览
|
||
.roster-mode {
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.roster-preview {
|
||
margin-top: 8px;
|
||
}
|
||
|
||
// 名单明细:将写入的员工 tag 列表,超出滚动
|
||
.roster-detail {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
max-height: 132px;
|
||
overflow-y: auto;
|
||
padding: 2px 0;
|
||
}
|
||
|
||
.roster-tag {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
// 关联题库:题库 Excel 上传行与模式区
|
||
.bank-picker-body {
|
||
margin-top: 8px;
|
||
}
|
||
|
||
.bank-upload-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
min-height: 32px;
|
||
}
|
||
|
||
.bank-upload-input {
|
||
display: none;
|
||
}
|
||
|
||
.bank-upload-name {
|
||
flex: 1;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
color: var(--td-text-color-primary);
|
||
font-size: var(--app-text-sm);
|
||
}
|
||
|
||
.bank-upload-placeholder {
|
||
flex: 1;
|
||
color: var(--td-text-color-placeholder);
|
||
font-size: var(--app-text-sm);
|
||
}
|
||
|
||
// AI 生成试题抽屉:工具条 + 可编辑题目卡片
|
||
.gen-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-bottom: 10px;
|
||
|
||
&__hint {
|
||
color: var(--td-text-color-secondary);
|
||
font-size: var(--app-text-md);
|
||
}
|
||
}
|
||
|
||
.gen-question {
|
||
padding: 10px;
|
||
border: 1px solid var(--td-component-stroke);
|
||
border-radius: var(--app-radius-md);
|
||
margin-bottom: 10px;
|
||
|
||
&__head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
&__options {
|
||
margin-top: 8px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
}
|
||
|
||
&__opt {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
&__letter {
|
||
flex-shrink: 0;
|
||
width: 20px;
|
||
font-weight: 600;
|
||
color: var(--td-text-color-secondary);
|
||
}
|
||
|
||
&__meta {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-top: 8px;
|
||
color: var(--td-text-color-secondary);
|
||
font-size: var(--app-text-sm);
|
||
}
|
||
|
||
&__meta-item {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
}
|
||
|
||
.gen-add-btn {
|
||
margin-top: 4px;
|
||
}
|
||
|
||
// 弹窗底部保存条
|
||
.detail-save-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin-top: 14px;
|
||
padding-top: 12px;
|
||
border-top: 1px solid var(--td-component-stroke);
|
||
}
|
||
|
||
.detail-save-hint {
|
||
margin-top: 0;
|
||
flex: 1;
|
||
}
|
||
|
||
// 课程资产行(000156):课件/试题展示 + 「更换」按钮一行排布;
|
||
// 隐藏的原生 file input 供「更换课件」触发系统选择框
|
||
.asset-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
width: 100%;
|
||
}
|
||
|
||
.asset-value {
|
||
flex: 1;
|
||
}
|
||
|
||
.asset-relink {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
width: 100%;
|
||
margin-top: 8px;
|
||
}
|
||
|
||
.hidden-file-input {
|
||
display: none;
|
||
}
|
||
|
||
// 列表行高固定两行:超长文案(课程名称/部门/地点)双行截断
|
||
// 修改记录弹窗:字段级变更明细行
|
||
.change-line {
|
||
padding: 2px 0;
|
||
font-size: var(--app-text-md);
|
||
overflow-wrap: anywhere;
|
||
}
|
||
|
||
// 列表单元格内容垂直居中:用行内级 -webkit-inline-box 承接两行截断,
|
||
// 配合下方 .t-table__cell 的 vertical-align: middle,单行/双行内容均随行居中
|
||
.clamp-2 {
|
||
display: -webkit-inline-box;
|
||
-webkit-line-clamp: 2;
|
||
line-clamp: 2;
|
||
-webkit-box-orient: vertical;
|
||
overflow: hidden;
|
||
word-break: break-all;
|
||
line-height: 1.5;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
// 学习/考试状态 tag 可点击跳转学习考试页
|
||
.status-link {
|
||
cursor: pointer;
|
||
|
||
&:hover {
|
||
opacity: 0.85;
|
||
}
|
||
}
|
||
|
||
// 课程名称可点击 → 培训签到页(与状态 tag 同款可点击观感,品牌色区分)
|
||
.course-name-link {
|
||
cursor: pointer;
|
||
color: var(--td-brand-color);
|
||
|
||
&:hover {
|
||
text-decoration: underline;
|
||
}
|
||
}
|
||
|
||
.course-panel :deep(.t-table .t-table__cell) {
|
||
vertical-align: middle;
|
||
}
|
||
|
||
.bank-hint {
|
||
margin-top: 6px;
|
||
color: var(--td-text-color-placeholder);
|
||
font-size: var(--app-text-sm);
|
||
}
|
||
|
||
.template-link {
|
||
color: var(--td-brand-color);
|
||
text-decoration: none;
|
||
|
||
&:hover {
|
||
text-decoration: underline;
|
||
}
|
||
}
|
||
|
||
.session-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 10px 4px;
|
||
border-bottom: 1px solid var(--td-component-border);
|
||
|
||
&__actions { display: flex; gap: 8px; }
|
||
}
|
||
|
||
.muted { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); }
|
||
|
||
/* 课程资产库查询条件行(名称/讲师/培训时间/状态) */
|
||
.course-filters {
|
||
display: flex;
|
||
gap: 10px;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
margin: 4px 0 12px;
|
||
}
|
||
|
||
.course-filter-count {
|
||
font-size: var(--app-text-sm);
|
||
color: var(--td-text-color-secondary);
|
||
}
|
||
</style>
|