feat(公告推送):配置中心-推送管理中增加一个手动推送功能
deploy-hxtesting / build-and-deploy (push) Successful in 1m19s

目的:为和信智汇学院有重要通知时可随时向用户手动推送重要信息使用
推送内容:标题、内容、落地页(均可自定义配置),默认值标题为“和信智汇学院”、内容为“重要通知”、落地页默认系统登录页如果已登录默认登录后系统页面
推送人员:默认全员通知,可根据部门、职位、具体人员进行自定义人员
推送时间:可立即推送也可设定定时推送!
This commit is contained in:
runny committed 2026-11-29 13:41:05 +08:00
1 parent 78e9787793
commit 61fb94744a
14 files changed
+1451 -2

No files matched your search

+58
View File
@@ -1427,6 +1427,8 @@ export interface TrainingNotification {
content: string
ref_type: string
ref_id: string
/** 落地页地址(手动推送可自定义;000155 起通知行可携带)。 */
link_url?: string
sent_at: string
read_at: string | null
}
@@ -1550,6 +1552,62 @@ export const notifySessionStudents = (sessionId: string) =>
export const runWeeklyLecturerReminders = () =>
post<{ success: boolean; data: { queued: number } }>(`${base}/notifications/run-weekly`, {})
// ---- 手动推送([2026-11 需求] 配置中心 · 推送管理) ----
/** 手动推送默认文案(与后端 manualPushDefault* 逐字一致,弹窗预填空值兜底)。 */
export const MANUAL_PUSH_DEFAULT_TITLE = '和信智汇学院'
export const MANUAL_PUSH_DEFAULT_CONTENT = '重要通知'
/** TrainingPushTaskItem 手动推送任务行(镜像 internal/types.TrainingPushTaskItem)。 */
export interface TrainingPushTaskItem {
id: string
title: string
audience_mode: 'all' | 'dept' | 'post' | 'user'
/** 人员范围摘要(全员 / 按部门 财务部、人事部 / 按职位 课长 / 指定人员)。 */
audience_text: string
send_at: string
status: 'pending' | 'sending' | 'sent' | 'cancelled'
created_by: string
created_at: string
sent_at: string | null
sent_count: number
}
// TrainingManualPushResult 创建结果:任务行 + 创建时点人员数(定时任务发送时
// 按当时代名单重新解析)+ 是否定时。
export interface TrainingManualPushResult {
task: TrainingPushTaskItem
audience_count: number
scheduled: boolean
}
// createManualPush 手动推送一次通知(标题/内容/落地页可空走后端默认;人员范围
// 全员/按部门/按职位/按人员;send_at 为空 = 立即推送,ISO 字符串 = 定时)。
export const createManualPush = (payload: {
title?: string
content?: string
link_url?: string
audience_mode?: 'all' | 'dept' | 'post' | 'user'
dept_ids?: string[]
posts?: string[]
user_ids?: string[]
send_at?: string
}) =>
post<{ success: boolean; data: TrainingManualPushResult }>(
`${base}/notifications/manual-push`,
payload,
)
// listManualPushTasks 待发送定时任务列表(配置中心「手动推送」面板展示)。
export const listManualPushTasks = () =>
get<{ success: boolean; data: TrainingPushTaskItem[] }>(
`${base}/notifications/manual-push-tasks`,
)
// cancelManualPushTask 取消待发送定时任务(仅 pending 可取消)。
export const cancelManualPushTask = (id: string) =>
post<{ success: boolean }>(`${base}/notifications/manual-push-tasks/${enc(id)}/cancel`, {})
// ---- 内部小工具 ----
function enc(value: string) {
@@ -139,9 +139,11 @@ const readCount = ref(0)
const trainingItems = ref<TrainingNotification[]>([])
const TRAINING_NOTIFICATION_LIMIT = 50
const trainingUnread = computed(() => trainingItems.value.filter(n => !n.read_at).length)
// 培训通知按 ref_type 定位跳转页面(需求收集通知直达培训计划-年度需求收集)
// 培训通知按 ref_type 定位跳转页面(需求收集通知直达培训计划-年度需求收集;
// 手动推送落地页自定义,点击打开通知行 link_url,缺省回培训首页)
const trainingLinkOf = (n: TrainingNotification) => {
if (n.ref_type === 'plan') return '/platform/training/plan'
if (n.ref_type === 'manual_push' && n.link_url) return n.link_url
return '/platform/training'
}
const toTrainingAppNotification = (n: TrainingNotification): AppNotification => ({
@@ -375,6 +377,8 @@ const openInvitations = () => { panelVisible.value = false; dialogVisible.value
function navigate(link: string) {
panelVisible.value = false
if (link.startsWith('/') && !link.startsWith('//')) void router.push(link)
// 绝对地址(手动推送自定义落地页可指向外部系统):新窗口打开,不打断当前会话
else if (/^https?:\/\//i.test(link)) window.open(link, '_blank', 'noopener')
}
function openPending(item: PendingNotification) { navigate(item.link) }
@@ -152,8 +152,37 @@
</div>
</t-tab-panel>
<!-- 推送管理:推送提醒参数配置 + 推送投递记录 -->
<!-- 推送管理:手动推送 + 推送提醒参数配置 + 推送投递记录 -->
<t-tab-panel value="notify" label="推送管理">
<!-- 手动推送([2026-11 需求] 重要通知随时向全员/指定人员推送;定时任务发送前可取消) -->
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">手动推送</span>
<div class="push-toolbar">
<t-button variant="outline" size="small" :loading="pushTasksLoading" @click="loadPushTasks">刷新</t-button>
<t-button theme="primary" size="small" @click="openManualPush">新建推送</t-button>
</div>
</div>
<div class="panel-box__sub">重要通知可随时向全员或指定人员手动推送:标题/内容/落地页可自定义,支持立即或定时推送,站内 + 企微双通道。</div>
<!-- 待发送定时任务:到达发送时间前可取消 -->
<template v-if="pushTasks.length">
<div class="push-task-title">待发送定时任务({{ pushTasks.length }})</div>
<t-table :data="pushTasks" :columns="pushTaskColumns" row-key="id" size="small" :loading="pushTasksLoading">
<template #send_at="{ row }">{{ fmtTime(row.send_at) }}</template>
<template #created_by="{ row }">{{ row.created_by || '—' }}</template>
<template #op="{ row }">
<t-popconfirm content="取消后该定时任务不再发送,确认取消?" theme="danger" @confirm="onCancelPushTask(row)">
<t-button variant="outline" theme="danger" size="small">取消</t-button>
</t-popconfirm>
</template>
</t-table>
</template>
<div v-else class="push-task-empty">暂无待发送的定时任务</div>
<div class="form-hint">
全员口径为空间全部在册成员(发送时按当时代名单解析,含新增账号);企微仅送达已绑定企微的同事,其余站内可达。推送明细在下方「推送记录」按场景「手动推送」查询。
</div>
</div>
<!-- 推送提醒配置(与业务规则同款点选式表单) -->
<div class="panel-box">
<div class="panel-box__header">
@@ -378,6 +407,94 @@
<t-button theme="primary" :loading="saving" @click="onSave">保存</t-button>
</template>
</t-dialog>
<!-- 新建手动推送弹窗:标题/内容/落地页 + 人员范围(全员/部门/职位/人员) + 立即/定时 -->
<t-dialog v-model:visible="manualPushVisible" header="新建手动推送" width="640">
<t-form label-width="88px">
<t-form-item label="标题">
<t-input v-model="manualPushForm.title" placeholder="和信智汇学院" :maxlength="50" />
</t-form-item>
<t-form-item label="内容">
<t-textarea
v-model="manualPushForm.content"
:autosize="{ minRows: 3, maxRows: 6 }"
placeholder="重要通知"
:maxlength="500"
/>
</t-form-item>
<t-form-item label="落地页">
<t-input v-model="manualPushForm.linkUrl" placeholder="https://" clearable />
</t-form-item>
<t-form-item label="推送人员">
<div class="push-audience">
<t-radio-group v-model="manualPushForm.audienceMode" variant="default-filled" size="small">
<t-radio-button value="all">全员</t-radio-button>
<t-radio-button value="dept">按部门</t-radio-button>
<t-radio-button value="post">按职位</t-radio-button>
<t-radio-button value="user">按人员</t-radio-button>
</t-radio-group>
<t-select
v-if="manualPushForm.audienceMode === 'dept'"
v-model="manualPushForm.deptIds"
multiple
clearable
placeholder="选择部门,推送部门全部员工"
>
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
</t-select>
<t-select
v-else-if="manualPushForm.audienceMode === 'post'"
v-model="manualPushForm.posts"
multiple
filterable
clearable
placeholder="选择职位,推送该职位全部员工"
>
<t-option v-for="p in postOptions" :key="p" :value="p" :label="p" />
</t-select>
<t-select
v-else-if="manualPushForm.audienceMode === 'user'"
v-model="manualPushForm.userIds"
multiple
filterable
clearable
placeholder="从员工名册选择推送人员"
>
<t-option v-for="m in members" :key="m.user_id" :value="m.user_id" :label="memberLabel(m)" />
</t-select>
<div class="form-hint">
<template v-if="manualPushForm.audienceMode === 'all'">默认全员:空间全部在册成员,发送时按当时代名单解析(含新增账号)</template>
<template v-else>已解析 {{ resolvedAudienceCount }} 名成员;实际推送名单以发送时点为准</template>
</div>
</div>
</t-form-item>
<t-form-item label="推送时间">
<div class="push-audience">
<t-radio-group v-model="manualPushForm.timing" variant="default-filled" size="small">
<t-radio-button value="now">立即推送</t-radio-button>
<t-radio-button value="scheduled">定时推送</t-radio-button>
</t-radio-group>
<t-date-picker
v-if="manualPushForm.timing === 'scheduled'"
v-model="manualPushForm.sendAt"
class="push-task-time"
clearable
allow-input
enable-time-picker
format="YYYY-MM-DD HH:mm"
placeholder="选择发送时间(北京时间)"
/>
</div>
</t-form-item>
</t-form>
<div class="form-hint">
落地页留空默认本系统地址(未登录打开登录页,已登录进入系统首页);标题/内容留空按默认文案「和信智汇学院/重要通知」推送。
</div>
<template #footer>
<t-button variant="outline" :disabled="manualPushSending" @click="manualPushVisible = false">取消</t-button>
<t-button theme="primary" :loading="manualPushSending" @click="onSendManualPush">确认推送</t-button>
</template>
</t-dialog>
</div>
</template>
@@ -389,9 +506,17 @@ import {
DEFAULT_COURSE_CATEGORIES,
DEFAULT_DEMAND_COLLECT_CONTENT,
DEFAULT_DEMAND_COLLECT_TITLE,
MANUAL_PUSH_DEFAULT_CONTENT,
MANUAL_PUSH_DEFAULT_TITLE,
ROLE_DICT_RULE_KEY,
cancelManualPushTask,
createManualPush,
deleteTrainingTemplate,
fetchRoleDict,
listDepts,
listManualPushTasks,
listMembers,
listPosts,
listRuleConfigs,
listTrainingPushLogs,
listTrainingTemplates,
@@ -400,9 +525,13 @@ import {
saveRuleConfig,
seedRuleConfigs,
uploadTrainingTemplate,
type TrainingDept,
type TrainingManualPushResult,
type TrainingMember,
type TrainingPushLog,
type TrainingPushLogPage,
type TrainingPushLogStats,
type TrainingPushTaskItem,
type TrainingRoleDef,
type TrainingRuleConfig,
type TrainingTemplateKey,
@@ -862,6 +991,7 @@ const PUSH_SCENE_OPTIONS = [
{ value: 'session_notice_student', label: '学员开课通知' },
{ value: 'remind_monthly_lecturer', label: '周一讲师提醒' },
{ value: 'remind_lecturer_maintain', label: '课程维护提醒' },
{ value: 'manual_push', label: '手动推送' },
]
// 企微状态筛选项:pending 合并排队与投递中,in_site = 仅站内(push_status 空)。
@@ -977,6 +1107,181 @@ const onRunWeekly = async () => {
}
}
// ---- 手动推送([2026-11 需求] 重要通知随时推送;定时任务发送前可取消) ----
const pushTasks = ref<TrainingPushTaskItem[]>([])
const pushTasksLoading = ref(false)
const pushTaskColumns = [
{ colKey: 'title', title: '标题', ellipsis: true },
{ colKey: 'audience_text', title: '推送人员', width: 200 },
{ colKey: 'send_at', title: '发送时间', width: 150 },
{ colKey: 'created_by', title: '创建人', width: 110 },
{ colKey: 'op', title: '操作', width: 80 },
]
const loadPushTasks = async () => {
pushTasksLoading.value = true
try {
const res = await listManualPushTasks()
pushTasks.value = unwrap<TrainingPushTaskItem[]>(res) || []
} finally {
pushTasksLoading.value = false
}
}
// onCancelPushTask 取消待发送定时任务;失败(已发送/已取消)后刷新列表纠偏。
const onCancelPushTask = async (row: TrainingPushTaskItem) => {
try {
await cancelManualPushTask(row.id)
MessagePlugin.success('已取消该定时推送')
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || '取消失败,任务可能已发送')
} finally {
loadPushTasks()
}
}
// 名册数据(部门/职位/成员)首次打开弹窗懒加载;职位下拉以 posts 接口为准,
// 拉取失败回落成员档案去重(与课程管理参加人员选择器同口径)。
const depts = ref<TrainingDept[]>([])
const members = ref<TrainingMember[]>([])
const postOptions = ref<string[]>([])
const rostersLoaded = ref(false)
const memberLabel = (m: TrainingMember) =>
[m.user_name || m.employee_no, m.post, m.dept_name].filter(Boolean).join(' · ') || m.user_id
const loadRosters = async () => {
if (rostersLoaded.value) return
rostersLoaded.value = true
try {
const [deptRes, memberRes, postRes] = await Promise.all([
listDepts(),
listMembers({ page_size: 500 }),
listPosts(),
])
depts.value = unwrap<TrainingDept[]>(deptRes) || []
members.value = unwrap<{ items: TrainingMember[] }>(memberRes)?.items || []
postOptions.value =
unwrap<string[]>(postRes) ||
[...new Set(members.value.map((m) => m.post).filter(Boolean))].sort()
} catch {
/* 拉取失败保留空态,可手动搜索/选择 */
}
}
type ManualPushAudienceMode = 'all' | 'dept' | 'post' | 'user'
const manualPushVisible = ref(false)
const manualPushSending = ref(false)
const manualPushForm = ref({
title: MANUAL_PUSH_DEFAULT_TITLE,
content: MANUAL_PUSH_DEFAULT_CONTENT,
linkUrl: '',
audienceMode: 'all' as ManualPushAudienceMode,
deptIds: [] as string[],
posts: [] as string[],
userIds: [] as string[],
timing: 'now' as 'now' | 'scheduled',
sendAt: '',
})
// resolvedAudienceCount 按部门/职位从名册联集已解析成员数;按人员=已选人数
// (全员不预览,后端发送时按当时代名单解析)。
const resolvedAudienceCount = computed(() => {
const f = manualPushForm.value
if (f.audienceMode === 'user') return new Set(f.userIds).size
const picked = f.audienceMode === 'dept' ? f.deptIds : f.posts
if (!picked.length) return 0
const matched = members.value.filter((m) =>
f.audienceMode === 'dept' ? picked.includes(m.dept_id) : picked.includes(m.post),
)
return new Set(matched.map((m) => m.user_id)).size
})
// defaultLandingURL 落地页默认值:配置中心「推送链接基址」优先(多入口/内外网
// 部署权威域名),否则当前访问 origin —— 站点根路径未登录打开登录页,已登录进系统首页。
const defaultLandingURL = () => {
const base = String(ruleValues.value.notify_link_base_url?.base_url || '').trim()
return base || window.location.origin
}
const openManualPush = () => {
manualPushForm.value = {
title: MANUAL_PUSH_DEFAULT_TITLE,
content: MANUAL_PUSH_DEFAULT_CONTENT,
linkUrl: defaultLandingURL(),
audienceMode: 'all',
deptIds: [],
posts: [],
userIds: [],
timing: 'now',
sendAt: '',
}
manualPushVisible.value = true
loadRosters()
}
const onSendManualPush = async () => {
const f = manualPushForm.value
if (f.audienceMode === 'dept' && !f.deptIds.length) {
MessagePlugin.warning('请选择要推送的部门')
return
}
if (f.audienceMode === 'post' && !f.posts.length) {
MessagePlugin.warning('请选择要推送的职位')
return
}
if (f.audienceMode === 'user' && !f.userIds.length) {
MessagePlugin.warning('请选择要推送的人员')
return
}
let sendAt: string | undefined
if (f.timing === 'scheduled') {
const parsed = new Date(f.sendAt.trim().replace(' ', 'T'))
if (!f.sendAt.trim() || Number.isNaN(parsed.getTime())) {
MessagePlugin.warning('请选择定时发送时间')
return
}
if (parsed.getTime() <= Date.now()) {
MessagePlugin.warning('定时发送时间必须晚于当前时刻')
return
}
sendAt = parsed.toISOString()
}
manualPushSending.value = true
try {
const res = await createManualPush({
title: f.title.trim(),
content: f.content.trim(),
link_url: f.linkUrl.trim(),
audience_mode: f.audienceMode,
dept_ids: f.deptIds,
posts: f.posts,
user_ids: f.userIds,
send_at: sendAt,
})
const result = unwrap<TrainingManualPushResult>(res)
if (result?.scheduled) {
MessagePlugin.success(
`定时推送已设定:${fmtTime(result.task.send_at)} 自动向 ${result.audience_count} 人推送,发送前可在上方取消`,
)
} else {
MessagePlugin.success(
`已推送 ${result?.audience_count ?? 0} 人(站内 + 企业微信;未绑定企微的同事仅站内送达,明细见下方推送记录)`,
)
}
manualPushVisible.value = false
loadPushTasks()
loadPushLogs()
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || '推送失败,请稍后重试')
} finally {
manualPushSending.value = false
}
}
const isDirty = (key: string) => JSON.stringify(ruleValues.value[key]) !== savedSnapshot.value[key]
const weightSum = computed(() => {
@@ -1129,6 +1434,7 @@ onMounted(() => {
loadRoles()
loadTemplates()
loadPushLogs()
loadPushTasks()
})
</script>
@@ -1410,4 +1716,40 @@ onMounted(() => {
white-space: nowrap;
color: var(--td-error-color);
}
/* 手动推送:待发送定时任务小表与弹窗表单([2026-11 需求]) */
.push-task-title {
margin: 12px 0 8px;
font-weight: 600;
font-size: var(--app-text-sm);
}
.push-task-empty {
margin-top: 12px;
padding: 10px 12px;
font-size: var(--app-text-sm);
color: var(--td-text-color-placeholder);
background: var(--td-bg-color-container);
border: 1px dashed var(--td-component-border);
border-radius: var(--td-radius-default);
}
.push-audience {
width: 100%;
display: flex;
flex-direction: column;
gap: 8px;
.t-select {
width: 100%;
}
.form-hint {
margin-top: 0;
}
}
.push-task-time {
width: 100%;
}
</style>