<script>
import md5Libs from '@/uni_modules/uview-ui/libs/function/md5';
import Vue from 'vue';

export default {
	created() {
		// #ifdef APP-PLUS
		ime: '', plus.navigator.closeSplashscreen();
		// #endif
	},
	onLaunch: async function () {
		console.log('App Launch');
		uni.hideTabBar();

		// #ifdef APP-PLUS
		// plus.android.requestPermissions(['Manifest.permission.READ_PHONE_STATE'], function(e){
		// 		if(e.deniedAlways.length>0){	//权限被永久拒绝
		// 			// 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
		// 			console.log('Always Denied!!! '+e.deniedAlways.toString());
		// 		}
		// 		if(e.deniedPresent.length>0){	//权限被临时拒绝
		// 			// 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
		// 			console.log('Present Denied!!! '+e.deniedPresent.toString());
		// 		}
		// 		if(e.granted.length>0){	//权限被允许
		// 		    //调用依赖获取定位权限的代码
		// 			console.log('Granted!!! '+e.granted.toString());
		// 		}
		// 	}, function(e){
		// 	    console.log('Request Permissions error:'+JSON.stringify(e));
		// 	});
		this.ime = plus.device.imei;
		console.log(this.ime);

		plus.device.getInfo({
			success: function (e) {
				this.ime = JSON.stringify(e);
				console.log('getDeviceInfo success: ' + JSON.stringify(e));
			},
			fail: function (e) {
				uni.showToast({
					title: '获取设备信息失败',
					mask: false,
					duration: 1500
				});
			}
		});

		let that = this;
		plus.runtime.getProperty(plus.runtime.appid, function (widgetInfo) {
			console.log(widgetInfo);
			uni.request({
				url: 'https://mnhcdn.wenlvti.net/api/minnansoul/version/version',
				sslVerify: false,
				data: {
					version: widgetInfo.version
				},
				success: (result) => {
					console.log(result);
					var data = result.data.data;
					if (data.update && data.wgtUrl) {
						uni.showModal({
							title: '更新提示',
							content: '有新的版本更新，请确认',
							showCancel: false,
							success(resmodal) {
								if (resmodal.confirm) {
									plus.runtime.openURL(data.wgtUrl);
								}
							}
						});
					}

					// 只有apk包的时间
					if (data.update && data.pkgUrl && !data.wgtUrl) {
						uni.showModal({
							title: '更新提示',
							content: '有新的版本更新，请确认',
							showCancel: false
						});
						var dtask = plus.downloader.createDownload(data.pkgUrl, {}, function (d, status) {
							// 下载完成
							if (status == 200) {
								plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function (error) {
									uni.showToast({
										title: '安装失败',
										mask: false,
										duration: 1500
									});
								});
							} else {
								uni.showToast({
									title: '下载失败',
									mask: false,
									duration: 1500
								});
							}
						});
						dtask.start();
					}
				},
				fail(res) {
					console.log(res, '错误');
				}
			});
		});
		// plus.screen.lockOrientation('portrait-primary'); //锁定屏幕
		// const dom = weex.requireModule('dom');
		// dom.addRule('fontFace', {
		// 	'fontFamily': "graceIconfont",
		// 	'src': "url('/static/grace.ttf')"
		// });
		// #endif

		//加载配置
		uni.getSystemInfo({
			success: function (e) {
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform == 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight + 50;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight + 45;
				}
				// #endif

				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				let custom = wx.getMenuButtonBoundingClientRect();
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif

				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
			}
		});
	},
	onReady() {
		// plus.screen.lockOrientation( 'landscape-secondary');
		this.plus.screen.lockOrientation('landscape-primary');
	},

	onShow: function () {
		// console.log('App 开启');
		uni.hideTabBar();
	},
	onHide: function () {
		// console.log('App 关闭');
	},
	onLoad: function () {
		uni.hideTabBar();
	}
};
</script>

<style lang="scss">
@import '@/uni_modules/uview-ui/index.scss';
// @import "common/iconfont.css";
@import 'common/app.css';
@import './GraceUI5/css/graceUI.css';
@import './GraceUI5/skin/black.css';
/* 加载图标字体 - 条件编译模式 */
/* #ifdef APP-PLUS-NVUE */
.gui-icons {
	font-family: graceIconfont;
}
/* #endif */
// body {
// 	max-width: 3840rpx; //最大宽度自己可以调整
// 	margin: auto !important;
// }
</style>
