Commit 203c834f1dabd542d09c4746d79c561145c2047a

Authored by qianbao
1 parent e08dd4d5

主数据源刷新,子数据源跟着定时刷新(text、文本)

src/store/modules/dataSource.js
... ... @@ -2,13 +2,17 @@ const dataSource = {
2 2 namespaced: true,
3 3 state: {
4 4 staticData: {},
5   - dynamicData: {}
  5 + dynamicData: {},
  6 + staticRefreshTime: 6000000
6 7 },
7 8  
8 9 mutations: {
9 10 SET_STATIC_DATA: (state, data) => {
10 11 state.staticData = data;
11 12 },
  13 + SET_REFRESHTIME: (state, data) => {
  14 + state.staticRefreshTime = data;
  15 + },
12 16 SET_DYNAMIC_DATA: (state, data) => {
13 17 state.dynamicData = data;
14 18 }
... ...
src/views/bigscreenDesigner/designer/widget/text/widgetDigitalFlop.vue
... ... @@ -44,11 +44,15 @@ export default {
44 44 optionsStyle: {}, // 样式
45 45 optionsData: {}, // 数据
46 46 optionsCollapse: {}, // 图标属性
47   - optionsSetup: {}
  47 + optionsSetup: {},
  48 + flagInter: null,
48 49 };
49 50 },
  51 + beforeDestroy() {
  52 + clearInterval(this.flagInter);
  53 + },
50 54 computed: {
51   - ...mapState('dataSource', ['staticData']),
  55 + ...mapState('dataSource', ['staticData','staticRefreshTime']),
52 56 styleObj() {
53 57 /*数字初始化*/
54 58 const {slectedDataType,numberText} = this.optionsSetup;
... ... @@ -100,20 +104,28 @@ export default {
100 104 methods: {
101 105 // 修改图标options属性
102 106 editorOptions() {
103   - //显示内容
104   - this.showText();
105   -
106 107 //数据修改
107 108 this.setOptionsData();
108 109  
109 110 //字体样式修改
110 111 this.setFontStyle();
  112 +
  113 + //显示内容
  114 + this.showText();
111 115 },
112 116  
113 117 //显示的内容
114 118 showText() {
115 119 const {slectedDataType,numberText} = this.optionsSetup;
116 120 let datav = this.staticData[slectedDataType] || numberText;
  121 + if(this.isNotBlank(slectedDataType)){
  122 + const refreshTime = this.staticRefreshTime || 300000;
  123 + this.dynamicDataFn(refreshTime);
  124 + }else{
  125 + this.setShowText(datav);
  126 + }
  127 + },
  128 + setShowText(datav) {
117 129 let dataArray = datav.toString().split(",");
118 130 const numArray=[];
119 131 if(this.isNotBlankArray(dataArray)){
... ... @@ -122,6 +134,7 @@ export default {
122 134 });
123 135 }
124 136 this.options.number = numArray;
  137 + this.options={...this.options};
125 138 },
126 139 //字体修改
127 140 setFontStyle() {
... ... @@ -134,7 +147,6 @@ export default {
134 147 fontStyle.fontFamily=this.optionsSetup.fontFamily;
135 148 this.options.textAlign =optionsSetup.textAlign;
136 149 this.options.style = fontStyle;
137   - this.options={...this.options};
138 150 },
139 151 //千为分隔符
140 152 formatterNum (number) {
... ... @@ -158,8 +170,23 @@ export default {
158 170 this.options.toFixed=optionsSetup.toFixed;
159 171 this.options.textAlign= this.options.style.textAlign;
160 172 this.options.animationFrame=optionsSetup.animationFrame;
161   - // this.options={...this.options};
162 173 },
  174 + //定时动态数据获取
  175 + dynamicDataFn(refreshTime) {
  176 + if (this.ispreview) {
  177 + this.flagInter = setInterval(() => {
  178 + this.getEchartData();
  179 + }, refreshTime);
  180 + } else {
  181 + this.getEchartData();
  182 + }
  183 + },
  184 + getEchartData() {
  185 + const {slectedDataType,numberText} = this.optionsSetup;
  186 + const datav = this.staticData[slectedDataType] || numberText;
  187 + // console.log("翻牌数值",datav)
  188 + this.setShowText(datav);
  189 + }
163 190 }
164 191 };
165 192  
... ...
src/views/bigscreenDesigner/designer/widget/text/widgetText.vue
1 1 <template>
2   - <div class="text" :style="styleColor">{{ showText }}</div>
  2 + <div class="text" :style="styleColor" v-if="isRouterAlive" v-html="showText" ></div>
3 3 </template>
4 4  
5 5 <script>
... ... @@ -11,16 +11,31 @@ export default {
11 11 value: Object,
12 12 ispreview: Boolean
13 13 },
  14 + provide(){
  15 + return{
  16 + reload:this.reload
  17 + }
  18 + },
14 19 data() {
15 20 return {
16 21 options: {},
17   - optionsData: {}
  22 + optionsData: {},
  23 + flagInter: null,
  24 + isRouterAlive:true,
  25 + showText:''
18 26 };
19 27 },
  28 + beforeDestroy() {
  29 + clearInterval(this.flagInter);
  30 + },
20 31 computed: {
21   - ...mapState('dataSource', ['staticData']),
  32 + ...mapState('dataSource', ['staticData','staticRefreshTime']),
22 33 transStyle() {
23   - return this.objToOne(this.options);
  34 + const obj = this.objToOne(this.options);
  35 + const {text, slectedDataType} = obj;
  36 + const val = this.staticData[slectedDataType] || text;
  37 + this.showText = val;
  38 + return obj;
24 39 },
25 40 styleColor() {
26 41 return {
... ... @@ -39,10 +54,6 @@ export default {
39 54 right: this.transStyle.right + "px"
40 55 };
41 56 },
42   - showText() {
43   - const {text, slectedDataType} = this.transStyle;
44   - return this.staticData[slectedDataType] || text;
45   - }
46 57 },
47 58 watch: {
48 59 value: {
... ... @@ -50,6 +61,7 @@ export default {
50 61 this.options = val;
51 62 this.optionsData = val.data;
52 63 this.setOptionsData();
  64 + this.setShowText();
53 65 },
54 66 deep: true
55 67 },
... ... @@ -62,28 +74,39 @@ export default {
62 74 methods: {
63 75 // 数据解析
64 76 setOptionsData() {
65   - const optionsData = this.optionsData; // 数据类型 静态 or 动态
66   - if (optionsData.dataType == "dynamicData") {
67   - this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
68   - };
  77 + const {slectedDataType} = this.transStyle;
  78 + if(this.isNotBlank(slectedDataType)){
  79 + const refreshTime = this.staticRefreshTime || 300000;
  80 + this.dynamicDataFn(refreshTime);
  81 + }
  82 + },
  83 + setShowTextRolad(){
  84 + this.setShowText();
  85 + this.reload();
  86 + },
  87 + setShowText() {
  88 + const {text, slectedDataType} = this.transStyle;
  89 + const val = this.staticData[slectedDataType] || text;
  90 + this.showText = val;
  91 + },
  92 + // vue hack 之强制刷新组件
  93 + reload(){
  94 + this.isRouterAlive=false;
  95 + this.$nextTick(function(){
  96 + this.isRouterAlive=true;
  97 + })
69 98 },
70   - dynamicDataFn(val, refreshTime) {
71   - if (!val) return;
  99 + dynamicDataFn(refreshTime) {
72 100 if (this.ispreview) {
73   - this.getEchartData(val);
74 101 this.flagInter = setInterval(() => {
75   - this.getEchartData(val);
  102 + this.getEchartData();
76 103 }, refreshTime);
77 104 } else {
78   - this.getEchartData(val);
  105 + this.getEchartData();
79 106 }
80 107 },
81   - getEchartData(val) {
82   - const data = this.queryEchartsData(val);
83   - data.then(res => {
84   - this.styleColor.text = res[0].value;
85   - this.$forceUpdate();
86   - });
  108 + getEchartData() {
  109 + this.setShowTextRolad();
87 110 }
88 111 }
89 112 };
... ...
src/views/bigscreenDesigner/viewer/index.vue
... ... @@ -34,7 +34,7 @@ export default {
34 34 this.getData();
35 35 },
36 36 methods: {
37   - ...mapMutations('dataSource', ['SET_STATIC_DATA']),
  37 + ...mapMutations('dataSource', ['SET_STATIC_DATA','SET_REFRESHTIME']),
38 38 async getData() {
39 39 const reportCode = this.$route.query.reportCode;
40 40 const { code, data } = await detailDashboard(reportCode);
... ... @@ -65,6 +65,7 @@ export default {
65 65 // 数据类型 静态 or 动态
66 66 const screenD = screenData.data;
67 67 const refreshTime = screenD["refreshTime"]||60000*30;
  68 + this.SET_REFRESHTIME(refreshTime);
68 69 screenD.dataType == "staticData"
69 70 ? this.staticDataFn(screenD.staticData)
70 71 : this.dynamicDataFn(screenD.dynamicData, refreshTime);
... ... @@ -100,6 +101,7 @@ export default {
100 101 }
101 102 }
102 103 }
  104 + // console.log("著数据源。。。。",this.masterData)
103 105 this.SET_STATIC_DATA(this.masterData);
104 106 },
105 107 },
... ...