Commit 60727c92a3a4febd2ad91b5f0b082393eebd1d8c

Authored by yvan.ni
1 parent 298b7a25

小程序检查更新

Showing 1 changed file with 42 additions and 1 deletions
@@ -50,7 +50,7 @@ App({ @@ -50,7 +50,7 @@ App({
50 config: null, //门店参数 50 config: null, //门店参数
51 config2: null, //门店配置 51 config2: null, //门店配置
52 code: null, 52 code: null,
53 - user_id:null,// 6519870,//5682094, 53 + user_id:null,//1564704,// 10153869,// 6453964,//5682094,
54 buy_now:null, 54 buy_now:null,
55 picklist:null, //门店列表 55 picklist:null, //门店列表
56 wuliuprice: null, //物流价格表 56 wuliuprice: null, //物流价格表
@@ -78,6 +78,10 @@ App({ @@ -78,6 +78,10 @@ App({
78 onLaunch: function() { 78 onLaunch: function() {
79 wx.hideTabBar(); 79 wx.hideTabBar();
80 this.initExt(); 80 this.initExt();
  81 +
  82 + //检查更新
  83 + this.checkUpdateVersion();
  84 +
81 var t = this.globalData.setting; 85 var t = this.globalData.setting;
82 //console.log(t) 86 //console.log(t)
83 t.resourceUrl = t.url + "/template/mobile/rainbow"; 87 t.resourceUrl = t.url + "/template/mobile/rainbow";
@@ -665,6 +669,7 @@ App({ @@ -665,6 +669,7 @@ App({
665 this.globalData.dis_buy_obj=null; //等级卡的购买记录 669 this.globalData.dis_buy_obj=null; //等级卡的购买记录
666 this.globalData.storeFooter=null; //底部的导航 670 this.globalData.storeFooter=null; //底部的导航
667 this.globalData.full_screen=null; //全屏 671 this.globalData.full_screen=null; //全屏
  672 +
668 }, 673 },
669 674
670 clear_word:function (word) { 675 clear_word:function (word) {
@@ -767,6 +772,42 @@ App({ @@ -767,6 +772,42 @@ App({
767 }, 772 },
768 773
769 774
  775 + checkUpdateVersion() {
  776 + //判断微信版本是否 兼容小程序更新机制API的使用
  777 + if (wx.canIUse('getUpdateManager')) {
  778 + //创建 UpdateManager 实例
  779 + const updateManager = wx.getUpdateManager();
  780 + console.log('是否进入模拟更新');
  781 + //检测版本更新
  782 + updateManager.onCheckForUpdate(function(res) {
  783 + console.log('是否获取版本');
  784 + // 请求完新版本信息的回调
  785 + if (res.hasUpdate) {
  786 + //监听小程序有版本更新事件
  787 + updateManager.onUpdateReady(function() {
  788 +
  789 + //TODO 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 ( 此处进行了自动更新操作)
  790 + updateManager.applyUpdate();
  791 + })
  792 + updateManager.onUpdateFailed(function() {
  793 + // 新版本下载失败
  794 + wx.showModal({
  795 + title: '已经有新版本喽~',
  796 + content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开哦~',
  797 + })
  798 + })
  799 + }
  800 + })
  801 + } else {
  802 + //TODO 此时微信版本太低(一般而言版本都是支持的)
  803 + wx.showModal({
  804 + title: '溫馨提示',
  805 + content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  806 + })
  807 + }
  808 + },
  809 +
  810 +
770 811
771 812
772 813