1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // subpackages/teaching/teaching.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: '',
- },
- onLoad(options) {
- // 获取tab数据
- this.getTabdata();
- const type = Number(options.type) || 1;
- console.log('收到的 type 参数:', type);
- if (type === 2 || type === 3) {
- this.setData({ viewType: 'list' });
- } else {
- this.setData({ viewType: 'grid' });
- }
- // 根据 type 加载数据
- this.setData({
- categoriesindex: type
- });
- 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',
- ];
-
- // 并发下载多个 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],
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- // tab数据
- async getTabdata() {
- const { data } = await models.tab.list({
- filter: {
- where: {
- position: 2, // 显示位置
- // 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
- })
- },
- tabcategories(e) {
- const type = e.currentTarget.dataset.type;
- if (type === 2 || type === 3) {
- this.setData({ viewType: 'list' });
- } else {
- this.setData({ viewType: 'grid' });
- }
-
- this.setData({
- categoriesindex: type
- });
- }
- })
|