mirror of
https://github.com/201206030/novel-front-web.git
synced 2025-04-27 07:50:50 +00:00
feat: 评论发表
This commit is contained in:
parent
39090b8810
commit
5833df6a04
@ -52,3 +52,4 @@ export function listUpdateRankBooks() {
|
|||||||
return request.get('/book/update_rank');
|
return request.get('/book/update_rank');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,4 +10,8 @@ export function login(params) {
|
|||||||
|
|
||||||
export function submitFeedBack(params) {
|
export function submitFeedBack(params) {
|
||||||
return request.post('/user/feedback', params);
|
return request.post('/user/feedback', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function comment(params) {
|
||||||
|
return request.post('/user/comment',params);
|
||||||
}
|
}
|
@ -1,4 +1,14 @@
|
|||||||
|
|
||||||
|
export const goToAnchor = (id) => {
|
||||||
|
var anchor = document.getElementById(id);
|
||||||
|
// chrome
|
||||||
|
document.body.scrollTop = anchor.offsetTop;
|
||||||
|
// firefox
|
||||||
|
document.documentElement.scrollTop = anchor.offsetTop;
|
||||||
|
// safari
|
||||||
|
window.pageYOffset = anchor.offsetTop;
|
||||||
|
}
|
||||||
|
|
||||||
export const getQueryObject = (url) => {
|
export const getQueryObject = (url) => {
|
||||||
url = url == null ? window.location.href : url
|
url = url == null ? window.location.href : url
|
||||||
const search = url.substring(url.lastIndexOf('?') + 1)
|
const search = url.substring(url.lastIndexOf('?') + 1)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Header />
|
<Header />
|
||||||
<div class="main box_center cf mb50">
|
<div class="main box_center cf mb50">
|
||||||
|
|
||||||
<div class="channelWrap channelBookInfo cf">
|
<div class="channelWrap channelBookInfo cf">
|
||||||
<div class="bookCover cf">
|
<div class="bookCover cf">
|
||||||
<a class="book_cover">
|
<a class="book_cover">
|
||||||
@ -80,7 +79,10 @@
|
|||||||
>({{ chapterAbout.chapterTotal }}章)</span
|
>({{ chapterAbout.chapterTotal }}章)</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<a class="fr" @click="chapterList(book.id)" href="javascript:void(0)"
|
<a
|
||||||
|
class="fr"
|
||||||
|
@click="chapterList(book.id)"
|
||||||
|
href="javascript:void(0)"
|
||||||
>全部目录</a
|
>全部目录</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@ -125,7 +127,12 @@
|
|||||||
<h3>作品评论区</h3>
|
<h3>作品评论区</h3>
|
||||||
<span id="bookCommentTotal">(0条)</span>
|
<span id="bookCommentTotal">(0条)</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- <a class="fr" href="#txtComment">发表评论</a> -->
|
<a
|
||||||
|
class="fr"
|
||||||
|
@click="goToAnchor('txtComment')"
|
||||||
|
href="javascript:void(0)"
|
||||||
|
>发表评论</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="no_comment" id="noCommentPanel">
|
<div class="no_comment" id="noCommentPanel">
|
||||||
<img :src="no_comment" alt="" />
|
<img :src="no_comment" alt="" />
|
||||||
@ -144,20 +151,19 @@
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
|
||||||
<div class="reply_bar" id="reply_bar">
|
<div class="reply_bar" id="reply_bar">
|
||||||
|
|
||||||
<div class="tit">
|
<div class="tit">
|
||||||
<span class="fl font16">发表评论</span>
|
<span class="fl font16">发表评论</span>
|
||||||
|
|
||||||
<span class="fr black9" style="display: none"
|
<span class="fr black9" style="display: none"
|
||||||
>请先 <a class="orange" href="/user/login.html">登录</a
|
>请先 <a class="orange" href="/user/login.html">登录</a
|
||||||
><em class="ml10 mr10">|</em
|
><em class="ml10 mr10">|</em
|
||||||
><a class="orange" href="/user/register.html">注册</a></span
|
><a class="orange" href="/user/register.html">注册</a></span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
|
v-model="commentContent"
|
||||||
name="txtComment"
|
name="txtComment"
|
||||||
rows="2"
|
rows="2"
|
||||||
cols="20"
|
cols="20"
|
||||||
@ -173,14 +179,12 @@
|
|||||||
><a
|
><a
|
||||||
class="btn_ora"
|
class="btn_ora"
|
||||||
href="javascript:void(0);"
|
href="javascript:void(0);"
|
||||||
onclick="javascript:BookDetail.SaveComment(37,0,$('#txtComment').val());"
|
@click="userComment"
|
||||||
>发表</a
|
>发表</a
|
||||||
></span
|
></span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--作品评论区 end-->
|
<!--作品评论区 end-->
|
||||||
@ -256,12 +260,20 @@
|
|||||||
<script>
|
<script>
|
||||||
import "@/assets/styles/book.css";
|
import "@/assets/styles/book.css";
|
||||||
import { reactive, toRefs, onMounted } from "vue";
|
import { reactive, toRefs, onMounted } from "vue";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
import { useRouter, useRoute } from "vue-router";
|
import { useRouter, useRoute } from "vue-router";
|
||||||
import { getBookById,addVisitCount,getLastChapterAbout,listRecBooks } from "@/api/book";
|
import {
|
||||||
|
getBookById,
|
||||||
|
addVisitCount,
|
||||||
|
getLastChapterAbout,
|
||||||
|
listRecBooks,
|
||||||
|
} from "@/api/book";
|
||||||
|
import { comment } from "@/api/user";
|
||||||
import Header from "@/components/common/Header";
|
import Header from "@/components/common/Header";
|
||||||
import Footer from "@/components/common/Footer";
|
import Footer from "@/components/common/Footer";
|
||||||
import author_head from "@/assets/images/author_head.png";
|
import author_head from "@/assets/images/author_head.png";
|
||||||
import no_comment from "@/assets/images/no_comment.png";
|
import no_comment from "@/assets/images/no_comment.png";
|
||||||
|
import { goToAnchor } from "@/utils";
|
||||||
export default {
|
export default {
|
||||||
name: "book",
|
name: "book",
|
||||||
components: {
|
components: {
|
||||||
@ -275,20 +287,21 @@ export default {
|
|||||||
const state = reactive({
|
const state = reactive({
|
||||||
book: {},
|
book: {},
|
||||||
books: {},
|
books: {},
|
||||||
chapterAbout:{},
|
chapterAbout: {},
|
||||||
|
commentContent: "",
|
||||||
imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL,
|
imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL,
|
||||||
});
|
});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const bookId = route.params.id;
|
const bookId = route.params.id;
|
||||||
loadBook(bookId)
|
loadBook(bookId);
|
||||||
loadRecBooks(bookId)
|
loadRecBooks(bookId);
|
||||||
loadLastChapterAbout(bookId)
|
loadLastChapterAbout(bookId);
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadBook = async (bookId) => {
|
const loadBook = async (bookId) => {
|
||||||
const { data } = await getBookById(bookId);
|
const { data } = await getBookById(bookId);
|
||||||
state.book = data;
|
state.book = data;
|
||||||
addBookVisit(bookId)
|
addBookVisit(bookId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadRecBooks = async (bookId) => {
|
const loadRecBooks = async (bookId) => {
|
||||||
@ -299,7 +312,7 @@ export default {
|
|||||||
const loadLastChapterAbout = async (bookId) => {
|
const loadLastChapterAbout = async (bookId) => {
|
||||||
const { data } = await getLastChapterAbout({ bookId: bookId });
|
const { data } = await getLastChapterAbout({ bookId: bookId });
|
||||||
state.chapterAbout = data;
|
state.chapterAbout = data;
|
||||||
}
|
};
|
||||||
|
|
||||||
const bookContent = (bookId, chapterId) => {
|
const bookContent = (bookId, chapterId) => {
|
||||||
router.push({ path: `/book/${bookId}/${chapterId}` });
|
router.push({ path: `/book/${bookId}/${chapterId}` });
|
||||||
@ -307,9 +320,9 @@ export default {
|
|||||||
|
|
||||||
const bookDetail = (bookId) => {
|
const bookDetail = (bookId) => {
|
||||||
router.push({ path: `/book/${bookId}` });
|
router.push({ path: `/book/${bookId}` });
|
||||||
loadBook(bookId)
|
loadBook(bookId);
|
||||||
loadRecBooks(bookId)
|
loadRecBooks(bookId);
|
||||||
loadLastChapterAbout(bookId)
|
loadLastChapterAbout(bookId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const chapterList = (bookId) => {
|
const chapterList = (bookId) => {
|
||||||
@ -317,8 +330,26 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addBookVisit = async (bookId) => {
|
const addBookVisit = async (bookId) => {
|
||||||
addVisitCount({bookId: bookId})
|
addVisitCount({ bookId: bookId });
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const userComment = async () => {
|
||||||
|
if (!state.commentContent) {
|
||||||
|
ElMessage.error("用户评论不能为空!");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (state.commentContent.length < 10) {
|
||||||
|
ElMessage.error("评论不能少于 10 个字符!");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (state.commentContent.length > 512) {
|
||||||
|
ElMessage.error("评论不能多于 512 个字符!");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await comment({'bookId':state.book.id,"commentContent":state.commentContent});
|
||||||
|
state.commentContent = ""
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
@ -326,7 +357,9 @@ export default {
|
|||||||
no_comment,
|
no_comment,
|
||||||
bookContent,
|
bookContent,
|
||||||
bookDetail,
|
bookDetail,
|
||||||
chapterList
|
chapterList,
|
||||||
|
goToAnchor,
|
||||||
|
userComment,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user