widgetText.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. whiteSpace: this.transStyle.whiteSpace ? "pre-line": "normal"
  44. };
  45. }
  46. },
  47. watch: {
  48. value: {
  49. handler(val) {
  50. this.options = val;
  51. this.optionsData = val.data;
  52. this.setOptionsData();
  53. },
  54. deep: true
  55. }
  56. },
  57. mounted() {
  58. this.options = this.value;
  59. this.optionsData = this.value.data;
  60. this.setOptionsData();
  61. },
  62. methods: {
  63. // 数据解析
  64. setOptionsData() {
  65. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  66. if (optionsData.dataType == "dynamicData") {
  67. this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  68. } else {};
  69. },
  70. dynamicDataFn(val, refreshTime) {
  71. if (!val) return;
  72. if (this.ispreview) {
  73. this.getEchartData(val);
  74. this.flagInter = setInterval(() => {
  75. this.getEchartData(val);
  76. }, refreshTime);
  77. } else {
  78. this.getEchartData(val);
  79. }
  80. },
  81. getEchartData(val) {
  82. const data = this.queryEchartsData(val);
  83. data.then(res => {
  84. this.styleColor.text = res[0].value;
  85. this.$forceUpdate();
  86. });
  87. }
  88. }
  89. };
  90. </script>
  91. <style scoped lang="scss">
  92. .text {
  93. width: 100%;
  94. height: 100%;
  95. overflow: hidden;
  96. }
  97. </style>