提交 06968f64 authored 作者: 龙菲's avatar 龙菲

fix: 修复从详情页直接进无法查看书签的问题

上级 e0813d99
......@@ -25,3 +25,16 @@ export function getDocumentDetail(id) {
method: 'get'
});
}
/**
* 获取文档书签
* @param {string} id - 文档ID
* @returns {Promise} 返回文档详情数据
*/
export function getDocumentBookmarks(id) {
return request({
url: `/micro-mgz/${id}/bookmarks`,
method: 'get'
});
}
......@@ -10,7 +10,7 @@
</div>
</template>
<script setup>
import { getDocumentDetail } from "@/api";
import { getDocumentDetail, getDocumentBookmarks } from "@/api";
import BookReader from "@/components/BookReader/index.vue";
const route = useRoute();
const router = useRouter();
......@@ -42,11 +42,30 @@ function goBack() {
// router.go(-1);
router.push("/");
}
async function fetchBookmarks(id) {
try {
const res = await getDocumentBookmarks(id);
if (res.status == "success") {
localStorage.setItem(`bookmarks-${id}`, JSON.stringify(res.bookmarks));
bookmarks.value = res.bookmarks;
}
} catch (error) {
console.log(error);
} finally {
}
}
onMounted(() => {
const { id } = route.params;
bookmarks.value = JSON.parse(localStorage.getItem(`bookmarks-${id}`));
title.value = route.query.title;
loadData(id);
const bookmarksData = JSON.parse(localStorage.getItem(`bookmarks-${id}`));
if (bookmarksData) {
bookmarks.value = bookmarksData;
} else {
fetchBookmarks(id);
}
});
</script>
<style lang="scss" scoped>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论