init
This commit is contained in:
7
xhs-mini-demos/api-case/download-file/download-file.css
Normal file
7
xhs-mini-demos/api-case/download-file/download-file.css
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
._dflex button {
|
||||
margin: 10px 0;
|
||||
background-color: red;
|
||||
color: white;
|
||||
}
|
||||
77
xhs-mini-demos/api-case/download-file/download-file.js
Normal file
77
xhs-mini-demos/api-case/download-file/download-file.js
Normal file
@@ -0,0 +1,77 @@
|
||||
const __templateJs = require("./templates.js");
|
||||
const __mergePageOptions = require("../../util/mergePageOptions.js");
|
||||
Page(__mergePageOptions({
|
||||
data: {
|
||||
remoteFilePath: 'https://fe-video-qc.xhscdn.com/fe-platform/541cb4b0e802f5bdd91845e85082132453f8d4f5.pdf',
|
||||
filePath: '',
|
||||
fileType: ''
|
||||
},
|
||||
onDownload() {
|
||||
this.task = xhs.downloadFile({
|
||||
url: this.data.remoteFilePath,
|
||||
// 文件 ID
|
||||
success: res => {
|
||||
console.log('【downloadFile success】:', res);
|
||||
this.setData({
|
||||
filePath: res.tempFilePath || res.filePath
|
||||
});
|
||||
},
|
||||
fail: res => {
|
||||
console.log('【downloadFile fail】:', res);
|
||||
}
|
||||
});
|
||||
if (this.task) {
|
||||
this.task.onHeadersReceived(res => {
|
||||
console.log('【onHeadersReceived】:', res);
|
||||
});
|
||||
this.task.onProgressUpdate(res => {
|
||||
console.log('【onProgressUpdate】:', res);
|
||||
});
|
||||
}
|
||||
},
|
||||
onAbort() {
|
||||
this.task?.abort();
|
||||
},
|
||||
offHeadersReceived() {
|
||||
this.task?.offHeadersReceived?.(() => {
|
||||
console.log('【offHeadersReceived】');
|
||||
});
|
||||
},
|
||||
offProgressUpdate() {
|
||||
this.task?.offProgressUpdate?.(() => {
|
||||
console.log('【offProgressUpdate】');
|
||||
});
|
||||
},
|
||||
removeSavedFile() {
|
||||
xhs.removeSavedFile({
|
||||
filePath: this.data.filePath,
|
||||
success: res => {
|
||||
console.log('【removeSavedFile success】', res);
|
||||
},
|
||||
fail: res => {
|
||||
console.log('【removeSavedFile fail】', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
openDocument() {
|
||||
xhs.openDocument({
|
||||
filePath: this.data.filePath,
|
||||
fileType: this.data.fileType || undefined
|
||||
});
|
||||
},
|
||||
handleRemoteFilePath(e) {
|
||||
this.setData({
|
||||
remoteFilePath: e.detail.value
|
||||
});
|
||||
},
|
||||
handleFilePath(e) {
|
||||
this.setData({
|
||||
filePath: e.detail.value
|
||||
});
|
||||
},
|
||||
handleFileType(e) {
|
||||
this.setData({
|
||||
fileType: e.detail.value
|
||||
});
|
||||
}
|
||||
}, __templateJs));
|
||||
8
xhs-mini-demos/api-case/download-file/download-file.json
Normal file
8
xhs-mini-demos/api-case/download-file/download-file.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "下载文件",
|
||||
"usingComponents": {
|
||||
"showbox": "../../common/component/showbox/index",
|
||||
"box": "../../common/component/container/index",
|
||||
"api-status": "../../common/component/api-status/index"
|
||||
}
|
||||
}
|
||||
36
xhs-mini-demos/api-case/download-file/download-file.xhsml
Normal file
36
xhs-mini-demos/api-case/download-file/download-file.xhsml
Normal file
@@ -0,0 +1,36 @@
|
||||
<view class="container">
|
||||
<showbox title="基本使用">
|
||||
<box>
|
||||
<view class="_ui-space">
|
||||
<view>
|
||||
<text>远程文件路径</text>
|
||||
<view class="_ui-input">
|
||||
<input placeholder="远程文件路径" value="{{remoteFilePath}}" bindinput="handleRemoteFilePath"/>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<text>本地文件路径</text>
|
||||
<view class="_ui-input">
|
||||
<input placeholder="本地文件路径" value="{{filePath}}" bindinput="handleFilePath"/>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<text>文件类型</text>
|
||||
<view class="_ui-input">
|
||||
<input placeholder="文件类型" value="{{fileType}}" bindinput="handleFileType"/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button bindtap="onDownload" class="_ui-button" hover-class="_ui-button-hover">下载文件</button>
|
||||
<!-- <button bindtap="onAbort" class="_ui-button" hover-class="_ui-button-hover">abort</button>
|
||||
<button bindtap="offHeadersReceived" class="_ui-button" hover-class="_ui-button-hover">offHeadersReceived</button>
|
||||
<button bindtap="offProgressUpdate" class="_ui-button" hover-class="_ui-button-hover">offProgressUpdate</button> -->
|
||||
<button bindtap="openDocument" class="_ui-button" hover-class="_ui-button-hover">打开文件</button>
|
||||
<button bindtap="removeSavedFile" class="_ui-button" hover-class="_ui-button-hover">删除文件</button>
|
||||
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
|
||||
<include src="templates.xhsml" />
|
||||
171
xhs-mini-demos/api-case/download-file/templates.js
Normal file
171
xhs-mini-demos/api-case/download-file/templates.js
Normal file
@@ -0,0 +1,171 @@
|
||||
/** 以下内容为自动生成,请勿手动修改 */
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
page_data_0: "",
|
||||
|
||||
page_data_1: "",
|
||||
|
||||
page_data_2: "",
|
||||
|
||||
page_data_3: "",
|
||||
|
||||
page_data_4: false,
|
||||
|
||||
page_data_5: false,
|
||||
|
||||
page_data_6: false,
|
||||
|
||||
page_data_7: "",
|
||||
|
||||
page_data_8: "",
|
||||
|
||||
page_data_9: "",
|
||||
|
||||
page_data_10: false,
|
||||
|
||||
page_data_11: false,
|
||||
|
||||
page_data_12: false,
|
||||
|
||||
page_data_13: "",
|
||||
|
||||
page_data_14: "",
|
||||
|
||||
page_data_15: false,
|
||||
|
||||
page_data_16: false,
|
||||
|
||||
page_data_17: false,
|
||||
|
||||
page_data_18: "",
|
||||
},
|
||||
|
||||
page_fun_1(e) {
|
||||
this.setData("page_data_0", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_2(e) {
|
||||
this.setData("page_data_1", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_3(e) {
|
||||
this.setData("page_data_2", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_4(e) {
|
||||
this.setData("page_data_3", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_0() {
|
||||
this.setData({
|
||||
page_data_4: false,
|
||||
page_data_5: false,
|
||||
page_data_6: false,
|
||||
});
|
||||
|
||||
xhs.downloadFile({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_4: true,
|
||||
page_data_7: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_5: true,
|
||||
page_data_7: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_6: true,
|
||||
});
|
||||
},
|
||||
url: this.data.page_data_0,
|
||||
header: this.data.page_data_1,
|
||||
timeout: this.data.page_data_2,
|
||||
filePath: this.data.page_data_3,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_6(e) {
|
||||
this.setData("page_data_8", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_7(e) {
|
||||
this.setData("page_data_9", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_5() {
|
||||
this.setData({
|
||||
page_data_10: false,
|
||||
page_data_11: false,
|
||||
page_data_12: false,
|
||||
});
|
||||
|
||||
xhs.openDocument({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_10: true,
|
||||
page_data_13: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_11: true,
|
||||
page_data_13: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_12: true,
|
||||
});
|
||||
},
|
||||
filePath: this.data.page_data_8,
|
||||
fileType: this.data.page_data_9,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_9(e) {
|
||||
this.setData("page_data_14", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_8() {
|
||||
this.setData({
|
||||
page_data_15: false,
|
||||
page_data_16: false,
|
||||
page_data_17: false,
|
||||
});
|
||||
|
||||
xhs.removeSavedFile({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_15: true,
|
||||
page_data_18: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_16: true,
|
||||
page_data_18: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_17: true,
|
||||
});
|
||||
},
|
||||
filePath: this.data.page_data_14,
|
||||
});
|
||||
},
|
||||
};
|
||||
94
xhs-mini-demos/api-case/download-file/templates.xhsml
Normal file
94
xhs-mini-demos/api-case/download-file/templates.xhsml
Normal file
@@ -0,0 +1,94 @@
|
||||
<!-- 以下内容为自动生成,请勿手动修改 -->
|
||||
|
||||
<view class="container">
|
||||
<showbox title="downloadFile演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_4}}"
|
||||
complete="{{page_data_6}}"
|
||||
fail="{{page_data_5}}"
|
||||
text="{{page_data_7}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="url" type="text" bindinput="page_fun_1" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="header" type="text" bindinput="page_fun_2" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="timeout" type="text" bindinput="page_fun_3" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="filePath" type="text" bindinput="page_fun_4" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_0"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="openDocument演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_10}}"
|
||||
complete="{{page_data_12}}"
|
||||
fail="{{page_data_11}}"
|
||||
text="{{page_data_13}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="filePath" type="text" bindinput="page_fun_6" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="fileType" type="text" bindinput="page_fun_7" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_5"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="removeSavedFile演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_15}}"
|
||||
complete="{{page_data_17}}"
|
||||
fail="{{page_data_16}}"
|
||||
text="{{page_data_18}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="filePath" type="text" bindinput="page_fun_9" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_8"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
Reference in New Issue
Block a user