Переглянути джерело

封装公共方法 减少代码

wy 1 рік тому
батько
коміт
281303ff90

+ 2 - 1
src/main.js

@@ -13,9 +13,10 @@ import './icons' // icon
 import './permission' // permission control
 import * as filters from './filters' // global filters
 import moment from "moment"
+import {minix} from '@/utils/minix'
 //表格宽度自适应
 import AFTableColumn from 'af-table-column'
-
+Vue.mixin(minix)
 Vue.use(Element, {
   size: Cookies.get('size') || 'medium', // set element-ui default size
 })

+ 26 - 0
src/utils/minix.js

@@ -0,0 +1,26 @@
+export const minix = {
+  methods: {
+    /* 设置初始视窗高度*/
+    onLoadHeight() {
+      this.$nextTick(() => {
+        let actual = this.getFontSize();
+        this.tableheight = document.body.clientHeight - actual;
+      });
+    },
+    /* 设置窗口变化高度*/
+    changeWindow() {
+      window.onresize = () => {
+        return (() => {
+          let actual = this.getFontSize();
+          this.tableheight = document.body.clientHeight - actual;
+        })();
+      };
+    },
+    //得到根标签的值
+    getFontSize() {
+      let num = getComputedStyle(window.document.documentElement)["font-size"]; //得到html中fontSize的值
+      let size = num.substring(0, num.length - 2); //去除px
+      return (350 / 80) * size;
+    },
+  },
+};

+ 1 - 37
src/views/manage-log/battery-charger.vue

@@ -208,19 +208,6 @@ export default {
       },
     };
   },
-  watch: {
-    tableheight(val) {
-      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
-      if (!this.heightTimer) {
-        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
-        this.screenHeight = val;
-        this.heightTimer = true;
-        setTimeout(function () {
-          this.heightTimer = false;
-        }, 400);
-      }
-    },
-  },
   mounted() {
     this.getChargeCode();
     this.onLoadHeight();
@@ -240,30 +227,7 @@ export default {
         column.label,
       ]);
     },
-    /* 设置初始视窗高度*/
-    onLoadHeight() {
-      this.$nextTick(() => {
-        let actual = this.getFontSize()
-        this.tableheight = document.body.clientHeight - actual;
-      });
-    },
-    /* 设置窗口变化高度*/
-    changeWindow() {
-      window.onresize = () => {
-        return (() => {
-          let actual = this.getFontSize()
-          this.tableheight = document.body.clientHeight - actual;
-        })();
-      };
-    },
-      //得到根标签的值
-      getFontSize(){
-      let num = getComputedStyle(window.document.documentElement)[
-            "font-size"
-          ]; //得到html中fontSize的值
-          let size = num.substring(0, num.length - 2); //去除px
-         return (350 / 80) * size;
-    },
+   
     // 获取充电机ID
     getChargeCode() {
       getChargeCode().then((res) => {

+ 2 - 37
src/views/manage-log/bms.vue

@@ -198,20 +198,8 @@ export default {
       },
     };
   },
-  watch: {
-    tableheight(val) {
-      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
-      if (!this.heightTimer) {
-        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
-        this.screenHeight = val;
-        this.heightTimer = true;
-        setTimeout(function () {
-          this.heightTimer = false;
-        }, 400);
-      }
-    },
-  },
   mounted() {
+    console.log(this,'this')
     this.onLoadHeight();
     this.changeWindow();
     this.getLogModel();
@@ -231,30 +219,7 @@ export default {
         column.label,
       ]);
     },
-    /* 设置初始视窗高度*/
-    onLoadHeight() {
-      this.$nextTick(() => {
-        let actual = this.getFontSize()
-        this.tableheight = document.body.clientHeight - actual;
-      });
-    },
-    /* 设置窗口变化高度*/
-    changeWindow() {
-      window.onresize = () => {
-        return (() => {
-          let actual = this.getFontSize()
-          this.tableheight = document.body.clientHeight - actual;
-        })();
-      };
-    },
-      //得到根标签的值
-      getFontSize(){
-      let num = getComputedStyle(window.document.documentElement)[
-            "font-size"
-          ]; //得到html中fontSize的值
-          let size = num.substring(0, num.length - 2); //去除px
-         return (350 / 80) * size;
-    },
+   
     selectAll() {
       if (this.robotValue.length < this.logOptions.length) {
         this.robotValue = [];

+ 0 - 13
src/views/manage-log/data-export.vue

@@ -191,19 +191,6 @@ export default {
       exportTimer: null, //定时器
     };
   },
-  watch: {
-    tableheight(val) {
-      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
-      if (!this.heightTimer) {
-        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
-        this.screenHeight = val;
-        this.heightTimer = true;
-        setTimeout(function () {
-          this.heightTimer = false;
-        }, 400);
-      }
-    },
-  },
   destroyed() {
     this.clearListTimer();
   },

+ 1 - 37
src/views/manage-log/robot.vue

@@ -183,19 +183,6 @@ export default {
       },
     };
   },
-  watch: {
-    tableheight(val) {
-      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
-      if (!this.heightTimer) {
-        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
-        this.screenHeight = val;
-        this.heightTimer = true;
-        setTimeout(function () {
-          this.heightTimer = false;
-        }, 400);
-      }
-    },
-  },
   mounted() {
     this.getrobotList();
     this.getLogModel();
@@ -215,30 +202,7 @@ export default {
         column.label,
       ]);
     },
-    /* 设置初始视窗高度*/
-    onLoadHeight() {
-      this.$nextTick(() => {
-        let actual = this.getFontSize()
-        this.tableheight = document.body.clientHeight - actual;
-      });
-    },
-    /* 设置窗口变化高度*/
-    changeWindow() {
-      window.onresize = () => {
-        return (() => {
-          let actual = this.getFontSize()
-          this.tableheight = document.body.clientHeight - actual;
-        })();
-      };
-    },
-    //得到根标签的值
-    getFontSize(){
-      let num = getComputedStyle(window.document.documentElement)[
-            "font-size"
-          ]; //得到html中fontSize的值
-          let size = num.substring(0, num.length - 2); //去除px
-         return (350 / 80) * size;
-    },
+  
     selectAll() {
       if (this.robotValue.length < this.logOptions.length) {
         this.robotValue = [];