From 46df6d66aecbbe23476a3e0ca2323df303cef4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JadeYang=28=E6=9D=A8=E7=90=BC=E7=92=9E=29?= Date: Sat, 10 Jul 2021 01:34:24 +0800 Subject: [PATCH] :sparkles: fixed sentence init content --- src/components/sidebar/AwesomeSentence.vue | 38 ++++++++++++++++++++++ src/components/sidebar/Main.vue | 9 ++++- src/views/Post.vue | 11 ++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/components/sidebar/AwesomeSentence.vue b/src/components/sidebar/AwesomeSentence.vue index f4dbac19..3d82f3bf 100644 --- a/src/components/sidebar/AwesomeSentence.vue +++ b/src/components/sidebar/AwesomeSentence.vue @@ -39,6 +39,10 @@ export default { type: [Object], default: '', }, + index: { + type: [Number], + default: 1, + }, }, computed: { @@ -62,6 +66,9 @@ export default { this.currentSentenceStr = val this.lastSentenceStr = val }, + index: function (val = 1) { + this.updateSentence(val) + }, }, methods: { @@ -73,6 +80,7 @@ export default { document.execCommand('copy') document.body.removeChild(el) }, + copyToIosClipboard(content) { window.getSelection().removeAllRanges() const node = document.getElementById('sentence') @@ -82,6 +90,7 @@ export default { document.execCommand('copy') window.getSelection().removeAllRanges() }, + /* ---------------------Click Event--------------------- */ onPreviousClick() { if (!this.isCanLookBack) { @@ -93,6 +102,7 @@ export default { this.currentSentenceStr = this.lastSentenceStr this.isCanLookBack = false }, + onRandomClick() { this.isLoading = true this.$apis @@ -110,6 +120,34 @@ export default { this.isLoading = false }) }, + + updateSentence(index) { + const params = { + pageCount: index, + pageSize: 1, + sortType: 1, + active: true, + sortTarget: 'createTime', + } + this.$apis + .getSentences(params) + .then((result) => { + if (!result || result.length === 0) return + + this.lastSentenceStr = this.currentSentenceStr + this.isCanLookBack = true + this.currentSentence = result[0] || {} + this.currentSentenceStr = result[0].content + }) + .catch((error) => { + console.log(error) + this.$message.error(`${error}`) + }) + .finally(() => { + this.isLoading = false + }) + }, + onCopy2ClipboardClick() { const tempStr = marked(this.currentSentenceStr, {}) + `── 倾城之链 · 箴言锦语` const content = tempStr.replace(/<[^>]*>/g, '') diff --git a/src/components/sidebar/Main.vue b/src/components/sidebar/Main.vue index 97e42b11..79436a35 100644 --- a/src/components/sidebar/Main.vue +++ b/src/components/sidebar/Main.vue @@ -3,7 +3,7 @@ - + - + @@ -35,6 +35,7 @@ export default { isLoading: true, niceLinksArrayay: [], niceLinksDetail: {}, + index: 0, currentPath: window.document.location.href, shareTitle: '', } @@ -59,6 +60,7 @@ export default { this.niceLinksArrayay = result this.niceLinksDetail = result[0] + this.updatePageSentence() this.updatePageMeta(result[0]) this.addHeaderNavActive() } else { @@ -85,6 +87,13 @@ export default { this.description = details.desc }, + updatePageSentence() { + const createTime = new Date(this.niceLinksDetail.created) + const startTime = new Date('2017-09-14') + const offsetTime = createTime.getTime() - startTime.getTime() + this.index = Math.ceil(offsetTime / 1296000000) // (15 * 24 * 60 * 60 * 1000) + }, + addHeaderNavActive() { const classify = +this.niceLinksDetail.classify const navItemNodes = document.getElementsByClassName('nav-item')