forked from lsl/xzjl-ui
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.
217 lines
6.1 KiB
217 lines
6.1 KiB
// pages/home/xx/hy/index.js
|
|
const app = getApp();//新建页面时 默认引入
|
|
const req = app.xzjlReq();//初始化一个的request() 实例
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
visible:false,
|
|
image: []
|
|
},
|
|
go2Reback(){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/lindex/lindex'
|
|
})
|
|
},
|
|
go2Xz(){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/hy/index'
|
|
})
|
|
},
|
|
go2Yx(){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/hy/yx/yx'
|
|
})
|
|
},
|
|
go2Hx(){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/hy/hx/hx'
|
|
})
|
|
},
|
|
go2Zt(){
|
|
wx.navigateTo({
|
|
url: '/pages/home/xx/hy/zt/zt'
|
|
})
|
|
},
|
|
blockClick(e){
|
|
console.log(e.target.dataset.url);
|
|
this.setData({
|
|
visible: true,
|
|
image: [e.target.dataset.url]
|
|
})
|
|
},
|
|
downloadBtn(){
|
|
wx.downloadFile({
|
|
url: this.data.image[0],
|
|
success: (res) => {
|
|
if (res.statusCode === 200) {
|
|
const tempFilePath = res.tempFilePath;
|
|
console.log('下载图片成功', tempFilePath);
|
|
// 在这里可以使用 tempFilePath 进行后续操作,比如保存到相册
|
|
this.downloadImg(tempFilePath)
|
|
} else {
|
|
console.log('下载图片失败', res);
|
|
}
|
|
},
|
|
fail: function (err) {
|
|
console.log('下载图片失败', err);
|
|
}
|
|
});
|
|
},
|
|
// 保存图片
|
|
downloadImg(src){
|
|
wx.authorize({
|
|
scope: 'scope.writePhotosAlbum',
|
|
success: () => {
|
|
// 用户已经同意授权
|
|
// 在这里调用保存图片的代码
|
|
wx.saveImageToPhotosAlbum({
|
|
filePath: src,
|
|
success: (res) => {
|
|
console.log('保存图片成功', res);
|
|
wx.showToast({
|
|
title: '保存成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
});
|
|
this.setData({visible: false})
|
|
},
|
|
fail: (err) => {
|
|
console.log('保存图片失败', err);
|
|
wx.showToast({
|
|
title: '保存失败',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
}
|
|
});
|
|
},
|
|
fail() {
|
|
// 用户拒绝授权或尚未授权
|
|
// 可以在这里给出提示或引导用户打开设置页面进行授权
|
|
}
|
|
});
|
|
},
|
|
onClose(){
|
|
this.setData({visible: false})
|
|
},
|
|
delBtn(e){
|
|
console.log('删除图片');
|
|
console.log(e.currentTarget.dataset.item);
|
|
const url = e.currentTarget.dataset.item
|
|
const arr = url.split("/"); // 将链接按照 / 分割成数组
|
|
const last = arr[arr.length - 1]; // 取得数组中的最后一个元素
|
|
const num = last.split("?")[0]; // 将最后一个元素按照 ? 分割成数组,取得倒数第二个元素
|
|
console.log(num); // 输出 128
|
|
this.setData({delKey: e.currentTarget.dataset.item, resourceId:num})
|
|
},
|
|
delBtnHx(){
|
|
const hxlist = this.data.hxlist
|
|
const id = hxlist.find(item => item.resourceId == this.data.resourceId).id
|
|
console.log(id);
|
|
req.deleteRequest(`/api/user/curt/message/${id}`,{}).then(res => {
|
|
console.log(res);
|
|
if (res.data.code === 200) {
|
|
this.getList()
|
|
this.setData({delKey: ''})
|
|
}
|
|
})
|
|
},
|
|
closeViewer(){this.setData({visible: false})},
|
|
getList(){
|
|
req.getRequest('/api/user/curt/message/lover',{
|
|
limit:-1,
|
|
type: 'graphic'
|
|
}).then(res => {
|
|
const list = res.data.data.records
|
|
list.forEach(item => {
|
|
// 将时间字符串转为Date对象
|
|
const date = new Date(item.createdAt);
|
|
|
|
// 获取年月日时分秒
|
|
const year = date.getFullYear();
|
|
const month = date.getMonth() + 1;
|
|
const day = date.getDate();
|
|
// 格式化时间
|
|
const formattedDate = `${year}年${month}月${day}日`;
|
|
item.createdAt = formattedDate
|
|
})
|
|
console.log(list);
|
|
this.setData({hxlist: list})
|
|
const treeData = list.reduce((result, item) => {
|
|
const group = result.find(group => group.createdAt === item.createdAt);
|
|
if (group) {
|
|
// group.list.push(item.resourceId);
|
|
group.list.push(`https://xzjl-api.windymuse.cn/api/resource/${item.resourceId}?k=${item.fromUserid}`);
|
|
} else {
|
|
result.push({
|
|
createdAt: item.createdAt,
|
|
list: [`https://xzjl-api.windymuse.cn/api/resource/${item.resourceId}?k=${item.fromUserid}`]
|
|
});
|
|
}
|
|
return result;
|
|
}, []);
|
|
|
|
console.log(treeData);
|
|
|
|
this.setData({list: treeData})
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.getList()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |