request-downFiles.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * 2019年4月7日15:33:06
  3. */
  4. import {
  5. RQ
  6. } from './request.js';
  7. class DonwFiles extends RQ {
  8. constructor(...arg) {
  9. super(arg);
  10. }
  11. /**
  12. * 下载文件
  13. */
  14. startDownFiles({
  15. path = '',
  16. title = false,
  17. abort = (bt, finsh) => {},
  18. ...extra
  19. } = {}) {
  20. return new Promise(async (resolve, reject) => {
  21. let obj = {
  22. tempFileInfo: [],
  23. FilePath: []
  24. };
  25. if (title) {
  26. uni.showLoading({
  27. title,
  28. mask: true,
  29. });
  30. }
  31. if(path.constructor===String){
  32. path = path.toString().split(',');
  33. }
  34. for (let i = 0; i < path.length; i++) {
  35. let url = path[i];
  36. try {
  37. let res = await this.downFiles({
  38. path: url,
  39. index:i,
  40. abort,
  41. ...extra
  42. })
  43. obj.FilePath.push(res.tempFilePath)
  44. obj.tempFileInfo.push({
  45. url,
  46. filePath: res.tempFilePath
  47. });
  48. } catch (e) {
  49. //TODO handle the exception
  50. }
  51. }
  52. resolve(obj);
  53. if (title) {
  54. uni.hideLoading();
  55. }
  56. })
  57. }
  58. }
  59. export const DF = DonwFiles;
  60. export const df = new DonwFiles();