当前位置:网站首页>APICloud 实现文档下载和预览功能
APICloud 实现文档下载和预览功能
2022-06-26 10:21:00 【海阔凭鱼跃_api】
文档下载是很多app,尤其是企业应用中常用的功能。使用APICloud开发app时,可以使用api.download方法实现下载;预览文档可以使用superFile 模块。superFile 模块封装了基于腾讯浏览服务TBS,使用X5Webkit内核,实现文件的展示功能,支持多种文件格式(PDF、Word、Execl、TXT、PPT)。
在项目中添加superFile模块:

然后编译自定义loader ,把自定义loader 安装包安装到手机上,然后就可以使用APICloud Studio3 wifi 同步功能,把代码同步到自定义loader 中进行调试。 参考教程: APICloud 自定义loader说明 – 手机APP开发、APP制作、APP定制平台
实例代码如下:
<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>边栏推荐
- The difference between NPM and yarn
- 在Oracle中update大量数据会不会导致undo空间爆掉
- Plookup table in appliedzkp zkevm (8)
- 机器学习线性回归——实验报告
- Machine Learning Clustering - Experimental Report
- [echart] i. how to learn echart and its characteristic document reading notes
- Laravel admin obtains non auto increment ID and submits hidden forms
- MySQL performance monitoring and SQL statements
- 3、 Linked list exercise
- mysql性能监控和sql语句
猜你喜欢
随机推荐
JS take the date of the previous month 【 pit filling 】
Expand and collapse too high div
[echart] i. how to learn echart and its characteristic document reading notes
UDP Flood攻击防御原理
Moore vote, leetcode169, leetcode229
CEPH operation and maintenance common instructions
Nacos2.x.x start error creating bean with name 'grpcclusterserver';
一键部署属于自己的社区论坛
9、 Beautify tables, forms, and hyperlinks
动态规划解决股票问题(下)
Tape library simple record 1
PC qq Hall upload Update Modifying versioninfo
wangEditor 上传本地视频修改
openresty 概述
滑动窗口
2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告
Machine learning PCA - Experimental Report
关于印发《深圳市福田区支持战略性新兴产业和未来产业集群发展若干措施》的通知
[echart] II. User manual and configuration item reading notes
SQL index learning notes



![[work details] March 18, 2020](/img/24/a72230daac08e7ec5bd57df08071f8.jpg)





