Browse Source

代码优化

lilei 3 years ago
parent
commit
ca36303da6

+ 3 - 3
src/components/MultiTab/MultiTab.vue

@@ -152,7 +152,7 @@ export default {
   watch: {
   watch: {
     '$route': function (newVal, oldVal) {
     '$route': function (newVal, oldVal) {
       if (newVal.name == oldVal.name) { return }
       if (newVal.name == oldVal.name) { return }
-      console.log(newVal, oldVal, this.pages)
+      // console.log(newVal, oldVal, this.pages)
       // 解决页面地址相同参数不同时打开多个页签问题(例 详情页id或sn不同时)
       // 解决页面地址相同参数不同时打开多个页签问题(例 详情页id或sn不同时)
       const index = this.tabsList.indexOf(newVal.name)
       const index = this.tabsList.indexOf(newVal.name)
 
 
@@ -181,7 +181,7 @@ export default {
       const oxt = oldMenu.meta.replaceTab
       const oxt = oldMenu.meta.replaceTab
 
 
       if (index < 0) { // 不存在
       if (index < 0) { // 不存在
-        console.log(1, hasChildren, '不存在')
+        // console.log(1, hasChildren, '不存在')
         if ((na || nb || nc || nxt || oa || ob || oc || oxt) && hasChildren) {
         if ((na || nb || nc || nxt || oa || ob || oc || oxt) && hasChildren) {
           // 替换当前页签
           // 替换当前页签
           this.replaceTab(newVal, oldMenu)
           this.replaceTab(newVal, oldMenu)
@@ -211,7 +211,7 @@ export default {
           }
           }
         }
         }
       } else { // 已存在
       } else { // 已存在
-        console.log(1, nxt, '已存在')
+        // console.log(1, nxt, '已存在')
         this.pages.splice(index, 1, newVal)
         this.pages.splice(index, 1, newVal)
         this.tabsList.splice(index, 1, newVal.name)
         this.tabsList.splice(index, 1, newVal.name)
         this.$store.state.app.isNewTab = !!nxt
         this.$store.state.app.isNewTab = !!nxt

+ 5 - 7
src/layouts/PageView.vue

@@ -55,7 +55,7 @@
 <script>
 <script>
 import { mapState } from 'vuex'
 import { mapState } from 'vuex'
 import PageHeader from '@/components/PageHeader'
 import PageHeader from '@/components/PageHeader'
-
+import { on, off } from '@/libs/tools'
 export default {
 export default {
   name: 'PageView',
   name: 'PageView',
   components: {
   components: {
@@ -102,12 +102,10 @@ export default {
     this.tabs = this.directTabs
     this.tabs = this.directTabs
     this.getPageMeta()
     this.getPageMeta()
     this.setpageH()
     this.setpageH()
-    const _this = this
-    window.onresize = () => {
-      return (() => {
-        _this.setpageH()
-      })()
-    }
+    on(window, 'resize', this.setpageH)
+  },
+  beforeDestroy () {
+    off(window, 'resize', this.setpageH)
   },
   },
   activated () {
   activated () {
     this.setpageH()
     this.setpageH()

+ 11 - 5
src/views/reportData/chainStockExpenditureReport/list.vue

@@ -74,6 +74,7 @@ import rangeDate from '@/views/common/rangeDate.vue'
 import echarts from 'echarts'
 import echarts from 'echarts'
 import { linkageGroupList } from '@/api/reportData'
 import { linkageGroupList } from '@/api/reportData'
 import { reportStockOutList } from '@/api/reportStock'
 import { reportStockOutList } from '@/api/reportStock'
+import { on, off } from '@/libs/tools'
 export default {
 export default {
   components: { rangeDate },
   components: { rangeDate },
   data () {
   data () {
@@ -306,13 +307,11 @@ export default {
         }
         }
       })
       })
     },
     },
+    chartResize () {
+      this.chart1.resize()
+    },
     pageInit () {
     pageInit () {
       this.getLinkageGroup()
       this.getLinkageGroup()
-      window.onresize = () => {
-        return (() => {
-          this.chart1.resize()
-        })()
-      }
     }
     }
   },
   },
   mounted () {
   mounted () {
@@ -322,12 +321,19 @@ export default {
     }
     }
   },
   },
   activated () {
   activated () {
+    on(window, 'resize', this.chartResize)
     // 如果是新页签打开,则重置当前页面
     // 如果是新页签打开,则重置当前页面
     if (this.$store.state.app.isNewTab) {
     if (this.$store.state.app.isNewTab) {
       this.pageInit()
       this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
+  deactivated () {
+    off(window, 'resize', this.chartResize)
+  },
+  beforeDestroy () {
+    off(window, 'resize', this.chartResize)
+  },
   beforeRouteEnter (to, from, next) {
   beforeRouteEnter (to, from, next) {
     next(vm => {})
     next(vm => {})
   }
   }

+ 11 - 5
src/views/reportData/chainStockIncomeReport/list.vue

@@ -74,6 +74,7 @@ import rangeDate from '@/views/common/rangeDate.vue'
 import echarts from 'echarts'
 import echarts from 'echarts'
 import { reportStockPutList } from '@/api/reportStock'
 import { reportStockPutList } from '@/api/reportStock'
 import { linkageGroupList } from '@/api/reportData'
 import { linkageGroupList } from '@/api/reportData'
+import { on, off } from '@/libs/tools'
 export default {
 export default {
   components: { rangeDate },
   components: { rangeDate },
   data () {
   data () {
@@ -306,13 +307,11 @@ export default {
         }
         }
       })
       })
     },
     },
+    chartResize () {
+      this.chart1.resize()
+    },
     pageInit () {
     pageInit () {
       this.getLinkageGroup()
       this.getLinkageGroup()
-      window.onresize = () => {
-        return (() => {
-          this.chart1.resize()
-        })()
-      }
     }
     }
   },
   },
   mounted () {
   mounted () {
@@ -322,12 +321,19 @@ export default {
     }
     }
   },
   },
   activated () {
   activated () {
+    on(window, 'resize', this.chartResize)
     // 如果是新页签打开,则重置当前页面
     // 如果是新页签打开,则重置当前页面
     if (this.$store.state.app.isNewTab) {
     if (this.$store.state.app.isNewTab) {
       this.pageInit()
       this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
+  deactivated () {
+    off(window, 'resize', this.chartResize)
+  },
+  beforeDestroy () {
+    off(window, 'resize', this.chartResize)
+  },
   beforeRouteEnter (to, from, next) {
   beforeRouteEnter (to, from, next) {
     next(vm => {})
     next(vm => {})
   }
   }

+ 10 - 8
src/views/reportData/stockExpenditureReport/list.vue

@@ -59,6 +59,7 @@
 import rangeDate from '@/views/common/rangeDate.vue'
 import rangeDate from '@/views/common/rangeDate.vue'
 import echarts from 'echarts'
 import echarts from 'echarts'
 import { reportStockOutList } from '@/api/reportStock'
 import { reportStockOutList } from '@/api/reportStock'
+import { on, off } from '@/libs/tools'
 export default {
 export default {
   components: { rangeDate },
   components: { rangeDate },
   data () {
   data () {
@@ -266,27 +267,28 @@ export default {
       this.totalData = null
       this.totalData = null
       this.chartInit()
       this.chartInit()
     },
     },
-    pageInit () {
-      window.onresize = () => {
-        return (() => {
-          this.chart1.resize()
-        })()
-      }
+    chartResize () {
+      this.chart1.resize()
     }
     }
   },
   },
   mounted () {
   mounted () {
     if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
     if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
-      this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
   activated () {
   activated () {
+    on(window, 'resize', this.chartResize)
     // 如果是新页签打开,则重置当前页面
     // 如果是新页签打开,则重置当前页面
     if (this.$store.state.app.isNewTab) {
     if (this.$store.state.app.isNewTab) {
-      this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
+  deactivated () {
+    off(window, 'resize', this.chartResize)
+  },
+  beforeDestroy () {
+    off(window, 'resize', this.chartResize)
+  },
   beforeRouteEnter (to, from, next) {
   beforeRouteEnter (to, from, next) {
     next(vm => {})
     next(vm => {})
   }
   }

+ 10 - 8
src/views/reportData/stockIncomeReport/list.vue

@@ -59,6 +59,7 @@
 import rangeDate from '@/views/common/rangeDate.vue'
 import rangeDate from '@/views/common/rangeDate.vue'
 import echarts from 'echarts'
 import echarts from 'echarts'
 import { reportStockPutList } from '@/api/reportStock'
 import { reportStockPutList } from '@/api/reportStock'
+import { on, off } from '@/libs/tools'
 export default {
 export default {
   components: { rangeDate },
   components: { rangeDate },
   data () {
   data () {
@@ -266,27 +267,28 @@ export default {
       this.totalData = null
       this.totalData = null
       this.chartInit()
       this.chartInit()
     },
     },
-    pageInit () {
-      window.onresize = () => {
-        return (() => {
-          this.chart1.resize()
-        })()
-      }
+    chartResize () {
+      this.chart1.resize()
     }
     }
   },
   },
   mounted () {
   mounted () {
     if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
     if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
-      this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
   activated () {
   activated () {
+    on(window, 'resize', this.chartResize)
     // 如果是新页签打开,则重置当前页面
     // 如果是新页签打开,则重置当前页面
     if (this.$store.state.app.isNewTab) {
     if (this.$store.state.app.isNewTab) {
-      this.pageInit()
       this.resetSearchForm()
       this.resetSearchForm()
     }
     }
   },
   },
+  deactivated () {
+    off(window, 'resize', this.chartResize)
+  },
+  beforeDestroy () {
+    off(window, 'resize', this.chartResize)
+  },
   beforeRouteEnter (to, from, next) {
   beforeRouteEnter (to, from, next) {
     next(vm => {})
     next(vm => {})
   }
   }