index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="scroll-container"
  3. :style="{background:'linear-gradient(to right,'+cardBackColor[0]+','+cardBackColor[1]+')',
  4. borderRadius: cardBorderRadius
  5. }"
  6. >
  7. <div
  8. style="display: flex;
  9. justify-content: space-evenly;
  10. align-items: center;"
  11. class="headCss"
  12. :style="{background:'linear-gradient(to right,'+titleBackColor[0]+','+titleBackColor[1]+')'}"
  13. >
  14. <n-icon
  15. :size="titleSize"
  16. :color="iconColor"
  17. :component="getIconComponent(iconType)" ></n-icon>
  18. <n-gradient-text
  19. :size="titleSize"
  20. :style="{fontWeight:fontWeight}"
  21. :gradient="{
  22. deg: 180,
  23. from:titleColor[0],
  24. to: titleColor[1],
  25. }"
  26. >
  27. {{cardTitle}}
  28. </n-gradient-text>
  29. </div>
  30. <div class="scroll-wrapper" ref="scrollWrapper">
  31. <ul class="scroll-list" :style="{ transform: `translateY(${scrollY}px)` }"
  32. @mouseenter="handleMouseEnter"
  33. @mouseleave="handleMouseLeave">
  34. <li v-for="(item, index) in option.dataset"
  35. :key="index" class="scroll-item scroll-itemData"
  36. :style="{height: itemHeight+'px',
  37. lineHeight: itemHeight+'px',
  38. fontSize:fontSize+'px',
  39. background:'linear-gradient(to right,'+(index%2===0?itemColor1[0]:itemColor2[0])+','+(index%2===0?itemColor1[1]:itemColor2[1])+')'}"
  40. >
  41. <div class="scroll-time" :style="{color:itemFontColor}">{{ item.title }}</div>
  42. <div class="scroll-time" :style="{color:itemFontColor}">{{ item.content }}</div>
  43. </li>
  44. </ul>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import {Component ,PropType, toRefs, shallowReactive, watch, computed, ref, onMounted, nextTick} from 'vue'
  50. import { CreateComponentType } from '@/packages/index.d'
  51. import { useChartDataFetch } from '@/hooks'
  52. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  53. import { option as configOption } from './config'
  54. import * as Icons from '@vicons/ionicons5'
  55. import { values } from 'lodash'
  56. const props = defineProps({
  57. chartConfig: {
  58. type: Object as PropType<CreateComponentType & typeof option>,
  59. required: true
  60. }
  61. })
  62. let scrollY = ref(0)
  63. let timer:any;
  64. const {
  65. cardTitle,
  66. fontSize,
  67. titleSize,
  68. titleColor,
  69. iconType,
  70. iconColor,
  71. itemColor1,
  72. itemColor2,
  73. cardBackColor,
  74. titleBackColor,
  75. cardBorderRadius,
  76. itemFontColor,
  77. fontWeight,
  78. itemHeight, // 每个项的高度,根据实际情况调整
  79. animationDuration, // 动画持续时间,根据实际情况调整
  80. dataList,
  81. } = toRefs(
  82. props.chartConfig.option
  83. )
  84. const option = shallowReactive({
  85. dataset: configOption.dataset
  86. })
  87. watch(
  88. () => props.chartConfig.option.dataset,
  89. (newData: any) => {
  90. option.dataset = newData
  91. },
  92. {
  93. immediate: true,
  94. deep: false
  95. }
  96. )
  97. const getIconComponent = (iconName: any) => {
  98. return (Icons as Record<string, Component>)[iconName]|| null; // 返回相应的图标组件
  99. }
  100. // 预览更新
  101. useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
  102. option.dataset = newData
  103. })
  104. onMounted(() => {
  105. console.log('22222222222222222222223')
  106. console.log(props.chartConfig.option)
  107. console.log(configOption)
  108. startScrollAnimation();
  109. })
  110. // onMethods(() => {
  111. //
  112. //
  113. // })
  114. // 滚动处理
  115. const startScrollAnimation = () => {
  116. const totalHeight = itemHeight.value * dataList.value.length;
  117. timer = setInterval(() => {
  118. console.log('滚动测试...')
  119. scrollY.value -= itemHeight.value;
  120. if (Math.abs(totalHeight - itemHeight.value * 2) <= Math.abs(scrollY.value)) {
  121. console.log('滚动测试2...')
  122. setTimeout(() => {
  123. scrollY.value = 0;
  124. }, animationDuration.value / 2);
  125. }
  126. }, animationDuration.value);
  127. }
  128. // 清除
  129. const clearTime = () => {
  130. if (timer) {
  131. clearInterval(timer)
  132. timer = null
  133. }
  134. }
  135. // 打开弹窗
  136. const openModal = (data:any) => {
  137. window.postMessage({
  138. type: 'hookEmitEvent',
  139. data: {
  140. // 动作类型:单击 click、双击 dblclick、移入 mouseenter、移出 mouseleave、更新 dataUpdate
  141. eventType: 'click',
  142. // 需要传递的数据,可以是任意类型
  143. value: {
  144. text: ''
  145. }
  146. }
  147. })
  148. }
  149. //
  150. const handleMouseEnter = () => {
  151. clearTime()
  152. }
  153. const handleMouseLeave = () => {
  154. scrollY.value = 0
  155. startScrollAnimation()
  156. }
  157. const beforeUnmount = () => {
  158. clearTime()
  159. }
  160. </script>
  161. <style>
  162. body {
  163. margin: 0;
  164. overflow: hidden;
  165. }
  166. html,
  167. body,
  168. #app,
  169. .scroll-container {
  170. height: 100%;
  171. }
  172. .scroll-container {
  173. width: 100%;
  174. overflow: hidden;
  175. position: relative;
  176. color: #FFFF;
  177. }
  178. .headCss {
  179. font-size: 14px;
  180. min-height: 30px;
  181. text-align: center;
  182. }
  183. .scroll-wrapper {
  184. position: absolute;
  185. width: 100%;
  186. height: 100%;
  187. overflow-y: auto;
  188. /* WebKit 浏览器(如 Chrome、Safari)*/
  189. scrollbar-width: thin;
  190. /* 确保滚动条尺寸一致 */
  191. scrollbar-color: transparent transparent;
  192. /* 隐藏滚动条颜色 */
  193. }
  194. .scroll-wrapper::-webkit-scrollbar {
  195. width: 0px;
  196. /* 设置滚动条宽度 */
  197. }
  198. .scroll-wrapper::-webkit-scrollbar-thumb {
  199. background-color: transparent;
  200. /* 设置滚动条颜色 */
  201. }
  202. .scroll-list {
  203. width: 100%;
  204. margin: 0;
  205. padding: 0;
  206. list-style: none;
  207. transition: transform 500ms ease-in-out;
  208. }
  209. .scroll-itemData {
  210. display: flex;
  211. }
  212. .scroll-time {
  213. opacity: 0.6;
  214. text-align: center;
  215. background-color: transparent;
  216. width: 50%;
  217. }
  218. </style>