|
|
|
@ -13,13 +13,13 @@ Page({
|
|
|
|
content:'',
|
|
|
|
content:'',
|
|
|
|
audioList:[], // 音频列表
|
|
|
|
audioList:[], // 音频列表
|
|
|
|
imgList:[], // 图片列表
|
|
|
|
imgList:[], // 图片列表
|
|
|
|
|
|
|
|
messageList: [{content: '', type: 'text', index: 1}], //消息列表
|
|
|
|
sound:'',
|
|
|
|
sound:'',
|
|
|
|
soundTime:'00:00:00',
|
|
|
|
soundTime:'00:00:00',
|
|
|
|
duration: '',
|
|
|
|
duration: '',
|
|
|
|
minute:0, //分
|
|
|
|
minute:0, //分
|
|
|
|
second:0, //秒
|
|
|
|
second:0, //秒
|
|
|
|
millisecond:0, //毫秒
|
|
|
|
millisecond:0, //毫秒
|
|
|
|
showBtn:true,
|
|
|
|
|
|
|
|
showImgBig:false, //图片太大弹层
|
|
|
|
showImgBig:false, //图片太大弹层
|
|
|
|
showSoundMore:false, //语音太多提示
|
|
|
|
showSoundMore:false, //语音太多提示
|
|
|
|
showSend:false, //寄出提示
|
|
|
|
showSend:false, //寄出提示
|
|
|
|
@ -33,30 +33,48 @@ Page({
|
|
|
|
btn3:false,
|
|
|
|
btn3:false,
|
|
|
|
btn4:false,
|
|
|
|
btn4:false,
|
|
|
|
showSoundImg:true,
|
|
|
|
showSoundImg:true,
|
|
|
|
isPlaying: false, // 是否正在播放语音
|
|
|
|
isPlaying: false // 是否正在播放语音
|
|
|
|
},
|
|
|
|
},
|
|
|
|
already(){
|
|
|
|
already(){
|
|
|
|
console.log('确定寄出');
|
|
|
|
console.log('确定寄出');
|
|
|
|
this.setData({showAlready:true})
|
|
|
|
this.setData({showAlready:true})
|
|
|
|
const list = [ ...this.data.audioList, ...this.data.imgList]
|
|
|
|
const list = []
|
|
|
|
list.push({
|
|
|
|
this.data.messageList.forEach(item => {
|
|
|
|
type: 'text',
|
|
|
|
const obj = {}
|
|
|
|
content: this.data.content
|
|
|
|
obj.type = item.type
|
|
|
|
|
|
|
|
if (item.content) {
|
|
|
|
|
|
|
|
obj.content = item.content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.resourceId) {
|
|
|
|
|
|
|
|
obj.resourceId = item.resourceId
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.extra) {
|
|
|
|
|
|
|
|
obj.extra = item.extra
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.videoSrc) {
|
|
|
|
|
|
|
|
obj.extra.videoSrc = item.videoSrc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.img) {
|
|
|
|
|
|
|
|
obj.extra = {}
|
|
|
|
|
|
|
|
obj.extra.img = item.img
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push(obj)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const fromData = {
|
|
|
|
const formData = {
|
|
|
|
|
|
|
|
type: 'letter',
|
|
|
|
|
|
|
|
letter: {
|
|
|
|
from: this.data.from,
|
|
|
|
from: this.data.from,
|
|
|
|
to: this.data.to,
|
|
|
|
to: this.data.to,
|
|
|
|
messageList: list,
|
|
|
|
messages: list
|
|
|
|
status:'unread'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(fromData);
|
|
|
|
req.postRequest('/api/user/curt/message/lover',formData).then(res =>{
|
|
|
|
// 修改信札
|
|
|
|
if (res.data.code === 200) {
|
|
|
|
req.putRequest('/api/user/curt/letter',fromData).then(res => {
|
|
|
|
wx.showToast({
|
|
|
|
console.log(res,'修改信札内容成功');
|
|
|
|
title: '信札发送成功',
|
|
|
|
// 修改状态
|
|
|
|
icon: 'success'
|
|
|
|
req.patchRequest('/api/user/curt/letter/send',{}).then(res => {
|
|
|
|
|
|
|
|
console.log(res,'信札状态修改成功');
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
closeShowImgBig(){
|
|
|
|
closeShowImgBig(){
|
|
|
|
@ -74,31 +92,53 @@ Page({
|
|
|
|
closeShowImgToast(){this.setData({showImgToast: false})},
|
|
|
|
closeShowImgToast(){this.setData({showImgToast: false})},
|
|
|
|
openPreview(){
|
|
|
|
openPreview(){
|
|
|
|
console.log('预览');
|
|
|
|
console.log('预览');
|
|
|
|
this.setData({Preview:true})
|
|
|
|
if (this.data.letterId) {
|
|
|
|
|
|
|
|
if (this.data.hy) {
|
|
|
|
|
|
|
|
return wx.redirectTo({
|
|
|
|
|
|
|
|
url: '/pages/home/xx/hy/index',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return wx.redirectTo({
|
|
|
|
|
|
|
|
url: '/pages/home/xx/lindex/lindex',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setData({Preview : !this.data.Preview})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClearYl(e){
|
|
|
|
ClearYl(e){
|
|
|
|
console.log('清除语音');
|
|
|
|
console.log('清除语音');
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
const list = this.data.audioList.filter(item => {
|
|
|
|
const list = this.data.messageList.filter(item => {
|
|
|
|
return item.resourceId !== id
|
|
|
|
return item.resourceId !== id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({audioList: list})
|
|
|
|
this.setData({messageList: list})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClearImg(e){
|
|
|
|
ClearImg(e){
|
|
|
|
console.log('清除图片');
|
|
|
|
console.log('清除图片');
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
const list = this.data.imgList.filter(item => {
|
|
|
|
const list = this.data.messageList.filter(item => {
|
|
|
|
return item.resourceId !== id
|
|
|
|
return item.resourceId !== id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({imgList: list})
|
|
|
|
this.setData({messageList: list})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
goBack(){
|
|
|
|
goBack(){
|
|
|
|
if (this.data.Preview) {
|
|
|
|
wx.redirectTo({
|
|
|
|
this.setData({Preview: false})
|
|
|
|
url: '/pages/home/xx/lindex/lindex',
|
|
|
|
}else{
|
|
|
|
})
|
|
|
|
console.log('返回');
|
|
|
|
},
|
|
|
|
wx.navigateBack()
|
|
|
|
// 获取文本框内容
|
|
|
|
|
|
|
|
getTextValue(e){
|
|
|
|
|
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
|
|
|
|
|
const content = e.detail.value
|
|
|
|
|
|
|
|
const list = this.data.messageList.map(item => {
|
|
|
|
|
|
|
|
if (item.index === index) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
content : content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setData({messageList: list})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 上传图片
|
|
|
|
// 上传图片
|
|
|
|
addImg(){
|
|
|
|
addImg(){
|
|
|
|
@ -114,6 +154,7 @@ Page({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 文件上传
|
|
|
|
// 文件上传
|
|
|
|
uploadFile(file,type) {
|
|
|
|
uploadFile(file,type) {
|
|
|
|
wx.uploadFile({
|
|
|
|
wx.uploadFile({
|
|
|
|
@ -129,35 +170,53 @@ Page({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
success: (async(res) => {
|
|
|
|
success: (async(res) => {
|
|
|
|
const data = JSON.parse(res.data);
|
|
|
|
const data = JSON.parse(res.data);
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
if (data.data.type === 'audio') {
|
|
|
|
if (data.data.type === 'audio') {
|
|
|
|
console.log('添加音频');
|
|
|
|
console.log('添加音频');
|
|
|
|
const list = this.data.audioList
|
|
|
|
const list = this.data.messageList
|
|
|
|
if(list.length >= 3){
|
|
|
|
const index = list.length + 1
|
|
|
|
|
|
|
|
const audioList = list.filter(item => {
|
|
|
|
|
|
|
|
return item.type === 'audio'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if(audioList.length >= 3){
|
|
|
|
this.setData({showSoundMore:true ,showSoundImg:true})
|
|
|
|
this.setData({showSoundMore:true ,showSoundImg:true})
|
|
|
|
console.log('语音太多了');
|
|
|
|
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
list.push({
|
|
|
|
list.push({
|
|
|
|
type: 'audio',
|
|
|
|
type: 'audio',
|
|
|
|
resourceId: data.data.id,
|
|
|
|
resourceId: data.data.id,
|
|
|
|
duration: this.data.duration,
|
|
|
|
duration: this.data.duration,
|
|
|
|
videoSrc: this.data.videoSrc,
|
|
|
|
videoSrc: this.data.videoSrc,
|
|
|
|
|
|
|
|
index:index,
|
|
|
|
extra: {duration : this.data.ssec}
|
|
|
|
extra: {duration : this.data.ssec}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({audioList: list})
|
|
|
|
list.push({
|
|
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
|
|
content: '',
|
|
|
|
|
|
|
|
index: index + 1
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setData({messageList: list})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (data.data.type === 'poster') {
|
|
|
|
} else if (data.data.type === 'poster') {
|
|
|
|
console.log('添加图片');
|
|
|
|
console.log('添加图片');
|
|
|
|
const list = this.data.imgList
|
|
|
|
const list = this.data.messageList
|
|
|
|
if (list.length >= 9) {
|
|
|
|
const migList = list.filter(item => {
|
|
|
|
|
|
|
|
return item.type === 'graphic'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if (migList.length >= 9) {
|
|
|
|
this.setData({showImgToast : true})
|
|
|
|
this.setData({showImgToast : true})
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
|
|
|
|
const index = list.length + 1
|
|
|
|
list.push({
|
|
|
|
list.push({
|
|
|
|
type: 'graphic',
|
|
|
|
type: 'graphic',
|
|
|
|
resourceId: data.data.id,
|
|
|
|
resourceId: data.data.id,
|
|
|
|
img: data.data.abUrl,
|
|
|
|
img: data.data.abUrl,
|
|
|
|
|
|
|
|
index: index
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({imgList: list, showImg:true})
|
|
|
|
list.push({
|
|
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
|
|
content: '',
|
|
|
|
|
|
|
|
index: index + 1
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setData({messageList: list, showImg:true})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
@ -288,39 +347,27 @@ Page({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
logout(){
|
|
|
|
logout(){
|
|
|
|
req.deleteRequest('/api/user/logout',{}).then((res)=>{
|
|
|
|
wx.redirectTo({
|
|
|
|
if(res.data.code===200){
|
|
|
|
url: '/pages/home/xx/lindex/lindex',
|
|
|
|
wx.navigateTo({
|
|
|
|
|
|
|
|
url: '/pages/index/index'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
|
|
title:'寄出成功'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modify(){
|
|
|
|
modify(){
|
|
|
|
this.setData({showAlready: false, showSend: false})
|
|
|
|
this.setData({showAlready: false, showSend: false})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getLetter(){
|
|
|
|
|
|
|
|
console.log('获取当前用户信札内容');
|
|
|
|
|
|
|
|
req.getRequest('/api/user/curt/letter',{}).then(res => {
|
|
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 点击音频试听
|
|
|
|
// 点击音频试听
|
|
|
|
listen(e){
|
|
|
|
listen(e){
|
|
|
|
if (this.data.isPlaying) {
|
|
|
|
if (this.data.isPlaying) {
|
|
|
|
return; // 如果正在播放语音,则不触发事件
|
|
|
|
return; // 如果正在播放语音,则不触发事件
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const id = e.currentTarget.dataset.url.resourceId
|
|
|
|
const id = e.currentTarget.dataset.url.resourceId
|
|
|
|
const videoSrc = this.data.audioList.find(item => {
|
|
|
|
const videoSrc = this.data.messageList.find(item => {
|
|
|
|
return item.resourceId === id
|
|
|
|
return item.resourceId === id
|
|
|
|
}).videoSrc
|
|
|
|
}).videoSrc
|
|
|
|
console.log(videoSrc);
|
|
|
|
console.log(videoSrc);
|
|
|
|
const innerAudioContext = wx.createInnerAudioContext()
|
|
|
|
const innerAudioContext = wx.createInnerAudioContext()
|
|
|
|
innerAudioContext.src = videoSrc
|
|
|
|
innerAudioContext.src = videoSrc
|
|
|
|
innerAudioContext.play() // 播放
|
|
|
|
innerAudioContext.play() // 播放
|
|
|
|
|
|
|
|
console.log('播放');
|
|
|
|
this.setData({ isPlaying: true }); // 设置为正在播放语音
|
|
|
|
this.setData({ isPlaying: true }); // 设置为正在播放语音
|
|
|
|
innerAudioContext.onEnded(() => {
|
|
|
|
innerAudioContext.onEnded(() => {
|
|
|
|
this.setData({ isPlaying: false }); // 播放完毕后设置为非播放状态
|
|
|
|
this.setData({ isPlaying: false }); // 播放完毕后设置为非播放状态
|
|
|
|
@ -332,12 +379,68 @@ Page({
|
|
|
|
this.setData({id:id})
|
|
|
|
this.setData({id:id})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取信札消息
|
|
|
|
|
|
|
|
getLetterDetail(id){
|
|
|
|
|
|
|
|
req.getRequest(`/api/user/curt/message/${id}`,{}).then(res => {
|
|
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
|
|
if(res.data.code === 200){
|
|
|
|
|
|
|
|
const letter = res.data.data.letter
|
|
|
|
|
|
|
|
const messages = letter.messages.map(item => {
|
|
|
|
|
|
|
|
if (item.extra && item.extra.videoSrc) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
videoSrc: item.extra.videoSrc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.extra && item.extra.img) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...item,
|
|
|
|
|
|
|
|
img: item.extra.img
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.content) {
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
|
|
from: letter.from,
|
|
|
|
|
|
|
|
to: letter.to,
|
|
|
|
|
|
|
|
messageList: messages
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为情侣信札 是就更改信札状态
|
|
|
|
|
|
|
|
if (res.data.data.fromUserid !== this.data.id && res.data.data.status === 'unread') {
|
|
|
|
|
|
|
|
req.patchRequest(`/api/user/curt/message/${id}/read`)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
|
|
title: '获取信札内容失败',
|
|
|
|
|
|
|
|
icon: 'error'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
onLoad(options) {
|
|
|
|
this.getLetter()
|
|
|
|
|
|
|
|
this.getUserInfo()
|
|
|
|
this.getUserInfo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 回忆页面点击信札 数据回显示
|
|
|
|
|
|
|
|
if (options.id) {
|
|
|
|
|
|
|
|
this.getLetterDetail(options.id)
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
|
|
Preview: true,
|
|
|
|
|
|
|
|
letterId: options.id
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是回忆页面跳转还是聊天页面跳转
|
|
|
|
|
|
|
|
if(options.hy){
|
|
|
|
|
|
|
|
this.setData({ hy: true })
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|