diff --git a/frontend/src/api/org-center/index.ts b/frontend/src/api/org-center/index.ts index 28ba902..f7cc55f 100644 --- a/frontend/src/api/org-center/index.ts +++ b/frontend/src/api/org-center/index.ts @@ -1,6 +1,8 @@ import { get, post, put, del } from '@/utils/request' import { unwrap } from '@/api/training' import type { WecomSyncSummary } from '@/api/training' +// 部门名展示清洗:剥离企微同步残留的「e10-<企微部门ID>」字样(2026-11 需求) +import { cleanDeptName, filterVisibleDepts } from '@/utils/deptName' // 组织中心(租户级共享组织架构)API 封装,对应后端 /api/v1/org/*(routes_org.go)。 // 部门/员工档案归租户所有;业务模块(企业培训/图纸标注/物料检核...)通过 @@ -67,7 +69,11 @@ export interface OrgPagedData { // ---- 部门 ---- -export const listDepts = () => get<{ success: boolean; data: OrgDept[] }>(`${base}/depts`) +// listDepts 部门树(2026-11 需求):整段即「e10-」的无名部门不进入部门表/下拉。 +export const listDepts = async () => { + const res = await get<{ success: boolean; data: OrgDept[] }>(`${base}/depts`) + return filterVisibleDepts(unwrap(res)) +} /** 新增/修改部门:id 为空走新增,否则更新。 */ export const saveDept = (payload: Partial) => @@ -77,8 +83,15 @@ export const deleteDept = (id: string) => del<{ success: boolean }>(`${base}/dep // ---- 员工档案 ---- -export const listEmployees = (query?: OrgListQuery) => - get<{ success: boolean; data: OrgPagedData }>(`${base}/employees`, { params: query }) +// listEmployees 员工档案分页(2026-11 需求):联查展示字段 dept_name 剥离「e10-」残留字样。 +export const listEmployees = async (query?: OrgListQuery) => { + const res = await get<{ success: boolean; data: OrgPagedData }>(`${base}/employees`, { params: query }) + const pageData = unwrap>(res) + if (pageData?.items?.length) { + for (const m of pageData.items) m.dept_name = cleanDeptName(m.dept_name) + } + return pageData +} // listAllOrgEmployees 拉取全量员工档案(分页循环,直到取满 total 或空页)。 // [2026-11-30] 档案超过 500 条后,单页 page_size=500 会把最早建档的员工截断 @@ -114,8 +127,13 @@ export interface OrgPlatformUser { in_roster: boolean } -export const listPlatformUsers = () => - get<{ success: boolean; data: OrgPlatformUser[] }>(`${base}/platform-users`) +// listPlatformUsers 平台账号列表(2026-11 需求):users.dept_name 同步剥离「e10-」残留字样。 +export const listPlatformUsers = async () => { + const res = await get<{ success: boolean; data: OrgPlatformUser[] }>(`${base}/platform-users`) + const users = unwrap(res) || [] + for (const u of users) u.dept_name = cleanDeptName(u.dept_name) + return users +} export interface OrgImportEmployee { user_id: string diff --git a/frontend/src/api/training/index.ts b/frontend/src/api/training/index.ts index 69364ea..1e932b5 100644 --- a/frontend/src/api/training/index.ts +++ b/frontend/src/api/training/index.ts @@ -1,4 +1,6 @@ import { get, post, put, del, getDown } from '@/utils/request' +// 部门名展示清洗:剥离企微同步残留的「e10-<企微部门ID>」字样(2026-11 需求) +import { cleanDeptName, filterVisibleDepts } from '@/utils/deptName' // 企业培训业务域 API 封装(对应后端 /api/v1/training/*,routes_training.go)。 // 数据形状镜像 internal/types/training.go。 @@ -74,8 +76,11 @@ export interface TrainingMember { dept_name?: string } -export const listDepts = () => - get<{ success: boolean; data: TrainingDept[] }>(`${base}/depts`) +// listDepts 部门表(2026-11 需求):整段即「e10-」的无名部门不进入下拉/展示。 +export const listDepts = async () => { + const res = await get<{ success: boolean; data: TrainingDept[] }>(`${base}/depts`) + return filterVisibleDepts(unwrap(res)) +} export const saveDept = (payload: Partial) => post<{ success: boolean; data: TrainingDept }>(`${base}/depts`, payload) @@ -83,8 +88,16 @@ export const saveDept = (payload: Partial) => export const deleteDept = (id: string) => del<{ success: boolean }>(`${base}/depts/${enc(id)}`) -export const listMembers = (query?: ListQuery) => - get<{ success: boolean; data: PagedData }>(`${base}/members`, { params: query }) +// listMembers 员工名册分页(2026-11 需求):联查展示字段 dept_name 剥离 +// 「e10-」残留字样,选人标签/部门展示统一干净。 +export const listMembers = async (query?: ListQuery) => { + const res = await get<{ success: boolean; data: PagedData }>(`${base}/members`, { params: query }) + const pageData = unwrap>(res) + if (pageData?.items?.length) { + for (const m of pageData.items) m.dept_name = cleanDeptName(m.dept_name) + } + return pageData +} // listAllTrainingMembers 拉取全量员工名册(分页循环,直到取满 total 或空页)。 // [2026-11-29 复测] 名册超过 500 人后,单页 page_size=500 会把老批次员工 diff --git a/frontend/src/utils/deptName.test.ts b/frontend/src/utils/deptName.test.ts new file mode 100644 index 0000000..c9219e1 --- /dev/null +++ b/frontend/src/utils/deptName.test.ts @@ -0,0 +1,47 @@ +import assert from 'node:assert/strict' +import { test } from 'node:test' +import { cleanDeptName, cleanDeptNameText, displayDeptName, filterVisibleDepts, isSyntheticDeptName } from './deptName' + +test('cleanDeptName strips e10- tokens and trims', () => { + assert.equal(cleanDeptName('e10-1115765553620631553'), '') + assert.equal(cleanDeptName('研发技术课'), '研发技术课') + assert.equal(cleanDeptName('研发组 e10-1172161210096713736'), '研发组') + assert.equal(cleanDeptName('e10-111 e10-222 研发组'), '研发组') + assert.equal(cleanDeptName(' E10-1172161210096713736 '), '') + assert.equal(cleanDeptName(null), '') + assert.equal(cleanDeptName(undefined), '') +}) + +test('isSyntheticDeptName detects nameless synced depts', () => { + assert.equal(isSyntheticDeptName('e10-1115765553620631553'), true) + assert.equal(isSyntheticDeptName('模具课'), false) + assert.equal(isSyntheticDeptName(''), true) + assert.equal(isSyntheticDeptName(null), true) +}) + +test('displayDeptName returns displayable text', () => { + assert.equal(displayDeptName('e10-1172161210096713736'), '') + assert.equal(displayDeptName('资讯组'), '资讯组') +}) + +test('filterVisibleDepts drops synthetic-only depts', () => { + const depts = [ + { id: '1', name: '研发技术课' }, + { id: '2', name: 'e10-1115765553620631553' }, + { id: '3', name: '模具课' }, + { id: '4', name: '' }, + ] + assert.deepEqual(filterVisibleDepts(depts), [ + { id: '1', name: '研发技术课' }, + { id: '3', name: '模具课' }, + ]) + assert.deepEqual(filterVisibleDepts(null), []) +}) + +test('cleanDeptNameText strips tokens inside free text without dangling separators', () => { + assert.equal(cleanDeptNameText('e10-1115765553620631553、研发组'), '研发组') + assert.equal(cleanDeptNameText('研发组、e10-1172161210096713736、模具课'), '研发组、模具课') + assert.equal(cleanDeptNameText('资讯组'), '资讯组') + assert.equal(cleanDeptNameText('e10-111,e10-222'), '') + assert.equal(cleanDeptNameText(null), '') +}) diff --git a/frontend/src/utils/deptName.ts b/frontend/src/utils/deptName.ts new file mode 100644 index 0000000..824a7db --- /dev/null +++ b/frontend/src/utils/deptName.ts @@ -0,0 +1,36 @@ +// 部门名展示清洗(2026-11 需求):企微同步经 Casdoor 落库时,上游未映射部门名的 +// 部门以「e10-<企微部门ID>」兜底形态存入 org_depts.name / users.dept_name, +// 平台各处(下拉/列表/导出)直出时呈现为一串「e10-1115765553620631553」字样。 +// 展示侧一律剥离该字样;整体即该形态的「无名部门」不进入部门下拉。 + +const E10_DEPT_TOKEN_RE = /e10-\d+/gi + +/** 剥离部门名中残留的「e10-数字」字样并去首尾空白(入参为空安全)。 */ +export function cleanDeptName(name: string | null | undefined): string { + return (name || '').replace(E10_DEPT_TOKEN_RE, '').trim() +} + +/** 部门名剥离后是否为空(整段就是「e10-数字」的同步残留部门,展示层视为无部门名)。 */ +export function isSyntheticDeptName(name: string | null | undefined): boolean { + return cleanDeptName(name) === '' +} + +/** 部门名展示值:剥掉「e10-数字」字样,空名由调用方回退 '-' 等占位符。 */ +export function displayDeptName(name: string | null | undefined): string { + return cleanDeptName(name) +} + +/** 过滤掉整段即「e10-数字」的无名部门(部门下拉/部门表数据源统一走这里)。 */ +export function filterVisibleDepts(depts: T[] | null | undefined): T[] { + return (depts || []).filter((d) => !isSyntheticDeptName(d.name)) +} + +/** 自由文本(适合人员/参加人员串等)清洗:按分隔符拆开逐段剥离「e10-数字」后重组, + * 避免段中残留后出现悬空分隔符。 */ +export function cleanDeptNameText(text: string | null | undefined): string { + return (text || '') + .split(/[、,,;;]/) + .map((part) => cleanDeptName(part)) + .filter(Boolean) + .join('、') +} diff --git a/frontend/src/views/settings/TenantMembers.vue b/frontend/src/views/settings/TenantMembers.vue index 50c3cd3..bb6044e 100644 --- a/frontend/src/views/settings/TenantMembers.vue +++ b/frontend/src/views/settings/TenantMembers.vue @@ -684,6 +684,8 @@ import { type TenantInvitation, } from '@/api/tenant/invitations' import { docsUrl } from '@/utils/docsUrl' +// 部门名展示清洗:剥离企微同步残留的「e10-」字样(2026-11 需求) +import { cleanDeptName } from '@/utils/deptName' import { listAuditLog, type AuditLog, @@ -981,7 +983,8 @@ async function loadMembers() { await loadMembers() return } - members.value = resp.data.members ?? [] + // 2026-11 需求:部门列剥离企微同步残留的「e10-」字样 + members.value = (resp.data.members ?? []).map((m) => ({ ...m, dept_name: cleanDeptName(m.dept_name) })) membersTotal.value = total if (typeof resp.data.page === 'number' && resp.data.page > 0) { membersPage.value = resp.data.page diff --git a/frontend/src/views/training/components/CourseCatalog.vue b/frontend/src/views/training/components/CourseCatalog.vue index cd4f997..6c0490d 100644 --- a/frontend/src/views/training/components/CourseCatalog.vue +++ b/frontend/src/views/training/components/CourseCatalog.vue @@ -81,7 +81,8 @@ >{{ card.roleTag === 'teach' ? '我主讲' : '我参加' }}

{{ card.name }}

-

{{ card.meta }}

+ +

{{ card.meta }}

{{ card.state }} @@ -117,8 +118,8 @@

{{ [ - learningCourse.owner_dept_name, - learningCourse.suitable_members, + cleanDeptNameText(learningCourse.owner_dept_name), + cleanDeptNameText(learningCourse.suitable_members), learningCourse.lecturer_name, learningCourse.hours ? `${learningCourse.hours} 学时` : '', ] @@ -156,6 +157,8 @@ import { MessagePlugin } from 'tdesign-vue-next' import DocumentPreview from '@/components/document-preview.vue' import TrainingPagination from './TrainingPagination.vue' import { useTrainingPager } from './useTrainingPager' +// 部门名展示清洗:剥离企微同步残留的「e10-」字样(2026-11 需求) +import { cleanDeptNameText } from '@/utils/deptName' import { downloadCourseLibraryMaterial, getMyProfile, @@ -395,6 +398,24 @@ const fmtMonthDay = (raw: string | null) => { const d = new Date(raw) return `${d.getMonth() + 1}月${d.getDate()}日` } +// 场次排期展示:M月D日 HH:mm(2026-11 需求:卡片带上具体开课时间;解析失败回退原文) +const fmtSessionTime = (raw: string | null) => { + if (!raw) return '' + const d = new Date(raw) + if (Number.isNaN(d.getTime())) return String(raw) + const p = (n: number) => String(n).padStart(2, '0') + return `${d.getMonth() + 1}月${d.getDate()}日 ${p(d.getHours())}:${p(d.getMinutes())}` +} +// [2026-11 需求] 参加人员展示:名单过长时卡片 meta 最多展示 2 人,其余以「...」 +// 收尾;完整名单放进 metaTitle(悬停卡片可见),避免长名单把时间/地点挤出单行 meta +const participantHeadOf = (postScope: string | null | undefined) => { + const names = cleanDeptNameText(postScope).split('、').filter(Boolean) + if (!names.length) return { text: '', full: '' } + return { + text: `参加:${names.slice(0, 2).join('、')}${names.length > 2 ? '...' : ''}`, + full: `参加:${names.join('、')}`, + } +} // [2026-11 需求] 「我的课程」排序时间锚点:最近场次排期优先,其次授课时间/计划时间/创建时间; // 月份粒度(YYYY-MM)展开为当月 1 日,无可用时间返回 NaN(排序时落到最后) @@ -419,6 +440,8 @@ interface CatalogCard { name: string mode: string meta: string + /** meta 悬停提示全文(参加人员完整名单+类型/学时;缺省回退 meta 本身) */ + metaTitle?: string state: string stateClass: string barWidth: string @@ -468,7 +491,7 @@ const visibleCards = computed(() => { id: c.id, name: c.name, mode: c.mode === 'online' ? 'online' : 'offline', - meta: [c.category, c.type === 'elective' ? '选修' : '必修', c.hours ? `${c.hours} 学时` : '', c.suitable_members] + meta: [c.category, c.type === 'elective' ? '选修' : '必修', c.hours ? `${c.hours} 学时` : '', cleanDeptNameText(c.suitable_members)] .filter(Boolean) .join(' · '), state: '已发布', @@ -505,9 +528,13 @@ const visibleCards = computed(() => { } return list .map((c) => { - // meta 首段为参加人员文案(post_scope),加「参加:」前缀——裸名字会被误读成讲师名 - // (讲师身份以「我主讲」角标为准,角标判定口径见 isMyTeaching)。 - const head = [c.post_scope ? `参加:${c.post_scope}` : '', typeText(c), `${c.hours} 学时`, c.exam_enabled ? '随堂考试' : ''].filter(Boolean).join(' · ') + // meta 首段为参加人员文案(post_scope,2026-11 需求:最多展示 2 人其余「...」, + // 完整名单与类型/学时/考试移入 metaTitle 悬停提示),时间与地点紧随其后 —— + // 单行 meta 尾部不再被长名单截断。 + const participant = participantHeadOf(c.post_scope) + const courseInfo = [typeText(c), c.hours ? `${c.hours} 学时` : '', c.exam_enabled ? '随堂考试' : ''] + .filter(Boolean) + .join(' · ') const maintainable = isMyTeaching(c) && canMaintainCourses.value const unpublished = c.status !== 'published' // 「我的培训」角色标记:我主讲(优先) / 我参加,其余视图不标记 @@ -515,11 +542,13 @@ const visibleCards = computed(() => { // 未发布讲师课:无学习任务与排期进度,展示草稿/待审 + 计划时间(需求确认同步) if (unpublished) { const planText = c.planned_time || (c.teach_time && !/^\d{4}-\d{2}$/.test(c.teach_time) ? c.teach_time : '') + const schedule = planText ? `计划 ${fmtMonthDay(planText)}` : '' return { id: c.id, name: c.name, mode: c.mode, - meta: `${head}${planText ? ` · 计划 ${fmtMonthDay(planText)}` : ''}`, + meta: [participant.text, schedule].filter(Boolean).join(' · '), + metaTitle: [participant.full, courseInfo, schedule].filter(Boolean).join(' · '), state: c.status === 'pending' ? '待审' : '草稿', stateClass: 'is-warn', barWidth: '0%', @@ -537,19 +566,35 @@ const visibleCards = computed(() => { : status === 'doing' ? { state: '学习中', cls: 'is-doing', width: '100%', bar: 'is-doing-bar' } : status === 'overdue' ? { state: '已逾期', cls: 'is-bad', width: '0%', bar: '' } : { state: '待学习', cls: '', width: '0%', bar: '' } - 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, maintainable, unpublished, kind: 'plan' as const, roleTag } + const materials = c.material_ids?.length ? `课件 ${c.material_ids.length} 个` : '' + return { + id: c.id, + name: c.name, + mode: c.mode, + meta: [participant.text, materials].filter(Boolean).join(' · '), + metaTitle: [participant.full, courseInfo, materials].filter(Boolean).join(' · '), + state: cur.state, + stateClass: cur.cls, + barWidth: cur.width, + barClass: cur.bar, + maintainable, + unpublished, + kind: 'plan' as const, + roleTag, + } } const sess = (sessionByCourse.value.get(c.id) || []).sort((a, b) => String(a.start_at).localeCompare(String(b.start_at))) const finished = sess.filter((s) => s.status === 'finished').length const next = sess.find((s) => s.status === 'scheduled' && s.start_at) - const scheduleText = next ? `${fmtMonthDay(next.start_at)} ${next.location || '线下授课'}` : finished ? `已完成 ${finished} 场` : '待排期' + // [2026-11 需求] 时间地点随卡片展示:最近一场排期的开课时间(含时分)与授课地点 + const scheduleText = next ? `${fmtSessionTime(next.start_at)} ${next.location || '线下授课'}` : finished ? `已完成 ${finished} 场` : '待排期' const ratio = sess.length ? Math.round((finished / sess.length) * 100) : 0 return { id: c.id, name: c.name, mode: c.mode, - meta: `${head} · ${scheduleText}`, + meta: [participant.text, scheduleText].filter(Boolean).join(' · '), + metaTitle: [participant.full, courseInfo, scheduleText].filter(Boolean).join(' · '), state: next ? '已排期' : finished ? '已结课' : '待排期', stateClass: next ? 'is-doing' : finished ? 'is-good' : '', barWidth: `${ratio}%`, diff --git a/frontend/src/views/training/components/CourseLearningStatus.vue b/frontend/src/views/training/components/CourseLearningStatus.vue index 9250db0..45627b1 100644 --- a/frontend/src/views/training/components/CourseLearningStatus.vue +++ b/frontend/src/views/training/components/CourseLearningStatus.vue @@ -94,6 +94,8 @@ import { unwrap, } from '@/api/training' import { fmtBeijingTime } from '@/utils/datetime' +// 部门名展示清洗:剥离企微同步残留的「e10-」字样(2026-11 需求) +import { cleanDeptName } from '@/utils/deptName' import TrainingPagination from './TrainingPagination.vue' import { useTrainingPager } from './useTrainingPager' @@ -181,7 +183,9 @@ const loadTasks = async () => { taskLoading.value = true try { const res = await listCourseLearningTasks(courseId.value) - rows.value = unwrap(res) || [] + // 2026-11 需求:部门列/部门筛选剥离企微同步残留的「e10-」字样(行装载处 + // 统一清洗,列表展示、部门筛选下拉与过滤同源生效) + rows.value = (unwrap(res) || []).map((r) => ({ ...r, dept_name: cleanDeptName(r.dept_name) })) } catch { rows.value = [] } finally { diff --git a/frontend/src/views/training/components/CoursePanel.vue b/frontend/src/views/training/components/CoursePanel.vue index 160f187..73d0733 100644 --- a/frontend/src/views/training/components/CoursePanel.vue +++ b/frontend/src/views/training/components/CoursePanel.vue @@ -154,7 +154,7 @@ 上传/更换(回写课程管理主数据并作为本次培训课件/试题,000165 复测起 课件/试题变更不再回「待审核」,课程保持已审核可直接发布) --> - +

@@ -243,8 +243,15 @@ - - + + @@ -371,7 +378,15 @@