瀏覽代碼

新增版本更新

lilei 1 年之前
父節點
當前提交
cc3dc59003
共有 8 個文件被更改,包括 513 次插入355 次删除
  1. 3 0
      App.vue
  2. 2 0
      config/api.js
  3. 112 0
      libs/tools.js
  4. 4 4
      pages/index/index.vue
  5. 41 4
      pages/login/index.vue
  6. 1 1
      store/index.js
  7. 123 119
      unpackage/dist/dev/app-plus/app-service.js
  8. 227 227
      unpackage/dist/dev/app-plus/app-view.js

+ 3 - 0
App.vue

@@ -1,5 +1,8 @@
 <script>
 	export default {
+		globalData: {
+			version: '' // 当前版本号
+		},
 		onLaunch: function() {
 			console.log('App Launch')
 		},

+ 2 - 0
config/api.js

@@ -2,6 +2,8 @@ const http = uni.$u.http
 
 // 登录
 export const login = (params, config = {custom:{auth:false}}) => http.post('/auth/login', params, config)
+// 查询最新版本信息
+export const getSysVersion = (params, config = {custom:{auth:false}}) => http.post('/sysVersion/getLatest', params, config)
 // 退出
 export const logout = (data) => http.get('/auth/logout', data)
 // 用户信息

+ 112 - 0
libs/tools.js

@@ -15,4 +15,116 @@ export function playAudio(type){
 	innerAudioContext.onEnded(res => {
 		innerAudioContext.destroy()
 	})
+}
+/**
+ * //设置应用版本号对应的缓存信息
+ * @param {Object} currTimeStamp 当前获取的时间戳
+ */
+export const  setStorageForAppVersion = function(currTimeStamp){
+	uni.setStorage({
+		key: 'tip_version_update_time',
+		data: currTimeStamp,
+		success: function () {
+			console.log('setStorage-success');
+		}
+	});
+}
+/**
+ * 进行版本型号的比对 以及下载更新请求
+ * @param {Object} server_version 服务器最新 应用版本号
+ * @param {Object} curr_version 当前应用版本号
+ * isQzgx 是否强制更新
+ * callback 登录
+ */
+export const checkVersionToLoadUpdate = function(newVersion,type,callback){
+	if(newVersion.version == '2001'||newVersion.version == '2002'){
+		newVersion.version = 201
+	}
+	const curVer = getApp().globalData.version  // 当前版本信息
+	console.log(newVersion)
+	console.log(curVer)
+	if(!newVersion || !curVer){
+		callback()
+		return
+	}
+	const curr_version = curVer && curVer.version ? curVer.version.replace(/\./g,'') : ''
+	const server_version = newVersion && newVersion.version ? newVersion.version : '' // 最新版本信息
+	const isQzgx = newVersion && newVersion.forceUpgrade != 1
+	let isWifi = plus.networkinfo.getCurrentType()!=3 ? '有新的版本发布,检测到您目前非Wifi连接,' : '有新的版本发布,'
+	let msg = isWifi + (!isQzgx ? '请立即更新?' : '是否立即更新版本?')
+	// 下载app并安装
+	let downloadApp = function(downloadApkUrl){
+		uni.showLoading({
+			title: '正在更新中...',
+			mask: true,
+		});
+		var dtask = plus.downloader.createDownload( downloadApkUrl, {}, function ( d, status ) {
+			// 下载完成  
+			if ( status == 200 ) {   
+				plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){  
+					uni.showToast({
+						icon: 'none',
+						title: '安装失败', 
+						duration: 1500  
+					});  
+				})
+				uni.hideLoading()
+			} else {  
+				 uni.showToast({  
+					icon: 'none',
+					title: '更新失败',
+					duration: 1500  
+				 });  
+			}
+		});  
+		dtask.start();
+	}
+	// 打开ios 应用市场
+	let openIosAppSotre = function(downloadUrl){
+		//在App Store Connect中的App Store下的app信息,可找到appleId
+		plus.runtime.launchApplication({
+			action: downloadUrl
+		}, function(e) {
+			console.log('Open system default browser failed: ' + e.message);
+		})
+	}
+	console.log(server_version,curr_version)
+	if(Number(server_version) > Number(curr_version)){
+		uni.showModal({
+			title: msg,
+			content: '更新内容:'+newVersion.upgradeContent,
+			showCancel: isQzgx,
+			confirmText:'立即更新',
+			cancelText:'稍后进行',
+			success: function (res) {
+				if (res.confirm) {
+					// 清空缓存token
+					let tmp = uni.getStorageSync('lifeData');
+					tmp = tmp ? tmp : {};
+					tmp['vuex_token'] = '';
+					uni.setStorageSync('lifeData', tmp);
+					if(curVer.platform == 'android'){
+						//设置 最新版本apk的下载链接
+						downloadApp(newVersion.attachment);
+					}else{
+						openIosAppSotre(newVersion.downloadUrl)
+					}
+				} else if (res.cancel) {
+					console.log('稍后更新');
+					callback()
+				}
+			}
+		});
+		uni.hideLoading();
+	}else{
+		if(type){
+			uni.showToast({
+				icon: 'none',
+				title: '已是最新版本',
+				duration: 1500  
+			}); 
+		}else{
+			callback()
+		}
+	}
 }

+ 4 - 4
pages/index/index.vue

@@ -88,7 +88,7 @@
 					if(res.status == 200){
 						this.$store.state.vuex_token = ''
 						this.$store.state.vuex_user = ''
-						uni.navigateTo({
+						uni.redirectTo({
 							url: "/pages/login/index"
 						})
 					}
@@ -162,19 +162,19 @@
 		.card-box{
 			border: 1px solid #eee;
 			border-radius: 20upx;
-			box-shadow: 1px 2px 5px #f8f8f8;
-			margin: 30upx;
+			margin: 20rpx 40rpx;
 			background: #fff;
 		}
 		.grid-box{
 			display: flex;
 			justify-content: space-around;
-			padding:20upx;
+			padding:0;
 			> view{
 				width: 50%;
 				display: flex;
 				flex-direction: column;
 				align-items: center;
+				border: 1px solid #eee;
 				.iconfont{
 					font-size: 120upx;
 					padding: 20upx 0;

+ 41 - 4
pages/login/index.vue

@@ -5,7 +5,7 @@
 			 <view>iSCM 检货系统</view>
 		</view>
 		<view class="u-forms">
-			<form @submit="formSubmit">
+			<form @submit="AndroidCheckUpdate">
 				<view class="uni-form-item">
 					<view class="uni-form-title">
 						<text class="iconfont icon-icon-test23"></text>
@@ -31,7 +31,8 @@
 </template>
 
 <script>
-	import { login } from '@/config/api.js'
+	import { login, getSysVersion } from '@/config/api.js'
+	import { checkVersionToLoadUpdate } from '@/libs/tools.js'
 	export default {
 		data() {
 			return {
@@ -41,6 +42,19 @@
 			};
 		},
 		onLoad() {
+			//#ifdef APP-PLUS
+			  uni.getSystemInfo({
+				  success:(res) => {
+					  console.log(res)
+					  // 获取最新版本信息
+					  plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
+						wgtinfo.platform = res.platform
+					  	getApp().globalData.version = wgtinfo
+					  })
+				  }  
+			  })
+			//#endif
+			
 			const devInfo = uni.getDeviceInfo()
 			this.$store.state.vuex_deviceId = devInfo.deviceId
 			
@@ -52,9 +66,31 @@
 			}
 		},
 		methods: {
+			// 版本更新
+			AndroidCheckUpdate(){
+				let _this = this
+				uni.showLoading({
+					title: '正在登录...'
+				});
+				getSysVersion({versionType:uni.getSystemInfoSync().platform == "ios"?'IOS':'ANDROID', applyCode: 'scsb'}).then(ret => {
+					console.log(ret)
+					if(ret.status == 200){
+						if(ret.data){
+							this.$store.state.vuex_versionInfo = ret.data || null
+							checkVersionToLoadUpdate(ret.data,0,_this.formSubmit)
+						}else{
+							_this.formSubmit();
+						}
+					}
+					uni.hideLoading()
+				})
+			},
 			// 登录
 			async formSubmit(e) {
-				const formdata = e.detail.value
+				const formdata = {
+					username: this.username,
+					password: this.password
+				}
 				if(formdata.username && formdata.password){
 					const res = await login(formdata)
 					if(res.status == 200){
@@ -66,10 +102,11 @@
 						 password: this.password
 						}
 						uni.setStorageSync('account',this.$store.state.vuex_userAccount)
-						uni.navigateTo({
+						uni.redirectTo({
 							url: "/pages/index/index"
 						})
 					}
+					uni.hideLoading()
 				}else{
 					uni.$u.toast("请输入用户名和密码")
 				}

+ 1 - 1
store/index.js

@@ -34,8 +34,8 @@ const store = new Vuex.Store({
 		// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
 		vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {name: '默认'},
 		vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
+		vuex_versionInfo: lifeData.vuex_versionInfo ? lifeData.vuex_versionInfo : {}, // 版本信息
 		// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
-		vuex_version: '1.0.1',
 		vuex_supplierList:[], // 供应商列表
 		vuex_sparePartsTypeList: [],//散件入库类型
 		// 盘点类型

文件差異過大導致無法顯示
+ 123 - 119
unpackage/dist/dev/app-plus/app-service.js


文件差異過大導致無法顯示
+ 227 - 227
unpackage/dist/dev/app-plus/app-view.js


部分文件因文件數量過多而無法顯示