This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.php
174 lines (158 loc) · 8.54 KB
/
index.php
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php get_header(); ?>
<div id="header_info">
<nav class="header-nav reveal">
<a style="text-decoration:none;" href="https://www.ouorz.com" class="header-logo" title="TonyHe">TonyHe</a>
<p class="lead" style="margin-top: 0px;margin-left:5px">Just A Poor Lifesinger</p>
</nav>
<div class="index-cates">
<li class="cat-item cat-item-4 cat-real" style="display:none" v-for="cate in cates" v-if="cate.count !== 0"> <a :href="cate.link" :title="cate.description">{{ cate.name }}</a>
</li>
<li class="cat-item cat-item-4" style="display: inline-block;width: 98%;height: 35px;box-shadow: none;border-radius: 0px;background: rgb(236, 237, 239);" v-if="loading_cates"></li>
</div>
<div>
<ul class="post_tags">
<li class="cat-real" v-for="tag in tages" style="display:none">
<a :href="tag.link">#{{ tag.name }}</a>
</li>
<li style="background: rgb(236, 237, 238);height: 25px;width: 100%;" v-if="loading_tages"></li>
</ul>
</div>
</div>
<ul class="article-list" style="opacity:0">
<!-- 占位DIV -->
<li uk-scrollspy="cls:uk-animation-slide-left-small" class="article-list-item reveal index-post-list uk-scrollspy-inview" v-if="loading"><em class="article-list-type1" style="padding: 5.5px 44px;"> </em> <a style="text-decoration: none;"><h5 style="background: rgb(236, 237, 238);"> </h5></a><p style="background: rgb(246, 247, 248);width: 90%;"> </p><p style="background: rgb(246, 247, 248);width: 60%;"> </p>
</li>
<!-- 占位DIV -->
<li class="article-list-item reveal index-post-list" uk-scrollspy="cls:uk-animation-slide-left-small" v-for="post in posts">
<div class="list-show-div">
<em v-if="post.post_categories[0].term_id === 7" class="article-list-type1">{{ post.post_categories[0].name + ' | ' + (post.post_metas.tag_name ? post.post_metas.tag_name.toUpperCase() : '技术') }}</em>
<button type="button" class="list-show-btn" @click="preview(post.id)" :id="'btn'+post.id">全文速览</button>
</div>
<a :href="post.link" style="text-decoration: none;"><h5 v-html="post.title.rendered"></h5></a>
<p v-html="post.post_excerpt" :id="post.id"></p>
<div class="article-list-footer">
<span class="article-list-date">{{ post.post_date }}</span>
<span class="article-list-divider">-</span>
<span v-if="post.post_metas.views !== ''" class="article-list-minutes">{{ post.post_metas.views }} Views</span>
<span v-else class="article-list-minutes">0 Views</span>
</div>
</li>
<!-- 加载占位DIV -->
<li uk-scrollspy="cls:uk-animation-slide-left-small" class="article-list-item reveal index-post-list uk-scrollspy-inview bottom"><em class="article-list-type1" style="padding: 5.5px 45px;"> </em> <a style="text-decoration: none;"><h5 style="background: rgb(236, 237, 238);"> </h5></a><p style="background: rgb(246, 247, 248);width: 90%;"> </p><p style="background: rgb(246, 247, 248);width: 60%;"> </p>
</li>
<!-- 加载占位DIV -->
<!-- 加载按钮 -->
<button @click="new_page" id="scoll_new_list" style="opacity:0"></button>
<!-- 加载按钮 -->
</ul>
<script>
window.onload = function(){ //避免爆代码
var pre_post = 0;
var pre_post_con = '';
var pre_status = 1;
var now = 20;
var click = 0; //初始化加载次数
var paged = 1; //获取当前页数
/* 展现内容(避免爆代码) */
$('.article-list').css('opacity','1');
$('.cat-real').attr('style','display:inline-block');
/* 展现内容(避免爆代码) */
new Vue({ //axios获取顶部信息
el : '#grid-cell',
data() {
return {
posts: null,
cates: null,
tages: null,
loading: true, //v-if判断显示占位符
loading_cates: true,
loading_tages: true,
errored: true
}
},
mounted () {
//获取分类
axios.get('https://www.ouorz.com/wp-json/wp/v2/categories?exclude=1')
.then(response => {
this.cates = response.data;
})
.finally(() => {
this.loading_cates = false;
//获取标签
axios.get('https://www.ouorz.com/wp-json/wp/v2/tags?order=desc&per_page=15')
.then(response => {
this.tages = response.data;
}).finally(() => {
this.loading_tages = false;
});
});
//获取文章列表
axios.get('https://www.ouorz.com/wp-json/wp/v2/posts?per_page=10&page='+paged+'&categories_exclude=5,2')
.then(response => {
this.posts = response.data
})
.catch(e => {
this.errored = false
})
.finally(() => {
this.loading = false;
paged++; //加载完1页后累加页数
//加载完文章列表后监听滑动事件
$(window).scroll(function(){
var scrollTop = $(window).scrollTop();
var scrollHeight = $('.bottom').offset().top - 800;
if(scrollTop >= scrollHeight){
if(click == 0){ //接近底部加载一次新文章
$('#scoll_new_list').click();
click++; //加载次数计次
}
}
});
})
},
methods: { //定义方法
new_page : function(){ //加载下一页文章列表
$('#view-text').html('- 加载中 -');
axios.get('https://www.ouorz.com/wp-json/wp/v2/posts?per_page=10&page='+paged+'&categories_exclude=5,2')
.then(response => {
if(response.data.length !== 0){ //判断是否最后一页
$('#view-text').html('- 文章列表 -');
this.posts.push.apply(this.posts,response.data); //拼接在上一页之后
click = 0;
paged++;
}else{
$('#view-text').html('- 全部文章 -');
$('.bottom h5').html('暂无更多文章了 O__O "…').css({'background':'#fff','color':'#999'});
}
})
},
preview : function(post){ //预览文章内容
if(post !== pre_post && pre_status){ //点开当前预览
pre_post = post;
pre_status = 0; //屏蔽其余预览按钮
$('#'+post).html('<div uk-spinner></div><h7 class="loading-text">加载中...</h7>');
axios.get('https://www.ouorz.com/wp-json/wp/v2/posts/'+post)
.then(response => {
if(response.data.length !== 0){ //判断是否最后一页
$('#btn'+post).html('收起速览'); //更改按钮
$('#'+post).attr('class','preview-p').html(response.data.content.rendered); //更改内容
pre_post_con = response.data.post_excerpt; //保存摘录
}else{
$('#'+post).html('Nothing Here');
}
});
}else if(post !== pre_post && pre_status == 0){ //点击了其余预览按钮,报错
UIkit.modal.dialog('<h3 style="margin: 0px;font-weight: 600;">错误</h3><p style="margin: 5px 0;">请先收起当前预览</p>');
}else{ //点击收起按钮
$('#btn'+post).html('全文速览');
$('#'+post).html(pre_post_con).attr('class','');
pre_post_con = '';
pre_post = 0;
pre_status = 1; //开放其他预览按钮
}
}
}
});
}
</script>
<?php get_footer(); ?>