1、普通自定义表格,自动循环滚动行拼接轮回
<template>
<div class="processing_container">
<div class="header">
<div class="left">
<span>预警消息</span>
<el-badge :value="total" class="item" />
</div>
<div class="right">
<el-button type="text" @click="goProcessing">更多 ></el-button>
</div>
</div>
<div
ref="scrollContainer"
class="main"
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
>
<span v-for="(reminder, index) in reminders" :key="index" class="reminder" @click="detail(reminder)">
<span class="seq">{{ reminder.index }}</span>
<span class="title">{{ reminder.name }}</span>
<span style="color: #cccccc;margin-right: 6.5px">|</span>
<span class="day">{{ reminder.count }}</span>
<span class="info">{{ reminder.content }}</span>
<span class="day">30天内到期</span>
</span>
</div>
</div>
</template>
<script>
import $api from '@/views/platform/api.js'
export default {
data() {
return {
reminders: [],
activeIndex: 0,
tabIndex: 0,
total: null,
timer: null,
scrollingPaused: false
}
},
created() {
$api.getWarningList().then(res => {
this.reminders = res.data.list
this.reminders = this.reminders.concat(res.data.list)
this.total = res.data.total
})
},
mounted() {
this.autoCycle()
},
beforeDestroy() {
clearInterval(this.timer)
},
methods: {
autoCycle() {
const scrollContainer = this.$refs.scrollContainer
this.timer = setInterval(() => {
if (!this.scrollingPaused) {
scrollContainer.scrollTop += 1
if (scrollContainer.clientHeight + scrollContainer.scrollTop >= scrollContainer.scrollHeight) {
scrollContainer.scrollTop = scrollContainer.scrollTop - scrollContainer.scrollHeight / 2
}
}
}, 50)
},
handleMouseEnter() {
this.scrollingPaused = true
},
handleMouseLeave() {
this.scrollingPaused = false
},
goProcessing() {
this.$emit('goProcessing')
},
detail(item) {
const routes = {
'客户合同': '/fms/customer/clientContract',
'供应商资质': '/fms/supplier/cert',
'供应商合同': '/fms/supplier/contract',
'车辆建档': '/system/vehicleManage',
'车辆合同': '/system/vehicleContract',
'场地合同': '/fms/lease/siteContract',
'项目合伙供应商合同': '/fms/partner/supplier/contract',
'项目合伙供应商资质': '/fms/partner/supplier/cert',
'内部借款合同': '/fms/intrabranch/borrowing/contract'
}
const targetPath = routes[item.name]
if (targetPath) {
const today = new Date()
const lastDate = new Date(today)
lastDate.setDate(today.getDate() + 30)
const formattedToday = today.toISOString().split('T')[0]
const formattedLastDate = lastDate.toISOString().split('T')[0]
this.$router.push({ path: targetPath, query: { beginDate: formattedToday, endDate: formattedLastDate }})
}
}
}
}
</script>
<style lang="scss" scoped>
:deep {
.el-button--text {
color: #999999;
}
}
::-webkit-scrollbar {
display: none;
}
.item {
margin-top: 10px;
margin-left: 5px;
}
.reminder {
background: linear-gradient(to right, #FFF3F3, #FFFFFF);
margin-bottom: 9px;
padding: 0 9px;
border-radius: 5px;
display: inline-block;
width: 100%;
cursor: pointer;
height: 36px;
line-height: 32px;
text-shadow: 0 10px 20px rgba(0,0,0,0.05);
text-align: left;
font-style: normal;
}
.title {
display: inline !important;
font-family: PingFangSC, PingFang SC;
font-weight: 600;
font-size: 16px;
color: #303133;
margin-right: 6.5px;
}
.seq {
font-family: HarmonyOS_Sans_Black;
font-size: 16px;
color: #FF5153;
margin-right: 10px;
}
.info {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 13px;
color: #303133;
}
.day {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 13px;
color: #ff6b6d;
}
.processing_container{
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
padding: 30px 0 0 30px;
.main{
overflow: hidden;
position: relative;
}
}
</style>
2、vue element table 自动循环滚动行拼接轮回,鼠标移上去能停止,移除能滚动
<template>
<div
class="scroll-container"
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
>
<el-table
ref="table"
:data="tableData"
stripe
style="width: 100%"
height="402"
>
<el-table-column prop="num" label="序号" width="80" />
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
timer: null,
scrollingPaused: false,
tableData: [
{ num: 1 },
{ num: 2 },
{ num: 3 },
{ num: 4 },
{ num: 5 },
{ num: 6 },
{ num: 7 },
{ num: 8 },
{ num: 9 },
{ num: 10 },
{ num: 1 },
{ num: 2 },
{ num: 3 },
{ num: 4 },
{ num: 5 },
{ num: 6 },
{ num: 7 },
{ num: 8 },
{ num: 9 },
{ num: 10 }
]
}
},
mounted() {
this.autoCycle()
},
beforeDestroy() {
clearInterval(this.timer)
},
methods: {
autoCycle() {
const wrapper = this.$refs.table.bodyWrapper
this.timer = setInterval(() => {
if (!this.scrollingPaused) {
wrapper.scrollTop += 1
if (wrapper.clientHeight + wrapper.scrollTop >= wrapper.scrollHeight) {
wrapper.scrollTop = wrapper.scrollTop - wrapper.scrollHeight / 2
}
}
}, 50)
},
handleMouseEnter() {
this.scrollingPaused = true
},
handleMouseLeave() {
this.scrollingPaused = false
}
}
}
</script>
<style>
.scroll-container {
overflow: hidden;
position: relative;
}
</style>