training.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // subpackages/training/training.js
  2. import { models, db } from '../../utils/cloudbase.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. categoriesindex: 1,
  9. categories: [],
  10. viewType: 'list',
  11. courseList: [
  12. { id: 1, title: '趣味识字 – 动物世界', type: 'PDF', grade: '小班', subject: '语文', views: 128 },
  13. { id: 2, title: '数字王国探险记', type: '视频', grade: '中班', subject: '数学', views: 128 },
  14. { id: 3, title: '儿歌大全 – 春天在哪里', type: '音频', grade: '大班', subject: '音乐', views: 128 },
  15. { id: 4, title: '创意绘画 – 我的小房子', type: 'PPT', grade: '中班', subject: '美术', views: 128 }
  16. ],
  17. sou: '',
  18. show_1: '',
  19. xiazi: '',
  20. },
  21. onLoad(options) {
  22. // 获取tab数据
  23. this.getTabdata();
  24. const type = Number(options.type) || 1;
  25. console.log('收到的 type 参数:', type);
  26. if (type === 4) {
  27. this.setData({ viewType: 'list' });
  28. } else {
  29. this.setData({ viewType: 'grid' });
  30. }
  31. // 根据 type 加载数据
  32. this.setData({
  33. categoriesindex: type
  34. });
  35. const fileIDs = [
  36. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
  37. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show_1.png',
  38. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xiazi.png',
  39. ];
  40. // 并发下载多个 fileID
  41. Promise.all(
  42. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  43. ).then(results => {
  44. // 每个 result 对应一个下载结果
  45. const tempFilePaths = results.map(r => r.tempFilePath);
  46. console.log('全部下载成功:', tempFilePaths);
  47. this.setData({
  48. sou: tempFilePaths[0],
  49. show_1: tempFilePaths[1],
  50. xiazi: tempFilePaths[2],
  51. });
  52. }).catch(err => {
  53. console.error('有文件下载失败:', err);
  54. });
  55. },
  56. // tab数据
  57. async getTabdata() {
  58. const { data } = await models.tab.list({
  59. filter: {
  60. where: {
  61. position: 1, // 显示位置
  62. // layout_type: 0, // 布局类型
  63. },
  64. },
  65. // envType: pre 体验环境, prod 正式环境
  66. envType: "prod",
  67. });
  68. // 返回查询到的数据
  69. console.log(data);
  70. const sortedRecords = data.records.sort((a, b) => {
  71. return a.sort - b.sort; // 升序排列
  72. });
  73. this.setData({
  74. categories: sortedRecords
  75. })
  76. },
  77. tabcategories(e) {
  78. const type = e.currentTarget.dataset.type;
  79. if (type === 4) {
  80. this.setData({ viewType: 'list' });
  81. } else {
  82. this.setData({ viewType: 'grid' });
  83. }
  84. this.setData({
  85. categoriesindex: type
  86. });
  87. }
  88. })