1 Star 1 Fork 0

杨小瑞/wx-mall

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 4.02 KB
一键复制 编辑 原始数据 按行查看 历史
yangfeng 提交于 2021-03-09 22:02 . first commit
App({
onLaunch: function () {
//获取小程序更新机制兼容
if (wx.canIUse('getUpdateManager')) {
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.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
})
})
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
})
}
},
globalData: {
userInfo: {
nickName: 'Hi,游客',
userName: '点击去登录',
avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
},
token: '',
userCoupon: 'NO_USE_COUPON',//默认不适用优惠券
courseCouponCode: {},//购买课程的时候优惠券信息
},
// 下拉刷新
onPullDownRefresh: function () {
// 显示顶部刷新图标
wx.showNavigationBarLoading();
var that = this;
// 隐藏导航栏加载框
wx.hideNavigationBarLoading();
// 停止下拉动作
wx.stopPullDownRefresh();
},
// 更新小程序
updateManager: function () {
//获取系统信息 客户端基础库
wx.getSystemInfo({
success: function (res) {
//基础库版本比较,版本更新必须是1.9.90以上
const v = util.compareVersion(res.SDKVersion, '1.9.90');
if (v > 0) {
const manager = wx.getUpdateManager();
manager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
//console.log(res.hasUpdate);
});
manager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
manager.applyUpdate();
}
}
})
});
manager.onUpdateFailed(function () {
// 新的版本下载失败
});
} else {
// wx.showModal({
// title: '温馨提示',
// content: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
// })
}
},
})
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangfeng005/wx-mall.git
git@gitee.com:yangfeng005/wx-mall.git
yangfeng005
wx-mall
wx-mall
master

搜索帮助