SuwellOFD JSAPI场景示例

1、实例化对象,jofdreader=new JOFDReader()

2、jofdreader调用registListener(String commandId,String functionName, boolean after);方法注册监听。

  • 参数说明:
    • commandId:String型,需要被设置回调的参数名。
    • functionName:String型,回调函数名,
    • after:boolean型,是否监听事后事件,true为事后监听,false为事前监听(是否在操作后触发监听,有些函数需要在操作前被监听,如打印,有些操作需要在操作后被监听,如转化)。
  • 以打开文件举例:jofdreader.registListener('f_open','showFile','true')

    3、jofdreader调用openFile(String filename)接口打开文件。

  • 参数说明:
    • filename:String型,本地文件路径、远程文件路径(http链接或ftp文件)。
  • 4、回调函数名获取监听结果,形如function functionName(message),operateresult字段判断是否打开成功。
    function showFile(message){}或window.showFile=(message)=>{}

    文件路径

    使用自定义保存按钮调用saveFile(String filename)方法,将文件保存到指定位置

  • 参数说明:
    • filename:String型,本地文件路径、远程URL链接或ftp文件路径。
  • 通过监听结果,判断是否打开成功

    保存路径
    查看接口调用示例
                                    
    //打开本地文件。
    async function openFile() {
        await jofdreader.registListener('f_open', 'showFile', 'true').then((data) => { })
        var path = document.getElementById("openPath").value;
        await jofdreader.openFile(path).then((data) => { });
        console.log('打开文件')
        window.showFile = async (res) => {
            var result = JSON.parse(res)
            if (result.operateresult === "1") {
                var savePath = document.getElementById("savePath").value;
                await jofdreader.saveFile(savePath, false).then((data) => {
                    console.log(data);
                })
            } else {
                alert("打开失败")
                }
            }
    }
    
    //上传文件
    jofdreader = new JOFDReader()
    async function saveFile() {
        await jofdreader.registListener('f_saveurl', 'savePerformed', 'true').then((data) => { })
            var path = document.getElementById("savePath").value;
            // 接收保存文件接口的响应结果,data中为响应结果
            await jofdreader.saveFile(path, false).then((data) => {
            console.log(data);
        })
    }
    
    //接收保存文件的监听结果
    function savePerformed(res) {
        console.log('监听结果', res)
        // res.operateresult === "1"为时,代表成功
    }