更新代码
This commit is contained in:
@ -66,6 +66,9 @@ const getList = (type) => {
|
||||
let arr = Array.isArray(res?.records) ? res.records : [];
|
||||
personList.value = pageNum.value == 1 ? arr : personList.value.concat(arr);
|
||||
total.value = res?.total || 0;
|
||||
if(pageNum.value == 1 && total.value > 3 ){
|
||||
startAutoScroll();
|
||||
}
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
loadingMore.value = false;
|
||||
@ -94,12 +97,11 @@ const autoScroll = () => {
|
||||
|
||||
// 开始自动滚动
|
||||
const startAutoScroll = () => {
|
||||
if(total.value < 3) return;
|
||||
if (isAutoScrolling.value || !carouselList.value) return;
|
||||
isAutoScrolling.value = true;
|
||||
// 清除可能存在的定时器
|
||||
if (scrollTimer) {
|
||||
clearInterval(scrollTimer);
|
||||
}
|
||||
if (scrollTimer) clearInterval(scrollTimer);
|
||||
// 设置新的定时器,控制滚动速度
|
||||
scrollTimer = setInterval(autoScroll, 30);
|
||||
};
|
||||
@ -118,29 +120,14 @@ const chooseItem = (item) => {
|
||||
stopAutoScroll(); // 点击时停止自动滚动
|
||||
const path = props.bglx === '01' ? '/tacticalResearch' : '/strategicResearch'
|
||||
router.push({
|
||||
// path: '/forumPost',
|
||||
path: path,
|
||||
query: { id: item.id }
|
||||
})
|
||||
};
|
||||
|
||||
// 添加跳转
|
||||
const chooseForumPost = () => {
|
||||
stopAutoScroll(); // 点击时停止自动滚动
|
||||
const path = props.bglx === '01' ? '/tacticalResearch' : '/strategicResearch'
|
||||
|
||||
router.push({ path: path })
|
||||
};
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
getList();
|
||||
// 数据加载完成后启动自动滚动
|
||||
setTimeout(() => {
|
||||
if (personList.value.length > 0) {
|
||||
startAutoScroll();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// 组件卸载前清除定时器
|
||||
|
||||
Reference in New Issue
Block a user