1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
    <view class="diy-notice"
        :style="{ padding: itemData.style.paddingTop + 'px' + ' 10px', background: itemData.style.background }"
        @click="gotoPages(item)">
        <view class="notice-icon">
            <image :src="itemData.params.icon" mode="aspectFill"></image>
        </view>
        <view class="notice-text flex-1 text-ellipsisss">
            <view class="transtext" :style="'color:'+itemData.style.textColor+';left:'+textW+'rpx'">{{ textData }}
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                textData: '',
                n: 0,
                textW: 0,
                start: 0,
                times: null
            };
        },
        props: ['itemData'],
        created() {
            this.textData = this.itemData.params.text;
            this.init();
            this.horseRaceLamp();
        },
        beforeDestroy() {
            clearTimeout(this.times)
        },
        methods: {
            /*初始化*/
            init() {
                let self = this;
                uni.getSystemInfo({
                    success(res) {
                        // 计算组件的高度
                        let view = uni.createSelectorQuery().in(self).select('.transtext');
                        view.boundingClientRect(data => {
                            let h = data.width;
                            self.textW = 0;
                            self.start = 2 * h;
                        }).exec();
                    }
                });
            },
            horseRaceLamp() {
                let self = this;
                // return
                self.times = setTimeout(function() {
                    self.textW--;
                    if (self.textW * (-1) >= self.start) {
                        self.textW = 710
                    }
                    // let firstWord=self.textData.slice(0,1);
                    // let afterWord=self.textData.slice(1,self.textData.length);
                    // self.textData=afterWord+firstWord;
                    self.horseRaceLamp();
                }, 10);
            },
 
            /*跳转页面*/
            gotoPages(e) {
                this.gotoPage(e.linkUrl);
            }
        }
    };
</script>
 
<style>
    .diy-notice {
        margin: 20rpx;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        border-radius: 6rpx;
        /* box-shadow: 0 0 8rpx rgba(0, 0, 0, 0.1); */
 
    }
 
    .diy-notice .notice-icon {
        width: 64rpx;
        height: 64rpx;
        margin-right: 20rpx;
    }
 
    .diy-notice .notice-icon image {
        width: 100%;
        height: 100%;
    }
 
    .diy-notice .notice-text {
        overflow: hidden;
        white-space: nowrap;
        position: relative;
        height: 64rpx;
    }
 
    .transtext {
        position: absolute;
        top: 0;
        bottom: 0;
        margin: auto;
        left: 0;
        line-height: 64rpx;
        /* display: inline-block; */
    }
</style>