index.js
5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Action 提交的是 mutation,而不是直接变更状态。
// Action 可以包含任意异步操作。
import cookie from '../../utils/cookie'
import pageUtil from '../../utils/page'
/* 导出actions方法 */
import {showLoading, hideLoading, showFullscreenImg, hideFullscreenImg} from './widgetUi'
import {initNimSDK} from './initNimSDK'
import {initChatroomSDK, resetChatroomSDK} from './initChatroomSDK'
import {updateBlack} from './blacks'
import {updateFriend, addFriend, deleteFriend} from './friends'
import {resetSearchResult, searchUsers, searchTeam} from './search'
import {deleteSession, setCurrSession, resetCurrSession} from './session'
import {sendMsg, sendFileMsg, sendMsgReceipt, sendRobotMsg, revocateMsg, getHistoryMsgs, resetNoMoreHistoryMsgs, continueRobotMsg} from './msgs'
import {markSysMsgRead, resetSysMsgs, deleteSysMsgs, markCustomSysMsgRead} from './sysMsgs'
import {sendChatroomMsg, sendChatroomRobotMsg, sendChatroomFileMsg, getChatroomHistoryMsgs} from './chatroomMsgs'
import {initChatroomInfos, getChatroomInfo, getChatroomMembers, clearChatroomMembers} from './chatroomInfos'
import {delegateTeamFunction, onTeamNotificationMsg, enterSettingPage, getTeamMembers} from './team'
function connectNim ({state, commit, dispatch}, obj) {
if(window.location.href.indexOf('?') != -1){
cookie.setCookie('userHref',window.location.href);
let session = window.location.href.substring(window.location.href.indexOf('?')+1);
/*if(session.indexOf('&') == -1){
let imId = window.location.href.substring(window.location.href.indexOf('?')+6);
console.log('location是',window.location.href)
console.log('action中的imId',imId)
cookie.setCookie('uid', imId);
cookie.setCookie('sdktoken', imId);
setTimeout(function(){
location.href = window.location.href.substring(0,window.location.href.indexOf('#'))+'#/contacts';//如果地址的参数只有一个,说明没有传sessionId,就跳转到聊天列表页
},200);
}else */if(session.indexOf('&') != -1){
let imId = window.location.href.substring(window.location.href.indexOf('?')+6,window.location.href.indexOf('&'));
cookie.setCookie('uid', imId);
cookie.setCookie('sdktoken', imId);
let sessionId = window.location.href.substring(window.location.href.indexOf('&')+11);
/*location.href = window.location.href.substring(0,window.location.href.indexOf('&'));*/
/*setTimeout(function(){
location.href = window.location.href.substring(0,window.location.href.indexOf('#'))+'#/chat/'+sessionId + "?" + imId + "&" + sessionId;//如果地址的参数有两个,说明传了sessionId,就跳转到聊天窗口
},1000);*/
}
}
let {force} = Object.assign({}, obj);
// 操作为内容页刷新页面,此时无nim实例
if (!state.nim || force) {
let loginInfo = {
uid: cookie.readCookie('uid'),
sdktoken: cookie.readCookie('sdktoken'),
};
if (!loginInfo.uid) {
// 无cookie,直接跳转登录页
pageUtil.turnPage('无历史登录记录,请重新登录', 'login')
} else {
// 有cookie,重新登录
dispatch('initNimSDK', loginInfo)
}
}
}
function connectChatroom ({state, commit, dispatch}, obj) {
let {chatroomId} = Object.assign({}, obj)
const nim = state.nim
if (nim) {
dispatch('showLoading')
nim.getChatroomAddress({
chatroomId,
done: function getChatroomAddressDone (error, obj) {
if (error) {
alert(error.message)
location.href = '#/room'
return
}
dispatch('initChatroomSDK', obj)
}
})
}
}
export default {
updateRefreshState ({commit}) {
commit('updateRefreshState')
},
// UI 及页面状态变更
showLoading,
hideLoading,
showFullscreenImg,
hideFullscreenImg,
continueRobotMsg,
// 连接sdk请求,false表示强制重连
connect (store, obj) {
let {type} = Object.assign({}, obj)
// type 可为 nim chatroom
type = type || 'nim'
switch (type) {
case 'nim':
connectNim(store, obj)
break
case 'chatroom':
connectChatroom(store, obj)
break
}
},
// 用户触发的登出逻辑
logout ({ state, commit }) {
cookie.delCookie('uid')
cookie.delCookie('sdktoken')
if (state.nim) {
state.nim.disconnect()
}
pageUtil.turnPage('', 'login')
},
// 初始化 重新连接SDK
initNimSDK,
// 清空所有搜索历史纪录
resetSearchResult,
// 搜索用户信息
searchUsers,
// 更新黑名单
updateBlack,
// 更新好友
addFriend,
deleteFriend,
updateFriend,
// 删除会话
deleteSession,
// 设置当前会话
setCurrSession,
// 重置当前会话
resetCurrSession,
// 发送消息
sendMsg,
sendFileMsg,
sendRobotMsg,
// 发送消息已读回执
sendMsgReceipt,
// 消息撤回
revocateMsg,
getHistoryMsgs,
// 重置历史消息状态
resetNoMoreHistoryMsgs,
// 标记系统消息已读
markSysMsgRead,
markCustomSysMsgRead,
resetSysMsgs,
deleteSysMsgs,
initChatroomSDK,
initChatroomInfos,
resetChatroomSDK,
sendChatroomMsg,
sendChatroomRobotMsg,
sendChatroomFileMsg,
getChatroomHistoryMsgs,
getChatroomInfo,
getChatroomMembers,
clearChatroomMembers,
// 搜索群
searchTeam,
// 代理sdk中的群方法
delegateTeamFunction,
// 处理群消息回调
onTeamNotificationMsg,
// 进入群信息设置页
enterSettingPage,
// 获取群成员
getTeamMembers
}