feat: 增加小说目录页

This commit is contained in:
xiongxiaoyang 2022-05-16 07:42:24 +08:00
parent 6ae9d8e239
commit 3681261de8
5 changed files with 135 additions and 5 deletions

View File

@ -16,6 +16,10 @@ export function listRecBooks(params) {
return request.get('/book/recList', { params }); return request.get('/book/recList', { params });
} }
export function listChapters(params) {
return request.get('/book/chapterList', { params });
}
export function getBookContent(chapterId) { export function getBookContent(chapterId) {
return request.get(`/book/content/${chapterId}`); return request.get(`/book/content/${chapterId}`);
} }

View File

@ -25,6 +25,12 @@ const router = createRouter({
name: 'book', name: 'book',
component: () => import('@/views/Book') component: () => import('@/views/Book')
},
{
path: '/chapterList/:bookId',
name: 'chapterList',
component: () => import('@/views/BookChapterList')
}, },
{ {
path: '/book/:id/:chapterId', path: '/book/:id/:chapterId',

View File

@ -84,7 +84,7 @@
>({{ chapterAbout.chapterTotal }})</span >({{ chapterAbout.chapterTotal }})</span
> >
</div> </div>
<a class="fr" href="/book/indexList-1431636283466297344.html" <a class="fr" @click="chapterList(book.id)" href="javascript:void(0)"
>全部目录</a >全部目录</a
> >
</div> </div>
@ -316,6 +316,10 @@ export default {
loadLastChapterAbout(bookId) loadLastChapterAbout(bookId)
}; };
const chapterList = (bookId) => {
router.push({ path: `/chapterList/${bookId}` });
};
const addBookVisit = async (bookId) => { const addBookVisit = async (bookId) => {
addVisitCount({bookId: bookId}) addVisitCount({bookId: bookId})
} }
@ -326,6 +330,7 @@ export default {
no_comment, no_comment,
bookContent, bookContent,
bookDetail, bookDetail,
chapterList
}; };
}, },
mounted() { mounted() {

View File

@ -0,0 +1,107 @@
<template>
<Header />
<div class="main box_center cf">
<div class="nav_sub">
<a href="/">小说精品屋</a>&gt;<a href="/book/bookclass.html?c=3"
>{{book.categoryName}}</a
>&gt;<a @click="bookDetail(book.id)" href="javascript:void(0)">{{book.bookName}}</a>&gt;<span
> 作品目录</span
>
</div>
<div class="channelWrap channelChapterlist cf mb50">
<div class="bookMain">
<div class="bookCover cf">
<div class="book_info1">
<div class="tit">
<h1>{{book.bookName}}</h1>
<!--<i class="vip_b">VIP</i>-->
</div>
<ul class="list">
<li>
<span>作者<a href="javascript:void(0)">{{book.authorName}}</a></span>
<span
>类别<a href="/book/bookclass.html?c=3">{{book.categoryName}}</a></span
>
<span>状态<em class="black3">{{
book.bookStatus == 0 ? "连载中" : "已完结"
}}</em></span>
<span>总点击<em class="black3" id="cTotal">{{book.visitCount}}</em></span>
<span>总字数<em class="black3">{{book.wordCount}}</em></span>
</li>
</ul>
</div>
</div>
<div class="dirWrap cf">
<h3>正文({{chapterList.length}})</h3>
<div class="dirList">
<ul v-for="(item,index) in chapterList" :key="index">
<li>
<a @click="bookContent(book.id,item.id)" href="javascript:void(0)">
<span>{{item.chapterName}}</span><i class="red"> [免费]</i>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<Footer />
</div>
</template>
<script>
import "@/assets/styles/book.css";
import { reactive, toRefs, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { getBookById, listChapters } from "@/api/book";
import Header from "@/components/common/Header";
import Footer from "@/components/common/Footer";
export default {
name: "chapterList",
components: {
Header,
Footer,
},
setup() {
const route = useRoute();
const router = useRouter();
const state = reactive({
book: {},
chapterList: [],
imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL,
});
onMounted(() => {
const bookId = route.params.bookId;
loadBook(bookId);
loadChapterList(bookId);
});
const loadBook = async (bookId) => {
const { data } = await getBookById(bookId);
state.book = data;
};
const loadChapterList = async (bookId) => {
const { data } = await listChapters({ bookId: bookId });
state.chapterList = data;
};
const bookContent = (bookId, chapterId) => {
router.push({ path: `/book/${bookId}/${chapterId}` });
};
const bookDetail = (bookId) => {
router.push({ path: `/book/${bookId}` });
};
return {
...toRefs(state),
bookContent,
bookDetail,
};
},
};
</script>

View File

@ -13,8 +13,8 @@
<ul> <ul>
<li> <li>
<a <a
class="ico_catalog" class="ico_catalog" @click="chapterList(data.chapterInfo.bookId)"
href="/book/indexList-1334332598936240128.html" href="javascript:void(0)"
title="目录" title="目录"
> >
<b>目录</b></a <b>目录</b></a
@ -24,7 +24,8 @@
<li> <li>
<a <a
class="ico_page" class="ico_page"
href="/book/1334332598936240128.html" @click="bookDetail(data.chapterInfo.bookId)"
href="javascript:void(0)"
title="返回书页" title="返回书页"
><b>书页</b></a ><b>书页</b></a
> >
@ -145,7 +146,8 @@
<a <a
style="background-color: rgba(255, 255, 255, 0.45)" style="background-color: rgba(255, 255, 255, 0.45)"
class="dir" class="dir"
href="/book/indexList-1334332598936240128.html" @click="chapterList(data.chapterInfo.bookId)"
href="javascript:void(0)"
>目录</a >目录</a
> >
<a <a
@ -303,6 +305,11 @@ export default {
router.push({ path: `/book/${bookId}` }); router.push({ path: `/book/${bookId}` });
}; };
const chapterList = (bookId) => {
router.push({ path: `/chapterList/${bookId}` });
};
const preChapter = async (bookId) => { const preChapter = async (bookId) => {
const { data } = await getPreChapterId(route.params.chapterId); const { data } = await getPreChapterId(route.params.chapterId);
if (data) { if (data) {
@ -331,6 +338,7 @@ export default {
return { return {
...toRefs(state), ...toRefs(state),
bookDetail, bookDetail,
chapterList,
preChapter, preChapter,
nextChapter nextChapter
}; };