jiangping
2023-08-21 525dae0dec6ba6afbe6bf81b82eb99d69aeb05b5
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<template>
    <div class="content1">
        <div class="content_left">
            <div class="content_left_item1">
                <div class="content_left_item1_head">
                    <span>当日员工产量TOP10</span>
                </div>
                <div class="content_left_item1_content">
                    <div class="content_left_item1_content_row" v-for="(item, index) in 10" :key="index">
                        <div class="content_left_item1_content_row_name">
                            <div :class="index > 2 ? 'num bg1' : 'num bg2'">{{ index + 1 }}</div>
                            <span>赵立{{ index }}</span>
                        </div>
                        <div class="content_left_item1_content_row_line">
                            <el-progress
                                :show-text="false"
                                :percentage="50">
                            </el-progress>
                        </div>
                        <div class="content_left_item1_content_row_num">342</div>
                    </div>
                </div>
            </div>
            <div class="content_left_item2">
                <div class="content_left_item2_head">
                    <span>仓库实时余量统计</span>
                </div>
                <div class="content_left_item2_content">
                    <div class="item2_content_head">
                        <div class="item2_content_head_item">物料名称 / 工序</div>
                        <div class="item2_content_head_item">仓库</div>
                        <div class="item2_content_head_item">货架</div>
                        <div class="item2_content_head_item">数量</div>
                    </div>
                    <div @mouseenter="handleMouseEnter" @mouseleave="handleMouseLeave" class="main_container">
                        <div ref="scrollContainer" class="scroll_container">
                            <div v-for="(item, index) in listData" :key="item.id" :class="index % 2 == 0 ? 'scroll_item scroll_item_bg1' : 'scroll_item scroll_item_bg2'">
                                <span>{{ item.name }}</span>
                                <div class="scroll_item_row"></div>
                                <div class="scroll_item_row"></div>
                                <div class="scroll_item_row"></div>
                                <div class="scroll_item_row"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="content_center">2</div>
        <div class="content_right">3</div>
    </div>
</template>
 
<script setup>
    import {reactive, ref, onMounted, onBeforeUnmount, onUnmounted, nextTick} from 'vue'
 
    let timer = ref(null)
    let scrollContainer = ref(null)
    let listData = reactive([
        {name: 'dom第一个'},
        {name: 'dom第二个'},
        {name: 'dom第三个'},
        {name: 'dom第四个'},
        {name: 'dom第五个'},
        {name: 'dom第六个'},
        {name: 'dom第七个'},
        {name: 'dom第八个'},
        {name: 'dom第九个'},
        {name: 'dom第十个'},
    ])
    start()
    // 注:示例中的 listData 写的是静态数据,可以直接调用 start()
    // 如果是接口获取 listData 列表时,需要在 nextTick 中调用 start()
    // 否则,进入页面不会滚动。必须鼠标移入移出才会滚动
    // 用 nextTick 的原因是需要等 dom 元素加载完毕后再执行方法
    
    // let chartData = reactive({
    //     data: []
    // })
    // function getSensorData() {
    //     GetSensorData().then(res=> {
    //         chartData.data = res.data.data
    //         nextTick(()=>{
    //             start()
    //         })
    //     })
    // }
    
    // onMounted(()=> {
    //     getSensorData()
    // })
 
    onBeforeUnmount(()=>{
        clearTimeout(timer.value)
    })
    onUnmounted(()=>{
        clearTimeout(timer.value)
    })
 
    function handleMouseEnter() {
        clearTimeout(timer.value)
    }
    function handleMouseLeave() {
        start()
    }
    // 开启定时器
    function start() {
        clearTimeout(timer.value)
        // 定时器触发周期
        let speed = ref(25)
        timer.value = setInterval(ListScroll, speed.value)
    }
    function ListScroll() {
        let scrollDom = scrollContainer.value
        // 判读组件是否渲染完成
        if(scrollDom.offsetHeight == 0) {
            scrollDom = scrollContainer.value
        }else {
            // 如果列表数量过少不进行滚动
            if(scrollDom.children.length < 4) {
                clearTimeout(timer.value)
                return
            }
            // 组件进行滚动
            scrollDom.scrollTop += 1
            // 判断是否滚动到底部
            if(scrollDom.scrollTop == (scrollDom.scrollHeight - scrollDom.clientHeight)) {
                // 获取组件第一个节点
                let first = scrollDom.children[0]
                // 删除节点
                scrollDom.removeChild(first)
                // 将该节点拼接到组件最后
                scrollDom.append(first)
            }
        }
    }  
</script>
 
<style lang="scss" scoped>
    .content1 {
        width: 100%;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .content_left {
            flex: 1;
            .content_left_item1 {
                width: 100%;
                margin-bottom: 20px;
                .content_left_item1_head {
                    background: url('@/assets/img/home_title_short@2x.png');
                    background-repeat: no-repeat;
                    background-size: 100% 100%;
                    width: 100%;
                    height: 38px;
                    line-height: 38px;
                    padding-left: 34px;
                    box-sizing: border-box;
                    span {
                        font-size: 16px;
                        font-family: SourceHanSansSC-Bold, SourceHanSansSC;
                        font-weight: bold;
                        color: #FFFFFF;
                        line-height: 24px;
                        text-shadow: 0px 0px 10px rgba(0,24,72,0.75);
                    }
                }
                .content_left_item1_content {
                    width: 100%;
                    height: 360px;
                    padding: 20px;
                    box-sizing: border-box;
                    background: linear-gradient(180deg, rgba(52,88,159,0) 0%, rgba(0,86,255,0.4) 100%);
                    .content_left_item1_content_row {
                        width: 100%;
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        margin-bottom: 13px;
                        &:last-child {
                            margin: 0;
                        }
                        .content_left_item1_content_row_name {
                            flex-shrink: 0;
                            display: flex;
                            align-items: center;
                            span {
                                font-size: 13px;
                                font-family: SourceHanSansSC-Regular, SourceHanSansSC;
                                font-weight: 400;
                                color: #D2E0FF;
                                margin-left: 9px;
                            }
                            .num {
                                width: 20px;
                                height: 20px;
                                line-height: 20px;
                                text-align: center;
                                font-size: 12px;
                                font-family: SourceHanSansSC-Medium, SourceHanSansSC;
                                font-weight: 500;
                                color: #FFFFFF;
                            }
                            .bg1 {
                                background: url('@/assets/img/rank_blue@2x.png');
                                background-repeat: no-repeat;
                                background-size: 100% 100%;
                            }
                            .bg2 {
                                background: url('@/assets/img/rank_yellow@2x.png');
                                background-repeat: no-repeat;
                                background-size: 100% 100%;
                            }
                        }
                        .content_left_item1_content_row_line {
                            flex: 1;
                            margin: 0 15px;
                            &::v-deep(.el-progress-bar__outer) {
                                border-radius: 0%;
                                background: rgba(255,255,255,0.13);
                            }
                            &::v-deep(.el-progress-bar__inner) {
                                border-radius: 0%;
                                background: linear-gradient(270deg, #00B0FF 0%, #345BA3 100%);
                            }
                        }
                        .content_left_item1_content_row_num {
                            font-size: 13px;
                            font-family: SourceHanSansSC-Regular, SourceHanSansSC;
                            font-weight: 400;
                            color: #D2E0FF;
                        }
                    }
                }
            }
            .content_left_item2 {
                width: 100%;
                .content_left_item2_head {
                    background: url('@/assets/img/home_title_short@2x.png');
                    background-repeat: no-repeat;
                    background-size: 100% 100%;
                    width: 100%;
                    height: 38px;
                    line-height: 38px;
                    padding-left: 34px;
                    box-sizing: border-box;
                    span {
                        font-size: 16px;
                        font-family: SourceHanSansSC-Bold, SourceHanSansSC;
                        font-weight: bold;
                        color: #FFFFFF;
                        line-height: 24px;
                        text-shadow: 0px 0px 10px rgba(0,24,72,0.75);
                    }
                }
                .content_left_item2_content {
                    width: 100%;
                    height: 361px;
                    padding: 20px;
                    box-sizing: border-box;
                    background: linear-gradient(180deg, rgba(52,88,159,0) 0%, rgba(0,86,255,0.4) 100%);
                    .item2_content_head {
                        width: 100%;
                        height: 36px;
                        display: flex;
                        align-items: center;
                        background: rgba(52,88,159,0.5);
                        .item2_content_head_item {
                            flex: 1;
                            height: 100%;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            font-size: 13px;
                            font-family: PingFangSC-Medium, PingFang SC;
                            font-weight: 500;
                            color: #01D9FE;
                            &:first-child {
                                flex: 1.5;
                            }
                        }
                    }
                    .main_container {
                        width: 100%;
                        height: calc(100% - 36px);
                        .scroll_container {
                            width: 100%;
                            height: 100%;
                            overflow: hidden;
                            .scroll_item_bg1 {
                                background: rgba(52,88,159,0.2);
                            }
                            .scroll_item_bg2 {
                                background: rgba(52,88,159,0.5);
                            }
                            .scroll_item {
                                width: 100%;
                                height: 36px;
                                display: flex;
                                align-items: center;
 
                            }
                        }
                    }
                }
            }
        }
        .content_center {
            flex: 2;
            margin: 0 40px;
            background-color: aquamarine;
        }
        .content_right {
            flex: 1;
            background-color: aquamarine;
        }
    }
</style>