|
|
@ -39,6 +39,7 @@ const tabs = computed(() => [ |
|
|
|
|
|
|
|
// 修改 setActiveTab 方法,添加一个可选参数 forceAIchat |
|
|
|
const setActiveTab = (tab, index, forceAIchat = false) => { |
|
|
|
isScrolling.value = false; //回复滚动到底部方法 |
|
|
|
isAnnouncementVisible.value = false; |
|
|
|
if (forceAIchat && activeTab.value !== "AIchat") { |
|
|
|
activeTab.value = "AIchat"; |
|
|
@ -51,6 +52,7 @@ const setActiveTab = (tab, index, forceAIchat = false) => { |
|
|
|
sessionStorage.setItem("activeTabAI", tab); |
|
|
|
sessionStorage.setItem("activeIndexAI", index.toString()); |
|
|
|
} |
|
|
|
console.log(tab, index, "tab, index"); |
|
|
|
setHeight(document.getElementById("testId")); // 给父组件发送窗口高度 |
|
|
|
}; |
|
|
|
|
|
|
@ -68,12 +70,13 @@ const ensureAIchat = () => { |
|
|
|
}; |
|
|
|
|
|
|
|
// 获取次数 |
|
|
|
const UserCount = ref(0); |
|
|
|
const getUserCount = async () => { |
|
|
|
const result = await getUserCountAPI({ token: localStorage.getItem('localToken') }); |
|
|
|
UserCount.value = result.data.hasCount; |
|
|
|
// const UserCount = ref(0); |
|
|
|
// const getUserCount = async () => { |
|
|
|
// const result = await getUserCountAPI({ token: localStorage.getItem('localToken') }); |
|
|
|
// UserCount.value = result.data.hasCount; |
|
|
|
// }; |
|
|
|
const UserCount = computed(() => chatStore.UserCount) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const getCount = () => { |
|
|
|
console.log('点击了获取次数的按钮') |
|
|
@ -98,6 +101,7 @@ const updateMessage = (title) => { |
|
|
|
// console.log("updateMessage 的值:", title); |
|
|
|
}; |
|
|
|
const sendMessage = async () => { |
|
|
|
isScrolling.value = false; |
|
|
|
// 调用 ensureAIchat 确保跳转到 AIchat 页面 |
|
|
|
ensureAIchat(); |
|
|
|
|
|
|
@ -132,8 +136,10 @@ const isAnnouncementVisible = ref(false); |
|
|
|
|
|
|
|
const showAnnouncement = () => { |
|
|
|
console.log("打开公告"); |
|
|
|
isScrolling.value = false; //回复滚动到底部方法 |
|
|
|
setActiveTab('', -1); // 清空当前选中状态 |
|
|
|
|
|
|
|
isAnnouncementVisible.value = true; // 显示公告页面 |
|
|
|
activeTab.value = 'Announcement`' |
|
|
|
}; |
|
|
|
|
|
|
|
// 点击剩余次数会弹出的弹窗 |
|
|
@ -147,48 +153,39 @@ const showCount = () => { |
|
|
|
console.log("dialogVisible 的值:", dialogVisible.value); // 添加日志确认 |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 保证发送消息时,滚动屏在底部 |
|
|
|
const chatStore = useChatStore() |
|
|
|
const tabContent = ref(null); |
|
|
|
const isScrolling = ref(false); //判断用户是否在滚动 |
|
|
|
|
|
|
|
const smoothScrollToBottom = async () => { |
|
|
|
await nextTick(); |
|
|
|
console.log('调用滚动到底部的方法') |
|
|
|
// await nextTick(); |
|
|
|
const container = tabContent.value; |
|
|
|
console.log(container, 'container') |
|
|
|
console.log(isScrolling.value, 'isScrolling.value') |
|
|
|
if (!container) return; |
|
|
|
if (!isScrolling.value) |
|
|
|
container.scrollTop = container.scrollHeight - container.offsetHeight; |
|
|
|
|
|
|
|
requestAnimationFrame(() => { |
|
|
|
await nextTick(); // 确保在DOM更新后执行 |
|
|
|
|
|
|
|
if (!isScrolling.value) { |
|
|
|
container.scrollTop = container.scrollHeight - container.offsetHeight; |
|
|
|
}); |
|
|
|
// container.scrollTop = container.scrollHeight; |
|
|
|
// container.scrollTop = container.offsetHeight; |
|
|
|
// container.scrollTop = container.scrollHeight + container.offsetHeight; |
|
|
|
console.log(container.scrollHeight, container.offsetHeight,container.scrollHeight-container.offsetHeight, container.scrollTop, "总长度", "可视长度", "位置") |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const throttledSmoothScrollToBottom = _.throttle(smoothScrollToBottom, 500, { trailing: false }); |
|
|
|
|
|
|
|
const handleScroll = function () { |
|
|
|
const scrollContainer = tabContent.value |
|
|
|
const scrollTop = scrollContainer.scrollTop |
|
|
|
const scrollHeight = scrollContainer.scrollHeight |
|
|
|
const offsetHeight = scrollContainer.offsetHeight |
|
|
|
// console.log(scrollTop, scrollHeight, offsetHeight, "scrollTop, scrollHeight, offsetHeight"); |
|
|
|
if (scrollTop + offsetHeight < scrollHeight) { |
|
|
|
// 用户开始滚动并在最底部之上,取消保持在最底部的效果 |
|
|
|
isScrolling.value = true |
|
|
|
} else { |
|
|
|
// 用户停止滚动并滚动到最底部,开启保持到最底部的效果 |
|
|
|
isScrolling.value = false |
|
|
|
} |
|
|
|
// console.log(isScrolling.value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
watch( |
|
|
|
() => chatStore.messages, |
|
|
|
() => { |
|
|
|
console.log('messages变化了') |
|
|
|
throttledSmoothScrollToBottom(); |
|
|
|
// setTimeout(throttledSmoothScrollToBottom, 100); |
|
|
|
}, |
|
|
|
{ deep: true, immediate: true } |
|
|
|
); |
|
|
@ -196,9 +193,15 @@ watch( |
|
|
|
|
|
|
|
watch( |
|
|
|
activeTab, |
|
|
|
async (newVal) => { |
|
|
|
async () => { |
|
|
|
console.log('activeTab变化了', activeTab.value) |
|
|
|
isScrolling.value = false; //回复滚动到底部方法 |
|
|
|
await nextTick(); // 等待DOM更新 |
|
|
|
throttledSmoothScrollToBottom(); |
|
|
|
}); |
|
|
|
// setTimeout(throttledSmoothScrollToBottom, 100); |
|
|
|
}, |
|
|
|
{ deep: true, immediate: true } |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 在setTimeout中延迟执行 |
|
|
@ -234,12 +237,60 @@ const fnGetToken = () => { |
|
|
|
useAppBridge().packageFun('JWwebReady', () => { }, 5, {}) |
|
|
|
} |
|
|
|
|
|
|
|
// const tabContainer = tabContent.value |
|
|
|
// let befortop = 0 |
|
|
|
// tabContainer.addEventListener('scroll', () => { |
|
|
|
// const aftertop = tabContainer.scrollTop |
|
|
|
// if (aftertop - befortop > 0) { |
|
|
|
// console.log('向下滚动') |
|
|
|
// isScrolling.value = true |
|
|
|
// } else { |
|
|
|
// console.log('向上滚动') |
|
|
|
// isScrolling.value = false |
|
|
|
// } |
|
|
|
// befortop = aftertop |
|
|
|
// }) |
|
|
|
|
|
|
|
const heightListener = () => { |
|
|
|
const tabContainer = tabContent.value; |
|
|
|
let befortop = 0; |
|
|
|
|
|
|
|
const scrollHandler = () => { |
|
|
|
const aftertop = tabContainer.scrollTop; |
|
|
|
|
|
|
|
// 新增底部判断逻辑 |
|
|
|
const isBottom = aftertop + tabContainer.offsetHeight + 50 >= tabContainer.scrollHeight; |
|
|
|
|
|
|
|
if (activeTab.value === 'AIchat') { |
|
|
|
if (aftertop - befortop > 0) { |
|
|
|
console.log('向下滚动'); |
|
|
|
isScrolling.value = true; |
|
|
|
} else { |
|
|
|
console.log('向上滚动'); |
|
|
|
isScrolling.value = true; |
|
|
|
} |
|
|
|
|
|
|
|
// 添加底部状态检测 |
|
|
|
if (isBottom) { |
|
|
|
console.log('滚动到底部'); |
|
|
|
isScrolling.value = false; |
|
|
|
} |
|
|
|
} |
|
|
|
befortop = aftertop; |
|
|
|
}; |
|
|
|
|
|
|
|
console.log(isScrolling.value, 'isScrolling.value') |
|
|
|
|
|
|
|
tabContainer.addEventListener('scroll', scrollHandler); |
|
|
|
}; |
|
|
|
|
|
|
|
const throttledHeightListener = _.throttle(heightListener, 500, { trailing: false }); |
|
|
|
|
|
|
|
onMounted(async () => { |
|
|
|
setHeight(document.getElementById("testId")); // 给父组件发送窗口高度 |
|
|
|
getUserCount(); |
|
|
|
await chatStore.getUserCount(); |
|
|
|
throttledSmoothScrollToBottom(); |
|
|
|
// 监听滚动事件,判断用户滚动状态 |
|
|
|
tabContent.value.addEventListener('scroll', handleScroll) |
|
|
|
throttledHeightListener(); |
|
|
|
|
|
|
|
}) |
|
|
|
</script> |
|
|
@ -270,7 +321,7 @@ onMounted(async () => { |
|
|
|
<section class="tab-section"> |
|
|
|
<div class="tab-container"> |
|
|
|
<div v-for="(tab, index) in tabs" :key="tab.name" @click="setActiveTab(tab.name, index)" |
|
|
|
:class="['tab-item', { active: activeIndex === index }]"> |
|
|
|
:class="['tab-item', { active: activeIndex === index && !isAnnouncementVisible }]"> |
|
|
|
<span>{{ tab.label }}</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -398,6 +449,7 @@ onMounted(async () => { |
|
|
|
background-repeat: no-repeat; |
|
|
|
background-position: center; |
|
|
|
display: flex; |
|
|
|
overflow: auto; |
|
|
|
} |
|
|
|
|
|
|
|
.homepage .el-container { |
|
|
@ -405,7 +457,7 @@ onMounted(async () => { |
|
|
|
flex-direction: column; |
|
|
|
/* 明确纵向排列 */ |
|
|
|
display: flex; |
|
|
|
overflow: hidden; |
|
|
|
overflow: auto; |
|
|
|
} |
|
|
|
|
|
|
|
.el-container .el-header { |
|
|
@ -469,11 +521,19 @@ onMounted(async () => { |
|
|
|
|
|
|
|
.homepage-right-group .announcement-btn { |
|
|
|
cursor: pointer; |
|
|
|
transition: transform 0.2s; |
|
|
|
transition: transform 0.3s; |
|
|
|
} |
|
|
|
|
|
|
|
/* @keyframes tilt { |
|
|
|
0% { transform: rotate(0deg); } |
|
|
|
50% { transform: rotate(10deg); } |
|
|
|
100% { transform: rotate(-10deg); } |
|
|
|
130% { transform: rotate(0deg); } |
|
|
|
} */ |
|
|
|
|
|
|
|
.homepage-right-group .announcement-btn:hover { |
|
|
|
transform: scale(1.05); |
|
|
|
transform: scale(1.3); |
|
|
|
/* animation: tilt 1s ease-in-out; */ |
|
|
|
} |
|
|
|
|
|
|
|
.homepage-body { |
|
|
|