/
index.vue
286 lines (269 loc) · 9.63 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<template>
<el-container>
<el-main class="el-container">
<el-row>
<el-col :xs="0" :md="2"> </el-col>
<el-col :xs="24" :md="20">
<el-main class="el-main">
<el-container>
<el-main class="el-main">
<el-container>
<el-header class="el-header">
<HeaderTime />
</el-header>
<el-header class="el-header">
<Header />
</el-header>
<el-main class="el-main">
<el-row>
<el-col :xs="24" :xl="18">
<div id="essay" class="essay">
<!-- 正文开始 -->
<div class="lay-blog">
<div class="container-wrap">
<div class="container container-message">
<div id="contar-wrap" class="contar-wrap">
<form class="layui-form" action="">
<div
class="layui-form-item layui-form-text"
>
<textarea
id="LAY-msg-content"
v-model="newEssay"
class="layui-textarea"
style="resize:none"
></textarea>
</div>
</form>
<div class="item-btn">
<el-button
id="item-btn"
slot="append"
type="primary"
size="small"
@click="publishEssay"
>
提交
</el-button>
</div>
<div id="LAY-msg-box">
<div class="info-box">
<div
v-for="timeline in postListArray"
:key="timeline.id"
class="info-item"
>
<img
class="info-img"
src="https://tvax1.sinaimg.cn/crop.0.0.540.540.180/0075uTFdly8fs75paasl1j30f00f0afd.jpg"
alt=""
/>
<div class="info-text">
<h4>
{{
new Date(
timeline.created
).toLocaleString()
}}
</h4>
<div class="title count">
<span class="name">倚楼听雨</span>
</div>
<div
class="info-intr"
v-html="timeline.desc"
></div>
<div class="read-more">
<span
v-if="
timeline.desc &&
timeline.desc.length >= 50
"
>
<nuxt-link
:to="
'/post/' +
timeline.id +
'.html'
"
>
<h2>阅读全文</h2>
</nuxt-link>
</span>
</div>
</div>
</div>
<div class="load-more text-center">
<p></p>
<p></p>
<p
class="loadmore-btn"
@click="loadmore"
>
{{ loadText }}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</el-col>
</el-row>
</el-main>
</el-container>
</el-main>
</el-container>
</el-main>
</el-col>
<el-col :xs="0" :md="2"> </el-col>
</el-row>
<el-row>
<el-col :xs="0" :md="2"> </el-col>
<el-col :xs="24" :md="20">
<el-footer>
<FriendLink />
<Footer :site-config="siteConfigObj" />
</el-footer>
</el-col>
<el-col :xs="0" :md="2"> </el-col>
</el-row>
</el-main>
</el-container>
</template>
<script>
import FriendLink from "../../components/themes/default/FriendLink";
import HeaderTime from "@/components/themes/default/HeaderTime";
import Header from "@/components/themes/default/Header";
import Footer from "@/components/themes/default/Footer";
import { inBrowser } from "@/util/dom";
export default {
name: "Essay",
components: { HeaderTime, Header, Footer, FriendLink },
async asyncData({ $axios }) {
const siteConfigResult = await $axios.$post("/site/config/list");
const siteConfigObj = siteConfigResult.data;
const postsResult = await $axios.$post("/blog/post/list", {
postType: "essay",
postStatus: "publish",
pageNum: 1,
pageSize: 10
});
const postListArray = postsResult.status === 1 ? postsResult.data.list : [];
return { siteConfigObj, postListArray };
},
data() {
return {
total: 0,
pageSize: 10,
currentPage: 1,
showNores: false,
loadText: "加载更多",
postListArray: [],
newEssay: ""
};
},
head() {
return {
title: "心情随笔" + " - " + this.siteConfigObj.webname,
meta: [
{
name: "keywords",
content: "心情,随笔,说说,微博"
},
{
hid: "description",
name: "description",
content:
"这里是记录心路历程的地方,IDEA、头脑风暴、小想法都来自于这里。记录心情点滴,享受快乐生活。"
}
]
};
},
mounted() {
this.loadmore();
},
methods: {
async loadmore() {
this.showNores = false;
this.loadText = "加载中...";
const postsResult = await this.$axios.$post("/blog/post/list", {
postType: "essay",
postStatus: "publish",
search: this.keyword,
pageNum: ++this.currentPage,
pageSize: this.pageSize
});
// console.log(postsResult);
if (postsResult.status === 1) {
this.total = postsResult.data.total;
if (postsResult.data.list.length > 0) {
// 渲染数据
for (const idx in postsResult.data.list) {
const post = postsResult.data.list[idx];
this.postListArray.push(post);
}
this.loadText = "加载更多";
} else {
this.showNores = true;
this.loadText = "加载完成";
}
}
},
async publishEssay() {
if (this.newEssay.trim() === "") {
this.$message.error("随笔内容不能为空哦~");
return;
}
console.log("start publish essay:" + this.newEssay);
const result = await this.$axios.$post("admin/post/save", {
title: new Date().toLocaleDateString(),
type: "essay",
status: "publish",
content: this.newEssay
});
const ret = result.status === 1;
console.log("ret=>", ret);
await this.loadmore();
this.$message({
message: "随笔发布成功",
type: "success"
});
setTimeout(function() {
if (inBrowser) {
window.location.reload();
}
}, 1000);
}
}
};
</script>
<style lang="scss">
@import "../common.css";
@import "../default.css";
@import "../essay.css";
.essay {
color: #333333;
}
.read-more a {
color: #1e9fff;
cursor: pointer;
h2 {
font-size: 14px;
padding-left: 10px;
}
}
.load-more {
color: #ffb800;
}
.loadmore-btn {
cursor: pointer;
}
.like em {
font-style: normal;
font-size: 12px;
color: red;
}
</style>