show.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // subpackages/show/show.js
  2. import { models, db } from '../../utils/cloudbase.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. categoriesindex: 1,
  9. categories: [],
  10. courses: [
  11. {
  12. videoUrl: 'image/123123.mp4',
  13. title: '活动名称',
  14. description: '课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍'
  15. },
  16. {
  17. videoUrl: '"image/123123.mp4"',
  18. title: '活动名称',
  19. description: '课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍'
  20. },
  21. {
  22. videoUrl: '"image/123123.mp4"',
  23. title: '活动名称',
  24. description: '课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍'
  25. }
  26. ],
  27. sou: '',
  28. show_1: '',
  29. xiazi: '',
  30. url: '',
  31. pdfurl: '',
  32. ppturl: '',
  33. audioUrl: '',
  34. carousel: ''
  35. },
  36. onLoad(options) {
  37. // 获取tab数据
  38. this.getTabdata();
  39. const type = Number(options.type) || 1;
  40. console.log('收到的 type 参数:', type);
  41. // 根据 type 加载数据
  42. this.setData({
  43. categoriesindex: type
  44. });
  45. const fileIDs = [
  46. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
  47. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show_1.png',
  48. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xiazi.png',
  49. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/123123.mp4',
  50. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/硬盘发票.pdf',
  51. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/newfile.ppt',
  52. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/许嵩 - 有何不可.mp3',
  53. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/banner/carousel_1.jpg'
  54. ];
  55. // 并发下载多个 fileID
  56. Promise.all(
  57. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  58. ).then(results => {
  59. // 每个 result 对应一个下载结果
  60. const tempFilePaths = results.map(r => r.tempFilePath);
  61. console.log('全部下载成功:', tempFilePaths);
  62. this.setData({
  63. sou: tempFilePaths[0],
  64. show_1: tempFilePaths[1],
  65. xiazi: tempFilePaths[2],
  66. url: tempFilePaths[3],
  67. pdfurl: tempFilePaths[4],
  68. ppturl: tempFilePaths[5],
  69. audioUrl: tempFilePaths[6],
  70. carousel: tempFilePaths[7]
  71. });
  72. }).catch(err => {
  73. console.error('有文件下载失败:', err);
  74. });
  75. },
  76. // tab数据
  77. async getTabdata() {
  78. const { data } = await models.tab.list({
  79. filter: {
  80. where: {
  81. position: 3, // 显示位置
  82. // layout_type: 0, // 布局类型
  83. },
  84. },
  85. // envType: pre 体验环境, prod 正式环境
  86. envType: "prod",
  87. });
  88. // 返回查询到的数据
  89. console.log(data);
  90. const sortedRecords = data.records.sort((a, b) => {
  91. return a.sort - b.sort; // 升序排列
  92. });
  93. this.setData({
  94. categories: sortedRecords
  95. })
  96. },
  97. tabcategories(e) {
  98. const type = e.currentTarget.dataset.type;
  99. this.setData({
  100. categoriesindex: type
  101. });
  102. },
  103. previewPDF() {
  104. wx.openDocument({
  105. filePath: this.data.ppturl,
  106. fileType: 'ppt',
  107. success(res) {
  108. console.log('打开 PDF 成功');
  109. },
  110. fail(err) {
  111. console.error('打开 PDF 失败', err);
  112. }
  113. });
  114. }
  115. })