Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0e2a0e7c3 | ||
|
|
e378e8b7fd | ||
|
|
7ec21f35b0 |
No files matched your search
@@ -23,27 +23,48 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 汇总行:与设计稿一致(共 N 门 · 线上 / 线下 / 本月新增或课件数) -->
|
<!-- 汇总行:与设计稿一致(共 N 门 · 线上 / 线下 / 本月新增或课件数)。
|
||||||
<div class="catalog-stats">{{ statsText }}</div>
|
待维护 = 我任讲师且未发布(草稿/待审)、或已发布但未上传课件的课程数
|
||||||
|
(2026-11 需求:>0 时用与「草稿」一致的橙色提醒,不再用红色)。 -->
|
||||||
|
<div class="catalog-stats">
|
||||||
|
{{ statsText }}
|
||||||
|
<span class="catalog-stats__maintain" :class="{ 'is-alert': maintainCount > 0 }">待维护 {{ maintainCount }} 门</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 课程卡片网格 -->
|
<!-- 课程卡片网格 -->
|
||||||
<t-loading :loading="loading" class="catalog-grid-wrap">
|
<t-loading :loading="loading" class="catalog-grid-wrap">
|
||||||
<div class="catalog-grid">
|
<div class="catalog-grid">
|
||||||
<article v-for="card in visibleCards" :key="card.id" class="course-card" role="link" tabindex="0" @click="openCourse(card.id)" @keydown.enter="openCourse(card.id)">
|
<article v-for="card in visibleCards" :key="card.id" class="course-card" role="link" tabindex="0" @click="openCourse(card)" @keydown.enter="openCourse(card)">
|
||||||
<div class="course-card__cover" :class="card.mode === 'online' ? 'is-online' : 'is-offline'">
|
<div class="course-card__cover" :class="card.mode === 'online' ? 'is-online' : 'is-offline'">
|
||||||
<svg v-if="card.mode === 'online'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/></svg>
|
<svg v-if="card.mode === 'online'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/></svg>
|
||||||
<svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 17.5V5a1.6 1.6 0 0 1 1.6-1.6h9A1.6 1.6 0 0 1 16.2 5v12.5"/><path d="M4 17.5A2.5 2.5 0 0 0 6.5 20h9.7"/><path d="M16.2 8.2H19a1.4 1.4 0 0 1 1.4 1.4v3.1a2.3 2.3 0 1 1-4.6 0V9.6"/><path d="M7.5 7h5M7.5 10h5"/></svg>
|
<svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 17.5V5a1.6 1.6 0 0 1 1.6-1.6h9A1.6 1.6 0 0 1 16.2 5v12.5"/><path d="M4 17.5A2.5 2.5 0 0 0 6.5 20h9.7"/><path d="M16.2 8.2H19a1.4 1.4 0 0 1 1.4 1.4v3.1a2.3 2.3 0 1 1-4.6 0V9.6"/><path d="M7.5 7h5M7.5 10h5"/></svg>
|
||||||
<span>课程封面</span>
|
<span>课程封面</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="course-card__body">
|
<div class="course-card__body">
|
||||||
|
<div class="course-card__tags">
|
||||||
<t-tag :theme="card.mode === 'online' ? 'primary' : 'success'" variant="light" size="small" :class="{ 'course-tag-offline': card.mode !== 'online' }">
|
<t-tag :theme="card.mode === 'online' ? 'primary' : 'success'" variant="light" size="small" :class="{ 'course-tag-offline': card.mode !== 'online' }">
|
||||||
{{ card.mode === 'online' ? '线上课程' : '线下课程' }}
|
{{ card.mode === 'online' ? '线上课程' : '线下课程' }}
|
||||||
</t-tag>
|
</t-tag>
|
||||||
|
<!-- [2026-11 需求]「我的课程」角色标记:区分我要进行培训(我主讲,橙色)/ 我要参加(蓝绿色)的课程 -->
|
||||||
|
<t-tag
|
||||||
|
v-if="card.roleTag"
|
||||||
|
:theme="card.roleTag === 'teach' ? 'warning' : 'primary'"
|
||||||
|
variant="light"
|
||||||
|
size="small"
|
||||||
|
>{{ card.roleTag === 'teach' ? '我主讲' : '我参加' }}</t-tag>
|
||||||
|
</div>
|
||||||
<h3 class="course-card__name" :title="card.name">{{ card.name }}</h3>
|
<h3 class="course-card__name" :title="card.name">{{ card.name }}</h3>
|
||||||
<p class="course-card__meta" :title="card.meta">{{ card.meta }}</p>
|
<p class="course-card__meta" :title="card.meta">{{ card.meta }}</p>
|
||||||
<div class="course-card__foot">
|
<div class="course-card__foot">
|
||||||
<div class="course-card__bar" :class="card.barClass"><i :style="{ width: card.barWidth }"></i></div>
|
<div class="course-card__bar" :class="card.barClass"><i :style="{ width: card.barWidth }"></i></div>
|
||||||
<span class="course-card__state" :class="card.stateClass">{{ card.state }}</span>
|
<span class="course-card__state" :class="card.stateClass">{{ card.state }}</span>
|
||||||
|
<!-- 我任讲师的课程:直达「培训课程」维护该课(自动打开课程详情弹窗) -->
|
||||||
|
<button
|
||||||
|
v-if="card.maintainable"
|
||||||
|
type="button"
|
||||||
|
class="course-card__maintain"
|
||||||
|
@click.stop="goMaintain(card.id)"
|
||||||
|
>维护课程</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
@@ -68,16 +89,28 @@ import {
|
|||||||
unwrap,
|
unwrap,
|
||||||
} from '@/api/training'
|
} from '@/api/training'
|
||||||
|
|
||||||
defineProps<{ roles: string[]; admin?: boolean }>()
|
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
// 卡片点击 → 课程学习详情页(课件在线预览 + 随堂考试)。
|
// 卡片点击 → 课程学习详情页(课件在线预览 + 随堂考试);
|
||||||
const openCourse = (courseId: string) => {
|
// 未发布课程(我任讲师的草稿/待审)无学习视角,点击直达维护。
|
||||||
router.push(`/platform/training/course/${courseId}`)
|
const openCourse = (card: CatalogCard) => {
|
||||||
|
if (card.unpublished) {
|
||||||
|
goMaintain(card.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
router.push(`/platform/training/course/${card.id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【维护课程】→ 培训课程页并自动打开该课的课程详情弹窗
|
||||||
|
const goMaintain = (courseId: string) => {
|
||||||
|
router.push({ path: '/platform/training/course', query: { courseId } })
|
||||||
}
|
}
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const courses = ref<TrainingCourse[]>([])
|
const courses = ref<TrainingCourse[]>([])
|
||||||
|
// 课程维护视角(不带 scope=student)的我名下课程:纯讲师含草稿,供「我的课程」与待维护统计
|
||||||
|
const lecturerCourses = ref<TrainingCourse[]>([])
|
||||||
const myProfile = ref<TrainingMember | null>(null)
|
const myProfile = ref<TrainingMember | null>(null)
|
||||||
const myTasks = ref<LearningTask[]>([])
|
const myTasks = ref<LearningTask[]>([])
|
||||||
const sessions = ref<TrainingCourseSession[]>([])
|
const sessions = ref<TrainingCourseSession[]>([])
|
||||||
@@ -88,7 +121,8 @@ const FILTERS = [
|
|||||||
{ key: 'offline', label: '线下课程' },
|
{ key: 'offline', label: '线下课程' },
|
||||||
{ key: 'mine', label: '我的课程' },
|
{ key: 'mine', label: '我的课程' },
|
||||||
] as const
|
] as const
|
||||||
const filter = ref<string>('all')
|
// 工作台进目录默认落在「我的课程」(2026-11 需求:与我相关的课优先展示)
|
||||||
|
const filter = ref<string>('mine')
|
||||||
const keyword = ref('')
|
const keyword = ref('')
|
||||||
|
|
||||||
// 目录页面向全体员工:仅展示已发布课程(草稿/待审在「培训课程」维护)
|
// 目录页面向全体员工:仅展示已发布课程(草稿/待审在「培训课程」维护)
|
||||||
@@ -122,14 +156,36 @@ const myTaskByCourse = computed(() => {
|
|||||||
// 「我的课程」相关性口径(与后端推送口径一致):
|
// 「我的课程」相关性口径(与后端推送口径一致):
|
||||||
// ① 我有该课学习任务(线上必修按部门推送);② 我是该课讲师;
|
// ① 我有该课学习任务(线上必修按部门推送);② 我是该课讲师;
|
||||||
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门)。
|
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门)。
|
||||||
|
// 讲师匹配用平台用户 id(user_id)——与后端 course.LecturerID == callerUserID 同口径。
|
||||||
|
const myUserId = computed(() => myProfile.value?.user_id || '')
|
||||||
|
const isMyTeaching = (c: TrainingCourse) => !!myUserId.value && c.lecturer_id === myUserId.value
|
||||||
const isMyCourse = (c: TrainingCourse) => {
|
const isMyCourse = (c: TrainingCourse) => {
|
||||||
if (myTaskByCourse.value.has(c.id)) return true
|
if (myTaskByCourse.value.has(c.id)) return true
|
||||||
if (myProfile.value && c.lecturer_id === myProfile.value.id) return true
|
if (isMyTeaching(c)) return true
|
||||||
const scope = c.dept_ids || []
|
const scope = c.dept_ids || []
|
||||||
if (!scope.length) return true
|
if (!scope.length) return true
|
||||||
return !!myProfile.value && scope.includes(myProfile.value.dept_id)
|
return !!myProfile.value && scope.includes(myProfile.value.dept_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 可进「培训课程」维护页的角色(与 Training.vue canManageTabs 同口径)
|
||||||
|
const canMaintainCourses = computed(
|
||||||
|
() => props.admin || props.roles.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r)),
|
||||||
|
)
|
||||||
|
|
||||||
|
// 我任讲师的课程(含未发布):维护视角列表 + 学员视角已发布列表按 id 合并去重。
|
||||||
|
// 纯讲师/管理角色才请求维护视角;纯学员只能拿到已发布的(后端强制),合并结果不受影响。
|
||||||
|
const myTeachingCourses = computed<TrainingCourse[]>(() => {
|
||||||
|
const map = new Map<string, TrainingCourse>()
|
||||||
|
publishedCourses.value.filter(isMyTeaching).forEach((c) => map.set(c.id, c))
|
||||||
|
lecturerCourses.value.filter(isMyTeaching).forEach((c) => map.set(c.id, c))
|
||||||
|
return [...map.values()]
|
||||||
|
})
|
||||||
|
|
||||||
|
// 待维护 = 我任讲师且未发布(草稿/待审)、或已发布但未上传课件的课程
|
||||||
|
// (线上课发布强制有课件,实际命中的多为线下课:学员通知在课件上传前不会推送)
|
||||||
|
const needsMaintain = (c: TrainingCourse) => c.status !== 'published' || !c.material_ids?.length
|
||||||
|
const maintainCount = computed(() => myTeachingCourses.value.filter(needsMaintain).length)
|
||||||
|
|
||||||
// 线下课排期索引:取最近一场排期/已完成场次汇总
|
// 线下课排期索引:取最近一场排期/已完成场次汇总
|
||||||
const sessionByCourse = computed(() => {
|
const sessionByCourse = computed(() => {
|
||||||
const map = new Map<string, TrainingCourseSession[]>()
|
const map = new Map<string, TrainingCourseSession[]>()
|
||||||
@@ -148,6 +204,24 @@ const fmtMonthDay = (raw: string | null) => {
|
|||||||
return `${d.getMonth() + 1}月${d.getDate()}日`
|
return `${d.getMonth() + 1}月${d.getDate()}日`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [2026-11 需求] 「我的课程」排序时间锚点:最近场次排期优先,其次授课时间/计划时间/创建时间;
|
||||||
|
// 月份粒度(YYYY-MM)展开为当月 1 日,无可用时间返回 NaN(排序时落到最后)
|
||||||
|
const courseTimeMs = (raw?: string | null): number => {
|
||||||
|
if (!raw) return NaN
|
||||||
|
const v = /^\d{4}-\d{2}$/.test(raw) ? `${raw}-01` : raw
|
||||||
|
const t = new Date(v).getTime()
|
||||||
|
return Number.isFinite(t) ? t : NaN
|
||||||
|
}
|
||||||
|
const courseNearestTime = (c: TrainingCourse): number => {
|
||||||
|
const list = (sessionByCourse.value.get(c.id) || [])
|
||||||
|
.slice()
|
||||||
|
.sort((a, b) => String(a.start_at).localeCompare(String(b.start_at)))
|
||||||
|
const s = list.find((x) => x.status === 'scheduled' && x.start_at) || list.find((x) => x.start_at)
|
||||||
|
const fallback =
|
||||||
|
c.teach_time || c.planned_time || (c as unknown as { created_at?: string }).created_at || ''
|
||||||
|
return courseTimeMs(s?.start_at || fallback)
|
||||||
|
}
|
||||||
|
|
||||||
interface CatalogCard {
|
interface CatalogCard {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
@@ -157,23 +231,73 @@ interface CatalogCard {
|
|||||||
stateClass: string
|
stateClass: string
|
||||||
barWidth: string
|
barWidth: string
|
||||||
barClass: string
|
barClass: string
|
||||||
|
/** 我任讲师且可进维护页:卡片展示【维护课程】按钮 */
|
||||||
|
maintainable: boolean
|
||||||
|
/** 未发布(草稿/待审)的讲师课程:无学习视角,点击直达维护 */
|
||||||
|
unpublished: boolean
|
||||||
|
/** [2026-11 需求]「我的课程」角色标记:teach=我主讲 / attend=我参加(其余视图不标记) */
|
||||||
|
roleTag?: 'teach' | 'attend'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 卡片元信息与底部进度条:
|
// 卡片元信息与底部进度条:
|
||||||
// 线上 = 我的学习任务状态(已完成/学习中/待学习/已逾期),进度条只表达确定状态,不虚构百分比;
|
// 线上 = 我的学习任务状态(已完成/学习中/待学习/已逾期),进度条只表达确定状态,不虚构百分比;
|
||||||
// 线下 = 真实排期进度(已完成场次/已排期场次)。
|
// 线下 = 真实排期进度(已完成场次/已排期场次)。
|
||||||
|
// 未发布的讲师课程(仅「我的课程」视图可见)以草稿/待审态展示。
|
||||||
const visibleCards = computed<CatalogCard[]>(() => {
|
const visibleCards = computed<CatalogCard[]>(() => {
|
||||||
const kw = keyword.value.trim().toLowerCase()
|
const kw = keyword.value.trim().toLowerCase()
|
||||||
return publishedCourses.value
|
// 数据源:全部/线上/线下 = 已发布目录;我的课程 = 我相关的已发布课 + 我任讲师的课(含未发布,已发布的按 id 去重)
|
||||||
.filter((c) => {
|
let source = publishedCourses.value
|
||||||
|
if (filter.value === 'mine') {
|
||||||
|
const minePublished = publishedCourses.value.filter(isMyCourse)
|
||||||
|
const mineIds = new Set(minePublished.map((c) => c.id))
|
||||||
|
source = [...minePublished, ...myTeachingCourses.value.filter((c) => !mineIds.has(c.id))]
|
||||||
|
}
|
||||||
|
let list = source.filter((c) => {
|
||||||
if (filter.value === 'online' && c.mode !== 'online') return false
|
if (filter.value === 'online' && c.mode !== 'online') return false
|
||||||
if (filter.value === 'offline' && c.mode !== 'offline') return false
|
if (filter.value === 'offline' && c.mode !== 'offline') return false
|
||||||
if (filter.value === 'mine' && !isMyCourse(c)) return false
|
if (filter.value === 'mine' && !isMyCourse(c) && !isMyTeaching(c)) return false
|
||||||
if (kw && !(c.name.toLowerCase().includes(kw) || (c.tags || []).some((t) => String(t).toLowerCase().includes(kw)))) return false
|
if (kw && !(c.name.toLowerCase().includes(kw) || (c.tags || []).some((t) => String(t).toLowerCase().includes(kw)))) return false
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
// [2026-11 需求] 「我的课程」排序:待维护(我主讲未发布/缺课件)置顶,
|
||||||
|
// 其余按与当前时间的邻近度升序(临近开课/结课的在前,无时间锚点的排最后)
|
||||||
|
if (filter.value === 'mine') {
|
||||||
|
const now = Date.now()
|
||||||
|
const dist = (c: TrainingCourse) => {
|
||||||
|
const t = courseNearestTime(c)
|
||||||
|
return Number.isFinite(t) ? Math.abs(t - now) : Number.POSITIVE_INFINITY
|
||||||
|
}
|
||||||
|
list = list.slice().sort((a, b) => {
|
||||||
|
const ma = isMyTeaching(a) && needsMaintain(a) ? 0 : 1
|
||||||
|
const mb = isMyTeaching(b) && needsMaintain(b) ? 0 : 1
|
||||||
|
if (ma !== mb) return ma - mb
|
||||||
|
return ma === 0 ? 0 : dist(a) - dist(b)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return list
|
||||||
.map((c) => {
|
.map((c) => {
|
||||||
const head = [c.post_scope, typeText(c), `${c.hours} 学时`, c.exam_enabled ? '随堂考试' : ''].filter(Boolean).join(' · ')
|
const head = [c.post_scope, typeText(c), `${c.hours} 学时`, c.exam_enabled ? '随堂考试' : ''].filter(Boolean).join(' · ')
|
||||||
|
const maintainable = isMyTeaching(c) && canMaintainCourses.value
|
||||||
|
const unpublished = c.status !== 'published'
|
||||||
|
// [2026-11 需求]「我的课程」角色标记:我主讲(优先) / 我参加,其余视图不标记
|
||||||
|
const roleTag = filter.value === 'mine' ? (isMyTeaching(c) ? ('teach' as const) : ('attend' as const)) : undefined
|
||||||
|
// 未发布讲师课:无学习任务与排期进度,展示草稿/待审 + 计划时间(需求确认同步)
|
||||||
|
if (unpublished) {
|
||||||
|
const planText = c.planned_time || (c.teach_time && !/^\d{4}-\d{2}$/.test(c.teach_time) ? c.teach_time : '')
|
||||||
|
return {
|
||||||
|
id: c.id,
|
||||||
|
name: c.name,
|
||||||
|
mode: c.mode,
|
||||||
|
meta: `${head}${planText ? ` · 计划 ${fmtMonthDay(planText)}` : ''}`,
|
||||||
|
state: c.status === 'pending' ? '待审' : '草稿',
|
||||||
|
stateClass: 'is-warn',
|
||||||
|
barWidth: '0%',
|
||||||
|
barClass: '',
|
||||||
|
maintainable,
|
||||||
|
unpublished,
|
||||||
|
roleTag,
|
||||||
|
}
|
||||||
|
}
|
||||||
if (c.mode === 'online') {
|
if (c.mode === 'online') {
|
||||||
const task = myTaskByCourse.value.get(c.id)
|
const task = myTaskByCourse.value.get(c.id)
|
||||||
const status = task?.status || 'pending'
|
const status = task?.status || 'pending'
|
||||||
@@ -188,13 +312,13 @@ const visibleCards = computed<CatalogCard[]>(() => {
|
|||||||
: status === 'overdue' ? { state: '已逾期', cls: 'is-bad', width: '0%', bar: '' }
|
: status === 'overdue' ? { state: '已逾期', cls: 'is-bad', width: '0%', bar: '' }
|
||||||
: { state: '待学习', cls: '', width: '0%', bar: '' }
|
: { state: '待学习', cls: '', width: '0%', bar: '' }
|
||||||
const materials = c.material_ids?.length ? ` · 课件 ${c.material_ids.length} 个` : ''
|
const materials = c.material_ids?.length ? ` · 课件 ${c.material_ids.length} 个` : ''
|
||||||
return { id: c.id, name: c.name, mode: c.mode, meta: `${head}${materials}`, state: cur.state, stateClass: cur.cls, barWidth: cur.width, barClass: cur.bar }
|
return { id: c.id, name: c.name, mode: c.mode, meta: `${head}${materials}`, state: cur.state, stateClass: cur.cls, barWidth: cur.width, barClass: cur.bar, maintainable, unpublished, roleTag }
|
||||||
}
|
}
|
||||||
const list = (sessionByCourse.value.get(c.id) || []).sort((a, b) => String(a.start_at).localeCompare(String(b.start_at)))
|
const sess = (sessionByCourse.value.get(c.id) || []).sort((a, b) => String(a.start_at).localeCompare(String(b.start_at)))
|
||||||
const finished = list.filter((s) => s.status === 'finished').length
|
const finished = sess.filter((s) => s.status === 'finished').length
|
||||||
const next = list.find((s) => s.status === 'scheduled' && s.start_at)
|
const next = sess.find((s) => s.status === 'scheduled' && s.start_at)
|
||||||
const scheduleText = next ? `${fmtMonthDay(next.start_at)} ${next.location || '线下授课'}` : finished ? `已完成 ${finished} 场` : '待排期'
|
const scheduleText = next ? `${fmtMonthDay(next.start_at)} ${next.location || '线下授课'}` : finished ? `已完成 ${finished} 场` : '待排期'
|
||||||
const ratio = list.length ? Math.round((finished / list.length) * 100) : 0
|
const ratio = sess.length ? Math.round((finished / sess.length) * 100) : 0
|
||||||
return {
|
return {
|
||||||
id: c.id,
|
id: c.id,
|
||||||
name: c.name,
|
name: c.name,
|
||||||
@@ -204,6 +328,9 @@ const visibleCards = computed<CatalogCard[]>(() => {
|
|||||||
stateClass: next ? 'is-doing' : finished ? 'is-good' : '',
|
stateClass: next ? 'is-doing' : finished ? 'is-good' : '',
|
||||||
barWidth: `${ratio}%`,
|
barWidth: `${ratio}%`,
|
||||||
barClass: ratio >= 100 ? 'is-done' : '',
|
barClass: ratio >= 100 ? 'is-done' : '',
|
||||||
|
maintainable,
|
||||||
|
unpublished,
|
||||||
|
roleTag,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -211,17 +338,22 @@ const visibleCards = computed<CatalogCard[]>(() => {
|
|||||||
const loadAll = async () => {
|
const loadAll = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const [c, t, s, me] = await Promise.all([
|
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
|
||||||
|
// 供「我的课程」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
|
||||||
|
const needMaintainView = props.admin || props.roles.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r))
|
||||||
|
const [c, t, s, me, lc] = await Promise.all([
|
||||||
// 学员目录视图:scope=student 统一走已发布课程口径(讲师账号的学习视角不受课程维护范围影响)
|
// 学员目录视图:scope=student 统一走已发布课程口径(讲师账号的学习视角不受课程维护范围影响)
|
||||||
listCourses({ page_size: 100, scope: 'student' }),
|
listCourses({ page_size: 100, scope: 'student' }),
|
||||||
listMyLearningTasks().catch(() => null),
|
listMyLearningTasks().catch(() => null),
|
||||||
listSessions({ year: 0, month: 0, scope: 'student' }).catch(() => null),
|
listSessions({ year: 0, month: 0, scope: 'student' }).catch(() => null),
|
||||||
getMyProfile().catch(() => null),
|
getMyProfile().catch(() => null),
|
||||||
|
needMaintainView ? listCourses({ page_size: 100 }).catch(() => null) : Promise.resolve(null),
|
||||||
])
|
])
|
||||||
courses.value = unwrap(c)?.items || []
|
courses.value = unwrap(c)?.items || []
|
||||||
myTasks.value = (t && unwrap(t)) || []
|
myTasks.value = (t && unwrap(t)) || []
|
||||||
sessions.value = (s && unwrap(s)) || []
|
sessions.value = (s && unwrap(s)) || []
|
||||||
myProfile.value = (me && unwrap(me)) || null
|
myProfile.value = (me && unwrap(me)) || null
|
||||||
|
lecturerCourses.value = (lc && unwrap(lc)?.items) || []
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@@ -298,6 +430,16 @@ onMounted(loadAll)
|
|||||||
color: var(--td-text-color-secondary);
|
color: var(--td-text-color-secondary);
|
||||||
font-size: var(--app-text-md);
|
font-size: var(--app-text-md);
|
||||||
margin-bottom: 14px;
|
margin-bottom: 14px;
|
||||||
|
|
||||||
|
// 待维护统计:与「草稿」状态同色(橙色提醒,2026-11 需求:不再用红色)
|
||||||
|
&__maintain {
|
||||||
|
margin-left: 6px;
|
||||||
|
|
||||||
|
&.is-alert {
|
||||||
|
color: var(--td-warning-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.catalog-grid-wrap {
|
.catalog-grid-wrap {
|
||||||
@@ -364,6 +506,14 @@ onMounted(loadAll)
|
|||||||
padding: 12px 14px 14px;
|
padding: 12px 14px 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 形式标签 + 「我的课程」角色标记(我主讲/我参加)同行展示
|
||||||
|
&__tags {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
&__name {
|
&__name {
|
||||||
margin: 8px 0 4px;
|
margin: 8px 0 4px;
|
||||||
font-size: var(--app-text-lg);
|
font-size: var(--app-text-lg);
|
||||||
@@ -418,8 +568,35 @@ onMounted(loadAll)
|
|||||||
|
|
||||||
&.is-good { color: var(--td-success-color); font-weight: 600; }
|
&.is-good { color: var(--td-success-color); font-weight: 600; }
|
||||||
&.is-doing { color: var(--td-brand-color); }
|
&.is-doing { color: var(--td-brand-color); }
|
||||||
|
&.is-warn { color: var(--td-warning-color); }
|
||||||
&.is-bad { color: var(--td-error-color); }
|
&.is-bad { color: var(--td-error-color); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 我任讲师课程的【维护课程】入口:小号文字按钮,点击不触发卡片跳转;
|
||||||
|
// 文案颜色与「草稿」状态一致(2026-11 需求:由品牌绿改为橙色)
|
||||||
|
&__maintain {
|
||||||
|
flex-shrink: 0;
|
||||||
|
border: 1px solid var(--td-warning-color);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--td-warning-color);
|
||||||
|
font: inherit;
|
||||||
|
font-size: var(--app-text-sm);
|
||||||
|
line-height: 1;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: var(--app-radius-sm);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all var(--app-motion-fast) ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--td-warning-color);
|
||||||
|
color: var(--td-text-color-anti);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--td-warning-color);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes catalogBarFlow {
|
@keyframes catalogBarFlow {
|
||||||
|
|||||||
@@ -75,8 +75,8 @@
|
|||||||
</t-table>
|
</t-table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 创建课程(5 步关键信息合一:类型/名称/讲师/时间地点/学员范围) -->
|
<!-- 创建课程(信息结构与课程详情弹窗对齐:类型/名称/讲师/时间地点/部门/参加人员/课件/题库) -->
|
||||||
<t-dialog v-model:visible="formVisible" :header="form.mode === 'online' ? '创建线上课程' : '创建线下课程'" width="560">
|
<t-dialog v-model:visible="formVisible" :header="form.mode === 'online' ? '创建线上课程' : '创建线下课程'" width="720">
|
||||||
<t-form label-width="100">
|
<t-form label-width="100">
|
||||||
<t-form-item label="课程名称" required>
|
<t-form-item label="课程名称" required>
|
||||||
<t-input v-model="form.name" placeholder="请输入课程名称" />
|
<t-input v-model="form.name" placeholder="请输入课程名称" />
|
||||||
@@ -97,6 +97,12 @@
|
|||||||
<t-input-number v-model="form.hours" :min="0" :step="0.5" style="width: 48%" />
|
<t-input-number v-model="form.hours" :min="0" :step="0.5" style="width: 48%" />
|
||||||
<t-input-number v-model="form.credits" :min="0" :step="0.5" style="width: 48%; margin-left: 4%" />
|
<t-input-number v-model="form.credits" :min="0" :step="0.5" style="width: 48%; margin-left: 4%" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
|
<t-form-item label="讲师">
|
||||||
|
<!-- 全体员工可选:保存后端自动授予 lecturer 角色;线上课可选(与详情弹窗一致) -->
|
||||||
|
<t-select v-model="form.lecturer_id" clearable filterable :placeholder="form.mode === 'offline' ? '线下课程发布前必须选择讲师' : '从全体员工中选择讲师(可选)'" style="width: 100%">
|
||||||
|
<t-option v-for="o in employeeOptions" :key="o.id" :value="o.id" :label="o.name" />
|
||||||
|
</t-select>
|
||||||
|
</t-form-item>
|
||||||
<t-form-item label="随堂考试">
|
<t-form-item label="随堂考试">
|
||||||
<t-switch v-model="form.exam_enabled" />
|
<t-switch v-model="form.exam_enabled" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
@@ -105,8 +111,16 @@
|
|||||||
<t-select v-model="form.question_bank_id" filterable clearable placeholder="选择题库(可留空)" style="width: 100%">
|
<t-select v-model="form.question_bank_id" filterable clearable placeholder="选择题库(可留空)" style="width: 100%">
|
||||||
<t-option v-for="b in banks" :key="b.id" :value="b.id" :label="`${b.name}(${b.question_count}题)`" />
|
<t-option v-for="b in banks" :key="b.id" :value="b.id" :label="`${b.name}(${b.question_count}题)`" />
|
||||||
</t-select>
|
</t-select>
|
||||||
|
<!-- 上传试题 Excel:创建时先建课再自动建库并关联(与详情弹窗「上传试题」同能力) -->
|
||||||
|
<div class="bank-upload-row">
|
||||||
|
<input ref="createBankInputRef" type="file" accept=".xlsx,.xls" class="bank-upload-input" @change="onCreateBankFileChange" />
|
||||||
|
<t-button variant="outline" size="small" @click="createBankInputRef?.click()">上传试题 Excel</t-button>
|
||||||
|
<span v-if="createBankFile" class="bank-upload-name">{{ createBankFile.name }}</span>
|
||||||
|
<span v-else class="bank-upload-placeholder">未选择文件(可选,与上方题库二选一,文件优先)</span>
|
||||||
|
<t-button v-if="createBankFile" variant="text" size="small" @click="clearCreateBankFile">移除</t-button>
|
||||||
|
</div>
|
||||||
<div class="bank-hint">
|
<div class="bank-hint">
|
||||||
还没有题库?<a class="template-link" href="javascript:void(0)" @click.prevent="downloadTrainingTemplate(QUESTION_TEMPLATE_KEY)">下载试题模板</a>,到「题库与考试 → Excel 批量导入」上传后即可关联
|
还没有题库?<a class="template-link" href="javascript:void(0)" @click.prevent="downloadTrainingTemplate(QUESTION_TEMPLATE_KEY)">下载试题模板</a>填写后直接在此上传,自动建库并关联本课程,原件同步知识库「企业培训(题库)」
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
@@ -124,12 +138,6 @@
|
|||||||
</t-select>
|
</t-select>
|
||||||
<div class="bank-hint">推送内容:上课时间、地点与讲师;课件未上传时不会推送,上传后自动补推。</div>
|
<div class="bank-hint">推送内容:上课时间、地点与讲师;课件未上传时不会推送,上传后自动补推。</div>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
<t-form-item v-if="form.mode === 'offline'" label="讲师">
|
|
||||||
<!-- 全体员工可选:保存后端自动授予 lecturer 角色 -->
|
|
||||||
<t-select v-model="form.lecturer_id" clearable filterable placeholder="从全体员工中选择讲师" style="width: 100%">
|
|
||||||
<t-option v-for="o in employeeOptions" :key="o.id" :value="o.id" :label="o.name" />
|
|
||||||
</t-select>
|
|
||||||
</t-form-item>
|
|
||||||
<t-form-item v-if="form.mode === 'online'" label="学习期限">
|
<t-form-item v-if="form.mode === 'online'" label="学习期限">
|
||||||
<t-select v-model="form.deadlineDays" style="width: 100%">
|
<t-select v-model="form.deadlineDays" style="width: 100%">
|
||||||
<t-option :value="7" label="发布后 7 天内完成" />
|
<t-option :value="7" label="发布后 7 天内完成" />
|
||||||
@@ -149,6 +157,51 @@
|
|||||||
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
|
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
|
||||||
</t-select>
|
</t-select>
|
||||||
</t-form-item>
|
</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-item label="课件登记">
|
<t-form-item label="课件登记">
|
||||||
<TrainingMaterialPicker v-model="material" />
|
<TrainingMaterialPicker v-model="material" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
@@ -255,7 +308,7 @@
|
|||||||
<t-option v-for="p in postOptions" :key="p" :value="p" :label="p" />
|
<t-option v-for="p in postOptions" :key="p" :value="p" :label="p" />
|
||||||
</t-select>
|
</t-select>
|
||||||
<div class="form-hint">
|
<div class="form-hint">
|
||||||
已选 {{ resolvedParticipantMembers.length }} 名员工<template v-if="resolvedParticipantMembers.length">:{{ resolvedParticipantMembers.map((m) => m.user_name || m.employee_no).join('、') }}</template>
|
已选 {{ resolvedParticipantMembers.length }} 名员工<template v-if="resolvedParticipantMembers.length">:{{ resolvedParticipantMembers.map((m) => m.user_name || m.employee_no).join('、') }}</template>;选择「适用部门」后自动带入部门人员,可在此增删;推送与应培人员以本名单为准
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
@@ -428,8 +481,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { MessagePlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import {
|
import {
|
||||||
createMaterial,
|
createMaterial,
|
||||||
@@ -442,7 +495,6 @@ import {
|
|||||||
listCourseChangeLogs,
|
listCourseChangeLogs,
|
||||||
listCourses,
|
listCourses,
|
||||||
listDepts,
|
listDepts,
|
||||||
listEnrollments,
|
|
||||||
listLecturers,
|
listLecturers,
|
||||||
listMaterials,
|
listMaterials,
|
||||||
listMembers,
|
listMembers,
|
||||||
@@ -457,7 +509,6 @@ import {
|
|||||||
type TrainingCourseChangeLog,
|
type TrainingCourseChangeLog,
|
||||||
type TrainingCourseSession,
|
type TrainingCourseSession,
|
||||||
type TrainingDept,
|
type TrainingDept,
|
||||||
type TrainingEnrollment,
|
|
||||||
type TrainingKnowledgeBaseRef,
|
type TrainingKnowledgeBaseRef,
|
||||||
type TrainingKnowledgeBases,
|
type TrainingKnowledgeBases,
|
||||||
type TrainingLecturerOption,
|
type TrainingLecturerOption,
|
||||||
@@ -515,6 +566,18 @@ const onDeptIdsChange = (
|
|||||||
else setter(vals.filter((v) => v !== ALL_DEPT))
|
else setter(vals.filter((v) => v !== ALL_DEPT))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [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)
|
// 详情弹窗的课程信息编辑表单(随打开预填,保存走 saveCourse)
|
||||||
const detailSaving = ref(false)
|
const detailSaving = ref(false)
|
||||||
const editForm = ref({
|
const editForm = ref({
|
||||||
@@ -611,6 +674,65 @@ const form = ref({
|
|||||||
// 课件登记: 上传文件(同步知识库) / 从课件库选择 / 仅登记名称
|
// 课件登记: 上传文件(同步知识库) / 从课件库选择 / 仅登记名称
|
||||||
const material = ref<MaterialPickerValue>({ mode: 'upload', file: null, knowledgeId: '', name: '' })
|
const material = ref<MaterialPickerValue>({ mode: 'upload', file: null, knowledgeId: '', name: '' })
|
||||||
|
|
||||||
|
// ---- 创建弹窗:参加人员(与详情弹窗同构,按人员/部门/岗位) + 上传试题 Excel ----
|
||||||
|
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))
|
||||||
|
})
|
||||||
|
// 上传试题 Excel(可选):保存时先建课再自动建库并关联
|
||||||
|
const createBankInputRef = ref<HTMLInputElement | null>(null)
|
||||||
|
const createBankFile = ref<File | null>(null)
|
||||||
|
const onCreateBankFileChange = (e: Event) => {
|
||||||
|
const input = e.target as HTMLInputElement
|
||||||
|
createBankFile.value = input.files?.[0] || null
|
||||||
|
}
|
||||||
|
const clearCreateBankFile = () => {
|
||||||
|
createBankFile.value = null
|
||||||
|
if (createBankInputRef.value) createBankInputRef.value.value = ''
|
||||||
|
}
|
||||||
|
const resetFormParticipants = () => {
|
||||||
|
formParticipantMode.value = 'member'
|
||||||
|
formParticipantIds.value = []
|
||||||
|
formParticipantDeptIds.value = []
|
||||||
|
formParticipantPostIds.value = []
|
||||||
|
clearCreateBankFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
// [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 = [
|
const courseColumns = [
|
||||||
// 课程名称固定左侧,状态/操作固定右侧:列多横向滚动时首尾始终可见(2026-11 需求)
|
// 课程名称固定左侧,状态/操作固定右侧:列多横向滚动时首尾始终可见(2026-11 需求)
|
||||||
{ colKey: 'name', title: '课程名称', width: 170, fixed: 'left' },
|
{ colKey: 'name', title: '课程名称', width: 170, fixed: 'left' },
|
||||||
@@ -980,9 +1102,10 @@ const loadAll = async () => {
|
|||||||
const openCreate = (mode: 'offline' | 'online') => {
|
const openCreate = (mode: 'offline' | 'online') => {
|
||||||
form.value = {
|
form.value = {
|
||||||
name: '', mode, type: 'required', hours: 2, credits: 1, exam_enabled: false,
|
name: '', mode, type: 'required', hours: 2, credits: 1, exam_enabled: false,
|
||||||
start_at: '', location: '', lecturer_id: '', deadlineDays: 7, dept_ids: [], question_bank_id: '',
|
start_at: '', location: '', notify_mode: 'immediate', lecturer_id: '', deadlineDays: 7, dept_ids: [], question_bank_id: '',
|
||||||
}
|
}
|
||||||
material.value = { mode: 'upload', file: null, knowledgeId: '', name: '' }
|
material.value = { mode: 'upload', file: null, knowledgeId: '', name: '' }
|
||||||
|
resetFormParticipants()
|
||||||
formVisible.value = true
|
formVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1001,6 +1124,9 @@ const onSave = async () => {
|
|||||||
}
|
}
|
||||||
saving.value = true
|
saving.value = true
|
||||||
try {
|
try {
|
||||||
|
// 参加人员(与详情弹窗同构):选中员工写 post_scope,落库后同步为场次学员名单
|
||||||
|
const selectedMembers = resolvedFormMembers.value
|
||||||
|
const postScope = selectedMembers.map((m) => m.user_name || m.employee_no).join('、')
|
||||||
const res = await saveCourse({
|
const res = await saveCourse({
|
||||||
name: form.value.name,
|
name: form.value.name,
|
||||||
mode: form.value.mode,
|
mode: form.value.mode,
|
||||||
@@ -1011,7 +1137,9 @@ const onSave = async () => {
|
|||||||
dept_ids: form.value.dept_ids,
|
dept_ids: form.value.dept_ids,
|
||||||
lecturer_id: form.value.lecturer_id || undefined,
|
lecturer_id: form.value.lecturer_id || undefined,
|
||||||
teach_time: teachTimeOf(form.value),
|
teach_time: teachTimeOf(form.value),
|
||||||
question_bank_id: form.value.question_bank_id || undefined,
|
post_scope: postScope,
|
||||||
|
// 上传了试题 Excel 时以导入建库为准,不再传已有题库 id
|
||||||
|
question_bank_id: (form.value.exam_enabled && !createBankFile.value && form.value.question_bank_id) || undefined,
|
||||||
})
|
})
|
||||||
const course = unwrap(res)
|
const course = unwrap(res)
|
||||||
if (!course) throw new Error('save failed')
|
if (!course) throw new Error('save failed')
|
||||||
@@ -1024,8 +1152,9 @@ const onSave = async () => {
|
|||||||
location: form.value.location,
|
location: form.value.location,
|
||||||
hours: form.value.hours,
|
hours: form.value.hours,
|
||||||
}
|
}
|
||||||
|
let rosterSession: TrainingCourseSession | undefined
|
||||||
if (form.value.mode === 'offline') {
|
if (form.value.mode === 'offline') {
|
||||||
await saveSession({
|
const sessionRes = await saveSession({
|
||||||
course_id: course.id,
|
course_id: course.id,
|
||||||
start_at: form.value.start_at ? new Date(form.value.start_at).toISOString() : '',
|
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() : '',
|
end_at: form.value.start_at ? new Date(new Date(form.value.start_at).getTime() + form.value.hours * 3600 * 1000).toISOString() : '',
|
||||||
@@ -1035,13 +1164,16 @@ const onSave = async () => {
|
|||||||
// [2026-11 推学员] 学员开课通知方式随排课落库
|
// [2026-11 推学员] 学员开课通知方式随排课落库
|
||||||
notify_mode: form.value.notify_mode,
|
notify_mode: form.value.notify_mode,
|
||||||
})
|
})
|
||||||
|
rosterSession = unwrap(sessionRes) || undefined
|
||||||
await refreshSessionCache()
|
await refreshSessionCache()
|
||||||
} else {
|
} else {
|
||||||
await ensureCourseSession(course.id, sessionOpts)
|
rosterSession = await ensureCourseSession(course.id, sessionOpts)
|
||||||
}
|
}
|
||||||
// 适用部门 → 默认学员名单(发布前写入,发布通知即可触达名单成员)
|
// [2026-11 需求] 学员名单以「参加人员」为准:适用部门选择时已自动带入部门人员,
|
||||||
if (form.value.dept_ids.length) {
|
// 此处可增删,实际推送与应培人员按「参加人员」落名单(清空参加人员 = 清空名单)
|
||||||
await syncRosterFromDepts(course.id, form.value.dept_ids, sessionOpts)
|
if (selectedMembers.length || form.value.dept_ids.length) {
|
||||||
|
const session = rosterSession || await ensureCourseSession(course.id, sessionOpts)
|
||||||
|
if (session) await setEnrollments(session.id, selectedMembers.map((m) => m.id))
|
||||||
}
|
}
|
||||||
// 课件登记: 上传→同步知识库;选题库文档→挂接已有知识;仅名称→旧行为。
|
// 课件登记: 上传→同步知识库;选题库文档→挂接已有知识;仅名称→旧行为。
|
||||||
let materialSynced = false
|
let materialSynced = false
|
||||||
@@ -1069,6 +1201,15 @@ const onSave = async () => {
|
|||||||
name: m.name,
|
name: m.name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 上传试题 Excel:课程已建,解析建库并自动关联(原件同步知识库题库)
|
||||||
|
if (form.value.exam_enabled && createBankFile.value) {
|
||||||
|
const fd = new FormData()
|
||||||
|
fd.append('file', createBankFile.value)
|
||||||
|
fd.append('name', createBankFile.value.name.replace(/\.[^.]+$/, ''))
|
||||||
|
fd.append('course_id', course.id)
|
||||||
|
await importQuestionBankExcel(fd)
|
||||||
|
materialSynced = true
|
||||||
|
}
|
||||||
await publishCourse(course.id)
|
await publishCourse(course.id)
|
||||||
MessagePlugin.success(
|
MessagePlugin.success(
|
||||||
materialSynced
|
materialSynced
|
||||||
@@ -1076,6 +1217,7 @@ const onSave = async () => {
|
|||||||
: '课程已保存并发布,讲师与学员通知已生成',
|
: '课程已保存并发布,讲师与学员通知已生成',
|
||||||
)
|
)
|
||||||
formVisible.value = false
|
formVisible.value = false
|
||||||
|
resetFormParticipants()
|
||||||
loadAll()
|
loadAll()
|
||||||
} catch {
|
} catch {
|
||||||
MessagePlugin.error('保存失败,请稍后重试')
|
MessagePlugin.error('保存失败,请稍后重试')
|
||||||
@@ -1123,6 +1265,9 @@ const onDelete = async (row: TrainingCourse) => {
|
|||||||
const openDetail = async (row: TrainingCourse) => {
|
const openDetail = async (row: TrainingCourse) => {
|
||||||
activeCourse.value = row
|
activeCourse.value = row
|
||||||
sessionsVisible.value = true
|
sessionsVisible.value = true
|
||||||
|
// 预填表单触发 dept_ids watcher,先抑制,避免自动带入覆盖 post_scope 回显的名单
|
||||||
|
suppressDetailDeptWatch.value = true
|
||||||
|
void nextTick(() => (suppressDetailDeptWatch.value = false))
|
||||||
// 预填课程信息编辑表单
|
// 预填课程信息编辑表单
|
||||||
editForm.value = {
|
editForm.value = {
|
||||||
name: row.name,
|
name: row.name,
|
||||||
@@ -1134,6 +1279,7 @@ const openDetail = async (row: TrainingCourse) => {
|
|||||||
dept_ids: [...((row.dept_ids as unknown as string[]) || [])],
|
dept_ids: [...((row.dept_ids as unknown as string[]) || [])],
|
||||||
start_at: '',
|
start_at: '',
|
||||||
location: '',
|
location: '',
|
||||||
|
notify_mode: 'immediate',
|
||||||
}
|
}
|
||||||
// 授课时间回填:优先课程授课时间(期望月份默认值 YYYY-MM 展开为当月 1 日),否则回退最近场次排期
|
// 授课时间回填:优先课程授课时间(期望月份默认值 YYYY-MM 展开为当月 1 日),否则回退最近场次排期
|
||||||
const list = courseSessions.value[row.id] || []
|
const list = courseSessions.value[row.id] || []
|
||||||
@@ -1153,7 +1299,13 @@ const openDetail = async (row: TrainingCourse) => {
|
|||||||
const matchedIds = members.value
|
const matchedIds = members.value
|
||||||
.filter((m) => participantNames.includes(m.user_name || ''))
|
.filter((m) => participantNames.includes(m.user_name || ''))
|
||||||
.map((m) => m.id)
|
.map((m) => m.id)
|
||||||
demandSync.value = { participantIds: matchedIds, initialIds: [] }
|
// [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'
|
participantMode.value = 'member'
|
||||||
participantDeptIds.value = []
|
participantDeptIds.value = []
|
||||||
participantPostIds.value = []
|
participantPostIds.value = []
|
||||||
@@ -1294,26 +1446,8 @@ const ensureCourseSession = async (
|
|||||||
return (courseSessions.value[courseId] || [])[0]
|
return (courseSessions.value[courseId] || [])[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 适用部门 → 默认学员名单:把部门下的员工写入场次名单。
|
|
||||||
// 仅当名单为空时初始化,不覆盖人工调整过的名单。
|
|
||||||
const syncRosterFromDepts = async (
|
|
||||||
courseId: string,
|
|
||||||
deptIds: string[],
|
|
||||||
opts: { mode: string; lecturerId?: string; startAt?: string; location?: string; hours?: number },
|
|
||||||
) => {
|
|
||||||
if (!deptIds.length) return
|
|
||||||
const session = await ensureCourseSession(courseId, opts)
|
|
||||||
if (!session) return
|
|
||||||
const res = await listEnrollments(session.id)
|
|
||||||
const current: TrainingEnrollment[] = unwrap(res) || []
|
|
||||||
if (current.length) return
|
|
||||||
const memberIds = members.value.filter((m) => deptIds.includes(m.dept_id)).map((m) => m.id)
|
|
||||||
if (!memberIds.length) return
|
|
||||||
await setEnrollments(session.id, memberIds)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存课程信息:基础信息走 saveCourse;线下课的授课时间/地点同步最近一场排期(无则创建);
|
// 保存课程信息:基础信息走 saveCourse;线下课的授课时间/地点同步最近一场排期(无则创建);
|
||||||
// 适用部门变化时,部门员工默认写入学员名单(名单为空才初始化)。
|
// 学员名单以「参加人员」为准同步(适用部门选择时已自动带入,可增删)。
|
||||||
const onSaveDetail = async () => {
|
const onSaveDetail = async () => {
|
||||||
const row = activeCourse.value
|
const row = activeCourse.value
|
||||||
if (!row) return
|
if (!row) return
|
||||||
@@ -1385,10 +1519,10 @@ const onSaveDetail = async () => {
|
|||||||
} else {
|
} else {
|
||||||
await ensureCourseSession(row.id, sessionOpts)
|
await ensureCourseSession(row.id, sessionOpts)
|
||||||
}
|
}
|
||||||
// 适用部门 → 默认学员名单(线上线下统一,名单为空才初始化)
|
// [2026-11 需求] 学员名单以「参加人员」为准(与场次学员名单合一):
|
||||||
await syncRosterFromDepts(row.id, editForm.value.dept_ids, sessionOpts)
|
// 选择有变化即按选中员工覆盖名单(含清空);未变化且有选中时幂等重写,
|
||||||
// 参加人员与学员名单合一:选择有变化时,以选中员工覆盖场次名单(计入应到人数)
|
// 兜底补齐历史课程空的名单(ReplaceEnrollments 对保留成员不重置状态)
|
||||||
if (rosterChanged && resolvedIds.length) {
|
if (rosterChanged || resolvedIds.length) {
|
||||||
const session = await ensureCourseSession(row.id, sessionOpts)
|
const session = await ensureCourseSession(row.id, sessionOpts)
|
||||||
if (session) {
|
if (session) {
|
||||||
await setEnrollments(session.id, resolvedIds)
|
await setEnrollments(session.id, resolvedIds)
|
||||||
@@ -1401,7 +1535,7 @@ const onSaveDetail = async () => {
|
|||||||
'课程信息已保存' +
|
'课程信息已保存' +
|
||||||
(attached === 'ok' ? ',课件已一并关联' : '') +
|
(attached === 'ok' ? ',课件已一并关联' : '') +
|
||||||
(attached === 'failed' ? ',但课件关联失败,请在详情中重新添加' : '') +
|
(attached === 'failed' ? ',但课件关联失败,请在详情中重新添加' : '') +
|
||||||
(editForm.value.dept_ids.length ? ',适用部门员工已默认写入学员名单' : ''),
|
(rosterChanged || resolvedIds.length ? ',学员名单已按「参加人员」同步' : ''),
|
||||||
)
|
)
|
||||||
sessionsVisible.value = false
|
sessionsVisible.value = false
|
||||||
loadAll()
|
loadAll()
|
||||||
@@ -1412,7 +1546,21 @@ const onSaveDetail = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(loadAll)
|
// 「维护课程」直达:工作台「我的课程」讲师卡片携 ?courseId= 跳入,
|
||||||
|
// 列表加载完成后自动打开该课的课程详情弹窗(找不到对应课程则停留在列表)。
|
||||||
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ const onPreviewSync = async () => {
|
|||||||
syncing.value = true
|
syncing.value = true
|
||||||
try {
|
try {
|
||||||
const res = await previewWecomUseridSync()
|
const res = await previewWecomUseridSync()
|
||||||
syncSummary.value = unwrap(res)
|
syncSummary.value = unwrap(res) ?? null
|
||||||
syncVisible.value = true
|
syncVisible.value = true
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
MessagePlugin.error(err?.response?.data?.message || 'OA 连接失败,请检查 OA_SQLSERVER_* 配置')
|
MessagePlugin.error(err?.response?.data?.message || 'OA 连接失败,请检查 OA_SQLSERVER_* 配置')
|
||||||
|
|||||||
@@ -61,7 +61,12 @@
|
|||||||
>保存</t-button>
|
>保存</t-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="rule-section__fields">
|
<div class="rule-section__fields">
|
||||||
<div v-for="field in schema.fields" :key="field.key" class="rule-field">
|
<div
|
||||||
|
v-for="field in schema.fields"
|
||||||
|
:key="field.key"
|
||||||
|
class="rule-field"
|
||||||
|
:class="{ 'rule-field--block': field.type === 'text' }"
|
||||||
|
>
|
||||||
<span class="rule-field__label">{{ field.label }}</span>
|
<span class="rule-field__label">{{ field.label }}</span>
|
||||||
<t-input-number
|
<t-input-number
|
||||||
v-if="field.type === 'number'"
|
v-if="field.type === 'number'"
|
||||||
@@ -73,10 +78,19 @@
|
|||||||
class="rule-field__input"
|
class="rule-field__input"
|
||||||
/>
|
/>
|
||||||
<t-switch
|
<t-switch
|
||||||
v-else
|
v-else-if="field.type === 'switch'"
|
||||||
v-model="ruleValues[schema.key][field.key]"
|
v-model="ruleValues[schema.key][field.key]"
|
||||||
/>
|
/>
|
||||||
|
<!-- [2026-11 需求] 提醒推送文案等文本模板:整行多行文本,支持 {占位符} -->
|
||||||
|
<t-textarea
|
||||||
|
v-else
|
||||||
|
v-model="ruleValues[schema.key][field.key]"
|
||||||
|
:autosize="{ minRows: 2, maxRows: 4 }"
|
||||||
|
:placeholder="field.placeholder"
|
||||||
|
class="rule-field__textarea"
|
||||||
|
/>
|
||||||
<span v-if="field.unit" class="rule-field__unit">{{ field.unit }}</span>
|
<span v-if="field.unit" class="rule-field__unit">{{ field.unit }}</span>
|
||||||
|
<span v-if="field.vars" class="rule-field__vars">可用变量:{{ field.vars }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="schema.key === 'lecturer_score_weight'" class="rule-sum" :class="{ 'rule-sum--warn': weightSum !== 100 }">
|
<div v-if="schema.key === 'lecturer_score_weight'" class="rule-sum" :class="{ 'rule-sum--warn': weightSum !== 100 }">
|
||||||
@@ -364,10 +378,14 @@ const onDeleteRole = async (row: TrainingRoleDef) => {
|
|||||||
interface RuleFieldDesc {
|
interface RuleFieldDesc {
|
||||||
key: string
|
key: string
|
||||||
label: string
|
label: string
|
||||||
type: 'number' | 'switch'
|
type: 'number' | 'switch' | 'text'
|
||||||
min?: number
|
min?: number
|
||||||
max?: number
|
max?: number
|
||||||
unit?: string
|
unit?: string
|
||||||
|
/** text 字段的输入提示 */
|
||||||
|
placeholder?: string
|
||||||
|
/** text 字段(文案模板)支持的 {占位符} 列表提示 */
|
||||||
|
vars?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RuleSchemaDesc {
|
interface RuleSchemaDesc {
|
||||||
@@ -460,6 +478,51 @@ const RULE_SCHEMAS: RuleSchemaDesc[] = [
|
|||||||
? {}
|
? {}
|
||||||
: { enabled: saved?.enabled !== false, hour: Number(saved?.hour ?? 9) },
|
: { enabled: saved?.enabled !== false, hour: Number(saved?.hour ?? 9) },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// [2026-11 需求] 提醒推送文案可编辑:各提醒场景的标题/内容模板,保存后新推送即刻生效;
|
||||||
|
// {占位符} 渲染时替换为实际值,清空保存即恢复内置默认文案(后端空值回落默认)。
|
||||||
|
key: 'notify_text_templates',
|
||||||
|
title: '提醒推送文案',
|
||||||
|
desc: '各提醒推送的标题与内容模板,支持 {占位符} 替换实际值;清空并保存即恢复内置默认文案,对保存后的新推送生效',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'student_notice_title',
|
||||||
|
label: '学员开课通知 · 标题',
|
||||||
|
type: 'text',
|
||||||
|
placeholder: '培训开课通知',
|
||||||
|
vars: '{course}(仅站内通知标题生效;企微消息自动追加「:课程名」)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'student_notice_content',
|
||||||
|
label: '学员开课通知 · 内容',
|
||||||
|
type: 'text',
|
||||||
|
vars: '{course} 课程名 / {time} 开课时间 / {place} 地点或线上说明 / {lecturer} 讲师(缺省「待定」)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'lecturer_open_title',
|
||||||
|
label: '讲师授课提醒 · 标题',
|
||||||
|
type: 'text',
|
||||||
|
placeholder: '授课提醒',
|
||||||
|
vars: '无需变量(自动追加「:课程名」)',
|
||||||
|
},
|
||||||
|
{ key: 'lecturer_open_footer', label: '讲师授课提醒 · 结尾', type: 'text' },
|
||||||
|
{
|
||||||
|
key: 'lecturer_maintain_title',
|
||||||
|
label: '课程维护提醒 · 标题',
|
||||||
|
type: 'text',
|
||||||
|
placeholder: '课程维护提醒',
|
||||||
|
vars: '无需变量(自动追加「:课程名」)',
|
||||||
|
},
|
||||||
|
{ key: 'lecturer_maintain_footer', label: '课程维护提醒 · 结尾', type: 'text' },
|
||||||
|
{ key: 'weekly_title', label: '周一讲师提醒 · 标题', type: 'text', vars: '{year} / {month} / {week}' },
|
||||||
|
{
|
||||||
|
key: 'weekly_content',
|
||||||
|
label: '周一讲师提醒 · 内容',
|
||||||
|
type: 'text',
|
||||||
|
vars: '{year} / {month} / {week} / {week_start} / {week_end} 本周起止(MM-DD) / {count} 未结束场次',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'pass_line',
|
key: 'pass_line',
|
||||||
title: '岗位胜任达标线',
|
title: '岗位胜任达标线',
|
||||||
@@ -485,6 +548,19 @@ const DEFAULT_RULE_VALUES: Record<string, Record<string, any>> = {
|
|||||||
notify_remind_days: { t3: true, t1: true },
|
notify_remind_days: { t3: true, t1: true },
|
||||||
notify_push_enabled: { enabled: true },
|
notify_push_enabled: { enabled: true },
|
||||||
notify_weekly_lecturer: { enabled: true, hour: 9 },
|
notify_weekly_lecturer: { enabled: true, hour: 9 },
|
||||||
|
// [2026-11 需求] 提醒推送文案默认模板(与后端 defaultNotifyTextTemplates 逐字一致)
|
||||||
|
notify_text_templates: {
|
||||||
|
student_notice_title: '培训开课通知',
|
||||||
|
student_notice_content: '您被点名参加「{course}」培训:{time},{place},讲师:{lecturer}。请准时参加。',
|
||||||
|
lecturer_open_title: '授课提醒',
|
||||||
|
lecturer_open_footer: '请准时参加,详情见培训平台。',
|
||||||
|
lecturer_maintain_title: '课程维护提醒',
|
||||||
|
lecturer_maintain_footer:
|
||||||
|
'该课程尚未上传课件/学习材料,请尽快登录培训平台补齐,以免影响学员课前学习。',
|
||||||
|
weekly_title: '{year}年{month}月教育训练(第{week}周提醒)',
|
||||||
|
weekly_content:
|
||||||
|
'{month} 月已进入第 {week} 周({week_start} 至 {week_end}),您本月仍有 {count} 场培训未结束,请与人事约定培训时间并于月内完成课件、签到与评价。',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const RULE_SCHEMA_KEYS = new Set(RULE_SCHEMAS.map((s) => s.key))
|
const RULE_SCHEMA_KEYS = new Set(RULE_SCHEMAS.map((s) => s.key))
|
||||||
@@ -862,6 +938,24 @@ watch(pushScene, () => loadPushLogs())
|
|||||||
font-size: var(--app-text-sm);
|
font-size: var(--app-text-sm);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 文案模板等长文本:整行块状布局(标签一行 + 多行输入 + 变量提示)
|
||||||
|
&--block {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
width: 100%;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__textarea {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__vars {
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
font-size: var(--app-text-xs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.rule-sum {
|
.rule-sum {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"academy/internal/errors"
|
"academy/internal/errors"
|
||||||
@@ -99,6 +101,103 @@ func (s *trainingService) weeklyLecturerRule(ctx context.Context, tenantID uint6
|
|||||||
return enabled, hour
|
return enabled, hour
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 推送文案模板([2026-11 需求] 配置中心「提醒推送文案」可编辑,空字段回落默认)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// notifyTextTemplates 各提醒场景的文案模板,占位符形如 {course}/{time};
|
||||||
|
// 只做占位符替换不引入富模板语法,避免配置中心编辑出语法错误。
|
||||||
|
type notifyTextTemplates struct {
|
||||||
|
// 学员开课通知(scene=session_notice_student):站内标题与内容
|
||||||
|
StudentNoticeTitle string `json:"student_notice_title"`
|
||||||
|
StudentNoticeContent string `json:"student_notice_content"`
|
||||||
|
// 讲师授课提醒(T-N):通知标题前缀与企微 markdown 结尾文案
|
||||||
|
//(标题自动追加「:课程名」,无需占位符;结尾文案同时用于 T-1 学员企微消息)
|
||||||
|
LecturerOpenTitle string `json:"lecturer_open_title"`
|
||||||
|
LecturerOpenFooter string `json:"lecturer_open_footer"`
|
||||||
|
// 课程维护提醒(临近开课仍缺课件):通知标题前缀与结尾文案
|
||||||
|
LecturerMaintainTitle string `json:"lecturer_maintain_title"`
|
||||||
|
LecturerMaintainFooter string `json:"lecturer_maintain_footer"`
|
||||||
|
// 周一讲师未完成汇总提醒:标题与内容
|
||||||
|
WeeklyTitle string `json:"weekly_title"`
|
||||||
|
WeeklyContent string `json:"weekly_content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内置默认文案(与历史硬编码逐字一致;{lecturer} 缺讲师时渲染为「待定」)。
|
||||||
|
const (
|
||||||
|
defaultStudentNoticeTitle = "培训开课通知"
|
||||||
|
defaultStudentNoticeContent = "您被点名参加「{course}」培训:{time},{place},讲师:{lecturer}。请准时参加。"
|
||||||
|
defaultLecturerOpenTitle = "授课提醒"
|
||||||
|
defaultLecturerOpenFooter = "请准时参加,详情见培训平台。"
|
||||||
|
defaultLecturerMaintainTitle = "课程维护提醒"
|
||||||
|
defaultLecturerMaintainFooter = "该课程尚未上传课件/学习材料,请尽快登录培训平台补齐,以免影响学员课前学习。"
|
||||||
|
defaultWeeklyTitle = "{year}年{month}月教育训练(第{week}周提醒)"
|
||||||
|
defaultWeeklyContent = "{month} 月已进入第 {week} 周({week_start} 至 {week_end}),您本月仍有 {count} 场培训未结束,请与人事约定培训时间并于月内完成课件、签到与评价。"
|
||||||
|
)
|
||||||
|
|
||||||
|
func defaultNotifyTextTemplates() notifyTextTemplates {
|
||||||
|
return notifyTextTemplates{
|
||||||
|
StudentNoticeTitle: defaultStudentNoticeTitle,
|
||||||
|
StudentNoticeContent: defaultStudentNoticeContent,
|
||||||
|
LecturerOpenTitle: defaultLecturerOpenTitle,
|
||||||
|
LecturerOpenFooter: defaultLecturerOpenFooter,
|
||||||
|
LecturerMaintainTitle: defaultLecturerMaintainTitle,
|
||||||
|
LecturerMaintainFooter: defaultLecturerMaintainFooter,
|
||||||
|
WeeklyTitle: defaultWeeklyTitle,
|
||||||
|
WeeklyContent: defaultWeeklyContent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseNotifyTextTemplates 解析租户配置(空字段回落默认,解析失败整体用默认);
|
||||||
|
// trainingService(经 repo)与 TrainingScheduler(直查 db)共用。
|
||||||
|
func parseNotifyTextTemplates(raw []byte) notifyTextTemplates {
|
||||||
|
t := defaultNotifyTextTemplates()
|
||||||
|
var saved notifyTextTemplates
|
||||||
|
if len(raw) == 0 || json.Unmarshal(raw, &saved) != nil {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
fill := func(dst *string, v string) {
|
||||||
|
if strings.TrimSpace(v) != "" {
|
||||||
|
*dst = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fill(&t.StudentNoticeTitle, saved.StudentNoticeTitle)
|
||||||
|
fill(&t.StudentNoticeContent, saved.StudentNoticeContent)
|
||||||
|
fill(&t.LecturerOpenTitle, saved.LecturerOpenTitle)
|
||||||
|
fill(&t.LecturerOpenFooter, saved.LecturerOpenFooter)
|
||||||
|
fill(&t.LecturerMaintainTitle, saved.LecturerMaintainTitle)
|
||||||
|
fill(&t.LecturerMaintainFooter, saved.LecturerMaintainFooter)
|
||||||
|
fill(&t.WeeklyTitle, saved.WeeklyTitle)
|
||||||
|
fill(&t.WeeklyContent, saved.WeeklyContent)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadNotifyTextTemplates 读取配置中心 notify_text_templates(缺行 = 全默认)。
|
||||||
|
func (s *trainingService) loadNotifyTextTemplates(ctx context.Context, tenantID uint64) notifyTextTemplates {
|
||||||
|
rules, err := s.repo.ListRuleConfigs(ctx, tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return defaultNotifyTextTemplates()
|
||||||
|
}
|
||||||
|
for _, rule := range rules {
|
||||||
|
if rule.RuleKey == ruleKeyNotifyTextTemplates {
|
||||||
|
return parseNotifyTextTemplates(rule.RuleValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultNotifyTextTemplates()
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderNotifyTemplate {name} 占位符替换;模板为空返回空串,未提供的占位符原样保留。
|
||||||
|
func renderNotifyTemplate(tpl string, vars map[string]string) string {
|
||||||
|
if tpl == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
pairs := make([]string, 0, len(vars)*2)
|
||||||
|
for k, v := range vars {
|
||||||
|
pairs = append(pairs, "{"+k+"}", v)
|
||||||
|
}
|
||||||
|
return strings.NewReplacer(pairs...).Replace(tpl)
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// 学员开课通知(immediate 立即推 / day_before 调度器推,共用 scene 幂等)
|
// 学员开课通知(immediate 立即推 / day_before 调度器推,共用 scene 幂等)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -134,23 +233,26 @@ func (s *trainingService) sessionNoticeTargets(ctx context.Context, tenantID uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sessionNoticeText 组装学员开课通知文案(时间/地点或线上链接/讲师)。
|
// sessionNoticeText 组装学员开课通知文案(时间/地点或线上链接/讲师)。
|
||||||
|
// [2026-11 需求] 文案模板在配置中心「提醒推送文案」可编辑;占位符:
|
||||||
|
// {course} 课程名 / {time} 开课时间 / {place} 地点或线上说明 / {lecturer} 讲师(缺省渲染「待定」)。
|
||||||
func (s *trainingService) sessionNoticeText(ctx context.Context, tenantID uint64, session *types.TrainingCourseSession) (string, string) {
|
func (s *trainingService) sessionNoticeText(ctx context.Context, tenantID uint64, session *types.TrainingCourseSession) (string, string) {
|
||||||
courseName := sessionCourseTitle(ctx, s, tenantID, session)
|
courseName := sessionCourseTitle(ctx, s, tenantID, session)
|
||||||
title := "培训开课通知"
|
|
||||||
place := session.Location
|
place := session.Location
|
||||||
if session.OnlineURL != "" {
|
if session.OnlineURL != "" {
|
||||||
place = "线上会议(链接见课程页)"
|
place = "线上会议(链接见课程页)"
|
||||||
}
|
}
|
||||||
lecturerName := ""
|
lecturerName := "待定"
|
||||||
if lecturer, err := s.repo.GetMember(ctx, tenantID, session.LecturerID); err == nil && lecturer != nil {
|
if lecturer, err := s.repo.GetMember(ctx, tenantID, session.LecturerID); err == nil && lecturer != nil && lecturer.UserName != "" {
|
||||||
lecturerName = lecturer.UserName
|
lecturerName = lecturer.UserName
|
||||||
}
|
}
|
||||||
content := fmt.Sprintf("您被点名参加「%s」培训:%s,%s。请准时参加。",
|
tpl := s.loadNotifyTextTemplates(ctx, tenantID)
|
||||||
courseName, sessionTimeText(session), place)
|
title := renderNotifyTemplate(tpl.StudentNoticeTitle, map[string]string{"course": courseName})
|
||||||
if lecturerName != "" {
|
content := renderNotifyTemplate(tpl.StudentNoticeContent, map[string]string{
|
||||||
content = fmt.Sprintf("您被点名参加「%s」培训:%s,%s,讲师:%s。请准时参加。",
|
"course": courseName,
|
||||||
courseName, sessionTimeText(session), place, lecturerName)
|
"time": sessionTimeText(session),
|
||||||
}
|
"place": place,
|
||||||
|
"lecturer": lecturerName,
|
||||||
|
})
|
||||||
return title, content
|
return title, content
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,9 +485,21 @@ func (s *trainingService) enqueueWeeklyLecturerReminders(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
title := fmt.Sprintf("%d年%d月教育训练(第%d周提醒)", local.Year(), int(local.Month()), weekOfMonth(local))
|
// [2026-11 需求] 文案模板在配置中心「提醒推送文案」可编辑;占位符:
|
||||||
|
// {year} 年 / {month} 月 / {week} 当月第几周 / {week_start} {week_end} 本周起止(MM-DD) / {count} 未结束场次数
|
||||||
|
tpl := s.loadNotifyTextTemplates(ctx, tenantID)
|
||||||
|
baseVars := map[string]string{
|
||||||
|
"year": strconv.Itoa(local.Year()),
|
||||||
|
"month": strconv.Itoa(int(local.Month())),
|
||||||
|
"week": strconv.Itoa(weekOfMonth(local)),
|
||||||
|
"week_start": "",
|
||||||
|
"week_end": "",
|
||||||
|
}
|
||||||
weekStart := local.AddDate(0, 0, -int(local.Weekday()+6)%7)
|
weekStart := local.AddDate(0, 0, -int(local.Weekday()+6)%7)
|
||||||
weekEnd := weekStart.AddDate(0, 0, 6)
|
weekEnd := weekStart.AddDate(0, 0, 6)
|
||||||
|
baseVars["week_start"] = weekStart.Format("01-02")
|
||||||
|
baseVars["week_end"] = weekEnd.Format("01-02")
|
||||||
|
title := renderNotifyTemplate(tpl.WeeklyTitle, baseVars)
|
||||||
rows := make([]*types.TrainingNotification, 0, len(pending))
|
rows := make([]*types.TrainingNotification, 0, len(pending))
|
||||||
for lecturerMemberID, count := range pending {
|
for lecturerMemberID, count := range pending {
|
||||||
member, err := s.repo.GetMember(ctx, tenantID, lecturerMemberID)
|
member, err := s.repo.GetMember(ctx, tenantID, lecturerMemberID)
|
||||||
@@ -396,9 +510,12 @@ func (s *trainingService) enqueueWeeklyLecturerReminders(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
notified[member.UserID] = true
|
notified[member.UserID] = true
|
||||||
content := fmt.Sprintf(
|
vars := make(map[string]string, len(baseVars)+1)
|
||||||
"%d 月已进入第 %d 周(%s 至 %s),您本月仍有 %d 场培训未结束,请与人事约定培训时间并于月内完成课件、签到与评价。",
|
for k, v := range baseVars {
|
||||||
int(local.Month()), weekOfMonth(local), weekStart.Format("01-02"), weekEnd.Format("01-02"), count)
|
vars[k] = v
|
||||||
|
}
|
||||||
|
vars["count"] = strconv.Itoa(count)
|
||||||
|
content := renderNotifyTemplate(tpl.WeeklyContent, vars)
|
||||||
status := ""
|
status := ""
|
||||||
if push {
|
if push {
|
||||||
status = pushStatusPending
|
status = pushStatusPending
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// training_notify_test.go 推送文案模板(配置中心「提醒推送文案」)的解析与渲染。
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseNotifyTextTemplatesFallsBackToDefaults(t *testing.T) {
|
||||||
|
// 缺行/损坏 JSON → 整体内置默认
|
||||||
|
require.Equal(t, defaultNotifyTextTemplates(), parseNotifyTextTemplates(nil))
|
||||||
|
require.Equal(t, defaultNotifyTextTemplates(), parseNotifyTextTemplates([]byte("not json")))
|
||||||
|
|
||||||
|
// 自定义字段生效,空字段回落默认(配置中心"清空即恢复默认")
|
||||||
|
raw, err := json.Marshal(map[string]any{
|
||||||
|
"student_notice_title": "自定义开课标题",
|
||||||
|
"student_notice_content": "",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
got := parseNotifyTextTemplates(raw)
|
||||||
|
require.Equal(t, "自定义开课标题", got.StudentNoticeTitle)
|
||||||
|
require.Equal(t, defaultStudentNoticeContent, got.StudentNoticeContent)
|
||||||
|
require.Equal(t, defaultWeeklyTitle, got.WeeklyTitle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderNotifyTemplate(t *testing.T) {
|
||||||
|
require.Equal(t, "", renderNotifyTemplate("", map[string]string{"course": "x"}))
|
||||||
|
require.Equal(t,
|
||||||
|
"您被点名参加「安全培训」培训:11月18日 09:00,大会议室。请准时参加。",
|
||||||
|
renderNotifyTemplate("您被点名参加「{course}」培训:{time},{place}。请准时参加。",
|
||||||
|
map[string]string{"course": "安全培训", "time": "11月18日 09:00", "place": "大会议室"}))
|
||||||
|
// 未提供变量的占位符原样保留(不做删改,便于发现漏配)
|
||||||
|
require.Equal(t, "{a}-x", renderNotifyTemplate("{a}-{b}", map[string]string{"b": "x"}))
|
||||||
|
}
|
||||||
@@ -169,6 +169,8 @@ func (s *trainingService) SettleLecturerScores(ctx context.Context, tenantID uin
|
|||||||
// 配置中心"初始化默认配置"与高级配置可见性)。
|
// 配置中心"初始化默认配置"与高级配置可见性)。
|
||||||
func defaultRuleSeed() map[string]string {
|
func defaultRuleSeed() map[string]string {
|
||||||
roleDictRaw, _ := json.Marshal(map[string]any{"roles": types.DefaultRoleDict()})
|
roleDictRaw, _ := json.Marshal(map[string]any{"roles": types.DefaultRoleDict()})
|
||||||
|
// [2026-11 需求] 提醒推送文案默认模板(配置中心「提醒推送文案」卡)
|
||||||
|
notifyTextRaw, _ := json.Marshal(defaultNotifyTextTemplates())
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
types.RuleKeyLecturerScoreWeight: `{"on_time":40,"rating":50,"qa":10}`,
|
types.RuleKeyLecturerScoreWeight: `{"on_time":40,"rating":50,"qa":10}`,
|
||||||
types.RuleKeyPointRules: `{"required":10,"score_90":10,"score_100":20,"pass":5,"elective":5,"self_study":3}`,
|
types.RuleKeyPointRules: `{"required":10,"score_90":10,"score_100":20,"pass":5,"elective":5,"self_study":3}`,
|
||||||
@@ -180,6 +182,7 @@ func defaultRuleSeed() map[string]string {
|
|||||||
ruleKeyNotifyRemindDays: `[3,1]`,
|
ruleKeyNotifyRemindDays: `[3,1]`,
|
||||||
ruleKeyNotifyPushEnabled: `true`,
|
ruleKeyNotifyPushEnabled: `true`,
|
||||||
ruleKeyNotifyWeeklyLecturer: `{"enabled":true,"hour":9}`,
|
ruleKeyNotifyWeeklyLecturer: `{"enabled":true,"hour":9}`,
|
||||||
|
ruleKeyNotifyTextTemplates: string(notifyTextRaw),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ const (
|
|||||||
ruleKeyNotifyWeeklyLecturer = "notify_weekly_lecturer"
|
ruleKeyNotifyWeeklyLecturer = "notify_weekly_lecturer"
|
||||||
ruleKeyNotifyWeeklyLecturerEnabled = "notify_weekly_lecturer_enabled"
|
ruleKeyNotifyWeeklyLecturerEnabled = "notify_weekly_lecturer_enabled"
|
||||||
ruleKeyNotifyWeeklyRemindHour = "notify_weekly_remind_hour"
|
ruleKeyNotifyWeeklyRemindHour = "notify_weekly_remind_hour"
|
||||||
|
// ruleKeyNotifyTextTemplates [2026-11 需求] 提醒推送文案模板(配置中心可编辑,
|
||||||
|
// 空字段回落 training_notify.go 的内置默认文案)。
|
||||||
|
ruleKeyNotifyTextTemplates = "notify_text_templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sendingReclaimAfter bounds how long a claimed row may stay 'sending'
|
// sendingReclaimAfter bounds how long a claimed row may stay 'sending'
|
||||||
@@ -216,6 +219,8 @@ type tenantNotifyConfig struct {
|
|||||||
remindDays []int
|
remindDays []int
|
||||||
lecturerMaintainIn int
|
lecturerMaintainIn int
|
||||||
pushEnabled bool
|
pushEnabled bool
|
||||||
|
// texts 提醒推送文案模板([2026-11 需求] 配置中心「提醒推送文案」可编辑)
|
||||||
|
texts notifyTextTemplates
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TrainingScheduler) generateReminders(ctx context.Context) error {
|
func (s *TrainingScheduler) generateReminders(ctx context.Context) error {
|
||||||
@@ -257,6 +262,7 @@ func (s *TrainingScheduler) defaultNotifyConfig() tenantNotifyConfig {
|
|||||||
remindDays: days,
|
remindDays: days,
|
||||||
lecturerMaintainIn: s.cfg.LecturerMaintainDays,
|
lecturerMaintainIn: s.cfg.LecturerMaintainDays,
|
||||||
pushEnabled: true,
|
pushEnabled: true,
|
||||||
|
texts: defaultNotifyTextTemplates(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +273,7 @@ func (s *TrainingScheduler) loadNotifyConfig(ctx context.Context, tenantID uint6
|
|||||||
var rules []types.TrainingRuleConfig
|
var rules []types.TrainingRuleConfig
|
||||||
err := s.db.WithContext(ctx).
|
err := s.db.WithContext(ctx).
|
||||||
Where("tenant_id = ? AND rule_key IN ?", tenantID,
|
Where("tenant_id = ? AND rule_key IN ?", tenantID,
|
||||||
[]string{ruleKeyNotifyRemindDays, ruleKeyNotifyLecturerMaintainDay, ruleKeyNotifyPushEnabled}).
|
[]string{ruleKeyNotifyRemindDays, ruleKeyNotifyLecturerMaintainDay, ruleKeyNotifyPushEnabled, ruleKeyNotifyTextTemplates}).
|
||||||
Find(&rules).Error
|
Find(&rules).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
@@ -297,6 +303,9 @@ func (s *TrainingScheduler) loadNotifyConfig(ctx context.Context, tenantID uint6
|
|||||||
if json.Unmarshal(rule.RuleValue, &enabled) == nil {
|
if json.Unmarshal(rule.RuleValue, &enabled) == nil {
|
||||||
cfg.pushEnabled = enabled
|
cfg.pushEnabled = enabled
|
||||||
}
|
}
|
||||||
|
case ruleKeyNotifyTextTemplates:
|
||||||
|
// [2026-11 需求] 提醒推送文案模板(空字段回落内置默认)
|
||||||
|
cfg.texts = parseNotifyTextTemplates(rule.RuleValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
@@ -341,7 +350,7 @@ func (s *TrainingScheduler) generateForTenant(
|
|||||||
if sess.LecturerID != "" {
|
if sess.LecturerID != "" {
|
||||||
rows := []*types.TrainingNotification{s.newReminderRow(tenantID, sess.LecturerID,
|
rows := []*types.TrainingNotification{s.newReminderRow(tenantID, sess.LecturerID,
|
||||||
types.TrainingRemindScene(d, true),
|
types.TrainingRemindScene(d, true),
|
||||||
remindTitle("授课提醒", course), remindContent(course, &sess, false),
|
remindTitle(cfg.texts.LecturerOpenTitle, course), remindContent(course, &sess, false, cfg.texts.LecturerOpenFooter),
|
||||||
sess.ID, cfg.pushEnabled, now)}
|
sess.ID, cfg.pushEnabled, now)}
|
||||||
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -365,7 +374,7 @@ func (s *TrainingScheduler) generateForTenant(
|
|||||||
for _, uid := range targets {
|
for _, uid := range targets {
|
||||||
rows = append(rows, s.newReminderRow(tenantID, uid,
|
rows = append(rows, s.newReminderRow(tenantID, uid,
|
||||||
types.SceneSessionNoticeStudent,
|
types.SceneSessionNoticeStudent,
|
||||||
remindTitle("培训开课通知", course), remindContent(course, &sess, false),
|
remindTitle(cfg.texts.StudentNoticeTitle, course), remindContent(course, &sess, false, cfg.texts.LecturerOpenFooter),
|
||||||
sess.ID, cfg.pushEnabled, now))
|
sess.ID, cfg.pushEnabled, now))
|
||||||
}
|
}
|
||||||
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
||||||
@@ -389,7 +398,7 @@ func (s *TrainingScheduler) generateForTenant(
|
|||||||
}
|
}
|
||||||
rows := []*types.TrainingNotification{s.newReminderRow(tenantID, sess.LecturerID,
|
rows := []*types.TrainingNotification{s.newReminderRow(tenantID, sess.LecturerID,
|
||||||
types.SceneRemindLecturerMaintain,
|
types.SceneRemindLecturerMaintain,
|
||||||
remindTitle("课程维护提醒", course), remindContent(course, &sess, true),
|
remindTitle(cfg.texts.LecturerMaintainTitle, course), remindContent(course, &sess, true, cfg.texts.LecturerMaintainFooter),
|
||||||
sess.ID, cfg.pushEnabled, now)}
|
sess.ID, cfg.pushEnabled, now)}
|
||||||
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
if err := s.insertNotifications(ctx, tenantID, sess.ID, rows); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -718,7 +727,8 @@ func remindTitle(prefix string, course types.TrainingCourse) string {
|
|||||||
|
|
||||||
// remindContent renders the WeCom markdown body of a session reminder; the
|
// remindContent renders the WeCom markdown body of a session reminder; the
|
||||||
// maintain variant asks the lecturer to upload missing materials.
|
// maintain variant asks the lecturer to upload missing materials.
|
||||||
func remindContent(course types.TrainingCourse, sess *types.TrainingCourseSession, maintain bool) string {
|
// [2026-11 需求] 结尾文案 footer 由配置中心「提醒推送文案」提供(缺省为内置默认)。
|
||||||
|
func remindContent(course types.TrainingCourse, sess *types.TrainingCourseSession, maintain bool, footer string) string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
if maintain {
|
if maintain {
|
||||||
b.WriteString("**【课程维护提醒】**\n")
|
b.WriteString("**【课程维护提醒】**\n")
|
||||||
@@ -737,10 +747,14 @@ func remindContent(course types.TrainingCourse, sess *types.TrainingCourseSessio
|
|||||||
case sess.Location != "":
|
case sess.Location != "":
|
||||||
b.WriteString(fmt.Sprintf("> 地点:%s\n", sess.Location))
|
b.WriteString(fmt.Sprintf("> 地点:%s\n", sess.Location))
|
||||||
}
|
}
|
||||||
|
footer = strings.TrimSpace(footer)
|
||||||
|
if footer == "" {
|
||||||
if maintain {
|
if maintain {
|
||||||
b.WriteString("\n该课程尚未上传课件/学习材料,请尽快登录培训平台补齐,以免影响学员课前学习。")
|
footer = defaultLecturerMaintainFooter
|
||||||
} else {
|
} else {
|
||||||
b.WriteString("\n请准时参加,详情见培训平台。")
|
footer = defaultLecturerOpenFooter
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
b.WriteString("\n" + footer)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
@@ -323,12 +323,12 @@ func TestRemindContent(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
course := courses[sess.CourseID]
|
course := courses[sess.CourseID]
|
||||||
|
|
||||||
student := remindContent(course, &sess, false)
|
student := remindContent(course, &sess, false, defaultLecturerOpenFooter)
|
||||||
require.Contains(t, student, "安全生产培训")
|
require.Contains(t, student, "安全生产培训")
|
||||||
require.Contains(t, student, sess.StartAt.Local().Format("2006-01-02 15:04"))
|
require.Contains(t, student, sess.StartAt.Local().Format("2006-01-02 15:04"))
|
||||||
require.Contains(t, student, "三楼会议室")
|
require.Contains(t, student, "三楼会议室")
|
||||||
|
|
||||||
maintain := remindContent(course, &sess, true)
|
maintain := remindContent(course, &sess, true, defaultLecturerMaintainFooter)
|
||||||
require.Contains(t, maintain, "课程维护提醒")
|
require.Contains(t, maintain, "课程维护提醒")
|
||||||
require.True(t, strings.Contains(maintain, "课件"), "maintain copy mentions materials")
|
require.True(t, strings.Contains(maintain, "课件"), "maintain copy mentions materials")
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user