<template>
	<div class="bimBox">
		<iframe :src="url" frameborder="0" width="100%" height="100%" id="iframe"></iframe>
	</div>
</template>

<script lang="ts" setup>
import { GlobalStore } from "@/stores";
import { getSelectProjectBimfaceList, getViewTokenByFileId } from "@/api/modules/binModel";
import { ref, onMounted } from "vue";
const store = GlobalStore();
const url = ref("");
const token = ref("" as any);
//获取bim列表
function getBimfaceList() {
	getSelectProjectBimfaceList({ projectSn: store.sn }).then(res => {
		res.result.page.records.forEach(item => {
			if (item.isEnable) {
				token.value = res.result.viewToken;
				console.log("token的值", token.value);
				localStorage.setItem("bimToken", JSON.stringify(token.value));
				// let iframe: any = document.getElementById("iframe");
				// console.log(iframe, "我的测试");
				// setTimeout(() => {
				// 	iframe.contentWindow.postMessage({ token: token.value });
				// }, 500);
			}
		});
	});
}

//获取token
// function getBimfaceToken(fileId) {
// 	getViewTokenByFileId({ projectSn: store.sn, fileId }).then(res => {
// 		console.log("token结果", res);
//
// 	});
// }
onMounted(async () => {
	// url.value = "http://jxj.zhgdyun.com:9809/static/bim.html";
	url.value = window.location.origin + "/static/bim.html";
	console.log("url-------的地址", window.location.origin);
	await getBimfaceList();
});
</script>

<style lang="scss" scoped>
.bimBox {
	width: 100%;
	height: 100%;
}
</style>
