fix: 设备验收预警优化
This commit is contained in:
1 parent
7e7bcbd388
commit
b8cc0cbe77
25 files changed
+1398
-193
No files matched your search
@@ -4,9 +4,9 @@
|
||||
* 依赖:统一 requestJson;后端 /api/equipment-acceptance。
|
||||
* 逻辑:Chat 作业面调用。同步只读 E10。配置只保存天数和系统用户,不保存发送时刻。
|
||||
* 保存配置自行声明 Content-Type: application/json,供 Flask get_json 解析。
|
||||
* 发送记录只读已落库的行,扫描尚未写入时列表为空。
|
||||
* 发送记录只读已落库的行。每位收件人的 Excel 可再下载。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { requestBlob, requestJson } from '@/shared/api/client';
|
||||
|
||||
export interface EquipmentAcceptanceNode {
|
||||
node_id?: string | null;
|
||||
@@ -150,6 +150,7 @@ export interface EquipmentAcceptanceSendRecord {
|
||||
sent_at?: string | null;
|
||||
error_message?: string | null;
|
||||
created_at?: string | null;
|
||||
files?: Array<{ id: number; excel_file_name?: string | null }>;
|
||||
}
|
||||
|
||||
export interface EquipmentAcceptanceSendListResponse {
|
||||
@@ -166,6 +167,33 @@ export interface EquipmentAcceptanceSendListResponse {
|
||||
* @param params.pageSize - 每页条数
|
||||
* @returns 当前页记录和总数
|
||||
*/
|
||||
export interface EquipmentAcceptanceSendFile {
|
||||
id: number;
|
||||
recipient_name?: string | null;
|
||||
excel_file_name?: string | null;
|
||||
excel_file_size?: number | null;
|
||||
status: string;
|
||||
sent_at?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出最近按收件人归档的 Excel。不含文件内容。
|
||||
* @returns 文件摘要
|
||||
*/
|
||||
export function listEquipmentAcceptanceSendFiles() {
|
||||
return requestJson<{ items: EquipmentAcceptanceSendFile[] }>('/api/equipment-acceptance/send-files');
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载一份当时发给收件人的 Excel。
|
||||
* @param fileId - 归档文件主键
|
||||
* @returns 文件字节和文件名
|
||||
*/
|
||||
export function downloadEquipmentAcceptanceSendFile(fileId: number) {
|
||||
return requestBlob(`/api/equipment-acceptance/send-files/${fileId}/excel`);
|
||||
}
|
||||
|
||||
export function listEquipmentAcceptanceSends(params?: { page?: number; pageSize?: number }) {
|
||||
const search = new URLSearchParams();
|
||||
if (params?.page) search.set('page', String(params.page));
|
||||
@@ -185,6 +213,7 @@ export interface EquipmentAcceptanceConfigUser {
|
||||
|
||||
export interface EquipmentAcceptanceConfig {
|
||||
days: number[];
|
||||
round_4_enabled?: boolean;
|
||||
buyer_manager_user_id?: number | null;
|
||||
coo_user_id?: number | null;
|
||||
executive_user_id?: number | null;
|
||||
@@ -202,9 +231,10 @@ export function getEquipmentAcceptanceConfig() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存四档天数和三个岗位的系统用户。仅平台管理员。
|
||||
* 核心逻辑:岗位传用户主键或 null,不传姓名。
|
||||
* 保存四档天数、第 4 轮开关和三个岗位的系统用户。仅平台管理员。
|
||||
* 核心逻辑:岗位传用户主键或 null,不传姓名。第 4 轮关闭时不通知总经理。
|
||||
* @param payload.days - 四个逐档增大的天数
|
||||
* @param payload.round4Enabled - 是否启用第 4 轮
|
||||
* @param payload.buyerManagerUserId - 采购经副理
|
||||
* @param payload.cooUserId - COO
|
||||
* @param payload.executiveUserId - 总经理对应岗位
|
||||
@@ -212,6 +242,7 @@ export function getEquipmentAcceptanceConfig() {
|
||||
*/
|
||||
export function saveEquipmentAcceptanceConfig(payload: {
|
||||
days: number[];
|
||||
round4Enabled: boolean;
|
||||
buyerManagerUserId: number | null;
|
||||
cooUserId: number | null;
|
||||
executiveUserId: number | null;
|
||||
@@ -221,6 +252,7 @@ export function saveEquipmentAcceptanceConfig(payload: {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
days: payload.days,
|
||||
round_4_enabled: payload.round4Enabled,
|
||||
buyer_manager_user_id: payload.buyerManagerUserId,
|
||||
coo_user_id: payload.cooUserId,
|
||||
executive_user_id: payload.executiveUserId,
|
||||
|
||||
+166
-107
@@ -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
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<!--
|
||||
features/equipment-acceptance/views/EquipmentAcceptanceSendsPage.vue
|
||||
用途:设备验收预警发送记录页,列出每张验收单某一档的主送、抄送和结果。
|
||||
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n。
|
||||
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。只读已落库记录。扫描尚未写入时显示空状态。
|
||||
用途:设备验收预警发送记录页,列出每张验收单某一档的主送、抄送、Excel 附件和结果。
|
||||
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n、lucide 图标。
|
||||
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。Excel 附件列点击文件名下载。发送失败时悬停图标看原因。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { CircleAlert, Download } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { formatLocalDateTime } from '@/shared/utils/dateTime';
|
||||
import {
|
||||
downloadEquipmentAcceptanceSendFile,
|
||||
listEquipmentAcceptanceSends,
|
||||
type EquipmentAcceptanceSendRecord,
|
||||
} from '../api/equipment-acceptance.api';
|
||||
@@ -19,11 +21,13 @@ import {
|
||||
const { t, te } = useI18n();
|
||||
const msg = useMessage();
|
||||
const records = ref<EquipmentAcceptanceSendRecord[]>([]);
|
||||
const downloadingId = ref<number | null>(null);
|
||||
const loading = ref(false);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const total = ref(0);
|
||||
const pages = ref(1);
|
||||
const failureTip = ref<{ text: string; left: number; top: number } | null>(null);
|
||||
|
||||
/**
|
||||
* 拉取当前页发送记录。
|
||||
@@ -76,6 +80,55 @@ function sentText(value?: string | null): string {
|
||||
return text === '-' ? '—' : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在失败图标下方显示原因。用固定定位,避免被表格滚动容器裁掉。
|
||||
* @param event - 悬停或聚焦事件
|
||||
* @param message - 发送失败原因
|
||||
*/
|
||||
function openFailureTip(event: Event, message: string): void {
|
||||
const target = event.currentTarget;
|
||||
if (!(target instanceof HTMLElement)) return;
|
||||
const rect = target.getBoundingClientRect();
|
||||
const width = 280;
|
||||
failureTip.value = {
|
||||
text: message || t('admin.equipmentAcceptance.failureReasonEmpty'),
|
||||
left: Math.max(8, Math.min(rect.left, window.innerWidth - width - 8)),
|
||||
top: rect.bottom + 6,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标离开或失焦时关掉失败原因提示。
|
||||
*/
|
||||
function closeFailureTip(): void {
|
||||
failureTip.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载一份已归档的收件人 Excel。
|
||||
* 核心逻辑:接口返回当时发出的字节,由浏览器保存。
|
||||
* @param file - 这一行上的 Excel 摘要
|
||||
*/
|
||||
async function downloadFile(file: { id: number; excel_file_name?: string | null }): Promise<void> {
|
||||
if (downloadingId.value === file.id) return;
|
||||
downloadingId.value = file.id;
|
||||
try {
|
||||
const { blob, filename } = await downloadEquipmentAcceptanceSendFile(file.id);
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = objectUrl;
|
||||
anchor.download = filename || file.excel_file_name || `equipment-acceptance-alert-${file.id}.xlsx`;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.excelDownloadFailed'));
|
||||
} finally {
|
||||
downloadingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
});
|
||||
@@ -97,6 +150,7 @@ defineExpose({ reload: load });
|
||||
<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>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.sendResult') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.excelColumn') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.sentAt') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -108,15 +162,43 @@ defineExpose({ reload: load });
|
||||
<td class="px-3 py-2.5">{{ item.to_text || '—' }}</td>
|
||||
<td class="px-3 py-2.5">{{ item.cc_text || '—' }}</td>
|
||||
<td class="px-3 py-2.5">
|
||||
{{ statusText(item.status) }}
|
||||
<span v-if="item.error_message" class="mt-1 block text-[#b42318]">
|
||||
{{ item.error_message }}
|
||||
<span class="inline-flex items-center gap-1" :class="item.status === 'failed' ? 'font-bold text-[#b42318]' : ''">
|
||||
{{ statusText(item.status) }}
|
||||
<button
|
||||
v-if="item.status === 'failed'"
|
||||
class="inline-flex h-[22px] w-[22px] items-center justify-center rounded-full text-[#b42318] hover:bg-[#fff1f2]"
|
||||
type="button"
|
||||
:aria-label="t('admin.equipmentAcceptance.failureReasonAria')"
|
||||
@mouseenter="openFailureTip($event, item.error_message || '')"
|
||||
@mouseleave="closeFailureTip"
|
||||
@focus="openFailureTip($event, item.error_message || '')"
|
||||
@blur="closeFailureTip"
|
||||
>
|
||||
<CircleAlert class="h-4 w-4" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-3 py-2.5">
|
||||
<div v-if="item.files?.length" class="flex max-w-[280px] flex-col gap-1">
|
||||
<button
|
||||
v-for="file in item.files"
|
||||
:key="file.id"
|
||||
class="inline-flex min-w-0 items-center gap-1 font-semibold text-[#2563eb] disabled:opacity-50"
|
||||
type="button"
|
||||
:disabled="downloadingId === file.id"
|
||||
:title="t('admin.equipmentAcceptance.excelColumn')"
|
||||
@click="downloadFile(file)"
|
||||
>
|
||||
<Download class="h-3.5 w-3.5 shrink-0" />
|
||||
<span class="truncate">{{ file.excel_file_name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<span v-else>—</span>
|
||||
</td>
|
||||
<td class="px-3 py-2.5">{{ sentText(item.sent_at) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && !records.length">
|
||||
<td colspan="7" class="px-3 py-10 text-center text-[#64748b]">
|
||||
<td colspan="8" class="px-3 py-10 text-center text-[#64748b]">
|
||||
{{ t('admin.equipmentAcceptance.sendsEmpty') }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -133,5 +215,15 @@ defineExpose({ reload: load });
|
||||
@update:page="() => load()"
|
||||
@update:page-size="() => load()"
|
||||
/>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="failureTip"
|
||||
class="pointer-events-none fixed z-[80] max-w-[280px] whitespace-normal break-words rounded-lg bg-slate-900 px-2.5 py-1.5 text-xs leading-relaxed text-white shadow-lg"
|
||||
role="tooltip"
|
||||
:style="{ left: `${failureTip.left}px`, top: `${failureTip.top}px` }"
|
||||
>
|
||||
{{ failureTip.text }}
|
||||
</div>
|
||||
</Teleport>
|
||||
</section>
|
||||
</template>
|
||||
Reference in new issue
Block a user