Browse Source

增加版本更新

空白格 3 years ago
parent
commit
54d927288e
5 changed files with 108 additions and 6 deletions
  1. 99 1
      App.vue
  2. 3 1
      common/apiurl.js
  3. 2 1
      common/config.js
  4. 3 0
      common/http.api.js
  5. 1 3
      pages/index/index.vue

+ 99 - 1
App.vue

@@ -1,14 +1,112 @@
 <script>
+	import {
+		config
+	} from '@/common/config.js';
 	export default {
+		data() {
+			return {
+				downloadUrl: ''
+			}
+		},
 		onLaunch: function() {
 			console.log('App Launch')
 		},
 		onShow: function() {
 			console.log('App Show')
+			this.getDownloadUrl();
+		},
+		methods: {
+			/**
+			 * 通过参数设置获取最新版本信息
+			 */
+			getVersion() {
+				uni.$u.api.getParameterApi({
+					key: 'parking.operation.version'
+				}).then(res => {
+					if (res.code === 200) {
+						if (res.msg !== config.version) {
+							uni.showModal({
+								title: '版本发布更新',
+								content: '发现新版本,请进行更新',
+								confirmText: '更新',
+								confirmColor: '#EE8F57',
+								success: (res) => {
+									if (res.confirm) {
+										this.downloadAppFile();
+									}
+								}
+							})
+						}
+					}
+				})
+			},
+			/**
+			 * 通过参数设置获取最新下载链接
+			 */
+			getDownloadUrl() {
+				uni.$u.api.getParameterApi({
+					key: 'parking.operation.package'
+				}).then(res => {
+					if (res.code === 200) {
+						this.downloadUrl = res?.msg
+						uni.getSystemInfo({
+							success: (res) => {
+								this.getVersion();
+							}
+						})
+					}
+				})
+			},
+			/**
+			 * 下载文件
+			 */
+			downloadAppFile() {
+				uni.showLoading({
+					title: '下载中',
+				})
+				let downloadTask = uni.downloadFile({ // 执行下载
+					url: this.downloadUrl,
+					success: downloadResult => {
+						// 下载成功
+						if (downloadResult.statusCode === 200) {
+							uni.showModal({
+								title: '',
+								content: '下载成功,确定现在更新吗?',
+								confirmText: '更新',
+								confirmColor: '#EE8F57',
+								success: function(res) {
+									if (res.confirm) {
+										plus.runtime.install( //安装
+											downloadResult.tempFilePath, {
+												force: true
+											},
+											function() {
+												plus.runtime.restart();
+												uni.navigateBack()
+											},
+											function(e) {
+												utils.showToast('更新失败');
+											}
+										);
+									}
+								}
+							});
+						}
+					},
+					complete: (res) => {
+						uni.hideLoading();
+					}
+				});
+				downloadTask.onProgressUpdate((res) => {
+					if (res.progress === 100) {
+						uni.hideLoading();
+					}
+				});
+			}
 		},
 		onHide: function() {
 			console.log('App Hide')
-		}
+		},
 	}
 </script>
 

+ 3 - 1
common/apiurl.js

@@ -3,8 +3,10 @@ export const apiurl = {
 	loginUrl: '/operator/auth/login',
 	// 退出登录接口
 	logoutUrl: '/operator/auth/loginOut',
-	// 获取数据字典
+	// 获取数据字典接口
 	getDictUrl: '/admin/dict/data/type/',
+	// 获取参数设置接口
+	getParameterUrl: '/admin/config/configKey/',
 	// 今日概况模块接口
 	todayOverview: {
 		// 获取今日概况接口

+ 2 - 1
common/config.js

@@ -1,3 +1,4 @@
 export const config = {
-	baseUrl: 'https://wx.hw.hongweisoft.com/parking/'
+	baseUrl: 'https://wx.hw.hongweisoft.com/parking/',
+	version: '0.1.1'
 }

+ 3 - 0
common/http.api.js

@@ -10,6 +10,8 @@ const install = (Vue, vm) => {
 	let logoutApi = (params = {}) => vm.$u.http.get(apiurl.logoutUrl, params);
 	// 获取字典数据
 	let getDictApi = (params = {}) => vm.$u.http.get(apiurl.getDictUrl + params.type);
+	// 获取参数设置接口
+	let getParameterApi = (params = {}) => vm.$u.http.get(apiurl.getParameterUrl + params.key);
 	// 今日概况
 	let todayOverviewApi = {
 		// 获取今日概况
@@ -184,6 +186,7 @@ const install = (Vue, vm) => {
 		loginApi,
 		logoutApi,
 		getDictApi,
+		getParameterApi,
 		todayOverviewApi,
 		operationalAnalysisApi,
 		statisticalReportApi,

+ 1 - 3
pages/index/index.vue

@@ -147,7 +147,7 @@
 		},
 		onLoad() {
 			// 为了验证token是否过期
-			this.getTodayData();
+			// this.getTodayData();
 		},
 		methods: {
 			/**
@@ -169,7 +169,6 @@
 									})
 								} else {
 									this.$refs.uToast.show({
-										loading: true,
 										message: res.msg || '退出登录失败!',
 										type: 'error'
 									})
@@ -188,7 +187,6 @@
 						this.todayData = res.data
 					} else {
 						this.$refs.uToast.show({
-							loading: true,
 							message: res.msg || '获取今日概况失败!',
 							type: 'error'
 						})