uni-app手机怎么下载安装包

67 阅读1分钟
<view>
				<view class="codeBox">
					<image :src=codeImage alt="" class="imageBox" />
				</view>
				<view class="orderBox" @click="orderClick">
					下载点餐宝
				</view>
				<view class="progressBox" v-if="update_flag">
					<u-line-progress :percent="process" :round="false"></u-line-progress>
				</view>
			</view>
                           		//下载 点餐宝
		orderClick() {
			this.update_flag = true;
			const downloadTask = uni.downloadFile({
				url: this.codeUrl, //仅为示例,并非真实的资源
				success: (res) => {
					if (res.statusCode == 200) {
						this.tempFilePath = res.tempFilePath
					} else {
						uni.showToast({
							title: '下载失败,网络错误',
							icon: 'none'
						});
					}
				},
				fail: (e) => {
					this.update_flag = false;
					console.log('下载失败', e);
					uni.showToast({
						title: '下载失败:' + e.errMsg,
						icon: 'none'
					});
				},
				complete: (msg) => {
					console.log(msg)
				},

			});
			downloadTask.onProgressUpdate((res) => {
				this.process = res.progress;
				if (parseInt(this.process) == 100) {
					setTimeout(() => {
						this.intallApp()
					}, 1500)
				}
			});


		},
		intallApp() {
			//开始安装
			plus.runtime.install(
				this.tempFilePath, {
					force: false
				},
				() => {
					console.log('install success...');
					plus.runtime.restart();
				},
				(e) => {
					console.error('install fail...', e);
					uni.showToast({
						title: '升级失败',
						icon: 'none'
					});
				}
			);
		},