1004749546@qq.com 4 лет назад
Родитель
Сommit
06f1d21db4
4 измененных файлов с 81 добавлено и 3 удалено
  1. 1 1
      package-lock.json
  2. 2 2
      package.json
  3. 35 0
      pages/index/index.vue
  4. 43 0
      pages/userCenter/index.vue

+ 1 - 1
package-lock.json

@@ -1,5 +1,5 @@
 {
-  "name": "zxyj-collect-mini-html",
+  "name": "zxyj-gather-mini-html",
   "version": "1.0.0",
   "lockfileVersion": 1,
   "requires": true,

+ 2 - 2
package.json

@@ -1,5 +1,5 @@
 {
-  "name": "zxyj-collect-mini-html",
+  "name": "zxyj-gather-mini-html",
   "version": "1.0.0",
   "description": "",
   "main": "main.js",
@@ -8,7 +8,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "http://git.chelingzhu.com/chelingzhu-web/zxyj-collect-mini-html.git"
+    "url": "http://git.chelingzhu.com/chelingzhu-web/zxyj-gather-mini-html.git"
   },
   "keywords": [],
   "author": "",

+ 35 - 0
pages/index/index.vue

@@ -102,6 +102,7 @@
 			}
 		},
 		onLoad() {
+			this.checkUpdate()
 			// 开启分享
 			uni.showShareMenu({
 				withShareTicket: true,
@@ -140,6 +141,40 @@
 				this.searchHandle()
 				this.getTotal()
 			},
+			// 检查更新
+			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: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
+				            })
+				          })
+				        }
+				      })
+				    }
+			},
 			// 打开查询弹窗
 			openSearch(){
 				if(this.hasLogin){

+ 43 - 0
pages/userCenter/index.vue

@@ -17,6 +17,7 @@
 			<u-cell-group>
 				<u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="0" @click="toPage" title="服务协议及隐私政策"></u-cell-item>
 				<u-cell-item  v-if="hasLogin" icon="lock" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @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 class="user-list quit">
@@ -34,6 +35,7 @@
 			return {
 				hasLogin: false,
 				userData: {},
+				version: '' // 小程序版本
 			};
 		},
 		onShow() {
@@ -55,6 +57,7 @@
 			}
 		},
 		onLoad() {
+			this.getVersion()
 			// 开启分享
 			uni.showShareMenu({
 				withShareTicket: true,
@@ -62,6 +65,46 @@
 			})
 		},
 		methods:{
+			// 获取当前小程序版本
+			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: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
+				            })
+				          })
+				        }
+				      })
+				    }
+			},
 			// 获取用户信息
 			getUserInfo(){
 				getUserInfo().then(res => {