// pages/tz/tz.js
//图片数量限制
const db = wx.cloud.database()
Page({
/**
* 页面的初始数据
*/
data: {
tpdz: [
{
url:'https://m.qpic.cn/psc?/V13KuwQF2X9Q0L/8pLzIOZGGDcBctBkTesZqtJ2AVs.JQqXC8xDcZgef8WAgu2gdwEBnZJfAsPab3cLhNLiyNamtYu7rnrjQTzmmHZD4xKZv4KoFciXEG2e50k!/b&bo=6wDnAOsA5wACCS0!&rf=viewer_4',
},
{
},
{
url: 'https://ae01.alicdn.com/kf/H5a0f8fdf45464d3e9c5c6a5c2eb0720et.jpg',
},
{
},
{
url: 'https://m.qpic.cn/psc?/V13KuwQF2X9Q0L/8pLzIOZGGDcBctBkTesZqtEsr0EViviwGee1CbxGR.xHqw.Qo2g7VVuAvFX3lQdgASOy3A5RJuf8v9LtAs8rUhyrYHR7dUJVDbQsJV5Gn7Y!/b&bo=2gJQAdoCUAEDCSw!&rf=viewer_4',
},
{
url: 'http://p1.music.126.net/Yo-FjrJTQ9clkDkuUCTtUg==/109951164169441928.jpg',
}
]
},
//获取预览图片地址
yl(e){
console.log(e)
var img = e.currentTarget.dataset.img
console.log(img)
wx.previewImage({
current: img, // 当前显示图片的http链接
urls: [img] // 需要预览的图片http链接列表
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
// 上传图片
doUpload: function () {
// 选择图片
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
wx.showLoading({
title: '上传中'
})
const filePath = res.tempFilePaths[0]
// 上传图片
const cloudPath = 'peitu/' + Date.now() + '-' + Math.random() * 1000000 + filePath.match(/\.[^.]+?$/)[0]
wx.cloud.uploadFile({
cloudPath,
filePath,
success: res => {
//console.log('[上传文件] 成功:', res)
console.log(res.fileID)
wx.showToast({
title: '上传成功',
icon: 'success',
duration: 1500
})
const fileid = res.fileID
app.globalData.fileID = res.fileID
app.globalData.cloudPath = cloudPath
app.globalData.imagePath = filePath
},
fail: e => {
console.error('[上传文件] 失败:', e)
wx.showToast({
icon: 'none',
title: '上传失败',
})
},
complete: () => {
wx.hideLoading()
}
})
complete: () => {
wx.hideLoading()
}
},
fail: e => {
console.error(e)
}
})
},
onAdd: function () {
db.collection('tupian').add({
data: {
count: 1
},
success: res => {
this.setData({
counterID: res.id
})
},
fail: err => {
wx.showToast({
title: '新增记录失败'
})
console.error('[数据库][新增记录]失败:', err)
}
})
},
onShareAppMessage: function () {
}
})