deploy-hxtesting / build-and-deploy (push) Successful in 1m14s
课程管理:canDeleteCourse 超管不限状态/部门(已审核/已发布行可删,确认弹窗文案区分);批量删除按钮超管可见 月培训计划:已发布行的「删除」仅超管可见(普通维护角色仍只能删未发布计划),行内确认弹窗替代原 window.confirm,失败时透出后端文案 Training.vue:canManageTabs 加入 super_admin,纯超管(未兼其他角色)也能进入这三个页面执行删除
1241 lines
45 KiB
Vue
1241 lines
45 KiB
Vue
<template>
|
|
<div class="rule-panel">
|
|
<!-- [2026-11 需求] 配置中心 tab 化:角色权限/业务规则(含业务参数与课程分类)/推送管理(推送提醒配置+推送记录)/导入模板 -->
|
|
<t-tabs v-model="activeTab" class="rule-tabs">
|
|
<t-tab-panel value="roles" label="角色权限">
|
|
<!-- 角色权限 · 角色与权限(点选式维护,自定义角色勾选权限分配即生效) -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">角色权限 · 角色与权限</span>
|
|
<t-button variant="outline" size="small" @click="openRoleDialog()">新增角色</t-button>
|
|
</div>
|
|
<t-table :data="roleRows" :columns="roleColumns" row-key="key" size="small" :loading="roleLoading">
|
|
<template #role="{ row }">
|
|
<span class="role-name">{{ row.label }}</span>
|
|
<t-tag v-if="row.system" theme="primary" variant="light" size="small" class="role-sys-tag">系统</t-tag>
|
|
</template>
|
|
<template #key="{ row }">
|
|
<code class="role-key">{{ row.key }}</code>
|
|
</template>
|
|
<template #inherits="{ row }">
|
|
<span v-if="!(row.inherits || []).length" class="perm-none">—</span>
|
|
<t-tag
|
|
v-for="p in row.inherits || []"
|
|
:key="p"
|
|
variant="light"
|
|
size="small"
|
|
class="perm-tag"
|
|
>{{ roleLabelOf(p, roleRows, true) }}</t-tag>
|
|
</template>
|
|
<template #op="{ row }">
|
|
<t-button variant="text" theme="primary" size="small" @click="openRoleDialog(row)">编辑</t-button>
|
|
<t-popconfirm
|
|
v-if="!row.system"
|
|
content="删除该角色?仍持有该角色的成员将回退为普通学员权限。"
|
|
theme="danger"
|
|
@confirm="onDeleteRole(row)"
|
|
>
|
|
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
|
</t-popconfirm>
|
|
</template>
|
|
</t-table>
|
|
<div class="form-hint">
|
|
系统角色不可删除,展示名与权限分配可改;「权限分配」= 继承所选权限组的全部接口与页面权限,勾选多个取并集。学员为全员默认角色,无需配置。
|
|
</div>
|
|
</div>
|
|
</t-tab-panel>
|
|
|
|
<!-- 业务规则:签到/评分/积分/达标线/滚动等业务规则与业务参数 + 课程分类字典 + 高级配置兜底 -->
|
|
<t-tab-panel value="rules" label="业务规则">
|
|
<!-- 业务规则(全部点选式表单,不再手写 JSON) -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">业务规则</span>
|
|
<t-button variant="outline" size="small" :loading="seeding" @click="onSeed">初始化默认配置</t-button>
|
|
</div>
|
|
<div class="panel-box__sub">点选即可修改,每项保存后立即生效;未保存的修改不生效。</div>
|
|
<div v-for="schema in ruleSchemas" :key="schema.key" class="rule-section">
|
|
<div class="rule-section__head">
|
|
<span class="rule-section__title">{{ schema.title }}</span>
|
|
<span class="rule-section__desc">{{ schema.desc }}</span>
|
|
<t-button
|
|
variant="outline"
|
|
size="small"
|
|
:disabled="!isDirty(schema.key)"
|
|
:loading="savingKey === schema.key"
|
|
@click="onSaveRule(schema.key)"
|
|
>保存</t-button>
|
|
</div>
|
|
<div class="rule-section__fields">
|
|
<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>
|
|
<t-input-number
|
|
v-if="field.type === 'number'"
|
|
v-model="ruleValues[schema.key][field.key]"
|
|
:min="field.min"
|
|
:max="field.max"
|
|
theme="normal"
|
|
size="small"
|
|
class="rule-field__input"
|
|
/>
|
|
<t-switch
|
|
v-else-if="field.type === 'switch'"
|
|
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.vars" class="rule-field__vars">可用变量:{{ field.vars }}</span>
|
|
</div>
|
|
</div>
|
|
<div v-if="schema.key === 'lecturer_score_weight'" class="rule-sum" :class="{ 'rule-sum--warn': weightSum !== 100 }">
|
|
三项权重合计:{{ weightSum }}<template v-if="weightSum !== 100">(建议合计 100)</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 课程分类:rule-configs course_category_dict,课程管理筛选/表单下拉选项来源 -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">课程分类</span>
|
|
<t-button variant="outline" size="small" :disabled="!categoriesDirty" :loading="categoriesSaving" @click="onSaveCategories">保存</t-button>
|
|
</div>
|
|
<div class="panel-box__sub">课程管理列表「按分类查询」与「新增课程」弹窗的分类下拉选项;预设之外可在课程表单直接输入自定义分类。</div>
|
|
<div class="category-editor">
|
|
<t-tag
|
|
v-for="c in categoryDraft"
|
|
:key="c"
|
|
theme="primary"
|
|
variant="light"
|
|
closable
|
|
@close="onRemoveCategory(c)"
|
|
>{{ c }}</t-tag>
|
|
<t-input
|
|
v-model="categoryInput"
|
|
class="category-input"
|
|
size="small"
|
|
clearable
|
|
placeholder="输入新分类后回车或点添加"
|
|
@enter="onAddCategory"
|
|
/>
|
|
<t-button variant="outline" size="small" :disabled="!categoryInput.trim()" @click="onAddCategory">添加</t-button>
|
|
<t-button variant="text" theme="primary" size="small" class="category-reset" @click="onResetCategories">恢复默认</t-button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 高级配置:未提供点选表单的规则键,保留 JSON 编辑兜底 -->
|
|
<div v-if="advancedRows.length" class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">高级配置</span>
|
|
<span class="panel-box__sub">以下配置项暂无点选表单,按 JSON 格式编辑</span>
|
|
</div>
|
|
<t-table :data="advancedRows" :columns="advancedColumns" row-key="rule_key" size="small">
|
|
<template #rule_key="{ row }"><code class="role-key">{{ row.rule_key }}</code></template>
|
|
<template #rule_value="{ row }">
|
|
<code class="rule-json">{{ stringify(row.rule_value) }}</code>
|
|
</template>
|
|
<template #op="{ row }">
|
|
<t-button variant="text" theme="primary" size="small" @click="openEdit(row)">编辑</t-button>
|
|
</template>
|
|
</t-table>
|
|
</div>
|
|
</t-tab-panel>
|
|
|
|
<!-- 推送管理:推送提醒参数配置 + 推送投递记录 -->
|
|
<t-tab-panel value="notify" label="推送管理">
|
|
<!-- 推送提醒配置(与业务规则同款点选式表单) -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">推送提醒配置</span>
|
|
</div>
|
|
<div class="panel-box__sub">点选即可修改,每项保存后立即生效;未保存的修改不生效。</div>
|
|
<div v-for="schema in notifySchemas" :key="schema.key" class="rule-section">
|
|
<div class="rule-section__head">
|
|
<span class="rule-section__title">{{ schema.title }}</span>
|
|
<span class="rule-section__desc">{{ schema.desc }}</span>
|
|
<t-button
|
|
variant="outline"
|
|
size="small"
|
|
:disabled="!isDirty(schema.key)"
|
|
:loading="savingKey === schema.key"
|
|
@click="onSaveRule(schema.key)"
|
|
>保存</t-button>
|
|
</div>
|
|
<div class="rule-section__fields">
|
|
<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>
|
|
<t-input-number
|
|
v-if="field.type === 'number'"
|
|
v-model="ruleValues[schema.key][field.key]"
|
|
:min="field.min"
|
|
:max="field.max"
|
|
theme="normal"
|
|
size="small"
|
|
class="rule-field__input"
|
|
/>
|
|
<t-switch
|
|
v-else-if="field.type === 'switch'"
|
|
v-model="ruleValues[schema.key][field.key]"
|
|
/>
|
|
<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.vars" class="rule-field__vars">可用变量:{{ field.vars }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 推送记录(逐人企微/站内投递明细;手动触发周一讲师提醒) -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">推送记录</span>
|
|
<div class="push-toolbar">
|
|
<t-select v-model="pushScene" class="push-scene-select" size="small" clearable placeholder="全部场景">
|
|
<t-option v-for="opt in PUSH_SCENE_OPTIONS" :key="opt.value" :value="opt.value" :label="opt.label" />
|
|
</t-select>
|
|
<t-button variant="outline" size="small" :loading="pushLogsLoading" @click="loadPushLogs">刷新</t-button>
|
|
<t-popconfirm content="立即执行一轮周一讲师未完成提醒?同一周重复执行不会重复推送。" theme="primary" @confirm="onRunWeekly">
|
|
<t-button variant="outline" theme="primary" size="small" :loading="runningWeekly">立即推送讲师提醒</t-button>
|
|
</t-popconfirm>
|
|
</div>
|
|
</div>
|
|
<t-table :data="pushLogs" :columns="pushLogColumns" row-key="id" size="small" :loading="pushLogsLoading" max-height="360">
|
|
<template #created_at="{ row }">{{ fmtTime(row.created_at) }}</template>
|
|
<template #scene="{ row }"><code class="role-key">{{ row.scene }}</code></template>
|
|
<template #target="{ row }">
|
|
<span>{{ row.target_name || row.target_user_id }}</span>
|
|
<span v-if="row.employee_no" class="push-empno">({{ row.employee_no }})</span>
|
|
</template>
|
|
<template #push_status="{ row }">
|
|
<t-tag
|
|
:theme="row.push_status === 'sent' ? 'success' : row.push_status === 'dead' || row.push_status === '' ? 'default' : row.push_status === 'pending' || row.push_status === 'sending' ? 'warning' : 'danger'"
|
|
variant="light" size="small"
|
|
>{{ pushStatusLabel(row.push_status) }}</t-tag>
|
|
</template>
|
|
<template #push_error="{ row }">
|
|
<span class="push-error" :title="row.push_error">{{ row.push_error || '—' }}</span>
|
|
</template>
|
|
</t-table>
|
|
<div class="form-hint">
|
|
展示最近 {{ pushLogs.length }} 条;pending/sending=排队与投递中,sent=企微已送达,skipped=收件人未绑定企微等跳过,dead=重试耗尽,空=仅站内通知。
|
|
</div>
|
|
</div>
|
|
</t-tab-panel>
|
|
|
|
<!-- 导入模板:上传自定义 Excel 模板替换内置默认 -->
|
|
<t-tab-panel value="templates" label="导入模板">
|
|
<!-- 导入模板管理(上传自定义 Excel 模板替换内置默认) -->
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">导入模板</span>
|
|
<span class="panel-box__sub">上传后,培训计划批量导入、题库 Excel 导入与课程管理批量导入的下载入口即刻使用新模板</span>
|
|
</div>
|
|
<t-table :data="templates" :columns="templateColumns" row-key="template_key" size="small" :loading="templateLoading">
|
|
<template #file_name="{ row }">
|
|
<span>{{ row.file_name }}</span>
|
|
<t-tag v-if="row.source === 'custom'" theme="primary" variant="light" size="small" class="tpl-tag">自定义</t-tag>
|
|
<t-tag v-else theme="default" variant="light" size="small" class="tpl-tag">内置默认</t-tag>
|
|
</template>
|
|
<template #file_size="{ row }">{{ fmtSize(row.file_size) }}</template>
|
|
<template #updated_at="{ row }">{{ row.source === 'custom' ? fmtTime(row.updated_at) : '—' }}</template>
|
|
<template #op="{ row }">
|
|
<t-button variant="text" theme="primary" size="small" @click="onDownloadTemplate(row)">下载</t-button>
|
|
<t-button variant="text" theme="primary" size="small" @click="onPickUpload(row)">上传更新</t-button>
|
|
<t-popconfirm
|
|
v-if="row.source === 'custom'"
|
|
content="恢复为内置默认模板?"
|
|
theme="danger"
|
|
@confirm="onResetTemplate(row)"
|
|
>
|
|
<t-button variant="text" theme="danger" size="small">恢复默认</t-button>
|
|
</t-popconfirm>
|
|
</template>
|
|
</t-table>
|
|
<div class="form-hint">仅支持 .xls / .xlsx,不超过 10MB;上传后原有内置模板仍可通过「恢复默认」找回。</div>
|
|
<!-- 复用的隐藏文件选择器:记录待上传模板键 -->
|
|
<input
|
|
ref="uploadInput"
|
|
type="file"
|
|
accept=".xls,.xlsx"
|
|
class="tpl-upload-input"
|
|
@change="onUploadFile"
|
|
/>
|
|
</div>
|
|
</t-tab-panel>
|
|
</t-tabs>
|
|
|
|
<!-- 角色编辑弹窗 -->
|
|
<t-dialog
|
|
v-model:visible="roleDialogVisible"
|
|
:header="roleForm.mode === 'add' ? '新增角色' : `编辑角色 · ${roleForm.label || roleForm.key}`"
|
|
width="480"
|
|
>
|
|
<t-form label-width="88px">
|
|
<t-form-item label="角色标识">
|
|
<t-input
|
|
v-model="roleForm.key"
|
|
:disabled="roleForm.mode === 'edit'"
|
|
placeholder="小写字母开头,仅含小写字母/数字/下划线,如 trainer"
|
|
/>
|
|
</t-form-item>
|
|
<t-form-item label="显示名">
|
|
<t-input v-model="roleForm.label" placeholder="如:培训专员" />
|
|
</t-form-item>
|
|
<t-form-item label="短名">
|
|
<t-input v-model="roleForm.short" placeholder="成员列表标签展示,缺省同显示名" />
|
|
</t-form-item>
|
|
<t-form-item label="权限分配">
|
|
<t-select v-model="roleForm.inherits" multiple clearable placeholder="点选要赋予的权限组(可多选)">
|
|
<t-option
|
|
v-for="r in inheritOptions"
|
|
:key="r.key"
|
|
:value="r.key"
|
|
:label="`${r.label}权限组`"
|
|
/>
|
|
</t-select>
|
|
</t-form-item>
|
|
</t-form>
|
|
<div class="form-hint">
|
|
权限分配决定该角色能使用哪些功能:如勾选「课长权限组+讲师权限组」即可管理培训计划与维护课程(经理权限组已包含课长全部权限与审批决策)。保存后立即生效,无需重启。
|
|
</div>
|
|
<template #footer>
|
|
<t-button theme="primary" :loading="roleSaving" @click="onSaveRole">保存</t-button>
|
|
</template>
|
|
</t-dialog>
|
|
|
|
<!-- 高级配置 JSON 编辑弹窗 -->
|
|
<t-dialog v-model:visible="editVisible" :header="`编辑规则 · ${activeKey}`" width="560">
|
|
<t-textarea v-model="editText" :autosize="{ minRows: 10 }" />
|
|
<div class="form-hint">JSON 格式,保存后立即生效;历史数据不受影响。</div>
|
|
<template #footer>
|
|
<t-button theme="primary" :loading="saving" @click="onSave">保存</t-button>
|
|
</template>
|
|
</t-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
import { MessagePlugin } from 'tdesign-vue-next'
|
|
import {
|
|
COURSE_CATEGORY_DICT_RULE_KEY,
|
|
DEFAULT_COURSE_CATEGORIES,
|
|
DEFAULT_DEMAND_COLLECT_CONTENT,
|
|
DEFAULT_DEMAND_COLLECT_TITLE,
|
|
ROLE_DICT_RULE_KEY,
|
|
deleteTrainingTemplate,
|
|
fetchRoleDict,
|
|
listRuleConfigs,
|
|
listTrainingPushLogs,
|
|
listTrainingTemplates,
|
|
roleLabelOf,
|
|
runWeeklyLecturerReminders,
|
|
saveRuleConfig,
|
|
seedRuleConfigs,
|
|
uploadTrainingTemplate,
|
|
type TrainingPushLog,
|
|
type TrainingRoleDef,
|
|
type TrainingRuleConfig,
|
|
type TrainingTemplateKey,
|
|
type TrainingTemplateMeta,
|
|
unwrap,
|
|
} from '@/api/training'
|
|
import { fmtBeijingTime } from '@/utils/datetime'
|
|
import { downloadTrainingTemplate } from '../trainingTemplates'
|
|
|
|
// [2026-11 需求] 配置中心 tab 切换(角色权限/业务规则/推送管理/导入模板)
|
|
const activeTab = ref('roles')
|
|
|
|
const loading = ref(false)
|
|
const saving = ref(false)
|
|
const editVisible = ref(false)
|
|
const editText = ref('')
|
|
const activeKey = ref('')
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// 职称角色 · 角色与权限
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const roleLoading = ref(false)
|
|
const roleRows = ref<TrainingRoleDef[]>([])
|
|
|
|
const roleColumns = [
|
|
{ colKey: 'role', title: '角色', width: 210 },
|
|
{ colKey: 'key', title: '标识', width: 110 },
|
|
{ colKey: 'inherits', title: '权限分配', minWidth: 200 },
|
|
{ colKey: 'op', title: '操作', width: 130 },
|
|
]
|
|
|
|
const loadRoles = async () => {
|
|
roleLoading.value = true
|
|
try {
|
|
roleRows.value = await fetchRoleDict()
|
|
} finally {
|
|
roleLoading.value = false
|
|
}
|
|
}
|
|
|
|
const roleDialogVisible = ref(false)
|
|
const roleSaving = ref(false)
|
|
const roleForm = ref<{ mode: 'add' | 'edit'; key: string; label: string; short: string; inherits: string[] }>({
|
|
mode: 'add',
|
|
key: '',
|
|
label: '',
|
|
short: '',
|
|
inherits: [],
|
|
})
|
|
|
|
// 权限组选项 = 系统角色(排除自身,自分配无意义且后端会拦截)
|
|
const inheritOptions = computed(() => roleRows.value.filter((r) => r.system && r.key !== roleForm.value.key))
|
|
|
|
const openRoleDialog = (row?: TrainingRoleDef) => {
|
|
roleForm.value = row
|
|
? { mode: 'edit', key: row.key, label: row.label, short: row.short || '', inherits: [...(row.inherits || [])] }
|
|
: { mode: 'add', key: '', label: '', short: '', inherits: [] }
|
|
roleDialogVisible.value = true
|
|
}
|
|
|
|
// 与后端 ParseRoleDict 同口径的前端校验(点选场景先提示,不依赖 400)
|
|
const ROLE_KEY_RE = /^[a-z][a-z0-9_]{0,31}$/
|
|
|
|
const onSaveRole = async () => {
|
|
const f = roleForm.value
|
|
const key = f.key.trim()
|
|
const label = f.label.trim()
|
|
if (f.mode === 'add' && !ROLE_KEY_RE.test(key)) {
|
|
MessagePlugin.warning('角色标识需小写字母开头,仅含小写字母/数字/下划线')
|
|
return
|
|
}
|
|
if (f.mode === 'add' && roleRows.value.some((r) => r.key === key)) {
|
|
MessagePlugin.warning(`角色标识 ${key} 已存在`)
|
|
return
|
|
}
|
|
if (!label) {
|
|
MessagePlugin.warning('显示名不能为空')
|
|
return
|
|
}
|
|
if (f.inherits.includes(key)) {
|
|
MessagePlugin.warning('不能分配自身权限组')
|
|
return
|
|
}
|
|
// 经理 = 课长全部权限 + 审批决策:必须分配课长权限组(与后端硬约束同口径)
|
|
if (key === 'exec' && !f.inherits.includes('supervisor')) {
|
|
MessagePlugin.warning('经理权限组必须分配课长权限组(经理 = 课长全部权限 + 审批决策)')
|
|
return
|
|
}
|
|
const short = f.short.trim() || label
|
|
const next: TrainingRoleDef[] =
|
|
f.mode === 'add'
|
|
? [...roleRows.value, { key, label, short, system: false, inherits: [...f.inherits] }]
|
|
: roleRows.value.map((r) => (r.key === key ? { ...r, label, short, inherits: [...f.inherits] } : r))
|
|
roleSaving.value = true
|
|
try {
|
|
await saveRuleConfig(ROLE_DICT_RULE_KEY, { roles: next })
|
|
MessagePlugin.success('角色已保存并生效')
|
|
roleDialogVisible.value = false
|
|
roleRows.value = next
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '保存失败')
|
|
} finally {
|
|
roleSaving.value = false
|
|
}
|
|
}
|
|
|
|
const onDeleteRole = async (row: TrainingRoleDef) => {
|
|
const next = roleRows.value.filter((r) => r.key !== row.key)
|
|
try {
|
|
await saveRuleConfig(ROLE_DICT_RULE_KEY, { roles: next })
|
|
MessagePlugin.success('角色已删除')
|
|
roleRows.value = next
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '删除失败')
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// 业务规则(点选式表单;字段描述驱动,与后端 defaultRuleSeed 同源)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface RuleFieldDesc {
|
|
key: string
|
|
label: string
|
|
type: 'number' | 'switch' | 'text'
|
|
min?: number
|
|
max?: number
|
|
unit?: string
|
|
/** text 字段的输入提示 */
|
|
placeholder?: string
|
|
/** text 字段(文案模板)支持的 {占位符} 列表提示 */
|
|
vars?: string
|
|
}
|
|
|
|
interface RuleSchemaDesc {
|
|
key: string
|
|
title: string
|
|
desc: string
|
|
fields: RuleFieldDesc[]
|
|
// group:notify = 推送提醒类配置,配置中心归入「推送管理」tab;缺省归「业务规则」tab。
|
|
group?: 'notify'
|
|
// serialize UI 表单值 → tr_rule_configs 落库值(默认原样 JSON);
|
|
// notify_remind_days(数组)/notify_push_enabled(bool) 等非对象契约用。
|
|
serialize?: (v: Record<string, any>) => any
|
|
// parse 落库值 → UI 表单值(缺省视为对象原样)。
|
|
parse?: (saved: any) => Record<string, any>
|
|
}
|
|
|
|
const RULE_SCHEMAS: RuleSchemaDesc[] = [
|
|
{
|
|
key: 'sign_policy',
|
|
title: '签到策略',
|
|
desc: '培训签到的迟到判定与定位校验',
|
|
fields: [
|
|
{ key: 'late_after_min', label: '迟到阈值', type: 'number', min: 1, max: 120, unit: '分钟后算迟到' },
|
|
{ key: 'geo_radius_m', label: '定位有效半径', type: 'number', min: 50, max: 5000, unit: '米' },
|
|
{ key: 'require_geo', label: '强制定位校验', type: 'switch' },
|
|
],
|
|
},
|
|
{
|
|
key: 'lecturer_score_weight',
|
|
title: '讲师评分权重',
|
|
desc: '讲师综合分的三个构成维度权重',
|
|
fields: [
|
|
{ key: 'on_time', label: '按时开课', type: 'number', min: 0, max: 100 },
|
|
{ key: 'rating', label: '学员评分', type: 'number', min: 0, max: 100 },
|
|
{ key: 'qa', label: '互动答疑', type: 'number', min: 0, max: 100 },
|
|
],
|
|
},
|
|
{
|
|
key: 'point_rules',
|
|
title: '积分规则',
|
|
desc: '学员完成相应学习行为获得的积分',
|
|
fields: [
|
|
{ key: 'required', label: '完成必修课', type: 'number', min: 0, max: 1000 },
|
|
{ key: 'score_90', label: '考试 ≥90 分', type: 'number', min: 0, max: 1000 },
|
|
{ key: 'score_100', label: '考试 100 分', type: 'number', min: 0, max: 1000 },
|
|
{ key: 'pass', label: '考试普通及格', type: 'number', min: 0, max: 1000 },
|
|
{ key: 'elective', label: '完成选修课', type: 'number', min: 0, max: 1000 },
|
|
{ key: 'self_study', label: '自学线上课件', type: 'number', min: 0, max: 1000 },
|
|
],
|
|
},
|
|
{
|
|
// [2026-11 推送管理] 接线真实调度器契约:scheduler 读 notify_remind_days 数组
|
|
// (training_scheduler.go loadNotifyConfig);原 remind_policy(t3/t1/third_week/
|
|
// month_end)从未被后端读取,由本卡替换(third_week/month_end 无实现,随卡移除)。
|
|
key: 'notify_remind_days',
|
|
group: 'notify',
|
|
title: '开课提醒时点',
|
|
desc: '调度器按提前天数生成讲师授课提醒;学员开课通知由场次"通知方式"决定(立即或前一天),不受本项影响',
|
|
fields: [
|
|
{ key: 't3', label: '开课前 3 天提醒', type: 'switch' },
|
|
{ key: 't1', label: '开课前 1 天提醒', type: 'switch' },
|
|
],
|
|
serialize: (v) => [...(v.t3 ? [3] : []), ...(v.t1 ? [1] : [])],
|
|
// 配置行不存在时必须返回 {} 让 DEFAULT_RULE_VALUES 打底(true),不能显式 false。
|
|
parse: (saved) =>
|
|
saved === undefined || saved === null
|
|
? {}
|
|
: {
|
|
t3: Array.isArray(saved) && saved.includes(3),
|
|
t1: Array.isArray(saved) && saved.includes(1),
|
|
},
|
|
},
|
|
{
|
|
key: 'notify_push_enabled',
|
|
group: 'notify',
|
|
title: '企微推送总开关',
|
|
desc: '关闭后新产生的通知只保留站内流水,不再推送企业微信;已入队消息不受影响',
|
|
fields: [{ key: 'enabled', label: '启用企微推送', type: 'switch' }],
|
|
serialize: (v) => !!v.enabled,
|
|
parse: (saved) =>
|
|
saved === undefined || saved === null ? {} : { enabled: saved === true || saved?.enabled === true },
|
|
},
|
|
{
|
|
key: 'notify_weekly_lecturer',
|
|
group: 'notify',
|
|
title: '周一讲师未完成提醒',
|
|
desc: '每周一上午向当月仍有未结束场次的讲师推送汇总提醒(标题带第 N 周);讲师场次全部结束即自动停推',
|
|
fields: [
|
|
{ key: 'enabled', label: '启用周一提醒', type: 'switch' },
|
|
{ key: 'hour', label: '发送时刻', type: 'number', min: 0, max: 23, unit: '点(北京时间)' },
|
|
],
|
|
serialize: (v) => ({ enabled: !!v.enabled, hour: Number(v.hour) || 9 }),
|
|
parse: (saved) =>
|
|
saved === undefined || saved === null
|
|
? {}
|
|
: { enabled: saved?.enabled !== false, hour: Number(saved?.hour ?? 9) },
|
|
},
|
|
{
|
|
// [2026-11 需求] 企微消息内深链接的环境级基址覆盖:多入口(域名/IP、内外网)
|
|
// 部署时固定链接指向权威域名,优先于推送人浏览器 origin;清空保存即回落 origin
|
|
// (本地开发零配置可用)。demand_collect 推送的「下载模板/查看更多详情」共用。
|
|
key: 'notify_link_base_url',
|
|
group: 'notify',
|
|
title: '推送链接基址',
|
|
desc: '企微推送消息内「下载模板/查看更多详情」链接的对外地址;多入口或内外网部署时请填写课长实际访问的权威地址(如 https://aido.corp.com),留空则跟随推送人当前访问地址',
|
|
fields: [{ key: 'base_url', label: '对外基址', type: 'text', placeholder: 'https://aido.corp.com' }],
|
|
serialize: (v) => String(v.base_url || '').trim(),
|
|
parse: (saved) => ({ base_url: typeof saved === 'string' ? saved : '' }),
|
|
},
|
|
{
|
|
// [2026-11 需求] 提醒推送文案可编辑:各提醒场景的标题/内容模板,保存后新推送即刻生效;
|
|
// {占位符} 渲染时替换为实际值,清空保存即恢复内置默认文案(后端空值回落默认)。
|
|
key: 'notify_text_templates',
|
|
group: 'notify',
|
|
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} 未结束场次',
|
|
},
|
|
{
|
|
// [2026-11 需求] 年培训计划收集推送(培训计划页「收集下年度计划」弹窗):
|
|
// 弹窗预填与后端广播空字段回落共用本模板,{year} 渲染为收集年度(下一年)。
|
|
key: 'demand_collect_title',
|
|
label: '年培训计划收集推送 · 标题',
|
|
type: 'text',
|
|
placeholder: DEFAULT_DEMAND_COLLECT_TITLE,
|
|
vars: '{year} 收集年度(推送时按下一年度替换)',
|
|
},
|
|
{
|
|
key: 'demand_collect_content',
|
|
label: '年培训计划收集推送 · 内容',
|
|
type: 'text',
|
|
vars: '{year} 收集年度(推送时按下一年度替换)',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
key: 'pass_line',
|
|
title: '岗位胜任达标线',
|
|
desc: '课程考试的默认及格分数线',
|
|
fields: [{ key: 'default', label: '默认及格线', type: 'number', min: 0, max: 100, unit: '分' }],
|
|
},
|
|
{
|
|
key: 'roll_policy',
|
|
title: '滚动规则',
|
|
desc: '连续未完成任务的升级提醒阈值',
|
|
fields: [{ key: 'escalate_after', label: '连续未完成', type: 'number', min: 1, max: 12, unit: '次后升级提醒' }],
|
|
},
|
|
]
|
|
|
|
// 默认值打底(与后端 defaultRuleSeed 一致):规则键尚未初始化时也能直接点选配置
|
|
const DEFAULT_RULE_VALUES: Record<string, Record<string, any>> = {
|
|
lecturer_score_weight: { on_time: 40, rating: 50, qa: 10 },
|
|
point_rules: { required: 10, score_90: 10, score_100: 20, pass: 5, elective: 5, self_study: 3 },
|
|
sign_policy: { late_after_min: 15, geo_radius_m: 300, require_geo: false },
|
|
pass_line: { default: 75 },
|
|
roll_policy: { escalate_after: 2 },
|
|
// [2026-11 推送管理] 企微推送卡默认值(与调度器缺省一致)
|
|
notify_remind_days: { t3: true, t1: true },
|
|
notify_push_enabled: { enabled: true },
|
|
notify_weekly_lecturer: { enabled: true, hour: 9 },
|
|
notify_link_base_url: { base_url: '' },
|
|
// [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} 场培训未结束,请与人事约定培训时间并于月内完成课件、签到与评价。',
|
|
// 年培训计划收集推送默认文案(与后端 defaultDemandCollect* 同源引用)
|
|
demand_collect_title: DEFAULT_DEMAND_COLLECT_TITLE,
|
|
demand_collect_content: DEFAULT_DEMAND_COLLECT_CONTENT,
|
|
},
|
|
}
|
|
|
|
const RULE_SCHEMA_KEYS = new Set(RULE_SCHEMAS.map((s) => s.key))
|
|
|
|
// tab 分组:业务规则(签到/评分/积分/达标线/滚动)与推送提醒(notify_*)各自成 tab
|
|
const ruleSchemas = RULE_SCHEMAS.filter((s) => s.group !== 'notify')
|
|
const notifySchemas = RULE_SCHEMAS.filter((s) => s.group === 'notify')
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// 课程分类(course_category_dict):课程管理筛选/表单下拉选项字典,
|
|
// tag 列表增删 + 保存;保存后课程管理页下次拉取即生效。
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const categoryDraft = ref<string[]>([])
|
|
const categorySnapshot = ref('[]')
|
|
const categoryInput = ref('')
|
|
const categoriesSaving = ref(false)
|
|
const categoriesDirty = computed(() => JSON.stringify(categoryDraft.value) !== categorySnapshot.value)
|
|
|
|
const onAddCategory = () => {
|
|
const name = categoryInput.value.trim()
|
|
if (!name) return
|
|
if (categoryDraft.value.some((c) => c === name)) {
|
|
MessagePlugin.warning(`分类「${name}」已存在`)
|
|
return
|
|
}
|
|
categoryDraft.value = [...categoryDraft.value, name]
|
|
categoryInput.value = ''
|
|
}
|
|
|
|
const onRemoveCategory = (name: string) => {
|
|
categoryDraft.value = categoryDraft.value.filter((c) => c !== name)
|
|
}
|
|
|
|
// 恢复默认分类(仅改草稿,点「保存」后落库生效)
|
|
const onResetCategories = () => {
|
|
categoryDraft.value = [...DEFAULT_COURSE_CATEGORIES]
|
|
}
|
|
|
|
const onSaveCategories = async () => {
|
|
if (!categoryDraft.value.length) {
|
|
MessagePlugin.warning('至少保留一个分类')
|
|
return
|
|
}
|
|
categoriesSaving.value = true
|
|
try {
|
|
await saveRuleConfig(COURSE_CATEGORY_DICT_RULE_KEY, { categories: categoryDraft.value })
|
|
categorySnapshot.value = JSON.stringify(categoryDraft.value)
|
|
MessagePlugin.success('课程分类已保存并生效')
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '保存失败')
|
|
} finally {
|
|
categoriesSaving.value = false
|
|
}
|
|
}
|
|
|
|
const ruleValues = ref<Record<string, Record<string, any>>>({})
|
|
const savedSnapshot = ref<Record<string, string>>({})
|
|
const savingKey = ref('')
|
|
|
|
const advancedRows = ref<TrainingRuleConfig[]>([])
|
|
const advancedColumns = [
|
|
{ colKey: 'rule_key', title: '规则', width: 220 },
|
|
{ colKey: 'rule_value', title: '配置值' },
|
|
{ colKey: 'op', title: '操作', width: 80 },
|
|
]
|
|
|
|
const stringify = (v: any) => JSON.stringify(v ?? {})
|
|
|
|
const applyConfigs = (configs: TrainingRuleConfig[]) => {
|
|
const values: Record<string, Record<string, any>> = {}
|
|
const snapshot: Record<string, string> = {}
|
|
for (const schema of RULE_SCHEMAS) {
|
|
const savedRaw = configs.find((c) => c.rule_key === schema.key)?.rule_value
|
|
// parse 转换落库契约(数组/bool)为 UI 表单形态;缺省视为对象。
|
|
const saved = schema.parse ? schema.parse(savedRaw) : savedRaw || {}
|
|
// 默认值打底 + 已保存值覆盖 + 保留配置中的其他键(保存时不丢字段)
|
|
const merged: Record<string, any> = { ...(DEFAULT_RULE_VALUES[schema.key] || {}) }
|
|
for (const k of Object.keys(saved)) merged[k] = saved[k]
|
|
values[schema.key] = merged
|
|
snapshot[schema.key] = JSON.stringify(merged)
|
|
}
|
|
ruleValues.value = values
|
|
savedSnapshot.value = snapshot
|
|
advancedRows.value = configs.filter(
|
|
(c) => !RULE_SCHEMA_KEYS.has(c.rule_key) && c.rule_key !== ROLE_DICT_RULE_KEY && c.rule_key !== COURSE_CATEGORY_DICT_RULE_KEY,
|
|
)
|
|
// 课程分类字典:有专属卡片,缺省回退默认分类(与 fetchCourseCategories 同口径)
|
|
const categoryRaw = configs.find((c) => c.rule_key === COURSE_CATEGORY_DICT_RULE_KEY)?.rule_value?.categories
|
|
const categories = Array.isArray(categoryRaw)
|
|
? categoryRaw.filter((c): c is string => typeof c === 'string' && !!c.trim())
|
|
: [...DEFAULT_COURSE_CATEGORIES]
|
|
categoryDraft.value = categories
|
|
categorySnapshot.value = JSON.stringify(categories)
|
|
}
|
|
|
|
const loadAll = async () => {
|
|
loading.value = true
|
|
try {
|
|
const res = await listRuleConfigs()
|
|
applyConfigs(unwrap<TrainingRuleConfig[]>(res) || [])
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
// ---- 推送记录(2026-11 推学员/推讲师需求,逐人企微/站内投递明细) ----
|
|
|
|
const PUSH_SCENE_OPTIONS = [
|
|
{ value: 'session_notice_student', label: '学员开课通知' },
|
|
{ value: 'remind_monthly_lecturer', label: '周一讲师提醒' },
|
|
{ value: 'remind_lecturer_maintain', label: '课程维护提醒' },
|
|
]
|
|
|
|
const pushScene = ref('')
|
|
const pushLogs = ref<TrainingPushLog[]>([])
|
|
const pushLogsLoading = ref(false)
|
|
const runningWeekly = ref(false)
|
|
|
|
const pushLogColumns = [
|
|
{ colKey: 'created_at', title: '时间', width: 150 },
|
|
{ colKey: 'scene', title: '场景', width: 180 },
|
|
{ colKey: 'title', title: '标题', ellipsis: true },
|
|
{ colKey: 'target', title: '收件人', width: 150 },
|
|
{ colKey: 'push_status', title: '企微状态', width: 100 },
|
|
{ colKey: 'push_error', title: '失败原因', ellipsis: true },
|
|
]
|
|
|
|
const pushStatusLabel = (status: string) => {
|
|
if (!status) return '仅站内'
|
|
const map: Record<string, string> = {
|
|
pending: '排队中',
|
|
sending: '投递中',
|
|
sent: '已送达',
|
|
skipped: '已跳过',
|
|
dead: '已失败',
|
|
}
|
|
return map[status] || status
|
|
}
|
|
|
|
const loadPushLogs = async () => {
|
|
pushLogsLoading.value = true
|
|
try {
|
|
const res = await listTrainingPushLogs({ scenes: pushScene.value || undefined, limit: 200 })
|
|
pushLogs.value = unwrap<TrainingPushLog[]>(res) || []
|
|
} finally {
|
|
pushLogsLoading.value = false
|
|
}
|
|
}
|
|
|
|
const onRunWeekly = async () => {
|
|
runningWeekly.value = true
|
|
try {
|
|
await runWeeklyLecturerReminders()
|
|
MessagePlugin.success('已触发,讲师提醒将按轮次幂等入队并推送')
|
|
loadPushLogs()
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '触发失败')
|
|
} finally {
|
|
runningWeekly.value = false
|
|
}
|
|
}
|
|
|
|
const isDirty = (key: string) => JSON.stringify(ruleValues.value[key]) !== savedSnapshot.value[key]
|
|
|
|
const weightSum = computed(() => {
|
|
const v = ruleValues.value.lecturer_score_weight || {}
|
|
return (Number(v.on_time) || 0) + (Number(v.rating) || 0) + (Number(v.qa) || 0)
|
|
})
|
|
|
|
// 数字字段被清空时回填默认值,避免保存出 null 破坏后端取值
|
|
const buildRulePayload = (schemaKey: string) => {
|
|
const schema = RULE_SCHEMAS.find((s) => s.key === schemaKey)
|
|
const out: Record<string, any> = { ...(ruleValues.value[schemaKey] || {}) }
|
|
for (const f of schema?.fields || []) {
|
|
if (out[f.key] === null || out[f.key] === undefined || out[f.key] === '') {
|
|
out[f.key] = DEFAULT_RULE_VALUES[schemaKey]?.[f.key] ?? 0
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
const onSaveRule = async (schemaKey: string) => {
|
|
const schema = RULE_SCHEMAS.find((s) => s.key === schemaKey)
|
|
savingKey.value = schemaKey
|
|
try {
|
|
const uiValues = buildRulePayload(schemaKey)
|
|
// serialize:UI 表单值 → 落库契约(数组/bool 等,见 RuleSchemaDesc.serialize)。
|
|
const payload = schema?.serialize ? schema.serialize(uiValues) : uiValues
|
|
await saveRuleConfig(schemaKey, payload)
|
|
ruleValues.value = { ...ruleValues.value, [schemaKey]: uiValues }
|
|
savedSnapshot.value = { ...savedSnapshot.value, [schemaKey]: JSON.stringify(uiValues) }
|
|
MessagePlugin.success('规则已保存并生效')
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '保存失败')
|
|
} finally {
|
|
savingKey.value = ''
|
|
}
|
|
}
|
|
|
|
// ---- 高级配置(JSON 兜底) ----
|
|
|
|
const openEdit = (row: TrainingRuleConfig) => {
|
|
activeKey.value = row.rule_key
|
|
editText.value = JSON.stringify(row.rule_value ?? {}, null, 2)
|
|
editVisible.value = true
|
|
}
|
|
|
|
const onSave = async () => {
|
|
let parsed: any
|
|
try {
|
|
parsed = JSON.parse(editText.value)
|
|
} catch {
|
|
MessagePlugin.warning('请输入合法的 JSON')
|
|
return
|
|
}
|
|
saving.value = true
|
|
try {
|
|
await saveRuleConfig(activeKey.value, parsed)
|
|
MessagePlugin.success('规则已保存并生效')
|
|
editVisible.value = false
|
|
loadAll()
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '保存失败')
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
|
|
const seeding = ref(false)
|
|
const onSeed = async () => {
|
|
seeding.value = true
|
|
try {
|
|
const res = await seedRuleConfigs()
|
|
MessagePlugin.success(`已初始化 ${unwrap(res)?.seeded ?? 0} 条默认规则(已存在的键不覆盖)`)
|
|
loadAll()
|
|
loadRoles()
|
|
} catch {
|
|
MessagePlugin.error('初始化失败')
|
|
} finally {
|
|
seeding.value = false
|
|
}
|
|
}
|
|
|
|
// ---- 导入模板 ----
|
|
const templateLoading = ref(false)
|
|
const templates = ref<TrainingTemplateMeta[]>([])
|
|
const uploadInput = ref<HTMLInputElement | null>(null)
|
|
const uploadKey = ref<TrainingTemplateKey | null>(null)
|
|
|
|
const templateColumns = [
|
|
{ colKey: 'file_name', title: '模板' },
|
|
{ colKey: 'file_size', title: '大小', width: 90 },
|
|
{ colKey: 'updated_at', title: '上传时间', width: 160 },
|
|
{ colKey: 'op', title: '操作', width: 210 },
|
|
]
|
|
|
|
const fmtSize = (size: number) => (size >= 1024 ? `${(size / 1024).toFixed(1)} KB` : `${size} B`)
|
|
const fmtTime = (raw: string) => fmtBeijingTime(raw) || '—'
|
|
|
|
const loadTemplates = async () => {
|
|
templateLoading.value = true
|
|
try {
|
|
const res = await listTrainingTemplates()
|
|
templates.value = unwrap(res) || []
|
|
} catch {
|
|
templates.value = []
|
|
} finally {
|
|
templateLoading.value = false
|
|
}
|
|
}
|
|
|
|
const onDownloadTemplate = (row: TrainingTemplateMeta) =>
|
|
downloadTrainingTemplate(row.template_key, row.file_name)
|
|
|
|
// 每行「上传更新」复用同一个隐藏 input,先记录目标模板键
|
|
const onPickUpload = (row: TrainingTemplateMeta) => {
|
|
uploadKey.value = row.template_key
|
|
uploadInput.value?.click()
|
|
}
|
|
|
|
const onUploadFile = async (e: Event) => {
|
|
const input = e.target as HTMLInputElement
|
|
const file = input.files?.[0]
|
|
input.value = ''
|
|
const key = uploadKey.value
|
|
if (!file || !key) return
|
|
try {
|
|
const fd = new FormData()
|
|
fd.append('file', file)
|
|
await uploadTrainingTemplate(key, fd)
|
|
MessagePlugin.success('模板已上传,各下载入口即刻生效')
|
|
loadTemplates()
|
|
} catch (err: any) {
|
|
MessagePlugin.error(err?.response?.data?.message || '上传失败,仅支持 .xls/.xlsx 且不超过 10MB')
|
|
} finally {
|
|
uploadKey.value = null
|
|
}
|
|
}
|
|
|
|
const onResetTemplate = async (row: TrainingTemplateMeta) => {
|
|
try {
|
|
await deleteTrainingTemplate(row.template_key)
|
|
MessagePlugin.success('已恢复为内置默认模板')
|
|
loadTemplates()
|
|
} catch {
|
|
MessagePlugin.error('操作失败')
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadAll()
|
|
loadRoles()
|
|
loadTemplates()
|
|
loadPushLogs()
|
|
})
|
|
|
|
// 场景筛选变化即重拉推送记录
|
|
watch(pushScene, () => loadPushLogs())
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
@import (reference) '../training.less';
|
|
|
|
.panel-box {
|
|
.training-panel-box();
|
|
|
|
& + .panel-box {
|
|
margin-top: 12px;
|
|
}
|
|
|
|
&__sub {
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
}
|
|
|
|
.rule-json {
|
|
font-size: var(--app-text-sm);
|
|
word-break: break-all;
|
|
}
|
|
|
|
.tpl-tag {
|
|
margin-left: 6px;
|
|
}
|
|
|
|
// 复用的隐藏文件选择器
|
|
.tpl-upload-input {
|
|
display: none;
|
|
}
|
|
|
|
// ---- tab 化布局:页头与页签条固定,仅 tab 内容区滚动(000164 布局诉求) ----
|
|
.rule-panel {
|
|
height: 100%;
|
|
min-height: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.rule-tabs {
|
|
flex: 1;
|
|
min-height: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
|
|
:deep(.t-tabs__header) {
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
:deep(.t-tabs__content) {
|
|
flex: 1;
|
|
min-height: 0;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
:deep(.t-tab-panel) {
|
|
padding: 12px 0 0;
|
|
}
|
|
}
|
|
|
|
// ---- 课程分类(tag 列表增删编辑) ----
|
|
.category-editor {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
|
|
.category-input {
|
|
width: 220px;
|
|
}
|
|
|
|
.category-reset {
|
|
margin-left: auto;
|
|
}
|
|
|
|
.form-hint {
|
|
margin-top: 8px;
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
|
|
// ---- 职称角色 ----
|
|
.role-name {
|
|
margin-right: 6px;
|
|
}
|
|
|
|
.role-sys-tag {
|
|
margin-left: 6px;
|
|
}
|
|
|
|
.role-key {
|
|
font-size: var(--app-text-sm);
|
|
color: var(--td-text-color-secondary);
|
|
word-break: break-all;
|
|
}
|
|
|
|
.perm-tag {
|
|
margin-right: 6px;
|
|
}
|
|
|
|
.perm-none {
|
|
color: var(--td-text-color-placeholder);
|
|
}
|
|
|
|
// ---- 业务规则点选式分区 ----
|
|
.rule-section {
|
|
padding: 12px 0;
|
|
|
|
& + .rule-section {
|
|
border-top: 1px solid var(--td-component-stroke);
|
|
}
|
|
|
|
&__head {
|
|
display: flex;
|
|
align-items: baseline;
|
|
gap: 10px;
|
|
|
|
.t-button {
|
|
margin-left: auto;
|
|
}
|
|
}
|
|
|
|
&__title {
|
|
font-weight: 600;
|
|
font-size: var(--app-text-base);
|
|
}
|
|
|
|
&__desc {
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
|
|
&__fields {
|
|
margin-top: 10px;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px 28px;
|
|
}
|
|
}
|
|
|
|
.rule-field {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
|
|
&__label {
|
|
color: var(--td-text-color-secondary);
|
|
font-size: var(--app-text-sm);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
&__input {
|
|
width: 130px;
|
|
}
|
|
|
|
&__unit {
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
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 {
|
|
margin-top: 8px;
|
|
font-size: var(--app-text-sm);
|
|
color: var(--td-text-color-secondary);
|
|
|
|
&--warn {
|
|
color: var(--td-warning-color);
|
|
}
|
|
}
|
|
|
|
/* 推送记录工具行与明细(2026-11 推送管理) */
|
|
.push-toolbar {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
}
|
|
|
|
.push-scene-select {
|
|
width: 180px;
|
|
}
|
|
|
|
.push-empno {
|
|
margin-left: 4px;
|
|
font-size: var(--app-text-xs);
|
|
color: var(--td-text-color-secondary);
|
|
}
|
|
|
|
.push-error {
|
|
display: inline-block;
|
|
max-width: 220px;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
color: var(--td-error-color);
|
|
}
|
|
</style>
|