Browse Source

bug修改

1004749546@qq.com 4 years ago
parent
commit
26a0dbdb2f
1 changed files with 43 additions and 1 deletions
  1. 43 1
      pages/userCenter/index.vue

+ 43 - 1
pages/userCenter/index.vue

@@ -35,6 +35,7 @@
 				<u-cell-item icon="phone" icon-size="40" :icon-style="{color:'#f00'}" @click="callPhone" title="联系客服"></u-cell-item>
 				<u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="3" @click="toPage" title="服务协议"></u-cell-item>
 				<u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#55aa00'}" index="4" @click="toPage" title="关于我们"></u-cell-item>
+				<u-cell-item  icon="error-circle" icon-size="38" :icon-style="{color:'#aaaaff'}" :value="version" @click="checkUpdate" title="版本检查"></u-cell-item>
 			</u-cell-group>
 		</view>
 	</view>
@@ -46,7 +47,8 @@
 		data() {
 			return {
 				hasLogin: false,
-				userData: {}
+				userData: {},
+				version: ''
 			};
 		},
 		onShow() {
@@ -85,6 +87,46 @@
 					}
 				})
 			},
+			// 获取当前小程序版本
+			getVersion(){
+				const accountInfo = uni.getAccountInfoSync();
+				this.version = accountInfo.miniProgram.version
+				// console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
+			},
+			// 检查更新
+			checkUpdate(){
+				if (uni.canIUse('getUpdateManager')) {
+				      const updateManager = uni.getUpdateManager()
+				      updateManager.onCheckForUpdate(function (res) {
+				        console.log('onCheckForUpdate====', res)
+				        // 请求完新版本信息的回调
+				        if (res.hasUpdate) {
+				          console.log('res.hasUpdate====')
+				          updateManager.onUpdateReady(function () {
+				            uni.showModal({
+				              title: '更新提示',
+				              content: '新版本已经准备好,是否重启应用?',
+				              success: function (res) {
+				                console.log('success====', res)
+				                // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
+				                if (res.confirm) {
+				                  // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+				                  updateManager.applyUpdate()
+				                }
+				              }
+				            })
+				          })
+				          updateManager.onUpdateFailed(function () {
+				            // 新的版本下载失败
+				            uni.showModal({
+				              title: '已经有新版本了哟~',
+				              content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
+				            })
+				          })
+				        }
+				      })
+				    }
+			},
 			// 打开对应的页面
 			toPage(index){
 				console.log(index)