<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 iframe = ref(null);
const token = ref("");
// function load() {
// 	iframe.value.contentWindow.postMessage("Message from parent：load complate！");
// }
//获取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);
				iframe.value.contentWindow.postMessage({ token });
				// getBimfaceToken(item.fileId);
			}
		});
	});
}
//获取token
// function getBimfaceToken(fileId) {
// 	getViewTokenByFileId({ projectSn: store.sn, fileId }).then(res => {
// 		console.log("token结果", res);
//
// 	});
// }
onMounted(() => {
	url.value = window.location.origin + "/static/bim.html";
	console.log("url-------的地址", window.location.origin);
	getBimfaceList();
});
</script>

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