217 lines
6.7 KiB
Vue
217 lines
6.7 KiB
Vue
<template>
|
||
<div class="default-main" :style="{ padding: prop.height ? '0px !important' : '10px' }">
|
||
<!-- 实时数据 -->
|
||
<!-- 实时数据 走驾驶舱-->
|
||
<!-- 添加加载事件监听 -->
|
||
<div class="dataBox" :style="{ height: prop.height ? prop.height : pageHeight.height }">
|
||
<div
|
||
class="iframe-container"
|
||
:style="{
|
||
boxShadow: `var(--el-box-shadow-light)`
|
||
}"
|
||
style="position: relative"
|
||
>
|
||
<iframe
|
||
:src="iframeSrc"
|
||
width="100%"
|
||
height="100%"
|
||
frameborder="0"
|
||
scrolling="no"
|
||
id="iframeLeft"
|
||
@load="onIframeLoad"
|
||
></iframe>
|
||
</div>
|
||
|
||
<el-card class="bottom-container" style="min-height: 230px">
|
||
<!-- <div class="buttonBox">
|
||
<el-button type="primary" icon="el-icon-Aim" @click="reset">复位</el-button>
|
||
</div> -->
|
||
<div class="tableBox">
|
||
<!-- <Table ref="tableRef" height="100%"></Table> -->
|
||
<vxe-table border auto-resize height="100%" :data="tableData" ref="tableRef">
|
||
<vxe-column type="seq" title="序号" align="center" width="80px"></vxe-column>
|
||
<vxe-column field="date" align="center" title="时间" width="200px"></vxe-column>
|
||
<vxe-column field="name" align="center" title="监测点名" width="200px"></vxe-column>
|
||
<vxe-column field="address" align="center" title="事件描述"></vxe-column>
|
||
</vxe-table>
|
||
</div>
|
||
</el-card>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { ref, watch, onMounted, onUnmounted, provide } from 'vue'
|
||
import Table from '@/components/table/index.vue'
|
||
import TableStore from '@/utils/tableStore'
|
||
import { mainHeight } from '@/utils/layout'
|
||
// import { getActive } from "@/api/manage_wx/index";
|
||
|
||
// const props = defineProps<{
|
||
// project: { id: string; name: string } | null
|
||
// }>()
|
||
|
||
const prop = defineProps({
|
||
width: { type: [String, Number] },
|
||
height: { type: [String, Number] },
|
||
timeKey: { type: Array as () => string[] },
|
||
timeValue: { type: Object }
|
||
})
|
||
|
||
const tableData = ref()
|
||
|
||
// 在父页面中添加事件监听器
|
||
window.addEventListener('message', function (event) {
|
||
const { action, data } = event.data
|
||
|
||
if (action == 'securityDetailData') {
|
||
console.log('tableArray:', data)
|
||
// 处理接收到的 tableArray 数据
|
||
tableData.value = data
|
||
}
|
||
})
|
||
|
||
const tableRef = ref()
|
||
|
||
const pageHeight = mainHeight(40)
|
||
|
||
const reset = () => {
|
||
// 向 iframe 发送复位事件
|
||
sendResetToIframe()
|
||
// 清空表格数据
|
||
// tableData.value = [];
|
||
}
|
||
|
||
// 向 iframe 发送复位消息的函数
|
||
const sendResetToIframe = () => {
|
||
const iframe = document.getElementById('iframeLeft') as HTMLIFrameElement
|
||
if (iframe && iframe.contentWindow) {
|
||
iframe.contentWindow.postMessage(
|
||
{
|
||
type: 'RESET_EVENT',
|
||
payload: true
|
||
},
|
||
'*' // 生产环境中应替换为具体的域名
|
||
)
|
||
}
|
||
}
|
||
|
||
const iframeSrc = ref('')
|
||
|
||
// 监听 props 变化
|
||
// watch(
|
||
// () => props.project,
|
||
// newVal => {
|
||
// if (newVal && newVal.id && newVal.name) {
|
||
// // window.location.origin
|
||
// // iframeSrc.value =
|
||
// // "http://192.168.1.179:4001" +
|
||
// // `/zutai/?id=${newVal.id}&&name=${encodeURIComponent(
|
||
// // newVal.name
|
||
// // )}&&preview=true&&display=true&&graphicDisplay=wx#/preview`;
|
||
// iframeSrc.value =
|
||
// 'http://192.168.1.179:4001' +
|
||
// `/zutai/?id=4b4f7f4260198776594f5f9d93a532e8&&name=stt&&preview=true&&display=true#/preview_YPT`
|
||
|
||
// // console.log("更新 iframeSrc:", iframeSrc.value);
|
||
// }
|
||
// },
|
||
// { immediate: true, deep: true }
|
||
// )
|
||
|
||
onMounted(() => {
|
||
iframeSrc.value =
|
||
window.location.origin + `/zutai/?id=4b4f7f4260198776594f5f9d93a532e8&&name=stt&&preview=true#/preview_YPT`
|
||
|
||
// tableStore.index()
|
||
|
||
// 监听来自 eventStatistics 组件的消息
|
||
window.addEventListener('message', handleMessage)
|
||
|
||
// getActive({}).then((res: any) => {
|
||
// if (res.code == "A0000") {
|
||
// // window.location.origin
|
||
// iframeSrc.value =
|
||
// "http://192.168.1.179:4001" +
|
||
// `/zutai/?id=${res.data.id}&&name=${encodeURIComponent(
|
||
// res.data.name
|
||
// )}&&preview=true&&display=true&&graphicDisplay=wx#/preview`;
|
||
// }
|
||
// });
|
||
})
|
||
|
||
onUnmounted(() => {
|
||
// 清理事件监听器
|
||
window.removeEventListener('message', handleMessage)
|
||
})
|
||
|
||
// iframe 加载完成回调 添加加载事件监听
|
||
const onIframeLoad = () => {
|
||
// 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
|
||
},
|
||
'*'
|
||
) // 在生产环境中应该指定具体的域名而不是 '*'
|
||
}
|
||
}
|
||
</script>
|
||
<style lang="scss" scoped>
|
||
.dataBox {
|
||
width: 100%;
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.iframe-container {
|
||
flex: 3.5;
|
||
}
|
||
|
||
:deep(.el-card__body) {
|
||
display: flex;
|
||
padding: 10px;
|
||
height: 100%;
|
||
|
||
.buttonBox {
|
||
display: flex;
|
||
width: 150px;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.tableBox {
|
||
flex: 1;
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|