当前位置:网站首页>Apiccloud implements the document download and preview functions

Apiccloud implements the document download and preview functions

2022-06-26 11:14:00 The broad sea leaps with the fish_ api

There are a lot of document downloads app, Especially the functions commonly used in enterprise applications . Use APICloud Development app when , have access to api.download Method implementation Download ; Preview the document using superFile modular .superFile The module encapsulates the browsing service based on Tencent TBS, Use X5Webkit kernel , Realize the display function of documents , Support multiple file formats (PDF、Word、Execl、TXT、PPT).

Add... To the project superFile modular :

Then compile the custom loader , Put custom loader Install the installation package on the mobile phone , And then you can use it APICloud Studio3 wifi sync , Synchronize code to custom loader Debugging in . Reference tutorial : APICloud Customize loader explain – mobile phone APP Development 、APP Make 、APP Customized platform

The example code is as follows : 

<template>
	<safe-area>
		<scroll-view class="main" scroll-y>
			<view><text onclick='this.downloadDoc_open'> Download and open document </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: '',  //  Fill in the file to download url
				savePath: 'fs://myapp/test.doc',
				report: true,
				cache: true,
				allowResume: true
			}, function (ret, err) {
				if (ret.state == 1) {
					// Download successful 
					console.log(JSON.stringify(ret));
					if (api.systemType == 'ios') {
						// ios   No initialization required , direct 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 broad sea leaps with the fish_ api]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261020287041.html