<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesTraceCrossRegionApi } from '#/api/mes/trace/crossregion';
|
|
import { gsap } from 'gsap';
|
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
|
import { useAccess } from '@vben/access';
|
import { CountTo, Page } from '@vben/common-ui';
|
import { IconifyIcon } from '@vben/icons';
|
|
import {
|
Card,
|
Col,
|
message,
|
Modal,
|
Row,
|
Segmented,
|
Skeleton,
|
Tag,
|
} from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
getTraceCrossRegionConfig,
|
getTraceCrossRegionPage,
|
getTraceCrossRegionSummary,
|
handleTraceCrossRegion,
|
updateTraceCrossRegionConfig,
|
} from '#/api/mes/trace/crossregion';
|
|
import {
|
WARNING_LEVEL_OPTIONS,
|
useGridColumns,
|
useGridFormSchema,
|
} from './data';
|
|
defineOptions({ name: 'MesTraceCrossRegion' });
|
|
const { hasAccessByCodes } = useAccess();
|
const canHandle = hasAccessByCodes(['mes:trace-cross-region:handle']);
|
|
/** 汇总数据 */
|
const summary = ref<MesTraceCrossRegionApi.Summary>({});
|
const summaryLoading = ref(false);
|
|
/** 判定粒度配置 */
|
const warningLevel = ref('PROVINCE');
|
|
/** 处理弹窗状态 */
|
const handleVisible = ref(false);
|
const handleLoading = ref(false);
|
|
/** GSAP 入场动画上下文(卸载时自动还原) */
|
let animationContext: gsap.Context | undefined;
|
const handleForm = ref<{
|
id?: number;
|
status: number;
|
handleRemark?: string;
|
}>({
|
id: undefined,
|
status: 20,
|
handleRemark: '',
|
});
|
|
/** 汇总卡片配置 */
|
const summaryCards = [
|
{
|
label: '预警总数',
|
value: 'total',
|
icon: 'lucide:alert-triangle',
|
color: '#409eff',
|
bg: 'linear-gradient(135deg, #409eff, #66b1ff)',
|
},
|
{
|
label: '待处理',
|
value: 'pending',
|
icon: 'lucide:clock',
|
color: '#e6a23c',
|
bg: 'linear-gradient(135deg, #e6a23c, #ebb563)',
|
},
|
{
|
label: '已处理',
|
value: 'handled',
|
icon: 'lucide:circle-check',
|
color: '#67c23a',
|
bg: 'linear-gradient(135deg, #67c23a, #85ce61)',
|
},
|
{
|
label: '误报',
|
value: 'falseAlarm',
|
icon: 'lucide:shield-x',
|
color: '#909399',
|
bg: 'linear-gradient(135deg, #909399, #b1b3b8)',
|
},
|
{
|
label: '跨省窜货',
|
value: 'crossProvince',
|
icon: 'lucide:map-pin-off',
|
color: '#f56c6c',
|
bg: 'linear-gradient(135deg, #f56c6c, #f78989)',
|
},
|
{
|
label: '跨市窜货',
|
value: 'crossCity',
|
icon: 'lucide:map-pin',
|
color: '#7c3aed',
|
bg: 'linear-gradient(135deg, #7c3aed, #9461f5)',
|
},
|
];
|
|
/** 加载汇总 */
|
async function loadSummary() {
|
summaryLoading.value = true;
|
try {
|
summary.value = await getTraceCrossRegionSummary();
|
} finally {
|
summaryLoading.value = false;
|
}
|
}
|
|
/** 加载判定粒度配置 */
|
async function loadConfig() {
|
const config = await getTraceCrossRegionConfig();
|
warningLevel.value = config.warningLevel || 'PROVINCE';
|
}
|
|
/** 切换判定粒度 */
|
async function handleLevelChange(value: string | number) {
|
try {
|
const level = String(value);
|
await updateTraceCrossRegionConfig(level);
|
message.success(
|
`判定粒度已切换为${
|
WARNING_LEVEL_OPTIONS.find((opt) => opt.value === level)?.label
|
}`,
|
);
|
} catch {
|
loadConfig();
|
}
|
}
|
|
/** 打开处理弹窗 */
|
function openHandle(row: MesTraceCrossRegionApi.Warning) {
|
handleForm.value = { id: row.id, status: 20, handleRemark: '' };
|
handleVisible.value = true;
|
}
|
|
/** 提交处理 */
|
async function submitHandle() {
|
if (!handleForm.value.id || handleLoading.value) return;
|
handleLoading.value = true;
|
try {
|
await handleTraceCrossRegion({
|
id: handleForm.value.id,
|
status: handleForm.value.status,
|
handleRemark: handleForm.value.handleRemark,
|
});
|
message.success('预警已处理');
|
handleVisible.value = false;
|
handleRefresh();
|
} catch {
|
message.error('处理失败,请重试');
|
} finally {
|
handleLoading.value = false;
|
}
|
}
|
|
/** 刷新列表与汇总 */
|
function handleRefresh() {
|
gridApi.query();
|
loadSummary();
|
}
|
|
/** 展示地区组合 */
|
function regionText(province?: string, city?: string) {
|
return [province, city].filter(Boolean).join('·') || '-';
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getTraceCrossRegionPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<MesTraceCrossRegionApi.Warning>,
|
});
|
|
onMounted(() => {
|
loadSummary();
|
loadConfig();
|
initEntranceAnimation();
|
});
|
|
/** 入场动画:尊重 prefers-reduced-motion */
|
async function initEntranceAnimation() {
|
await nextTick();
|
animationContext = gsap.context(() => {
|
const reduceMotion = window.matchMedia(
|
'(prefers-reduced-motion: reduce)',
|
).matches;
|
gsap.from('.mes-cr-summary, .mes-cr-grid', {
|
autoAlpha: reduceMotion ? 1 : 0,
|
y: reduceMotion ? 0 : 14,
|
duration: reduceMotion ? 0 : 0.45,
|
stagger: reduceMotion ? 0 : 0.08,
|
ease: 'power2.out',
|
});
|
});
|
}
|
|
onUnmounted(() => {
|
animationContext?.revert();
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<Card class="mes-cr-summary mb-4">
|
<template #title>
|
<div class="flex items-center justify-between">
|
<span>窜货预警</span>
|
<span class="flex items-center gap-2 text-sm">
|
<span class="text-muted-foreground">判定粒度</span>
|
<Segmented
|
v-model:value="warningLevel"
|
:disabled="!canHandle"
|
:options="WARNING_LEVEL_OPTIONS"
|
@change="handleLevelChange"
|
/>
|
</span>
|
</div>
|
</template>
|
<Row :gutter="16">
|
<Col
|
v-for="card in summaryCards"
|
:key="card.value"
|
:lg="4"
|
:md="8"
|
:sm="12"
|
:xs="24"
|
class="mb-4"
|
>
|
<Card class="kpi-card">
|
<div class="flex items-center gap-4">
|
<div
|
class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
|
:style="{ background: card.bg }"
|
>
|
<IconifyIcon class="size-7" :icon="card.icon" />
|
</div>
|
<div>
|
<div class="text-muted-foreground mb-1 text-sm">
|
{{ card.label }}
|
</div>
|
<Skeleton.Input
|
v-if="summaryLoading"
|
:size="'small'"
|
active
|
style="width: 4rem"
|
/>
|
<CountTo
|
v-else
|
class="text-2xl font-bold leading-tight"
|
:style="{ color: card.color }"
|
:end-val="summary[card.value] || 0"
|
:duration="1200"
|
/>
|
</div>
|
</div>
|
</Card>
|
</Col>
|
</Row>
|
</Card>
|
|
<Grid class="mes-cr-grid" table-title="窜货预警列表">
|
<template #bagCode="{ row }">
|
<Tag v-if="row.bagCode" color="blue">{{ row.bagCode }}</Tag>
|
<Tag v-else-if="row.palletCode" color="purple">
|
{{ row.palletCode }}
|
</Tag>
|
<span v-else>-</span>
|
</template>
|
<template #dealerRegion="{ row }">
|
{{ regionText(row.dealerProvince, row.dealerCity) }}
|
</template>
|
<template #scanRegion="{ row }">
|
<span class="text-[#dc2626] font-medium">
|
{{ regionText(row.scanProvince, row.scanCity) }}
|
</span>
|
</template>
|
<template #warningType="{ row }">
|
<Tag
|
:color="row.warningType === 'CROSS_PROVINCE' ? 'red' : 'orange'"
|
>
|
{{ row.warningTypeName }}
|
</Tag>
|
</template>
|
<template #status="{ row }">
|
<Tag
|
:color="
|
row.status === 10
|
? 'orange'
|
: row.status === 20
|
? 'green'
|
: 'default'
|
"
|
>
|
{{ row.statusName }}
|
</Tag>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '处理',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['mes:trace-cross-region:handle'],
|
ifShow: row.status === 10,
|
onClick: openHandle.bind(null, row),
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
|
<Modal
|
v-model:open="handleVisible"
|
title="处理窜货预警"
|
:confirm-loading="handleLoading"
|
ok-text="确认处理"
|
cancel-text="取消"
|
@ok="submitHandle"
|
>
|
<a-form layout="vertical">
|
<a-form-item label="处理结果">
|
<a-radio-group v-model:value="handleForm.status">
|
<a-radio :value="20">已处理</a-radio>
|
<a-radio :value="30">误报</a-radio>
|
</a-radio-group>
|
</a-form-item>
|
<a-form-item label="处理备注">
|
<a-textarea
|
v-model:value="handleForm.handleRemark"
|
:rows="3"
|
placeholder="请输入处理备注(如:确认为物流中转)"
|
/>
|
</a-form-item>
|
</a-form>
|
</Modal>
|
</Page>
|
</template>
|