<script>
import { initAppDatabase } from '@/utils/appDb';

export default {
	onLaunch: (options) => {
		// #ifdef APP
		initAppDatabase();
		// #endif

		console.log('App Launch');
		console.log(options);
		// uni.onNetworkStatusChange((event) => {
		//   console.log(event)
		// })

		// #ifdef H5
		// 保存钉钉消息传递的参数，参数可能存在path或query中
		if (options.query.type) {
			uni.setStorageSync('dingTalkJson', JSON.stringify(options.query));
		} else if (options.path && options.path.includes('type')) {
			const path = options.path;
			const args = path.split('&');
			const params = {};

			args.forEach((arg) => {
				const [key, value] = arg.split('=');
				if (key && value) {
					params[key] = value;
				}
				console.log(params);
			});
			uni.setStorageSync('dingTalkJson', JSON.stringify(params));
		}
		// #endif

		// #ifdef APP
		plus.globalEvent.addEventListener('newintent', () => {
			const args = plus.runtime.arguments;
			const parts = args.match(/^deepoil:\/\/([^/]+)\/([^/]+)$/);
			if (parts) {
				const type = parts[1];
				const id = parts[2];

				uni.setStorageSync('dingTalkJson', JSON.stringify({ type, id }));
				console.log('App: dingTalkJson -> ' + uni.getStorageSync('dingTalkJson'));
			}
		});
		// #endif
	},
	onExit: () => {
		// #ifdef APP
		// sqlite.closeDB('app')
		// #endif
	},
	onShow: function () {
		// console.log('App Show')
	},
	onHide: function () {
		// console.log('App Hide')
	}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import './style/common.scss';
@import './style/fonts.scss';

/* uniapp组件 样式覆盖  */
uni-button[type='primary'] {
	background: #004098 !important;
}

uni-button[disabled][type='primary'] {
	background: rgba(0, 64, 152, 0.6) !important;
}
uni-button[type='primary'][plain] {
	color: #004098 !important;
	border: 1px solid #004098 !important;
	background-color: transparent !important;
}

uni-page-body,
body {
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	position: relative;
}

:deep(.uni-tabbar-bottom .uni-tabbar) {
	box-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.1);
	// padding-top: 9px !important;
	// padding-bottom: 10px !important;
	box-sizing: border-box;

	.uni-tabbar__icon {
		margin-top: 4px;
	}
}

.page {
	position: relative;
	padding: 20rpx;
	padding-top: 0;
	box-sizing: border-box;
	background: #f3f5f9;
	width: 100%;
	height: 100%;
	font-family: PingFangSC, PingFang SC;
	overflow: hidden;
}

.page-nopadding {
	position: relative;
	box-sizing: border-box;
	background: #f3f5f9;
	width: 100%;
	height: 100%;
	font-family: PingFangSC, PingFang SC;
	overflow: hidden;
}

.page-back {
	background-image: url('/static/common/1.png');
	background-repeat: no-repeat;
	background-size: 100% 100%;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 350px;
	z-index: 0;
}

.navgator {
	width: 100%;
	height: $header-height;
	line-height: 1;
	position: fixed;
	top: $header-top-height;
	left: 0;
	background-color: transparent !important;
	padding-top: calc(7px + env(safe-area-inset-top));
	box-sizing: border-box;
	z-index: 22;

	.nav-title {
		font-family: PingFang-SC, PingFang-SC;
		font-weight: bold;
		font-size: 16px;
		color: #ffffff;
		line-height: 22px;
		text-align: right;
		font-style: normal;
	}

	.nav-back {
		width: 40rpx;
		line-height: 1;
		position: absolute;
		left: 20rpx;

		.uni-icons {
			color: #fff !important;
		}
	}
}

.page-content {
	position: relative;
	box-sizing: border-box;
	width: 100%;
	height: calc(100% - $header-height - $header-top-height);
	margin-top: calc($header-height + $header-top-height);
	overflow: hidden;
	overflow-y: auto;
}

.item {
	box-sizing: border-box;
}
</style>
