From b0c6b819514c0167f65bd1d166018dd332b802cc Mon Sep 17 00:00:00 2001 From: yi-ge Date: Fri, 17 Jul 2020 14:00:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/post/_id.vue | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/pages/post/_id.vue b/pages/post/_id.vue index 13d86df..a743960 100644 --- a/pages/post/_id.vue +++ b/pages/post/_id.vue @@ -30,6 +30,7 @@ img(:src="item.comment_author_avatar_url ? item.comment_author_avatar_url : 'https://picsum.photos/100/100/?blur=' + item.user_id") .comment-area .comment-author {{ item.comment_author }} + span(class="comment-status", v-if="item.comment_approved === '0'")   此内容正在审核中... .comment-content(v-html="item.comment_content_html") .comment-info {{ item.comment_date }} span.reply(@click="reply(item.comment_ID, null, true)" v-if="replyLastID === null && item.comment_ID === replyID") 取消回复 @@ -39,6 +40,7 @@ img(:src="i.comment_author_avatar_url ? i.comment_author_avatar_url : 'https://picsum.photos/100/100/?blur=' + i.user_id") .comment-area .comment-author {{ i.comment_author }} + span(class="comment-status", v-if="i.comment_approved === '0'")   此内容正在审核中... .comment-content(v-html="i.comment_content_html") .comment-info {{ i.comment_date }} span.reply(@click="reply(item.comment_ID, i.comment_ID)" v-if="replyLastID !== i.comment_ID") 回复 @@ -123,13 +125,15 @@ export default { }, mounted () { // 创建编辑器 - this.visitorToken = window.localStorage.visitorToken - if (this.visitorToken && window.localStorage.visitorInfo) { - try { - this.visitorInfo = JSON.parse(window.localStorage.visitorInfo) - } catch (_) { } - } if (process.client) { + this.visitorToken = window.localStorage.visitorToken + if (this.visitorToken && window.localStorage.visitorInfo) { + try { + this.visitorInfo = JSON.parse(window.localStorage.visitorInfo) + this.getCommentWithVisitorInfo(this.postID) + } catch (_) { } + } + window.setAuthToken = (visitorToken, visitorInfo) => { window.localStorage.visitorToken = visitorToken window.localStorage.visitorInfo = JSON.stringify(visitorInfo) @@ -482,7 +486,7 @@ export default { method: 'post', url: process.env.baseURL + '/comments/commit', headers: { - Authorization: 'Bearer ' + window.localStorage.visitorToken + Authorization: 'Bearer ' + this.visitorToken }, data: { postID, @@ -496,13 +500,7 @@ export default { this.replyID = null this.replyLastID = null window.location.hash = '_' - // 获取评论 - const tmp = await this.$axios.get(process.env.baseURL + `/public/comments/post?ID=${postID}`) - const comments = tmp.data.result.list || [] - const commentAmount = tmp.data.result.amount || 0 - this.comments = comments - this.commentAmount = commentAmount - this.setCommentMap() + this.getCommentWithVisitorInfo(postID) editorObj.setValue('', true) this.$nextTick(() => { editorObj.focus() @@ -510,6 +508,21 @@ export default { }) } }, + async getCommentWithVisitorInfo (postID) { + // 获取评论 + const tmp = await this.$axios({ + method: 'get', + url: process.env.baseURL + `/public/comments/post?ID=${postID}`, + headers: { + Authorization: 'Bearer ' + this.visitorToken + } + }) + const comments = tmp.data.result.list || [] + const commentAmount = tmp.data.result.amount || 0 + this.comments = comments + this.commentAmount = commentAmount + this.setCommentMap() + }, commentLogout () { window.localStorage.removeItem('visitorToken') this.visitorToken = null @@ -693,6 +706,9 @@ export default { img max-width 100% + .comment-status + color #ca7474 + .comment-logout width 51px height 100%