diff --git a/pages/auth.vue b/pages/auth.vue index 3c66ef6..a242459 100644 --- a/pages/auth.vue +++ b/pages/auth.vue @@ -15,7 +15,7 @@ export default { if (!code) { this.notice = '
非法访问,缺少授权参数"code"。
返回首页'; this.$finishLoad(); return }
- const { data } = await this.$axios.post('http://127.0.0.1:65534/visitor/user/auth', {
+ const { data } = await this.$axios.post('/visitor/user/auth', {
type: 'github',
code
})
diff --git a/pages/post/_id.vue b/pages/post/_id.vue
index 5082d5a..6d1ab1d 100644
--- a/pages/post/_id.vue
+++ b/pages/post/_id.vue
@@ -55,7 +55,7 @@
img(:src="visitorInfo.avatarURL")
.comment-nickname {{ visitorInfo.nickname }}
.comment-logout(@click="commentLogout") 退出
- .comment-btn(@click="commentCommit") 发布
+ .comment-btn(@click="commentCommit('editor')") 发布
.comment-reply-commit(id="comment-reply-commit", v-show="replyID")
.login(v-show="!visitorToken", @click="login")
img(src="https://cdn.wyr.me/imgs/GitHub-Login.png")
@@ -67,7 +67,7 @@
img(:src="visitorInfo.avatarURL")
.comment-nickname {{ visitorInfo.nickname }}
.comment-logout(@click="commentLogout") 退出
- .comment-btn(@click="commentCommit") 发布
+ .comment-btn(@click="commentCommit('editor-reply')") 发布
ins.adsbygoogle(style="display:block; text-align:center; margin-top:20px;", data-ad-layout="in-article", data-ad-format="fluid", data-ad-client="ca-pub-2143583075951360", data-ad-slot="4741804954")
.articelRightToc(v-show="articels.post_toc_show && showRightToc", @click="articelRightTocClick")
.articelTitle 目录
@@ -103,6 +103,7 @@ export default {
const commentAmount = tmp.result.amount || 0
return {
+ postID: route.params.id,
articels: result,
comments,
commentsMap: new Map(),
@@ -256,15 +257,7 @@ export default {
})
}
- const comments = this.comments
- for (let i = 0; i < comments.length; i++) {
- this.commentsMap.set(comments[i].comment_ID, comments[i])
- if (comments[i].children) {
- for (let j = 0; j < comments[i].children.length; j++) {
- this.commentsMap.set(comments[i].children[j].comment_ID, comments[i].children[j])
- }
- }
- }
+ this.setCommentMap()
}
this.$finishLoad()
@@ -465,8 +458,31 @@ export default {
})
}
},
- commentCommit () {
+ async commentCommit (type) {
+ const parentID = this.replyID || 0
+ const lastID = this.replyLastID || 0
+ const postID = this.postID
+ if (!postID) {
+ alert('致命错误')
+ return
+ }
+ const { data } = await this.$axios.post('/comments/commit', {
+ postID,
+ lastID,
+ parentID,
+ content: type === 'editor-reply' ? window.editorReplyObj.getValue() : window.editorObj.getValue()
+ })
+
+ if (data.status === 1) {
+ // 获取评论
+ const tmp = await this.$axios.get(`/public/comments/post?ID=${postID}`)
+ const comments = tmp.result.list || []
+ const commentAmount = tmp.result.amount || 0
+ this.comments = comments
+ this.commentAmount = commentAmount
+ this.setCommentMap()
+ }
},
commentLogout () {
window.localStorage.removeItem('visitorToken')
@@ -474,6 +490,17 @@ export default {
},
login () {
window.open('https://github.com/login/oauth/authorize?client_id=ce1673a37333e47e482d&redirect_uri=https://www.wyr.me/auth', 'Github授权', 'scrollbars=yes,resizable=yes,status=no,location=yes,toolbar=no,menubar=no,width=800,height=600,left=0,top=0')
+ },
+ setCommentMap () {
+ const comments = this.comments
+ for (let i = 0; i < comments.length; i++) {
+ this.commentsMap.set(comments[i].comment_ID, comments[i])
+ if (comments[i].children) {
+ for (let j = 0; j < comments[i].children.length; j++) {
+ this.commentsMap.set(comments[i].children[j].comment_ID, comments[i].children[j])
+ }
+ }
+ }
}
},
head () {