当前位置:网站首页>Using apiccloud to realize document download and Preview

Using apiccloud to realize document download and Preview

2022-06-21 15:47:00 Ice cream happy

There are a lot of document downloads app, Especially the functions commonly used in enterprise applications . Use APICloud(www.apicloud.com) 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 : https://docs.apicloud.com/Dev-Guide/Custom_Loader

 

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>

 

原网站

版权声明
本文为[Ice cream happy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211532427405.html