1 Star 0 Fork 104

陌上少年 / 租车小程序前端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.37 KB
一键复制 编辑 原始数据 按行查看 历史
shensi88 提交于 2018-08-04 10:28 . 加入阿拉丁统计
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) {
url = that.globalData.siteRoot + "/api/services/app/weixinUser/GetWeixinUserByIdToMiniAsync";
network.request(url, {
id: result.userId
},
function (json) {
that.globalData.userInfo = json.result;
wx.setStorageSync('userInfo', json.result);
if (success != undefined) {
success();
}
})
} else {
if (login != undefined) {
login();
}
}
}
}
)
} else {
console.log('登录失败!' + res.errMsg)
}
}
});
} else {
//有缓存,但数据库可能已经把用户删除了,这里需要再次从数据库获取用户信息,确认真的有用户存在
//这个概率非常小,所以这里不作验证,避免给服务器造成压力
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);
}
})
},
globalData: {
userInfo: null,
//siteRoot: "https://das.mynatapp.cc",
siteRoot: "https://zuche.shensigzs.com",
diyID: "",//专属ID,请到后台--小程序管理--小程序源码管理 页面获取
setting: null,//系统配置
day: null,
phoneNumber: null,
pickUpCar: null,//以后都使用这个
returnCar: null//以后都使用这个
}
})
JavaScript
1
https://gitee.com/xiaoxiao_oschina/zuchemini.git
git@gitee.com:xiaoxiao_oschina/zuchemini.git
xiaoxiao_oschina
zuchemini
租车小程序前端
master

搜索帮助