diff --git a/README.md b/README.md index 45d127a..d83742d 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,9 @@ export default { }, methods: { async fetchList(){ - const { code,listData }= await this.$http.get("xx/xx/xx"x); + const { code, listData } = await this.$http.get("xx/xx/xx"); if(code === 200){ - this.ListDataSelf= listData; + this.ListDataSelf = listData; } } } diff --git a/src/components/echart/bottom/bottomLeftChart.vue b/src/components/echart/bottom/bottomLeftChart.vue index d8f4199..790c7a9 100644 --- a/src/components/echart/bottom/bottomLeftChart.vue +++ b/src/components/echart/bottom/bottomLeftChart.vue @@ -258,9 +258,6 @@ export default { }; this.chart.setOption(option); } - }, - destroyed() { - window.onresize = null; } }; diff --git a/src/components/echart/bottom/bottomRightChart.vue b/src/components/echart/bottom/bottomRightChart.vue index 4330c56..4edc269 100644 --- a/src/components/echart/bottom/bottomRightChart.vue +++ b/src/components/echart/bottom/bottomRightChart.vue @@ -393,12 +393,8 @@ export default { } ] }; - this.chart.setOption(option); } - }, - destroyed() { - window.onresize = null; } }; diff --git a/src/components/echart/center/centerChartRate.vue b/src/components/echart/center/centerChartRate.vue index be0021c..7f664d0 100644 --- a/src/components/echart/center/centerChartRate.vue +++ b/src/components/echart/center/centerChartRate.vue @@ -94,9 +94,6 @@ export default { }; this.chart.setOption(option); } - }, - destroyed() { - window.onresize = null; } }; diff --git a/src/components/echart/centerLeft2/centreLeft1Chart.vue b/src/components/echart/centerLeft/centreLeft1Chart.vue similarity index 100% rename from src/components/echart/centerLeft2/centreLeft1Chart.vue rename to src/components/echart/centerLeft/centreLeft1Chart.vue diff --git a/src/components/echart/centerLeft2/centreLeft2Chart.vue b/src/components/echart/centerLeft/centreLeft2Chart.vue similarity index 98% rename from src/components/echart/centerLeft2/centreLeft2Chart.vue rename to src/components/echart/centerLeft/centreLeft2Chart.vue index 8903a16..fd58ed8 100644 --- a/src/components/echart/centerLeft2/centreLeft2Chart.vue +++ b/src/components/echart/centerLeft/centreLeft2Chart.vue @@ -192,9 +192,6 @@ export default { }; this.chart.setOption(option); } - }, - destroyed() { - window.onresize = null; } }; diff --git a/src/components/echart/centerRight2/centerRight2Chart.vue b/src/components/echart/centerRight/centerRight2Chart.vue similarity index 98% rename from src/components/echart/centerRight2/centerRight2Chart.vue rename to src/components/echart/centerRight/centerRight2Chart.vue index 2c89f28..796f791 100644 --- a/src/components/echart/centerRight2/centerRight2Chart.vue +++ b/src/components/echart/centerRight/centerRight2Chart.vue @@ -153,9 +153,6 @@ export default { }; this.chart.setOption(option); } - }, - destroyed() { - window.onresize = null; } }; diff --git a/src/utils/index.js b/src/utils/index.js index 3d5a51a..14e554d 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,35 +1,16 @@ -export function debounce(func, wait, immediate) { - let timeout, args, context, timestamp, result; - - const later = function() { - // 据上一次触发时间间隔 - const last = +new Date() - timestamp; - - // 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait - if (last < wait && last > 0) { - timeout = setTimeout(later, wait - last); - } else { - timeout = null; - // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用 - if (!immediate) { - result = func.apply(context, args); - if (!timeout) context = args = null; - } - } - }; - - return function(...args) { - context = this; - timestamp = +new Date(); - const callNow = immediate && !timeout; - // 如果延时不存在,重新设定延时 - if (!timeout) timeout = setTimeout(later, wait); - if (callNow) { - result = func.apply(context, args); - context = args = null; - } - - return result; +/** + * @param {Function} fn 函数 + * @param {Number} delay 延迟时间 + */ +export function debounce(fn, delay) { + var timer; + return function () { + var context = this; + var args = arguments; + clearTimeout(timer); + timer = setTimeout(function () { + fn.apply(context, args); + }, delay); }; } @@ -38,9 +19,9 @@ export function debounce(func, wait, immediate) { * @param {String} fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss */ export function formatTime(time, fmt) { - if (!time) return '' + if (!time) return ''; else { - const date = new Date(time) + const date = new Date(time); const o = { 'M+': date.getMonth() + 1, 'd+': date.getDate(), @@ -48,15 +29,23 @@ export function formatTime(time, fmt) { 'm+': date.getMinutes(), 's+': date.getSeconds(), 'q+': Math.floor((date.getMonth() + 3) / 3), - 'S': date.getMilliseconds() - } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) + S: date.getMilliseconds(), + }; + if (/(y+)/.test(fmt)) + fmt = fmt.replace( + RegExp.$1, + (date.getFullYear() + '').substr(4 - RegExp.$1.length) + ); for (const k in o) { if (new RegExp('(' + k + ')').test(fmt)) { - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (( - '00' + o[k]).substr(('' + o[k]).length))) + fmt = fmt.replace( + RegExp.$1, + RegExp.$1.length === 1 + ? o[k] + : ('00' + o[k]).substr(('' + o[k]).length) + ); } } - return fmt + return fmt; } } diff --git a/src/utils/resizeMixins.js b/src/utils/resizeMixins.js index 8caae20..bd52c45 100644 --- a/src/utils/resizeMixins.js +++ b/src/utils/resizeMixins.js @@ -1,5 +1,5 @@ // 混入代码 resize-mixins.js -import { debounce } from '@/utils/index'; +import { debounce } from '@/utils'; const resizeChartMethod = '$__resizeChartMethod'; export default { diff --git a/src/views/centerLeft1.vue b/src/views/centerLeft1.vue index bc4e3b0..46ed4c6 100644 --- a/src/views/centerLeft1.vue +++ b/src/views/centerLeft1.vue @@ -31,7 +31,7 @@