Quellcode durchsuchen

航段组合函数修改

zhongxiaoyu vor 2 Jahren
Ursprung
Commit
e9211272f4
2 geänderte Dateien mit 30 neuen und 29 gelöschten Zeilen
  1. 28 0
      src/utils/index.js
  2. 2 29
      src/views/newFlightView/index.vue

+ 28 - 0
src/utils/index.js

@@ -115,3 +115,31 @@ export function param2Obj(url) {
   })
   return obj
 }
+
+export function combine(array, startKey, endKey, result = []) {
+  function swap(startIndex, endIndex, arr) {
+    if (startIndex > endIndex) {
+      const temp = arr[startIndex]
+      arr[startIndex] = arr[endIndex]
+      arr[endIndex] = temp
+    }
+  }
+
+  array.forEach(path => {
+    const { [startKey]: start, [endKey]: end } = path
+    const startIndex = result.findIndex(item => item === start)
+    const endIndex = result.findIndex(item => item === end)
+    if (startIndex > -1) {
+      if (endIndex > -1) {
+        swap(startIndex, endIndex, result)
+      } else {
+        result.splice(startIndex + 1, 0, end)
+      }
+    } else if (endIndex > -1) {
+      result.splice(endIndex, 0, start)
+    } else {
+      result.push(start, end)
+    }
+  })
+  return result
+}

+ 2 - 29
src/views/newFlightView/index.vue

@@ -73,6 +73,7 @@
 import Table from '@/views/newQuery/components/table.vue'
 import TimeZoneSelector from "@/components/TimeZoneSelector"
 import { throttledExportToExcel } from "@/utils/table"
+import { combine } from '@/utils'
 import pf from '@/layout/mixin/publicFunc'
 import Item from './item.vue'
 export default {
@@ -121,7 +122,7 @@ export default {
     }
     const newDatas = _.cloneDeep(this.deArrs)
     if (newDatas && newDatas.length) {
-      const m = this.combine3(newDatas, 'depStation_iataCd', 'arrStation_iataCd')
+      const m = combine(newDatas, 'depStation_iataCd', 'arrStation_iataCd')
       m.forEach((item, index) => {
         const obj = {
           item,
@@ -135,36 +136,8 @@ export default {
   mounted () {
     this.table1 = this.dataContent
     this.table2 = this.showObj
-
   },
   methods: {
-    combine3 (array, startKey, endKey) {
-      const caculatedArray = []
-      const weightMap = {}
-      const set = new Set()
-      array.forEach(item => {
-        const caculated = caculatedArray.some(
-          caculatedItem =>
-            item[startKey] === caculatedItem[startKey] &&
-            item[endKey] === caculatedItem[endKey]
-        )
-        if (!caculated) {
-          caculatedArray.push(item)
-          set.add(item[startKey])
-          set.add(item[endKey])
-          if (!weightMap[item[startKey]]) {
-            weightMap[item[startKey]] = 0
-          }
-          if (weightMap[item[endKey]]) {
-            weightMap[item[endKey]] += 1
-          } else {
-            weightMap[item[endKey]] = 1
-          }
-        }
-      })
-      const result = [...set]
-      return result.sort((a, b) => weightMap[a] - weightMap[b])
-    },
     // 获取基本信息
     async getViewInfo (dataContent = this.dataContent) {
       const { code, returnData } = await this.getQueryList(SERVICE_ID.bagViewId, dataContent)