<template>
	<div class="main">
		<div class="bg_gif"></div>
	</div>
</template>

<script setup name="load">
import { onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { userAnalysis } from "@/api/modules/huizhou";
import { ElMessage } from "element-plus";
import { GlobalStore } from "@/stores";
import { TabsStore } from "@/stores/modules/tabs";
import { KeepAliveStore } from "@/stores/modules/keepAlive";
import { initDynamicRouter } from "@/routers/modules/dynamicRouter";
import { getHomePage } from "@/api/modules/goverment";
const router = useRouter();
const route = useRoute();
const globalStore = GlobalStore();
const tabsStore = TabsStore();
const keepAlive = KeepAliveStore();

onMounted(() => {
	tokenIdentify();
});

const tokenIdentify = async () => {
	const res = await userAnalysis({
		ssoToken: route.query.token
	});
	console.log(res);
	if (res.result) {
		let responseData = res.result;
		globalStore.setToken(responseData.token);
		globalStore.setAccount(responseData.account);
		globalStore.setAccountType(responseData.accountType);
		globalStore.setProjectDateAuth(responseData.projectDateAuth);
		globalStore.setIsManager(responseData.isManager); //我已知晓
		// 2.添加动态路由
		// await initDynamicRouter();
		// router.push(arr[result.accountType - 1]);
		// 3.清空 tabs、keepAlive 保留的数据
		// 获取module
		const res1 = await getHomePage();
		let data = {};
		data = res1.result || {};
		tabsStore.closeMultipleTab();
		keepAlive.setKeepAliveName();
		await sendMessage({ isSuccess: true }, 2);
		globalStore.setPath(data["惠州项目"][0].modulePath);
		await initDynamicRouter({ moduleId: data["惠州项目"][0].moduleId });
		globalStore.moduleId = data["惠州项目"][0].moduleId;
		// if (responseData.accountType === 2) {
		// 	await sendMessage({ isSuccess: true }, 2);
		// 	globalStore.setPath("/goverment/huizhou/largeScreen/largeScreenOne/index");
		// 	await initDynamicRouter({ moduleId: "1670639811581595650" });
		// 	globalStore.moduleId = "1670639811581595650";
		// } else if (responseData.accountType == 3) {
		// 	await sendMessage({ isSuccess: true }, 2);
		// 	globalStore.setPath("/goverment/huizhou/projectList/index");
		// 	await initDynamicRouter({ moduleId: "1681837103227502594" });
		// 	globalStore.moduleId = "1681837103227502594";
		// }
	} else {
		// ElMessage.error("登录信息异常，请刷新或重新登录！");
		return;
	}
};
const sendMessage = (msg, type, iframeEle) => {
	console.log(666);
	if (type === 1) {
		// 父 => 子
		iframeEle.contentWindow.postMessage(msg, "*");
	} else if (type === 2) {
		// 子 => 父
		window.parent.postMessage(msg, "*");
	}
	console.log(777);
};
</script>
<style scoped lang="scss">
.main {
	width: 100%;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #0e111f;

	.bg_gif {
		width: 30%;
		height: 520px;
		background: url("@/assets/images/123.gif") no-repeat;
		background-size: 100%;
	}
}
</style>
