Browse Source

Signed-off-by: yukangzhe <382985154@qq.com>

yukangzhe 4 years ago
parent
commit
ca60515ab0
3 changed files with 79 additions and 25 deletions
  1. 1 1
      pages/index/index.wxml
  2. 77 24
      pages/login/login.js
  3. 1 0
      pages/login/login.wxml

+ 1 - 1
pages/index/index.wxml

@@ -23,7 +23,7 @@
 			<swiper class="banner" autoplay circular interval="3000">
 				<block wx:for="{{bannerList}}" wx:key="index">
 					<swiper-item class="banner-box" >
-						<image lazy-load mode="widthFix" class="bb-image" src="{{item.imageUrl}}"></image>
+						<image lazy-load mode="aspectFill" class="bb-image" src="{{item.imageUrl}}"></image>
 					</swiper-item>
 				</block>
 			</swiper>

+ 77 - 24
pages/login/login.js

@@ -8,7 +8,60 @@ Page({
    */
   data: {
     isPage: '',
-    isId: ''
+    isId: '',
+    imageUrl: app.globalData.imageUrl,
+  },
+
+  update: function () {
+    const updateManager = wx.getUpdateManager()
+    const that = this
+    updateManager.onCheckForUpdate(function (res) {
+      // 请求完新版本信息的回调
+      if(res.hasUpdate){//发现新版本,提示更新
+        updateManager.onUpdateReady(function () {
+          wx.showModal({
+            title: '更新提示',
+            content: '发现新版本,请重新启动小程序',
+            showCancel: false,
+            success(res) {
+              if (res.confirm) {
+                // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+                updateManager.applyUpdate()
+              }
+            }
+          })
+        })
+      } else {//没有新版本,直接进行下一步获取相关参数
+        that.getVersion()
+      }
+    })
+
+    updateManager.onUpdateReady(function () {
+      wx.showModal({
+        title: '更新提示',
+        content: '新版本已经准备好,是否重启应用?',
+        success(res) {
+          if (res.confirm) {
+            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+            updateManager.applyUpdate()
+          }
+        }
+      })
+    })
+
+    updateManager.onUpdateFailed(function () {
+      // 新版本下载失败
+      wx.showModal({
+        title: '提示',
+        content: '更新失败,请检查网络或者重新启动小程序',
+        showCancel: false,
+        success(res){
+          if(res.confirm){
+            updateManager.applyUpdate()
+          }
+        }
+      })
+    })
   },
 
   /**
@@ -19,13 +72,14 @@ Page({
       title: '加载中',
       mask: true
     })
-    if(options.isPage){
+    if (options.isPage) {
       this.setData({
         isPage: options.isPage,
         isId: options.isId
       })
     }
-    this.getVersion()
+    this.update()
+    
   },
 
   //判断版本号
@@ -50,14 +104,13 @@ Page({
       success: res => {
         util.doPost(
           'getOpenId', {
-          appId: app.globalData.appId,
-          code: res.code
-        },
+            appId: app.globalData.appId,
+            code: res.code
+          },
         ).then(res => {
           if (res.success == 1) {
             wx.setStorageSync('openId', res.data.openId)
-            wx.hideLoading({
-            })
+            wx.hideLoading({})
           }
         })
       },
@@ -85,10 +138,10 @@ Page({
       })
       util.doPost(
         'getPhoneNumber', {
-        encryptedData: e.detail.encryptedData,
-        iv: e.detail.iv,
-        openId: wx.getStorageSync('openId'),
-      }
+          encryptedData: e.detail.encryptedData,
+          iv: e.detail.iv,
+          openId: wx.getStorageSync('openId'),
+        }
       ).then(rs => {
         if (rs.success > 0) {
           wx.setStorageSync('phone', rs.data.phoneNumber);
@@ -110,8 +163,8 @@ Page({
   autoLogin: function () {
     util.doPost(
       'autoLogin', {
-      openId: wx.getStorageSync('openId'),
-    }
+        openId: wx.getStorageSync('openId'),
+      }
     ).then(rs => {
       wx.hideLoading()
       if (rs.success > 0) {
@@ -119,16 +172,16 @@ Page({
         wx.showToast({
           title: '登录成功',
         })
-       if(this.data.isPage){
-        wx.redirectTo({
-          url: '/pages/'+this.data.isPage+"/"+this.data.isPage+"?proId="+this.data.isId,
-        })
-       } else {
-        wx.switchTab({
-          url: '/pages/index/index'
-        })
-       }
-        
+        if (this.data.isPage) {
+          wx.redirectTo({
+            url: '/pages/' + this.data.isPage + "/" + this.data.isPage + "?proId=" + this.data.isId,
+          })
+        } else {
+          wx.switchTab({
+            url: '/pages/index/index'
+          })
+        }
+
       } else {
         wx.showToast({
           title: rs.errMsg,

+ 1 - 0
pages/login/login.wxml

@@ -1,5 +1,6 @@
 <!--pages/Components/campusBinding/campusBinding.wxml-->
 <view class="main">
+	<image lazy-load class="background" mode="aspectFill" src="{{imageUrl ? imageUrl+'bg0608.png': ''}}"></image>
 	<image lazy-load class="logo" mode="aspectFill" src="/images/logo.png"></image>
 	<!-- <text class="name">艾克斯朗学生端</text> -->
 	<button class="button" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" hidden="{{btnShow}}">