添加评论

This commit is contained in:
yi-ge 2020-07-10 17:49:51 +08:00
parent 0cbd50eeda
commit 80192652ed
6 changed files with 225 additions and 119 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

12
layouts/auth.vue Normal file
View File

@ -0,0 +1,12 @@
<template lang="pug">
.content
#loading.allSpinner
.spinner
.bounce1
.bounce2
.bounce3
.container
.page-container
nuxt
v-dialog
</template>

42
pages/auth.vue Normal file
View File

@ -0,0 +1,42 @@
<template lang="pug">
.auth(v-html="notice")
</template>
<script>
export default {
layout: 'auth',
data () {
return {
notice: 'Loading...'
}
},
async mounted () {
const code = this.$route.query.code
if (!code) { this.notice = '<p style="color: #999">非法访问,缺少授权参数"code"。<p><br><br> <a href="https://www.wyr.me" target="_blank">返回首页<a>' }
const { data } = await this.$axios.post('/visitor/user/auth', {
type: 'github',
code
})
if (data.status !== 1) {
this.notice = '<p style="color: #999">授权失败,请再试一次。<p><br><br> <a href="https://www.wyr.me" target="_blank">返回首页<a>'
}
console.log(data)
this.$finishLoad()
},
methods: {
}
}
</script>
<style lang="stylus" scoped>
.auth
width 100%
height 100%
padding 50px
</style>

View File

@ -45,12 +45,16 @@ div
span.reply(@click="reply(item.comment_ID, i.comment_ID, true)" v-else) 取消回复
p(v-if="!comments.length", style="color: #cecece; text-align: center; margin-top: 40px") 暂无内容
.comment-default-commit
.comment-userinfo
.login(v-if="!visitorToken", @click="login")
img(src="https://cdn.wyr.me/imgs/GitHub-Login.png")
.comment-userinfo(v-else)
.comment-avatar
img(:src="'https://picsum.photos/100/100/?blur=1'")
.comment-nickname 张三
#editor
.comment-default-commit(id="editor-reply", v-show="replyID")
.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")
#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")
@ -94,20 +98,22 @@ export default {
showRightToc: false,
tocIds: result.post_toc_ids,
replyLastID: null,
replyID: null
replyID: null,
visitorToken: null
}
},
mounted () {
//
if (process.client) {
if (!window.editorObj && window.Vditor) {
this.visitorToken = window.localStorage.visitorToken
const upload = {
accept: 'image/*, video/*, audio/*, text/*, application/*, .rar, .zip, .php, .pptx, .ppt, .doc, .docx, .txt, .xls, .xlsx',
url: process.env.baseURL + '/public/file/upload',
url: process.env.baseURL + '/visitor/file/upload',
max: 10485760, // 10 MB
linkToImgUrl: process.env.baseURL + '/public/file/fetch',
linkToImgUrl: process.env.baseURL + '/visitor/file/fetch',
headers: {
Authorization: 'Bearer ' + window.localStorage.token
Authorization: 'Bearer ' + window.localStorage.visitorToken
},
filename: name => encodeURIComponent(name.replace(/[^(a-zA-Z0-9\u4E00-\u9FA5\.)]/g, '') // eslint-disable-line
.replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '') // eslint-disable-line
@ -408,7 +414,7 @@ export default {
})
},
reply (id, replyLastID, cancel) {
const editorReplyObject = document.getElementById('editor-reply')
const editorReplyObject = document.getElementById('comment-reply-commit')
if (cancel) {
this.replyID = null
this.replyLastID = null
@ -429,6 +435,9 @@ export default {
window.location.hash = '#comment_ID_' + id
})
}
},
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')
}
},
head () {
@ -545,7 +554,6 @@ export default {
margin-left 10px
.comment-userinfo
margin-top 90px
margin-left 5px
padding 10px 5px
@ -571,125 +579,164 @@ export default {
margin-top 10px
margin-bottom 10px
#editor-reply
margin 10px 0 10px 50px
.comment-reply-commit
margin 10px 0 10px 50px
.btnFooter
font-size 12px
margin-top 25px
.comment-default-commit
margin-top 125px
i
margin 10px
.comment-default-commit, .comment-reply-commit
position relative
.btnPrevt
float left
.login
position absolute
left 0
top 0
width 100%
height 100%
text-align center
line-height 1
margin auto
z-index 99
cursor pointer
user-select none
.btnNext
float right
img
margin-top 70px
footer .footer
color #cccccc
text-align left
line-height 1.5
margin 20px 0
.login:hover
background-color #fff
.anchor-fix
display block
height 70px /* same height as header */
margin-top -70px /* same height as header */
visibility hidden
.login:before
content ''
position absolute
background rgba(0, 0, 0, 0.1)
top 0
left 0
width 100%
height 100%
filter blur(5px)
z-index 9
.articelRightToc
position fixed
width 15%
top 0
right 0
overflow-y auto
background-color #000
padding 10px
box-shadow 0 0 8px #000
z-index 999999
#editor-reply
margin 0
.articelToc
width 100%
.btnFooter
font-size 12px
margin-top 25px
.articelToc, .articelRightToc
color #bbb
user-select none
i
margin 10px
.articelTitle
font-weight 400
margin-bottom 10px
.btnPrevt
float left
.articelTocList
color #bbb
.btnNext
float right
a
footer .footer
color #cccccc
text-align left
line-height 1.5
margin 20px 0
.anchor-fix
display block
height 70px /* same height as header */
margin-top -70px /* same height as header */
visibility hidden
.articelRightToc
position fixed
width 15%
top 0
right 0
overflow-y auto
background-color #000
padding 10px
box-shadow 0 0 8px #000
z-index 999999
.articelToc
width 100%
.articelToc, .articelRightToc
color #bbb
user-select none
&:visited
.articelTitle
font-weight 400
margin-bottom 10px
.articelTocList
color #bbb
&:hover
color #d01c2e
a
color #bbb
ol.toc, ol.toc ol
counter-reset toc
list-style none
&:visited
color #bbb
ol li
counter-increment toc
&:hover
color #d01c2e
.toc li:before
content counters(toc, '.') ' '
ol.toc, ol.toc ol
counter-reset toc
list-style none
ol
margin-left 20px
ol li
counter-increment toc
li
font-weight 400
.toc li:before
content counters(toc, '.') ' '
ol
margin-left 20px
li
font-weight 300
font-weight 400
.tools
margin-top 80px
margin-bottom 10px
text-align center
user-select none
ol
margin-left 20px
.reward
margin 15px 0
border 1px solid #888
padding 5px 10px
display inline-block
color #888
font-weight 300
cursor pointer
margin auto
li
font-weight 300
.vditor--fullscreen
z-index 9999999
.tools
margin-top 80px
margin-bottom 10px
text-align center
user-select none
@media (max-width: 768px)
.articleDetails
padding 20px
margin-top 50px
.reward
margin 15px 0
border 1px solid #888
padding 5px 10px
display inline-block
color #888
font-weight 300
cursor pointer
margin auto
.articelRightToc
position fixed
width 80%
top 100px
bottom 95px
right 10px
background-color #000
padding 10px
overflow-y auto
box-shadow 0 0 8px #000
.vditor--fullscreen
z-index 9999999
.mobileToc
bottom 48px
@media (max-width: 768px)
.articleDetails
padding 20px
margin-top 50px
.articelRightToc
position fixed
width 80%
top 100px
bottom 95px
right 10px
background-color #000
padding 10px
overflow-y auto
box-shadow 0 0 8px #000
.mobileToc
bottom 48px
</style>

View File

@ -3,7 +3,10 @@ import vditor from 'vditor'
import 'vditor/dist/index.css'
const $tags = document.getElementById('tags')
const floatTop = $tags.offsetTop + $tags.scrollHeight + 30
let floatTop = null
if ($tags) {
floatTop = $tags.offsetTop + $tags.scrollHeight + 30
}
function addEvent (obj, type, fn) {
if (obj.attachEvent) {
@ -24,30 +27,32 @@ window.onload = function () {
// 底部返回顶部按钮
const top = document.getElementById('gotop')
// 滚动一屏幕时显示回到顶部
addEvent(window, 'scroll', function () {
const currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition > window.screen.availHeight ? top.style.display = 'block' : top.style.display = 'none'
if (top) {
// 滚动一屏幕时显示回到顶部
addEvent(window, 'scroll', function () {
const currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition > window.screen.availHeight ? top.style.display = 'block' : top.style.display = 'none'
// 左部导航自动浮动
if (currentPosition > floatTop) {
document.getElementById('navication').style.position = 'fixed'
} else {
document.getElementById('navication').style.position = 'static'
}
})
top.onclick = function () {
var timer = setInterval(function () { // eslint-disable-line
let currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition -= 100
if (currentPosition > 0) {
window.scrollTo(0, currentPosition)
// 左部导航自动浮动
if (currentPosition > floatTop) {
document.getElementById('navication').style.position = 'fixed'
} else {
window.scrollTo(0, 0)
clearInterval(timer)
document.getElementById('navication').style.position = 'static'
}
}, 10)
})
top.onclick = function () {
var timer = setInterval(function () { // eslint-disable-line
let currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition -= 100
if (currentPosition > 0) {
window.scrollTo(0, currentPosition)
} else {
window.scrollTo(0, 0)
clearInterval(timer)
}
}, 10)
}
}
let _hmt = _hmt || [] // eslint-disable-line

BIN
static/.DS_Store vendored Normal file

Binary file not shown.