关于app开发:APICloud-实现文档下载和预览功能

2次阅读

共计 1156 个字符,预计需要花费 3 分钟才能阅读完成。

文档下载是很多 app,尤其是企业应用中罕用的性能。应用 APICloud 开发 app 时,能够应用 api.download 办法实现下载;预览文档能够应用 superFile 模块。superFile 模块封装了基于腾讯浏览服务 TBS,应用 X5Webkit 内核,实现文件的展现性能,反对多种文件格式(PDF、Word、Execl、TXT、PPT)。

在我的项目中增加 superFile 模块:

而后编译自定义 loader,把自定义 loader 安装包装置到手机上,而后就能够应用 APICloud Studio3 wifi 同步性能,把代码同步到自定义 loader 中进行调试。参考教程:https://docs.apicloud.com/Dev-Guide/Custom_Loader

实例代码如下: 

<template>
    <safe-area>
        <scroll-view class="main" scroll-y>
            <view><text onclick='this.downloadDoc_open'> 下载并打开文档 </text></view>
        </scroll-view>
    </safe-area>
</template>
<style>
.main {
    width: 100%;
    height: 100%;
    background-color: #fff;
}
</style>
<script>
export default {
    name: 'test',
    data() {return {}
    },
    apiready() {},
    methods: {downloadDoc_open() {
            api.download({
                url: '',  // 填写要下载文档的 url
                savePath: 'fs://myapp/test.doc',
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {if (ret.state == 1) {
                    // 下载胜利
                    console.log(JSON.stringify(ret));
                    if (api.systemType == 'ios') {
                        // ios  不须要初始化,间接 open
                        var superFile = api.require('superFile');
                        superFile.open({path: ret.savePath,})
                    }
                    if (api.systemType == 'android') {console.log(2);
                        var superFile = api.require('superFile');
                        superFile.init(function (ret) {if (ret.eventType == 'onViewInitFinished') {
                                superFile.open({path: ret.savePath})
                            }
                        });
                    }
                }
            });
        }

    }
}
</script>
正文完
 0