details.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // subpackagestow/details/details.js
  2. import { models, db, _ } from '../../utils/cloudbase.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. fileType: 'video',
  9. viewType: 'grid',
  10. courseList: [],
  11. shouchang: '',
  12. show_1: '',
  13. xiazi: '',
  14. xia: '',
  15. itemlist: {}
  16. },
  17. onLoad(options) {
  18. // 获取传递过来的数据
  19. const itemStr = decodeURIComponent(options.item);
  20. const item = JSON.parse(itemStr);
  21. // 设置到页面数据中
  22. this.setData({
  23. itemlist: item
  24. }, () => {
  25. // 相关推荐
  26. this.getcourseList()
  27. });
  28. // 获取图片
  29. const fileIDs = [
  30. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/shouchang.png',
  31. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show_1.png',
  32. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xiazi.png',
  33. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xia_1.png'
  34. ];
  35. // 并发下载多个 fileID
  36. Promise.all(
  37. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  38. ).then(results => {
  39. // 每个 result 对应一个下载结果
  40. const tempFilePaths = results.map(r => r.tempFilePath);
  41. console.log('全部下载成功:', tempFilePaths);
  42. this.setData({
  43. shouchang: tempFilePaths[0],
  44. show_1: tempFilePaths[1],
  45. xiazi: tempFilePaths[2],
  46. xia: tempFilePaths[3],
  47. });
  48. }).catch(err => {
  49. console.error('有文件下载失败:', err);
  50. });
  51. },
  52. // 相关课件推荐
  53. async getcourseList() {
  54. console.log(this.data.itemlist.range, 'this.data.itemlist.range');
  55. const { data } = await models.file_manage.list({
  56. filter: {
  57. where: {
  58. range: db.command.in(['小班', '中班']),
  59. tag_id: this.data.itemlist.tag_id
  60. }
  61. },
  62. // envType: pre 体验环境, prod 正式环境
  63. envType: "prod",
  64. });
  65. // 返回查询到的数据列表 records 和 总数 total
  66. console.log(data);
  67. this.setData({
  68. courseList: data.records
  69. })
  70. },
  71. goToGoodsLists(event) {
  72. // 获取绑定的数据
  73. const item = event.currentTarget.dataset.item;
  74. // 将数据转换为 JSON 字符串并传递
  75. const itemStr = encodeURIComponent(JSON.stringify(item));
  76. wx.navigateTo({
  77. url: `/subpackagestow/down/down?item=${itemStr}`
  78. });
  79. },
  80. goToGoodsList(event) {
  81. // 获取绑定的数据
  82. const item = event.currentTarget.dataset.item;
  83. // 将数据转换为 JSON 字符串并传递
  84. const itemStr = encodeURIComponent(JSON.stringify(item));
  85. wx.navigateTo({
  86. url: `/subpackagestow/details/details?item=${itemStr}`
  87. });
  88. }
  89. })