tiezidetail.vue
18.8 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
<template>
<div class="container">
<div class="tiezhlist tiezhlistbox">
<div class="tieziitem">
<div class="tiezitop flexone" >
<div class="tieziimg" @click="personclick">
<img :src="tiezidetail.user.avatar" alt="" />
</div>
<div class="tieziright">
<div class="tiezirighttop flex">
<div>
<div class="tieziming">{{ tiezidetail.user.nickname }}</div>
</div>
<div v-if="tiezidetail.user.level">
<div class="vipimg" style="margin-left:0.2rem">
<img
src="../../../assets/vip_icon@2x.png"
alt=""
v-if="tiezidetail.forum_type == 1"
/>
<div class="vipname">{{ tiezidetail.user.level.name1 }}</div>
</div>
</div>
<img
:src="item"
class="banggongimg"
alt=""
v-for="(item, index) in tiezidetail.user.label"
:key="index"
/>
<img
src="../../../assets/yirenzheng_icon@2x.png"
class="banggongimg"
alt=""
v-if="tiezidetail.is_card == 1"
/>
</div>
<div class="tiezibto flexone"></div>
</div>
</div>
<div class="tiezicontent">
<div class="flexone">
<div class="tiezifen">{{tiezidetail.createtime}}</div>
<div class="tiezizhuan tiezhuanbox" v-for="(item,index) in tiezidetail.user.label" :key="index" >{{item.name_label}}</div>
</div>
<div class="teizicontenttop flextwo">
<div class="tiezicontentname">{{ tiezidetail.title }}</div>
<img
src="../../../assets/xingxing_icon@2x.png"
alt=""
class="starimg"
v-if="tiezidetail.is_collect==1"
@click="collect"
/>
<img
src="../../../assets/weishoucang_icon@2x.png"
alt=""
class="starimg"
@click="collect"
v-else
/>
</div>
<div class="tieziwordbox" v-if="tiezidetail.type==1">{{ tiezidetail.content}}</div>
<div class="tieziwordbox" v-html="tiezidetail.content" v-else></div>
<div
class="teiziimgbox flexone"
v-if="tiezidetail.video != null"
@click="govideo(tiezidetail.video)"
>
<div class="videoimg">
<img :src="tiezidetail.video_image" alt="" />
<img
src="../../../assets/bofang_icon@2x.png"
alt=""
class="videobtn"
/>
</div>
</div>
<div class="teiziimgbox flexone" v-if="tiezidetail.images != null">
<div
class="tieziimgimg"
v-for="(item, indexk) in tiezidetail.images"
:key="indexk"
@click.stop="previewimg(index, indexk, item)"
>
<img :src="item" alt="" />
</div>
</div>
<div class="tiezipingbot">
<div class="teizipingitem flexone">
<img
src="../../../assets/pinglun_icon@2x.png"
alt=""
class="lunimg"
/>
{{ tiezidetail.comment }}
</div>
<div class="teizipingitem flexone" @click="tiezizan">
<img
src="../../../assets/zan_icon@2x.png"
alt=""
class="lunimg zanimg"
v-if="tiezidetail.is_praise == 1"
/>
<img
src="../../../assets/nodianzan.png"
alt=""
class="lunimg zanimg"
v-if="tiezidetail.is_praise == 2"
/>
{{ tiezidetail.praise }}
</div>
<div class="teizipingitem flexone">
<img
src="../../../assets/number.png"
alt=""
class="lunimg zanimg"
/>
{{tiezidetail.view}}
</div>
</div>
</div>
</div>
<!-- 全部评论 -->
<div class="allcomentbox">
<div class="commentname">全部评论</div>
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<div
class="tieziitem"
v-for="(item, index) in commentlist"
:key="index"
>
<div class="tiezitop flexone">
<div class="tieziimg">
<img :src="item.user.avatar" alt="" />
</div>
<div class="tieziright flextwo">
<div class="tiezirighttop flextwo">
<div class="flexone">
<div>
<div class="tieziming">{{ item.user.nickname }}</div>
<div class="tiezifen">{{item.createtime}}</div>
</div>
<div>
<div class="vipimg" v-if="item.forum_type == 1">
<img src="../../../assets/vip_icon@2x.png" alt="" />
<div class="vipname">{{ item.user.level.name1 }}</div>
</div>
<div style="margni-left:0.1rem">
<div class="tiezizhuan tiezhuanbox" v-for="(item,index) in tiezidetail.user.label" :key="index" >{{item.name_label}}</div>
</div>
</div>
</div>
<img
src="../../../assets/xingxing_icon@2x.png"
alt=""
class="starimg"
v-if="tiezidetail.is_collect==1"
@click="collect"
/>
<img
src="../../../assets/weishoucang_icon@2x.png"
alt=""
class="starimg"
@click="collect"
v-else
/>
</div>
<div class="tiezibto flexone"></div>
</div>
</div>
<div class="tiezicontent">
<div class="teizicontenttop flextwo">
<div class="tiezicontentname">{{ item.title }}</div>
<!-- <img
src="../../../assets/xingxing_icon@2x.png"
alt=""
class="starimg"
/>
<img
src="../../../assets/weishoucang_icon@2x.png"
alt=""
class="starimg"
/> -->
</div>
<div class="tieziwordbox" v-html="item.content"></div>
<div class="tiezipingbot">
<div
class="teizipingitem flexone"
@click="dianzan(item, index)"
>
<img
src="../../../assets/zan_icon@2x.png"
alt=""
class="lunimg zanimg"
v-if="item.is_praise == 1"
/>
<img
src="../../../assets/nodianzan.png"
alt=""
class="lunimg zanimg"
v-if="item.is_praise == 2"
/>
{{ item.praise }}
</div>
</div>
</div>
</div>
</van-list>
</div>
<div class="commentboxfix flexone">
<div class="writebox">
<input type="text" placeholder="写点什么..." v-model="comment" />
</div>
<div class="fasend" @click="sendcomment">发送</div>
</div>
</div>
</div>
</template>
<script>
import wx from "weixin-js-sdk";
import { Toast } from "vant";
import {text} from "../../../utils/base.js"
export default {
data() {
return {
tiezisel: 1,
forum_id: "",
tiezidetail: "",
page: 1,
loading: false,
finished: false,
showpull: true,
commentlist: [],
// 发送评论
comment: "",
user: "",//用户信息
baseurl:''
};
},
created() {
this.baseurl = "http://" + location.host;
document.title = "帖子详情";
this.forum_id = this.$route.query.id;
console.log(this.forum_id);
// 获取帖子详情
this.getformdetail();
// 获取评论列表
this.getcommentlist();
},
beforeRouteEnter(to, from, next) {
var u = navigator.userAgent;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
// XXX: 修复iOS版微信HTML5 History兼容性问题
if (isiOS && to.path !== location.pathname) {
// 此处不可使用location.replace
location.assign(to.fullPath);
} else {
next();
}
},
methods: {
seltiekind(id) {
this.tiezisel = id;
},
onLoad() {
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(() => {
let newpage = this.page;
newpage++;
this.page = newpage;
this.getcommentlist();
// 加载状态结束
this.loading = false;
// 数据全部加载完成
if (this.showpull == false) {
this.finished = true;
}
}, 1000);
},
// 获取appid
getappid() {
let that = this;
let urlk = window.location.href;
var url = "/api/user/get_jssdk";
let param = {
url: urlk
};
that.$axios
.post(url, param)
.then(function (res) {
console.log(res, "hahahahaiaioaioaio4");
wx.config({
debug: false,
appId: res.data.appId, // 和获取Ticke的必须一样------必填,公众号的唯一标识
timestamp: res.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature, // 必填,签名,见附录1
//需要分享的列表项:发送给朋友,分享到朋友圈,分享到QQ,分享到QQ空间
jsApiList: [
"showOptionMenu",
"updateAppMessageShareData",
"updateTimelineShareData"
]
});
that.sharetofriend();
})
.catch(function (err) {
console.log(err);
});
},
// 分享给朋友
sharetofriend() {
var that = this;
localStorage.setItem("type", "");
// 处理验证失败的信息
wx.error(function (res) {
logUtil.printLog("验证失败返回的信息:", res);
});
// 处理验证成功的信息
wx.ready(function () {
// alert(window.location.href.split('#')[0]);
// var share_title = that.sharemsg.title;
// if (share_title.indexOf("${title}") >= 0) {
// share_title = share_title.replace(
// "${title}",
// that.details.details.title
// );
// }
// var share_desc = that.sharemsg.content;
// if (share_desc.indexOf("${title}") >= 0) {
// share_desc = share_desc.replace(
// "${title}",
// that.details.details.title
// );
// }
// if (share_desc.indexOf("${text}") >= 0) {
// share_desc = share_desc.replace("${text}", that.details.details.text);
// }
// 分享到朋友圈
wx.updateTimelineShareData({
title: "中国面条", // 分享标题
desc:that.tiezidetail.title,
link:
that.baseurl +
"/redirect.html?shareRedirect=" +
encodeURIComponent(window.location.href), // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl:
"https://app.chinesenooddles.com/uploads/20201026/9d7ab1da16673a04e56215f8faf1fc47.png",
// imgUrl: that.details.details.img
// ? that.details.details.img
// : that.sharemsg.img,
// 分享图标
// desc: that.sharemsg.content,
success: function (res) {
// 用户确认分享后执行的回调函数
console.log("suss");
logUtil.printLog("分享到朋友圈成功返回的信息为:", res);
that.showMsg("分享成功!");
},
cancel: function (res) {
// 用户取消分享后执行的回调函数
console.log("err");
logUtil.printLog("取消分享到朋友圈返回的信息为:", res);
}
}),
// 分享给朋友
wx.updateAppMessageShareData({
title: "中国面条", // 分享标题
desc: that.tiezidetail.title, // 分享描述
link:
that.baseurl +
"/redirect.html?shareRedirect=" +
encodeURIComponent(window.location.href), // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl:
"https://app.chinesenooddles.com/uploads/20201026/9d7ab1da16673a04e56215f8faf1fc47.png",
// imgUrl: that.details.details.img
// ? that.details.details.img
// : that.sharemsg.img,
// 分享图标
type: "", // 分享类型,music、video或link,不填默认为link
dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
success: function (res) {
// 用户确认分享后执行的回调函数
// logUtil.printLog("分享给朋友成功返回的信息为:", res);
},
cancel: function (res) {
// 用户取消分享后执行的回调函数
// logUtil.printLog("取消分享给朋友返回的信息为:", res);
}
});
});
},
// 获取帖子详情
getformdetail() {
let that = this;
var url = "/api/forum/get_forum_detail";
var params = {
forum_id: that.forum_id
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log("111111111", res);
setTimeout(function() {
that.tiezidetail = res.data;
if(that.tiezidetail.type==2){
that.tiezidetail.content=text(that.tiezidetail.content)
}
that.tiezidetail=that.tiezidetail;
that.$forceUpdate()
that.user = res.data.user;
that.getappid()
}, 200);
})
.catch(err => {
console.log(err);
});
},
// 收藏和取消收藏
collect(){
let that = this;
var url = "/api/forum/collect";
var params = {
forum_id: that.forum_id
};
console.log("7766554", params);
that.$axios
.post(url, params)
.then(res => {
let newtiezidetail=that.tiezidetail;
if(newtiezidetail.is_collect==2){
newtiezidetail.is_collect=1;
Toast("收藏成功")
}else{
newtiezidetail.is_collect=2;
Toast("取消收藏成功")
}
that.tiezidetail=newtiezidetail;
})
.catch(err => {
console.log(err);
});
},
// 帖子详情点赞
tiezizan() {
let that = this;
if (that.tiezidetail.is_praise == 2) {
that.tiezidetail.is_praise = 1;
that.tiezidetail.praise = that.tiezidetail.praise + 1;
Toast("点赞成功");
} else {
that.tiezidetail.is_praise = 2;
that.tiezidetail.praise = that.tiezidetail.praise - 1;
Toast("取消点赞成功");
}
that.tiezidetail = that.tiezidetail;
var url = "/api/forum/praise";
var params = {
forum_id: that.forum_id
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {})
.catch(err => {
console.log(err);
});
},
// 获取评论列表
getcommentlist() {
let that = this;
var url = "/api/comments/get_comments";
var params = {
forum_id: that.forum_id,
page: that.page,
pageNum: 10
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res, "评论列表", this.commentlist);
this.commentlist = this.commentlist.concat(res.data);
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
console.log(this.commentlist);
})
.catch(err => {
console.log(err);
});
},
// 发送评论
sendcomment() {
let that = this;
if (that.comment == "") {
Toast("请输入评论内容");
return false;
}
var url = "/api/comments/publish_comments";
var params = {
forum_id: that.forum_id,
content: that.comment
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
Toast("评论成功");
that.comment = "";
that.page = 1;
that.commentlist = [];
that.getcommentlist();
})
.catch(err => {
console.log(err);
});
},
// 评论列表点赞
dianzan(item, index) {
let that = this;
console.log(item, index);
if (this.commentlist[index].is_praise == 2) {
Toast("点赞成功");
this.commentlist[index].is_praise = 1;
this.commentlist[index].praise = this.commentlist[index].praise + 1;
} else {
this.commentlist[index].is_praise = 2;
this.commentlist[index].praise = this.commentlist[index].praise - 1;
Toast("取消点赞成功");
}
this.commentlist = this.commentlist;
var url = "/api/comments/praise";
var params = {
comments_id: item.id
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {})
.catch(err => {
console.log(err);
});
},
govideo(src) {
this.$router.push({
path: "/videoplay",
query: { url: src }
});
},
personclick() {
console.log(this.tiezidetail)
this.$router.push({
path: "/personpage",
query: {
type: 3,
userid: this.tiezidetail.user_id
}
});
}
}
};
</script>
<style scoped>
@import "../../style/homepage.css";
.tiezhlistbox {
margin-top: 0.24rem;
}
.tieziright,.tiezirighttop {
flex:1
}
</style>