You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
5.3 KiB

import {
http
} from '../../../../../utils/util'
import {
cdn
} from '../../../../../utils/config'
Page({
/**
* 页面的初始数据
*/
data: {
cdn: getApp().globalData.cdn,
type: 0,
records: [],
infoObject: {},
isClick: false,
// imageUrl:"/pages/index/shortimage/img_xingtue@2x.png"
},
back() {
wx.navigateBack({
delta: 1
})
},
to(e) {
console.log(e.target.dataset.url)
wx.navigateTo({
url: e.target.dataset.url
})
},
//跳转详情
detail(e) {
console.log(e)
wx.setStorageSync('info', e.currentTarget.dataset.cycle_id)
wx.navigateTo({
url: "/pages/index/subpage/brand/brandDetails/brandDetails"
})
},
//收藏
collection(e) {
var that = this
let userId = this.data.infoObject.id
let referenceId = this.data.infoObject.id
// let referenceId = wx.getStorageSync('referenceId')
let isClick = this.data.isClick
console.log(e)
if (!isClick) {
that.setData({
isClick: true
})
wx.showToast({
title: '收藏成功',
icon: 'none'
})
http("/userReference/add", "post", {
userId,
referenceId
}).then(res => {
this.setData({
// userId:e.currentTarget.dataset.cycle_id,
// referenceId:this.id
})
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: '动态详情',
success: function (res) {}
})
this.setData({
type: options.type,
infoObject: wx.getStorageSync('info')
})
this.getrecordslist()
},
getrecordslist() {
http("/topicActivity/list", "post", {}).then(res => {
this.setData({
records: res.data.records,
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
var that = this
return {
title: that.data.infoObject.title,
path: "pages/index/subpage/brand/brandDetails/brandDetails",
// imageUrl:that.cdn+infoObject.cover,
}
},
//保存
preserve: function (e) {
console.log(this.data.infoObject.content)
wx.getImageInfo({
src: cdn + this.data.infoObject.content, //这里放你要下载图片的数组(多张) 或 字符串(一张) 下面代码不用改动
success: function (ret) {
var path = ret.path
wx.saveImageToPhotosAlbum({
filePath: path,
success(result) {
console.log("成功");
wx.hideLoading();
wx.showToast({
title: '下载图片成功',
duration: 2000,
mask: true,
});
},
fail(result) {
console.log("失败,你取消了" + JSON.stringify(result))
console.log(path);
wx.openSetting({
success: (res) => {
console.log(res);
}
})
}
});
}
});
},
//保存视频
handleDownload(e) {
let link = e.currentTarget.dataset.link;
let fileName = new Date().valueOf();
wx.downloadFile({
url: link,
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: res => {
console.log(res);
let filePath = res.filePath;
wx.saveVideoToPhotosAlbum({
filePath,
success: file => {
wx.showToast({
title: '下载视频成功',
duration: 2000,
mask: true,
});
let fileMgr = wx.getFileSystemManager();
fileMgr.unlink({
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: function (r) {
},
})
},
fail: err => {
console.log(err)
if (err.errMsg === 'saveVideoToPhotosAlbum:fail auth deny') {
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,
success: data => {
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showModal({
title: '提示',
content: '获取权限成功,再次点击下载即可保存',
showCancel: false,
})
} else {
wx.showModal({
title: '提示',
content: '获取权限失败,将无法保存到相册哦~',
showCancel: false,
})
}
},
})
}
})
}
}
})
}
})
},
})