Showing
1 changed file
with
29 additions
and
1 deletions
| ... | @@ -847,12 +847,40 @@ const endAction = (item) => { | ... | @@ -847,12 +847,40 @@ const endAction = (item) => { |
| 847 | } | 847 | } |
| 848 | 848 | ||
| 849 | /** | 849 | /** |
| 850 | - * 新增记录 | 850 | + * 添加学习记录 |
| 851 | * @param paramsObj | 851 | * @param paramsObj |
| 852 | */ | 852 | */ |
| 853 | const addRecord = async (paramsObj) => { | 853 | const addRecord = async (paramsObj) => { |
| 854 | await addStudyRecordAPI(paramsObj); | 854 | await addStudyRecordAPI(paramsObj); |
| 855 | } | 855 | } |
| 856 | + | ||
| 857 | +// 监听目录弹框显示状态,当打开时滚动到当前课程位置 | ||
| 858 | +watch(showCatalog, (newVal) => { | ||
| 859 | + if (newVal) { | ||
| 860 | + // 等待DOM更新后执行滚动 | ||
| 861 | + nextTick(() => { | ||
| 862 | + // 查找当前选中的课程元素 | ||
| 863 | + const selectedLesson = document.querySelector('.text-green-600')?.closest('.bg-white'); | ||
| 864 | + if (selectedLesson) { | ||
| 865 | + // 获取滚动容器 | ||
| 866 | + const scrollContainer = document.querySelector('.van-popup .overflow-y-auto'); | ||
| 867 | + if (scrollContainer) { | ||
| 868 | + // 计算滚动位置,使选中元素位于容器中间 | ||
| 869 | + const containerHeight = scrollContainer.clientHeight; | ||
| 870 | + const lessonTop = selectedLesson.offsetTop; | ||
| 871 | + const lessonHeight = selectedLesson.clientHeight; | ||
| 872 | + const scrollTop = lessonTop - (containerHeight / 2) + (lessonHeight / 2); | ||
| 873 | + | ||
| 874 | + // 平滑滚动到指定位置 | ||
| 875 | + scrollContainer.scrollTo({ | ||
| 876 | + top: scrollTop, | ||
| 877 | + behavior: 'smooth' | ||
| 878 | + }); | ||
| 879 | + } | ||
| 880 | + } | ||
| 881 | + }); | ||
| 882 | + } | ||
| 883 | +}); | ||
| 856 | </script> | 884 | </script> |
| 857 | 885 | ||
| 858 | <style lang="less" scoped> | 886 | <style lang="less" scoped> | ... | ... |
-
Please register or login to post a comment