<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// #ifdef H5
			// console.log(window.location.host)
			uni.setStorageSync('h5_url', window.location.host)
			// #endif
			if (uni.getStorageSync('theme')) {} else {
				uni.setStorageSync('theme', 'light')
			}
			// 强制使用浅色主题
			uni.setStorageSync('theme', 'light')
			this.connectWS()
			if (uni.getStorageSync('rateid')) {

			} else {
				this.post('/publics/exchange_list').then(res => {
					if (res.code == 1) {
						let item = res.data[0]
						uni.setStorageSync('rateid', item.id)
						uni.setStorageSync('ratename', item.name_sx)
						uni.setStorageSync('ratenum', item.exchange)
					}
				})
			}
		},
		computed: {
			i18n() {
				return this.$t('message');
			}
		},
		onShow: function() {
			console.log('App Show')
			var that = this
			let lang = uni.getStorageSync('Language');
			// 判断选择的语言
			if (lang) {
				that.$i18n.locale = lang;
				uni.setStorageSync('Language', lang);
			} else {
				that.$i18n.locale = 'en-us';
				uni.setStorageSync('Language', 'en-us');
			}
			const pages = getCurrentPages()
			if (pages && pages.length) {
				const current = pages[pages.length - 1]
				const path = '/' + (current.route || '')
				const whiteList = [
					'/pages/index/index',
					'/pages/login/index',
					'/pages/login/register',
					'/pages/login/forget',
					'/pages/lang/lang'
				]
				if (!whiteList.includes(path) && !uni.getStorageSync('token')) {
					uni.reLaunch({
						url: '/pages/login/index'
					})
				}
			}
			if (getApp().globalData.socket == false) {
				getApp().globalData.reConnect = setInterval(function() {
					if (getApp().globalData.socket == false) {
						that.connectWS()
					} else {
						clearInterval(getApp().globalData.reConnect)
					}
				}, 1000)
			}
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			url: "",
			data: "",
			type: "",
			socket: true,
			reConnect: "",
			symbol: "",
			period: "",
			buyType: ""
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";

	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "/colorui/animation.css";
	@import '/static/css/main.css';
	@import '/static/css/180css.css';

	// 引入字体
	@font-face {
		font-family: 'Bold';
		src: url('~@/static/fonts/PINGFANG_BOLD.TTF');
	}

	@font-face {
		font-family: 'Medium';
		src: url('~@/static/fonts/PINGFANG_REGULAR.TTF');
	}

	@font-face {
		font-family: 'NumBold';
		src: url('~@/static/fonts/D-DINExp-Bold.ttf');
	}

	@font-face {
		font-family: 'NumMedium';
		src: url('~@/static/fonts/D-DINExp.ttf');
	}

	.numbold-font {
		font-family: "NumBold" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.nummedium-font {
		font-family: "NumMedium" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.bold-font {
		font-family: "Bold" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.medium-font {
		font-family: "Medium" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	page {
		// background: #F6F8FB;
		// padding-bottom: 40rpx;
		font-family: "Medium";
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
	}

	.fixed {
		position: fixed;
	}

	.z-1000 {
		z-index: 1000;
	}

	.topBar {
		padding-top: var(--status-bar-height);
		height: calc(74rpx + var(--status-bar-height));
		width: 750rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 100;
	}

	/* TabBar 边框样式 */
	.uni-tabbar-border {
		background-color: rgb(238, 238, 238) !important;
	}
</style>
