widgetFunnel.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div :style="styleObj">
  3. <v-chart :options="options" autoresize/>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "WidgetFunnel",
  9. components: {},
  10. props: {
  11. value: Object,
  12. ispreview: Boolean
  13. },
  14. data() {
  15. return {
  16. options: {
  17. color: [],
  18. title: {
  19. text: "",
  20. textStyle: {
  21. color: "#fff"
  22. }
  23. },
  24. tooltip: {
  25. trigger: "item",
  26. formatter: "{a} <br/>{b} : {c}"
  27. },
  28. legend: {
  29. x: 'center',
  30. y: '92%',
  31. textStyle: {
  32. color: "#fff"
  33. }
  34. },
  35. series: [
  36. {
  37. name: "",
  38. type: "funnel",
  39. left: "center",
  40. width: "80%",
  41. //maxSize: '80%',
  42. sort: "descending",
  43. label: {
  44. normal: {
  45. show: true,
  46. position: 'inside',
  47. formatter: '{c}',
  48. textStyle: {
  49. color: '#fff',
  50. fontSize: 14,
  51. }
  52. },
  53. emphasis: {
  54. position: 'inside',
  55. formatter: '{b}: {c}'
  56. }
  57. },
  58. itemStyle: {
  59. normal: {
  60. opacity: 0.8,
  61. borderColor: 'rgba(12, 13, 43, .9)',
  62. borderWidth: 1,
  63. shadowBlur: 4,
  64. shadowOffsetX: 0,
  65. shadowOffsetY: 0,
  66. shadowColor: 'rgba(0, 0, 0, .6)'
  67. }
  68. },
  69. data: []
  70. }
  71. ]
  72. },
  73. optionsStyle: {}, // 样式
  74. optionsData: {}, // 数据
  75. optionsCollapse: {}, // 图标属性
  76. optionsSetup: {}
  77. };
  78. },
  79. computed: {
  80. styleObj() {
  81. return {
  82. position: this.ispreview ? "absolute" : "static",
  83. width: this.optionsStyle.width + "px",
  84. height: this.optionsStyle.height + "px",
  85. left: this.optionsStyle.left + "px",
  86. top: this.optionsStyle.top + "px",
  87. background: this.optionsSetup.background
  88. };
  89. }
  90. },
  91. watch: {
  92. value: {
  93. handler(val) {
  94. this.optionsStyle = val.position;
  95. this.optionsData = val.data;
  96. this.optionsCollapse = val.collapse;
  97. this.optionsSetup = val.setup;
  98. this.editorOptions();
  99. },
  100. deep: true
  101. }
  102. },
  103. created() {
  104. this.optionsStyle = this.value.position;
  105. this.optionsData = this.value.data;
  106. this.optionsCollapse = this.value.collapse;
  107. this.optionsSetup = this.value.setup;
  108. this.editorOptions();
  109. },
  110. methods: {
  111. // 修改图标options属性
  112. editorOptions() {
  113. this.setEnding();
  114. this.setOptionsText();
  115. this.setOptionsTitle();
  116. this.setOptionsTooltip();
  117. this.setOptionsLegend();
  118. this.setOptionsColor();
  119. this.setOptionsData();
  120. },
  121. // 翻转
  122. setEnding() {
  123. const optionsSetup = this.optionsSetup;
  124. const series = this.options.series;
  125. if (optionsSetup.ending) {
  126. series[0].sort = "ascending";
  127. } else {
  128. series[0].sort = "descending";
  129. }
  130. },
  131. // 数值设置
  132. setOptionsText() {
  133. const optionsSetup = this.optionsSetup;
  134. const normal = {
  135. show: optionsSetup.isShow,
  136. position: 'inside',
  137. formatter: '{c}',
  138. textStyle: {
  139. color: optionsSetup.color,
  140. fontSize: optionsSetup.fontSize,
  141. fontWeight: optionsSetup.fontWeight,
  142. }
  143. }
  144. this.options.series[0].label['normal'] = normal;
  145. },
  146. // 标题修改
  147. setOptionsTitle() {
  148. const optionsSetup = this.optionsSetup;
  149. const title = {};
  150. title.text = optionsSetup.titleText;
  151. title.show = optionsSetup.isNoTitle;
  152. title.left = optionsSetup.textAlign;
  153. title.textStyle = {
  154. color: optionsSetup.textColor,
  155. fontSize: optionsSetup.textFontSize,
  156. fontWeight: optionsSetup.textFontWeight
  157. };
  158. title.subtext = optionsSetup.subText;
  159. title.subtextStyle = {
  160. color: optionsSetup.subTextColor,
  161. fontWeight: optionsSetup.subTextFontWeight,
  162. fontSize: optionsSetup.subTextFontSize
  163. };
  164. this.options.title = title;
  165. },
  166. // 提示语设置 tooltip
  167. setOptionsTooltip() {
  168. const optionsSetup = this.optionsSetup;
  169. const tooltip = {
  170. trigger: "item",
  171. show: true,
  172. textStyle: {
  173. color: optionsSetup.lineColor,
  174. fontSize: optionsSetup.tipFontSize
  175. }
  176. };
  177. this.options.tooltip = tooltip;
  178. },
  179. // 图例操作 legend
  180. setOptionsLegend() {
  181. const optionsSetup = this.optionsSetup;
  182. const legend = this.options.legend;
  183. legend.show = optionsSetup.isShowLegend;
  184. legend.left = optionsSetup.lateralPosition;
  185. legend.right = optionsSetup.lateralPosition;
  186. legend.top = optionsSetup.longitudinalPosition;
  187. legend.bottom =
  188. optionsSetup.longitudinalPosition;
  189. legend.orient = optionsSetup.layoutFront;
  190. legend.textStyle = {
  191. color: optionsSetup.lengedColor,
  192. fontSize: optionsSetup.lengedFontSize
  193. };
  194. legend.itemWidth = optionsSetup.lengedWidth;
  195. },
  196. // 图例颜色修改
  197. setOptionsColor() {
  198. const optionsSetup = this.optionsSetup;
  199. const customColor = optionsSetup.customColor;
  200. if (!customColor) return;
  201. const arrColor = [];
  202. for (let i = 0; i < customColor.length; i++) {
  203. arrColor.push(customColor[i].color);
  204. }
  205. this.options.color = arrColor;
  206. this.options = Object.assign({}, this.options);
  207. },
  208. setOptionsData() {
  209. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  210. optionsData.dataType == "staticData"
  211. ? this.staticDataFn(optionsData.staticData)
  212. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  213. },
  214. staticDataFn(val) {
  215. const staticData = typeof val == "string" ? JSON.parse(val) : val;
  216. for (const key in this.options.series) {
  217. if (this.options.series[key].type == "funnel") {
  218. this.options.series[key].data = staticData;
  219. }
  220. }
  221. },
  222. dynamicDataFn(val, refreshTime) {
  223. if (!val) return;
  224. if (this.ispreview) {
  225. this.getEchartData(val);
  226. this.flagInter = setInterval(() => {
  227. this.getEchartData(val);
  228. }, refreshTime);
  229. } else {
  230. this.getEchartData(val);
  231. }
  232. },
  233. getEchartData(val) {
  234. const data = this.queryEchartsData(val);
  235. data.then(res => {
  236. this.renderingFn(res);
  237. });
  238. },
  239. renderingFn(val) {
  240. for (const key in this.options.series) {
  241. if (this.options.series[key].type == "funnel") {
  242. this.options.series[key].data = val;
  243. }
  244. }
  245. }
  246. }
  247. };
  248. </script>
  249. <style scoped lang="scss">
  250. .echarts {
  251. width: 100%;
  252. height: 100%;
  253. overflow: hidden;
  254. }
  255. </style>