123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // subpackages/show/show.js
- import { models, db } from '../../utils/cloudbase.js'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- categoriesindex: 1,
- viewType: 'grid',
- categories: [],
- courseList: [],
- sou: '',
- show_1: '',
- xiazi: '',
- itemlist: {},
- pageNumber: 1,
- pageSize: 10,
- hasMore: true, // 是否还有更多数据
- isLoading: false, // 防止多次触发
- // url: '',
- // pdfurl: '',
- // ppturl: '',
- // audioUrl: '',
- // carousel: ''
- },
- 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/123123.mp4',
- // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/硬盘发票.pdf',
- // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/newfile.ppt',
- // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/许嵩 - 有何不可.mp3',
- // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/banner/carousel_1.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],
- // url: tempFilePaths[3],
- // pdfurl: tempFilePaths[4],
- // ppturl: tempFilePaths[5],
- // audioUrl: tempFilePaths[6],
- // carousel: tempFilePaths[7]
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- // tab数据
- async getTabdata() {
- const { data } = await models.tab.list({
- filter: {
- where: {
- position: 3, // 显示位置
- // layout_type: 0, // 布局类型
- },
- },
- // envType: pre 体验环境, prod 正式环境
- envType: "prod",
- });
-
- // 返回查询到的数据
- const sortedRecords = data.records.sort((a, b) => {
- return a.sort - b.sort; // 升序排列
- });
- this.setData({
- categories: sortedRecords
- }, () => {
- const type = Number(this.options.type) || 1;
- this.data.categories.forEach((item, index) => {
- if (item.sort === type) {
- this.setData({
- categorieslist: item,
- categoriesindex: type
- });
- if (this.data.categorieslist.layout_type === 0) {
- this.setData({ viewType: 'list' });
- } else {
- this.setData({ viewType: 'grid' });
- }
- // 获取列表数据
- this.getdatalist()
- }
- });
- })
- },
- onReachBottom() {
- // 上拉触底事件的处理函数
- this.loadMore();
- },
- loadMore() {
- // 加载更多数据的逻辑
- console.log('加载更多');
- this.getdatalist(true);
- },
- // 列表数据
- async getdatalist(isLoadMore = false) {
- if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
- const { pageNumber, pageSize } = this.data;
- const { data } = await models.file_manage.list({
- filter: {
- where: {
- tag_id: this.data.categorieslist._id,
- }
- },
- pageSize,
- pageNumber,
- getCount: true,
- envType: "prod",
- });
-
- const collectList = data.records || [];
- this.setData({
- courseList: isLoadMore ? this.data.courseList.concat(collectList) : collectList,
- pageNumber: pageNumber + 1,
- hasMore: collectList.length === pageSize,
- isLoading: false
- });
- },
- tabcategories(e) {
- const sort = Number(e.currentTarget.dataset.type); // 直接转换为数字
- const currentCategory = this.data.categories.find(item => item.sort === sort);
-
- if (!currentCategory) return;
-
- const viewType = currentCategory.layout_type === 0 ? 'list' : 'grid';
-
- this.setData({
- categoriesindex: sort,
- categorieslist: currentCategory,
- viewType,
- courseList: [], // 重置课程列表
- pageNumber: 1, // 重置分页
- hasMore: true,
- isLoading: false
- }, () => {
- this.getdatalist(); // 重新加载数据
- });
- },
- goToGoodsList(event) {
- // 获取绑定的数据
- const item = event.currentTarget.dataset.item;
- // 将数据转换为 JSON 字符串并传递
- const itemStr = encodeURIComponent(JSON.stringify(item));
- wx.navigateTo({
- url: `/subpackagestow/details/details?item=${itemStr}`
- });
- },
- // previewPDF() {
- // wx.openDocument({
- // filePath: this.data.ppturl,
- // fileType: 'ppt',
- // success(res) {
- // console.log('打开 PDF 成功');
- // },
- // fail(err) {
- // console.error('打开 PDF 失败', err);
- // }
- // });
- // }
- })
|