Easy Pivot Logo
  • 定价

安装与升级

使用

文件夹系统数据源
定时任务资源分享资源依赖分析用户与权限管理Restful接口

外部系统集成

以 iframe 形式嵌入看板多看报集成父页面异步消息交互Vue2组件化集成IBI功能模块整合到外部系统

常见问题

外部系统集成

多看报集成父页面异步消息交互

多看报集成父页面异步消息交互

多看报集成父页面异步消息交互

0 流程概览

  1. url里面传入一个参数waitMsg=true,标记不要直接加载看板等消息
  2. iframe所有相关资源加载好之后,postMessage给父页面,消息内容为‘ready’
  3. 父页面接到消息之后,再把之前所有在url里面传递的数据传给iframe

1 开启异步交互模式

url传参waitMessage=true
http://ip:port[/ibi]/render-lite.html?waitMessage=true

该模式只支持多看报集成

2 等待iframe资源加载完毕消息

当集成iframe展示看板需要的js、css资源加载完毕之后,iframe会向父页面发送加载完毕消息,加载完毕消息为'ready'字符串

window.addEventListener('message', function (event) {
                if (event.data == 'ready') {
                    vm.loadBoard();
                }
            });

3 向iframe发送初次加载看板所需数据

消息格式为js对象,需要有type='loadBoard'属性,该消息只会在iframe中触发一次

属性值解释
type'loadBoard',必须值,标识该消息类型
userName必须值,ibi用户名
password必须值,ibi密码
boards必须值,指定加载看板
baseServerUrl可选值,切换ibi服务端地址
height可选值,iframe页面内容器高度,为css style字符串
background可选值,看板容器背景色
locale可选值,国际化语言,cn/en
loadBoard() {
    const iframe = document.getElementById('frm');
    iframe.contentWindow.postMessage({
        type: 'loadBoard',
        boards: [
                    {boardId: 1, title: "表格看板2"},
                    {boardId: 2, title: "综合看板2"},
                ],
        userName: 'peter',
        password: 'peter',
        background: 'white',
        height: 'calc(100vh - 40px)',
    }, '*');
},

4 更新boards数据

消息格式为js对象,boards为新看板数据

updateBoard2() {
    const iframe = document.getElementById('frm');
    iframe.contentWindow.postMessage({
        type: 'updateBoard',
        boards: [
            {boardId: 3, title: "地图合集"},
            {boardId: 4, title: "其他图形综合看板"},
        ],
    }, '*');
}

5 完整实例

<template>
    <div style={{height: "calc(100vh - 160px)", overflow: "hidden"}}>
        <button @click="updateBoard">UpdateBoard1</button>
        <button @click="updateBoard2">UpdateBoard2</button>
        <iframe id="frm" :src="shareUrl" style={{width: "100%", height: "100vh", border: "none"}}></iframe>
    </div>
</template>

<script>

    export default {
        name: 'demo-iframe-tab2',
        props: {},
        components: {},
        data() {
            return {
                boards: [
                    {boardId: 1, title: "表格看板"},
                    {boardId: 9, title: "综合看板"},
                ]
            }
        },
        computed: {
            shareUrl() {
                let ret = `http://localhost:8026/cboard/render-lite.html?waitMessage=true`;
                return ret;
            }
        },
        methods: {
            loadBoard() {
                const iframe = document.getElementById('frm');
                iframe.contentWindow.postMessage({
                    type: 'loadBoard',
                    boards: this.boards,
                    userName: 'peter',
                    password: 'peter',
                    background: 'white',
                    height: 'calc(100vh - 40px)',
                }, '*');
            },
            updateBoard() {
                const iframe = document.getElementById('frm');
                iframe.contentWindow.postMessage({
                    type: 'updateBoard',
                    boards: [
                        {boardId: 1, title: "表格看板2"},
                        {boardId: 2, title: "综合看板2"},
                    ],
                }, '*');
            },
            updateBoard2() {
                const iframe = document.getElementById('frm');
                iframe.contentWindow.postMessage({
                    type: 'updateBoard',
                    boards: [
                        {boardId: 3, title: "地图合集"},
                        {boardId: 4, title: "其他图形综合看板"},
                    ],
                }, '*');
            },
        },
        mounted() {
            let vm = this;
            // 等待iframe资源准备完毕立即发送加载看板消息
            window.addEventListener('message', function (event) {
                if (event.data == 'ready') {
                    vm.loadBoard();
                }
            });
        }
    }
</script>

<style>
</style>

以 iframe 形式嵌入看板

以 iframe 形式嵌入看板

Vue2组件化集成

Vue2组件化集成

On this page

多看报集成父页面异步消息交互0 流程概览1 开启异步交互模式2 等待iframe资源加载完毕消息3 向iframe发送初次加载看板所需数据4 更新boards数据5 完整实例
登录免费试用