2025-09-25 13:32:47 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="plan">
|
2025-10-27 14:09:47 +08:00
|
|
|
|
<bdMap
|
|
|
|
|
|
v-show="store.state.showMap"
|
|
|
|
|
|
width="100%"
|
|
|
|
|
|
height="100%"
|
|
|
|
|
|
@pointClick="pointClick"
|
|
|
|
|
|
></bdMap>
|
2025-10-27 13:21:31 +08:00
|
|
|
|
|
2025-09-25 13:32:47 +08:00
|
|
|
|
<!-- 添加加载事件监听 -->
|
|
|
|
|
|
<iframe
|
2025-10-27 13:21:31 +08:00
|
|
|
|
v-if="!store.state.showMap"
|
2025-09-25 13:32:47 +08:00
|
|
|
|
:src="iframeSrc"
|
|
|
|
|
|
width="100%"
|
|
|
|
|
|
height="100%"
|
|
|
|
|
|
frameborder="0"
|
|
|
|
|
|
scrolling="no"
|
|
|
|
|
|
id="iframeLeft"
|
|
|
|
|
|
@load="onIframeLoad"
|
|
|
|
|
|
></iframe>
|
2025-10-27 14:09:47 +08:00
|
|
|
|
<el-button class="backButton" @click="backButton" size="small" :icon="Back"
|
|
|
|
|
|
>返回</el-button
|
|
|
|
|
|
>
|
2025-09-25 13:32:47 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { ref, watch, onMounted, onUnmounted } from "vue";
|
|
|
|
|
|
import { getActive } from "@/api/manage_wx/index";
|
2025-10-27 14:09:47 +08:00
|
|
|
|
import { Back } from "@element-plus/icons-vue";
|
2025-10-27 13:21:31 +08:00
|
|
|
|
import bdMap from "./bdMap.vue";
|
2025-10-27 14:09:47 +08:00
|
|
|
|
import { useStore } from "vuex";
|
2025-10-27 08:55:54 +08:00
|
|
|
|
const store = useStore();
|
2025-09-25 13:32:47 +08:00
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
project: { id: string; name: string } | null;
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const iframeSrc = ref("");
|
|
|
|
|
|
|
|
|
|
|
|
// 监听 props 变化
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => props.project,
|
|
|
|
|
|
(newVal) => {
|
|
|
|
|
|
if (newVal && newVal.id && newVal.name) {
|
|
|
|
|
|
// window.location.origin
|
|
|
|
|
|
iframeSrc.value =
|
2025-10-22 09:05:35 +08:00
|
|
|
|
window.location.origin +
|
2025-10-27 08:55:54 +08:00
|
|
|
|
// "http://192.168.1.128:4001" +
|
2025-09-25 13:32:47 +08:00
|
|
|
|
`/zutai/?id=${newVal.id}&&name=${encodeURIComponent(
|
|
|
|
|
|
newVal.name
|
|
|
|
|
|
)}&&preview=true&&display=true&&graphicDisplay=wx#/preview`;
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("更新 iframeSrc:", iframeSrc.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true, deep: true }
|
|
|
|
|
|
);
|
2025-10-27 14:09:47 +08:00
|
|
|
|
// 点击监测点传入 接线图id
|
|
|
|
|
|
const pointClick = (row: any) => {
|
|
|
|
|
|
setUrl(row.pictureId, row.pictureName);
|
|
|
|
|
|
};
|
2025-09-25 13:32:47 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
// 监听来自 eventStatistics 组件的消息
|
|
|
|
|
|
window.addEventListener("message", handleMessage);
|
|
|
|
|
|
getActive({}).then((res: any) => {
|
|
|
|
|
|
if (res.code == "A0000") {
|
|
|
|
|
|
// window.location.origin
|
2025-10-27 14:09:47 +08:00
|
|
|
|
setUrl(res.data.id, res.data.name);
|
2025-09-25 13:32:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-10-27 14:09:47 +08:00
|
|
|
|
const setUrl = (url: string, nam: string) => {
|
|
|
|
|
|
iframeSrc.value =
|
|
|
|
|
|
// window.location.origin +
|
|
|
|
|
|
"http://192.168.1.179:4001" +
|
|
|
|
|
|
`/zutai/?id=${url}&&name=${encodeURIComponent(
|
|
|
|
|
|
nam
|
|
|
|
|
|
)}&&preview=true&&display=true&&graphicDisplay=wx#/preview`;
|
|
|
|
|
|
// const iframe = document.getElementById("iframeLeft");
|
|
|
|
|
|
// if (iframe) {
|
|
|
|
|
|
// // 监听 iframe 加载完成事件
|
|
|
|
|
|
// iframe.addEventListener("load", function () {
|
|
|
|
|
|
// // 通知父页面:我已加载完毕
|
|
|
|
|
|
// store.dispatch("setStateKey", { key: "iframeLoad", value: true });
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
};
|
2025-09-25 13:32:47 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
// 清理事件监听器
|
|
|
|
|
|
window.removeEventListener("message", handleMessage);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// iframe 加载完成回调 添加加载事件监听
|
|
|
|
|
|
const onIframeLoad = () => {
|
2025-10-27 14:09:47 +08:00
|
|
|
|
store.dispatch("setStateKey", { key: "iframeLoad", value: true });
|
2025-09-25 13:32:47 +08:00
|
|
|
|
// console.log("iframe 加载完成");
|
|
|
|
|
|
// 通知 securityDetail.vue 组件 iframe 已加载完成
|
|
|
|
|
|
window.postMessage(
|
|
|
|
|
|
{
|
|
|
|
|
|
type: "IFRAME_LOADED",
|
|
|
|
|
|
data: { loaded: true },
|
|
|
|
|
|
},
|
|
|
|
|
|
"*"
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 处理来自 eventStatistics 组件的消息
|
|
|
|
|
|
const handleMessage = (event: MessageEvent) => {
|
|
|
|
|
|
// 验证消息来源(在生产环境中应该验证 origin)
|
|
|
|
|
|
// if (event.origin !== 'trusted-origin') return;
|
|
|
|
|
|
|
|
|
|
|
|
const { type, payload } = event.data;
|
|
|
|
|
|
|
|
|
|
|
|
if (type === "SEND_KEYS_TO_IFRAME") {
|
|
|
|
|
|
// 将数据转发给 iframe
|
|
|
|
|
|
sendKeysToIframe(payload);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 向 iframe 发送 keyList 数据
|
|
|
|
|
|
const sendKeysToIframe = (keyList: string[]) => {
|
|
|
|
|
|
const iframe = document.getElementById("iframeLeft") as HTMLIFrameElement;
|
|
|
|
|
|
if (iframe && iframe.contentWindow) {
|
|
|
|
|
|
iframe.contentWindow.postMessage(
|
|
|
|
|
|
{
|
|
|
|
|
|
type: "ANALYSIS_KEYS",
|
|
|
|
|
|
payload: keyList,
|
|
|
|
|
|
},
|
|
|
|
|
|
"*"
|
|
|
|
|
|
); // 在生产环境中应该指定具体的域名而不是 '*'
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-10-27 14:09:47 +08:00
|
|
|
|
// 返回地图
|
|
|
|
|
|
const backButton = () => {
|
|
|
|
|
|
window.removeEventListener("message", handleMessage);
|
|
|
|
|
|
store.dispatch("setStateKey", { key: "showMap", value: true });
|
|
|
|
|
|
};
|
2025-09-25 13:32:47 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.plan {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 990px;
|
|
|
|
|
|
padding: 5px;
|
|
|
|
|
|
}
|
2025-10-27 14:09:47 +08:00
|
|
|
|
.backButton {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
right: 10px;
|
|
|
|
|
|
top: 10px;
|
|
|
|
|
|
z-index: 1;
|
|
|
|
|
|
}
|
2025-09-25 13:32:47 +08:00
|
|
|
|
</style>
|