<script>
	export default {
		data() {
			return {}
		},
		onLoad() {},
		onShow() {},
		onLaunch() {
			const that = this;
			// 设备信息
			let system = that.$config.system;
			if (system.uniPlatform == 'app') {
				// that.appCheck()
			} else if (system.uniPlatform == 'mp-weixin') {
				that.weixinCheck()
			}
		},
		methods: {
			// app检查版本
			appCheck() {
				const that = this;
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					uni.request({
						url: `${that.$config.serverUrl}/files/project/appVersion.json`,
						method: 'GET',
						success: (res) => {
							if (wgtinfo.version === res.data.version) return;
							uni.showModal({
								title: '更新',
								content: "有新版本,是否下载?",
								success: (oneres) => {
									if (oneres.confirm) {
										// 下载app
										this.toUpdateAPK(res.data.url);
									}
								}
							})
						}
					})
				})
			},
			toUpdateAPK(url) {
				if (!url) return;
				uni.showLoading({
					title: '更新中……',
					mask: true,
				})
				uni.downloadFile({
					url: url,
					success: (res) => {
						uni.hideLoading();
						if (res.statusCode == 200) {
							uni.showModal({
								content: '更新成功，确定现在重启吗？',
								confirmText: '重启',
								confirmColor: '#EE8F57',
								success: modalRes => {
									if (modalRes.confirm) {
										plus.runtime.install(
											res.tempFilePath, {
												force: true
											},
											function(res) {
												plus.runtime.restart();
											})
									}
								}
							})
						}
					}
				})
			},
			// 微信检查版本
			weixinCheck() {
				console.log('微信检查本版');
			}
		},
	}
</script>

<style>
	@import url('@/uni.scss');
	.textOver {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	page {
		/* 主要背景色 */
		--rgb000: #000000;
		--rgb111: #111111;
		--rgbfff: #ffffff;
		--rgbf1f: #f1f1f1;
		--rgb61: #161616;
		--rgbfa4: #FA4343;
	}
</style>
