Showing
2 changed files
with
101 additions
and
0 deletions
src/components/MarqueeField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-08-29 14:31:20 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-11-23 10:49:41 | ||
| 5 | + * @FilePath: /data-table/src/components/MarqueeField/index.vue | ||
| 6 | + * @Description: 跑马灯控件 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="marquee-field-page"> | ||
| 10 | + <div class="title">- {{ item.component_props.title }} -</div> | ||
| 11 | + <div class="scroll-wrap"> | ||
| 12 | + <div class="scroll-content" :style="{ top }"> | ||
| 13 | + <p v-for="x in marqueeList"> | ||
| 14 | + <van-row> | ||
| 15 | + <van-col span="8">{{ x.name }}</van-col> | ||
| 16 | + <van-col span="8">{{ x.tel }}</van-col> | ||
| 17 | + <van-col span="8">{{ x.time }}</van-col> | ||
| 18 | + </van-row> | ||
| 19 | + </p> | ||
| 20 | + </div> | ||
| 21 | + </div> | ||
| 22 | + </div> | ||
| 23 | +</template> | ||
| 24 | + | ||
| 25 | +<script setup> | ||
| 26 | +const props = defineProps({ | ||
| 27 | + item: Object, | ||
| 28 | +}); | ||
| 29 | + | ||
| 30 | +onMounted(() => { | ||
| 31 | + getList(); | ||
| 32 | + ScrollUp(); | ||
| 33 | +}); | ||
| 34 | + | ||
| 35 | +const top = computed(() => { | ||
| 36 | + return -activeIndex.value * 30 + "px"; | ||
| 37 | +}); | ||
| 38 | + | ||
| 39 | +const activeIndex = ref(0); | ||
| 40 | +const intNum = ref(0); | ||
| 41 | +const marqueeList = ref([]); | ||
| 42 | +// 查询名单 | ||
| 43 | +// TODO: 数据从哪里来? | ||
| 44 | +const getList = () => { | ||
| 45 | + const arr = []; | ||
| 46 | + for (let index = 0; index < 100; index++) { | ||
| 47 | + arr.push({ | ||
| 48 | + name: `abc${index}`, | ||
| 49 | + tel: "137***3456", | ||
| 50 | + time: `${index}分钟前`, | ||
| 51 | + }); | ||
| 52 | + } | ||
| 53 | + console.warn(arr); | ||
| 54 | + marqueeList.value = arr; | ||
| 55 | +}; | ||
| 56 | +//滚动播报方法 | ||
| 57 | +const ScrollUp = () => { | ||
| 58 | + intNum.value = setInterval(() => { | ||
| 59 | + if (activeIndex.value < marqueeList.value.length) { | ||
| 60 | + activeIndex.value += 1; | ||
| 61 | + } else { | ||
| 62 | + activeIndex.value = 0; | ||
| 63 | + } | ||
| 64 | + }, 1000); | ||
| 65 | +}; | ||
| 66 | +</script> | ||
| 67 | + | ||
| 68 | +<style lang="less" scoped> | ||
| 69 | +.marquee-field-page { | ||
| 70 | + padding-bottom: 1rem; | ||
| 71 | + .title { | ||
| 72 | + font-weight: bold; | ||
| 73 | + text-align: center; | ||
| 74 | + width: 100%; | ||
| 75 | + font-size: 1rem; | ||
| 76 | + padding: 1rem 0; | ||
| 77 | + } | ||
| 78 | + .scroll-wrap { | ||
| 79 | + position: relative; | ||
| 80 | + z-index: 2; | ||
| 81 | + overflow: hidden; | ||
| 82 | + .scroll-content { | ||
| 83 | + position: relative; | ||
| 84 | + transition: top 0.5s; | ||
| 85 | + height: 10rem; | ||
| 86 | + } | ||
| 87 | + .scroll-content p { | ||
| 88 | + /* 每行信息间隔高度 */ | ||
| 89 | + line-height: 2; | ||
| 90 | + font-size: 1rem; | ||
| 91 | + text-align: center; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | +} | ||
| 95 | +</style> |
| ... | @@ -20,6 +20,7 @@ import NumberField from '@/components/NumberField/index.vue' | ... | @@ -20,6 +20,7 @@ import NumberField from '@/components/NumberField/index.vue' |
| 20 | import DesField from '@/components/DesField/index.vue' | 20 | import DesField from '@/components/DesField/index.vue' |
| 21 | import DividerField from '@/components/DividerField/index.vue' | 21 | import DividerField from '@/components/DividerField/index.vue' |
| 22 | import VideoField from '@/components/VideoField/index.vue' | 22 | import VideoField from '@/components/VideoField/index.vue' |
| 23 | +import MarqueeField from '@/components/MarqueeField/index.vue' | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * 生成自定义组件类型 | 26 | * 生成自定义组件类型 |
| ... | @@ -43,6 +44,7 @@ import VideoField from '@/components/VideoField/index.vue' | ... | @@ -43,6 +44,7 @@ import VideoField from '@/components/VideoField/index.vue' |
| 43 | * @type desc 文字描述 DesField | 44 | * @type desc 文字描述 DesField |
| 44 | * @type divider 分割线 DividerField | 45 | * @type divider 分割线 DividerField |
| 45 | * @type video 视频控件 VideoField | 46 | * @type video 视频控件 VideoField |
| 47 | + * @type marquee 跑马灯控件 MarqueeField | ||
| 46 | */ | 48 | */ |
| 47 | export function createComponentType(data) { | 49 | export function createComponentType(data) { |
| 48 | // 判断类型和使用组件 | 50 | // 判断类型和使用组件 |
| ... | @@ -127,5 +129,9 @@ export function createComponentType(data) { | ... | @@ -127,5 +129,9 @@ export function createComponentType(data) { |
| 127 | item.name = item.key; | 129 | item.name = item.key; |
| 128 | item.component = VideoField; | 130 | item.component = VideoField; |
| 129 | } | 131 | } |
| 132 | + if (item.component_props.name === 'marquee') { | ||
| 133 | + item.name = item.key; | ||
| 134 | + item.component = MarqueeField; | ||
| 135 | + } | ||
| 130 | }) | 136 | }) |
| 131 | } | 137 | } | ... | ... |
-
Please register or login to post a comment