miniprogram-downloader
Version:
minprogram download package
32 lines • 1.19 kB
JavaScript
import { LifeCycle } from 'miniprogram-network-life-cycle';
import { transfomDownloadSendDefault } from './transform';
/**
* 下载封装
* @template T 扩展参数类型
*/
export class Downloader extends LifeCycle {
/**
* 新建 Http实列
* @param config 全局默认配置
* @param downloader 下载处理方法,默认使用下载队列处理
* @param listeners 下载事件监听回调
*/
constructor(config, downloader, listeners) {
super(
// tslint:disable-next-line: no-use-before-declare
downloader || wx.downloadFile,
// tslint:disable-next-line: no-object-literal-type-assertion
config || { transformSend: transfomDownloadSendDefault }, listeners);
}
download() {
const isMultiParam = typeof arguments[0] === 'string';
// tslint:disable-next-line: no-unsafe-any
const options = isMultiParam ? (arguments[2] || {}) : arguments[0];
if (isMultiParam) {
options.url = arguments[0];
options.filePath = arguments[1];
}
return this.process(options);
}
}
//# sourceMappingURL=downloader.js.map