widget.vue
6.11 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
<template>
<avue-draggable
:step="step"
:width="widgetsWidth"
:height="widgetsHeight"
:left="widgetsLeft"
:top="widgetsTop"
ref="draggable"
:index="index"
:z-index="-1"
@focus="handleFocus"
@blur="handleBlur"
>
<component :is="type" :value="value" />
</avue-draggable>
</template>
<script>
import widgetHref from "./text/widgetHref.vue";
import widgetText from "./text/widgetText.vue";
import WidgetMarquee from "./text/widgetMarquee.vue";
import widgetTime from "./text/widgetTime.vue";
import widgetVideo from "./text/widgetVideo.vue";
import WidgetIframe from "./text/widgetIframe.vue";
import widgetBarchart from "./bar/widgetBarchart.vue";
import widgetGradientColorBarchart from "./bar/widgetGradientColorBarchart.vue";
import widgetLinechart from "./line/widgetLinechart.vue";
import widgetBarlinechart from "./barline/widgetBarlinechart";
import WidgetPiechart from "./pie/widgetPiechart.vue";
import WidgetFunnel from "./funnel/widgetFunnel.vue";
import WidgetGauge from "./percent/widgetGauge.vue";
import WidgetPieNightingaleRoseArea from "./pie/widgetPieNightingaleRose";
import widgetTable from "./text/widgetTable.vue";
import widgetLineMap from "./map/widgetLineMap.vue";
import widgetPiePercentageChart from "./percent/widgetPiePercentageChart";
import widgetAirBubbleMap from "./map/widgetAirBubbleMap";
import widgetBarStackChart from "./bar/widgetBarStackChart";
import widgetLineStackChart from "./line/widgetLineStackChart";
import widgetBarCompareChart from "./bar/widgetBarCompareChart";
import widgetLineCompareChart from "./line/widgetLineCompareChart";
import widgetDecoratePieChart from "./decorate/widgetDecoratePieChart";
import widgetMoreBarLineChart from "./barline/widgetMoreBarLineChart";
import widgetWordCloud from "./wordcloud/widgetWordCloud";
import widgetHeatmap from "./heatmap/widgetHeatmap";
import widgetRadar from "./radar/widgetRadar";
import widgetBarLineStackChart from "./barline/widgetBarLineStackChart";
import widgetDecorate from "./decorate/decorate.vue";
// import widgetDiv from "./div/widgetDiv.vue";
import widgetImage from "./div/widgetImage.vue";
import widgetSlider from "./div/widgetSlider.vue";
import widgetBorderBox from "./div/widgetBorderBox.vue";
import widgetDecoration from "./div/widgetDecoration.vue";
import widgetCapsuleChart from "./bar/widgetCapsuleChart";
import widgetProgress from "./percent/widgetProgress";
import widgetWaterLevelPond from "./div/widgetWaterLevelPond";
export default {
name: "Widget",
components: {
widgetDecorate,
widgetDecoration,
widgetCapsuleChart,
// widgetDiv,
widgetBorderBox,
widgetHref,
widgetText,
WidgetMarquee,
widgetTime,
widgetImage,
widgetSlider,
widgetVideo,
WidgetIframe,
widgetBarchart,
widgetGradientColorBarchart,
widgetLinechart,
widgetBarlinechart,
WidgetPiechart,
WidgetFunnel,
WidgetGauge,
WidgetPieNightingaleRoseArea,
widgetTable,
widgetLineMap,
widgetPiePercentageChart,
widgetAirBubbleMap,
widgetBarStackChart,
widgetLineStackChart,
widgetBarCompareChart,
widgetLineCompareChart,
widgetDecoratePieChart,
widgetMoreBarLineChart,
widgetWordCloud,
widgetHeatmap,
widgetRadar,
widgetBarLineStackChart,
widgetProgress,
widgetWaterLevelPond
},
model: {
prop: "value",
event: "input"
},
props: {
/*
widget-text widget-marquee widget-href widget-time widget-image widget-slider widget-video widget-table widget-iframe widget-universal
widget-linechart widget-barlinechart widget-piechart widget-hollow-piechart widget-funnel widget-gauge widget-china-map
*/
// 当前组件,在工作区变量widgetInWorkbench中的索引
index: Number,
type: String,
value: {
type: [Object],
default: () => {}
},
step: Number,
},
data() {
return {
data: {
setup: {},
data: {},
position: {},
/* leftMargin: null,
topMargin: null*/
},
};
},
computed: {
widgetsWidth() {
return this.value.position.width;
},
widgetsHeight() {
return this.value.position.height;
},
widgetsLeft() {
return this.value.position.left// >= this.leftMargin ? this.leftMargin : this.value.position.left;
},
widgetsTop() {
return this.value.position.top// >= this.topMargin ? this.topMargin : this.value.position.top;
},
widgetsZIndex() {
return this.value.position.zIndex || 1;
}
},
mounted() {},
methods: {
handleFocus({ index, left, top, width, height }) {},
handleBlur({ index, left, top, width, height }) {
this.$emit("onActivated", { index, left, top, width, height });
this.$refs.draggable.setActive(true);
// 处理widget超出workbench的问题
//this.handleBoundary({ index, left, top, width, height })
},
handleBoundary({ index, left, top, width, height }) {
// 计算workbench的X轴边界值
// 组件距离左侧宽度 + 组件宽度 > 大屏总宽度时,右侧边界值 = (大屏宽度 - 组件宽度);左侧边界值 = 0
const { bigscreenWidth, bigscreenHeight } = this.bigscreen;
const xBoundaryValue = (left + width) > bigscreenWidth ? bigscreenWidth - width : left < 0 ? 0 : left;
// 初始化X轴边界值
this.leftMargin = left;
// 计算Y轴边界值
const yBoundaryValue = (top + height) > bigscreenHeight ? bigscreenHeight - height : top < 0 ? 0 : top;
// 初始化Y轴边界值
this.topMargin = top;
// 若位置超出边界值则重新设置位置
if (this.leftMargin != xBoundaryValue || this.topMargin != yBoundaryValue) {
this.$nextTick(() => {
this.leftMargin = xBoundaryValue;
this.topMargin = yBoundaryValue;
this.$emit("onActivated", { index, left: xBoundaryValue, top: yBoundaryValue, width, height });
})
}
}
}
};
</script>
<style scoped lang="scss">
.vue-draggalbe {
position: absolute;
}
.widget-active {
cursor: move;
border: 1px dashed #09f;
background-color: rgba(115, 170, 229, 0.5);
}
.avue-draggable {
padding: 0 !important;
}
</style>