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.
xzjl-ui/pages/xz/index.js

163 lines
4.1 KiB

// pages/xz/index.js
const app = getApp();//新建页面时 默认引入
const req = app.xzjlReq();//初始化一个的request() 实例
Page({
/**
* 页面的初始数据
*/
data: {
img:'',
letterMsg:{},
showLetter: true,
showMore: false,
showDel:false,
imgList:[],
audioList:[],
messageList: [],
playVideos: true
},
openLetter(){
this.setData({showLetter: !this.data.showLetter}),
req.patchRequest('/api/user/curt/letter/read',{}).then(res => {
console.log(res,'已读信札');
})
},
openMore(){this.setData({showMore: !this.data.showMore})},
openDel(){this.setData({showDel: !this.data.showDel})},
getLetterMsg(id){
console.log('获取信札');
req.getRequest('/api/user/curt/letter',{}).then(res => {
console.log(res);
const { messageList } = res.data.data
// 获取创建时间
const date = new Date(res.header.Date);
// 获取年月日时分秒等信息
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const formattedDate = `${year}${month}${day}${hour}:${minute}`;
this.setData({
letterMsg: res.data.data,
time: formattedDate
})
// 判断是否有图片
console.log(messageList);
messageList.forEach(item => {
if(item.type === 'graphic') {
item.img = `https://xzjl-api.windymuse.cn/api/resource/${item.resourceId}?k=${id}`
}else if(item.type === 'audio') {
item.audio = `https://xzjl-api.windymuse.cn/api/resource/${item.resourceId}?k=${id}`
}
})
this.setData({messageList: messageList})
})
},
getUserInfo(){
req.getRequest('/api/user/curt',{}).then(res => {
const id = res.data.data.id
this.getLetterMsg(id)
})
},
// 播放录音
playVideos(e){
if (this.data.playVideos) {
this.setData({playVideos: false})
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.src = e.currentTarget.dataset.url.audio
innerAudioContext.play()
innerAudioContext.onEnded(() => {
this.setData({playVideos: true})
})
}
},
// 重置信札
resetLetter(){
req.putRequest('/api/user/curt/letter/reset',{}).then( res => {
console.log(res, '重置成功');
})
wx.switchTab({
url: '/pages/home/xy/index'
})
},
go2Back(){
wx.switchTab({
url: '/pages/home/xy/index'
})
},
// 修改信札
editXz(){
wx.redirectTo({
url: '/pages/home/xx/xz/xz'
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (options.open) {
// 单人状态下点击【信札】跳转的页面
this.setData({showLetter: false})
}else if (options.id) {
// 情侣状态下点击【信札】跳转的页面
console.log(options.id, '111');
this.setData({showLetter: false})
}else {
this.getUserInfo()
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})