down.js 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // subpackagestow/down/down.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. fuzhi: '',
  8. itemlist: {},
  9. },
  10. onLoad(options) {
  11. // 获取传递过来的数据
  12. const itemStr = decodeURIComponent(options.item);
  13. const item = JSON.parse(itemStr);
  14. // 设置到页面数据中
  15. this.setData({
  16. itemlist: item
  17. });
  18. const fileIDs = [
  19. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/fuzhi.png',
  20. ];
  21. // 并发下载多个 fileID
  22. Promise.all(
  23. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  24. ).then(results => {
  25. // 每个 result 对应一个下载结果
  26. const tempFilePaths = results.map(r => r.tempFilePath);
  27. console.log('全部下载成功:', tempFilePaths);
  28. this.setData({
  29. fuzhi: tempFilePaths[0],
  30. });
  31. }).catch(err => {
  32. console.error('有文件下载失败:', err);
  33. });
  34. },
  35. })