Browse Source

实时视图-定时刷新修改

zhongxiaoyu 2 years ago
parent
commit
03d8350fcf

+ 5 - 2
src/hooks/useLoop.ts

@@ -1,14 +1,14 @@
 import { WatchSource } from 'vue'
 
 export function useLoop(
-  loopFunc: () => void | Promise<void>,
+  loopFunctions: (() => void | Promise<void>)[],
   interval: number | string,
   watchSources: (WatchSource | object)[] = []
 ) {
   let queryLoop: number | null = null
   const startQuery = async () => {
     queryLoop = 1 // 先赋值,表示已经在进行查询
-    await loopFunc()
+    await Promise.all(loopFunctions.map(func => func()))
     queryLoop = window.setTimeout(
       startQuery,
       typeof interval === 'string'
@@ -38,4 +38,7 @@ export function useLoop(
   onDeactivated(() => {
     stopQuery()
   })
+  onBeforeUnmount(() => {
+    stopQuery()
+  })
 }

+ 1 - 1
src/router/index.ts

@@ -84,7 +84,7 @@ router.beforeEach((to, from, next) => {
     delCachedViewUntil,
   } = useKeepAlive()
   if (from.matched?.[0]?.name === 'RealTime') {
-    if (to.matched[0].name !== from.matched[0].name) {
+    if (to.matched[1].name !== from.matched[1].name) {
       delCachedViewAll()
     } else if (to.matched.length < from.matched.length) {
       delCachedViewUntil(to.name as string)

+ 1 - 10
src/views/realTime/components/AirportView/index.vue

@@ -114,15 +114,6 @@ const props = defineProps({
   },
 })
 
-// onMounted(() => {
-//   console.log('mounted', 'airport')
-// })
-// onActivated(() => {
-//   console.log('activated', 'airport')
-// })
-// onDeactivated(() => {
-//   console.log('deactivated', 'airport')
-// })
 
 const isDeparture = props.name.includes('Departure')
 
@@ -140,7 +131,7 @@ const { tableColumns, tableData, getTableData } = useAirportTable(
   props.name,
   formData
 )
-useLoop(getTableData, 'airport', [formData])
+useLoop([getTableData], 'airport', [formData])
 const { columnChecked } = useTableColumnSet(tableColumns)
 const { rowClassV2, cellClassV2 } = useTableStyle(props.name)
 const cellPropsGetter = params => ({

+ 2 - 3
src/views/realTime/components/FlightView/index.vue

@@ -123,7 +123,6 @@ const {
   computedFlightInfo,
   getFlightInfo,
 } = useFlightInfo(props.name, dataContent)
-useLoop(getFlightInfo, 'flight')
 
 const airLine = toRef(flightInfo, 'flightinfo')
 
@@ -132,7 +131,6 @@ const {
   tableData: containerTableData,
   getTableData: getContainerTableData,
 } = useTable(`${props.name}Container`, dataContent)
-useLoop(getContainerTableData, 'flight')
 const waybillTableFormatter = (row, column, cellValue, index) => {
   if (column.property.includes('Time') && typeof cellValue === 'string') {
     return cellValue.replace('T', '\n')
@@ -145,7 +143,8 @@ const {
   tableData: waybillTableData,
   getTableData: getWaybillTableData,
 } = useTable(`${props.name}Waybill`, dataContent)
-useLoop(getWaybillTableData, 'flight')
+
+useLoop([getFlightInfo, getContainerTableData, getWaybillTableData], 'flight')
 
 const UTCFlag = ref(true)
 

+ 2 - 2
src/views/realTime/components/WaybillView/index.vue

@@ -128,14 +128,14 @@ const {
   computedWaybillInfo,
   getWaybillInfo,
 } = useWaybillInfo(props.name, [waybillNO as string])
-useLoop(getWaybillInfo, 'waybill')
 
 const {
   tableColumns,
   tableData: trackData,
   getTableData,
 } = useTable(`${props.name}Goods`, [waybillNO as string])
-useLoop(getTableData, 'waybill')
+
+useLoop([getWaybillInfo, getTableData], 'waybill')
 
 const { trackAirlines, trackBoxStyle } = useTrackData(props.name, trackData)
 

+ 3 - 0
src/views/realTime/hooks/useTable.ts

@@ -881,6 +881,9 @@ export function useTable(tableName: string, dataContent?: CommonValue[]) {
     }))
   }
   const getTableData = async () => {
+    if (!idGetter(tableName)) {
+      return
+    }
     try {
       const {
         code,