fix: 设备验收预警优化

This commit is contained in:
sophie committed 2026-10-13 15:52:09 +08:00
1 parent 7e7bcbd388
commit b8cc0cbe77
25 files changed
+1398 -193

No files matched your search

@@ -1,8 +1,8 @@
<!--
features/equipment-acceptance/views/EquipmentAcceptanceConfigPage.vue
用途:设备验收预警配置页。编辑四档天数,并为三个固定岗位选择系统用户。
用途:设备验收预警配置页。按升级轮次编辑天数、第 4 轮开关和三个固定岗位。
依赖:equipment-acceptance.api、UserPickerDialog、userPicker.utils、vue-i18n。
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。姓名只用于展示。
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。同一岗位在多个轮次里共用一个人。
发送时刻不在本页,由排程 Cron 配置。非管理员只能查看。
-->
<script setup lang="ts">
@@ -23,15 +23,47 @@ const props = defineProps<{
}>();
type RoleKey = 'buyer_manager' | 'coo' | 'executive';
type RoundLine =
| { kind: 'plain'; tag: 'ruleTo' | 'ruleCc'; text: string; note?: string }
| { kind: 'roles'; tag: 'ruleTo' | 'ruleCc'; roles: RoleKey[] };
const ROLE_FIELDS: RoleKey[] = ['buyer_manager', 'coo', 'executive'];
const TIER_WHO = ['tierWho1', 'tierWho2', 'tierWho3', 'tierWho4'] as const;
const ROUNDS: Array<{ index: number; lines: RoundLine[] }> = [
{
index: 0,
lines: [
{ kind: 'plain', tag: 'ruleTo', text: 'ruleTo1' },
{ kind: 'plain', tag: 'ruleCc', text: 'ruleCc1', note: 'roundFixedNote' },
],
},
{
index: 1,
lines: [
{ kind: 'plain', tag: 'ruleTo', text: 'ruleTo2' },
{ kind: 'roles', tag: 'ruleCc', roles: ['coo', 'buyer_manager'] },
],
},
{
index: 2,
lines: [
{ kind: 'roles', tag: 'ruleTo', roles: ['coo'] },
{ kind: 'roles', tag: 'ruleCc', roles: ['buyer_manager'] },
],
},
{
index: 3,
lines: [
{ kind: 'roles', tag: 'ruleTo', roles: ['executive'] },
{ kind: 'roles', tag: 'ruleCc', roles: ['coo', 'buyer_manager'] },
],
},
];
const { t } = useI18n();
const msg = useMessage();
const loading = ref(false);
const saving = ref(false);
const days = ref<number[]>([30, 37, 44, 51]);
const round4Enabled = ref(false);
const roleIds = ref<Record<RoleKey, number | null>>({
buyer_manager: null,
coo: null,
@@ -54,13 +86,6 @@ const pickerSelectedIds = computed(() => {
return id ? [id] : [];
});
const ruleRows = computed(() => ([
{ to: 'ruleTo1', cc: 'ruleCc1' },
{ to: 'ruleTo2', cc: 'ruleCc2' },
{ to: 'ruleTo3', cc: 'ruleCc3' },
{ to: 'ruleTo4', cc: 'ruleCc4' },
]));
/**
* 读取当前配置。管理员响应里包含候选人。
* 核心逻辑:失败时保留页面上的默认天数,并用统一错误提示。
@@ -70,6 +95,7 @@ async function load(): Promise<void> {
try {
const result = await getEquipmentAcceptanceConfig();
days.value = result.days?.length === 4 ? [...result.days] : [30, 37, 44, 51];
round4Enabled.value = result.round_4_enabled === true;
roleIds.value = {
buyer_manager: result.buyer_manager_user_id ?? null,
coo: result.coo_user_id ?? null,
@@ -114,7 +140,7 @@ function clearRole(role: RoleKey): void {
}
/**
* 保存天数和三个岗位。天数须逐档增大。
* 保存天数、第 4 轮开关和三个岗位。天数须逐档增大。
* 核心逻辑:先在页面拦住空值和倒序,服务端再校验用户是否存在。
*/
async function save(): Promise<void> {
@@ -131,11 +157,13 @@ async function save(): Promise<void> {
try {
const result = await saveEquipmentAcceptanceConfig({
days: nextDays,
round4Enabled: round4Enabled.value,
buyerManagerUserId: roleIds.value.buyer_manager,
cooUserId: roleIds.value.coo,
executiveUserId: roleIds.value.executive,
});
days.value = [...result.days];
round4Enabled.value = result.round_4_enabled === true;
knownUsers.value = result.selected_users || [];
candidates.value = result.users || [];
msg.success(t('admin.equipmentAcceptance.configSaved'));
@@ -147,14 +175,47 @@ async function save(): Promise<void> {
}
/**
* 岗位上已选用户的展示名。没有选择时返回空串,模板改显示未选择。
* @param role - 岗位键
* @returns 姓名,有工号时附在后面
* 取出某个岗位已选的人。没有选择时为空。
* @param role - buyer_manager、coo、executive
* @returns 选人组件里的用户,或空
*/
function roleLabel(role: RoleKey): string {
function rolePerson(role: RoleKey): UserPickerPerson | undefined {
const id = roleIds.value[role];
if (!id) return '';
return userPickerLabel(people.value.get(id), id);
if (!id) return undefined;
return people.value.get(id);
}
/**
* 芯片上的姓名。没有选择时返回空串。
* @param role - 岗位键
* @returns 展示名
*/
function roleName(role: RoleKey): string {
const person = rolePerson(role);
if (!person) return '';
return userPickerLabel(person).replace(/([^)]*)$/, '') || userPickerLabel(person);
}
/**
* 姓名首字,画在圆形头像里。
* @param role - 岗位键
* @returns 一个字符
*/
function roleInitial(role: RoleKey): string {
const name = roleName(role).trim();
return name.slice(0, 1) || '?';
}
/**
* 芯片第二行:工号和岗位名。
* @param role - 岗位键
* @returns 例如 26030025 · COO
*/
function roleMeta(role: RoleKey): string {
const person = rolePerson(role);
const roleText = t(`admin.equipmentAcceptance.role.${role}`);
const employeeId = String(person?.employee_id || person?.username || '').trim();
return employeeId ? `${employeeId} · ${roleText}` : roleText;
}
onMounted(() => {
@@ -167,97 +228,95 @@ onMounted(() => {
<p class="mb-3 text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.configLead') }}</p>
<p v-if="loading" class="text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.loading') }}</p>
<template v-else>
<div class="grid grid-cols-4 gap-3">
<label
v-for="(who, index) in TIER_WHO"
:key="who"
class="rounded-xl border border-[#dce4ef] border-t-[3px] bg-white px-3 py-3"
:class="index === 0 ? 'border-t-[#93c5fd]' : index === 1 ? 'border-t-[#2563eb]' : index === 2 ? 'border-t-[#d97706]' : 'border-t-[#dc2626]'"
>
<span class="block text-xs font-bold text-[#64748b]">{{ t(`admin.equipmentAcceptance.tier${index + 1}`) }}</span>
<span class="mt-2 flex items-center gap-2">
<input
v-model.number="days[index]"
class="h-11 w-16 rounded-lg border border-[#d7dee8] bg-[#f8fafc] text-center text-xl font-bold text-[#142033] disabled:opacity-70"
type="number"
min="1"
:disabled="!editable"
/>
<span class="text-sm font-semibold text-[#94a3b8]">{{ t('admin.equipmentAcceptance.dayUnit') }}</span>
</span>
<span class="mt-2 block text-xs font-bold text-[#334155]">{{ t(`admin.equipmentAcceptance.${who}`) }}</span>
</label>
</div>
<div class="mt-3 grid gap-3 lg:grid-cols-2">
<article class="rounded-xl border border-[#dce4ef] bg-white">
<h2 class="px-4 pt-4 text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.fixedRoles') }}</h2>
<div class="px-4 pb-2">
<div
v-for="role in ROLE_FIELDS"
:key="role"
class="grid grid-cols-[108px_minmax(0,1fr)] items-center gap-3 border-b border-[#dce4ef] py-3 last:border-b-0"
>
<span class="text-sm font-bold text-[#334155]">{{ t(`admin.equipmentAcceptance.role.${role}`) }}</span>
<div class="flex min-w-0 flex-wrap items-center gap-2">
<span v-if="roleLabel(role)" class="truncate text-sm text-[#142033]">{{ roleLabel(role) }}</span>
<span v-else class="text-sm text-[#94a3b8]">{{ t('admin.equipmentAcceptance.roleEmpty') }}</span>
<button
v-if="editable"
class="ml-auto rounded-lg border border-[#bfdbfe] bg-[#eaf2ff] px-2.5 py-1 text-xs font-bold text-[#1d4ed8]"
type="button"
@click="openPicker(role)"
>
{{ t('admin.equipmentAcceptance.selectUser') }}
</button>
<button
v-if="editable && roleIds[role]"
class="text-xs font-bold text-[#64748b]"
type="button"
@click="clearRole(role)"
>
{{ t('admin.equipmentAcceptance.clearUser') }}
</button>
<section class="overflow-hidden rounded-2xl border border-[#dce4ef] bg-white">
<div class="px-5 pb-2 pt-4">
<h2 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.configSheetTitle') }}</h2>
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.configSheetLead') }}</p>
</div>
<div class="px-3 pb-2">
<article
v-for="round in ROUNDS"
:key="round.index"
class="relative ml-4 grid grid-cols-1 gap-3 border-l-2 border-[#c9d4e3] py-4 pl-7 sm:grid-cols-[168px_minmax(0,1fr)] sm:gap-x-5"
:class="round.index === ROUNDS.length - 1 ? 'border-transparent' : ''"
>
<span class="absolute -left-[7px] top-6 h-3 w-3 rounded-full border-2 border-white bg-[#1d4e89] shadow-[0_0_0_1px_#c9d4e3]"></span>
<div class="flex flex-col gap-2">
<b class="text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.roundName', { n: round.index + 1 }) }}</b>
<label class="flex items-center gap-2 text-[13px] text-[#64748b]">
{{ t('admin.equipmentAcceptance.overPrefix') }}
<input
v-model.number="days[round.index]"
class="h-10 w-[72px] rounded-lg border border-[#d5dee8] bg-[#f8fafc] text-center text-[22px] font-semibold text-[#142033] disabled:opacity-70"
type="number"
min="1"
:disabled="!editable"
/>
{{ t('admin.equipmentAcceptance.dayUnit') }}
</label>
<template v-if="round.index === 3">
<label class="flex items-center gap-1.5 text-[13px] font-bold text-[#142033]">
<input v-model="round4Enabled" class="h-4 w-4 accent-[#1d4e89]" type="checkbox" :disabled="!editable" />
{{ t('admin.equipmentAcceptance.round4Enabled') }}
</label>
<small class="text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.round4ShortHint') }}</small>
</template>
</div>
<div class="flex flex-col gap-2" :class="round.index === 3 && !round4Enabled ? 'opacity-45' : ''">
<div v-for="(line, lineIndex) in round.lines" :key="`${round.index}-${lineIndex}`" class="flex items-start gap-2.5">
<span class="mt-1.5 w-9 shrink-0 text-xs font-bold text-[#64748b]">{{ t(`admin.equipmentAcceptance.${line.tag}`) }}</span>
<div class="min-w-0">
<template v-if="line.kind === 'plain'">
<p class="mt-1 text-sm font-semibold text-[#142033]">{{ t(`admin.equipmentAcceptance.${line.text}`) }}</p>
<p v-if="line.note" class="mt-1 text-xs text-[#94a3b8]">{{ t(`admin.equipmentAcceptance.${line.note}`) }}</p>
</template>
<div v-else class="flex flex-wrap gap-2">
<div
v-for="role in line.roles"
:key="role"
class="flex min-h-8 items-center gap-2 rounded-full bg-[#eef3f8] py-1 pl-1 pr-2"
>
<span class="grid h-6 w-6 place-items-center rounded-full bg-[#d7e4f2] text-xs font-bold text-[#1d4e89]">{{ roleInitial(role) }}</span>
<span class="flex flex-col leading-tight">
<strong class="text-[13px] text-[#142033]">{{ roleName(role) || t('admin.equipmentAcceptance.roleEmpty') }}</strong>
<span class="text-[11px] text-[#64748b]">{{ roleMeta(role) }}</span>
</span>
<button
v-if="editable"
class="text-xs font-bold text-[#1d4e89]"
type="button"
@click="openPicker(role)"
>
{{ roleIds[role] ? t('admin.equipmentAcceptance.replaceUser') : t('admin.equipmentAcceptance.selectUser') }}
</button>
<button
v-if="editable && roleIds[role]"
class="text-xs text-[#64748b]"
type="button"
@click="clearRole(role)"
>
{{ t('admin.equipmentAcceptance.clearUser') }}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="flex items-center justify-between gap-3 border-t border-[#dce4ef] bg-[#fafbfd] px-4 py-3">
<span class="text-xs text-[#64748b]">{{ editable ? t('admin.equipmentAcceptance.configSaveHint') : t('admin.equipmentAcceptance.configReadOnly') }}</span>
<button
v-if="editable"
class="rounded-lg bg-[#2563eb] px-3 py-1.5 text-xs font-bold text-white disabled:opacity-50"
type="button"
:disabled="saving"
@click="save"
>
{{ t('admin.equipmentAcceptance.saveConfig') }}
</button>
</div>
</article>
<article class="overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
<div class="px-4 pt-4">
<h2 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.rulesTitle') }}</h2>
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.rulesLead') }}</p>
</div>
<table class="mt-3 w-full border-collapse text-left text-xs">
<thead class="bg-[#f8fbff] text-[#64748b]">
<tr>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleTier') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleTo') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleCc') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in ruleRows" :key="row.to" class="border-t border-[#dce4ef]">
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.ruleOver', { days: days[index] || '—' }) }}</td>
<td class="px-3 py-2.5">{{ t(`admin.equipmentAcceptance.${row.to}`) }}</td>
<td class="px-3 py-2.5">{{ t(`admin.equipmentAcceptance.${row.cc}`) }}</td>
</tr>
</tbody>
</table>
</article>
</div>
</article>
</div>
<div class="flex items-center justify-between gap-4 border-t border-[#dce4ef] bg-[#fafbfd] px-5 py-3.5">
<span class="text-xs text-[#64748b]">{{ editable ? t('admin.equipmentAcceptance.configSaveHint') : t('admin.equipmentAcceptance.configReadOnly') }}</span>
<button
v-if="editable"
class="h-9 rounded-lg bg-[#1d4e89] px-4 text-[13px] font-bold text-white disabled:opacity-50"
type="button"
:disabled="saving"
@click="save"
>
{{ t('admin.equipmentAcceptance.saveConfig') }}
</button>
</div>
</section>
</template>
<UserPickerDialog