<tabs currentTab="{{currentTab}}" tabList="{{statusType}}" bind:changeTab="switchTab">
<swiper current="{{currentTab}}" duration="300" bindchange="bindChange" style="height:{{windowHeight-35}}px;">
<swiper-item wx:for="{{list}}" wx:key="*this">
<view>{{item}}</view>
<button wx:if="{{index==0}}" bindtap="uploadFile">Upload</button>
<button wx:if="{{index==0}}" bindtap="downloadFile">Download</button>
<button wx:if="{{index==0}}" bindtap="delFile">Delete</button>
<image src="{{tempFile}}"></image>
</swiper-item>
</swiper>
</tabs>
// pages/componentPage/componentPage.js
var self;
Page({
/**
* 页面的初始数据
*/
data: {
statusType: [
{
name: "待付款",
page: 0
},
{
name: "待发货",
page: 1
},
{
name: "待收货",
page: 2
},
{
name: "待评价",
page: 3
},
{
name: "已完成",
page: 4
}
],
currentTab: 0,
list: ["page1", "Page2", "Page3", "Page4", "Page5"],
windowHeight: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
self = this;
this.setData({
windowHeight: wx.getSystemInfoSync().windowHeight
});
this.cloudRequire();
},
switchTab: function(event){
console.log("page",event.detail.currentNum);
if (this.data.currentTab === event.detail.currentNum) {
return;
}
this.setData({
currentTab: event.detail.currentNum
});
},
bindChange: function(event){
this.setData({
currentTab: event.detail.current
});
},
cloudRequire(){
if(!wx.cloud){
console.error('请使用2.2.3以上的基础库来使用云函数');
} else{
wx.cloud.init({
traceUser:true
});
}
wx.cloud.callFunction({
name: 'return',
data:{
a:2,
b:6
},
complete: res => {
//console.log('callFunction return result: ',res);
}
});
const db = wx.cloud.database();
const todos = db.collection('todos');
const todo = todos.doc('6aebd2215e7f000c001ac5ab2b839d05');
console.log("todo--- ",todo);
// 添加数据
// todos.add({
// // data字段表示需要新增的JSON数据
// data: {
// description: 'learn cloud database',
// due: new Date('2020-03-28'),
// tags: ['Cloud', 'Database'],
// location: new db.Geo.Point(113,23),
// done: false
// },
// success: function(res){
// console.log(res);
// }
// });
// 查询数据
// todo.get({
// complete(res){
// console.log('查询数据',res);
// }
// });
todos.where({
"done": false
}).get({
complete(res){
console.log('查询数据', res);
}
});
// update数据 (只会更新指定field)
// todo.update({
// data: {
// description: '我修改的数据描述'
// },
// success: (res) => {
// }
// });
// set会整个覆盖掉,如果todo不存在,将新建一条数据
todo.set({
// data字段表示需要set的JSON数据
data: {
description: 'learn cloud database 12',
due: new Date('2020-03-28'),
tags: ['Cloud', 'Database'],
location: new db.Geo.Point(113,23),
done: false
},
success: function(res){
console.log(res);
}
});
// 删除数据remove
todo.remove({
success: function(res){
console.log(res);
}
});
todos.where({
"done": true
}).remove();
},
downloadFile: function (e) {
wx.cloud.downloadFile({
fileID: 'cloud://d666.6436-d666-1301631881/aa.jpg',
success(res){
console.log(res);
self.setData({
tempFile: res.tempFilePath
});
},
fail(res){
console.log(res);
}
});
},
delFile: function (e) {
wx.cloud.deleteFile({
fileList: ['cloud://d666.6436-d666-1301631881/aa.jpg'],
success(res) {
console.log(res);
},
fail(res) {
console.log(res);
}
});
},
uploadFile: function(e){
wx.chooseImage({
success: function(res) {
console.log(res);
wx.cloud.uploadFile({
cloudPath: 'aa.jpg',
filePath: res.tempFilePaths[0],
success(r){
console.log('uploadFile',r);
},
fail(err){
console.log('uploadFile fail', err);
}
})
},
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})