|
|
|
|
@ -36,28 +36,26 @@ Page({
|
|
|
|
|
ztVisible:false,//写纸条弹窗
|
|
|
|
|
messages:[],
|
|
|
|
|
loverInfo:{},
|
|
|
|
|
hasLover:false,// 是否单身
|
|
|
|
|
userInfo:{},
|
|
|
|
|
savePicture: false, // 保存图片成功
|
|
|
|
|
soundData:{}, //音频数据
|
|
|
|
|
userImg: '', //用户默认头像
|
|
|
|
|
loveImg: '' //情侣默认头像
|
|
|
|
|
loveImg: '', //情侣默认头像
|
|
|
|
|
chatHeight:0
|
|
|
|
|
},
|
|
|
|
|
doLuYINBoF(e){
|
|
|
|
|
console.log(e.currentTarget.dataset.tp);
|
|
|
|
|
// 判断点击的是否为对方的语音
|
|
|
|
|
if(e.currentTarget.dataset.item){
|
|
|
|
|
const id = e.currentTarget.dataset.item.id
|
|
|
|
|
console.log(id);
|
|
|
|
|
// 改变语音状态
|
|
|
|
|
req.patchRequest(`/api/user/curt/message/${id}/read`,{}).then(res => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
console.log(res,'已读语音');
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
//先判断是开是关
|
|
|
|
|
if(!e.currentTarget.dataset.bf){//此时点击为关闭
|
|
|
|
|
//设置当前状态为关闭,并关闭
|
|
|
|
|
if(!e.currentTarget.dataset.bf){
|
|
|
|
|
this.setData({['messages['+e.currentTarget.dataset.index+'].extra.isBf']:false})
|
|
|
|
|
this.data.innerAudioContext.stop() // 关闭
|
|
|
|
|
}else{//此时点击为开启
|
|
|
|
|
// 先设置全部为false
|
|
|
|
|
for(var i =0;i<this.data.messages.length;i++){
|
|
|
|
|
@ -65,18 +63,10 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
//先停止
|
|
|
|
|
this.data.innerAudioContext.stop()
|
|
|
|
|
const innerAudioContext = wx.createInnerAudioContext({
|
|
|
|
|
useWebAudioImplement: false
|
|
|
|
|
})
|
|
|
|
|
this.data.innerAudioContext.src = e.currentTarget.dataset.tp
|
|
|
|
|
this.setData({['messages['+e.currentTarget.dataset.index+'].extra.isBf']:true})
|
|
|
|
|
|
|
|
|
|
this.data.innerAudioContext.play() // 播放
|
|
|
|
|
// 此时需要向对应的item赋值
|
|
|
|
|
|
|
|
|
|
//innerAudioContext.pause() // 暂停
|
|
|
|
|
|
|
|
|
|
// innerAudioContext.stop() // 停止
|
|
|
|
|
this.data.innerAudioContext.onEnded((res)=>{
|
|
|
|
|
this.setData({['messages['+e.currentTarget.dataset.index+'].extra.isBf']:false})
|
|
|
|
|
})
|
|
|
|
|
@ -356,6 +346,13 @@ Page({
|
|
|
|
|
},
|
|
|
|
|
deleteMsg(){
|
|
|
|
|
console.log(this.data.delId);
|
|
|
|
|
if (this.data.delId === -1) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '该信札不允许删除',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return this.setData({delId: 0})
|
|
|
|
|
}
|
|
|
|
|
req.deleteRequest(`/api/user/curt/message/${this.data.delId}`,{}).then(res => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
if (res.data.code === 200) {
|
|
|
|
|
@ -518,6 +515,7 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
this.setData({messages:list.reverse()})
|
|
|
|
|
this.getDeteleImg()
|
|
|
|
|
this.getNewMsg()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@ -536,10 +534,9 @@ Page({
|
|
|
|
|
doQueryInit(){
|
|
|
|
|
req.getRequest('/api/user/curt',{}).then((res)=>{
|
|
|
|
|
if(res.data.code==200){
|
|
|
|
|
this.setData({hasLover:res.data.data.hasLover})
|
|
|
|
|
this.setData({userInfo:res.data.data})
|
|
|
|
|
if(!res.data.data.hasLover){
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
wx.redirectTo({
|
|
|
|
|
url: '/pages/home/xx/index'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@ -646,12 +643,33 @@ Page({
|
|
|
|
|
this.setData({userImg: userImg['elf-avatar'], loveImg: loveImg['elf-avatar']})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 时时显示最新聊天记录
|
|
|
|
|
getNewMsg(){
|
|
|
|
|
// 获取到聊天记录的总高度
|
|
|
|
|
const text = this.data.messages.filter(item => {
|
|
|
|
|
return item.type === 'text'
|
|
|
|
|
}).length
|
|
|
|
|
const letter = this.data.messages.filter(item => {
|
|
|
|
|
return item.type === 'letter'
|
|
|
|
|
}).length
|
|
|
|
|
const graphic = this.data.messages.filter(item => {
|
|
|
|
|
return item.type === 'graphic'
|
|
|
|
|
}).length
|
|
|
|
|
const audio = this.data.messages.filter(item => {
|
|
|
|
|
return item.type === 'audio'
|
|
|
|
|
}).length
|
|
|
|
|
const height = text * 92 + letter * 75 + graphic * 127 + audio * 84 + 100000
|
|
|
|
|
if (height !== this.data.chatHeight) {
|
|
|
|
|
this.setData({chatHeight:height})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
const innerAudioContext = wx.createInnerAudioContext({
|
|
|
|
|
useWebAudioImplement: false
|
|
|
|
|
useWebAudioImplement: true
|
|
|
|
|
})
|
|
|
|
|
this.setData({innerAudioContext:innerAudioContext})
|
|
|
|
|
this.doQueryInit()
|
|
|
|
|
@ -676,7 +694,6 @@ Page({
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|