Commit 203c834f1dabd542d09c4746d79c561145c2047a
1 parent
e08dd4d5
主数据源刷新,子数据源跟着定时刷新(text、文本)
Showing
4 changed files
with
88 additions
and
32 deletions
src/store/modules/dataSource.js
| @@ -2,13 +2,17 @@ const dataSource = { | @@ -2,13 +2,17 @@ const dataSource = { | ||
| 2 | namespaced: true, | 2 | namespaced: true, |
| 3 | state: { | 3 | state: { |
| 4 | staticData: {}, | 4 | staticData: {}, |
| 5 | - dynamicData: {} | 5 | + dynamicData: {}, |
| 6 | + staticRefreshTime: 6000000 | ||
| 6 | }, | 7 | }, |
| 7 | 8 | ||
| 8 | mutations: { | 9 | mutations: { |
| 9 | SET_STATIC_DATA: (state, data) => { | 10 | SET_STATIC_DATA: (state, data) => { |
| 10 | state.staticData = data; | 11 | state.staticData = data; |
| 11 | }, | 12 | }, |
| 13 | + SET_REFRESHTIME: (state, data) => { | ||
| 14 | + state.staticRefreshTime = data; | ||
| 15 | + }, | ||
| 12 | SET_DYNAMIC_DATA: (state, data) => { | 16 | SET_DYNAMIC_DATA: (state, data) => { |
| 13 | state.dynamicData = data; | 17 | state.dynamicData = data; |
| 14 | } | 18 | } |
src/views/bigscreenDesigner/designer/widget/text/widgetDigitalFlop.vue
| @@ -44,11 +44,15 @@ export default { | @@ -44,11 +44,15 @@ export default { | ||
| 44 | optionsStyle: {}, // 样式 | 44 | optionsStyle: {}, // 样式 |
| 45 | optionsData: {}, // 数据 | 45 | optionsData: {}, // 数据 |
| 46 | optionsCollapse: {}, // 图标属性 | 46 | optionsCollapse: {}, // 图标属性 |
| 47 | - optionsSetup: {} | 47 | + optionsSetup: {}, |
| 48 | + flagInter: null, | ||
| 48 | }; | 49 | }; |
| 49 | }, | 50 | }, |
| 51 | + beforeDestroy() { | ||
| 52 | + clearInterval(this.flagInter); | ||
| 53 | + }, | ||
| 50 | computed: { | 54 | computed: { |
| 51 | - ...mapState('dataSource', ['staticData']), | 55 | + ...mapState('dataSource', ['staticData','staticRefreshTime']), |
| 52 | styleObj() { | 56 | styleObj() { |
| 53 | /*数字初始化*/ | 57 | /*数字初始化*/ |
| 54 | const {slectedDataType,numberText} = this.optionsSetup; | 58 | const {slectedDataType,numberText} = this.optionsSetup; |
| @@ -100,20 +104,28 @@ export default { | @@ -100,20 +104,28 @@ export default { | ||
| 100 | methods: { | 104 | methods: { |
| 101 | // 修改图标options属性 | 105 | // 修改图标options属性 |
| 102 | editorOptions() { | 106 | editorOptions() { |
| 103 | - //显示内容 | ||
| 104 | - this.showText(); | ||
| 105 | - | ||
| 106 | //数据修改 | 107 | //数据修改 |
| 107 | this.setOptionsData(); | 108 | this.setOptionsData(); |
| 108 | 109 | ||
| 109 | //字体样式修改 | 110 | //字体样式修改 |
| 110 | this.setFontStyle(); | 111 | this.setFontStyle(); |
| 112 | + | ||
| 113 | + //显示内容 | ||
| 114 | + this.showText(); | ||
| 111 | }, | 115 | }, |
| 112 | 116 | ||
| 113 | //显示的内容 | 117 | //显示的内容 |
| 114 | showText() { | 118 | showText() { |
| 115 | const {slectedDataType,numberText} = this.optionsSetup; | 119 | const {slectedDataType,numberText} = this.optionsSetup; |
| 116 | let datav = this.staticData[slectedDataType] || numberText; | 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 | let dataArray = datav.toString().split(","); | 129 | let dataArray = datav.toString().split(","); |
| 118 | const numArray=[]; | 130 | const numArray=[]; |
| 119 | if(this.isNotBlankArray(dataArray)){ | 131 | if(this.isNotBlankArray(dataArray)){ |
| @@ -122,6 +134,7 @@ export default { | @@ -122,6 +134,7 @@ export default { | ||
| 122 | }); | 134 | }); |
| 123 | } | 135 | } |
| 124 | this.options.number = numArray; | 136 | this.options.number = numArray; |
| 137 | + this.options={...this.options}; | ||
| 125 | }, | 138 | }, |
| 126 | //字体修改 | 139 | //字体修改 |
| 127 | setFontStyle() { | 140 | setFontStyle() { |
| @@ -134,7 +147,6 @@ export default { | @@ -134,7 +147,6 @@ export default { | ||
| 134 | fontStyle.fontFamily=this.optionsSetup.fontFamily; | 147 | fontStyle.fontFamily=this.optionsSetup.fontFamily; |
| 135 | this.options.textAlign =optionsSetup.textAlign; | 148 | this.options.textAlign =optionsSetup.textAlign; |
| 136 | this.options.style = fontStyle; | 149 | this.options.style = fontStyle; |
| 137 | - this.options={...this.options}; | ||
| 138 | }, | 150 | }, |
| 139 | //千为分隔符 | 151 | //千为分隔符 |
| 140 | formatterNum (number) { | 152 | formatterNum (number) { |
| @@ -158,8 +170,23 @@ export default { | @@ -158,8 +170,23 @@ export default { | ||
| 158 | this.options.toFixed=optionsSetup.toFixed; | 170 | this.options.toFixed=optionsSetup.toFixed; |
| 159 | this.options.textAlign= this.options.style.textAlign; | 171 | this.options.textAlign= this.options.style.textAlign; |
| 160 | this.options.animationFrame=optionsSetup.animationFrame; | 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 | <template> | 1 | <template> |
| 2 | - <div class="text" :style="styleColor">{{ showText }}</div> | 2 | + <div class="text" :style="styleColor" v-if="isRouterAlive" v-html="showText" ></div> |
| 3 | </template> | 3 | </template> |
| 4 | 4 | ||
| 5 | <script> | 5 | <script> |
| @@ -11,16 +11,31 @@ export default { | @@ -11,16 +11,31 @@ export default { | ||
| 11 | value: Object, | 11 | value: Object, |
| 12 | ispreview: Boolean | 12 | ispreview: Boolean |
| 13 | }, | 13 | }, |
| 14 | + provide(){ | ||
| 15 | + return{ | ||
| 16 | + reload:this.reload | ||
| 17 | + } | ||
| 18 | + }, | ||
| 14 | data() { | 19 | data() { |
| 15 | return { | 20 | return { |
| 16 | options: {}, | 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 | computed: { | 31 | computed: { |
| 21 | - ...mapState('dataSource', ['staticData']), | 32 | + ...mapState('dataSource', ['staticData','staticRefreshTime']), |
| 22 | transStyle() { | 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 | styleColor() { | 40 | styleColor() { |
| 26 | return { | 41 | return { |
| @@ -39,10 +54,6 @@ export default { | @@ -39,10 +54,6 @@ export default { | ||
| 39 | right: this.transStyle.right + "px" | 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 | watch: { | 58 | watch: { |
| 48 | value: { | 59 | value: { |
| @@ -50,6 +61,7 @@ export default { | @@ -50,6 +61,7 @@ export default { | ||
| 50 | this.options = val; | 61 | this.options = val; |
| 51 | this.optionsData = val.data; | 62 | this.optionsData = val.data; |
| 52 | this.setOptionsData(); | 63 | this.setOptionsData(); |
| 64 | + this.setShowText(); | ||
| 53 | }, | 65 | }, |
| 54 | deep: true | 66 | deep: true |
| 55 | }, | 67 | }, |
| @@ -62,28 +74,39 @@ export default { | @@ -62,28 +74,39 @@ export default { | ||
| 62 | methods: { | 74 | methods: { |
| 63 | // 数据解析 | 75 | // 数据解析 |
| 64 | setOptionsData() { | 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 | if (this.ispreview) { | 100 | if (this.ispreview) { |
| 73 | - this.getEchartData(val); | ||
| 74 | this.flagInter = setInterval(() => { | 101 | this.flagInter = setInterval(() => { |
| 75 | - this.getEchartData(val); | 102 | + this.getEchartData(); |
| 76 | }, refreshTime); | 103 | }, refreshTime); |
| 77 | } else { | 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,7 +34,7 @@ export default { | ||
| 34 | this.getData(); | 34 | this.getData(); |
| 35 | }, | 35 | }, |
| 36 | methods: { | 36 | methods: { |
| 37 | - ...mapMutations('dataSource', ['SET_STATIC_DATA']), | 37 | + ...mapMutations('dataSource', ['SET_STATIC_DATA','SET_REFRESHTIME']), |
| 38 | async getData() { | 38 | async getData() { |
| 39 | const reportCode = this.$route.query.reportCode; | 39 | const reportCode = this.$route.query.reportCode; |
| 40 | const { code, data } = await detailDashboard(reportCode); | 40 | const { code, data } = await detailDashboard(reportCode); |
| @@ -65,6 +65,7 @@ export default { | @@ -65,6 +65,7 @@ export default { | ||
| 65 | // 数据类型 静态 or 动态 | 65 | // 数据类型 静态 or 动态 |
| 66 | const screenD = screenData.data; | 66 | const screenD = screenData.data; |
| 67 | const refreshTime = screenD["refreshTime"]||60000*30; | 67 | const refreshTime = screenD["refreshTime"]||60000*30; |
| 68 | + this.SET_REFRESHTIME(refreshTime); | ||
| 68 | screenD.dataType == "staticData" | 69 | screenD.dataType == "staticData" |
| 69 | ? this.staticDataFn(screenD.staticData) | 70 | ? this.staticDataFn(screenD.staticData) |
| 70 | : this.dynamicDataFn(screenD.dynamicData, refreshTime); | 71 | : this.dynamicDataFn(screenD.dynamicData, refreshTime); |
| @@ -100,6 +101,7 @@ export default { | @@ -100,6 +101,7 @@ export default { | ||
| 100 | } | 101 | } |
| 101 | } | 102 | } |
| 102 | } | 103 | } |
| 104 | + // console.log("著数据源。。。。",this.masterData) | ||
| 103 | this.SET_STATIC_DATA(this.masterData); | 105 | this.SET_STATIC_DATA(this.masterData); |
| 104 | }, | 106 | }, |
| 105 | }, | 107 | }, |