index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="marquee-box">
  3. <div class="scroll-area">
  4. <!-- 设置margin,使内容 有从无到有的出现效果 -->
  5. <div class="marquee-container">
  6. <svg class="svg-container">
  7. <defs>
  8. <linearGradient
  9. :id="'backgroundGradient-'+config.code"
  10. :x1="0"
  11. :y1="['to top right'].includes(config.customize.bgGradientDirection) ? '100%' : '0'"
  12. :x2="['to right','to bottom right','to top right'].includes(config.customize.bgGradientDirection) ? '100%' : '0'"
  13. :y2="['to bottom','to bottom right'].includes(config.customize.bgGradientDirection) ? '100%' : '0'"
  14. >
  15. <stop
  16. offset="0%"
  17. :stop-color="config.customize.backgroundColorType === 'pure' ? config.customize.backgroundColor : config.customize.bgGradientColor0"
  18. />
  19. <stop
  20. offset="100%"
  21. :stop-color="config.customize.backgroundColorType === 'pure' ? config.customize.backgroundColor : config.customize.bgGradientColor1"
  22. />
  23. </linearGradient>
  24. <linearGradient
  25. :id="'textGradient-'+config.code"
  26. :x1="0"
  27. :y1="['to top right'].includes(config.customize.textGradientDirection) ? '100%' : '0'"
  28. :x2="['to right','to bottom right','to top right'].includes(config.customize.textGradientDirection) ? '100%' : '0'"
  29. :y2="['to bottom','to bottom right'].includes(config.customize.textGradientDirection) ? '100%' : '0'"
  30. >
  31. <stop
  32. offset="0%"
  33. :stop-color="config.customize.textColorType === 'pure' ? config.customize.textColor : config.customize.textGradientColor0"
  34. />
  35. <stop
  36. offset="100%"
  37. :stop-color="config.customize.textColorType === 'pure' ? config.customize.textColor : config.customize.textGradientColor1"
  38. />
  39. </linearGradient>
  40. </defs>
  41. <rect
  42. v-if="config.customize.backgroundColorType !== 'transparent'"
  43. width="100%"
  44. height="100%"
  45. :fill="`url(#backgroundGradient-${config.code})`"
  46. />
  47. <text
  48. :x="10"
  49. :y="config.customize.fontSize"
  50. :style="{ fontSize: config.customize.fontSize + 'px', fontWeight: config.customize.fontWeight }"
  51. :fill="`url(#textGradient-${config.code})`"
  52. >
  53. <animate
  54. v-if="isAnimate"
  55. :attributeName="attributeName[config.customize.direction]"
  56. :from="from[config.customize.direction]"
  57. :to="to[config.customize.direction]"
  58. :dur="config.customize.dur + 's'"
  59. repeatCount="indefinite"
  60. />
  61. <i
  62. v-if="config.customize.icon.position === 'left'"
  63. :class="config.customize.icon.name"
  64. :style="{ color: config.customize.icon.color, fontSize: config.customize.fontSize + 'px' }"
  65. />
  66. {{ config.customize.title }}
  67. <i
  68. v-if="config.customize.icon.position === 'right'"
  69. :class="config.customize.icon.name"
  70. :style="{ color: config.customize.icon.color, fontSize: config.customize.fontSize + 'px' }"
  71. />
  72. </text>
  73. </svg>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  80. import commonMixins from 'data-room-ui/js/mixins/commonMixins'
  81. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  82. export default {
  83. props: {
  84. // 卡片的属性
  85. config: {
  86. type: Object,
  87. default: () => ({})
  88. }
  89. },
  90. data () {
  91. return {
  92. customClass: {},
  93. attributeName: {
  94. right: 'x',
  95. left: 'x',
  96. top: 'y',
  97. bottom: 'y'
  98. },
  99. // 动画开始
  100. from: {
  101. left: '-100%',
  102. right: '100%',
  103. top: '-100%',
  104. bottom: '100%'
  105. },
  106. // 动画结束
  107. to: {
  108. left: '100%',
  109. right: '-100%',
  110. top: '100%',
  111. bottom: '-100%'
  112. },
  113. isAnimate: true
  114. }
  115. },
  116. mixins: [paramsMixins, commonMixins],
  117. mounted () {
  118. this.chartInit()
  119. // 如果点击了生成图片,则先关闭动画
  120. EventBus.$on('stopMarquee', () => {
  121. this.isAnimate = false
  122. })
  123. // 图片生成完成后,再开启动画
  124. EventBus.$on('startMarquee', () => {
  125. this.isAnimate = true
  126. })
  127. },
  128. beforeDestroy () {
  129. EventBus.$off('stopMarquee')
  130. EventBus.$off('startMarquee')
  131. },
  132. methods: {
  133. changeStyle () {
  134. },
  135. dataFormatting (config, data) {
  136. // 文本数据配置原则:选择数据集则以后端返回的数据为主,否则以设置面板中标题设置为准
  137. if (config.dataSource.businessKey) {
  138. config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
  139. }
  140. return config
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .marquee-box {
  147. width: 100%;
  148. height: 100%;
  149. display: inline-block;
  150. white-space: nowrap;
  151. overflow: hidden;
  152. .scroll-area {
  153. width: 100%;
  154. height: 100%;
  155. display: inline-block;
  156. .marquee-container {
  157. width: 100%;
  158. height: 100%;
  159. display: inline-block;
  160. .svg-container {
  161. display: inline-block;
  162. width: 100%;
  163. height: 100%;
  164. }
  165. }
  166. }
  167. }
  168. </style>