添加评论功能
This commit is contained in:
parent
54a1633884
commit
c618c83f9b
@ -135,15 +135,105 @@ export default {
|
||||
window.localStorage.visitorInfo = JSON.stringify(visitorInfo)
|
||||
this.visitorToken = visitorToken
|
||||
this.visitorInfo = visitorInfo
|
||||
window.editorObj.vditor.options.upload.headers = {
|
||||
Authorization: 'Bearer ' + this.visitorToken
|
||||
}
|
||||
window.editorReplyObj.vditor.options.upload.headers = {
|
||||
Authorization: 'Bearer ' + this.visitorToken
|
||||
}
|
||||
}
|
||||
if (!window.editorObj && window.Vditor) {
|
||||
this.initEditor()
|
||||
}
|
||||
|
||||
this.setCommentMap()
|
||||
}
|
||||
|
||||
this.$finishLoad()
|
||||
|
||||
if (this.articels.post_toc_show) {
|
||||
const tocShow = () => {
|
||||
if (window.addEvent) {
|
||||
window.addEvent(window, 'scroll', () => {
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth
|
||||
if (document.getElementById('articelToc') && !this.isOnScreen(document.getElementById('articelToc'))) {
|
||||
if (windowWidth < 768) {
|
||||
this.showRightToc = false
|
||||
document.getElementById('mobileToc').style.display = 'block'
|
||||
} else {
|
||||
this.showRightToc = true
|
||||
}
|
||||
} else {
|
||||
this.showRightToc = false
|
||||
if (windowWidth < 768) {
|
||||
document.getElementById('mobileToc').style.display = 'none'
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
tocShow()
|
||||
}, 50)
|
||||
}
|
||||
}
|
||||
tocShow()
|
||||
|
||||
const tocIdsTop = []
|
||||
const tocIdsTopMap = new Map()
|
||||
for (const n in this.tocIds) {
|
||||
const tTop = document.getElementById(this.tocIds[n]).offsetTop
|
||||
tocIdsTop.push(tTop)
|
||||
tocIdsTopMap.set(tTop, '#' + this.tocIds[n])
|
||||
}
|
||||
|
||||
const findInIds = (arr, num) => { for (let x = 0; x < arr.length; x++) { if (arr[x] > num) { return x - 1 } } }
|
||||
|
||||
let debounce = null
|
||||
let lastIdInx = null
|
||||
|
||||
const scrollToc = () => {
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth
|
||||
if (windowWidth < 768) { scrollTop = scrollTop * 2.7 + 175 }
|
||||
const tocIdsInx = findInIds(tocIdsTop, scrollTop + 130)
|
||||
if (tocIdsInx !== -1 && lastIdInx !== tocIdsInx && document.getElementsByClassName('articelRightToc')[0]) {
|
||||
const tocAList = document.getElementsByClassName('articelRightToc')[0].getElementsByTagName('a')
|
||||
const nowId = tocIdsTopMap.get(tocIdsTop[tocIdsInx])
|
||||
for (const i in tocAList) {
|
||||
if (tocAList[i] && tocAList[i].getAttribute && tocAList[i].getAttribute('href') === nowId) {
|
||||
tocAList[i].style.color = '#ff8a8a'
|
||||
} else if (tocAList[i] && tocAList[i].style) {
|
||||
tocAList[i].style.color = '#bbb'
|
||||
}
|
||||
}
|
||||
lastIdInx = tocIdsInx
|
||||
}
|
||||
}
|
||||
window.addEvent(window, 'scroll', () => {
|
||||
clearTimeout(debounce)
|
||||
debounce = setTimeout(() => {
|
||||
scrollToc()
|
||||
}, 20)
|
||||
})
|
||||
|
||||
document.getElementById('mobileToc').onclick = () => {
|
||||
this.showRightToc = !this.showRightToc
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
(adsbygoogle = window.adsbygoogle || []).push({}) // eslint-disable-line
|
||||
} catch (_) { }
|
||||
},
|
||||
methods: {
|
||||
initEditor () {
|
||||
const upload = {
|
||||
accept: 'image/*, video/*, audio/*, text/*, application/*, .rar, .zip, .php, .pptx, .ppt, .doc, .docx, .txt, .xls, .xlsx',
|
||||
url: process.env.baseURL + '/visitor/file/upload',
|
||||
max: 10485760, // 10 MB
|
||||
linkToImgUrl: process.env.baseURL + '/visitor/file/fetch',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + window.localStorage.visitorToken
|
||||
Authorization: 'Bearer ' + this.visitorToken
|
||||
},
|
||||
filename: name => encodeURIComponent(name.replace(/[^(a-zA-Z0-9\u4E00-\u9FA5\.)]/g, '') // eslint-disable-line
|
||||
.replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '') // eslint-disable-line
|
||||
@ -255,88 +345,7 @@ export default {
|
||||
upload,
|
||||
placeholder: '我们书写的不是代码,而是人生'
|
||||
})
|
||||
}
|
||||
|
||||
this.setCommentMap()
|
||||
}
|
||||
|
||||
this.$finishLoad()
|
||||
|
||||
if (this.articels.post_toc_show) {
|
||||
const tocShow = () => {
|
||||
if (window.addEvent) {
|
||||
window.addEvent(window, 'scroll', () => {
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth
|
||||
if (document.getElementById('articelToc') && !this.isOnScreen(document.getElementById('articelToc'))) {
|
||||
if (windowWidth < 768) {
|
||||
this.showRightToc = false
|
||||
document.getElementById('mobileToc').style.display = 'block'
|
||||
} else {
|
||||
this.showRightToc = true
|
||||
}
|
||||
} else {
|
||||
this.showRightToc = false
|
||||
if (windowWidth < 768) {
|
||||
document.getElementById('mobileToc').style.display = 'none'
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
tocShow()
|
||||
}, 50)
|
||||
}
|
||||
}
|
||||
tocShow()
|
||||
|
||||
const tocIdsTop = []
|
||||
const tocIdsTopMap = new Map()
|
||||
for (const n in this.tocIds) {
|
||||
const tTop = document.getElementById(this.tocIds[n]).offsetTop
|
||||
tocIdsTop.push(tTop)
|
||||
tocIdsTopMap.set(tTop, '#' + this.tocIds[n])
|
||||
}
|
||||
|
||||
const findInIds = (arr, num) => { for (let x = 0; x < arr.length; x++) { if (arr[x] > num) { return x - 1 } } }
|
||||
|
||||
let debounce = null
|
||||
let lastIdInx = null
|
||||
|
||||
const scrollToc = () => {
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth
|
||||
if (windowWidth < 768) { scrollTop = scrollTop * 2.7 + 175 }
|
||||
const tocIdsInx = findInIds(tocIdsTop, scrollTop + 130)
|
||||
if (tocIdsInx !== -1 && lastIdInx !== tocIdsInx && document.getElementsByClassName('articelRightToc')[0]) {
|
||||
const tocAList = document.getElementsByClassName('articelRightToc')[0].getElementsByTagName('a')
|
||||
const nowId = tocIdsTopMap.get(tocIdsTop[tocIdsInx])
|
||||
for (const i in tocAList) {
|
||||
if (tocAList[i] && tocAList[i].getAttribute && tocAList[i].getAttribute('href') === nowId) {
|
||||
tocAList[i].style.color = '#ff8a8a'
|
||||
} else if (tocAList[i] && tocAList[i].style) {
|
||||
tocAList[i].style.color = '#bbb'
|
||||
}
|
||||
}
|
||||
lastIdInx = tocIdsInx
|
||||
}
|
||||
}
|
||||
window.addEvent(window, 'scroll', () => {
|
||||
clearTimeout(debounce)
|
||||
debounce = setTimeout(() => {
|
||||
scrollToc()
|
||||
}, 20)
|
||||
})
|
||||
|
||||
document.getElementById('mobileToc').onclick = () => {
|
||||
this.showRightToc = !this.showRightToc
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
(adsbygoogle = window.adsbygoogle || []).push({}) // eslint-disable-line
|
||||
} catch (_) { }
|
||||
},
|
||||
methods: {
|
||||
decodeTitle (name) {
|
||||
try {
|
||||
return this.urldecode(name)
|
||||
|
Loading…
Reference in New Issue
Block a user