getApp();
const app = getApp();
var communityId1 = "710101"; //默认为空赋值维多利亚湾社区id
var t = require("../../A3169927CCD47ACFC570F120B621F1F5.js"), e = require("../../7AB83E42CCD47ACF1CDE5645A701F1F5.js");
var forums = [];
var btns = [];
Page({
data: {
winWidth: 0,
winHeight: 0,
isHiddenToast: !0,
currentTab: 0,
reachBottom: !1,
hide_btn: !1,
page: 1,
loaded: !1,
hideHeader: !0,
pageSize: 20,
hasMoreData: !0,
contentlist: [],
newlist: [],
bbslist: [],
piclist: [], //首页播放的广告图片展示
btns: [],
scrollTop: 1,
delid: 0,
is_deled: {},
inputKey: !0, //1表示显示站内那个搜索,0时标题栏显示维多利亚湾社区几个字
fid: 0,
topheight: 40,
subscribe: 0,
mp4_type: "video", //wxml判断用
communityTitle: "",
},
isShowToast: function() {
this.setData({
isHiddenToast: !1
});
},
toastChange: function() {
this.setData({
isHiddenToast: !0
});
},
onShow: function() { //这里变量变了会实时更新
t.setBadge();
wx.setNavigationBarTitle({
title: app.globalData.communityTitle
});
},
//点击文章标题然后展示文字内容,点击这个直接进去showbbs.js
showbbs: function(t) {
var e = t.currentTarget.id, a = t.currentTarget.dataset.url, s = t.currentTarget.dataset.current, i = t.currentTarget.dataset.forum;
var way = 1; //表示从首页去bbs展示页
if (console.log(a), -1 != e.indexOf("wx")) wx.navigateToMiniProgram({
appId: e,
path: a,
extraData: {
foo: "bar"
},
envVersion: "release",
success: function(t) {
console.log("成功");
}
}); else {
if (e > 0)
{
var n = "/pages/bbs/showbbs?id=" + e + "¤t=" + s + "&forum=" + i + "&way=" + way;
//点击的bbs主题帖,这个时候对浏览记录加1
wx.cloud.callFunction({
name:'update_bbs_list',
data:{
a: 3,
authorId: app.globalData.openId, //传入此用户的openId
tid: parseInt(e), //此主题的tid传入,还真是这个e不一定是数字
views: 0, //随便给views传个值,这个零不起作用
},
success:res=>{
console.log("success update_bbs_list777");
},
fail: function() {
console.log("fail update_bbs_list777");
},
complete: function() {}
});
//对浏览记录加1结束
}
else n = "/pages/index/webview?url=" + a;
if ("" != a && null != a) if ("pages" == a.split("/")[1]) n = a;
wx.navigateTo({
url: n
});
}
},
//扫描方法,此功能暂时未开发
scan: function() {
wx.scanCode({
onlyFromCamera: !0,
success: function(t) {
var e = t.result;
if (e.indexOf("hlgnet.mobi/bbs/") > -1) {
var a = e.split("hlgnet.mobi/bbs/")[1].split("_");
wx.navigateTo({
url: "/pages/bbs/showbbs?id=" + a[1]
});
}
if (e.indexOf("bbs.hlgnet.com/info/") > -1) {
a = e.split("bbs.hlgnet.com/info/")[1].split("_");
// console.log("s = a.split("/") 8888=", a);
wx.navigateTo({
url: "/pages/bbs/showbbs?id=" + a[1]
});
}
}
});
},
search: function() {
wx.navigateTo({
url: "/pages/search/index?from=index"
});
},
//首页中间图标按钮进入goto,goto进入到bbs/index.js
goto: function(t) {
var e = t.currentTarget.dataset.url, a = t.currentTarget.dataset.action;
if ("module" == a) var s = "/pages/" + e; else if ("plugin" == a) s = e; else if ("login" == a) {
// s = "/pages/index/webview?url=" + e;
wx.setStorage({
key: "from_url",
data: s
}), wx.navigateTo({
url: "/pages/index/login"
});
}
wx.navigateTo({
url: s
});
},
selectarea: function(t){
wx.navigateTo({
url: "/pages/index/selectarea"
});
},
delbbs: function(t) {
var e = this.data.is_deled;
e[t] = {
key: 2
}, this.setData({
is_deled: e
});
},
onLoad: function(t) {
//存储首页bbs的列表信息
// console.log(" forums111=", forums);\
var e = this;
var communityId2 = app.globalData.communityId;
if (communityId2 == "110101" || communityId2 == "110102" || communityId2 == "110103") //如果是校友类社区,首页菜单和图标选择模板2的
{
forums = forums2;
btns = btns2;
} else {
forums = forums1;
btns = btns1;
}
wx.setStorage({
key: "forums",
data: forums
});
wx.setStorage({ //存储首页的几个图标
key: "btns",
data: btns
});
var a = decodeURIComponent(t.q);
// console.log("decodeURIComponent(t.q)r 111=",a);
//a输出没有定义,所以下面if逻辑没进去
if (a) {
var s = a.split("/");
// console.log("s = a.split("/") 111=",s);
// console.log("s = a.split("/") 8888=",s);
if ("bbs" == s[4] && wx.navigateTo({
url: "/pages/bbs/showbbs?id=" + s[5]
}), "bbs" == s[3] || "info" == s[3]) {
var i = s[4].split("_");
wx.navigateTo({
url: "/pages/bbs/showbbs?id=" + i[1]
});
}
}
// console.log("/pages/bbs/showbbs?id==9999991111");
t.current && (e.setData({
currentTab: t.current
}), e.getBbsList("正在加载数据"));
wx.getSystemInfo({
success: function(t) {
e.setData({
winWidth: t.windowWidth,
winHeight: t.windowHeight,
topheight: t.statusBarHeight
}), console.log(e.data.topheight);
}
});
e.getMsgList("正在加载数据"), wx.showShareMenu({
withShareTicket: !0,
menus: [ "shareAppMessage", "shareTimeline" ]
});
},
onShareTimeline: function() {
var t = wx.getStorageSync("UserInfo");
if (t) {
t.nickName;
var e = t.usersId;
}
return {
title: app.globalData.communityTitle,
path: "/pages/index/index?usersid=" + e,
success: function(t) {}
};
},
getMsgList: function(t) { //点击推荐展示的首页下面的bbs信息
var a = this;
a.setData({
inputKey: !1 //o 推荐页显示标题
});
wx.setNavigationBarTitle({
title: app.globalData.communityTitle
});
this.setData({
communityTitle: app.globalData.communityTitle
});
var communityId2 = app.globalData.communityId;
if (communityId2 == "110101" || communityId2 == "110102" || communityId2 == "110103") //如果是校友类社区,首页菜单和图标选择模板2的
{
forums = forums2;
btns = btns2;
} else {
forums = forums1;
btns = btns1;
}
wx.setStorage({
key: "forums",
data: forums
});
wx.setStorage({ //存储首页的几个图标
key: "btns",
data: btns
});
var r1 = wx.getStorageSync("forums"), g1 = wx.getStorageSync("btns");
var pic_list = wx.getStorageSync("pic_list");
a.setData({
boardlist: r1, //菜单栏
btns: g1, //图片按钮
})
if(app.globalData.communityId) //判断是否为空
{
var communityId = app.globalData.communityId;
}
else
{
var communityId = communityId1;//如果为空,赋值维多利亚湾社区id
}
var state = "0";
wx.cloud.callFunction({
name: 'search_bbs_list', //云函数的名称
data: {
a : 8,
adversting: 2, //等于2时为首页播放图片的bbs
communityId: communityId,
state: state, //状态,字符零表示正常,字符1表示删除的帖子
},
success: res => {
pic_list = res.result.data;
// console.log("pic_list===", pic_list);
a.setData({
piclist: pic_list, //播放的图片
})
wx.setStorage({ //存储首页的播放的图片
key: "pic_list",
data: pic_list
});
},
fail: err => {
console.error('search_bbs_list adversting', err)
}
});
//获取此新帖板块页面信息
if(app.globalData.communityId) //判断是否为空
{
var communityId = app.globalData.communityId;
}
else
{
var communityId = communityId1;//如果为空,赋值维多利亚湾社区id
}
var state = "0";
wx.cloud.callFunction({
name: 'search_bbs_list', //云函数的名称
data: {
a : 5,
parent_id: 0, //0表示没有父id,就是主帖
communityId: communityId,
state: state, //状态,字符零表示正常,字符1表示删除的帖子
},
success: res => {
var e = a.data.contentlist;
if (1 == a.data.page && (e = [])) {
var s = res.result.data;
1 == a.data.page && wx.setStorage({
key: "index_list",
data: s
}),
s.length < a.data.pageSize ? a.setData({
contentlist: e.concat(s),
piclist: pic_list, //播放的图片
boardlist: r1, //菜单栏
btns: g1, //图片按钮
hasMoreData: !1,
loaded: !0,
scrollTop: 1
}) : a.setData({
contentlist: e.concat(s),
piclist: pic_list, //播放的图片
boardlist: r1, //菜单栏
btns: g1, //图片按钮
hasMoreData: !0,
hideHeader: !0,
loaded: !0,
page: a.data.page + 1
});
}
},
fail: err => {
console.error('search_bbs_list', err)
}
})
},
// 将时间戳转换为几分钟前、几小时前
timeago: function (dateTimeStamp) {
// dateTimeStamp是一个时间毫秒,注意时间戳是秒的形式,在这个毫秒的基础上除以1000,就是十位数的时间戳。13位数的都是时间毫秒。
var minute = 1000 * 60; //把分,时,天,周,半个月,一个月用毫秒表示
var hour = minute * 60;
var day = hour * 24;
// var week = day * 7;
// var halfamonth = day * 15;
// var month = day * 30;
var now = new Date().getTime(); //获取当前时间毫秒
var diffValue = now - dateTimeStamp; //时间差
var result = '';
if (diffValue < 0) {
console.log("diffValue < 0 diffValue==", diffValue);
return result;
}
var minC = diffValue / minute; //计算时间差的分,时,天,周,月
var hourC = diffValue / hour;
var dayC = diffValue / day;
// var weekC = diffValue / week;
// var monthC = diffValue / month;
if (dayC >= 1 && dayC <= 3) {
result = "" + parseInt(dayC) + "天前";
} else if (hourC >= 1 && hourC <= 24) {
result = "" + parseInt(hourC) + "小时前";
} else if (minC >= 1 && minC <= 60) {
// console.log("result = minC",minC);
result = "" + parseInt(minC) + "分钟前";
} else if (minC < 1) {
// console.log("result = 刚刚");
result = "刚刚";
}
return result;
},
//首页上面点击各个菜单栏显示的bbs信息(只有贴子标题列)
getBbsList: function(t) {
var a = this, s = (a.data.currentTab, a.data.currentTab), i = wx.getStorageSync("forums"), o = i[s].fid, r = i[s].name;
// var n = wx.getStorageSync("input_key");
wx.setNavigationBarTitle({
title: r
});
var g = wx.getStorageSync("bbs_list" + o);
g && 1 == a.data.page && a.setData({
bbslist: g
}), a.setData({
inputKey: !0
});
// var l = wx.getStorageSync("UserInfo");//这个好像没啥用
// if (l.unionId) var d = l.unionId; else d = "";
//获取此bbs板块页面信息
if(app.globalData.communityId) //判断是否为空
{
var communityId = app.globalData.communityId;
}
else
{
var communityId = communityId1;//如果为空,赋值维多利亚湾社区id
}
var state = "0";
wx.cloud.callFunction({
name: 'search_bbs_list', //云函数的名称
data: {
a : 1,
fid : o,
parent_id: 0, //0表示没有父id,就是主帖
communityId: communityId,
state: state, //状态,字符零表示正常,字符1表示删除的帖子
},
success: res => {
// console.log("res.result.data666fid", o); //res的数据结构如下图
var e = a.data.bbslist;
if (1 == a.data.page && (e = [])) {
var s = res.result.data, i = !0; //n为inputKey是显示搜索的输入框
// 对s处理,生成lastpost,最后人回帖距离时间,比如45分钟前
for(var j=0;j<s.length;j++)
{
// var lastpost1 = this.timeago(s[j].dblastpost);
s[j].lastpost = this.timeago(s[j].dblastpost);
}
// console.log("res.result777==", s);
// 这个点击下面的bbs信息才走到这
1 == a.data.page && wx.setStorage({
key: "bbs_list" + o,
data: s
}),
s.length < a.data.pageSize ? a.setData({
bbslist: e.concat(s),
hasMoreData: !1,
inputKey: i,
loaded: !0
}) : a.setData({
bbslist: e.concat(s),
hasMoreData: !0,
hideHeader: !0,
loaded: !0,
page: a.data.page + 1
});
}
},
fail: err => {
console.error('search_bbs_list', err)
}
})
},
getNewList: function(t) {
var a = this, s = (a.data.currentTab, a.data.currentTab), i = wx.getStorageSync("forums"), n = wx.getStorageSync("input_key"), r = i[s].name;
// var o = i[s].fid;
wx.setNavigationBarTitle({
title: r
});
var g = wx.getStorageSync("newlist");
g && 1 == a.data.page && a.setData({
newlist: g
}), a.setData({
inputKey: !0 //n
});
//获取此新帖板块页面信息
if(app.globalData.communityId) //判断是否为空
{
var communityId = app.globalData.communityId;
}
else
{
var communityId = communityId1;//如果为空,赋值维多利亚湾社区id
}
var state = "0";
wx.cloud.callFunction({
name: 'search_bbs_list', //云函数的名称
data: {
a : 4,
parent_id: 0, //0表示没有父id,就是主帖
communityId: communityId,
state: state, //状态,字符零表示正常,字符1表示删除的帖子
},
success: res => {
var e = a.data.newlist;
if (1 == a.data.page && (e = [])) {
var s = res.result.data, i = 1; //inputKey是显示搜索的输入框
// 对s处理,生成lastpost,最后人回帖距离时间,比如45分钟前
for(var j=0;j<s.length;j++)
{
// var lastpost1 = this.timeago(s[j].dblastpost);
s[j].lastpost = this.timeago(s[j].dblastpost);
}
// console.log("res.result777==", s);
// 这个点击下面的bbs信息才走到这
1 == a.data.page && wx.setStorage({
key: "newlist",
data: s
}),
s.length < a.data.pageSize ? a.setData({
newlist: e.concat(s),
hasMoreData: !1,
inputKey: i,
loaded: !0
}) : a.setData({
newlist: e.concat(s),
hasMoreData: !0,
hideHeader: !0,
loaded: !0,
page: a.data.page + 1
});
}
},
fail: err => {
console.error('search_bbs_list', err)
}
})
},
onPullDownRefresh: function() {
var t = this;
t.data.page = 1, t.setData({
hideHeader: !1
}), setTimeout(function() {
0 == t.data.currentTab ? t.getMsgList("正在刷新数据") : 1 == t.data.currentTab ? t.getNewList("正在刷新数据") : t.getBbsList("正在刷新数据"),
wx.stopPullDownRefresh();
}, 400);
},
handletouchmove: function(t) {},
bindChange: function(t) {
var e = t.detail.current;
if (this.data.page = 1, this.setData({
currentTab: e
}), 0 == e ? this.getMsgList("正在刷新数据") : 1 == e ? this.getNewList("正在刷新数据") : this.getBbsList("正在刷新数据"),
this.setData({
scrollTop: 1
}), e > 7) {
var a = e - 8;
this.setData({
toview: "f" + a
});
}
},
swichNav: function(t) {
if (this.data.currentTab === t.currentTarget.dataset.current) return !1;
// console.log("swichNav: function(t)==",this.data.currentTab);
// console.log("swichNav: function(t)==",t.currentTarget.dataset.current);
this.setData({
currentTab: t.currentTarget.dataset.current
});
},
onReachBottom: function() {
this.data.hasMoreData && (this.setData({
reachBottom: !0,
hasMoreData: !1
}), 0 == this.data.currentTab ? this.getMsgList("") : 1 == this.data.currentTab ? this.getNewList("") : this.getBbsList(""));
},
newbbs: t.throttle(function(t) {
var e = this.data.currentTab;
if (wx.showToast({
title: "正在加载数据",
icon: "loading",
duration: 0
}), e > 1) {
var a = wx.getStorageSync("forums")[e].fid;
wx.navigateTo({
url: "/pages/bbs/NewBbs?fid=" + a + "¤t=" + e
});
} else {
wx.getStorageSync("UserInfo").unionId ? wx.navigateTo({
url: "/pages/bbs/ListBoard?current=" + e
}) : (wx.setStorage({
key: "from_url",
data: "/pages/bbs/ListBoard?current=" + e
}), wx.navigateTo({
url: "/pages/index/login"
}));
}
}, 1e3),
onShareAppMessage: function(t) {
var e = wx.getStorageSync("UserInfo");
if (e) var a = e.nickName, s = e.usersId; else a = "观网网友", s = 0;
return {
title: a + " 分享了一个微信小程序",
path: "/pages/index/index?usersid=" + s,
success: function(t) {
console.log(t.shareTickets[0]), wx.getShareInfo({
shareTicket: t.shareTickets[0],
success: function(t) {
that.setData({
isShow: !0
}), console.log(that.setData.isShow);
},
fail: function(t) {
console.log(t);
},
complete: function(t) {
console.log(t);
}
});
},
fail: function(t) {
console.log(t);
}
};
}
});
贴入代码前段,更容易分析
s.length + 2 < a.data.pageSize ? a.setData({
contentlist: e.concat(s),
piclist: pic_list, //播放的图片
boardlist: r1, //菜单栏
btns: g1, //图片按钮
hasMoreData: !1,
loaded: !0,
scrollTop: 1
}) : a.setData({
contentlist: e.concat(s),
piclist: pic_list, //播放的图片
boardlist: r1, //菜单栏
btns: g1, //图片按钮
hasMoreData: !0,
hideHeader: !0,
loaded: !0,
page: a.data.page + 1
});