Browse Source

提取公共函数flattenKeys

shaun-sheep 5 years ago
parent
commit
60ff140af4

+ 20 - 0
src/utils/scan/tools.js

@@ -553,7 +553,27 @@ tools.setDataForKey = function (data, key, value) {
     }
   }
 }
+tools.flattenKeys = function (obj) {
+  let res = {}
 
+  function isObject(val) {
+    return typeof val === 'object' && !Array.isArray(val)
+  }
+
+  function digKeys(prev, obj) {
+    Object.entries(obj).forEach(([key, value]) => {
+      const currentKey = prev ? `${prev}.${key}` : key
+      if (isObject(value)) {
+        digKeys(currentKey, value)
+      } else {
+        res[currentKey] = value
+      }
+    })
+  }
+
+  digKeys('', obj)
+  return res
+}
 function dateToDate(date) {
   var sDate = new Date();
   if (typeof date == 'object' && typeof new Date().getMonth == "function") {

+ 2 - 20
src/views/ledger/cenotelist/cenoteDetail/index.vue

@@ -55,26 +55,8 @@
   import systemTable from '@/components/ledger/cenote/table/systemTable'
   import exhibitionBaseInformation from "@/components/ledger/details/detail/exhibitionBaseInformation";
   import selectRadio from "@/components/ledger/details/detail/selectRadio";
-  function flattenKeys(obj) {
-    let res = {}
+  import tools from "@/utils/scan/tools"
 
-    function isObject(val) {
-      return typeof val === 'object' && !Array.isArray(val)
-    }
-
-    function digKeys(prev, obj) {
-      Object.entries(obj).forEach(([key, value]) => {
-        const currentKey = prev ? `${prev}.${key}` : key
-        if (isObject(value)) {
-          digKeys(currentKey, value)
-        } else {
-          res[currentKey] = value
-        }
-      })
-    }
-    digKeys('', obj)
-    return res
-  }
   export default {
     data() {
       return {
@@ -163,7 +145,7 @@
         this.pointData = values[0].Content;
         this.exampleData = values[1].Content[0];
         let obj = this.deepCopy(values[1].Content[0]);
-        obj = flattenKeys(obj);
+        obj = tools.flattenKeys(obj);
         this.instance = obj;
         this.handleRadios(1)
       })

+ 1 - 21
src/views/ledger/facility/details/index.vue

@@ -73,26 +73,6 @@
   import {BeatchQueryParam, getDataDictionary, queryEquip} from "@/api/scan/request";
   import {mapGetters} from "vuex";
 
-  function flattenKeys(obj) {
-    let res = {}
-
-    function isObject(val) {
-      return typeof val === 'object' && !Array.isArray(val)
-    }
-
-    function digKeys(prev, obj) {
-      Object.entries(obj).forEach(([key, value]) => {
-        const currentKey = prev ? `${prev}.${key}` : key
-        if (isObject(value)) {
-          digKeys(currentKey, value)
-        } else {
-          res[currentKey] = value
-        }
-      })
-    }
-    digKeys('', obj)
-    return res
-  }
   export default {
     name: "deviceDetails",
     components: {
@@ -212,7 +192,7 @@
           this.name = this.exampleData.EquipLocalName?this.exampleData.EquipLocalName:this.exampleData.EquipName?this.exampleData.EquipName:'';
           this.code = this.exampleData.EquipLocalID?this.exampleData.EquipLocalID:'';
           let obj = this.deepCopy(values[1].Content[0]);
-          obj = flattenKeys(obj);
+          obj = tools.flattenKeys(obj);
           this.instance = obj;
           this.handleRadios(1)
           this.pointData.forEach(item => {

+ 2 - 20
src/views/ledger/property/details/index.vue

@@ -61,27 +61,9 @@
 
   import {getDataDictionary, queryProperty} from "@/api/scan/request";
   import {mapGetters} from "vuex";
+  import tools from "@/utils/scan/tools"
 
-  function flattenKeys(obj) {
-    let res = {}
 
-    function isObject(val) {
-      return typeof val === 'object' && !Array.isArray(val)
-    }
-
-    function digKeys(prev, obj) {
-      Object.entries(obj).forEach(([key, value]) => {
-        const currentKey = prev ? `${prev}.${key}` : key
-        if (isObject(value)) {
-          digKeys(currentKey, value)
-        } else {
-          res[currentKey] = value
-        }
-      })
-    }
-    digKeys('', obj)
-    return res
-  }
   export default {
     name: "propertyDetails",
     components: {
@@ -190,7 +172,7 @@
           this.name = this.exampleData.EquipLocalName?this.exampleData.EquipLocalName:this.exampleData.EquipName?this.exampleData.EquipName:'';
           this.code = this.exampleData.EquipLocalID?this.exampleData.EquipLocalID:'';
           let obj = this.deepCopy(values[1].Content[0]);
-          obj = flattenKeys(obj);
+          obj = tools.flattenKeys(obj);
           this.instance = obj;
           this.handleRadios(1)
         })

+ 1 - 21
src/views/ledger/spacelist/spaceDetail/index.vue

@@ -84,27 +84,7 @@
   import exhibitionMaintain from "@/components/ledger/details/detail/exhibitionMaintain";
   import selectRadio from "@/components/ledger/details/detail/selectRadio";
 
-  function flattenKeys(obj) {
-    let res = {}
 
-    function isObject(val) {
-      return typeof val === 'object' && !Array.isArray(val)
-    }
-
-    function digKeys(prev, obj) {
-      Object.entries(obj).forEach(([key, value]) => {
-        const currentKey = prev ? `${prev}.${key}` : key
-        if (isObject(value)) {
-          digKeys(currentKey, value)
-        } else {
-          res[currentKey] = value
-        }
-      })
-    }
-
-    digKeys('', obj)
-    return res
-  }
 
   export default {
     data() {
@@ -234,7 +214,7 @@
         this.pointData = values[0].Content;
         this.exampleData = values[1].Content[0];
         let obj = this.deepCopy(values[1].Content[0]);
-        obj = flattenKeys(obj);
+        obj = tools.flattenKeys(obj);
         this.instance = obj;
         this.handleRadios(1)
         this.pointData.forEach(item => {

+ 2 - 22
src/views/ledger/system/systemDetail/index.vue

@@ -79,28 +79,8 @@
   import selectRadio from "@/components/ledger/details/detail/selectRadio";
   import exhibitionMaintain from "@/components/ledger/details/detail/exhibitionMaintain";
   import exhibitionVideo from "@/components/ledger/details/detail/exhibitionVideo";
+  import tools from "@/utils/scan/tools"
 
-  function flattenKeys(obj) {
-    let res = {}
-
-    function isObject(val) {
-      return typeof val === 'object' && !Array.isArray(val)
-    }
-
-    function digKeys(prev, obj) {
-      Object.entries(obj).forEach(([key, value]) => {
-        const currentKey = prev ? `${prev}.${key}` : key
-        if (isObject(value)) {
-          digKeys(currentKey, value)
-        } else {
-          res[currentKey] = value
-        }
-      })
-    }
-
-    digKeys('', obj)
-    return res
-  }
 
   export default {
     data() {
@@ -255,7 +235,7 @@
         this.pointData = values[0].Content;
         this.exampleData = values[1].Content[0];
         let obj = this.deepCopy(values[1].Content[0]);
-        obj = flattenKeys(obj);
+        obj = tools.flattenKeys(obj);
         this.instance = obj;
         this.handleRadios(1)
       })