-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.vue
150 lines (149 loc) · 4.67 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<section id="three" class="wrapper style2">
<div class="inner">
<TabSort v-show="config.showHomeSort === '是' && isIndex === 'true'" @setArticleOrder="setArticleOrder" />
<Loading :show="showLoading" />
<template v-if="emptyPic">
<div class="align-center shake-chunk shake-constant shake-constant--hover" style="padding-top: 6em;">
<img src="https://i.loli.net/2019/10/16/CnoBqkweLcPgfNM.png" />
</div>
</template>
<div class="grid-style">
<div v-for="item in article_list" :key="item.id" :data-id="item.id">
<div class="box wow zoomIn" style="animation-duration: .6s;">
<nuxt-link class="article_box_item"
:to="{ path: `/post/${item.id}?cid=${cid || item.cid}&index=${isIndex}` }">
<span class="image fit article_item">
<img :title="item.title" class="img-fit"
v-lazy="item.pic ? item.pic : `https://picsum.photos/id/${item.id}/600/350`" />
</span>
<span class="entry-category">
<span v-if="item.look" class="entry-category-tag">阅读 {{ item.look }}</span>
<span v-if="item.comment_count" class="entry-category-tag">评论 {{ item.comment_count }}</span>
<span v-for="(key, ind) in item.keywords" @click.prevent="gotoPage(`/search/${key}`)" :key="ind"
class="entry-category-tag">
{{ key }}
</span>
</span>
</nuxt-link>
<div class="content">
<header class="align-center">
<h2 class="title">
<nuxt-link :title="item.title"
:to="{ path: `/post/${item.id}?cid=${cid || item.cid}&index=${isIndex}` }">
{{ item.title }}
</nuxt-link>
</h2>
<p>
<span class="inline-block">
<i class="icon fa-calendar"></i>
<span> {{ item.create_time }}</span>
</span>
<span class="inline-block">
<i class="icon fa-list-alt"></i>
<span> {{ item.catename }}</span>
</span>
</p>
</header>
<p>{{ item.content }}</p>
</div>
</div>
</div>
</div>
<PageMore ref="pageBtn" @nextnewpage="moreArticles" v-if="pageStatus" />
</div>
</section>
</template>
<script>
import { mapGetters } from 'vuex';
import Loading from '@/components/Loading';
import PageMore from '@/components/PageMore';
import TabSort from "@/components/TabSort";
import { indexList } from "@/api";
export default {
components: {
TabSort,
Loading,
PageMore
},
computed: {
isIndex() {
if (this.$route.path === '/') {
return 'true';
}
return 'false';
},
...mapGetters(['config']),
},
props: {
cid: { type: String, default: '' }
},
head() {
return {
title: this.$route.query.title ? this.$route.query.title + ' - ' + this.config.seo_name : this.config.seo_name,
}
},
data() {
return {
limitNum: null,
showLoading: true,
pageStatus: null,
emptyPic: false,
article_list: [],
orderName: 'create_time'
}
},
methods: {
async setArticleOrder(order) {
this.article_list = [];
this.pageStatus = false;
this.showLoading = true;
this.orderName = order;
await this.getArticles(1)
this.$nextTick(() => {
if (this.$refs.pageBtn) this.$refs.pageBtn.pageNumber = 1
})
},
gotoPage(path) {
if (!path) return
this.$router.push({ path })
},
moreArticles(n) {
this.getArticles(n)
},
async getArticles(n) {
const p = {
order: this.orderName,
pageNumber: n || 1,
limitNumber: 10,
cid: this.cid
}
const res = await indexList(p)
let rowsList = res.rows
this.showLoading = false;
this.limitNum = +this.config.artlsit_number
if (res.count > 0) {
rowsList.map(item => {
if (item.pic === "") {
item.pic = `https://picsum.photos/id/${item.id}/600/350`;
}
if (this.$refs['pageBtn']) this.$refs['pageBtn'].moreTxt = 'More'; // 变回more文案
})
} else {
this.emptyPic = true;
}
this.article_list = this.article_list.concat(rowsList);
this.pageStatus = this.article_list.length !== res.count; // 显示条数按钮
},
WOWInit() {
new WOW().init();
}
},
async mounted() {
this.WOWInit();
},
created() {
this.getArticles()
}
}
</script>