-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
190 lines (183 loc) · 5.13 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
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
//app.js
var util = require('./utils/util.js');
App({
onLaunch: function () {
var that = this;
this.getTlist();
},
hasLogin: function () {//是否登录
wx.getStorage({
key: 'userInfo',
success: function (res) {
},
fail: function (res) {
wx.showModal({
title: '提示',
content: '请先登录后再继续操作',
success (res) {
if (res.confirm) {
wx.reLaunch({
url:"/pages/my/index"
})
} else if (res.cancel) {
wx.navigateBack({//返回
delta: 1
})
}
}
})
}
});
},
hasPhone: function () {//是否绑定手机号
wx.getStorage({
key: 'userInfo',
success: function (res) {
var phone = res.data.phone
if(phone==''||phone==null){
wx.showModal({
title: '提示',
content: '请先绑定手机后再继续操作',
success (res) {
if (res.confirm) {
wx.reLaunch({
url:"/pages/my/info"
})
} else if (res.cancel) {
wx.navigateBack({//返回
delta: 1
})
}
}
})
}
},
fail: function (res) {
}
});
},
//获取类别列表
getTlist() {
var self = this;
wx.request({
url: self.globalData.baseUrl + '/source/json/category.json',
data: {},
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
//划分分类
var _data = res.data.data, _tlist = [];
//选出一级分类,放入firstType
for (var x in _data) {
if (_data[x].pid == 0) {
_tlist.push({
firstType: _data[x],
second: []
})
}
//判断是否存在二级分类
if (self.globalData.navigate_type == 1 && _data[x].pid != 0) {
self.globalData.navigate_type = 2;
}
}
//如果存在二级分类
if (self.globalData.navigate_type == 2) {
//选出二级分类,放入对应的secondList
for (var x in _data) {
for (var y in _tlist) {
if (_data[x].pid == _tlist[y].firstType.id) {
_tlist[y].second.push(_data[x]);
}
}
}
//整理二级分类
for (var x in _tlist) {
//两行显示
if (_tlist[x].second.length >= 10) {
var _slist = _tlist[x].second;
_tlist[x].secondList = [];
_tlist[x].thirdList = [];
for (var y in _slist) {
if (y % 2) {
_tlist[x].thirdList.push(_slist[y]);
} else {
_tlist[x].secondList.push(_slist[y]);
}
}
}
}
} else {
_tlist[0].secondList = [];
_tlist[0].thirdList = [];
for (var x in _tlist) {
//两行显示
if (_tlist.length >= 10) {
if (x % 2) {
_tlist[0].thirdList.push(_tlist[x].firstType);
} else {
_tlist[0].secondList.push(_tlist[x].firstType);
}
} else {
_tlist[0].secondList.push(_tlist[x].firstType);
}
}
}
self.globalData.tlist = _tlist;
}
})
},
loginFail: function () {
var that = this;
wx.showModal({
content: '登录失败,请允许获取用户信息,如不显示请删除小程序重新进入',
showCancel: false
});
that.login();
},
setUserInfo: function (data) { //将用户信息缓存保存
this.globalData.userInfo = data;
wx.setStorage({
key: "userInfo",
data: data
})
},
hasUpdate() {
// 检查更新
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
// 监听更新完成事件(更新动作微信会自动触发,无需开发者调用)
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
wx.showToast({
title: '更新失败!',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
})
})
}
})
},
globalData: {
userInfo: '',
sk: '',
URL: "http://134.175.114.99",
ad: [],
baseUrl: 'https://nginx.ngrok2.xiaomiqiu.cn',
tlist: [],
navigate_type:1,
}
})