-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
157 lines (152 loc) · 5.42 KB
/
app.js
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
//app.js
App({
globalData: {
url: {
host: "https://nmb.fastmirror.org",//https://tnmb.org http://adnmb1.com
thumb_img_url: "",//缩略图
full_img_url: "",//原图
timeline_url: "/Api/timeline?appid=wechatapp",//时间线
show_forum_url: "/Api/showf?appid=wechatapp",//获得板块内串
get_forum_url: "/Api/getForumList?appid=wechatapp",//获得板块列表
thread_url: "/Api/thread?appid=wechatapp",//获得串回复列表
get_thread_url: "/Api/ref?appid=wechatapp",//获得串内容
get_feed_url: "/Api/feed?appid=wechatapp",//获取所有订阅
add_feed_url: "/Api/addFeed?appid=wechatapp",//将串添加到订阅列表
del_feed_url: "/Api/delFeed?appid=wechatapp",//删除某个订阅的串
search_url: "/Api/search?appid=wechatapp",//搜索
getcdn_url: "/Api/getCdnPath?appid=wechatapp",//获取CDN地址
new_thread_url: "/Home/Forum/doPostThread.html?appid=wechatapp",//发送新串
new_reply_url: "/Home/Forum/doReplyThread.html?appid=wechatapp",//发送新回复
top_image_url: "https://mfweb.top/adao/getpicture.php",//首页大图
// get_cookie_url: "https://mfweb.top/adao/getcookie.php",//小程序不支持获取Cookie 暂时从服务器端拿
get_openid_url: "https://mfweb.top/adao/getopenid.php"//获取用户openid
},
userinfo: {//用户标识 用来保存收藏
user_openid: null,
},
sysinfo: {
sys_height: 0,//屏幕大小
sys_width: 0,
mode: 1//1:主岛 2:备胎岛
}
},
onLaunch: function () {
if (this.globalData.sysinfo.mode == 1) {
this.globalData.url.host = "https://nmb.fastmirror.org";
this.globalData.url.thumb_img_url = "http://nmbimg.fastmirror.org/thumb/";
this.globalData.url.full_img_url = "http://nmbimg.fastmirror.org/image/";
}
else if (this.globalData.sysinfo.mode == 2) {
this.globalData.url.host = "https://tnmb.org";
this.globalData.url.thumb_img_url = "https://tnmbstatic.fastmirror.org/Public/Upload/thumb/";
this.globalData.url.full_img_url = "https://tnmbstatic.fastmirror.org/Public/Upload/image/";
}
//获取CDN地址
var AdaoAPI = require('API/adao.js');
var that = this;
AdaoAPI.api_request(null, this.globalData.url.host + this.globalData.url.getcdn_url,null,
function(res){
var max = 0;
for (let i = 0; i < res.data.length; i++) {
if(res.data[i].rate > max)
{
that.globalData.url.thumb_img_url = res.data[i].url + "thumb/"
that.globalData.url.full_img_url = res.data[i].url + "image/"
max = res.data[i].rate;
}
}
},
function(){
console.log('get cdn error');
},null,null);
var res = wx.getSystemInfoSync();//获取屏幕尺寸
this.globalData.sysinfo.sys_width = res.windowWidth;
this.globalData.sysinfo.sys_height = res.windowHeight;
this.get_user_openid();
},
get_user_openid: function () {
//获取用户openid
if (this.globalData.userinfo.user_openid != null) return;
var t_openid = wx.getStorageSync('user_openid');
if (t_openid != null && t_openid != undefined && t_openid != "")//从本地缓存中拉取
{
this.globalData.userinfo.user_openid = t_openid;
this.get_feed();
return;
}
//直接拉取
wx.login({
success: function (res) {
var my = getApp();
wx.request({
url: my.globalData.url.get_openid_url + '?code=' + res.code,
data: {},
method: 'GET',
success: function (res) {
var my = getApp();
my.globalData.userinfo.user_openid = res.data.openid;
wx.setStorageSync('user_openid', res.data.openid);
console.log(my.globalData.userinfo.user_openid);
my.get_feed();
},
fail: function () {
console.log('fail');
}
})
},
fail: function () {
console.log("login fail!");
}
});
},
/*获取订阅串*/
get_feed: function (page = 1, success = null, ndata = null) {
var AdaoAPI = require('API/adao.js');
if (page == 1) wx.setStorageSync('FeedObj', null);
AdaoAPI.api_request(
"",
this.globalData.url.host + this.globalData.url.get_feed_url + "&uuid=" + this.globalData.userinfo.user_openid,
{ page: page },
function (res, ndata) {//success
console.log(res);
if (res.data.length == 0)//订阅已经拉取到最后一页了
{
if (success != null)
success(res.data, ndata, true);
console.log(wx.getStorageSync('FeedObj'));
}
else//还没有拉取完
{
var temp_obj = wx.getStorageSync('FeedObj');
if (temp_obj == null || temp_obj == undefined || temp_obj == "")
temp_obj = res.data;
else
temp_obj = temp_obj.concat(res.data);
wx.setStorageSync('FeedObj', temp_obj);
page++;
var app = getApp();
app.get_feed(page, success, ndata);
}
},
function (res, ndata) {//fail
if (success != null)
success(null, ndata, false);
},
function () {//finish
}, ndata);
},
showError: function (title){
wx.showToast({
title: title,
image: '../../icons/alert.png',
duration: 1500
});
},
showSuccess: function (title){
wx.showToast({
title: title,
icon: 'success',
duration: 1500
});
}
})