提交代码
This commit is contained in:
@@ -213,13 +213,32 @@
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 新增页面 iframe 对话框 -->
|
||||
<el-dialog
|
||||
v-model="showAddIframe"
|
||||
title="新增采购申请"
|
||||
width="1000px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="true"
|
||||
destroy-on-close
|
||||
@close="closeAddIframe">
|
||||
<div class="iframe-dialog-content">
|
||||
<iframe
|
||||
ref="addIframeRef"
|
||||
:src="addIframeSrc"
|
||||
frameborder="0"
|
||||
class="add-iframe"
|
||||
@load="onIframeLoad" />
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 编辑、新增表单对话框 -->
|
||||
<FormDialog ref="formDialogRef" @refresh="getDataList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="PurchasingRequisition">
|
||||
import { ref, reactive, defineAsyncComponent } from 'vue'
|
||||
import { ref, reactive, defineAsyncComponent, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { getPage, delObj } from "/@/api/finance/purchasingrequisition";
|
||||
@@ -235,6 +254,9 @@ const tableRef = ref()
|
||||
const formDialogRef = ref()
|
||||
const searchFormRef = ref()
|
||||
const showSearch = ref(true)
|
||||
const showAddIframe = ref(false)
|
||||
const addIframeRef = ref<HTMLIFrameElement>()
|
||||
const addIframeSrc = ref('')
|
||||
|
||||
/**
|
||||
* 定义响应式表格数据
|
||||
@@ -265,12 +287,42 @@ const handleReset = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增采购申请 - 跳转到新页面
|
||||
* 新增采购申请 - 在 iframe 中展示
|
||||
*/
|
||||
const handleAdd = () => {
|
||||
router.push({
|
||||
path: '/finance/purchasingrequisition/add'
|
||||
});
|
||||
// 构建 iframe 的 src,使用当前页面的 hash 路由
|
||||
const baseUrl = window.location.origin + window.location.pathname
|
||||
addIframeSrc.value = `${baseUrl}#/finance/purchasingrequisition/add`
|
||||
showAddIframe.value = true
|
||||
// 监听来自 iframe 的消息
|
||||
window.addEventListener('message', handleIframeMessage)
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭新增 iframe
|
||||
*/
|
||||
const closeAddIframe = () => {
|
||||
showAddIframe.value = false
|
||||
// 移除消息监听器
|
||||
window.removeEventListener('message', handleIframeMessage)
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理 iframe 发送的消息
|
||||
*/
|
||||
const handleIframeMessage = (event: MessageEvent) => {
|
||||
// 验证消息来源(可选,根据实际需求)
|
||||
// if (event.origin !== window.location.origin) return
|
||||
|
||||
if (event.data && event.data.type === 'purchasingrequisition:submitSuccess') {
|
||||
// 提交成功,关闭 iframe 并刷新列表
|
||||
closeAddIframe()
|
||||
getDataList()
|
||||
useMessage().success('提交成功')
|
||||
} else if (event.data && event.data.type === 'purchasingrequisition:close') {
|
||||
// 关闭 iframe
|
||||
closeAddIframe()
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -296,9 +348,31 @@ const handleDelete = async (row: any) => {
|
||||
useMessage().error(err.msg || '删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 组件卸载时清理事件监听器
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('message', handleIframeMessage)
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import '/@/assets/styles/modern-page.scss';
|
||||
|
||||
.iframe-dialog-content {
|
||||
width: 100%;
|
||||
height: 70vh;
|
||||
min-height: 500px;
|
||||
position: relative;
|
||||
|
||||
.add-iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-dialog__body) {
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user