-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.js
130 lines (122 loc) · 3.76 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
const App = require('./utils/ald-stat.js').App;
var fundebug = require('./utils/fundebug.0.6.1.min.js')
fundebug.init(
{
apikey: "4b8c4668c63e5a97704debea971a8b9d5698520a15432683cde00a95fc4b233f",
silentInject: true,
setSystemInfo: true,
monitorHttpData: true,
silent: true
})
var network = require("./utils/network.js")
var startTime = Date.now();//启动时间
//app.js
App({
onLaunch: function () {
var that = this;
that.getUserInfo(function () {
console.log("用户信息:", that.globalData.userInfo);
});
},
onShow: function () {
this.aldstat.sendEvent('小程序的启动时长', {
time: Date.now() - startTime
})
},
onError: function (err) {
fundebug.notifyError(err);
},
/**
* 获取用户信息
* @param success 成功回调函数
* @param login 登录回调函数
*/
getUserInfo(success, login) {
var that = this;
var userInfo = wx.getStorageSync("userInfo");
if (userInfo == "") {
wx.login({
success: function (res) {
if (res.code) {
var url = that.globalData.siteRoot + "/Mpa/Weixinopen/OnLogin";
//发起网络请求
network.request(url, {
code: res.code
},
function (json) {
var result = json.result;
if (result.success) {
wx.setStorageSync('sessionId', result.sessionId);
console.log('sessionId=>', wx.getStorageSync('sessionId'));
console.log('userId=>', result.userId);
//有userId,就可以获取用户信息
if (result.userId) {
that.getUserInfoById(result.userId);
} else {
if (login != undefined) {
login();
}
}
}
}
)
} else {
console.log('登录失败!' + res.errMsg)
}
}
});
} else {
//有缓存,但数据库可能已经把用户删除了,这里需要再次从数据库获取用户信息,确认真的有用户存在
//这个概率非常小,所以这里不作验证,避免给服务器造成压力
success();
}
},
getUserInfoById(userId, success) {
var that = this;
var url = that.globalData.siteRoot + "/api/services/app/weixinUser/GetWeixinUserByIdToMiniAsync";
var params = {
id: userId
};
network.request(url, params, function (json) {
that.globalData.userInfo = json.result;
wx.setStorageSync('userInfo', json.result);
if (success != undefined) {
success();
}
})
},
getSetting(success) {
var that = this;
var url = that.globalData.siteRoot + "/api/services/app/SystemSettings/GetSettingToMiniAsync";
network.requestLoading(url, {}, "加载中...", function (res) {
if (success != undefined) {
success(res.result);
}
})
},
//提交formId
commitFormId(formId){
var that=this;
var url=that.globalData.siteRoot + "/api/services/app/FormIdContainer/CommitFormIdToMiniAsync";
var userInfo=wx.getStorageSync('userInfo');
if(userInfo=="")return;
var params={
formId:formId,
weixinUserId:userInfo.id
}
network.request(url,params,function(res){
console.log("commitFormId",res);
});
},
globalData: {
userInfo: null,
siteRoot: "https://das.mynatapp.cc",
//siteRoot: "https://zuche.shensigzs.com",
diyID: "582425050df045409a546712c6517fd4",//专属ID,请到后台--小程序管理--小程序源码管理 页面获取
setting: null,//系统配置
day: null,
phoneNumber: null,
pickUpCar: null,//以后都使用这个
returnCar: null//以后都使用这个
}
})