From 27c8277d717b34b55f3ea967027b53b067f77df3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 20 八月 2026 16:58:49 +0800
Subject: [PATCH] feat 功能变更
---
src/views/mes/dv/telemetry/index.vue | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 168 insertions(+), 0 deletions(-)
diff --git a/src/views/mes/dv/telemetry/index.vue b/src/views/mes/dv/telemetry/index.vue
new file mode 100644
index 0000000..27b8ef1
--- /dev/null
+++ b/src/views/mes/dv/telemetry/index.vue
@@ -0,0 +1,168 @@
+<script lang="ts" setup>
+ import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+ import type { MesDvTelemetryApi } from '#/api/mes/dv/telemetry';
+
+ import { onBeforeUnmount, onMounted, ref, useTemplateRef } from 'vue';
+
+ import { Page } from '@vben/common-ui';
+ import { useVbenVxeGrid } from '#/adapter/vxe-table';
+
+ import { Button, message, Switch, Tabs, Tag } from 'ant-design-vue';
+ import dayjs from 'dayjs';
+
+ import {
+ getLatestTelemetry,
+ getTelemetryPage,
+ pullTelemetry,
+ } from '#/api/mes/dv/telemetry';
+
+ import { useHistoryColumns, useHistoryGridFormSchema, useLatestColumns } from './data';
+
+ const activeTab = ref<'latest' | 'history'>('latest');
+ const autoRefresh = ref(false);
+ const pulling = ref(false);
+ const lastUpdateTime = ref<Date>();
+ let refreshTimer: ReturnType<typeof setInterval> | undefined;
+
+ const contentRef = useTemplateRef('contentRef');
+ let resizeObserver: ResizeObserver | undefined;
+
+ /** 璁$畻琛ㄦ牸楂樺害锛氬唴瀹瑰尯鍙敤楂樺害 - 宸ュ叿鏍忚/Tabs瀵艰埅绛夊浐瀹氬紑閿�锛屼繚璇佽〃鏍兼拺婊¢〉闈紙瀵归綈璁惧鍙拌处椤碉級 */
+ function calcTableHeight() {
+ const el = contentRef.value;
+ if (!el) return;
+ const height = Math.max(el.clientHeight - 115, 240);
+ latestGridApi.setGridOptions({ height });
+ historyGridApi.setGridOptions({ height });
+ }
+
+ onMounted(() => {
+ calcTableHeight();
+ resizeObserver = new ResizeObserver(calcTableHeight);
+ if (contentRef.value) resizeObserver.observe(contentRef.value);
+ });
+
+ const [LatestGrid, latestGridApi] = useVbenVxeGrid({
+ gridOptions: {
+ columns: useLatestColumns(),
+ height: 400,
+ keepSource: true,
+ // /latest 杩斿洖瑁告暟缁勶紝闇�鍏抽棴鍒嗛〉锛屽惁鍒� vxe 浼氭寜 {list,total} 瑙f瀽瀵艰嚧涓嶅睍绀�
+ pagerConfig: { enabled: false },
+ proxyConfig: {
+ ajax: {
+ query: async () => await getLatestTelemetry(),
+ },
+ },
+ rowConfig: { keyField: 'id', isHover: true },
+ toolbarConfig: { refresh: true },
+ } as VxeTableGridOptions<MesDvTelemetryApi.Telemetry>,
+ });
+
+ const [HistoryGrid, historyGridApi] = useVbenVxeGrid({
+ formOptions: { schema: useHistoryGridFormSchema() },
+ gridOptions: {
+ columns: useHistoryColumns(),
+ height: 400,
+ keepSource: true,
+ proxyConfig: {
+ ajax: {
+ query: async ({ page }, formValues) =>
+ await getTelemetryPage({
+ pageNo: page.currentPage,
+ pageSize: page.pageSize,
+ ...formValues,
+ }),
+ },
+ },
+ rowConfig: { keyField: 'id', isHover: true },
+ toolbarConfig: { refresh: true, search: true },
+ } as VxeTableGridOptions<MesDvTelemetryApi.Telemetry>,
+ });
+
+ /** 鎷夊彇鏈�鏂版暟閲囨暟鎹苟鍒锋柊褰撳墠 Tab */
+ async function handlePull() {
+ pulling.value = true;
+ try {
+ const result = await pullTelemetry();
+ lastUpdateTime.value = result.pullTime;
+ message.success(
+ `鎷夊彇鎴愬姛锛屾柊澧� ${result.recordCount} 鏉★紝娑夊強璁惧 ${result.deviceCount} 鍙癭,
+ );
+ refreshActive();
+ } finally {
+ pulling.value = false;
+ }
+ }
+
+ /** 鍒锋柊褰撳墠 Tab 鏁版嵁 */
+ function refreshActive() {
+ if (activeTab.value === 'latest') {
+ latestGridApi.query();
+ } else {
+ historyGridApi.query();
+ }
+ }
+
+ /** 鍒囨崲瀹炴椂鑷姩鍒锋柊锛堟瘡 30 绉掞級 */
+ function toggleAutoRefresh(checked: boolean | string | number) {
+ if (checked) {
+ refreshTimer = setInterval(() => {
+ if (activeTab.value === 'latest') {
+ latestGridApi.query();
+ }
+ }, 30_000);
+ } else if (refreshTimer) {
+ clearInterval(refreshTimer);
+ refreshTimer = undefined;
+ }
+ }
+
+ onBeforeUnmount(() => {
+ resizeObserver?.disconnect();
+ if (refreshTimer) {
+ clearInterval(refreshTimer);
+ }
+ });
+</script>
+
+<template>
+ <Page auto-content-height>
+ <div ref="contentRef" class="flex h-full w-full flex-col">
+ <div class="mb-4 flex items-center gap-4">
+ <Button type="primary" :loading="pulling" @click="handlePull">
+ 鎷夊彇鏈�鏂版暟鎹�
+ </Button>
+ <Switch
+ v-model:checked="autoRefresh"
+ checked-children="瀹炴椂鑷姩鍒锋柊"
+ un-checked-children="瀹炴椂鑷姩鍒锋柊"
+ @change="toggleAutoRefresh"
+ />
+ <span v-if="lastUpdateTime" class="text-sm text-gray-500">
+ 鏈�杩戞媺鍙栵細{{ dayjs(lastUpdateTime).format('YYYY-MM-DD HH:mm:ss') }}
+ </span>
+ </div>
+ <Tabs v-model:active-key="activeTab" class="min-h-0 flex-1">
+ <Tabs.TabPane key="latest" tab="瀹炴椂鏁版嵁">
+ <LatestGrid table-title="瀹炴椂鏁版嵁">
+ <template #anomaly="{ row }">
+ <Tag :color="row.whetherAnomaly ? 'red' : 'green'">
+ {{ row.whetherAnomaly ? '寮傚父' : '姝e父' }}
+ </Tag>
+ </template>
+ </LatestGrid>
+ </Tabs.TabPane>
+ <Tabs.TabPane key="history" tab="鍘嗗彶璁板綍">
+ <HistoryGrid table-title="鍘嗗彶璁板綍">
+ <template #anomaly="{ row }">
+ <Tag :color="row.whetherAnomaly ? 'red' : 'green'">
+ {{ row.whetherAnomaly ? '寮傚父' : '姝e父' }}
+ </Tag>
+ </template>
+ </HistoryGrid>
+ </Tabs.TabPane>
+ </Tabs>
+ </div>
+ </Page>
+</template>
--
Gitblit v1.9.3