// subpackages/course/course.js import { models, db } from '../../utils/cloudbase.js' Page({ /** * 页面的初始数据 */ data: { categoriesindex: 1, categories: [], viewType: 'grid', courseList: [ // { id: 1, title: '趣味识字 – 动物世界', type: 'PDF', grade: '小班', subject: '语文', views: 128 }, // { id: 2, title: '数字王国探险记', type: '视频', grade: '中班', subject: '数学', views: 128 }, // { id: 3, title: '儿歌大全 – 春天在哪里', type: '音频', grade: '大班', subject: '音乐', views: 128 }, // { id: 4, title: '创意绘画 – 我的小房子', type: 'PPT', grade: '中班', subject: '美术', views: 128 } ], sou: '', show_1: '', xiazi: '', goods_9: '', categorieslist: {} }, onLoad(options) { // 存储 options 到 this 中 this.options = options; // 获取tab数据 this.getTabdata(); // 获取图片 const fileIDs = [ 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png', 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show_1.png', 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xiazi.png', 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/goods/goods_9.jpg' ]; // 并发下载多个 fileID Promise.all( fileIDs.map(fileID => wx.cloud.downloadFile({ fileID })) ).then(results => { // 每个 result 对应一个下载结果 const tempFilePaths = results.map(r => r.tempFilePath); console.log('全部下载成功:', tempFilePaths); this.setData({ sou: tempFilePaths[0], show_1: tempFilePaths[1], xiazi: tempFilePaths[2], goods_9: tempFilePaths[3], }); }).catch(err => { console.error('有文件下载失败:', err); }); }, // tab数据 async async getTabdata() { const { data } = await models.tab.list({ filter: { where: { position: 0, // 显示位置 // layout_type: 0, // 布局类型 }, }, // envType: pre 体验环境, prod 正式环境 envType: "prod", }); // 返回查询到的数据 // console.log(data); const sortedRecords = data.records.sort((a, b) => { return a.sort - b.sort; // 升序排列 }); this.setData({ categories: sortedRecords }, () => { // 在 setData 回调中执行逻辑,确保 categories 已经更新 const type = Number(this.options.type) || 1; this.data.categories.forEach((item, index) => { if (item.sort === type) { this.setData({ categorieslist: item, categoriesindex: type }); // 获取列表数据 this.getdatalist() } }); }) }, // 列表数据 async getdatalist() { console.log(this.data.categorieslist, '123123'); const { data } = await models.file_manage.list({ filter: { where: { tag_id: this.data.categorieslist._id, } }, pageSize: 10, // 分页大小,建议指定,如需设置为其它值,需要和 pageNumber 配合使用,两者同时指定才会生效 pageNumber: 1, // 第几页 getCount: true, // 开启用来获取总数 // envType: pre 体验环境, prod 正式环境 envType: "prod", }); // 返回查询到的数据列表 records 和 总数 total console.log(data, '123123'); this.setData({ courseList: data.records }) }, // async tabcategories(e) { const types = e.currentTarget.dataset.type; // if (type === 2) { // this.setData({ viewType: 'list' }); // } else { // this.setData({ viewType: 'grid' }); // } this.setData({ categoriesindex: types }, () => { // 在 setData 回调中执行逻辑,确保 categories 已经更新 const type = Number(types) || 1; this.data.categories.forEach((item, index) => { if (item.sort === type) { this.setData({ categorieslist: item, categoriesindex: type }); // 获取列表数据 this.getdatalist() } }); }); // const { data } = await models.file_manage.create({ // data: { // level: 1, // 级别 // range: ['中班'], // 适用范围 // remark: "备注文本字段", // 备注 // type: 3, // 文件类型 0-视频 1-音频 2-pdf 3-ppt 4-图文 // url: ['cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/newfile.ppt'], // 路径 // download_count: 1, // 下载人数 // dan: 0, // 段位 // cover: "cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/未命名的设计.png", // 封面 // size: "123.12KB", // 文件大小 // name: "PPT-文件名33", // 文件名 // tag_id: "BT6QJSE5RS", // 标签id // describe: "描述文本字段", // 描述 // }, // // envType: pre 体验环境, prod 正式环境 // envType: "prod", // }); // // 返回创建的数据 id // console.log(data, '234234'); }, goToGoodsList(event) { // 获取绑定的数据 const item = event.currentTarget.dataset.item; // 将数据转换为 JSON 字符串并传递 const itemStr = encodeURIComponent(JSON.stringify(item)); wx.navigateTo({ url: `/subpackagestow/details/details?item=${itemStr}` }); } })