Vue大數據可視化(大屏展示)解決方案


DataV:組件庫基於Vue (React版) ,主要用於構建大屏(全屏)數據展示頁面即數據可視化

官網地址: http://datav.jiaminghi.com/guide/#%E7%94%A8%E5%89%8D%E5%BF%85%E7%9C%8B

 

https://blog.csdn.net/qq_40282732/article/details/105656848

https://gitee.com/MTrun/big-screen-vue-datav

 

 屏幕適配 mixin 函數
 1 // 屏幕適配 mixin 函數
 2 
 3 // * 默認縮放值
 4 const scale = {
 5   width: '1',
 6   height: '1',
 7 }
 8 
 9 // * 設計稿尺寸(px)
10 const baseWidth = 1920
11 const baseHeight = 1080
12 
13 // * 需保持的比例(默認1.77778)
14 const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
15 
16 export default {
17   data() {
18     return {
19       // * 定時函數
20       drawTiming: null
21     }
22   },
23   mounted () {
24     this.calcRate()
25     window.addEventListener('resize', this.resize)
26   },
27   unMounted () {
28     window.removeEventListener('resize', this.resize)
29   },
30   methods: {
31     calcRate () {
32       const appRef = this.$refs["appRef"]
33       console.log(appRef)
34       if (!appRef) return 
35       // 當前寬高比
36       const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
37       if (appRef) {
38         if (currentRate > baseProportion) {
39           // 表示更寬
40           scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
41           scale.height = (window.innerHeight / baseHeight).toFixed(5)
42           appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
43         } else {
44           // 表示更高
45           scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5)
46           scale.width = (window.innerWidth / baseWidth).toFixed(5)
47           appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
48         }
49       }
50     },
51     resize () {
52       clearTimeout(this.drawTiming)
53       this.drawTiming = setTimeout(() => {
54         this.calcRate()
55       }, 200)
56     }
57   },
58 }

使用:

大屏防抖:

 1 // 混入代碼 resize-mixins.js
 2 import { debounce } from '@/utils';
 3 const resizeChartMethod = '$__resizeChartMethod';
 4 
 5 export default {
 6   data() {
 7     // 在組件內部將圖表 init 的引用映射到 chart 屬性上
 8     return {
 9       chart: null,
10     };
11   },
12   created() {
13     window.addEventListener('resize', this[resizeChartMethod], false);
14   },
15   activated() {
16     // 防止 keep-alive 之后圖表變形
17     if (this.chart) {
18       this.chart.resize()
19     }
20   },
21   beforeDestroy() {
22     window.removeEventListener('reisze', this[resizeChartMethod]);
23   },
24   methods: {
25     // 防抖函數來控制 resize 的頻率
26     [resizeChartMethod]: debounce(function() {
27       if (this.chart) {
28         this.chart.resize();
29       }
30     }, 300),
31   },
32 };

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM