<script setup lang="ts">
    import api from "./api";
    import {onLaunch, onShow, onHide} from "@dcloudio/uni-app";
    import {WXUtils} from "./utils/utils";

    function getUrl(url) {
        const q = {};
        url.replace(/([^?&=]+)=([^&]+)/g, (_, k, v) => q[k] = v);
        return q;
    }

    onLaunch((e) => {
        let device = navigator.userAgent.toLowerCase();
        window._wx.miniProgram.postMessage({ data:{}});
        console.log(window.__wxjs_environment === 'miniprogram','window.__wxjs_environment === \'miniprogram\'');
        if (!(window.__wxjs_environment === 'miniprogram')) {

            if (!/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile|mobile/.test(device)) {
                if (window.location.port === '3000') {
                    window.location.href = 'https://etaoh5-pre.edstao.com/pc/'
                } else {
                    window.location.href = '/pc/'
                }
            }
        }
        uni.setStorageSync('isWxjs_environment', window.__wxjs_environment === 'miniprogram')
        if (window.__wxjs_environment === 'miniprogram') {
            let subdomain =getUrl(window.location.href)
            if(subdomain.name){
                uni.setStorageSync('subdomain','alisa1')
            }
            try {
                uni.setStorageSync('uniEnv', process.uniEnv) // 打包后没有process
            } catch {
            }
        } else {
            window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function () {
                if (window.orientation === 180 || window.orientation === 0) {
                    window.location.reload()
                }
                ;
            }, false);
            uni.setStorageSync('subdomain','alisa1')
            uni.setStorageSync('isWX', WXUtils.isWeiXin())
            try {
                uni.setStorageSync('uniEnv', process.uniEnv) // 打包后没有process
                uni.setStorageSync('subdomain', process.uniEnv.subdomain) // 打包后没有process
            } catch {
            }
        }
        console.log(window.location.port,'window.location.port ');
        uni.setStorageSync('subdomain',(window.location.port === '3000'||window.location.host === 'etaoh5dz-pre.edstao.com')?'fl':'fl')
    });
    onShow(() => {
        console.log("App Show");
    });
    onHide(() => {
        console.log("App Hide");
    });
</script>
<style lang="scss">
	.host_tip {
		color: #ff5500;
		border: 1px solid #ff5500;
		font-size: 12px;
		margin-right: 2px;
		font-weight: bold;
		padding: 0 1px
	}
	.van-badge{
		border: 1px!important;
	}
	.sign {
		position: absolute;
		right: 1.8vw;
		top: 2vw;
		width: 40px;
		text-align: center;

		img {
			width: 40px;
			margin-bottom: -18px;
		}

		.discount {
			font-family: MiSans-Semibold;
			text-shadow: 0.5px 0.5px #ddd;
			color: #A532E0;
			font-weight: 1000;
			font-size: 12px;
		}
	}
	// #ifdef H5
	uni-page-head {
		display: none;
	}

	.noLandScape {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		display: flex;
		justify-content: center;
		text-align: center;
		background: gray;
		display: none;

		img {
			max-width: 100vw;
			max-height: 100vh;
		}
	}

	// @media screen and (orientation: portrait) and (max-width:1024px) {
	//   .noLandScape {
	//     z-index: 0;
	//     display: none;
	//   }
	// }

	// @media screen and (orientation: landscape) and (max-width:1024px) {
	//   .noLandScape {
	//     z-index: 99999;
	//     display: block;
	//   }
	// }
	// #endif
</style>
