123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
- })
- }
- this.onGetSysInfo()
- },
- globalData: {
- userInfo: {
- nickName: 'Hi,游客',
- userName: '点击去登录',
- avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
- },
- token: '',
- userCoupon: 'NO_USE_COUPON',//默认不适用优惠券
- courseCouponCode: {},//购买课程的时候优惠券信息
- isiPhoneX: false
- },
- onGetSysInfo() {
- // 先缓存获取
- let isiPhoneX = wx.getStorageSync('isiPhoneX') || false
- // 缓存没有 再获取
- if (!isiPhoneX) {
- wx.getSystemInfo({
- success: res => {
- // 手机品牌
- let modelmes = res.model;
- console.log('mode---------------lmes',modelmes)
- // 如果是 X,XS,XR,XS MAX 均可适配
- if (modelmes.indexOf('iPhone X') != -1) {
- // 存储型号
- this.globalData.isiPhoneX = true
- wx.setStorageSync('isiPhoneX', true)
- // 加入回调
- this.sysCallback && this.sysCallback()
- }
- },
- })
- } else {
- this.globalData.isiPhoneX = isiPhoneX
- }
- },
- // 下拉刷新
- 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: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
- // })
- }
- },
- })
- }
- })
|