Skip to content

Commit

Permalink
✨ fixed sentence init content
Browse files Browse the repository at this point in the history
  • Loading branch information
nicejade committed Jul 9, 2021
1 parent 5e8a147 commit 46df6d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/components/sidebar/AwesomeSentence.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default {
type: [Object],
default: '',
},
index: {
type: [Number],
default: 1,
},
},
computed: {
Expand All @@ -62,6 +66,9 @@ export default {
this.currentSentenceStr = val
this.lastSentenceStr = val
},
index: function (val = 1) {
this.updateSentence(val)
},
},
methods: {
Expand All @@ -73,6 +80,7 @@ export default {
document.execCommand('copy')
document.body.removeChild(el)
},
copyToIosClipboard(content) {
window.getSelection().removeAllRanges()
const node = document.getElementById('sentence')
Expand All @@ -82,6 +90,7 @@ export default {
document.execCommand('copy')
window.getSelection().removeAllRanges()
},
/* ---------------------Click Event--------------------- */
onPreviousClick() {
if (!this.isCanLookBack) {
Expand All @@ -93,6 +102,7 @@ export default {
this.currentSentenceStr = this.lastSentenceStr
this.isCanLookBack = false
},
onRandomClick() {
this.isLoading = true
this.$apis
Expand All @@ -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, '')
Expand Down
9 changes: 8 additions & 1 deletion src/components/sidebar/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ads-position :adverts-list="advertsList"></ads-position>
<el-collapse v-model="activeNames" @change="handleChange">
<el-collapse-item :title="$t('awesomeSentence')" name="awesomeSentence">
<awesome-sentence :sentence="sentence" />
<awesome-sentence :sentence="sentence" :index="index" />
</el-collapse-item>
<el-collapse-item :title="$t('miniprogramCode')" name="miniprogramCode">
<img
Expand Down Expand Up @@ -55,6 +55,13 @@ export default {
}
},
props: {
index: {
type: [Number],
default: 1,
},
},
computed: {
isShowFriendFlag() {
return !this.$isFromQuickapp()
Expand Down
11 changes: 10 additions & 1 deletion src/views/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</social-share>
</links-list>
</div>
<aside-list></aside-list>
<aside-list :index="index"></aside-list>
</div>
</div>
</div>
Expand All @@ -35,6 +35,7 @@ export default {
isLoading: true,
niceLinksArrayay: [],
niceLinksDetail: {},
index: 0,
currentPath: window.document.location.href,
shareTitle: '',
}
Expand All @@ -59,6 +60,7 @@ export default {
this.niceLinksArrayay = result
this.niceLinksDetail = result[0]
this.updatePageSentence()
this.updatePageMeta(result[0])
this.addHeaderNavActive()
} else {
Expand All @@ -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')
Expand Down

0 comments on commit 46df6d6

Please sign in to comment.