feat(equipment-acceptance): 补抓E8数据并更新需求文档

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
sophieandCursor committed 2026-10-28 10:55:09 +08:00
1 parent f0334e5d22
commit 02aa00e913
47 files changed
+4423 -1261

No files matched your search

@@ -2,7 +2,9 @@
* features/equipment-acceptance/api/equipment-acceptance.api.ts
* 用途:设备验收预警同步列表、详情和手动同步。
* 依赖:统一 requestJson;后端 /api/equipment-acceptance。
* 逻辑:Chat 作业面调用。同步只读 E10。配置只保存天数和系统用户,不保存发送时刻。
* 逻辑:Chat 作业面调用。同步同时读 E10 和 E8,列表用来源字段区分。
* 停留列表的 keyword 同时查流程编号、验收单号、采购单号,applicant 只查申请人。
* 配置只保存天数和系统用户,不保存发送时刻。
* 保存配置自行声明 Content-Type: application/json,供 Flask get_json 解析。
* 发送记录只读已落库的行。每位收件人的 Excel 可再下载。
*/
@@ -23,7 +25,15 @@ export interface EquipmentAcceptanceOperator {
export interface EquipmentAcceptanceOrder {
id: number;
/** 来源。e10 或 e8。旧数据未返回时为空。 */
oa_system?: string | null;
acceptance_no?: string | null;
/** 流程编号。E10 为 requestmark,E8 为 lcbh。 */
flow_no?: string | null;
/** 流程标题。两边都是流程表 requestname。 */
request_title?: string | null;
/** 流程创建时间。E10 为 createdatetime,E8 为 createdate 加 createtime。 */
request_created_at?: string | null;
purchase_order_no?: string | null;
contract_no?: string | null;
timer_started_at?: string | null;
@@ -72,19 +82,27 @@ export interface EquipmentAcceptanceSyncResult {
/**
* 分页查询已同步的验收单。
* 核心逻辑:focus 对应原型分组。空或 all 不过滤。
* 核心逻辑:focus 对应状态分组。keyword 同时匹配流程编号、验收单号、采购单号。applicant 只匹配申请人。空值不传。
* @param params.focus - watching、overdue、stopped、not_started
* @param params.keyword - 三种单号的包含匹配
* @param params.applicant - 申请人姓名的包含匹配
* @param params.page - 页码,从 1 开始
* @param params.pageSize - 每页条数
* @returns 分页快照和全部单据汇总
* @returns 分页快照和汇总。汇总不看状态分组,但跟着单号和申请人走
*/
export function listEquipmentAcceptanceOrders(params?: {
focus?: string;
keyword?: string;
applicant?: string;
page?: number;
pageSize?: number;
}) {
const query = new URLSearchParams();
if (params?.focus && params.focus !== 'all') query.set('focus', params.focus);
const keyword = params?.keyword?.trim();
const applicant = params?.applicant?.trim();
if (keyword) query.set('keyword', keyword);
if (applicant) query.set('applicant', applicant);
if (params?.page) query.set('page', String(params.page));
if (params?.pageSize) query.set('page_size', String(params.pageSize));
const suffix = query.toString() ? `?${query.toString()}` : '';
@@ -1,19 +1,30 @@
<!--
features/equipment-acceptance/components/EquipmentAcceptanceChatPanel.vue
用途:设备验收预警 Chat 主区:停留列表、详情、发送记录、预警配置,以及管理员同步、扫描和发送。
依赖:停留列表、详情、发送记录、配置页、auth.store、equipment-acceptance.api、DeleteConfirmDialog、vue-router query。
依赖:停留列表、详情、发送记录、配置页、Element Plus、auth.store、equipment-acceptance.api、vue-router query。
逻辑:由 ChatViewContent 在 agent_code=equipment_acceptance 时替换消息列表与输入框。
本文件引入 Element 样式并包住 ElConfigProvider。标题和页签压到两行,下面整块留给当前页。
view=config 打开预警配置;view=sends 打开发送记录;orderId 只在停留列表下钻。
同步只在停留列表。扫描和发送只在发送记录,且仅平台管理员可见。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { RefreshCw } from 'lucide-vue-next';
import { Refresh } from '@element-plus/icons-vue';
import { useI18n } from 'vue-i18n';
import {
ElButton,
ElConfigProvider,
ElMessageBox,
ElTabPane,
ElTabs,
} from 'element-plus';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
import '@/features/admin/styles/element-trial.css';
import { BusinessError } from '@/shared/api/client';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import { useAuthStore } from '@/features/auth/stores/auth.store';
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
import { useMessage } from '@/shared/composables/useMessage';
import {
scanEquipmentAcceptanceAlerts,
@@ -32,9 +43,9 @@ const route = useRoute();
const router = useRouter();
const auth = useAuthStore();
const msg = useMessage();
const { elementLocale } = useElementProvider();
const syncing = ref(false);
const alertRunning = ref(false);
const pendingAlert = ref<'scan' | 'send' | null>(null);
const runningAction = ref<'scan' | 'send' | null>(null);
const listPage = ref<{ reload: () => Promise<void> } | null>(null);
const sendsPage = ref<{ reload: () => Promise<void> } | null>(null);
@@ -44,17 +55,6 @@ const activeView = computed<WorkspaceView>(() => {
if (route.query.view === 'sends') return 'sends';
return 'ledger';
});
const showAlertConfirm = computed({
get: () => pendingAlert.value !== null,
set: (open: boolean) => {
if (!open) pendingAlert.value = null;
},
});
const alertConfirmCopy = computed(() => (
pendingAlert.value === 'send'
? { title: t('admin.equipmentAcceptance.sendAlerts'), message: t('admin.equipmentAcceptance.sendConfirm') }
: { title: t('admin.equipmentAcceptance.scanAlerts'), message: t('admin.equipmentAcceptance.scanConfirm') }
));
const detailId = computed(() => {
if (activeView.value !== 'ledger') return null;
const raw = Number(route.query.orderId);
@@ -97,23 +97,33 @@ function selectView(view: WorkspaceView): void {
}
/**
* 管理员在发送记录页立即扫描或发送。
* 核心逻辑:公共确认框点确定后才调用。先取出动作再关掉弹窗,避免关闭时把待执行动作清掉。
* 只接受本页三个页签,避免 Element 回传任意字符串。
* @param name - 被点中的页签名
*/
function confirmAlertAction(): void {
const action = pendingAlert.value;
pendingAlert.value = null;
if (action) void runAlertAction(action);
function onTabChange(name: string | number): void {
if (name === 'ledger' || name === 'sends' || name === 'config') selectView(name);
}
/**
* 执行已经确认的扫描或发送。
* 核心逻辑:扫描会同步 E10;发送把待发送记录推到企业微信。
* 管理员在发送记录页确认后立即扫描或发送。
* 核心逻辑:确认框取消会拒绝,这里直接返回。扫描会同步 E10;发送把待发送记录推到企业微信。
* @param action - scan 或 send
*/
async function runAlertAction(action: 'scan' | 'send'): Promise<void> {
if (alertRunning.value) return;
alertRunning.value = true;
async function askAlert(action: 'scan' | 'send'): Promise<void> {
if (runningAction.value) return;
const copy = action === 'send'
? { title: t('admin.equipmentAcceptance.sendAlerts'), message: t('admin.equipmentAcceptance.sendConfirm') }
: { title: t('admin.equipmentAcceptance.scanAlerts'), message: t('admin.equipmentAcceptance.scanConfirm') };
try {
await ElMessageBox.confirm(copy.message, copy.title, {
type: 'warning',
confirmButtonText: t('common.deleteDialog.confirm'),
cancelButtonText: t('common.cancel'),
});
} catch {
return;
}
runningAction.value = action;
try {
if (action === 'scan') {
const result = await scanEquipmentAcceptanceAlerts();
@@ -133,12 +143,12 @@ async function runAlertAction(action: 'scan' | 'send'): Promise<void> {
} catch (error) {
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.syncFailed'));
} finally {
alertRunning.value = false;
runningAction.value = null;
}
}
/**
* 管理员从 E10 同步后刷新列表。
* 管理员从 OA 同步后刷新列表。
* 核心逻辑:成功提示写入、跳过和本次未见条数。失败展示业务错误。
*/
async function runSync(): Promise<void> {
@@ -161,65 +171,107 @@ async function runSync(): Promise<void> {
</script>
<template>
<section class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[var(--surface-muted,#f4f7fb)]">
<div class="flex flex-wrap items-center justify-between gap-2 px-5 pt-3">
<div class="min-w-0">
<h1 class="text-lg font-bold text-primary md:text-xl">{{ t('admin.equipmentAcceptance.title') }}</h1>
<ElConfigProvider :locale="elementLocale">
<section class="ea-workspace">
<header class="ea-workspace__bar">
<h1 class="section-title">{{ t('admin.equipmentAcceptance.title') }}</h1>
<div v-if="isAdmin && activeView === 'sends'" class="ea-workspace__actions">
<ElButton :loading="runningAction === 'scan'" :disabled="runningAction !== null" @click="askAlert('scan')">
{{ t('admin.equipmentAcceptance.scanAlerts') }}
</ElButton>
<ElButton :loading="runningAction === 'send'" :disabled="runningAction !== null" @click="askAlert('send')">
{{ t('admin.equipmentAcceptance.sendAlerts') }}
</ElButton>
</div>
<ElButton
v-else-if="isAdmin && activeView === 'ledger' && !detailId"
:icon="Refresh"
:loading="syncing"
@click="runSync"
>
{{ t('admin.equipmentAcceptance.sync') }}
</ElButton>
</header>
<ElTabs :model-value="activeView" class="ea-tabs" @tab-change="onTabChange">
<ElTabPane v-for="tab in tabs" :key="tab.key" :name="tab.key" :label="tab.label" />
</ElTabs>
<div class="ea-workspace__body">
<EquipmentAcceptanceDetailPage
v-if="detailId"
:order-id="detailId"
@back="syncQuery('ledger', null)"
/>
<EquipmentAcceptanceConfigPage
v-else-if="activeView === 'config'"
:editable="isAdmin"
/>
<EquipmentAcceptanceSendsPage v-else-if="activeView === 'sends'" ref="sendsPage" />
<EquipmentAcceptancePage
v-else
ref="listPage"
@open-detail="syncQuery('ledger', $event)"
/>
</div>
<div v-if="isAdmin && activeView === 'sends'" class="flex flex-wrap items-center gap-2">
<button class="btn-secondary-ds" type="button" :disabled="alertRunning" @click="pendingAlert = 'scan'">
{{ t('admin.equipmentAcceptance.scanAlerts') }}
</button>
<button class="btn-secondary-ds" type="button" :disabled="alertRunning" @click="pendingAlert = 'send'">
{{ t('admin.equipmentAcceptance.sendAlerts') }}
</button>
</div>
<button
v-if="isAdmin && activeView === 'ledger' && !detailId"
class="btn-secondary-ds"
type="button"
:disabled="syncing"
@click="runSync"
>
<RefreshCw class="h-4 w-4" aria-hidden="true" />{{ t('admin.equipmentAcceptance.sync') }}
</button>
</div>
<div class="mt-2 flex gap-0 border-b border-default px-5">
<button
v-for="tab in tabs"
:key="tab.key"
type="button"
class="mb-[-1px] border-b-2 px-3 py-2 text-sm font-bold"
:class="activeView === tab.key
? 'border-brand-500 text-brand-600'
: 'border-transparent text-muted hover:text-secondary'"
@click="selectView(tab.key)"
>
{{ tab.label }}
</button>
</div>
<EquipmentAcceptanceDetailPage
v-if="detailId"
:order-id="detailId"
@back="syncQuery('ledger', null)"
/>
<EquipmentAcceptanceConfigPage
v-else-if="activeView === 'config'"
:editable="isAdmin"
/>
<EquipmentAcceptanceSendsPage v-else-if="activeView === 'sends'" ref="sendsPage" />
<EquipmentAcceptancePage
v-else
ref="listPage"
@open-detail="syncQuery('ledger', $event)"
/>
<DeleteConfirmDialog
v-if="isAdmin"
v-model="showAlertConfirm"
:title="alertConfirmCopy.title"
:message="alertConfirmCopy.message"
confirm-tone="primary"
@confirm="confirmAlertAction"
/>
</section>
</section>
</ElConfigProvider>
</template>
<style scoped>
.ea-workspace {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-height: 0;
min-width: 0;
overflow: hidden;
background: var(--surface-muted, var(--el-fill-color-light));
}
.ea-workspace__bar {
display: flex;
flex: none;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 8px 16px 0;
}
.ea-workspace__actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.ea-tabs {
flex: none;
padding: 0 8px;
}
.ea-tabs :deep(.el-tabs__header) {
margin-bottom: 0;
}
.ea-tabs :deep(.el-tabs__nav-wrap::after) {
height: 1px;
background: var(--el-border-color-lighter);
}
.ea-tabs :deep(.el-tabs__content) {
display: none;
}
.ea-tabs :deep(.el-tabs__item) {
height: 36px;
padding: 0 12px;
font-size: var(--el-font-size-base);
line-height: 36px;
}
.ea-workspace__body {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-height: 0;
padding: 8px 12px 12px;
}
</style>
@@ -0,0 +1,41 @@
/**
* features/equipment-acceptance/composables/useFillHeight.ts
* 用途:把 Element 表格高度收成容器剩余像素,表头固定、表体在卡片内滚动。
* 依赖:vue。
* 逻辑:停留列表和发送记录把表格外包一层,本函数监听该层高度并回写给 ElTable 的 height。
*/
import { onBeforeUnmount, onMounted, ref, type Ref } from 'vue';
/**
* 读取容器当前高度,供 ElTable 占满剩余区域。
* 核心逻辑:容器由 flex 撑开,表格再用同样的像素高度内部滚动,避免整页把表头卷走。
* @param host - 表格外层,高度应等于剩余视口
* @returns height 为不小于 160 的像素高度
*/
export function useFillHeight(host: Ref<HTMLElement | null>): { height: Ref<number> } {
const height = ref(240);
let observer: ResizeObserver | null = null;
/**
* 用容器客户区高度更新表格。容器尚未挂上时跳过。
*/
function measure(): void {
const el = host.value;
if (!el) return;
height.value = Math.max(160, Math.floor(el.clientHeight));
}
onMounted(() => {
measure();
if (typeof ResizeObserver === 'undefined' || !host.value) return;
observer = new ResizeObserver(() => measure());
observer.observe(host.value);
});
onBeforeUnmount(() => {
observer?.disconnect();
observer = null;
});
return { height };
}
@@ -1,13 +1,20 @@
<!--
features/equipment-acceptance/views/EquipmentAcceptanceConfigPage.vue
用途:设备验收预警配置页。按升级轮次编辑天数、第 4 轮开关和三个固定岗位。
依赖:equipment-acceptance.api、UserPickerDialog、userPicker.utils、vue-i18n。
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。同一岗位在多个轮次里共用一个人。
发送时刻不在本页,由排程 Cron 配置。非管理员只能查看。
依赖:equipment-acceptance.api、Element Plus、UserPickerDialog、userPicker.utils、vue-i18n。
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。样式和 ElConfigProvider 由作业面提供。
同一岗位在多个轮次里共用一个人。发送时刻不在本页,由排程 Cron 配置。非管理员只能查看。
-->
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import {
ElButton,
ElCard,
ElCheckbox,
ElInputNumber,
ElLoading,
} from 'element-plus';
import { BusinessError } from '@/shared/api/client';
import UserPickerDialog from '@/shared/components/UserPickerDialog.vue';
import { useMessage } from '@/shared/composables/useMessage';
@@ -60,6 +67,7 @@ const ROUNDS: Array<{ index: number; lines: RoundLine[] }> = [
const { t } = useI18n();
const msg = useMessage();
const vLoading = ElLoading.directive;
const loading = ref(false);
const saving = ref(false);
const days = ref<number[]>([30, 37, 44, 51]);
@@ -224,100 +232,74 @@ onMounted(() => {
</script>
<template>
<section class="min-h-0 flex-1 overflow-auto px-5 pb-6 pt-3">
<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>
<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>
<section v-loading="loading" class="ea-scroll">
<p class="ea-lead">{{ t('admin.equipmentAcceptance.configLead') }}</p>
<ElCard v-if="!loading" shadow="never" class="ea-config-card">
<template #header>
<h2 class="ea-card-title">{{ t('admin.equipmentAcceptance.configSheetTitle') }}</h2>
<p class="ea-lead">{{ t('admin.equipmentAcceptance.configSheetLead') }}</p>
</template>
<article
v-for="round in ROUNDS"
:key="round.index"
class="ea-round"
:class="round.index === ROUNDS.length - 1 ? 'ea-round--last' : ''"
>
<div class="ea-round__when">
<b>{{ t('admin.equipmentAcceptance.roundName', { n: round.index + 1 }) }}</b>
<label class="ea-days">
{{ t('admin.equipmentAcceptance.overPrefix') }}
<ElInputNumber
v-model="days[round.index]"
:min="1"
:step="1"
:precision="0"
:disabled="!editable"
controls-position="right"
/>
{{ t('admin.equipmentAcceptance.dayUnit') }}
</label>
<template v-if="round.index === 3">
<ElCheckbox v-model="round4Enabled" :disabled="!editable">
{{ t('admin.equipmentAcceptance.round4Enabled') }}
</ElCheckbox>
<p class="ea-lead">{{ t('admin.equipmentAcceptance.round4ShortHint') }}</p>
</template>
</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>
<div class="ea-round__who" :class="round.index === 3 && !round4Enabled ? 'is-muted' : ''">
<div v-for="(line, lineIndex) in round.lines" :key="`${round.index}-${lineIndex}`" class="ea-line">
<span class="ea-line__tag">{{ t(`admin.equipmentAcceptance.${line.tag}`) }}</span>
<div class="ea-line__body">
<template v-if="line.kind === 'plain'">
<p class="ea-line__text">{{ t(`admin.equipmentAcceptance.${line.text}`) }}</p>
<p v-if="line.note" class="ea-lead">{{ t(`admin.equipmentAcceptance.${line.note}`) }}</p>
</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 v-else class="ea-people">
<div v-for="role in line.roles" :key="role" class="ea-person">
<span class="ea-person__avatar">{{ roleInitial(role) }}</span>
<span class="ea-person__text">
<strong>{{ roleName(role) || t('admin.equipmentAcceptance.roleEmpty') }}</strong>
<span>{{ roleMeta(role) }}</span>
</span>
<ElButton v-if="editable" link type="primary" @click="openPicker(role)">
{{ roleIds[role] ? t('admin.equipmentAcceptance.replaceUser') : t('admin.equipmentAcceptance.selectUser') }}
</ElButton>
<ElButton v-if="editable && roleIds[role]" link @click="clearRole(role)">
{{ t('admin.equipmentAcceptance.clearUser') }}
</ElButton>
</div>
</div>
</div>
</article>
</div>
</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>
</article>
<div class="ea-config-foot">
<span>{{ editable ? t('admin.equipmentAcceptance.configSaveHint') : t('admin.equipmentAcceptance.configReadOnly') }}</span>
<ElButton v-if="editable" type="primary" :loading="saving" @click="save">
{{ t('admin.equipmentAcceptance.saveConfig') }}
</ElButton>
</div>
</ElCard>
<UserPickerDialog
v-model="pickerOpen"
@@ -329,3 +311,166 @@ onMounted(() => {
/>
</section>
</template>
<style scoped>
.ea-scroll {
flex: 1 1 auto;
min-height: 240px;
overflow: auto;
}
.ea-lead {
margin: 0;
font-size: var(--el-font-size-extra-small);
line-height: 1.4;
color: var(--el-text-color-secondary);
}
.ea-scroll > .ea-lead {
margin-bottom: 8px;
}
.ea-config-card :deep(.el-card__header) {
padding: 12px 16px 8px;
}
.ea-config-card :deep(.el-card__body) {
padding: 0 16px 12px;
}
.ea-card-title {
margin: 0 0 4px;
font-size: var(--el-font-size-base);
font-weight: var(--el-font-weight-primary);
color: var(--el-text-color-primary);
}
.ea-round {
position: relative;
display: grid;
grid-template-columns: 200px minmax(0, 1fr);
gap: 12px 20px;
margin-left: 12px;
border-left: 2px solid var(--el-border-color);
padding: 12px 0 12px 20px;
}
.ea-round--last {
border-left-color: transparent;
}
.ea-round::before {
content: '';
position: absolute;
left: -7px;
top: 18px;
width: 12px;
height: 12px;
border: 2px solid var(--el-bg-color);
border-radius: 999px;
background: var(--el-color-primary);
box-shadow: 0 0 0 1px var(--el-border-color);
}
.ea-round__when {
display: flex;
flex-direction: column;
gap: 8px;
color: var(--el-text-color-secondary);
font-size: var(--el-font-size-small);
}
.ea-days {
display: flex;
align-items: center;
gap: 8px;
}
.ea-days :deep(.el-input-number) {
width: 120px;
}
.ea-round__who.is-muted {
opacity: 0.45;
}
.ea-line {
display: flex;
align-items: flex-start;
gap: 8px;
margin-bottom: 8px;
}
.ea-line__tag {
flex: none;
width: 36px;
margin-top: 6px;
font-size: var(--el-font-size-extra-small);
font-weight: var(--el-font-weight-primary);
color: var(--el-text-color-secondary);
}
.ea-line__text {
margin: 6px 0 0;
color: var(--el-text-color-primary);
font-weight: var(--el-font-weight-primary);
}
.ea-people {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.ea-person {
display: flex;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 4px 8px 4px 4px;
border-radius: 999px;
background: var(--el-fill-color-light);
}
.ea-person__avatar {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border-radius: 999px;
background: var(--el-color-primary-light-8);
color: var(--el-color-primary);
font-size: var(--el-font-size-extra-small);
font-weight: var(--el-font-weight-primary);
}
.ea-person__text {
display: flex;
flex-direction: column;
line-height: 1.2;
color: var(--el-text-color-primary);
}
.ea-person__text span {
color: var(--el-text-color-secondary);
font-size: var(--el-font-size-extra-small);
}
.ea-config-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 4px -16px 0;
padding: 12px 16px;
border-top: 1px solid var(--el-border-color-lighter);
color: var(--el-text-color-secondary);
font-size: var(--el-font-size-extra-small);
}
@media (max-width: 720px) {
.ea-round {
grid-template-columns: 1fr;
}
}
</style>
@@ -0,0 +1,75 @@
/**
* features/equipment-acceptance/views/EquipmentAcceptanceDetailPage.spec.ts
* 用途:确认详情在接口返回后能画出标题和当前节点表格,加载遮罩会关掉。
* 依赖:EquipmentAcceptanceDetailPage、vue-i18n、@vue/test-utils。
* 逻辑:只挂本页,接口用桩数据。不覆盖对话壳。
*/
import { flushPromises, mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import { describe, expect, it, vi } from 'vitest';
import { getEquipmentAcceptanceOrder } from '../api/equipment-acceptance.api';
import EquipmentAcceptanceDetailPage from './EquipmentAcceptanceDetailPage.vue';
vi.mock('../api/equipment-acceptance.api', () => ({
getEquipmentAcceptanceOrder: vi.fn(),
}));
const sample = {
id: 1,
request_title: '托威斯平台式自动拉钉机/1套资产验收单提交OA-20260718000003',
acceptance_no: '20260718000003',
flow_no: '20260718-1520',
request_created_at: '2026-07-18T16:51:47',
finished_at: null,
applicant_name: '柴晓红',
purchase_order_no: '5202-2606030008',
flow_status_raw: 1,
dwell_days: null,
timer_started_at: null,
can_accept: 1,
is_returned: 0,
cannot_accept_note: null,
monitor_status: 'not_started',
overdue: false,
nodes: [{ node_id: '1', node_name: '品质担当', node_type: null }],
operators: [{ node_id: '1', user_id: '9', handler_name: '温德佳', handler_job_num: '25060045' }],
};
describe('设备验收详情', () => {
it('接口返回后显示标题、当前节点、处理人和工号,并关掉加载遮罩', async () => {
const errors: unknown[] = [];
vi.mocked(getEquipmentAcceptanceOrder).mockResolvedValue(sample as never);
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
missing: (_locale, key) => key,
messages: { 'zh-CN': {} },
});
const wrapper = mount(EquipmentAcceptanceDetailPage, {
props: { orderId: 1 },
global: {
plugins: [i18n],
config: {
errorHandler(err) {
errors.push(err);
},
},
},
});
await flushPromises();
await new Promise((resolve) => setTimeout(resolve, 500));
const text = wrapper.text();
// 标题用流程标题,不再用验收单号占页眉。
expect(text).toContain(sample.request_title);
// 采购单号单独占字段表第一行。
expect(wrapper.find('.el-descriptions__label').text()).toBe('admin.equipmentAcceptance.purchaseOrderNo');
// 当前节点、处理人、工号只出现在下方表格。
expect(text).toContain('品质担当');
expect(text).toContain('温德佳');
expect(text).toContain('25060045');
// 加载结束不能留下可见遮罩,否则页面会一直转圈。
const mask = wrapper.find('.el-loading-mask');
expect(mask.exists() && mask.isVisible()).toBe(false);
expect(errors).toEqual([]);
});
});
@@ -1,13 +1,26 @@
<!--
features/equipment-acceptance/views/EquipmentAcceptanceDetailPage.vue
用途:一张验收单的详情卡片,展示状态徽章、停留进度、当前节点和操作人。
依赖:equipment-acceptance.api、vue-i18n、统一消息提示。
逻辑:由 Chat 作业面在选中某行后展示。操作人只显示姓名和工号。
用途:一张验收单的详情卡片,展示状态标签、停留进度、当前节点和操作人。
依赖:equipment-acceptance.api、Element Plus、vue-i18n、统一消息提示。
逻辑:由 Chat 作业面在选中某行后展示。样式和 ElConfigProvider 由作业面提供。
页眉是流程标题。采购单号单独占第一行。流程编号与验收单单号、创建时间与结束时间各占一行。申请人单独占一行。
监控状态贴在标题下方。当前节点、处理人和工号只在下方表格出现一次。
进度条只按签核天数画到 30/37/44/51,不表示已经发送。
-->
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import { ArrowLeft } from '@element-plus/icons-vue';
import { useI18n } from 'vue-i18n';
import {
ElButton,
ElDescriptions,
ElDescriptionsItem,
ElLoading,
ElProgress,
ElTable,
ElTableColumn,
ElTag,
} from 'element-plus';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import {
@@ -23,7 +36,7 @@ const emit = defineEmits<{
back: [];
}>();
type BadgeTone = 'red' | 'green' | 'gray';
type TagType = 'danger' | 'success' | 'info';
const STOPPED_STATUSES = new Set([
'stopped_returned',
@@ -49,21 +62,68 @@ const FLOW_STATUS_KEYS: Record<number, string> = {
const REMINDER_DAYS = [30, 37, 44, 51];
interface OperatorRow {
rowKey: string;
nodeName: string;
handlerName: string;
jobNum: string;
}
const { t } = useI18n();
const msg = useMessage();
const vLoading = ElLoading.directive;
const loading = ref(false);
const order = ref<EquipmentAcceptanceOrder | null>(null);
const operatorRows = ref<OperatorRow[]>([]);
/**
* 把接口里的节点和操作人收成表格行。
* 核心逻辑:操作人的 node_id 对上节点名。没有操作人时仍列出节点,人和工号为空。
* 表格会改传入的数组,所以这里每次返回新的普通对象,不把计算属性直接交给表格。
* @param current - 当前验收单,空则没有行
* @returns 当前节点、处理人、工号各一列
*/
function buildOperatorRows(current: EquipmentAcceptanceOrder | null): OperatorRow[] {
if (!current) return [];
const nodes = Array.isArray(current.nodes) ? current.nodes.filter((node) => node) : [];
const people = Array.isArray(current.operators) ? current.operators.filter((item) => item) : [];
const nodeNameById = new Map(
nodes
.filter((node) => node.node_id)
.map((node) => [String(node.node_id), node.node_name || '—']),
);
const namedNodes = nodes.filter((node) => node.node_name);
const onlyNamed = namedNodes.length === 1 ? namedNodes[0] : undefined;
const fallbackNode = onlyNamed?.node_name || '—';
if (!people.length) {
return namedNodes.map((node, index) => ({
rowKey: `node-${node.node_id || index}`,
nodeName: node.node_name || '—',
handlerName: '—',
jobNum: '—',
}));
}
return people.map((item, index) => ({
rowKey: `${item.user_id || ''}-${item.node_id || ''}-${index}`,
nodeName: (item.node_id && nodeNameById.get(String(item.node_id))) || fallbackNode,
handlerName: item.handler_name || '—',
jobNum: item.handler_job_num || '—',
}));
}
/**
* 读取当前验收单详情。
* 核心逻辑:orderId 变化时重新请求。失败清空详情,避免上一张单残留。
* 核心逻辑:先算出表格行,再写入单据。失败时单据和表格一起清空,避免上一张单残留。
*/
async function load(): Promise<void> {
loading.value = true;
try {
order.value = await getEquipmentAcceptanceOrder(props.orderId);
const next = await getEquipmentAcceptanceOrder(props.orderId);
operatorRows.value = buildOperatorRows(next);
order.value = next;
} catch (error) {
order.value = null;
operatorRows.value = [];
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.detailLoadFailed'));
} finally {
loading.value = false;
@@ -80,6 +140,16 @@ function dateText(value?: string | null): string {
return value.slice(0, 10);
}
/**
* 展示流程创建时间,保留时分秒,不按浏览器时区再换算。
* @param value - 接口返回的 ISO 时间
* @returns 本地墙上时间或横线
*/
function dateTimeText(value?: string | null): string {
if (!value) return '—';
return value.replace('T', ' ').replace(/Z$/, '').slice(0, 19);
}
/**
* 把 0/1 写成否/是。可以验收为空时显示未标明,退回在同步时已把空收成否。
* @param value - 标准 0 否、1 是
@@ -114,55 +184,23 @@ function dwellText(item: EquipmentAcceptanceOrder): string {
}
/**
* 当前节点名称。没有节点时为空,模板改显示横线。
* 与列表相同的标签颜色。红是已逾期,绿是不再提醒,灰是未开始和未超时。
* @param item - 当前验收单
* @returns 节点名称列表
* @returns 文案和 Element 标签类型
*/
function nodeNames(item: EquipmentAcceptanceOrder): string[] {
return (item.nodes || []).map((node) => node.node_name).filter((name): name is string => Boolean(name));
}
/**
* 当前处理人去重后拼成一行。
* @param item - 当前验收单
* @returns 处理人姓名
*/
function handlerNames(item: EquipmentAcceptanceOrder): string {
const names = Array.from(new Set(
(item.operators || []).map((person) => person.handler_name).filter((name): name is string => Boolean(name)),
));
return names.length ? names.join('、') : '—';
}
/**
* 与列表相同的徽章颜色。红是已逾期,绿是不再提醒,灰是未开始和未超时。
* @param item - 当前验收单
* @returns 文案和颜色
*/
function statusBadge(item: EquipmentAcceptanceOrder): { label: string; tone: BadgeTone } {
function statusTag(item: EquipmentAcceptanceOrder): { label: string; type: TagType } {
if (item.monitor_status === 'watching' && item.overdue) {
return { label: t('admin.equipmentAcceptance.badgeOverdue'), tone: 'red' };
return { label: t('admin.equipmentAcceptance.badgeOverdue'), type: 'danger' };
}
if (item.monitor_status === 'watching') {
return { label: t('admin.equipmentAcceptance.badgeOnTime'), tone: 'gray' };
return { label: t('admin.equipmentAcceptance.badgeOnTime'), type: 'info' };
}
return {
label: t(`admin.equipmentAcceptance.statusLabel.${item.monitor_status}`),
tone: STOPPED_STATUSES.has(item.monitor_status) ? 'green' : 'gray',
type: STOPPED_STATUSES.has(item.monitor_status) ? 'success' : 'info',
};
}
/**
* 徽章底色。
* @param tone - 徽章颜色
* @returns Tailwind 类名
*/
function badgeClass(tone: BadgeTone): string {
if (tone === 'red') return 'bg-[#fff0ef] text-[#b42318]';
if (tone === 'green') return 'bg-[#eafaf1] text-[#067647]';
return 'bg-[#edf1f6] text-[#475569]';
}
/**
* 按签核天数在 0 到第 4 档之间画进度。没有天数时不画。
* 核心逻辑:刻度至少到 60 天,避免 51 天贴在条的尽头。
@@ -172,8 +210,9 @@ const track = computed(() => {
if (order.value?.monitor_status === 'not_started' || days == null) return null;
const lastMark = REMINDER_DAYS[REMINDER_DAYS.length - 1] ?? 51;
const scale = Math.max(60, lastMark + 9, days);
const percent = Math.min(100, Math.round((days / scale) * 100));
return {
width: `${Math.min(100, Math.round((days / scale) * 100))}%`,
percent,
marks: [0, ...REMINDER_DAYS, scale].map((day) => ({
day,
left: `${(day / scale) * 100}%`,
@@ -192,35 +231,22 @@ watch(() => props.orderId, () => {
</script>
<template>
<section class="min-h-0 flex-1 overflow-auto px-5 pb-6 pt-3">
<button
class="mb-3 rounded-lg border border-[#dce4ef] bg-white px-3 py-1.5 text-xs font-bold text-[#142033]"
type="button"
@click="emit('back')"
>
<section v-loading="loading" class="ea-scroll">
<ElButton class="ea-back" :icon="ArrowLeft" @click="emit('back')">
{{ t('admin.equipmentAcceptance.back') }}
</button>
<p v-if="loading && !order" class="text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.loading') }}</p>
<article v-else-if="order" class="overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
<div class="flex items-start justify-between gap-3 px-4 pt-4">
<h2 class="text-lg font-bold text-[#142033]">{{ order.acceptance_no || '—' }}</h2>
<span
class="inline-flex shrink-0 rounded-full px-2 py-0.5 text-[11px] font-extrabold"
:class="badgeClass(statusBadge(order).tone)"
>
{{ statusBadge(order).label }}
</span>
</div>
</ElButton>
<article v-if="order" class="ea-detail">
<header class="ea-detail__head">
<h2>{{ order.request_title || order.acceptance_no || '—' }}</h2>
<ElTag :type="statusTag(order).type" effect="light">{{ statusTag(order).label }}</ElTag>
</header>
<div v-if="track" class="px-7 pt-5">
<div class="h-2 overflow-hidden rounded-full bg-[#e7edf5]">
<i class="block h-full rounded-full bg-gradient-to-r from-[#93c5fd] to-[#2563eb]" :style="{ width: track.width }"></i>
</div>
<div class="relative mt-1 h-4 text-[11px] text-[#64748b]">
<div v-if="track" class="ea-track">
<ElProgress :percentage="track.percent" :show-text="false" :stroke-width="8" />
<div class="ea-track__marks">
<span
v-for="mark in track.marks"
:key="mark.day"
class="absolute -translate-x-1/2 whitespace-nowrap"
:style="{ left: mark.left }"
>
{{ mark.label }}
@@ -228,87 +254,130 @@ watch(() => props.orderId, () => {
</div>
</div>
<div class="flex flex-wrap gap-1.5 px-4 pb-1 pt-4">
<span
v-for="(name, index) in nodeNames(order)"
:key="`${name}-${index}`"
class="rounded-full bg-[#dbeafe] px-2 py-1 text-[11px] font-extrabold text-[#1d4ed8]"
>
{{ name }}
</span>
<span v-if="!nodeNames(order).length" class="text-sm text-[#64748b]">—</span>
</div>
<ElDescriptions :column="2" border>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.purchaseOrderNo')" :span="2">
{{ order.purchase_order_no || '—' }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.flowNo')">
{{ order.flow_no || '—' }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.acceptanceNo')">
{{ order.acceptance_no || '—' }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.createdAt')">
{{ dateTimeText(order.request_created_at) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.finishedAt')">
{{ dateText(order.finished_at) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.applicant')" :span="2">
{{ order.applicant_name || '—' }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.flowStatus')" :span="2">
{{ flowText(order.flow_status_raw) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.dwellDays')">
{{ dwellText(order) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.timerStart')">
{{ dateText(order.timer_started_at) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.canAccept')">
{{ yesNo(order.can_accept, t('admin.equipmentAcceptance.unspecified')) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.returnFlag')">
{{ yesNo(order.is_returned, t('common.no')) }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="t('admin.equipmentAcceptance.cannotAcceptNote')" :span="2">
<span class="ea-pre">{{ order.cannot_accept_note || '—' }}</span>
</ElDescriptionsItem>
</ElDescriptions>
<dl class="mt-3 grid border-t border-[#dce4ef] px-4 sm:grid-cols-2">
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.purchaseOrderNo') }}</dt>
<dd class="text-[#142033]">{{ order.purchase_order_no || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.applicant') }}</dt>
<dd class="text-[#142033]">{{ order.applicant_name || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.dwellDays') }}</dt>
<dd class="text-[#142033]">{{ dwellText(order) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.timerStart') }}</dt>
<dd class="text-[#142033]">{{ dateText(order.timer_started_at) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:col-span-2">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.currentHandlers') }}</dt>
<dd class="text-[#142033]">{{ handlerNames(order) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.canAccept') }}</dt>
<dd class="text-[#142033]">{{ yesNo(order.can_accept, t('admin.equipmentAcceptance.unspecified')) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:col-span-2">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.cannotAcceptNote') }}</dt>
<dd class="whitespace-pre-wrap text-[#142033]">{{ order.cannot_accept_note || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.returnFlag') }}</dt>
<dd class="text-[#142033]">{{ yesNo(order.is_returned, t('common.no')) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.flowStatus') }}</dt>
<dd class="text-[#142033]">{{ flowText(order.flow_status_raw) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.finishedAt') }}</dt>
<dd class="text-[#142033]">{{ dateText(order.finished_at) }}</dd>
</div>
</dl>
<div class="px-4 pb-4 pt-4">
<h3 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.operators') }}</h3>
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.operatorsNote') }}</p>
<div class="mt-3 overflow-auto rounded-xl border border-[#dce4ef]">
<table class="w-full min-w-[640px] 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.operatorName') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.jobNum') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="(item, index) in order.operators"
:key="`${item.user_id}-${item.node_id}-${index}`"
class="border-t border-[#dce4ef]"
>
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ item.handler_name || '—' }}</td>
<td class="px-3 py-2.5">{{ item.handler_job_num || '—' }}</td>
</tr>
<tr v-if="!order.operators.length">
<td colspan="2" class="px-3 py-6 text-center text-[#64748b]">—</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 class="ea-operators-title">{{ t('admin.equipmentAcceptance.operators') }}</h3>
<p class="ea-lead">{{ t('admin.equipmentAcceptance.operatorsNote') }}</p>
<ElTable class="ea-operators" :data="operatorRows" row-key="rowKey" :empty-text="'—'">
<ElTableColumn :label="t('admin.equipmentAcceptance.currentNodes')" min-width="160">
<template #default="{ row }">{{ row.nodeName }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.currentHandlers')" min-width="160">
<template #default="{ row }">{{ row.handlerName }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.jobNum')" min-width="140">
<template #default="{ row }">{{ row.jobNum }}</template>
</ElTableColumn>
</ElTable>
</article>
</section>
</template>
<style scoped>
.ea-scroll {
flex: 1 1 auto;
min-height: 0;
overflow: auto;
}
.ea-back {
margin-bottom: 8px;
}
.ea-detail {
padding: 16px;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color);
border-radius: var(--el-border-radius-base);
}
.ea-detail__head {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
margin-bottom: 12px;
}
.ea-detail__head h2 {
margin: 0;
font-size: var(--el-font-size-large);
font-weight: var(--el-font-weight-primary);
line-height: 1.4;
color: var(--el-text-color-primary);
overflow-wrap: anywhere;
}
.ea-track {
padding: 16px 12px 0;
}
.ea-track__marks {
position: relative;
height: 18px;
margin-top: 4px;
color: var(--el-text-color-secondary);
font-size: var(--el-font-size-extra-small);
}
.ea-track__marks span {
position: absolute;
white-space: nowrap;
transform: translateX(-50%);
}
.ea-pre {
white-space: pre-wrap;
}
.ea-operators-title {
margin: 16px 0 4px;
font-size: var(--el-font-size-base);
font-weight: var(--el-font-weight-primary);
color: var(--el-text-color-primary);
}
.ea-lead {
margin: 0 0 8px;
font-size: var(--el-font-size-extra-small);
line-height: 1.4;
color: var(--el-text-color-secondary);
}
</style>
@@ -1,16 +1,30 @@
<!--
features/equipment-acceptance/views/EquipmentAcceptancePage.vue
用途:设备验收预警停留列表,对齐原型的汇总卡、分组筛选和状态徽章。
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n。
逻辑:由 Chat 作业面嵌入。点「查看详情」交给父级下钻。
已逾期只看接口给出的 overdue。发送结果在「发送记录」页,这里不显示第几档。
用途:设备验收预警停留列表。四张数字卡既是总览也是状态筛选。
依赖:equipment-acceptance.api、Element Plus、useFillHeight、统一消息提示、vue-i18n。
逻辑:由 Chat 作业面嵌入。样式和 ElConfigProvider 由 EquipmentAcceptanceChatPanel 提供。
点一张卡片只看该状态,再点一次回到全部。单号和申请人是另外两个输入框。
点「查看详情」交给父级下钻。已逾期只看接口给出的 overdue。
列表前五列是来源、标题、采购单号、验收单单号、流程编号,其余列接在后面。
发送结果在「发送记录」页,这里不显示第几档。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import {
ElButton,
ElCard,
ElInput,
ElLoading,
ElPagination,
ElStatistic,
ElTable,
ElTableColumn,
ElTag,
} from 'element-plus';
import { BusinessError } from '@/shared/api/client';
import PaginationBar from '@/shared/components/PaginationBar.vue';
import { useMessage } from '@/shared/composables/useMessage';
import { useFillHeight } from '../composables/useFillHeight';
import {
listEquipmentAcceptanceOrders,
type EquipmentAcceptanceOrder,
@@ -22,7 +36,7 @@ const emit = defineEmits<{
}>();
type FocusKey = 'all' | 'watching' | 'overdue' | 'stopped' | 'not_started';
type BadgeTone = 'red' | 'green' | 'gray';
type TagType = 'danger' | 'success' | 'info';
const STOPPED_STATUSES = new Set([
'stopped_returned',
@@ -33,23 +47,23 @@ const STOPPED_STATUSES = new Set([
'stopped_revoked',
]);
const filters: Array<{ key: FocusKey; label: string }> = [
{ key: 'all', label: 'filterAll' },
{ key: 'watching', label: 'filterWatching' },
{ key: 'overdue', label: 'filterOverdue' },
{ key: 'stopped', label: 'filterStopped' },
{ key: 'not_started', label: 'filterNotStarted' },
];
const PAGE_SIZES = [10, 20, 50, 100];
const { t } = useI18n();
const msg = useMessage();
const vLoading = ElLoading.directive;
const tableHost = ref<HTMLElement | null>(null);
const { height: tableHeight } = useFillHeight(tableHost);
const loading = ref(false);
const orders = ref<EquipmentAcceptanceOrder[]>([]);
const focus = ref<FocusKey>('all');
const page = ref(1);
const pageSize = ref(20);
const total = ref(0);
const pages = ref(1);
const keyword = ref('');
const applicant = ref('');
let searchTimer: ReturnType<typeof setTimeout> | null = null;
let skipNextInput = false;
const summary = ref<EquipmentAcceptanceSummary>({
watching: 0,
overdue: 0,
@@ -57,10 +71,17 @@ const summary = ref<EquipmentAcceptanceSummary>({
not_started: 0,
});
const kpis = computed(() => [
{ key: 'watching' as const, label: 'kpiWatching', value: summary.value.watching },
{ key: 'overdue' as const, label: 'kpiOverdue', value: summary.value.overdue },
{ key: 'stopped' as const, label: 'kpiStopped', value: summary.value.stopped },
{ key: 'not_started' as const, label: 'filterNotStarted', value: summary.value.not_started },
]);
/**
* 加载当前分组的验收单,并刷新全部单据的汇总数字。
* 核心逻辑:汇总不受当前筛选影响,由接口的 summary 给出。
* @param resetPage - 为 true 时回到第一页,用于更换筛选。
* 核心逻辑:状态分组只影响表格。单号和申请人同时影响表格和分组数字。
* @param resetPage - 为 true 时回到第一页,用于更换筛选或每页条数。
*/
async function load(resetPage = false): Promise<void> {
if (resetPage) page.value = 1;
@@ -68,12 +89,13 @@ async function load(resetPage = false): Promise<void> {
try {
const result = await listEquipmentAcceptanceOrders({
focus: focus.value,
keyword: keyword.value,
applicant: applicant.value,
page: page.value,
pageSize: pageSize.value,
});
orders.value = result.items || [];
total.value = result.total || 0;
pages.value = result.pages || 1;
if (result.summary) summary.value = result.summary;
} catch (error) {
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.loadFailed'));
@@ -83,15 +105,93 @@ async function load(resetPage = false): Promise<void> {
}
/**
* 切换原型分组并回到第一页。
* @param next - all、watching、overdue、stopped、not_started
* 用数字卡切换停留分组,并回到第一页。
* 核心逻辑:再点当前卡片回到全部,避免卡片下面再放一排同样的标签。
* @param next - watching、overdue、stopped、not_started
*/
function selectFocus(next: FocusKey): void {
if (focus.value === next) return;
focus.value = next;
focus.value = focus.value === next ? 'all' : next;
void load(true);
}
/**
* 翻页后按当前分组重拉。
* @param next - 从 1 开始的页码
*/
function onPageChange(next: number): void {
if (page.value === next) return;
page.value = next;
void load();
}
/**
* 更换每页条数后回到第一页,避免停在已经不存在的页上。
* @param next - 每页条数
*/
function onSizeChange(next: number): void {
pageSize.value = next;
void load(true);
}
/**
* 停掉尚未发出的搜索,避免连续按键打出一串过期请求。
*/
function clearSearchTimer(): void {
if (searchTimer === null) return;
clearTimeout(searchTimer);
searchTimer = null;
}
/**
* 单号或申请人变化后稍等再查,并回到第一页。
* 核心逻辑:输入停 300 毫秒才请求。清空按钮紧接着还会发一次 input,那一次丢掉。
*/
function scheduleSearch(): void {
if (skipNextInput) {
skipNextInput = false;
return;
}
clearSearchTimer();
searchTimer = setTimeout(() => {
searchTimer = null;
void load(true);
}, 300);
}
/**
* 立刻按当前两个输入框查询。
* 核心逻辑:回车或点清空时不等待防抖。清空后的 input 由 skipNextInput 吃掉。
*/
function searchNow(): void {
clearSearchTimer();
skipNextInput = true;
queueMicrotask(() => {
skipNextInput = false;
});
void load(true);
}
/**
* 把来源代码显示成 E10 或 E8。
* @param order - 列表行
* @returns 来源名称,空值显示横线
*/
function sourceText(order: EquipmentAcceptanceOrder): string {
if (order.oa_system === 'e10') return t('admin.equipmentAcceptance.sourceE10');
if (order.oa_system === 'e8') return t('admin.equipmentAcceptance.sourceE8');
return '—';
}
/**
* 空单元格显示横线。
* @param value - 接口原值
* @returns 文本或横线
*/
function textOrDash(value?: string | null): string {
const text = String(value || '').trim();
return text || '—';
}
/**
* 把节点名称拼成一格。没有节点时显示横线。
* @param order - 列表行
@@ -124,6 +224,17 @@ function dateText(value?: string | null): string {
return value.slice(0, 10);
}
/**
* 展示流程创建时间,保留时分秒,不按浏览器时区再换算。
* @param value - 接口返回的 ISO 时间
* @returns 本地墙上时间或横线
*/
function dateTimeText(value?: string | null): string {
if (!value) return '—';
const text = value.replace('T', ' ').replace(/Z$/, '');
return text.slice(0, 19);
}
/**
* 未开始或没有天数时显示横线,其余显示「N 天」。
* @param order - 列表行
@@ -135,130 +246,270 @@ function dwellText(order: EquipmentAcceptanceOrder): string {
}
/**
* 按监控状态收成徽章。已逾期用红色,表示还要提醒。不再提醒用绿色,未开始和未超时用灰色。
* 按监控状态收成标签。已逾期用危险色,不再提醒用成功色,未开始和未超时用信息色。
* @param order - 列表行
* @returns 文案和颜色
* @returns 文案和 Element 标签类型
*/
function statusBadge(order: EquipmentAcceptanceOrder): { label: string; tone: BadgeTone } {
function statusTag(order: EquipmentAcceptanceOrder): { label: string; type: TagType } {
if (order.monitor_status === 'watching' && order.overdue) {
return { label: t('admin.equipmentAcceptance.badgeOverdue'), tone: 'red' };
return { label: t('admin.equipmentAcceptance.badgeOverdue'), type: 'danger' };
}
if (order.monitor_status === 'watching') {
return { label: t('admin.equipmentAcceptance.badgeOnTime'), tone: 'gray' };
return { label: t('admin.equipmentAcceptance.badgeOnTime'), type: 'info' };
}
return {
label: t(`admin.equipmentAcceptance.statusLabel.${order.monitor_status}`),
tone: STOPPED_STATUSES.has(order.monitor_status) ? 'green' : 'gray',
type: STOPPED_STATUSES.has(order.monitor_status) ? 'success' : 'info',
};
}
/**
* 徽章底色。红是已逾期,绿是不再提醒,灰是未超时、未开始和不在监控范围。
* @param tone - 徽章颜色
* @returns Tailwind 类名
*/
function badgeClass(tone: BadgeTone): string {
if (tone === 'red') return 'bg-[#fff0ef] text-[#b42318]';
if (tone === 'green') return 'bg-[#eafaf1] text-[#067647]';
return 'bg-[#edf1f6] text-[#475569]';
}
defineExpose({ reload: () => load(false) });
onMounted(() => {
void load();
});
onBeforeUnmount(() => {
clearSearchTimer();
});
</script>
<template>
<section class="flex min-h-0 flex-1 flex-col gap-3 px-5 pb-4 pt-3">
<div class="grid grid-cols-4 gap-3">
<article class="rounded-xl border border-[#dce4ef] bg-white px-4 py-3.5">
<b class="block text-[26px] font-bold leading-none text-[#142033]">{{ summary.watching }}</b>
<span class="mt-1 block text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.kpiWatching') }}</span>
</article>
<article class="rounded-xl border border-[#dce4ef] bg-white px-4 py-3.5">
<b class="block text-[26px] font-bold leading-none text-[#142033]">{{ summary.overdue }}</b>
<span class="mt-1 block text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.kpiOverdue') }}</span>
</article>
<article class="rounded-xl border border-[#dce4ef] bg-white px-4 py-3.5">
<b class="block text-[26px] font-bold leading-none text-[#142033]">{{ summary.stopped }}</b>
<span class="mt-1 block text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.kpiStopped') }}</span>
</article>
<article class="rounded-xl border border-[#dce4ef] bg-white px-4 py-3.5">
<b class="block text-[26px] font-bold leading-none text-[#142033]">{{ summary.not_started }}</b>
<span class="mt-1 block text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.filterNotStarted') }}</span>
</article>
<div class="ea-board">
<div class="ea-kpis">
<ElCard
v-for="item in kpis"
:key="item.key"
shadow="never"
class="ea-kpi"
:class="{ 'is-active': focus === item.key }"
role="button"
tabindex="0"
@click="selectFocus(item.key)"
@keyup.enter="selectFocus(item.key)"
>
<ElStatistic :title="t(`admin.equipmentAcceptance.${item.label}`)" :value="item.value" />
</ElCard>
</div>
<div class="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
<div class="flex flex-wrap gap-2 p-3">
<button
v-for="item in filters"
:key="item.key"
type="button"
class="rounded-full border px-2.5 py-1 text-xs font-bold"
:class="focus === item.key
? 'border-[#bfdbfe] bg-[#eaf2ff] text-[#1d4ed8]'
: 'border-[#dce4ef] bg-white text-[#475569]'"
@click="selectFocus(item.key)"
>
{{ t(`admin.equipmentAcceptance.${item.label}`) }}
</button>
</div>
<div class="min-h-0 flex-1 overflow-auto">
<table class="min-w-[960px] w-full border-collapse text-left text-xs">
<thead class="sticky top-0 bg-[#f8fbff] text-[#64748b]">
<tr>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.acceptanceNo') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.purchaseOrderNo') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.applicant') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.currentNodes') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.currentHandlers') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.timerStart') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.dwellDays') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.status') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="item in orders" :key="item.id" class="border-b border-[#dce4ef] hover:bg-[#f3f7ff]">
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ item.acceptance_no || '—' }}</td>
<td class="px-3 py-2.5">{{ item.purchase_order_no || '—' }}</td>
<td class="px-3 py-2.5">{{ item.applicant_name || '—' }}</td>
<td class="px-3 py-2.5">{{ nodeNames(item) }}</td>
<td class="px-3 py-2.5">{{ handlerNames(item) }}</td>
<td class="px-3 py-2.5">{{ dateText(item.timer_started_at) }}</td>
<td class="px-3 py-2.5">{{ dwellText(item) }}</td>
<td class="px-3 py-2.5">
<span
class="inline-flex rounded-full px-2 py-0.5 text-[11px] font-extrabold"
:class="badgeClass(statusBadge(item).tone)"
>
{{ statusBadge(item).label }}
</span>
</td>
<td class="px-3 py-2.5">
<button class="font-extrabold text-[#175cd3]" type="button" @click="emit('open-detail', item.id)">
{{ t('admin.equipmentAcceptance.detail') }}
</button>
</td>
</tr>
<tr v-if="!loading && !orders.length">
<td colspan="9" class="px-3 py-9 text-center text-[#64748b]">{{ t('admin.equipmentAcceptance.empty') }}</td>
</tr>
</tbody>
</table>
<section class="ea-pane">
<div class="ea-filters">
<div class="ea-searches">
<ElInput
v-model="keyword"
clearable
class="ea-filter-keyword"
:placeholder="t('admin.equipmentAcceptance.keywordPlaceholder')"
@input="scheduleSearch"
@clear="searchNow"
@keyup.enter="searchNow"
/>
<ElInput
v-model="applicant"
clearable
class="ea-filter-applicant"
:placeholder="t('admin.equipmentAcceptance.applicant')"
@input="scheduleSearch"
@clear="searchNow"
@keyup.enter="searchNow"
/>
</div>
</div>
<PaginationBar
class="shrink-0"
v-model:page="page"
v-model:page-size="pageSize"
:total="total"
:pages="pages"
@update:page="() => load()"
@update:page-size="() => load()"
/>
</section>
<div ref="tableHost" class="ea-table-host">
<ElTable
v-loading="loading"
class="ea-table"
:data="orders"
:height="tableHeight"
row-key="id"
:empty-text="t('admin.equipmentAcceptance.empty')"
>
<ElTableColumn :label="t('admin.equipmentAcceptance.source')" width="72" class-name="ea-ellipsis">
<template #default="{ row }">
<span class="ea-strong">{{ sourceText(row as EquipmentAcceptanceOrder) }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.requestTitle')" min-width="220" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceOrder).request_title) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.purchaseOrderNo')" min-width="132" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceOrder).purchase_order_no) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.acceptanceNo')" min-width="156" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">
<span class="ea-strong">{{ textOrDash((row as EquipmentAcceptanceOrder).acceptance_no) }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.flowNo')" min-width="132" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceOrder).flow_no) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.createdAt')" min-width="168" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ dateTimeText((row as EquipmentAcceptanceOrder).request_created_at) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.applicant')" min-width="88" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceOrder).applicant_name) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.currentNodes')" min-width="120" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ nodeNames(row as EquipmentAcceptanceOrder) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.currentHandlers')" min-width="120" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ handlerNames(row as EquipmentAcceptanceOrder) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.timerStart')" min-width="112" class-name="ea-ellipsis">
<template #default="{ row }">{{ dateText((row as EquipmentAcceptanceOrder).timer_started_at) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.dwellDays')" min-width="96" class-name="ea-ellipsis">
<template #default="{ row }">{{ dwellText(row as EquipmentAcceptanceOrder) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.status')" min-width="168">
<template #default="{ row }">
<ElTag :type="statusTag(row as EquipmentAcceptanceOrder).type" effect="light">
{{ statusTag(row as EquipmentAcceptanceOrder).label }}
</ElTag>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.actions')" width="96" fixed="right" align="right">
<template #default="{ row }">
<ElButton link type="primary" @click="emit('open-detail', (row as EquipmentAcceptanceOrder).id)">
{{ t('admin.equipmentAcceptance.detail') }}
</ElButton>
</template>
</ElTableColumn>
</ElTable>
</div>
<div class="ea-pager">
<ElPagination
background
layout="total, sizes, prev, pager, next"
:total="total"
:page-size="pageSize"
:current-page="page"
:page-sizes="PAGE_SIZES"
@current-change="onPageChange"
@size-change="onSizeChange"
/>
</div>
</section>
</div>
</template>
<style scoped>
.ea-board {
display: flex;
flex: 1 1 auto;
flex-direction: column;
gap: 8px;
min-height: 0;
min-width: 0;
}
.ea-kpis {
display: grid;
flex: none;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px;
}
.ea-kpi {
cursor: pointer;
border-radius: 12px;
}
.ea-kpi.is-active {
border-color: var(--el-color-primary);
}
.ea-kpi:focus-visible {
outline: 2px solid var(--el-color-primary);
outline-offset: 2px;
}
.ea-kpi :deep(.el-card__body) {
padding: 14px 16px;
}
.ea-kpi :deep(.el-statistic) {
display: flex;
flex-direction: column-reverse;
align-items: flex-start;
--el-statistic-content-font-size: 26px;
}
.ea-kpi :deep(.el-statistic__head) {
margin-top: 6px;
margin-bottom: 0;
color: var(--el-text-color-secondary);
font-size: var(--el-font-size-extra-small);
line-height: 1.2;
}
.ea-kpi :deep(.el-statistic__content) {
line-height: 1;
}
.ea-pane {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-height: 0;
min-width: 0;
overflow: hidden;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color);
border-radius: var(--el-border-radius-base);
}
.ea-filters {
display: flex;
flex: none;
flex-wrap: wrap;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-bottom: 1px solid var(--el-border-color-lighter);
}
.ea-searches {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.ea-filter-keyword {
width: 18rem;
flex: none;
}
.ea-filter-applicant {
width: 11rem;
flex: none;
}
.ea-table-host {
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
}
.ea-table :deep(.el-table__cell) {
padding-top: 6px;
padding-bottom: 6px;
}
.ea-table :deep(.ea-ellipsis .cell) {
white-space: nowrap;
word-break: normal;
}
.ea-strong {
font-weight: var(--el-font-weight-primary);
color: var(--el-text-color-primary);
}
.ea-pager {
display: flex;
flex: none;
justify-content: flex-end;
padding: 8px 12px;
border-top: 1px solid var(--el-border-color-lighter);
}
</style>
@@ -1,55 +1,89 @@
<!--
features/equipment-acceptance/views/EquipmentAcceptanceSendsPage.vue
用途:设备验收预警发送记录页,列出每张验收单某一档的主送、抄送、Excel 附件和结果。
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n、lucide 图标。
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。Excel 附件列点击文件名下载。发送失败时悬停图标看原因。
依赖:equipment-acceptance.api、Element Plus、useFillHeight、统一消息提示、vue-i18n。
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。样式和 ElConfigProvider 由作业面提供。
Excel 附件列点击文件名下载。发送失败时悬停图标看原因。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { CircleAlert, Download } from 'lucide-vue-next';
import { Download, Warning } from '@element-plus/icons-vue';
import { useI18n } from 'vue-i18n';
import {
ElButton,
ElLoading,
ElPagination,
ElTable,
ElTableColumn,
ElTag,
ElTooltip,
} from 'element-plus';
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 { useFillHeight } from '../composables/useFillHeight';
import {
downloadEquipmentAcceptanceSendFile,
listEquipmentAcceptanceSends,
type EquipmentAcceptanceSendRecord,
} from '../api/equipment-acceptance.api';
type TagType = 'success' | 'danger' | 'warning' | 'info';
const PAGE_SIZES = [10, 20, 50, 100];
const { t, te } = useI18n();
const msg = useMessage();
const vLoading = ElLoading.directive;
const tableHost = ref<HTMLElement | null>(null);
const { height: tableHeight } = useFillHeight(tableHost);
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);
/**
* 拉取当前页发送记录。
* 核心逻辑:失败时清空表格并提示。空列表留给模板显示「还没有发送记录」。
* 核心逻辑:失败时清空表格并提示。空列表留给表格显示「还没有发送记录」。
* @param resetPage - 为 true 时回到第一页,用于更换每页条数。
*/
async function load(): Promise<void> {
async function load(resetPage = false): Promise<void> {
if (resetPage) page.value = 1;
loading.value = true;
try {
const result = await listEquipmentAcceptanceSends({ page: page.value, pageSize: pageSize.value });
records.value = result.items || [];
total.value = result.total || 0;
pages.value = Math.max(1, Math.ceil(total.value / pageSize.value));
} catch (error) {
records.value = [];
total.value = 0;
pages.value = 1;
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.sendsFailed'));
} finally {
loading.value = false;
}
}
/**
* 翻页后重拉发送记录。
* @param next - 从 1 开始的页码
*/
function onPageChange(next: number): void {
if (page.value === next) return;
page.value = next;
void load();
}
/**
* 更换每页条数后回到第一页。
* @param next - 每页条数
*/
function onSizeChange(next: number): void {
pageSize.value = next;
void load(true);
}
/**
* 轮次列写成「超过 N 天」。
* @param item - 一条发送记录
@@ -69,6 +103,18 @@ function statusText(status: string): string {
return te(key) ? t(key) : status;
}
/**
* 发送结果对应的标签颜色。
* @param status - pending、sent、failed、cancelled
* @returns Element 标签类型
*/
function sendTagType(status: string): TagType {
if (status === 'sent') return 'success';
if (status === 'failed') return 'danger';
if (status === 'pending') return 'warning';
return 'info';
}
/**
* 已发送显示本地时间,待发送没有时间时显示横线。
* @param value - 接口返回的发送时间
@@ -81,27 +127,13 @@ function sentText(value?: string | null): string {
}
/**
* 在失败图标下方显示原因。用固定定位,避免被表格滚动容器裁掉。
* @param event - 悬停或聚焦事件
* @param message - 发送失败原因
* 空单元格显示横线。
* @param value - 接口原值
* @returns 文本或横线
*/
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;
function textOrDash(value?: string | null): string {
const text = String(value || '').trim();
return text || '—';
}
/**
@@ -133,97 +165,159 @@ onMounted(() => {
void load();
});
defineExpose({ reload: load });
defineExpose({ reload: () => load(false) });
</script>
<template>
<section class="flex min-h-0 flex-1 flex-col gap-3 px-5 pb-4 pt-3">
<p class="text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.sendsLead') }}</p>
<div class="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
<div class="min-h-0 flex-1 overflow-auto">
<table class="min-w-[960px] w-full border-collapse text-left text-xs">
<thead class="sticky top-0 bg-[#f8fbff] text-[#64748b]">
<tr>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.acceptanceNo') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.purchaseOrderNo') }}</th>
<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>
<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>
<tbody>
<tr v-for="item in records" :key="item.id" class="border-b border-[#dce4ef]">
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ item.acceptance_no || '—' }}</td>
<td class="px-3 py-2.5">{{ item.purchase_order_no || '—' }}</td>
<td class="px-3 py-2.5">{{ tierText(item) }}</td>
<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">
<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="8" class="px-3 py-10 text-center text-[#64748b]">
{{ t('admin.equipmentAcceptance.sendsEmpty') }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
<PaginationBar
class="shrink-0"
v-model:page="page"
v-model:page-size="pageSize"
:total="total"
:pages="pages"
@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` }"
<section class="ea-pane">
<p class="ea-lead">{{ t('admin.equipmentAcceptance.sendsLead') }}</p>
<div ref="tableHost" class="ea-table-host">
<ElTable
v-loading="loading"
class="ea-table"
:data="records"
:height="tableHeight"
row-key="id"
:empty-text="t('admin.equipmentAcceptance.sendsEmpty')"
>
{{ failureTip.text }}
</div>
</Teleport>
<ElTableColumn :label="t('admin.equipmentAcceptance.acceptanceNo')" min-width="156" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">
<span class="ea-strong">{{ textOrDash((row as EquipmentAcceptanceSendRecord).acceptance_no) }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.purchaseOrderNo')" min-width="132" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceSendRecord).purchase_order_no) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.ruleTier')" min-width="120" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ tierText(row as EquipmentAcceptanceSendRecord) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.ruleTo')" min-width="160" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceSendRecord).to_text) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.ruleCc')" min-width="160" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ textOrDash((row as EquipmentAcceptanceSendRecord).cc_text) }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.sendResult')" min-width="140">
<template #default="{ row }">
<span class="ea-result">
<ElTag :type="sendTagType((row as EquipmentAcceptanceSendRecord).status)" effect="light">
{{ statusText((row as EquipmentAcceptanceSendRecord).status) }}
</ElTag>
<ElTooltip
v-if="(row as EquipmentAcceptanceSendRecord).status === 'failed'"
:content="(row as EquipmentAcceptanceSendRecord).error_message || t('admin.equipmentAcceptance.failureReasonEmpty')"
placement="top"
>
<ElButton
link
type="danger"
:icon="Warning"
:title="t('admin.equipmentAcceptance.failureReasonAria')"
/>
</ElTooltip>
</span>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.excelColumn')" min-width="220">
<template #default="{ row }">
<div v-if="(row as EquipmentAcceptanceSendRecord).files?.length" class="ea-files">
<ElButton
v-for="file in (row as EquipmentAcceptanceSendRecord).files"
:key="file.id"
link
type="primary"
:icon="Download"
:loading="downloadingId === file.id"
:title="t('admin.equipmentAcceptance.excelColumn')"
@click="downloadFile(file)"
>
{{ file.excel_file_name }}
</ElButton>
</div>
<span v-else>—</span>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.equipmentAcceptance.sentAt')" min-width="168" class-name="ea-ellipsis" show-overflow-tooltip>
<template #default="{ row }">{{ sentText((row as EquipmentAcceptanceSendRecord).sent_at) }}</template>
</ElTableColumn>
</ElTable>
</div>
<div class="ea-pager">
<ElPagination
background
layout="total, sizes, prev, pager, next"
:total="total"
:page-size="pageSize"
:current-page="page"
:page-sizes="PAGE_SIZES"
@current-change="onPageChange"
@size-change="onSizeChange"
/>
</div>
</section>
</template>
<style scoped>
.ea-pane {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-height: 0;
min-width: 0;
overflow: hidden;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color);
border-radius: var(--el-border-radius-base);
}
.ea-lead {
flex: none;
margin: 0;
padding: 8px 12px;
border-bottom: 1px solid var(--el-border-color-lighter);
font-size: var(--el-font-size-extra-small);
line-height: 1.4;
color: var(--el-text-color-secondary);
}
.ea-table-host {
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
}
.ea-table :deep(.el-table__cell) {
padding-top: 6px;
padding-bottom: 6px;
}
.ea-table :deep(.ea-ellipsis .cell) {
white-space: nowrap;
word-break: normal;
}
.ea-strong {
font-weight: var(--el-font-weight-primary);
color: var(--el-text-color-primary);
}
.ea-result {
display: inline-flex;
align-items: center;
gap: 4px;
}
.ea-files {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.ea-pager {
display: flex;
flex: none;
justify-content: flex-end;
padding: 8px 12px;
border-top: 1px solid var(--el-border-color-lighter);
}
</style>