当前位置:网站首页>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>边栏推荐
- mysql性能监控和sql语句
- Notes - simple but adequate series_ KVM quick start
- Getting started with postman
- Hazelnut cloud - SMS (tool)
- SQL Server foundation introduction collation
- MySQL performance monitoring and SQL statements
- 【北邮果园微处理器设计】10 Serial Communication 串口通信笔记
- Tape library simple record 1
- JS take the date of the previous month 【 pit filling 】
- Detailed explanation of MySQL fuzzy query
猜你喜欢

Using reflection to export entity data to excel

Vscode environment setup: synchronous configuration

Machine learning deep neural network -- Experimental Report

Redis (basic) - learning notes

MQTT断开重连

TCP面试

【深度学习理论】(7) 长短时记忆网络 LSTM

机器学习线性回归——实验报告
![[echart] II. User manual and configuration item reading notes](/img/03/fa87e5b8f8d23381ea6923d507f250.jpg)
[echart] II. User manual and configuration item reading notes

loggie 编码以及换行符测试
随机推荐
MySQL模糊查询详解
【北邮果园微处理器设计】10 Serial Communication 串口通信笔记
Server single and two-way adjustable one key mutual trust script!
.net中,日志组件 Nlog,SerialLog, Log4Net的用法
[echart] II. User manual and configuration item reading notes
9、 Beautify tables, forms, and hyperlinks
Hazelnut cloud - SMS (tool)
机器学习聚类——实验报告
你好!正向代理!
最牛X的CMDB系统
Character sets and comparison rules
redux相关用法
基于slate构建文档编辑器
Is it safe for compass software to buy stocks for trading? How to open an account to buy shares
Fabric. JS upper dash, middle dash (strikethrough), underline
UDP Flood攻击防御原理
Detailed explanation of MySQL fuzzy query
Laravel admin uses native JS to realize sound prompt and automatic playback
4、 Stacks and queues
Laravel-admin 登录添加图形验证码