微信小程序实现聊天功能,带表情,拍照等功能
微信小程序实现聊天功能,带表情,拍照等功能(后端用php的Workerman来实现),想要知道具体怎么实现的加我QQ:1346883814
【微信小程序实现聊天功能,带表情,拍照等功能】部分代码:
toSend: function (msgType, messageId, msgContent, fileContent, path, duration) {
let that = this
let uid = that.data.userId
let cuid = that.data.currenId
if (msgType == 'img' || msgType == 'audio'){
util.common.uploadFile(path, function (res) {
let msg = '{ "type":"chat", "target":' + uid + ', "from":' + cuid + ',"room_id":1, "msg": { "type":"' + msgType + '", "messageId":"' + messageId + '", "msg":"' + msgContent + '","fileContent":"' + res.data.url + '","path":"' + res.data.url + '","duration":"' + duration + '"}}'
let msgRecords = { msg: msgContent, filePath: conf.apiImgUrl + res.data.url, msgType: msgType, duration: duration, position: "right" }
var chatRecords = wx.getStorageSync('chat' + cuid + uid)
if (chatRecords == "" || chatRecords == undefined) {
wx.setStorageSync('chat' + cuid + uid, [msgRecords])
} else {
if (chatRecords.length >= 100) {
chatRecords.splice(0, 1);
}
chatRecords.push(msgRecords)
wx.setStorageSync('chat' + cuid + uid, chatRecords)
}
that.setData({
msg: chatRecords
})
that.sendSocketMessage(msg)
})
}else{
let msg = '{ "type":"chat", "target":' + uid + ', "from":' + cuid + ',"room_id":1, "msg": { "type":"' + msgType + '", "messageId":"' + messageId + '", "msg":"' + msgContent + '","fileContent":"' + fileContent + '","path":"' + path + '","duration":"' + duration + '"}}'
let msgRecords = { msg: msgContent, filePath: path, msgType: msgType, duration: duration, position: "right" }
var chatRecords = wx.getStorageSync('chat' + cuid + uid)
if (chatRecords == "" || chatRecords == undefined) {
wx.setStorageSync('chat' + cuid + uid, [msgRecords])
} else {
if (chatRecords.length >= 100) {
chatRecords.splice(0, 1);
}
chatRecords.push(msgRecords)
wx.setStorageSync('chat' + cuid + uid, chatRecords)
}
// console.log(JSON.parse(chatRecords[8]))
that.setData({
msg: chatRecords
})
that.sendSocketMessage(msg)
}
},
效果图如下:
文章图片
文章图片
文章图片
推荐阅读
- 一个小故事,我的思考。
- 家乡的那条小河
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 昨夜小楼听风
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 2019.4.18感恩日记
- 那件我们忽略的小事叫感恩
- 你有婚内虐待行为吗()