<script>
import { RequestApi } from '@/api/requestApi';
import { useGlobalStore } from '@/stores/global';

export default {
	onLaunch: function () {
		this.listenNetwork();
	},
	onShow: function () {
		console.log('App Show');
    let global = useGlobalStore();
    global.setAppHide(false);
		this.initNetworkStatus();
	},
	onHide: function () {
		console.log('App Hide');
    let global = useGlobalStore();
    global.setAppHide(true);
	},
	data() {
		return {
			globalStore: useGlobalStore()
		};
	},
	methods: {
		loadBasic() {
			RequestApi.getBasic().then((basic) => {
				this.globalStore.setBasic(basic);
			});
		},
		loadService() {
			RequestApi.getService().then((service) => {
				this.globalStore.setService(service);
			});
		},
		initNetworkStatus() {
			uni.getNetworkType({
				success: (e) => {
					if (e.networkType != 'none') {
						this.globalStore.setNetworkIsConnected(true);
						this.loadBasic();
						this.loadService();
					} else {
						this.globalStore.setNetworkIsConnected(false);
					}
				}
			});
		},
		listenNetwork() {
			uni.onNetworkStatusChange((e) => {
				this.globalStore.setNetworkIsConnected(e.isConnected);
				if (e.isConnected) {
					this.loadBasic();
					this.loadService();
				}
			});
		}
	}
};
</script>

<style lang="scss">
@import '@/static/global.scss';

view {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	tap-highlight-color: rgba(0, 0, 0, 0);
}

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_Thin.ttf')) format('truetype');
// 	font-weight: 100;
// }

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_ExtraLight.ttf')) format('truetype');
// 	font-weight: 200;
// }

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_Light.ttf')) format('truetype');
// 	font-weight: 300;
// }

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_Regular.ttf')) format('truetype');
// 	font-weight: 400;
// }

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_Medium.ttf')) format('truetype');
// 	font-weight: 500;
// }

// @font-face {
// 	font-family: 'PingFang SC';
// 	src: url(getImageUrl('/fonts/PingFang_SC_Semibold.ttf')) format('truetype');
// 	font-weight: 00;
// }

.uni-load-more {
	height: unset !important;
}
</style>
<style>
/* 自定义全局样式 */
/deep/ .markdown-body {
	padding: 20rpx;
	font-size: 28rpx;
	line-height: 1.6;
}

/deep/ pre {
	padding: 20rpx;
	background: #f8f8f8;
	border-radius: 8rpx;
	overflow-x: auto;
}

/deep/ .uni-load-more {
	height: unset !important;
}
</style>
