聊天
This commit is contained in:
@@ -61,9 +61,8 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<Message> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
|
||||||
logger.info("***********************收到消息:{}", msg);
|
// logger.info("***********************收到消息:{}", msg);
|
||||||
logger.info("***********************收到消息:{}", msg);
|
// logger.info("***********************收到消息:{}", msg);
|
||||||
logger.info("***********************收到消息:{}", msg);
|
|
||||||
|
|
||||||
Integer command = msg.getMessageHeader().getCommand();
|
Integer command = msg.getMessageHeader().getCommand();
|
||||||
|
|
||||||
@@ -149,6 +148,9 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<Message> {
|
|||||||
ctx.channel().attr(AttributeKey.valueOf(Constants.ReadTime)).set(System.currentTimeMillis());
|
ctx.channel().attr(AttributeKey.valueOf(Constants.ReadTime)).set(System.currentTimeMillis());
|
||||||
}else if(command == MessageCommand.MSG_P2P.getCommand()
|
}else if(command == MessageCommand.MSG_P2P.getCommand()
|
||||||
|| command == GroupEventCommand.MSG_GROUP.getCommand()){
|
|| command == GroupEventCommand.MSG_GROUP.getCommand()){
|
||||||
|
logger.info("***********************收到单聊或者群聊消息:{}", msg);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String toId = "";
|
String toId = "";
|
||||||
CheckSendMessageReq req = new CheckSendMessageReq();
|
CheckSendMessageReq req = new CheckSendMessageReq();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
export default class config{
|
export default class config{
|
||||||
static getBaseApiUrl(){
|
static getBaseApiUrl(){
|
||||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:8989' :'http://www.shudong.xyz/shudong_api/';
|
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:8989' :'http://192.168.1.117:8989';
|
||||||
}
|
}
|
||||||
static getImApiUrl(){
|
static getImApiUrl(){
|
||||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:28000/v1' :'http://www.shudong.xyz/shudong_api/';
|
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:28000/v1' :'http://192.168.1.117:28000/v1';
|
||||||
}
|
}
|
||||||
static getImAppId(){
|
static getImAppId(){
|
||||||
return 10000;
|
return 10000;
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ export default {
|
|||||||
browser.show(url)
|
browser.show(url)
|
||||||
},
|
},
|
||||||
//获取时间format
|
//获取时间format
|
||||||
getNewDate(format, add0,datetime) {
|
getNewDate(format, add0, datetime) {
|
||||||
//获取当前时间
|
//获取当前时间
|
||||||
function addZero(val) {
|
function addZero(val) {
|
||||||
//补零
|
//补零
|
||||||
@@ -197,10 +197,10 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var date = new Date()
|
var date = new Date()
|
||||||
if(datetime){
|
if (datetime) {
|
||||||
date=Date.parse(new Date(datetime))
|
date = Date.parse(new Date(datetime))
|
||||||
}
|
}
|
||||||
|
|
||||||
var year = date.getFullYear(),
|
var year = date.getFullYear(),
|
||||||
month = addZero(date.getMonth() + 1),
|
month = addZero(date.getMonth() + 1),
|
||||||
strDate = addZero(date.getDate()),
|
strDate = addZero(date.getDate()),
|
||||||
@@ -254,37 +254,39 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadMore({
|
loadMore({
|
||||||
url='xxx/list/',
|
url = 'xxx/list/',
|
||||||
queryParams={
|
queryParams = {
|
||||||
refreshing:false,
|
refreshing: false,
|
||||||
pageNum:1,
|
pageNum: 1,
|
||||||
status: 'more',//more loading前 loading loading中 noMore 没有更多了
|
status: 'more', //more loading前 loading loading中 noMore 没有更多了
|
||||||
pageSize:10
|
pageSize: 10
|
||||||
},
|
},
|
||||||
status='0'//0无更多数据 1持续加载 2重新加载 3无数据+清空数据
|
status = '0' //0无更多数据 1持续加载 2重新加载 3无数据+清空数据
|
||||||
}){
|
}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
http.request({
|
http.request({
|
||||||
url:url+'&pageNum='+(queryParams.refreshing ? 1 : queryParams.pageNum) +'&pageSize=' +queryParams.pageSize,
|
url: url + '&pageNum=' + (queryParams.refreshing ? 1 : queryParams.pageNum) +
|
||||||
|
'&pageSize=' + queryParams.pageSize,
|
||||||
success: res => {
|
success: res => {
|
||||||
if (res.data.code == 200) {
|
if (res.data.code == 200) {
|
||||||
let list = [];
|
let list = [];
|
||||||
let data = res.data.rows;
|
let data = res.data.rows;
|
||||||
if (queryParams.refreshing&&res.data.rows == ''||queryParams.refreshing&&res.data.rows.length==0) {
|
if (queryParams.refreshing && res.data.rows == '' || queryParams
|
||||||
queryParams.status='noMore'
|
.refreshing && res.data.rows.length == 0) {
|
||||||
|
queryParams.status = 'noMore'
|
||||||
resolve({
|
resolve({
|
||||||
queryParams:queryParams,
|
queryParams: queryParams,
|
||||||
list:list,
|
list: list,
|
||||||
status:'3'
|
status: '3'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (res.data.rows == ''||res.data.rows.length==0) {
|
if (res.data.rows == '' || res.data.rows.length == 0) {
|
||||||
queryParams.status='noMore'
|
queryParams.status = 'noMore'
|
||||||
resolve({
|
resolve({
|
||||||
queryParams:queryParams,
|
queryParams: queryParams,
|
||||||
list:list,
|
list: list,
|
||||||
status:'0'
|
status: '0'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -295,19 +297,19 @@ export default {
|
|||||||
if (queryParams.refreshing) {
|
if (queryParams.refreshing) {
|
||||||
queryParams.refreshing = false;
|
queryParams.refreshing = false;
|
||||||
queryParams.pageNum = 2;
|
queryParams.pageNum = 2;
|
||||||
queryParams.status='more'
|
queryParams.status = 'more'
|
||||||
resolve({
|
resolve({
|
||||||
queryParams:queryParams,
|
queryParams: queryParams,
|
||||||
list:list,
|
list: list,
|
||||||
status:'2'
|
status: '2'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
queryParams.pageNum += 1;
|
queryParams.pageNum += 1;
|
||||||
queryParams.status='more'
|
queryParams.status = 'more'
|
||||||
resolve({
|
resolve({
|
||||||
queryParams:queryParams,
|
queryParams: queryParams,
|
||||||
list:list,
|
list: list,
|
||||||
status:'1'
|
status: '1'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -325,55 +327,64 @@ export default {
|
|||||||
console.log(resbody)
|
console.log(resbody)
|
||||||
var pushType = resbody.pushType //推送类型
|
var pushType = resbody.pushType //推送类型
|
||||||
if (pushType == 'MSG') {
|
if (pushType == 'MSG') {
|
||||||
|
/*
|
||||||
if(resbody.msgContent.msgType=='TRTC_VOICE_START'||resbody.msgContent.msgType=='TRTC_VIDEO_START'){
|
if(resbody.msgContent.msgType=='TRTC_VOICE_START'||resbody.msgContent.msgType=='TRTC_VIDEO_START'){
|
||||||
//音视频开始拦截
|
//音视频开始拦截
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var userId=resbody.fromInfo.userId
|
*/
|
||||||
var windowType='SINGLE'
|
var userId = resbody.userId
|
||||||
|
var windowType = 'SINGLE'
|
||||||
|
/*
|
||||||
if(resbody.groupInfo.userId){
|
if(resbody.groupInfo.userId){
|
||||||
userId=resbody.groupInfo.userId
|
userId=resbody.groupInfo.userId
|
||||||
windowType='GROUP'
|
windowType='GROUP'
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
const _userId = uni.getStorageSync("userId")
|
||||||
|
|
||||||
|
debugger
|
||||||
|
|
||||||
this.pushInMsg({
|
this.pushInMsg({
|
||||||
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
||||||
msgContent: resbody.msgContent.content, //msg内容
|
msgContent: resbody.msgContent.content, //msg内容
|
||||||
msgType: resbody.msgContent.msgType, //msgType信息类型
|
msgType: resbody.msgContent.msgType, //msgType信息类型
|
||||||
windowType: windowType, //聊天室类型 SINGLE GROUP
|
windowType: windowType, //聊天室类型 SINGLE GROUP
|
||||||
time: resbody.createTime, //时间
|
time: resbody.createTime, //时间
|
||||||
fromInfo:resbody.fromInfo,//来源信息
|
fromInfo: resbody.fromInfo, //来源信息
|
||||||
groupInfo:resbody.groupInfo,//群信息
|
groupInfo: resbody.groupInfo, //群信息
|
||||||
userId: userId,//talktoId
|
userId: _userId, //talktoId
|
||||||
personId:resbody.fromInfo.userId,
|
personId: resbody.fromInfo.userId,
|
||||||
msgId:resbody.msgId,//消息Id
|
msgId: resbody.msgId, //消息Id
|
||||||
disturb:resbody.msgContent.disturb,//是否静默消息
|
disturb: resbody.msgContent.disturb, //是否静默消息
|
||||||
top:resbody.msgContent.top//是否置顶
|
top: resbody.msgContent.top //是否置顶
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pushType == 'NOTICE') {//红点通知等
|
if (pushType == 'NOTICE') { //红点通知等
|
||||||
if(resbody.msgContent.topicReply.count){
|
if (resbody.msgContent.topicReply.count) {
|
||||||
store.commit('update_topicReply',resbody.msgContent.topicReply)
|
store.commit('update_topicReply', resbody.msgContent.topicReply)
|
||||||
}
|
}
|
||||||
if(resbody.msgContent.topicRed.portrait){
|
if (resbody.msgContent.topicRed.portrait) {
|
||||||
store.commit('update_topicRed',resbody.msgContent.topicRed)
|
store.commit('update_topicRed', resbody.msgContent.topicRed)
|
||||||
}
|
}
|
||||||
if(resbody.msgContent.friendApply.count){
|
if (resbody.msgContent.friendApply.count) {
|
||||||
store.commit('update_friendApply',resbody.msgContent.friendApply)
|
store.commit('update_friendApply', resbody.msgContent.friendApply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pushType == 'BIG') {//大消息
|
if (pushType == 'BIG') { //大消息
|
||||||
var bigId=resbody.msgContent.content
|
var bigId = resbody.msgContent.content
|
||||||
http.request({
|
http.request({
|
||||||
url: '/chat/getBigMsg/'+bigId,
|
url: '/chat/getBigMsg/' + bigId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.data.code == 200) {
|
if (res.data.code == 200) {
|
||||||
var resbody=res.data.data
|
var resbody = res.data.data
|
||||||
var userId=resbody.fromInfo.userId
|
var userId = resbody.fromInfo.userId
|
||||||
var windowType='SINGLE'
|
var windowType = 'SINGLE'
|
||||||
if(resbody.groupInfo.userId){
|
if (resbody.groupInfo.userId) {
|
||||||
userId=resbody.groupInfo.userId
|
userId = resbody.groupInfo.userId
|
||||||
windowType='GROUP'
|
windowType = 'GROUP'
|
||||||
}
|
}
|
||||||
this.pushInMsg({
|
this.pushInMsg({
|
||||||
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
||||||
@@ -381,13 +392,13 @@ export default {
|
|||||||
msgType: resbody.msgContent.msgType, //msgType信息类型
|
msgType: resbody.msgContent.msgType, //msgType信息类型
|
||||||
windowType: windowType, //聊天室类型 SINGLE GROUP
|
windowType: windowType, //聊天室类型 SINGLE GROUP
|
||||||
time: resbody.createTime, //时间
|
time: resbody.createTime, //时间
|
||||||
fromInfo:resbody.fromInfo,//来源信息
|
fromInfo: resbody.fromInfo, //来源信息
|
||||||
groupInfo:resbody.groupInfo,//群信息
|
groupInfo: resbody.groupInfo, //群信息
|
||||||
userId: userId,//talktoId
|
userId: userId, //talktoId
|
||||||
personId:resbody.fromInfo.userId,
|
personId: resbody.fromInfo.userId,
|
||||||
msgId:resbody.msgId,//消息Id
|
msgId: resbody.msgId, //消息Id
|
||||||
disturb:resbody.msgContent.disturb,//是否静默消息
|
disturb: resbody.msgContent.disturb, //是否静默消息
|
||||||
top:resbody.msgContent.top//是否置顶
|
top: resbody.msgContent.top //是否置顶
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,18 +408,18 @@ export default {
|
|||||||
},
|
},
|
||||||
// 接收到的聊天推送
|
// 接收到的聊天推送
|
||||||
pushInMsg({
|
pushInMsg({
|
||||||
msgId,//消息Id
|
msgId, //消息Id
|
||||||
msgContent,//内容
|
msgContent, //内容
|
||||||
msgType,//消息类型
|
msgType, //消息类型
|
||||||
windowType,//聊天室类型 SINGLE GROUP
|
windowType, //聊天室类型 SINGLE GROUP
|
||||||
userId,//聊天对象ID
|
userId, //聊天对象ID
|
||||||
personId,//发送人ID
|
personId, //发送人ID
|
||||||
time,//时间
|
time, //时间
|
||||||
type,//显示类型 1左侧 2右侧 3中间
|
type, //显示类型 1左侧 2右侧 3中间
|
||||||
fromInfo,//来源
|
fromInfo, //来源
|
||||||
groupInfo,//群信息
|
groupInfo, //群信息
|
||||||
disturb,//是否静默消息
|
disturb, //是否静默消息
|
||||||
top//是否置顶
|
top //是否置顶
|
||||||
}) {
|
}) {
|
||||||
var msgTypeLabel = ''; //消息类型
|
var msgTypeLabel = ''; //消息类型
|
||||||
if (msgType == 'TEXT') {
|
if (msgType == 'TEXT') {
|
||||||
@@ -444,26 +455,37 @@ export default {
|
|||||||
if (msgType == 'TRTC_VIDEO_END') {
|
if (msgType == 'TRTC_VIDEO_END') {
|
||||||
msgTypeLabel = '[视频通话]'
|
msgTypeLabel = '[视频通话]'
|
||||||
}
|
}
|
||||||
store.dispatch('createChatObj',{
|
console.log(userId)
|
||||||
userId:userId,
|
debugger
|
||||||
windowType:windowType,
|
store.dispatch('createChatObj', {
|
||||||
}).then(res=>{
|
userId: userId,
|
||||||
var localData=res.data
|
windowType: windowType,
|
||||||
|
}).then(res => {
|
||||||
|
debugger
|
||||||
|
var localData = res.data
|
||||||
store.dispatch('getchatDatalist');
|
store.dispatch('getchatDatalist');
|
||||||
store.dispatch('getChatList');
|
store.dispatch('getChatList');
|
||||||
var chatWindowData = store.state.chatDatalist[userId].list
|
var chatWindowData = store.state.chatDatalist[userId].list
|
||||||
var chatListInfo = store.state.chatlist[userId]
|
var chatListInfo = store.state.chatlist[userId]
|
||||||
// 找到数组中对象属性值一样的对象并返回
|
// 找到数组中对象属性值一样的对象并返回
|
||||||
function arrfindobject({arr,object,key}){
|
function arrfindobject({
|
||||||
var result=arr.find(item =>{
|
arr,
|
||||||
return item[key] == object[key]
|
object,
|
||||||
|
key
|
||||||
|
}) {
|
||||||
|
var result = arr.find(item => {
|
||||||
|
return item[key] == object[key]
|
||||||
});
|
});
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
var same=arrfindobject({arr:chatWindowData,object:{
|
var same = arrfindobject({
|
||||||
msgId:msgId
|
arr: chatWindowData,
|
||||||
},key:'msgId'})
|
object: {
|
||||||
if(same){
|
msgId: msgId
|
||||||
|
},
|
||||||
|
key: 'msgId'
|
||||||
|
})
|
||||||
|
if (same) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//离线消息体
|
//离线消息体
|
||||||
@@ -476,13 +498,13 @@ export default {
|
|||||||
content: msgContent,
|
content: msgContent,
|
||||||
time: time,
|
time: time,
|
||||||
type: type,
|
type: type,
|
||||||
msgId:msgId,
|
msgId: msgId,
|
||||||
windowType: windowType
|
windowType: windowType
|
||||||
}
|
}
|
||||||
|
|
||||||
// 聊天记录体
|
// 聊天记录体
|
||||||
var msgList = {}
|
var msgList = {}
|
||||||
if(windowType=='SINGLE'){
|
if (windowType == 'SINGLE') {
|
||||||
msgList = {
|
msgList = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
personId: personId,
|
personId: personId,
|
||||||
@@ -490,14 +512,14 @@ export default {
|
|||||||
portrait: fromInfo.portrait,
|
portrait: fromInfo.portrait,
|
||||||
content: msgTypeLabel,
|
content: msgTypeLabel,
|
||||||
time: time,
|
time: time,
|
||||||
num: disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
num: disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||||
windowType: windowType,
|
windowType: windowType,
|
||||||
disturb:disturb,//是否静默消息
|
disturb: disturb, //是否静默消息
|
||||||
top:top,//是否置顶
|
top: top, //是否置顶
|
||||||
userType:fromInfo.userType
|
userType: fromInfo.userType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(windowType=='GROUP'){
|
if (windowType == 'GROUP') {
|
||||||
msgList = {
|
msgList = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
personId: personId,
|
personId: personId,
|
||||||
@@ -505,11 +527,11 @@ export default {
|
|||||||
portrait: groupInfo.portrait,
|
portrait: groupInfo.portrait,
|
||||||
content: msgTypeLabel,
|
content: msgTypeLabel,
|
||||||
time: time,
|
time: time,
|
||||||
num: disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
num: disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||||
windowType: windowType,
|
windowType: windowType,
|
||||||
disturb:disturb,//是否静默消息
|
disturb: disturb, //是否静默消息
|
||||||
top:top,//是否置顶
|
top: top, //是否置顶
|
||||||
userType:'GROUP'
|
userType: 'GROUP'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chatWindowData.push(msgOffline)
|
chatWindowData.push(msgOffline)
|
||||||
@@ -522,7 +544,7 @@ export default {
|
|||||||
data: msgList
|
data: msgList
|
||||||
})
|
})
|
||||||
store.dispatch('tabBarpull')
|
store.dispatch('tabBarpull')
|
||||||
store.dispatch('updateChatDataState',userId);
|
store.dispatch('updateChatDataState', userId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
//发送消息
|
//发送消息
|
||||||
@@ -567,28 +589,28 @@ export default {
|
|||||||
msgTypeLabel = '[视频通话]'
|
msgTypeLabel = '[视频通话]'
|
||||||
}
|
}
|
||||||
var userInfo = store.state.userInfo;
|
var userInfo = store.state.userInfo;
|
||||||
store.dispatch('createChatObj',{
|
store.dispatch('createChatObj', {
|
||||||
userId:userId,
|
userId: userId,
|
||||||
windowType:windowType,
|
windowType: windowType,
|
||||||
}).then(res=>{
|
}).then(res => {
|
||||||
var localData=res.data
|
var localData = res.data
|
||||||
store.dispatch('getchatDatalist');
|
store.dispatch('getchatDatalist');
|
||||||
store.dispatch('getChatList');
|
store.dispatch('getChatList');
|
||||||
var chatWindowData = store.state.chatDatalist[userId].list
|
var chatWindowData = store.state.chatDatalist[userId].list
|
||||||
var chatListInfo = store.state.chatlist[userId]
|
var chatListInfo = store.state.chatlist[userId]
|
||||||
var time = this.getNewDate('format',true)
|
var time = this.getNewDate('format', true)
|
||||||
//在线消息体
|
//在线消息体
|
||||||
var msgOnlie={}
|
var msgOnlie = {}
|
||||||
//聊天记录
|
//聊天记录
|
||||||
var msgList={}
|
var msgList = {}
|
||||||
var url=''
|
var url = ''
|
||||||
if(windowType=='SINGLE'){
|
if (windowType == 'SINGLE') {
|
||||||
msgOnlie = {
|
msgOnlie = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
msgType: msgType,
|
msgType: msgType,
|
||||||
content: msgContent
|
content: msgContent
|
||||||
}
|
}
|
||||||
url='/chat/sendMsg'
|
url = '/chat/sendMsg'
|
||||||
msgList = {
|
msgList = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
personId: userInfo.userId,
|
personId: userInfo.userId,
|
||||||
@@ -596,20 +618,20 @@ export default {
|
|||||||
portrait: localData.fromInfo.portrait,
|
portrait: localData.fromInfo.portrait,
|
||||||
content: msgTypeLabel,
|
content: msgTypeLabel,
|
||||||
time: time,
|
time: time,
|
||||||
num: chatListInfo.disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
num: chatListInfo.disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
||||||
windowType: windowType,
|
windowType: windowType,
|
||||||
disturb:chatListInfo.disturb ? chatListInfo.disturb : 'N',//是否静默消息
|
disturb: chatListInfo.disturb ? chatListInfo.disturb : 'N', //是否静默消息
|
||||||
top:chatListInfo.top ? chatListInfo.top : 'N',//是否置顶
|
top: chatListInfo.top ? chatListInfo.top : 'N', //是否置顶
|
||||||
userType:localData.fromInfo.userType
|
userType: localData.fromInfo.userType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(windowType=='GROUP'){
|
if (windowType == 'GROUP') {
|
||||||
msgOnlie = {
|
msgOnlie = {
|
||||||
groupId: userId,
|
groupId: userId,
|
||||||
msgType: msgType,
|
msgType: msgType,
|
||||||
content: msgContent
|
content: msgContent
|
||||||
}
|
}
|
||||||
url='/group/sendMsg'
|
url = '/group/sendMsg'
|
||||||
msgList = {
|
msgList = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
personId: userInfo.userId,
|
personId: userInfo.userId,
|
||||||
@@ -617,11 +639,11 @@ export default {
|
|||||||
portrait: localData.groupInfo.portrait,
|
portrait: localData.groupInfo.portrait,
|
||||||
content: msgTypeLabel,
|
content: msgTypeLabel,
|
||||||
time: time,
|
time: time,
|
||||||
num: chatListInfo.disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
num: chatListInfo.disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
||||||
windowType: windowType,
|
windowType: windowType,
|
||||||
disturb:chatListInfo.disturb ? chatListInfo.disturb : 'N',//是否静默消息
|
disturb: chatListInfo.disturb ? chatListInfo.disturb : 'N', //是否静默消息
|
||||||
top:chatListInfo.top ? chatListInfo.top : 'N',//是否置顶
|
top: chatListInfo.top ? chatListInfo.top : 'N', //是否置顶
|
||||||
userType:'GROUP'
|
userType: 'GROUP'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//离线消息体 自己的消息
|
//离线消息体 自己的消息
|
||||||
@@ -634,7 +656,7 @@ export default {
|
|||||||
content: msgContent,
|
content: msgContent,
|
||||||
time: time,
|
time: time,
|
||||||
type: 2,
|
type: 2,
|
||||||
msgId:'local',
|
msgId: 'local',
|
||||||
windowType: windowType
|
windowType: windowType
|
||||||
};
|
};
|
||||||
//离线/发送失败错误消息体
|
//离线/发送失败错误消息体
|
||||||
@@ -646,6 +668,40 @@ export default {
|
|||||||
type: 3
|
type: 3
|
||||||
};
|
};
|
||||||
var msgSendType = 'wating';
|
var msgSendType = 'wating';
|
||||||
|
|
||||||
|
//开始发送消息
|
||||||
|
store.dispatch('sendMsg', {
|
||||||
|
userId: userId,
|
||||||
|
data: msgOnlie
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// 发送完成之后设置消息状态
|
||||||
|
|
||||||
|
// msgSendType = 'error';
|
||||||
|
msgOffline.sendtype = msgSendType;
|
||||||
|
msgOffline.msgId = "1231"
|
||||||
|
msgNotSend.content = msgOnlie.content;
|
||||||
|
msgList.content = msgOnlie.content;
|
||||||
|
|
||||||
|
chatWindowData.push(msgOffline);
|
||||||
|
if (msgSendType == 'error') {
|
||||||
|
chatWindowData.push(msgNotSend);
|
||||||
|
}
|
||||||
|
store.dispatch('updateChatById', {
|
||||||
|
userId: userId,
|
||||||
|
data: chatWindowData
|
||||||
|
});
|
||||||
|
store.dispatch('updateChatListInfoById', {
|
||||||
|
userId: userId,
|
||||||
|
data: msgList
|
||||||
|
});
|
||||||
|
store.dispatch('tabBarpull');
|
||||||
|
store.dispatch('updateChatDataState', userId);
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
http.request({
|
http.request({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -655,7 +711,7 @@ export default {
|
|||||||
if (res.data.data.status !== '0') {
|
if (res.data.data.status !== '0') {
|
||||||
msgSendType = 'error';
|
msgSendType = 'error';
|
||||||
msgOffline.sendtype = msgSendType;
|
msgOffline.sendtype = msgSendType;
|
||||||
msgOffline.msgId=res.data.data.msgId
|
msgOffline.msgId = res.data.data.msgId
|
||||||
msgNotSend.content = res.data.data.statusLabel;
|
msgNotSend.content = res.data.data.statusLabel;
|
||||||
msgList.content = res.data.data.statusLabel;
|
msgList.content = res.data.data.statusLabel;
|
||||||
} else {
|
} else {
|
||||||
@@ -679,7 +735,7 @@ export default {
|
|||||||
data: msgList
|
data: msgList
|
||||||
});
|
});
|
||||||
store.dispatch('tabBarpull');
|
store.dispatch('tabBarpull');
|
||||||
store.dispatch('updateChatDataState',userId);
|
store.dispatch('updateChatDataState', userId);
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
msgSendType = 'error';
|
msgSendType = 'error';
|
||||||
@@ -696,7 +752,7 @@ export default {
|
|||||||
data: msgList
|
data: msgList
|
||||||
});
|
});
|
||||||
store.dispatch('tabBarpull');
|
store.dispatch('tabBarpull');
|
||||||
store.dispatch('updateChatDataState',userId);
|
store.dispatch('updateChatDataState', userId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -890,24 +946,24 @@ export default {
|
|||||||
}
|
}
|
||||||
return sortlist
|
return sortlist
|
||||||
},
|
},
|
||||||
saoyisao(){//扫一扫
|
saoyisao() { //扫一扫
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
success: (res)=> {
|
success: (res) => {
|
||||||
var result=res.result
|
var result = res.result
|
||||||
var data=res.result.split(':')
|
var data = res.result.split(':')
|
||||||
var type=data[0]
|
var type = data[0]
|
||||||
var value=data[1]
|
var value = data[1]
|
||||||
switch (type){
|
switch (type) {
|
||||||
case 'group':
|
case 'group':
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:'../../wx/groupInfo/scanCodeDetail?param='+result
|
url: '../../wx/groupInfo/scanCodeDetail?param=' + result
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case 'user':
|
case 'user':
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:'../../wx/personInfo/detail?param='+value+'&source=1'
|
url: '../../wx/personInfo/detail?param=' + value + '&source=1'
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -917,13 +973,13 @@ export default {
|
|||||||
// #endif
|
// #endif
|
||||||
// #ifndef APP-PLUS
|
// #ifndef APP-PLUS
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title:'扫一扫',
|
title: '扫一扫',
|
||||||
icon:'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
// 设置原生titleNView导航文字
|
// 设置原生titleNView导航文字
|
||||||
setTitleNViewBtns(index,text){
|
setTitleNViewBtns(index, text) {
|
||||||
let pages = getCurrentPages();
|
let pages = getCurrentPages();
|
||||||
let page = pages[pages.length - 1];
|
let page = pages[pages.length - 1];
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
@@ -938,7 +994,7 @@ export default {
|
|||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
debounce(func, wait = 1000, immediate = true){
|
debounce(func, wait = 1000, immediate = true) {
|
||||||
/**
|
/**
|
||||||
* @desc 函数防抖
|
* @desc 函数防抖
|
||||||
* @param func 目标函数
|
* @param func 目标函数
|
||||||
@@ -957,7 +1013,7 @@ export default {
|
|||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
timer = null;
|
timer = null;
|
||||||
}, wait);
|
}, wait);
|
||||||
if (callNow){
|
if (callNow) {
|
||||||
func.apply(this, args);
|
func.apply(this, args);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -967,7 +1023,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
throttle (func, wait = 1000, type = 1) {
|
throttle(func, wait = 1000, type = 1) {
|
||||||
/**
|
/**
|
||||||
* @desc 函数节流
|
* @desc 函数节流
|
||||||
* @param func 函数
|
* @param func 函数
|
||||||
@@ -981,7 +1037,7 @@ export default {
|
|||||||
let args = arguments;
|
let args = arguments;
|
||||||
if (type === 1) {
|
if (type === 1) {
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
|
|
||||||
if (now - previous > wait) {
|
if (now - previous > wait) {
|
||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
previous = now;
|
previous = now;
|
||||||
@@ -996,4 +1052,4 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import config from "@/common/config.js"
|
import config from "@/common/config.js"
|
||||||
let timer = null
|
let timer = null
|
||||||
let retimer = null
|
let retimer = null
|
||||||
|
import store from '../store'
|
||||||
|
|
||||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||||
|
|
||||||
@@ -30,15 +30,35 @@ export default {
|
|||||||
},
|
},
|
||||||
onTestMessage: (e) => {
|
onTestMessage: (e) => {
|
||||||
console.log("onTestMessage :" + e);
|
console.log("onTestMessage :" + e);
|
||||||
|
store.dispatch('onP2PMessage',e)
|
||||||
},
|
},
|
||||||
onP2PMessage: (e) => {
|
onP2PMessage: (e) => {
|
||||||
console.log("onP2PMessage :" + e);
|
console.log("onP2PMessage :" + e);
|
||||||
e = JSON.parse(e)
|
e = JSON.parse(e)
|
||||||
e.pushType="TEXT"
|
e.data.pushType="MSG"
|
||||||
|
e.data.msgContent={
|
||||||
|
msgType:"UNKOWN",
|
||||||
|
content:e.data.messageBody,
|
||||||
|
disturb:false,
|
||||||
|
top:false,
|
||||||
|
}
|
||||||
|
|
||||||
|
e.data.windowType="SINGLE"
|
||||||
|
e.data.createTime=e.data.messageTime;
|
||||||
|
e.data.fromInfo={
|
||||||
|
userId:e.data.fromId
|
||||||
|
};
|
||||||
|
e.data.groupInfo={};
|
||||||
|
e.data.msgId=e.data.messageId;
|
||||||
|
|
||||||
|
debugger
|
||||||
uni.$emit('onP2PMessage', e.data);
|
uni.$emit('onP2PMessage', e.data);
|
||||||
|
store.dispatch('onP2PMessage',e.data)
|
||||||
},
|
},
|
||||||
onLogin: (uid) => {
|
onLogin: (uid) => {
|
||||||
console.log("用户" + uid + "登陆sdk成功");
|
console.log("用户" + uid + "登陆sdk成功");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -54,6 +74,7 @@ export default {
|
|||||||
|
|
||||||
console.log(lim)
|
console.log(lim)
|
||||||
|
|
||||||
|
// 防止多次建立ws链接,貌似还没有生效,需要检查
|
||||||
if (this.socketTask != null) {
|
if (this.socketTask != null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name" : "微聊",
|
"name" : "IM",
|
||||||
"appid" : "__UNI__CA19A2D",
|
"appid" : "__UNI__1A208D0",
|
||||||
"description" : "考拉Team微聊",
|
"description" : "HS-IM",
|
||||||
"versionName" : "1.2.1",
|
"versionName" : "1.2.1",
|
||||||
"versionCode" : 121,
|
"versionCode" : 121,
|
||||||
"developer" : {
|
"developer" : {
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ const store = new Vuex.Store({
|
|||||||
|
|
||||||
|
|
||||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||||
|
|
||||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||||
|
|
||||||
|
const _im=lim.lim.im
|
||||||
|
|
||||||
// #ifdef VUE3
|
// #ifdef VUE3
|
||||||
import { createStore } from 'vuex'
|
import { createStore } from 'vuex'
|
||||||
const store = createStore({
|
const store = createStore({
|
||||||
@@ -52,6 +53,21 @@ import { createStore } from 'vuex'
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
onP2PMessage(context,data){
|
||||||
|
console.log("========================store 收到信息")
|
||||||
|
console.log("========================store 收到信息")
|
||||||
|
console.log("========================store 收到信息")
|
||||||
|
console.error(data)
|
||||||
|
publicFc.getPush(data)
|
||||||
|
|
||||||
|
},
|
||||||
|
sendMsg(context,data){
|
||||||
|
console.log("========================")
|
||||||
|
console.log("========================")
|
||||||
|
console.log("========================")
|
||||||
|
console.error(data)
|
||||||
|
_im.sendP2PMessage(_im.createP2PTextMessage(data.userId,data.data.content))
|
||||||
|
},
|
||||||
updateChatDataState(context,data){
|
updateChatDataState(context,data){
|
||||||
context.state.chatDataState++
|
context.state.chatDataState++
|
||||||
context.state.chatDataUserId=data
|
context.state.chatDataUserId=data
|
||||||
@@ -118,15 +134,19 @@ import { createStore } from 'vuex'
|
|||||||
context.commit('update_ChatList',data)
|
context.commit('update_ChatList',data)
|
||||||
},
|
},
|
||||||
updateChatListInfoById(context,data) {//修改聊天记录
|
updateChatListInfoById(context,data) {//修改聊天记录
|
||||||
|
console.log("修改聊天记录 2")
|
||||||
var getKey=data.userId
|
var getKey=data.userId
|
||||||
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||||
retdata[getKey]=data.data
|
retdata[getKey]=data.data
|
||||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(retdata));
|
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(retdata));
|
||||||
},
|
},
|
||||||
createChatObj(context,data){
|
createChatObj(context,data){
|
||||||
|
console.log("修改聊天记录 3")
|
||||||
|
console.log("context.state.userInfo.userId:",context.state.userInfo.userId)
|
||||||
|
console.log("data.userId:",data.userId)
|
||||||
var userId=data.userId
|
var userId=data.userId
|
||||||
var windowType=data.windowType
|
var windowType=data.windowType
|
||||||
|
debugger
|
||||||
//初始化聊天记录
|
//初始化聊天记录
|
||||||
var data2=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
var data2=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||||
if(!data2[userId]){
|
if(!data2[userId]){
|
||||||
@@ -145,7 +165,7 @@ import { createStore } from 'vuex'
|
|||||||
// console.warn(res)
|
// console.warn(res)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
lim.lim.im.getSingleUserInfo(userId).then((res)=>{
|
_im.getSingleUserInfo(userId).then((res)=>{
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
@@ -155,7 +175,7 @@ import { createStore } from 'vuex'
|
|||||||
data1[userId]={
|
data1[userId]={
|
||||||
fromInfo:{
|
fromInfo:{
|
||||||
nickName: detail.nickName,
|
nickName: detail.nickName,
|
||||||
portrait: detail.portrait,
|
portrait: detail.photo,
|
||||||
userId: detail.userId,
|
userId: detail.userId,
|
||||||
userType:detail.userType
|
userType:detail.userType
|
||||||
},
|
},
|
||||||
@@ -169,7 +189,7 @@ import { createStore } from 'vuex'
|
|||||||
userId: detail.userId,
|
userId: detail.userId,
|
||||||
personId: context.state.userInfo.userId,
|
personId: context.state.userInfo.userId,
|
||||||
nickName: detail.nickName,
|
nickName: detail.nickName,
|
||||||
portrait: detail.portrait,
|
portrait: detail.photo,
|
||||||
content: '',
|
content: '',
|
||||||
time: publicFc.getNewDate('format',true),
|
time: publicFc.getNewDate('format',true),
|
||||||
num: 0,
|
num: 0,
|
||||||
|
|||||||
@@ -174,7 +174,7 @@
|
|||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
|
|
||||||
// // 监听接收聊天信息
|
// // 监听接收聊天信息
|
||||||
uni.$on('onP2PMessage', this.onMessage)
|
// uni.$on('onP2PMessage', this.onMessage)
|
||||||
|
|
||||||
this.talkTo = e;
|
this.talkTo = e;
|
||||||
// 根据Id
|
// 根据Id
|
||||||
@@ -263,28 +263,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
console.log('[聊天页] 监听接收聊天信息', message);
|
|
||||||
if (message.fromId != this.talkTo.userId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('[聊天页] 监听接收聊天信息', message);
|
|
||||||
|
|
||||||
this.$fc.getPush(data);
|
|
||||||
|
|
||||||
// var messageBody = message
|
|
||||||
|
|
||||||
// let msg = {
|
|
||||||
// userId: message.fromId,
|
|
||||||
// avatar: "/static/images/userpic.png",
|
|
||||||
// data: messageBody.messageBody == '' ? '空消息' : messageBody.messageBody,
|
|
||||||
// nickname: message.fromId,
|
|
||||||
// type: "text",
|
|
||||||
// createTime: message.messageTime / 1000,
|
|
||||||
// isRemove: false
|
|
||||||
// }
|
|
||||||
// this.list.push(msg)
|
|
||||||
|
|
||||||
},
|
},
|
||||||
addMsg(e) {
|
addMsg(e) {
|
||||||
this.msg += e;
|
this.msg += e;
|
||||||
|
|||||||
@@ -35,26 +35,26 @@
|
|||||||
var list=[
|
var list=[
|
||||||
{
|
{
|
||||||
name:"测试18200702230",
|
name:"测试18200702230",
|
||||||
avatar:"item.portrait",
|
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||||
userId:"18200702230",
|
userId:"18200702230",
|
||||||
userType:"item.userType",
|
userType:"item.userType",
|
||||||
chatNo:"item.chatNo"
|
chatNo:"item.chatNo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"测试18200000000",
|
name:"测试18200000000",
|
||||||
avatar:"item.portrait",
|
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||||
userId:"18200000000",
|
userId:"18200000000",
|
||||||
userType:"item.userType",
|
userType:"item.userType",
|
||||||
chatNo:"item.chatNo"
|
chatNo:"item.chatNo"
|
||||||
},{
|
},{
|
||||||
name:"测试18200000001",
|
name:"测试18200000001",
|
||||||
avatar:"item.portrait",
|
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||||
userId:"18200000001",
|
userId:"18200000001",
|
||||||
userType:"item.userType",
|
userType:"item.userType",
|
||||||
chatNo:"item.chatNo"
|
chatNo:"item.chatNo"
|
||||||
},{
|
},{
|
||||||
name:"测试lld3",
|
name:"测试lld3",
|
||||||
avatar:"item.portrait",
|
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||||
userId:"lld3",
|
userId:"lld3",
|
||||||
userType:"item.userType",
|
userType:"item.userType",
|
||||||
chatNo:"item.chatNo"
|
chatNo:"item.chatNo"
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ export class ImClient {
|
|||||||
let bodyLen = byteBuffer[1];//解析bodylen
|
let bodyLen = byteBuffer[1];//解析bodylen
|
||||||
let unpack = bytebuf.vstring(null, bodyLen).unpack();//解析出字符串
|
let unpack = bytebuf.vstring(null, bodyLen).unpack();//解析出字符串
|
||||||
let msgBody = unpack[2];
|
let msgBody = unpack[2];
|
||||||
|
console.log("sdk收到服务端数据 command:" + command)
|
||||||
console.log("sdk收到服务端数据:" + msgBody)
|
console.log("sdk收到服务端数据:" + msgBody)
|
||||||
|
|
||||||
if (command === MessageCommand.MSG_P2P) {
|
if (command === MessageCommand.MSG_P2P) {
|
||||||
|
|||||||
Reference in New Issue
Block a user