184 lines
3.2 KiB
JavaScript
184 lines
3.2 KiB
JavaScript
// pages/works/works.js
|
|
var urlPath = require('../../../config.js');
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
workTitleArr: ['保存的作品', '分享的作品'],
|
|
workIndex: 0,
|
|
imgArr: [],
|
|
page: 1,
|
|
size: 200,
|
|
times:0
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
this.checkImg();
|
|
},
|
|
// chooseTitle(e){
|
|
// let newIndex = e.currentTarget.dataset.index;
|
|
// this.setData({
|
|
// workIndex:newIndex
|
|
// })
|
|
// console.log(this.data.workIndex);
|
|
|
|
// },
|
|
checkImg() {
|
|
wx.request({
|
|
url: urlPath.myBottleReleaseList,
|
|
data: {
|
|
page: this.data.page,
|
|
size: this.data.size
|
|
},
|
|
header: {
|
|
'token': wx.getStorageSync('token')
|
|
},
|
|
method: 'post',
|
|
success: (res) => {
|
|
if (res.data.code == 0) {
|
|
let newArr = [];
|
|
if (res.data.data.list.length) {
|
|
res.data.data.list.forEach(item => {
|
|
let obj = {
|
|
name: item.name,
|
|
id: item.id,
|
|
imgSrc: urlPath.host + item.release_img,
|
|
img_thumb: urlPath.host + item.img_thumb,
|
|
userId: item.user_id,
|
|
time: item.create_time,
|
|
isShare: item.production_id //0未分享
|
|
}
|
|
newArr.push(obj);
|
|
})
|
|
}
|
|
this.setData({
|
|
imgArr: newArr
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title:'暂无作品数据',
|
|
icon:'none'
|
|
})
|
|
}
|
|
}
|
|
});
|
|
},
|
|
shareEv(e) {
|
|
if(this.data.times==0){
|
|
wx.showToast({
|
|
title:'正在调起分享',
|
|
duration:5000
|
|
})
|
|
this.setData({
|
|
times:this.data.times++
|
|
})
|
|
wx.downloadFile({
|
|
url: this.data.imgArr[e.currentTarget.dataset.index].imgSrc,
|
|
success: (res) => {
|
|
wx.showShareImageMenu({
|
|
path: res.tempFilePath,
|
|
success:(res)=>{
|
|
this.setData({
|
|
times:0
|
|
})
|
|
},
|
|
fail:(err)=>{
|
|
console.log(err);
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
},
|
|
// 立即参与活动
|
|
partEv(e){
|
|
wx.request({
|
|
url: urlPath.publishMyBottle,
|
|
data: {
|
|
id: e.currentTarget.dataset.id
|
|
},
|
|
header: {
|
|
'token': wx.getStorageSync('token')
|
|
},
|
|
method: 'post',
|
|
success: (res) => {
|
|
if (res.data.code == 0) {
|
|
this.data.imgArr[e.currentTarget.dataset.index].isShare=1;
|
|
this.setData({
|
|
imgArr:this.data.imgArr
|
|
})
|
|
wx.showToast({
|
|
title: '参加活动成功'
|
|
})
|
|
}
|
|
}
|
|
});
|
|
},
|
|
// 预览图片
|
|
preImg(e){
|
|
let newIndex = e.currentTarget.dataset.index;
|
|
let newImg = [];
|
|
this.data.imgArr.forEach(item=>{
|
|
newImg.push(item.imgSrc);
|
|
})
|
|
wx.previewImage({
|
|
current:this.data.imgArr[newIndex].imgSrc,
|
|
urls:newImg,
|
|
success: () => {}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
|
|
}
|
|
})
|