web: 优化目录跳转

This commit is contained in:
Xwite 2023-05-11 13:20:19 +08:00
parent b9600aac5a
commit a5bd387145
2 changed files with 15 additions and 19 deletions

View File

@ -1,5 +1,8 @@
<template>
<div class="cata-wrapper" :style="popupTheme">
<div
:class="{ 'cata-wrapper': true, visible: popCataVisible }"
:style="popupTheme"
>
<div class="title">目录</div>
<virtual-list
style="height: 300px; overflow: auto"
@ -53,23 +56,13 @@ const virtualListdata = computed(() => {
while (i < length) {
virtualListDataSource[i] = {
index: i,
catas: catalogValue.slice(2 * i, 2 * i + 2)
}
catas: catalogValue.slice(2 * i, 2 * i + 2),
};
i++;
}
return virtualListDataSource;
});
const virtualListRef = ref();
const virtualListIndex = computed(() => {
if (miniInterface.value) return index.value;
return Math.floor(index.value / 2);
});
watch(popCataVisible, (visible) => {
if (visible) return; // sizes Map0
nextTick(() => virtualListRef.value.scrollToIndex(virtualListIndex.value));
});
const emit = defineEmits(["getContent"]);
const gotoChapter = (note) => {
index.value = catalog.value.indexOf(note);
@ -77,11 +70,16 @@ const gotoChapter = (note) => {
store.setContentLoading(true);
emit("getContent", index.value);
};
const virtualListRef = ref();
const virtualListIndex = computed(() => {
if (miniInterface.value) return index.value;
return Math.floor(index.value / 2);
});
onUpdated(() => {
// catalogdomResizeObserversizes Map
store.popCataVisible = false;
// popCataVisible watcher
// virtualListRef.value.scrollToIndex(index.value)
// domResizeObserversizes Map
virtualListRef.value.scrollToIndex(virtualListIndex.value);
});
</script>

View File

@ -520,8 +520,6 @@ onMounted(() => {
let data = res.data.data;
store.setCatalog(data);
store.setReadingBook(book);
// 使便
store.popCataVisible = true;
getContent(chapterIndex, true, chapterPos);
window.addEventListener("keyup", handleKeyPress);