widgetActiveRingChart.vue
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!--
动态环图
-->
<template>
<div v-if="isRouterAlive" style="position: relative;">
<div class="bcci-header" :style="titleConfig.titleStyle" v-if="titleConfig.isNoTitle" >{{titleConfig.titleText}}</div>
<div class="bc-chart-item" :style="styleObj">
<Label-Tag :config="labelConfig" v-if="labelConfig.isNoTipTitle && labelConfig.tipsAlign=='top'"/>
<dv-active-ring-chart :config="options" :style="styleRingChart"/>
<Label-Tag :config="labelConfig" v-if="labelConfig.isNoTipTitle
&& (labelConfig.tipsAlign=='down' || labelConfig.tipsAlign=='right' || labelConfig.tipsAlign=='left')"/>
</div>
</div>
</template>
<script>
import Vue from "vue";
import LabelTag from '../../components/LabelTag'
import activeRingChart from "@jiaminghi/data-view/lib/components/activeRingChart";
Vue.use(activeRingChart)
export default {
name: "widgetActiveRingChart",
props: {
value: Object,
ispreview: Boolean,
},
components: {
LabelTag
},
data() {
return {
options: {
radius:'75%',//环半径
activeRadius:'85%',//环半径(动态)
data:[],//环数据
lineWidth:40,//环数据
activeTimeGap:3000,//切换间隔(ms)
color:[],//环颜色
digitalFlopStyle: {
fontSize: 30,
fill: '#3de7c9'
},//数字翻牌器样式
digitalFlopToFixed :0,//数字翻牌器小数位数
digitalFlopUnit :'',//数字翻牌器单位
animationFrame :50,//动效帧数
showOriginValue :false//显示原始值
},
optionsStyle: {}, // 样式
optionsData: {}, // 数据
optionsCollapse: {}, // 图标属性
optionsSetup: {},
labelConfig: {
data: [],
colors:[],
labelStyle:{},
isNoTipTitle:false,
tipsAlign:'down',
labelTagStyle:{}
},
titleConfig:{
titleStyle:{},
isNoTitle:false,
titleText:"测试标题"
},
flagInter: null,
isRouterAlive:true,
}
},
provide(){
return{
reload:this.reload
}
},
beforeDestroy() {
clearInterval(this.flagInter);
},
computed: {
styleObj() {
const style ={
position: this.ispreview ? "absolute" : "static",
width: this.optionsStyle.width + "px",
height: this.optionsStyle.height + "px",
left: this.optionsStyle.left + "px",
top: this.optionsStyle.top + "px",
background: this.optionsSetup.background
};
return style;
},
styleRingChart() {
const style ={
width: this.optionsStyle.width + "px",
height: this.optionsStyle.height+ "px",
left: this.optionsStyle.left + "px",
top: this.optionsStyle.top - 20 + "px",
position: "static",
display: 'flex'
};
return style;
}
},
watch: {
value: {
handler(val) {
this.optionsStyle = val.position;
this.optionsData = val.data;
this.optionsSetup = val.setup;
this.editorOptions();
this.reload();
},
deep: true
}
},
created() {
this.optionsStyle = this.value.position;
this.optionsData = this.value.data;
this.optionsSetup = this.value.setup;
this.editorOptions();
},
methods: {
// 修改图标options属性
editorOptions() {
//数据修改
this.setOptionsData();
//环颜色修改
this.setOptionsColor();
//数字翻牌器样式
this.setFontStyle();
//设置提示语
this.setLabelConfig();
//标题设置
this.setTitleConfig();
//基础数据修改
this.setOptionsConfig();
},
//提示语设置
setLabelConfig(){
const optionsSetup = this.optionsSetup;
let labelStyle = {};
let labelTagStyleOne = {};
if(optionsSetup.isNoTipTitle){
this.labelConfig.isNoTipTitle = optionsSetup.isNoTipTitle;
this.labelConfig.tipsAlign = optionsSetup.tipsAlign;
labelStyle.color = optionsSetup.tipsColor;
labelStyle['font-size'] = optionsSetup.tipFontSize+'px';
if(optionsSetup.tipsAlign=='right' || optionsSetup.tipsAlign=='left'){
labelTagStyleOne[optionsSetup.tipsAlign]=optionsSetup.tipFontLeft+"%";
labelTagStyleOne['height']=optionsSetup.tipFontHeight+"%";
labelTagStyleOne['width']="20%";
labelTagStyleOne['top']="0";
labelTagStyleOne['bottom']="0";
}else if(optionsSetup.tipsAlign=='top'){
labelTagStyleOne['left']= optionsSetup.tipFontLeft+"%";
labelTagStyleOne['top']= -optionsSetup.tipFontTop+"%";
}else{
labelTagStyleOne['left']= optionsSetup.tipFontLeft+"%";
labelTagStyleOne['bottom']= optionsSetup.tipFontTop+"%";
}
this.labelConfig.labelTagStyle = labelTagStyleOne;
this.labelConfig.labelStyle = labelStyle;
}else{
this.labelConfig.isNoTipTitle = false;
}
},
//标题设置
setTitleConfig(){
const optionsSetup = this.optionsSetup;
let titleStyle = {};
if(optionsSetup.isNoTitle){
this.titleConfig.isNoTitle = optionsSetup.isNoTitle;
this.titleConfig.titleText = optionsSetup.titleText;
titleStyle.color = optionsSetup.textColor;
titleStyle['font-size'] = optionsSetup.textFontSize+'px';
titleStyle['font-style'] = optionsSetup.textFontStyle;
titleStyle['font-weight'] = optionsSetup.textFontWeight;
titleStyle['text-align'] = optionsSetup.textAlign;
if (this.$router.history.current.path === "/bigscreen/viewer") {
titleStyle['position'] = 'absolute';
titleStyle['top'] = this.optionsStyle.top + "px";
titleStyle['left'] = this.optionsStyle.left + "px";
titleStyle['width'] = this.optionsStyle.width + "px";
}
this.titleConfig.titleStyle = titleStyle;
}else{
this.titleConfig.isNoTitle = false;
}
},
// 颜色修改
setOptionsColor() {
const optionsSetup = this.optionsSetup;
const customColor = optionsSetup.customColor;
if (!customColor) return;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
this.options.color = arrColor;
this.labelConfig.colors = arrColor;
},
//字体修改
setFontStyle() {
const optionsSetup = this.optionsSetup;
const fontStyle = {};
fontStyle.fill=optionsSetup.fill;
fontStyle.fontSize=optionsSetup.fontSize;
fontStyle.fontWeight=optionsSetup.fontWeight;
this.options.digitalFlopStyle = fontStyle;
this.$nextTick(() => this.moveDigitalFlop())
},
// 配置修改
setOptionsConfig() {
const optionsSetup = this.optionsSetup;
this.options.radius = optionsSetup.radius+"%";
this.options.activeRadius = optionsSetup.activeRadius+"%";
this.options.lineWidth = optionsSetup.lineWidth;
this.options.activeTimeGap = optionsSetup.activeTimeGap;
this.options.digitalFlopToFixed = optionsSetup.digitalFlopToFixed;
this.options.digitalFlopUnit = optionsSetup.digitalFlopUnit;
this.options.animationFrame = optionsSetup.animationFrame;
this.options.showOriginValue = optionsSetup.showOriginValue;
//改变options
// console.log("配置修改:",this.styleObj);
// this.options={...this.options};
},
//数据类型
setOptionsData() {
const optionsData = this.optionsData; // 数据类型 静态 or 动态
optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData)
: this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
},
staticDataFn(val) {
// console.log("设置静态数据",this.options)
const staticData = typeof val == "string" ? JSON.parse(val) : val;
this.options.data=staticData;
this.setLabelConfigData(val);
},
dynamicDataFn(val, refreshTime) {
if (!val) return;
if (this.ispreview) {
this.getEchartData(val);
this.flagInter = setInterval(() => {
this.getEchartData(val);
}, refreshTime);
} else {
this.getEchartData(val);
}
},
getEchartData(val) {
const data = this.queryEchartsData(val);
data.then(res => {
this.renderingFn(res);
});
},
renderingFn(val) {
// console.log("设置静态数据",val)
this.options.data=val;
this.setLabelConfigData(val);
this.reload();
},
setLabelConfigData(val){
const optionsSetup = this.optionsSetup;
const data = [];
if(this.isNotBlankArray(val)){
for(let i = 0;i<val.length;i++){
const oneVal = val[i];
let showName = oneVal['name'];
if(optionsSetup.isShowTipVal){
showName = showName+' '+oneVal['value'];
}
data.push(showName);
}
this.labelConfig.data = data;
}
},
// vue hack 之强制刷新组件
reload(){
this.isRouterAlive=false;
this.$nextTick(function(){
this.isRouterAlive=true;
this.$nextTick(() => this.moveDigitalFlop())
})
},
moveDigitalFlop() {
this.$nextTick(() => {
// 真实数字容器 class = active-ring-info
const box = this.$el.querySelector('.active-ring-info')
if (!box) return
const dx = this.optionsSetup.digitalLeft || 0
const dy = this.optionsSetup.digitalTop || 0
// 直接 translate 即可
box.style.left = dx + 'px'
box.style.top = dy + 'px'
})
},
}
};
</script>
<style scoped lang="scss">
.bottom-charts {
width: 100%;
height: 100%;
position: absolute;
.bc-chart-item {
//width: 25%;
//height: 100%;
//padding-top: 20px;
//box-sizing: border-box;
position: absolute;
}
.ringChart{
width: 100%;
height: 95%;
position: absolute;
}
//.bcci-header {
// height: 50px;
// text-align: center;
// line-height: 50px;
// font-size: 20px;
//}
//
//.label-tag {
// height: 30px;
//}
//.active-ring-info{ position: absolute;}
.active-ring-name {
font-size: 18px!important;
}
}
</style>