widgetText.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. <div class="text" :style="styleColor">{{ styleColor.text }}</div>
  9. </template>
  10. <script>
  11. export default {
  12. name: "WidgetText",
  13. components: {},
  14. props: {
  15. value: Object,
  16. ispreview: Boolean
  17. },
  18. data() {
  19. return {
  20. options: {},
  21. optionsData: {}
  22. };
  23. },
  24. computed: {
  25. transStyle() {
  26. return this.objToOne(this.options);
  27. },
  28. styleColor() {
  29. return {
  30. position: this.ispreview ? "absolute" : "static",
  31. color: this.transStyle.color,
  32. "font-weight": this.transStyle.fontWeight,
  33. text: this.transStyle.text,
  34. "font-size": this.transStyle.fontSize + "px",
  35. "letter-spacing": this.transStyle.letterSpacing + "em",
  36. background: this.transStyle.background,
  37. "text-align": this.transStyle.textAlign,
  38. width: this.transStyle.width + "px",
  39. height: this.transStyle.height + "px",
  40. left: this.transStyle.left + "px",
  41. top: this.transStyle.top + "px",
  42. right: this.transStyle.right + "px"
  43. };
  44. }
  45. },
  46. watch: {
  47. value: {
  48. handler(val) {
  49. this.options = val;
  50. this.optionsData = val.data;
  51. this.setOptionsData();
  52. },
  53. deep: true
  54. }
  55. },
  56. mounted() {
  57. this.options = this.value;
  58. this.optionsData = this.value.data;
  59. this.setOptionsData();
  60. },
  61. methods: {
  62. // 数据解析
  63. setOptionsData() {
  64. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  65. if (optionsData.dataType == "dynamicData") {
  66. this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  67. } else {};
  68. },
  69. dynamicDataFn(val, refreshTime) {
  70. if (!val) return;
  71. if (this.ispreview) {
  72. this.getEchartData(val);
  73. this.flagInter = setInterval(() => {
  74. this.getEchartData(val);
  75. }, refreshTime);
  76. } else {
  77. this.getEchartData(val);
  78. }
  79. },
  80. getEchartData(val) {
  81. const data = this.queryEchartsData(val);
  82. data.then(res => {
  83. this.styleColor.text = res[0].value;
  84. this.$forceUpdate();
  85. });
  86. }
  87. }
  88. };
  89. </script>
  90. <style scoped lang="scss">
  91. .text {
  92. width: 100%;
  93. height: 100%;
  94. overflow: hidden;
  95. }
  96. </style>