blog-client/pages/_terms/page/_page.vue

122 lines
4.2 KiB
Vue
Raw Normal View History

2019-02-07 16:26:17 +08:00
<template lang="pug">
.pageList
.articleContent(ref='articleImgs', v-if='Articels')
article.articleList(v-for='(post, index) in Articels', :key='index')
.articleImgs(v-if='post.postImages.length')
2020-09-16 23:35:24 +08:00
nuxt-link(:to='"/post/" + post.ID')
Swiper(:style='"height: " + imageHeight + "px"')
Slide(v-for='(imgUrl, inx) in post.postImages', :key='inx')
2019-02-07 16:26:17 +08:00
img(:src='imgUrl')
.articleAbstract
2020-09-16 23:35:24 +08:00
nuxt-link(:to='"/post/" + post.ID')
2019-02-07 16:26:17 +08:00
.articleTitle(v-html='post.post_title')
.articalMeta
ul
li
2020-09-16 23:35:24 +08:00
Icon(:icon='["far", "calendar-alt"]')
2019-02-07 16:26:17 +08:00
| &nbsp; {{ post.post_date }}
li
2020-09-16 23:35:24 +08:00
Icon(:icon='["far", "bookmark"]')
nuxt-link(
v-for='(relationships, idx) in post.term_relationships',
:key='idx',
v-if='relationships.term_taxonomy',
:to='"/" + relationships.term_taxonomy.term.slug'
)
2019-02-07 16:26:17 +08:00
span
| &nbsp; {{ relationships.term_taxonomy.term.name }}
li(v-if='post.postmetum.meta_value !== 0')
2020-09-16 23:35:24 +08:00
Icon(:icon='["fas", "thermometer-" + post.hotValue]')
2019-02-07 16:26:17 +08:00
| &nbsp; {{ post.postmetum.meta_value }}
2020-09-16 23:35:24 +08:00
.articelAbstractContent(
v-html='post.post_excerpt || post.post_content'
)
2019-02-07 16:26:17 +08:00
.readMore
2020-09-16 23:35:24 +08:00
nuxt-link.readMoreBtn(:to='"/post/" + post.ID')
2019-02-07 16:26:17 +08:00
| READ MORE
.Info(v-if='Info')
| {{ Info }}
2020-09-16 23:35:24 +08:00
nuxt-link(
:to='nowPage > 2 ? nowPath + "/page/" + (nowPage - 1) : nowPath + "/"',
:class='nowPage > 1 ? "btn-footer btn-prev" : "btn-footer btn-prev btn-disable"'
)
Icon(:icon='["fas", "chevron-left"]')
2019-02-07 16:26:17 +08:00
| &nbsp; 上一页
2020-09-16 23:35:24 +08:00
nuxt-link(
:to='nowPage + 1 <= Math.ceil(ArticelsCount / 8) ? nowPath + "/page/" + (nowPage + 1) : ""',
:class='nowPage + 1 <= Math.ceil(ArticelsCount / 8) ? "btn-footer btn-next" : "btn-footer btn-next btn-disable"'
)
2019-02-07 16:26:17 +08:00
| 下一页 &nbsp;
2020-09-16 23:35:24 +08:00
Icon(:icon='["fas", "chevron-right"]')
2019-02-07 16:26:17 +08:00
</template>
<script>
export default {
2019-12-13 11:46:15 +08:00
async asyncData ({ app, params, $axios }) {
2019-02-07 16:26:17 +08:00
let Info = null
let Articels = []
const nowPage = params.page ? parseInt(params.page) : 1
2019-02-07 17:03:39 +08:00
const data = await $axios.$get('/public/article/list', {
2019-02-07 16:26:17 +08:00
params: {
page: nowPage,
num: 8,
category: params.terms || ''
}
})
if (data.status === 1) {
Articels = data.result.list
for (const n in Articels) {
Articels[n].post_date = app.$moment(Articels[n].post_date).utc().format('lll')// 格式化时间
// 热度值计算
if (Articels[n].postmetum !== null && Articels[n].postmetum !== '') {
Articels[n].hotValue = app.$getHatValue(Articels[n].postmetum.meta_value)
} else {
Articels[n].hotValue = 0
Articels[n].postmetum = {}
Articels[n].postmetum.meta_value = 0
}
Articels[n].postImages = []
}
} else if (data.status === 404) {
Info = '未找到文章。'
2020-09-16 23:35:24 +08:00
// redirect('/404')
// return
2019-02-07 16:26:17 +08:00
}
return {
Articels,
imageHeight: 0,
Info,
nowPage,
ArticelsCount: data.result.count || 0,
nowPath: params.terms ? '/' + params.terms : ''
}
},
2019-12-13 11:46:15 +08:00
mounted () {
2019-02-07 16:26:17 +08:00
this.$finishLoad()
this.analyseImages()
},
methods: {
2019-12-13 11:46:15 +08:00
async analyseImages () { // 图片大小分析及处理
2019-02-07 16:26:17 +08:00
const articleImgsWidth = this.$refs.articleImgs.getBoundingClientRect().width
this.imageHeight = articleImgsWidth * 0.5625
for (const n in this.Articels) {
if (this.Articels[n].postimages.length !== 0) {
for (const i in this.Articels[n].postimages) {
2019-02-07 17:03:39 +08:00
const data = await this.$axios.$get(this.Articels[n].postimages[i].guid + '?x-oss-process=image/info')
2019-02-07 16:26:17 +08:00
const widthValue = data.ImageWidth.value
const heightValue = data.ImageHeight.value
if (widthValue > articleImgsWidth && (articleImgsWidth * heightValue / widthValue > this.imageHeight) && this.Articels[n].postImages.length < 10) {
this.Articels[n].postImages.push(this.Articels[n].postimages[i].guid + '?x-oss-process=image/resize,m_lfit,w_' + articleImgsWidth)
}
}
}
}
}
}
}
</script>