uniapp更新、热更新弹框

uniapp更新、热更新弹框

<template>
	<view>
		<umask :show="uploadPopShow" @click="" :duration="0">
			<view class="page-height">
				<view class="page-content">
					<view class="wrap">
						<view class="popup-bg">
							<view class="popup-content popup-content-show">
								<view class="update-wrap">
									<image src="./img/img.png" class="top-img">
									</image>
									<view class="content">
										<text class="title">发现新版本V{{newVision}}</text>
										<view class="title-sub">app新版本升级:{{notes}}</view>
										<button class="btn" v-if="!pressShow" @click.stop="toUpLoad()">立即升级</button>
										<view class="sche-wrap" v-else>
											<view class="sche-bg">
												<view class="sche-bg-jindu" :style="{'width':pressValue+'%'}"></view>
											</view>
											<text
												class="down-text">下载进度:{{(downSize/1024/1024 ).toFixed(2)}}M/{{(fileSize/1024/1024).toFixed(2)}}M</text>
										</view>
									</view>
								</view>
								<image src="./img/close.png" class="close-ioc" @click.stop="closeUpdate()">
								</image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</umask>
	</view>
</template>
<script>
	import manifest from '@/manifest.json'
	import umask from "./u-mask/u-mask.vue"
	export default {
		name: "am-upVersion",
		components: {
			umask
		},
		data() {
			return {
				pressShow: false, 				downSize: null, 				pressValue: null, 				fileSize: null, 				uploadPopShow: null,
			};
		},
		props: {
			upLoadUrl: {
				type: String,
				default: "",
			},
			newVision: {
				type: String,
				default: "1.1.0",
			},
			appStoreUrl: {
				type: String,
				default: "",
			},
			notes: {
				type:String,
				default:"",
			}
		},
		watch: {
			newVision(newValue, oldValue) {
				if (newValue > manifest.versionName) {
					this.uploadPopShow = true
				}
			}
		},
		methods: {
			toUpLoad() {
				if (!this.upLoadUrl) {
					uni.showToast({
						title: "未检测到下载地址",
						icon: "none"
					})
					return
				}
				if (uni.getSystemInfoSync().platform === 'ios') {
					plus.runtime.launchApplication({
						action: this.appStoreUrl
					}, function(e) {
						console.log('Open system default browser failed: ' + e.message);
					});
					return
				}
				let that = this
				that.pressShow = true
				that.downloadTask = uni.downloadFile({
					url: that.upLoadUrl, 					success: (res) => {
						if (res.statusCode === 200) {
							that.pressShow = false
							that.uploadPopShow = false
														plus.runtime.install(res.tempFilePath)
													} else {
							uni.showToast({
								title: "安装包下载失败!请联系管理员。",
								icon: "none"
							})
						}
					}
				});
				that.downloadTask.onProgressUpdate((res) => {
					that.downSize = res.totalBytesWritten
					that.fileSize = res.totalBytesExpectedToWrite
					that.pressValue = res.progress
				});
			},
			closeUpdate() {
				this.pressShow = false
				this.uploadPopShow = false
				this.$root.newVision = ""
				if (this.downloadTask) {
					this.downloadTask.abort()
				}
			}
		},
	}
</script>
<style lang="scss">
	.page-height {
				display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: rgba($color: #000000, $alpha: .7);
	}
	.popup-bg {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 750rpx;
	}
	.popup-content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.popup-content-show {
		animation: mymove 300ms;
		transform: scale(1);
	}
	@keyframes mymove {
		0% {
			transform: scale(0);
		}
		100% {
			transform: scale(1);
		}
	}
	.update-wrap {
		width: 580rpx;
		border-radius: 18rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		background-color: #ffffff;
		padding: 170rpx 30rpx 0;
		.top-img {
			position: absolute;
			left: 0;
			width: 100%;
			height: 256rpx;
			top: -128rpx;
		}
		.content {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-bottom: 40rpx;
			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #6526f3;
			}
			.title-sub {
				text-align: center;
				font-size: 24rpx;
				color: #666666;
				padding: 30rpx 0;
			}
			.btn {
				width: 460rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #ffffff;
				font-size: 30rpx;
				height: 80rpx;
				line-height: 80rpx;
				border-radius: 100px;
				background-color: #6526f3;
				margin-top: 20rpx;
			}
		}
	}
	.close-ioc {
		width: 70rpx;
		height: 70rpx;
		margin-top: 30rpx;
	}
	.sche-wrap {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-end;
		padding: 10rpx 50rpx 0;
		.sche-wrap-text {
			font-size: 24rpx;
			color: #666;
			margin-bottom: 20rpx;
		}
		.sche-bg {
			position: relative;
			background-color: #cccccc;
			height: 30rpx;
			border-radius: 100px;
			width: 480rpx;
			display: flex;
			align-items: center;
			.sche-bg-jindu {
				position: absolute;
				left: 0;
				top: 0;
				height: 30rpx;
				min-width: 40rpx;
				border-radius: 100px;
				background: url(./img/round.png) #5775e7 center right 4rpx no-repeat;
				background-size: 26rpx 26rpx;
			}
		}
		.down-text {
			font-size: 24rpx;
			color: #5674e5;
			margin-top: 16rpx;
		}
	}
</style>
<template>
	<view class="content">
		<navigator url="" open-type="switchTab">
			<web-view ref="webview" :src="network" @message="message" @error="webviewError"></web-view>
		</navigator>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				network: '', 			};
		},
		onLoad(options) {
						this.network = options.network ? decodeURIComponent(options.network) : '';
		},
		methods: {
			message(event) {
				console.log('eventevent的值获取',event);
				const localPackageInfo = uni.getStorageSync('__NGN500__package_info__');
								let addCurrentTime = Math.floor(new Date().getTime() / 1000) + 60; 				let myCustomIdentifier = "GN500Client" +'/' +localPackageInfo['versionNum'];
				let deviceInfo = event.detail.data[0].deviceInfo + ' ' + myCustomIdentifier; 				uni.setStorage({
					key: 'userInfo',
					data: {
						'key': 'userInfo',
						'user': event.detail.data[0].user,
						'pwd': event.detail.data[0].pwd,
						'deviceInfo': deviceInfo,
						'timestamp': addCurrentTime, 					}
				});
				this.isSave();
			},
						isSave() {
				uni.getStorage({
					key: 'userInfo',
					success: function(res) {
						console.log('获取的数据为111: ', res.data);
						if (res.data !== '') {
														let userInfo = res.data;
							let currentTime = Math.floor(new Date().getTime() / 1000); 							let storedTime = userInfo.timestamp; 							console.log('当前时间', currentTime)
							console.log('存储时间戳', storedTime)
							if (currentTime - storedTime > 0) { 																uni.removeStorage({
									key: 'userInfo',
									success: function() {
										console.log('数据已过期,已清空');
									}
								});
							} else {
																								uni.showModal({
									title: '已保存账号密码数据到本地',
									content: '已保存账号密码数据到本地',
									success: function(res) {
										if (res.confirm) {
																						uni.getSystemInfo({
												success: function(res) {
													if (res.platform == 'android') {
														console.log('已缓存数据');
													}
												}
											});
										} else if (res.cancel) {
											console.log('取消操作');
																					}
									}
								});
							}
						} else {
													}
					}
				});
			},
						webviewError(event) {
				console.error('Webview error:', event);
			}
		}
	};
</script>
<style>
	.content {
		flex: 1;
		justify-content: center;
		align-items: center;
	}
	.title {
		font-size: 36px;
		color: #8f8f94;
	}
</style>
<template>
	<view class="content">
		<image class="logo" :src="titleLogo"></image>
		<view class="welcome_txt">{{welcome_txt}}</view>
		<view class="text-area">
			<text class="title">{{startTitle}}</text>
		</view>
		<pinapp-loading v-if="loading"></pinapp-loading>
	</view>
</template>
<script>
	import pinappLoading from "@/components/pinapp-loading/pinapp-loading.vue"
	import {encrypt,decrypt} from "@/common/crypto.js";
	import {config} from "@/common/config.js";
	import {profile} from "@/common/profile.js";
	import crypto from 'crypto-js';
	import {get,post} from '@/common/api.js';
	import {noNetwork,requestData,configurationError,serviceException} from '@/common/exception.js';
	import malicheckUpdate from '@/common/update.js';
    import { version } from "vue";
	const configString = JSON.stringify(config);
	const encryptedConfigString = encrypt(configString, 'ngnsxycyt');
			const encryptedProfileString = profile.profile;
	let printValue = ''; 	let result = ''; 	try {
		const decryptedConfigString = decrypt(encryptedProfileString, 'ngnsxycyt');
				const decryptedConfig = JSON.parse(decryptedConfigString);
								result = decryptedConfig;
		printValue = 'success'; 	} catch (error) {
		printValue = 'fail'; 			}
	const PACKAGE_INFO_KEY = '__NGN500__package_info__';
	export default {
		data() {
			return {
				startTitle: '',
				welcome_txt: '',
				titleLogo:'', 				loading: true
			}
		},
		components: {
			pinappLoading
		}, 		onLoad() {
			 let version = '';
			 									if ( printValue === 'success') {
								this.startTitle = result.startTitle;
				this.welcome_txt = result.welcome_txt;
				this.titleLogo = result.titleLogo;
								uni.setStorage({
					key: 'configInformation',
					data: {
						'Network': result.Network,
					}
				});
								let isnetworkType = ''; 				uni.getNetworkType({
					success: (res) => {
												isnetworkType = res.networkType;
					},
					fail: (err) => {
						console.error('获取网络状态失败:', err);
					}
				});
								if (isnetworkType === 'none') {
					uni.onNetworkStatusChange((res) => {
												if (res.networkType != 'none') {
							this.ToIndex(result.Network); 						}
					});	
						noNetwork(); 				} else {
										get('hotUpdate.php', {
					      type: 'getData'
					    }).then(res => {
					      						  uni.setStorageSync(PACKAGE_INFO_KEY, res);
						 let version = res.versionNum; 						 						 						 						 let resVersion = result.version; 						 
						 if (resVersion === version) {
						 							 							 	this.ToIndex(result.Network);									
						 } else {
						 							 	console.log('版本不同');
						 							 		malicheckUpdate()
						 }
					    }).catch(err => {
					      						  console.log('请求失败111')
						  requestData(); 					    })
				}
			} else { 								this.loading = false; 				configurationError(); 			}
		},
		onUnload() {
			clearTimeout(this.timer);
		},
		methods: {
						ToIndex(Network) {
								 uni.request({
				    url: Network,
				    method: 'GET',
				    success: (res) => {
				      if (res.statusCode === 200) {
						  						   uni.getStorage({
						     key: 'userInfo',
						     success: function(res) {
						       if (res.data !== undefined && res.data !== null) {
						         						         console.log('获取的数据为ccc: ', res);
						       } else {
						         						         console.log('没有找到对应的数据或数据为空');
						       }
						     },
						     fail: function() {
						       						       console.log('获取数据失败或数据不存在');
						     }
						   });
				        				        setTimeout(() => {
				          uni.redirectTo({
							 url: '/pages/index/index?network=' + encodeURIComponent(Network),
							 				          });
				        }, 3000);
				      } else {
				        				        						serviceException(); 				      }
				    },
				    fail: (error) => {
				      					 serviceException(); 				    }
				  });
			}
		}
	}
</script>
<style>
	body, html {
		height: 100%;
		margin: 0;
	}
	.content {
		position: absolute;
		top: 40%;
		left: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		overflow: hidden;
	}
	.logo {
		height: 300rpx;
		width: 300rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
	}
	.text-area {
		display: flex;
		justify-content: center;
	}
	.welcome_txt {
		font-size: 35rpx;
		margin-bottom: 20rpx;
	}
	.title {
		font-size: 23rpx;
		color: #8f8f94;
	}
</style>
<template>
	<view class="loader">
		<view class="loader-inner line-scale">
			<view></view>
			<view></view>
			<view></view>
			<view></view>
			<view></view>
		</view>
		<vew class="loader-tips">加载中</vew>
	</view>
</template>
<script>
	export default {
		name:"pinapp-loading",
		data() {
			return {
			};
		}
	}
</script>
<style scoped>
	.loader {
		display: flex;
		max-width: 100%;
		height: 20vh;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}
	.loader-tips {
		color: #333;
		display: none;
	}
	@-webkit-keyframes line-scale {
		0% {
			-webkit-transform: scaley(1);
			transform: scaley(1);
		}
		50% {
			-webkit-transform: scaley(0.4);
			transform: scaley(0.4);
		}
		100% {
			-webkit-transform: scaley(1);
			transform: scaley(1);
		}
	}
	@keyframes line-scale {
		0% {
			-webkit-transform: scaley(1);
			transform: scaley(1);
		}
		50% {
			-webkit-transform: scaley(0.4);
			transform: scaley(0.4);
		}
		100% {
			-webkit-transform: scaley(1);
			transform: scaley(1);
		}
	}
	.line-scale>view:nth-child(1) {
		-webkit-animation: line-scale 1s 0.1s infinite cubic-bezier(.2, .68, .18, 1.08);
		animation: line-scale 1s 0.1s infinite cubic-bezier(.2, .68, .18, 1.08);
	}
	.line-scale>view:nth-child(2) {
		-webkit-animation: line-scale 1s 0.2s infinite cubic-bezier(.2, .68, .18, 1.08);
		animation: line-scale 1s 0.2s infinite cubic-bezier(.2, .68, .18, 1.08);
	}
	.line-scale>view:nth-child(3) {
		-webkit-animation: line-scale 1s 0.3s infinite cubic-bezier(.2, .68, .18, 1.08);
		animation: line-scale 1s 0.3s infinite cubic-bezier(.2, .68, .18, 1.08);
	}
	.line-scale>view:nth-child(4) {
		-webkit-animation: line-scale 1s 0.4s infinite cubic-bezier(.2, .68, .18, 1.08);
		animation: line-scale 1s 0.4s infinite cubic-bezier(.2, .68, .18, 1.08);
	}
	.line-scale>view:nth-child(5) {
		-webkit-animation: line-scale 1s 0.5s infinite cubic-bezier(.2, .68, .18, 1.08);
		animation: line-scale 1s 0.5s infinite cubic-bezier(.2, .68, .18, 1.08);
	}
	.line-scale>view {
		background-color: #2376FF;
		width: 4px;
		height: 35px;
		border-radius: 2px;
		margin: 2px;
		-webkit-animation-fill-mode: both;
		animation-fill-mode: both;
		display: inline-block;
	}
</style>
<template>
	<view class="u-mask" hover-stop-propagation :style="[maskStyle, zoomStyle]" @tap="click"
		@touchmove.stop.prevent="() => {}" :class="{
		'u-mask-zoom': zoom,
		'u-mask-show': show
	}">
		<slot />
	</view>
</template>
<script>
	export default {
		name: "u-mask",
		props: {
						show: {
				type: Boolean,
				default: false
			},
						zIndex: {
				type: [Number, String],
				default: '10070'
			},
						customStyle: {
				type: Object,
				default () {
					return {}
				}
			},
						zoom: {
				type: Boolean,
				default: true
			},
						duration: {
				type: [Number, String],
				default: 300
			},
						maskClickAble: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				zoomStyle: {
					transform: ''
				},
				scale: 'scale(1.2, 1.2)'
			}
		},
		watch: {
			show(n) {
				if (n && this.zoom) {
										this.zoomStyle.transform = 'scale(1, 1)';
				} else if (!n && this.zoom) {
										this.zoomStyle.transform = this.scale;
				}
			}
		},
		computed: {
			maskStyle() {
				let style = {};
				style.backgroundColor = "rgba(0, 0, 0, 0.6)";
				if (this.show) style.zIndex = this.zIndex ? this.zIndex : this.$u.zIndex.mask;
				else style.zIndex = -1;
				style.transition = `all ${this.duration / 1000}s ease-in-out`;
								if (Object.keys(this.customStyle).length) style = {
					...style,
					...this.customStyle
				};
				return style;
			}
		},
		methods: {
			click() {
				if (!this.maskClickAble) return;
				this.$emit('click');
			}
		}
	}
</script>
<style lang="scss" scoped>
	.u-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		opacity: 0;
		transition: transform 0.3s;
	}
	.u-mask-show {
		opacity: 1;
	}
	.u-mask-zoom {
		transform: scale(1.2, 1.2);
	}
</style>
<template>
	<view class="mask flex-center">
	  <view class="content botton-radius">
		<view class="content-top">
		  <image class="content-top" style="top: 0" width="100%" height="100%" src="/static/images/update-img.png"/>
		   <text class="content-top-text">{{ title }}</text>
		   <view class="content-top-sub">V{{versionNum}}</view>
		</view>
		<view class="content-header"></view>
		<view class="content-body">
		  <view class="title">
			<text>{{ subTitle }}</text>
		  </view>
		  <view class="body">
			<scroll-view class="box-des-scroll" scroll-y="true">
			  <text class="box-des">
				{{ contents || versionDesc }}
			  </text>
			</scroll-view>
		  </view>
		  <view class="footer flex-center">
			<template v-if="isiOS">
			  <button class="content-button" style="border: none; color: #fff" plain @click="jumpToAppStore">
				{{ downLoadBtnTextiOS }}
			  </button>
			</template>
			<template v-else>
			  <template v-if="!downloadSuccess">
				<view class="progress-box flex-column" v-if="downloading">
				  <progress class="progress" border-radius="35" :percent="downLoadPercent" activeColor="#03bdac" show-info stroke-width="10" />
				  <view style="width: 100%; font-size: 28rpx; display: flex; justify-content: space-around">
					<text>{{ downLoadingText }}</text>
				  </view>
				</view>
				<button v-else class="content-button" style="border: none; color: #fff" plain @click="downloadPackage">
				  {{ downLoadBtnText }}
				</button>
			  </template>
			  <button
				v-else-if="downloadSuccess && !installed"
				class="content-button"
				style="border: none; color: #fff"
				plain
				:loading="installing"
				:disabled="installing"
				@click="installPackage"
			  >
				{{ installing ? '正在安装……' : '下载完成,立即安装' }}
			  </button>
			  <button v-if="installed && isWGT" class="content-button" style="border: none; color: #fff" plain @click="restart">安装完毕,点击重启</button>
			</template>
		  </view>
		</view>
		<image v-if="!is_mandatory" class="close-img" src="/static/images/close.png" @click.stop="closeUpdate"></image>
	  </view>
	</view>
  </template>
  <script>
	  import {noNetwork,requestData,configurationError,serviceException} from '@/common/exception.js';
  const localFilePathKey = '__localFilePath__';
  const platform_iOS = 'iOS';
  let downloadTask = null;
  function compare(v1 = '0', v2 = '0') {
	v1 = String(v1).split('.');
	v2 = String(v2).split('.');
	const minVersionLens = Math.min(v1.length, v2.length);
	let result = 0;
	for (let i = 0; i < minVersionLens; i++) {
	  const curV1 = Number(v1[i]);
	  const curV2 = Number(v2[i]);
	  if (curV1 > curV2) {
		result = 1;
		break;
	  } else if (curV1 < curV2) {
		result = -1;
		break;
	  }
	}
	if (result === 0 && v1.length !== v2.length) {
	  const v1BiggerThenv2 = v1.length > v2.length;
	  const maxLensVersion = v1BiggerThenv2 ? v1 : v2;
	  for (let i = minVersionLens; i < maxLensVersion.length; i++) {
		const curVersion = Number(maxLensVersion[i]);
		if (curVersion > 0) {
		  v1BiggerThenv2 ? (result = 1) : (result = -1);
		  break;
		}
	  }
	}
	return result;
  }
  export default {
	data() {
	  return {
				installForBeforeFilePath: '',
				installed: false,
		installing: false,
				downloadSuccess: false,
		downloading: false,
		downLoadPercent: 0,
		downloadedSize: 0,
		packageFileSize: 0,
		tempFilePath: '',   
				title: '发现新版本',
		contents: '',
		versionDesc: '',
		is_mandatory: false,
				subTitle: '更新内容',
		downLoadBtnTextiOS: '立即跳转更新',
		downLoadBtnText: '立即下载更新',
		downLoadingText: '安装包下载中,请稍候...',
		versionNum:'',
		local_storage: ''
	  };
	},
	onLoad({ local_storage_key }) {
				this.local_storage = local_storage_key;
	  if (!local_storage_key) {
		console.error('local_storage_key为空,请检查后重试');
		uni.navigateBack();
		return;
	  }
	  const localPackageInfo = uni.getStorageSync(local_storage_key);
	  if (!localPackageInfo) {
		console.error('安装包信息为空,请检查后重试');
		uni.navigateBack();
		return;
	  }
	   const requiredKey = ['versionNum', 'resourceUrl', 'appType']; 	  for (let key in localPackageInfo) {
		if (requiredKey.indexOf(key) !== -1 && localPackageInfo[key] == '') {
		  console.error(`参数 ${key} 必填,请检查后重试`);
		  uni.navigateBack();
		  return;
		}
	  }
	  this.is_mandatory = localPackageInfo['isNeedUpdate'];
	  this.appType = localPackageInfo['isWgt']; 	  	  Object.assign(this, localPackageInfo);
	  this.checkLocalStoragePackage();
	  this.title = localPackageInfo['updateTitle']; 	  this.versionNum=localPackageInfo['versionNum']; 	  this.contents = localPackageInfo['updateContent']; 	   this.resourceUrl = localPackageInfo['updateLink']; 	  
	},
	onBackPress() {
	  	  if (this.is_mandatory) {
		return true;
	  }
	  downloadTask && downloadTask.abort();
	},
	computed: {
	  isWGT() {
		  		  		return this.appType === 'wgt';
	  },
	  isiOS() {
		return !this.isWGT ? plus.os.name.toLocaleLowerCase().includes(platform_iOS) : false;
	  },
	  showPrenct(){
		  return parseInt(this.downLoadPercent)+'%';
	  },
	},
	methods: {
	  checkLocalStoragePackage() {
				const localFilePathRecord = uni.getStorageSync(localFilePathKey);
		if (localFilePathRecord) {
		  const { version, savedFilePath, installed } = localFilePathRecord;
		  		  if (!installed && compare(version, this.versionNum) === 0) {
			this.downloadSuccess = true;
			this.installForBeforeFilePath = savedFilePath;
						this.tempFilePath = savedFilePath;
		  } else {
			  console.log('如果已经安装过则直接删除掉');
						this.deleteSavedFile(savedFilePath);
		  }
		}
	  },
	  async closeUpdate() {
		if (this.downloading) {
		  if (this.is_mandatory) {
			return uni.showToast({
			  title: '下载中,请稍候……',
			  icon: 'none',
			  duration: 500,
			});
		  }
		  var that = this;
		  uni.showModal({
			title: '是否取消下载?',
			cancelText: '否',
			confirmText: '是',
			success: (res) => {
			  if (res.confirm) {
				downloadTask && downloadTask.abort();
				uni.navigateBack();
				uni.getSystemInfo({
				  success: function (res) {
					if (res.platform == 'android') {
						console.log('取消成功,进行下一步')
						that.jumpIndex();
					}
				  }
				});
			  }
			},
		  });
		  return;
		} else {
									this.jumpIndexWithoutBack();
		}
		if (this.downloadSuccess && this.tempFilePath) {
		  		  await this.saveFile(this.tempFilePath, this.versionNum);
		  uni.navigateBack();
		  return;
		}
		uni.navigateBack();
	  },
	  downloadPackage() {
		this.downloading = true;
				 		  				const  self = this;
	   let downloadTask = uni.downloadFile({
		  url: this.resourceUrl,
		  success: (res) => {
			  console.log('打印出下载包的返回code',res)
			if (res.statusCode == 200) {
			  self.downloadSuccess = true;
			  self.tempFilePath = res.tempFilePath;	
			  			  if (self.is_mandatory) {
				self.installPackage();
			  }
			}
		  },
		  complete: () => {
			this.downloading = false;
			this.downLoadPercent = 0;
			this.downloadedSize = 0;
			this.packageFileSize = 0;
			downloadTask = null;
		  },
		});
		downloadTask.onProgressUpdate((res) => {
		  this.downLoadPercent = res.progress;
		  this.downloadedSize = (res.totalBytesWritten / Math.pow(1024, 2)).toFixed(2);
		  this.packageFileSize = (res.totalBytesExpectedToWrite / Math.pow(1024, 2)).toFixed(2);
		});
	  },
	  installPackage() {
		  console.log('this.isWGT111:',this.isWGT)
						if (this.isWGT) {
		  this.installing = true;
		}
		plus.runtime.install(
		  this.tempFilePath,
		  {
			force: false,
		  },
		  async (res) => {
			this.installing = false;
			this.installed = true;
				console.log('this.isWGT',this.isWGT);
				console.log('this.is_mandatory',this.is_mandatory);
						if (this.isWGT) {
			  			  				uni.showLoading({
				  icon: 'none',
				  title: '安装成功,正在重启……',
				});
				setTimeout(() => {
				  uni.hideLoading();
				  this.restart();
				  				  				   this.jumpIndexWithoutBack();
				}, 1000);	  
			} else {
				console.log('运行二次跳转')
			  const localFilePathRecord = uni.getStorageSync(localFilePathKey);
			  uni.setStorageSync(localFilePathKey, {
				...localFilePathRecord,
				installed: true,
			  });		
			  			  setTimeout(() => {
			   uni.getStorage({
				 key: 'configInformation',
				 success: function(res) {
				   if (res.data !== undefined && res.data !== null) {
					 					 const network = res.data['Network'];
					 uni.redirectTo({
					   url: '/pages/index/index?network=' + encodeURIComponent(network),
					 });
				   } else {
					 					 serviceException();	  
				   }
				 },
				 fail: function() {
				   				   serviceException();
				 }
			   });
			  }, 1000);
			}
		  },
		  async (err) => {
						if (this.installForBeforeFilePath) {
			  await this.deleteSavedFile(this.installForBeforeFilePath);
			  this.installForBeforeFilePath = '';
			}
						this.installing = false;
			this.installed = false;
			uni.showModal({
			  title: `更新失败${this.isWGT ? '' : ',APK文件不存在'},请重新下载`,
			  content: err.message,
			  showCancel: false,
			});
		  }
		);
				if (!this.isWGT) {
		  uni.navigateBack();
		}
			  },
	  restart() {
		this.installed = false;
						plus.runtime.restart();
			  },
	  async saveFile(tempFilePath, version) {
		const [err, res] = await uni.saveFile({
		  tempFilePath,
		});
		if (err) {
		  return;
		}
		uni.setStorageSync(localFilePathKey, {
		  version,
		  savedFilePath: res.savedFilePath,
		});
	  },
	  deleteSavedFile(filePath) {
		uni.removeStorageSync(localFilePathKey);
		return uni.removeSavedFile({
		  filePath,
		});
	  },
	  jumpToAppStore() {
		plus.runtime.openURL(this.resourceUrl);
	  },
	  	  jumpIndex() {
		  uni.getStorage({
			key: 'configInformation',
			success: function(res) {
			  if (res.data !== undefined && res.data !== null) {
								const network = res.data['Network'];
				uni.redirectTo({
				  url: '/pages/index/index?network=' + encodeURIComponent(network),
				});
			  } else {
								serviceException();	  
			  }
			},
			fail: function() {
			  			  serviceException();
			}
		  });
	  },
	  async jumpIndexWithoutBack() {
		try {
		  const res = await new Promise((resolve, reject) => {
			uni.getStorage({
			  key: 'configInformation',
			  success: resolve,
			  fail: reject
			});
		  });
		  if (res.data !== undefined && res.data !== null) {
						const network = res.data['Network'];
			uni.reLaunch({
			  url: '/pages/index/index?network=' + encodeURIComponent(network),
			});
		  } else {
						serviceException();
		  }
		} catch (error) {
		  		  serviceException();
		}
	  }
	},
  };
  </script>
  <style>
  page {
	background: transparent;
  }
  .flex-center {
	display: flex;
	justify-content: center;
	align-items: center;
  }
  .mask {
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.65);
  }
  .botton-radius {
	border-bottom-left-radius: 30rpx;
	border-bottom-right-radius: 30rpx;
  }
  .content {
	position: relative;
	top: 0;
	width: 618rpx;
	background-color: #fff;
	box-sizing: border-box;
	padding: 0 50rpx;
	font-family: Source Han Sans CN;
  }
  .text {
	display: block;
	line-height: 200px;
	text-align: center;
	color: #ffffff;
  }
  .content-top {
	position: absolute;
	top: -195rpx;
	left: 0;
	width: 618rpx;
	height: 310rpx;
  }
  .content-top-text {
	font-size: 34rpx;
	font-weight: 600;
	color: #333;
	position: absolute;
	bottom: 40rpx;
	left: 0;
	right: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1;
  }
  .content-top-sub{
	  position: absolute;
	  bottom: 0rpx;
	  left: 0;
	  right: 0; font-size: 28rpx;
	font-weight: 400;
	color: #333;  display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1;
  }
  .content-header {
	height:140rpx;
  }
  .title {
	font-size: 28rpx;
	font-weight: bold;
	color: #333;
	line-height: 38rpx;
  }
  .footer {
	height: 150rpx;
	display: flex;
	align-items: center;
	justify-content: space-around;
  }
  .box-des-scroll {
	box-sizing: border-box;
	padding: 0 40rpx 0 0;
	height: 200rpx;
	text-align: left;
  }
  .box-des {
	font-size: 24rpx;
	color: #666;
	line-height: 34rpx;
  }
  .progress-box {
	width: 100%;
  }
  .progress {
	width: 90%;
	height: 40rpx;
	border-radius: 35px;
  }
  .close-img {
	width: 70rpx;
	height: 70rpx;
	z-index: 1000;
	position: absolute;
	bottom: -120rpx;
	left: calc(50% - 70rpx / 2);
  }
  .content-button {
	text-align: center;
	flex: 1;
	font-size: 30rpx;
	font-weight: 400;
	color: #333;
	border-radius: 40rpx;
	margin: 0 18rpx;
	height: 80rpx;
	line-height: 80rpx;
	background: linear-gradient(to right, #2376FF, #2376FF);
  }
  .flex-column {
	display: flex;
	flex-direction: column;
	align-items: center;
  }
  </style>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骨子里的偏爱

上传不易,还请多多支持。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值