|
|
@@ -232,37 +232,38 @@ export default new (class {
|
|
|
*/
|
|
|
createDownload(url: string) {
|
|
|
this.onPlusReady((plus) => {
|
|
|
- plus.downloader.enumerate((downloads: any) => {
|
|
|
- if (downloads.length) {
|
|
|
- plus.nativeUI.toast('正在下载')
|
|
|
- } else {
|
|
|
- const task = plus.downloader.createDownload(url, {
|
|
|
- filename: '_downloads/', // 非系统 Download 目录
|
|
|
- retry: 1,
|
|
|
- }, (d: any, status: number) => {
|
|
|
- if (status !== 200) {
|
|
|
- plus.nativeUI.toast('下载失败')
|
|
|
- }
|
|
|
- })
|
|
|
- // 监听下载状态
|
|
|
- task.addEventListener('statechanged', (task: any) => {
|
|
|
- switch (task.state) {
|
|
|
- case 3:
|
|
|
- const progress = task.downloadedSize / task.totalSize * 100
|
|
|
- for (const fn of this.downloadTask.values()) {
|
|
|
- fn(task.filename, progress) // 推送下载进度
|
|
|
- }
|
|
|
- break
|
|
|
- case 4:
|
|
|
- console.log('下载完成', task.filename)
|
|
|
- this.downloadTask.clear()
|
|
|
- break
|
|
|
+ // plus.downloader.enumerate((downloads: any) => {
|
|
|
+ // if (downloads.length) {
|
|
|
+ // plus.nativeUI.toast('正在下载')
|
|
|
+ // } else {
|
|
|
+
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ const task = plus.downloader.createDownload(url, {
|
|
|
+ filename: '_downloads/', // 非系统 Download 目录
|
|
|
+ retry: 1,
|
|
|
+ }, (d: any, status: number) => {
|
|
|
+ if (status !== 200) {
|
|
|
+ plus.nativeUI.toast('下载失败')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 监听下载状态
|
|
|
+ task.addEventListener('statechanged', (task: any) => {
|
|
|
+ switch (task.state) {
|
|
|
+ case 3:
|
|
|
+ const progress = task.downloadedSize / task.totalSize * 100
|
|
|
+ for (const fn of this.downloadTask.values()) {
|
|
|
+ fn(task.filename, progress) // 推送下载进度
|
|
|
}
|
|
|
- })
|
|
|
- // 开始下载
|
|
|
- task.start()
|
|
|
+ break
|
|
|
+ case 4:
|
|
|
+ console.log('下载完成', task.filename)
|
|
|
+ this.downloadTask.clear()
|
|
|
+ break
|
|
|
}
|
|
|
})
|
|
|
+ // 开始下载
|
|
|
+ task.start()
|
|
|
})
|
|
|
}
|
|
|
|