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

156 lines
3.9 KiB

// pages/xz/index.js
const app = getApp();//新建页面时 默认引入
const req = app.xzjlReq();//初始化一个的request() 实例
Page({
/**
* 页面的初始数据
*/
data: {
img:'',
letterMsg:{},
showLetter: true,
showMore: false,
showDel:false
},
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 === 'text') {
this.setData({content: item.content})
}else if(item.type === 'graphic') {
this.getResource(id, item.resourceId, 'graphic')
}else if(item.type === 'audio') {
this.getResource(id, item.resourceId, 'audio')
}
})
})
},
getUserInfo(){
req.getRequest('/api/user/curt',{}).then(res => {
const id = res.data.data.id
// console.log(res.data.data.id,'当前用户id');
this.getLetterMsg(id)
})
},
// 获取文件
getResource(id,k,type){
if(type === 'graphic'){
this.setData({
img: `https://xzjl-api.windymuse.cn/api/resource/${k}?k=${id}`
})
}else if(type === 'audio'){
this.setData({
videos: `https://xzjl-api.windymuse.cn/api/resource/${k}?k=${id}`
})
console.log(this.data.videos,'语音路径');
}
},
// 播放录音
playVideos(){
console.log('播放录音');
wx.playVoice({
filePath: this.data.videos,
complete: () => {
console.log('录音播放结束');
}
});
},
// 重置信札
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'
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getUserInfo()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})