-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
157 lines (157 loc) · 3.63 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({
onLaunch: function() {
var that = this;
that.urls();
wx.getSystemInfo({
success: function(res) {
if (res.model.search("iPhone X") != -1) {
that.globalData.iphone = true;
}
if (res.model.search("MI 8") != -1) {
that.globalData.iphone = true;
}
}
});
that.login()
},
urls: function() {
var that = this;
that.globalData.urls = that.siteInfo.url + that.siteInfo.subDomain;
that.globalData.share = that.siteInfo.shareProfile;
},
siteInfo: require("config.js"),
login: function () {
var that = this;
var token = that.globalData.token;
if (token) {
wx.request({
url: that.globalData.urls + "/user/check-token",
data: {
token: token
},
success: function (res) {
if (res.data.code != 0) {
that.globalData.token = null;
that.login();
}
}
});
return;
}
wx.login({
success: function (res) {
wx.request({
url: that.globalData.urls + "/user/wxapp/login",
data: {
code: res.code
},
success: function (res) {
if (res.data.code == 1e4) {
that.globalData.usinfo = 0;
return;
}
if (res.data.code != 0) {
wx.hideLoading();
wx.showModal({
title: "提示",
content: "无法登录,请重试",
showCancel: false
});
return;
}
that.globalData.token = res.data.data.token;
that.globalData.uid = res.data.data.uid;
}
});
}
});
},
sendTempleMsg: function (orderId, trigger, template_id, form_id, page, postJsonString) {
var that = this;
wx.request({
url: that.globalData.urls + "/template-msg/put",
method: "POST",
header: {
"content-type": "application/x-www-form-urlencoded"
},
data: {
token: that.globalData.token,
type: 0,
module: "order",
business_id: orderId,
trigger: trigger,
template_id: template_id,
form_id: form_id,
url: page,
postJsonString: postJsonString
}
});
},
sendTempleMsgImmediately: function (template_id, form_id, page, postJsonString) {
var that = this;
wx.request({
url: that.globalData.urls + "/template-msg/put",
method: "POST",
header: {
"content-type": "application/x-www-form-urlencoded"
},
data: {
token: that.globalData.token,
type: 0,
module: "immediately",
template_id: template_id,
form_id: form_id,
url: page,
postJsonString: postJsonString
}
});
},
fadeInOut:function(that,param,opacity){
var animation = wx.createAnimation({
//持续时间800ms
duration: 300,
timingFunction: 'ease',
})
animation.opacity(opacity).step()
var json = '{"' + param + '":""}'
json = JSON.parse(json);
json[param] = animation.export()
that.setData(json)
},
isStrInArray:function(item, arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == item) {
return true;
}
}
return false;
},
getShopCartNum:function(){
var that = this
wx.getStorage({
key: 'shopCarInfo',
success: function (res) {
if (res.data) {
if (res.data.shopNum > 0) {
wx.setTabBarBadge({
index: 2,
text: '' + res.data.shopNum + ''
})
} else {
wx.removeTabBarBadge({
index: 2,
})
}
} else {
wx.removeTabBarBadge({
index: 2,
})
}
}
})
},
globalData: {
userInfo: null
}
})