123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import { models, db } from '../../utils/cloudbase.js'
- Page({
- data: {
- categoriesindex: 1,
- categories: [],
- goods: [
- {
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '儿童大颗粒积木 安全无毒 益智玩具',
- price: '68.00',
- originalPrice: '88.00',
- sold: 256
- },
- {
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '幼儿启蒙绘本 10册套装',
- price: '68.00',
- originalPrice: '88.00',
- sold: 256
- },
- {
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '防摔儿童保温水杯 350ml',
- price: '68.00',
- originalPrice: '88.00',
- sold: 256
- },
- {
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '可水洗儿童彩笔24色套装',
- price: '68.00',
- originalPrice: '88.00',
- sold: 256
- }
- ],
- souimg: '',
- gouwucimg: '',
- },
- onLoad(options) {
- // 获取tab数据
- this.getTabdata();
- // const title = options.title ? decodeURIComponent(options.title) : '商品列表';
- // this.setData({ title });
- // wx.setNavigationBarTitle({ title });
- const fileIDs = [
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/gouwuc_img.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({
- souimg: tempFilePaths[0],
- gouwucimg: tempFilePaths[1]
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
-
- // tab数据
- async getTabdata() {
- const { data } = await models.tab.list({
- filter: {
- where: {
- position: 4, // 显示位置
- // 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;
- this.setData({
- categoriesindex: type
- });
- },
- navigateToDetail(e) {
- const index = e.currentTarget.dataset.index;
- const item = this.data.goods[index];
- wx.navigateTo({
- url: '/subpackages/productdetails/productdetails?data=' + encodeURIComponent(JSON.stringify(item))
- });
- console.log('走进来了');
- }
- });
|