widget.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <!--
  2. * @Author: lide1202@hotmail.com
  3. * @Date: 2021-3-13 11:04:24
  4. * @Last Modified by: lide1202@hotmail.com
  5. * @Last Modified time: 2021-3-13 11:04:24
  6. !-->
  7. <template>
  8. <avue-draggable
  9. :step="step"
  10. :width="widgetsWidth"
  11. :height="widgetsHeight"
  12. :left="widgetsLeft"
  13. :top="widgetsTop"
  14. ref="draggable"
  15. :index="index"
  16. :z-index="-1"
  17. @focus="handleFocus"
  18. @blur="handleBlur"
  19. >
  20. <component :is="type" :value="value" />
  21. </avue-draggable>
  22. </template>
  23. <script>
  24. import widgetHref from "./widgetHref.vue";
  25. import widgetText from "./widgetText.vue";
  26. import WidgetMarquee from "./widgetMarquee.vue";
  27. import widgetTime from "./widgetTime.vue";
  28. import widgetImage from "./widgetImage.vue";
  29. import widgetSlider from "./widgetSlider.vue";
  30. import widgetVideo from "./widgetVideo.vue";
  31. import WidgetIframe from "./widgetIframe.vue";
  32. import widgetBarchart from "./bar/widgetBarchart.vue";
  33. import widgetGradientColorBarchart from "./bar/widgetGradientColorBarchart.vue";
  34. import widgetLinechart from "./line/widgetLinechart.vue";
  35. import widgetBarlinechart from "./barline/widgetBarlinechart";
  36. import WidgetPiechart from "./pie/widgetPiechart.vue";
  37. import WidgetFunnel from "./funnel/widgetFunnel.vue";
  38. import WidgetGauge from "./percent/widgetGauge.vue";
  39. import WidgetPieNightingaleRoseArea from "./pie/widgetPieNightingaleRose";
  40. import widgetTable from "./widgetTable.vue";
  41. import widgetLineMap from "./map/widgetLineMap.vue";
  42. import widgetPiePercentageChart from "./percent/widgetPiePercentageChart";
  43. import widgetAirBubbleMap from "./map/widgetAirBubbleMap";
  44. import widgetBarStackChart from "./bar/widgetBarStackChart";
  45. import widgetLineStackChart from "./line/widgetLineStackChart";
  46. import widgetBarCompareChart from "./bar/widgetBarCompareChart";
  47. import widgetLineCompareChart from "./line/widgetLineCompareChart";
  48. import widgetDecoratePieChart from "./decorate/widgetDecoratePieChart";
  49. import widgetMoreBarLineChart from "./barline/widgetMoreBarLineChart";
  50. import widgetWordCloud from "./wordcloud/widgetWordCloud";
  51. import widgetHeatmap from "./heatmap/widgetHeatmap";
  52. import widgetRadar from "./radar/widgetRadar";
  53. import widgetBarLineStackChart from "./barline/widgetBarLineStackChart";
  54. import widgetSelect from "./form/widgetSelect";
  55. import widgetInput from "./form/widgetInput.vue";
  56. export default {
  57. name: "Widget",
  58. components: {
  59. widgetHref,
  60. widgetText,
  61. WidgetMarquee,
  62. widgetTime,
  63. widgetImage,
  64. widgetSlider,
  65. widgetVideo,
  66. WidgetIframe,
  67. widgetBarchart,
  68. widgetGradientColorBarchart,
  69. widgetLinechart,
  70. widgetBarlinechart,
  71. WidgetPiechart,
  72. WidgetFunnel,
  73. WidgetGauge,
  74. WidgetPieNightingaleRoseArea,
  75. widgetTable,
  76. widgetLineMap,
  77. widgetPiePercentageChart,
  78. widgetAirBubbleMap,
  79. widgetBarStackChart,
  80. widgetLineStackChart,
  81. widgetBarCompareChart,
  82. widgetLineCompareChart,
  83. widgetDecoratePieChart,
  84. widgetMoreBarLineChart,
  85. widgetWordCloud,
  86. widgetHeatmap,
  87. widgetRadar,
  88. widgetBarLineStackChart,
  89. widgetSelect,
  90. widgetInput
  91. },
  92. model: {
  93. prop: "value",
  94. event: "input",
  95. },
  96. props: {
  97. /*
  98. widget-text widget-marquee widget-href widget-time widget-image widget-slider widget-video widget-table widget-iframe widget-universal
  99. widget-linechart widget-barlinechart widget-piechart widget-hollow-piechart widget-funnel widget-gauge widget-china-map
  100. */
  101. index: Number, // 当前组件,在工作区变量widgetInWorkbench中的索引
  102. type: String,
  103. bigscreen: Object,
  104. value: {
  105. type: [Object],
  106. default: () => {},
  107. },
  108. step: Number,
  109. },
  110. data() {
  111. return {
  112. data: {
  113. setup: {},
  114. data: {},
  115. position: {},
  116. /* leftMargin: null,
  117. topMargin: null*/
  118. },
  119. };
  120. },
  121. computed: {
  122. widgetsWidth() {
  123. return this.value.position.width;
  124. },
  125. widgetsHeight() {
  126. return this.value.position.height;
  127. },
  128. widgetsLeft() {
  129. return this.value.position.left; // >= this.leftMargin ? this.leftMargin : this.value.position.left;
  130. },
  131. widgetsTop() {
  132. return this.value.position.top; // >= this.topMargin ? this.topMargin : this.value.position.top;
  133. },
  134. widgetsZIndex() {
  135. return this.value.position.zIndex || 1;
  136. },
  137. },
  138. mounted() {},
  139. methods: {
  140. handleFocus({ index, left, top, width, height }) {},
  141. handleBlur({ index, left, top, width, height }) {
  142. this.$emit("onActivated", { index, left, top, width, height });
  143. this.$refs.draggable.setActive(true);
  144. // 处理widget超出workbench的问题
  145. //this.handleBoundary({ index, left, top, width, height })
  146. },
  147. handleBoundary({ index, left, top, width, height }) {
  148. // 计算workbench的X轴边界值
  149. // 组件距离左侧宽度 + 组件宽度 > 大屏总宽度时,右侧边界值 = (大屏宽度 - 组件宽度);左侧边界值 = 0
  150. const { bigscreenWidth, bigscreenHeight } = this.bigscreen;
  151. const xBoundaryValue =
  152. left + width > bigscreenWidth
  153. ? bigscreenWidth - width
  154. : left < 0
  155. ? 0
  156. : left;
  157. // 初始化X轴边界值
  158. this.leftMargin = left;
  159. // 计算Y轴边界值
  160. const yBoundaryValue =
  161. top + height > bigscreenHeight
  162. ? bigscreenHeight - height
  163. : top < 0
  164. ? 0
  165. : top;
  166. // 初始化Y轴边界值
  167. this.topMargin = top;
  168. // 若位置超出边界值则重新设置位置
  169. if (
  170. this.leftMargin != xBoundaryValue ||
  171. this.topMargin != yBoundaryValue
  172. ) {
  173. this.$nextTick(() => {
  174. this.leftMargin = xBoundaryValue;
  175. this.topMargin = yBoundaryValue;
  176. this.$emit("onActivated", {
  177. index,
  178. left: xBoundaryValue,
  179. top: yBoundaryValue,
  180. width,
  181. height,
  182. });
  183. });
  184. }
  185. },
  186. },
  187. };
  188. </script>
  189. <style scoped lang="scss">
  190. .vue-draggalbe {
  191. position: absolute;
  192. }
  193. .widget-active {
  194. cursor: move;
  195. border: 1px dashed #09f;
  196. background-color: rgba(115, 170, 229, 0.5);
  197. }
  198. .avue-draggable {
  199. padding: 0 !important;
  200. }
  201. </style>