Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
gzydong committed Jan 12, 2021
1 parent ee26dfc commit 7b9a5b5
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/assets/css/talk/panel-record.less
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
background: #efeaea;
}

img {
border-radius: 3px;
.el-image {
border-radius: 5px;
}
}

Expand Down
56 changes: 39 additions & 17 deletions src/main-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import {
getToken
} from '@/utils/auth';

// 加载配置文件
import config from '@/config/config'
// 加载配置信息
import config from '@/config/config';

// 全局引入自定义的WebSocket 插件
// 全局引入自定义的 WebSocket 插件
import WsSocket from '@/plugins/socket/ws-socket';

// 引入WebSocket消息处理类
import SocketResourceHandle from '@/plugins/socket/socket-resource-handle';
// 引入消息处理类
import TalkEvent from '@/plugins/socket/event/talk-event';
import RevokeEvent from '@/plugins/socket/event/revoke-event';
import LoginEvent from '@/plugins/socket/event/login-event';
import KeyboardEvent from '@/plugins/socket/event/keyboard-event';
import GroupJoinEvent from '@/plugins/socket/event/group-join-event';
import FriendApplyEvent from '@/plugins/socket/event/friend-apply-event';

export default {
data() {
Expand Down Expand Up @@ -46,9 +51,11 @@ export default {

// 连接websocket服务器
loadWebsocket() {
let store = this.$store;
this.socket = new WsSocket(config.ws_url, {
// Websocket 连接失败回调方法
const store = this.$store;
const url = `${config.ws_url}?token=` + getToken();

// 实例化
let socket = new WsSocket(url, {
onError: (evt) => {
console.log('Websocket 连接失败回调方法')
},
Expand All @@ -60,16 +67,31 @@ export default {
onClose: (evt) => {
store.commit('UPDATE_SOCKET_STATUS', false);
},
// Websocket 接收消息回调方法
onMessage(evt, event, data) {
new SocketResourceHandle({
event,
data
});
}
}, getToken);
});

// 绑定接收的事件
socket.on('event_talk', (data) => {
(new TalkEvent(data)).handle();
});
socket.on('event_online_status', (data) => {
(new LoginEvent(data)).handle();
});
socket.on('event_keyboard', (data) => {
(new KeyboardEvent(data)).handle();
});
socket.on('event_revoke_talk', (data) => {
(new RevokeEvent(data)).handle();
});
socket.on('event_friend_apply', (data) => {
(new FriendApplyEvent(data)).handle();
});
socket.on('join_group', (data) => {
(new GroupJoinEvent(data)).handle();
});

this.socket.initWebSocket();
// 连接服务
socket.connection();
this.socket = socket;
},

// 更新当前正在对话的用户数据
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '@/icons';

// 引入自定义全局css
import '@/assets/css/im-base.css';
import './global.less'; // 预留
import './global.less';

Vue.config.productionTip = false;

Expand Down
79 changes: 0 additions & 79 deletions src/plugins/socket/socket-resource-handle.js

This file was deleted.

Loading

0 comments on commit 7b9a5b5

Please sign in to comment.