(url, options = {})
| 367 | } |
| 368 | |
| 369 | download(url, options = {}) { |
| 370 | return new Promise((resolve, reject) => { |
| 371 | let next = true |
| 372 | const pubConfig = { |
| 373 | baseUrl: this.config.baseUrl, |
| 374 | url, |
| 375 | method: 'DOWNLOAD', |
| 376 | header: {...this.config.header, ...(options.header || {})}, |
| 377 | params: options.params || {}, |
| 378 | custom: {...this.config.custom, ...(options.custom || {})}, |
| 379 | getTask: options.getTask || this.config.getTask |
| 380 | } |
| 381 | const cancel = (t = 'handle cancel', config = pubConfig) => { |
| 382 | const err = { |
| 383 | errMsg: t, |
| 384 | config: config |
| 385 | } |
| 386 | reject(err) |
| 387 | next = false |
| 388 | } |
| 389 | |
| 390 | const handleRe = {...this.requestBeforeFun(pubConfig, cancel)} |
| 391 | if (!next) return |
| 392 | const requestTask = uni.downloadFile({ |
| 393 | url: buildURL(buildFullPath(handleRe.baseUrl, handleRe.url), handleRe.params), |
| 394 | header: handleRe.header, |
| 395 | complete: (response) => { |
| 396 | response.config = handleRe |
| 397 | if (this.validateStatus(response.statusCode)) { // 成功 |
| 398 | response = this.requestComFun(response) |
| 399 | resolve(response) |
| 400 | } else { |
| 401 | response = this.requestComFail(response) |
| 402 | reject(response) |
| 403 | } |
| 404 | } |
| 405 | }) |
| 406 | if (handleRe.getTask) { |
| 407 | handleRe.getTask(requestTask, handleRe) |
| 408 | } |
| 409 | }) |
| 410 | } |
| 411 | } |
| 412 | |
| 413 |
nothing calls this directly
no test coverage detected