index.vue
20.5 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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
<template>
<div class="container">
<div class="hometop">
<div class="hometopbar flextwo">
<!-- ../../../assets/touxiang_img@2x.png -->
<img
:src="userinfo.avatar"
alt=""
class="homelogo"
/>
<div class="homesearch flexone">
<!-- <img src="../../../assets/sousuo.png" alt="" class="souimg" /> -->
<div class="souenter">
<input
type="text"
placeholder="请输入关键词搜索"
v-model="keyword"
@blur="finishword"
/>
</div>
</div>
<div class="searchpro flexone" @click="selectpro">
<div class="proname">{{ proname }}</div>
<img src="../../../assets/xiasanjiao.png" alt="" class="xiasanjiao" />
</div>
</div>
<div class="docswiper">
<van-swipe
class="my-swipe"
:autoplay="2000"
indicator-color="white"
:loop="true"
>
<van-swipe-item v-for="(item, index) in bannertop" :key="index">
<div class="bannerimg">
<img :src="item.image" alt="" />
</div>
</van-swipe-item>
</van-swipe>
</div>
</div>
<div class="homepagebox">
<div class="homekind flexone">
<div
class="homepageboxitem flexfour"
@click="duanshipin(1, item)"
v-for="(item, index) in tiezikind"
:key="index"
>
<img :src="item.image" alt="" class="homepageitemimg" />
<div class="homepageitemname">{{ item.name }}</div>
</div>
</div>
<div class="homefenlei flextwo">
<div
class="fenleiword"
:class="fenlei == 0 ? 'fenleiactive' : ''"
@click="getfen(0)"
>
默认
</div>
<div
class="fenleiword"
:class="fenlei == 1 ? 'fenleiactive' : ''"
@click="getfen(1)"
>
热门
</div>
<div
class="fenleiword"
:class="fenlei == 2 ? 'fenleiactive' : ''"
@click="getfen(2)"
>
最高点赞
</div>
</div>
<!-- 帖子列表 -->
<div class="nodata" v-if="tiezilist.length == 0">暂无数据</div>
<div class="tiezhlist" v-else>
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<div
class="tieziitem"
v-for="(item, index) in tiezilist"
:key="index"
@click="luntandetail(item)"
>
<div class="tiezitop flexone">
<div class="tieziimg">
<img :src="item.user.avatar" alt="" />
</div>
<div class="tieziright" v-if="showlist">
<div class="tiezirighttop flex">
<div class="timeright">
<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 class="tiezizhuan" v-for="(item,index) in item.user.label" :key="index" >{{item.name_label}}</div>
</div>
<!-- {{item.user.label.length}} -->
<!-- v-if="item.user.label.length!=0" -->
<div class="flex" v-if="item.user.label!='[]'">
<img
:src="itemk.logo_image"
class="banggongimg"
alt=""
v-for="(itemk, index) in item.user.label"
:key="index"
/>
<!-- <img
src="../../../assets/peisong_icon@2x.png"
class="banggongimg"
alt=""
/> -->
</div>
<img
src="../../../assets/yirenzheng_icon@2x.png"
class="banggongimg"
alt=""
v-if="item.is_card == 1"
/>
</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"
v-if="item.is_collect==1"
@click.stop="collect(index,item.id)"
/>
<img
src="../../../assets/weishoucang_icon@2x.png"
alt=""
class="starimg"
v-else
@click.stop="collect(index,item.id)"
/>
</div>
<div class="tieziwordbox" v-html="item.content"></div>
<div
class="teiziimgbox flexone"
v-if="item.video != null"
@click.stop="govideo(item.video)"
>
<div class="videoimg">
<img :src="item.video_image" alt="" />
<img
src="../../../assets/bofang_icon@2x.png"
alt=""
class="videobtn"
/>
</div>
</div>
<div class="teiziimgbox flexone" v-if="item.images != null">
<div
class="tieziimgimg"
v-for="(item, indexk) in item.images"
:key="indexk"
@click.stop="previewimg(index, indexk, item)"
>
<img :src="item" alt="" />
</div>
</div>
<div class="tiezipingbot">
<div class="teizipingitem flexone" v-if="item.comment != 0">
<img
src="../../../assets/pinglun_icon@2x.png"
alt=""
class="lunimg"
/>
{{ item.comment }}
</div>
<div
class="teizipingitem flexone"
@click.stop="praisedian(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 class="teizipingitem flexone">
<img
src="../../../assets/number.png"
alt=""
class="lunimg zanimg"
/>
{{item.view}}
</div>
</div>
</div>
</div>
</van-list>
</div>
</div>
<!-- 弹出层 -->
<div class="register" v-if="showpublish">
<div class="publishwrap">
<div class="flextwo">
<div class="homepageboxitem flexfour">
<img
src="../../../assets/duanzhipin.png"
alt=""
class="homepageitemimg"
/>
<div class="homepageitemname">短视频区</div>
</div>
<div class="homepageboxitem flexfour">
<img
src="../../../assets/banggong.png"
alt=""
class="homepageitemimg"
/>
<div class="homepageitemname">帮工招聘</div>
</div>
<div class="homepageboxitem flexfour">
<img
src="../../../assets/zhuanrang.png"
alt=""
class="homepageitemimg"
/>
<div class="homepageitemname">面坊转让</div>
</div>
<div class="homepageboxitem flexfour">
<img
src="../../../assets/zhenghun.png"
alt=""
class="homepageitemimg"
/>
<div class="homepageitemname">征婚交友</div>
</div>
</div>
<div class="chahao" @click="hidetanceng">
<img src="../../../assets/chahao.png" alt="" />
</div>
</div>
</div>
<!-- 选择器 -->
<van-picker
title="标题"
show-toolbar
:columns="citylist"
@confirm="onConfirm"
@cancel="onCancel"
v-if="showcity"
/>
<tabBar v-bind:active="0" />
</div>
</template>
<script>
import Vue from "vue";
import wx from "weixin-js-sdk";
import tabBar from "@/components/tabsec.vue";
import { Swipe, SwipeItem, List, Toast } from "vant";
import area from "../../../utils/area.js";
import { changename } from "../../../utils/base.js"; //城市去掉市
import { text } from "../../../utils/base.js"; //富文本格式化
import {richTextFormat} from "../../../utils/base.js" //富文本超出显示省略号
Vue.use(List);
Vue.use(Swipe);
Vue.use(SwipeItem);
export default {
components: {
tabBar
},
data() {
return {
fenlei: 0,
showlist:false,
showpublish: false,
tiezikind: [],
tiezilist: [],
loading: false,
finished: false,
showpull: true,
page: 1,
citylist: area.province_list,
showcity: false,
proname: "",
province_id: "",
keyword: "",
bannertop: [], // 顶部轮播图
userinfo:''
};
},
created() {
document.title = "中国面条";
// 获取顶部轮播图
this.getbannertop();
// 获取jssdk
this.getappid();
// 获取帖子分类
this.gettiezikind();
// 获取用户信息
this.getuserinfo()
},
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: {
// 获取用户信息
getuserinfo() {
let that = this;
var url = "/api/member/index";
var params = {};
console.log("7766554", params);
that.$axios
.post(url, params)
.then(res => {
that.userinfo = res.data;
})
.catch(err => { });
},
// 收藏和取消收藏
collect(index,id){
let that = this;
var url = "/api/forum/collect";
var params = {
forum_id: id
};
console.log("7766554", params);
that.$axios
.post(url, params)
.then(res => {
let newtiezilist=that.tiezilist;
if( newtiezilist[index].is_collect==2){
newtiezilist[index].is_collect=1;
Toast("收藏成功")
}else{
newtiezilist[index].is_collect=2;
Toast("取消收藏成功")
}
that.tiezilist=newtiezilist;
that.$forceUpdate()
that.bannertop = res.data;
})
.catch(err => {
console.log(err);
});
},
// 获取轮播图
getbannertop() {
let that = this;
var url = "/api/sundry/get_slide2";
var params = {};
console.log("7766554", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res, "000000");
that.bannertop = res.data;
})
.catch(err => {
console.log(err);
});
},
// 确定选择城市
onConfirm(value, index) {
console.log(value, index);
let that = this;
this.showcity = false;
if (changename(value) != "") {
that.proname = changename(value);
} else {
that.proname = value;
}
that.page = 1;
that.tiezilist = [];
that.getprovinceid();
},
onCancel() {
this.showcity = false;
},
// 选择城市
selectpro() {
this.showcity = true;
},
// 输入完成之后
finishword() {
this.page = 1;
this.tiezilist = [];
this.getteizilist();
},
onLoad() {
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(() => {
let newpage = this.page;
newpage++;
this.page = newpage;
this.getteizilist();
// 加载状态结束
this.loading = false;
// 数据全部加载完成
if (this.showpull == false) {
this.finished = true;
}
}, 1000);
},
getlocation() {
console.log(999999);
},
// 获取appid
getappid() {
let that = this;
console.log(34734894890);
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, "jssdkjsskd");
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: ["imagePreview","geoLocation"]
});
wx.ready(function() {
wx.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
console.log(res, "获取地理位置");
var url =
"https://restapi.amap.com/v3/geocode/regeo?key=735d888fa7a9599eea4de210edc32335&location=" +
res.longitude +
"," +
res.latitude +
"&output=JSON&batch=false&roadlevel=0";
that.$http
.get(url)
.then(mapres => {
console.log(mapres, "详细地址");
})
.catch(function (maperr) {
that.proname = maperr.regeocode.addressComponent.province;
if (changename(that.proname) != "") {
that.proname = changename(that.proname);
}
localStorage.setItem("proname", that.proname);
that.getprovinceid();
});
}
});
});
})
.catch(function (err) {
console.log(err);
});
},
// 根据城市名字获取id
getprovinceid() {
let that = this;
var url = "/api/question/get_area";
var params = {
province_name: that.proname
};
console.log("7766554", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res, "000000");
that.province_id = res.data.id;
that.tiezilist = [];
that.page = 1;
// 获取论坛列表
this.getteizilist();
})
.catch(err => {
console.log(err);
});
},
// 获取分类列表
gettiezikind() {
let that = this;
console.log(34734894890);
let urlk = window.location.href;
var url = "/api/forum/get_forum_category";
let param = {
type:2
};
that.$axios
.post(url, param)
.then(function (res) {
that.tiezikind = res.data;
console.log(that.tiezikind);
})
.catch(function (err) {
console.log(err);
});
},
// 获取帖子列表
getteizilist() {
let that = this;
console.log(34734894890);
let urlk = window.location.href;
var url = "/api/forum/get_forum";
let param = {
province_id: that.province_id,
search_type: "",
keyword: that.keyword,
type: that.type,
order: that.fenlei,
page: that.page,
pageNum: 10
};
that.$axios
.post(url, param)
.then(function (res) {
that.tiezilist = that.tiezilist.concat(res.data);
that.tiezilist.forEach(function (value, index, array) {
value.content = text(value.content);
});
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
setTimeout(function(){
that.showlist=true
},200)
console.log(that.tiezilist);
that.tiezilist.forEach(function(value,index,array){
value.content=richTextFormat(value.content)
})
that.tiezilist=that.tiezilist;
that.$forceUpdate()
})
.catch(function (err) {
console.log(err);
});
},
// 论坛详情
luntandetail(item) {
this.$router.push({
path: "/tiezidetail",
query: { id: item.id }
});
},
// 点赞和取消点赞
praisedian(item, index) {
let that = this;
if (that.tiezilist[index].is_praise == 2) {
Toast("点赞成功");
that.tiezilist[index].is_praise = 1;
that.tiezilist[index].praise = that.tiezilist[index].praise + 1;
} else {
Toast("取消点赞成功");
that.tiezilist[index].is_praise = 2;
that.tiezilist[index].praise = that.tiezilist[index].praise - 1;
}
that.tiezilist = that.tiezilist;
var url = "/api/forum/praise";
var params = {
forum_id: item.id
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
},
// 进入video
govideo(src) {
console.log(src);
this.$router.push({
path: "/videoplay",
query: { url: src }
});
},
getfen(id) {
this.fenlei = id;
this.page = 1;
this.tiezilist = [];
this.getteizilist();
},
hidetanceng() {
this.showpublish = false;
},
// 预览图片
previewimg(index, indexk, item) {
wx.previewImage({
current: item, // 当前显示图片的http链接
urls: this.tiezilist[index].images // 需要预览的图片http链接列表
});
},
duanshipin(id, item) {
console.log(id, item.id);
if (item.id == 1) {
this.$router.push({
path: "/duanshipinlist",
query: {
id: item.id
}
});
} else if (item.id == 2) {
this.$router.push({
path: "/duanshipinlist",
query: {
id: item.id
}
});
} else if (item.id == 3) {
this.$router.push({
path: "/duanshipinlist",
query: {
id: item.id
}
});
} else if (item.id == 4) {
this.$router.push({
path: "/duanshipinlist",
query: {
id: item.id
}
});
}
else if (item.id == 5) {
this.$router.push({
path: "/zhongmianzixun"
});
} else if (item.id == 6) {
this.$router.push({
path: "/articledetail",
query: {
name: '中面资质'
}
});
}
else if (item.id == 7) {
this.$router.push({
path: "/tousuweiquan"
});
}
else if (item.id == 8) {
this.$router.push({
path: "/mykaoshi"
});
}
else if (item.id == 8) {
this.$router.push({
path: "/mykaoshi"
});
}
}
}
};
</script>
<style scoped>
@import "../../style/homepage.css";
.van-picker {
position: fixed;
bottom: 0;
left: 0;
z-index: 999;
width: 100%;
}
.nodata {
color: #999;
font-size: 0.28rem;
text-align: center;
margin: 2rem auto 0;
}
</style>