2 Star 1 Fork 0

LL / 外卖2.x

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.js 3.33 KB
一键复制 编辑 原始数据 按行查看 历史
LL 提交于 2019-05-21 18:28 . 5-21
import { locationInfo } from "./module/CaCheUtil";
//app.js
App({
onLaunch: function () {
var that = this;
this.getLocation((res) => { })
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
getLocation: function (cb) {
wx.getLocation({
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
locationInfo().setMyLocation(res);
cb(res);
},
fail: function (e) {
locationInfo().setMyLocation({ latitude: 30.64242, longitude: 104.04311 })
cb({ latitude: 30.64242, longitude: 104.04311 });
},
})
},
//检查更新强制更新
updated: function () {
var that = this;
let boo = wx.canIUse('getUpdateManager');
var version = ''
wx.getSystemInfo({
success: function (res) {
version = res.SDKVersion;
console.log(res, version)
}
})
//console.log('基础库支持?', version, wx.canIUse('getUpdateManager'))
if (boo) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log("是否有最新版本小程序?", res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否马上重启小程序?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '新版本小程序更新失败!',
content: '建议清理一下缓存再试!',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate()
}
}
})
})
} else {
wx.showModal({
title: '微信版本提示',
content: '当前基础库(' + version + ')不是最新版本,请更新微信APP后再来',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate()
}
}
})
}
},
globalData: {
userInfo: null,
}
})
微信
1
https://gitee.com/LL45808/takeaway_2x.git
git@gitee.com:LL45808/takeaway_2x.git
LL45808
takeaway_2x
外卖2.x
master

搜索帮助