<script lang="ts" setup>
|
import { onMounted, reactive } from 'vue';
|
|
import { useGlobSetting } from '@jnpf/hooks';
|
import { BasicPopup, usePopupInner } from '@jnpf/ui/popup';
|
|
import { useAccessStore } from '@vben/stores';
|
|
import { getDataReportInfo } from '#/api/onlineDev/dataReport';
|
import { getRealJnpfAppEnCode } from '#/utils/jnpf';
|
|
interface State {
|
url: string;
|
}
|
|
defineEmits(['register']);
|
const { dataReportPre } = useGlobSetting();
|
const accessStore = useAccessStore();
|
const [registerPopup, { closePopup }] = usePopupInner(init);
|
const state = reactive<State>({
|
url: '',
|
});
|
|
function init(data) {
|
let targetUrl = `${dataReportPre}/preview.html?id=${data.id}&token=${accessStore.accessToken}&appCode=${getRealJnpfAppEnCode()}&page=1`;
|
getDataReportInfo(data.id).then((res) => {
|
const item = {};
|
if (res.data?.searchForm?.components && Array.isArray(res.data.searchForm.components)) {
|
listQuery(res.data.searchForm.components, item);
|
for (const key in item) {
|
const item1 = `&${key}=${item[key]}`;
|
targetUrl += item1;
|
}
|
}
|
state.url = targetUrl;
|
});
|
}
|
function listQuery(list, callback) {
|
for (const item of list) {
|
let arrayList: any[] = [];
|
if (item.cols && Array.isArray(item.cols)) {
|
arrayList = [...arrayList, ...item.cols];
|
}
|
if (item.children && Array.isArray(item.children)) {
|
arrayList = [...arrayList, ...item.children];
|
}
|
if (item.bindParameter && item.defaultValue) {
|
callback[item.bindParameter] = item.defaultValue;
|
}
|
listQuery(arrayList, callback);
|
}
|
}
|
function handleMessage(e) {
|
const data = e.data;
|
if (data !== 'closeDialog') return;
|
state.url = '';
|
closePopup();
|
}
|
|
onMounted(() => {
|
window.addEventListener('message', handleMessage);
|
});
|
</script>
|
<template>
|
<BasicPopup v-bind="$attrs" @register="registerPopup" class="full-popup report-popup">
|
<iframe :src="state.url" width="100%" height="100%" frameborder="0"></iframe>
|
</BasicPopup>
|
</template>
|
<style lang="scss">
|
.report-popup {
|
.jnpf-basic-popup-header {
|
display: none !important;
|
}
|
}
|
</style>
|