-
\ No newline at end of file
+
diff --git a/src/router/index.js b/src/router/index.js
index 2d2bf80..d6aedd4 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,33 +1,33 @@
-import Vue from 'vue'
-import VueRouter from 'vue-router'
+import Vue from "vue";
+import VueRouter from "vue-router";
-import Login from '../pages/LoginPage'
-import Chatting from '../pages/ChattingPage'
+import Login from "../pages/LoginPage";
+import Chatting from "../pages/ChattingPage";
-Vue.use(VueRouter)
+Vue.use(VueRouter);
const routes = [
{
- path: '/',
- name: 'login',
+ path: "/",
+ name: "login",
component: Login,
},
{
- path: '/chatting',
- name: 'chatting',
+ path: "/chatting",
+ name: "chatting",
component: Chatting,
beforeEnter: (to, from, next) => {
if (window.sessionStorage.getItem("user") == null) {
next({
- path: '/',
- })
+ path: "/",
+ });
} else {
- next()
+ next();
}
},
},
-]
+];
export default new VueRouter({
- routes
-})
\ No newline at end of file
+ routes,
+});
diff --git a/src/service/request.js b/src/service/request.js
index 3db56c9..fa5766f 100644
--- a/src/service/request.js
+++ b/src/service/request.js
@@ -1,12 +1,12 @@
-import axios from 'axios'
-import { baseUrl } from '@/config/env'
+import axios from "axios";
+import { baseUrl } from "@/config/env";
function get(url, params, data) {
- return request('get', url, params, data)
+ return request("get", url, params, data);
}
function post(url, params, data) {
- return request('post', url, params, data)
+ return request("post", url, params, data);
}
function request(method, url, params, data) {
@@ -15,11 +15,8 @@ function request(method, url, params, data) {
url: baseUrl + url,
params,
data,
- responseType: 'json',
- })
+ responseType: "json",
+ });
}
-export {
- get,
- post,
-}
\ No newline at end of file
+export { get, post };
diff --git a/src/store/index.js b/src/store/index.js
index 1196364..2427d19 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -1,16 +1,12 @@
-import { socket } from '@/utils/socket'
-import Vue from 'vue'
-import Vuex from 'vuex'
+import { socket } from "@/utils/socket";
+import Vue from "vue";
+import Vuex from "vuex";
-Vue.use(Vuex)
+Vue.use(Vuex);
-const actions = {
+const actions = {};
-}
-
-const mutations = {
-
-}
+const mutations = {};
const state = {
messages: {},
@@ -24,7 +20,7 @@ const state = {
socket: socket,
toId: -1,
isGroup: false,
-}
+};
const getters = {
getApplications: (state) => (isGroup, isRequest) => {
@@ -52,11 +48,11 @@ const getters = {
return state.joinGroups;
}
}
- }
-}
+ },
+};
export default new Vuex.Store({
actions,
mutations,
state,
getters,
-})
\ No newline at end of file
+});
diff --git a/src/utils/date.js b/src/utils/date.js
index 11670c5..8237c04 100644
--- a/src/utils/date.js
+++ b/src/utils/date.js
@@ -1,12 +1,12 @@
-import dayjs from 'dayjs';
+import dayjs from "dayjs";
export default {
getCurrentTime: () => {
- return dayjs().add(8, 'h').format('YYYY-MM-DD HH:mm:ss');
+ return dayjs().add(8, "h").format("YYYY-MM-DD HH:mm:ss");
},
convertTime: (time) => {
- return dayjs(time).add(-8, 'h').format('YYYY-MM-DD HH:mm:ss');
+ return dayjs(time).add(-8, "h").format("YYYY-MM-DD HH:mm:ss");
},
wrapSendTime: (time) => {
- return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
- }
-}
\ No newline at end of file
+ return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
+ },
+};
diff --git a/src/utils/socket.js b/src/utils/socket.js
index 11d17ad..52374fb 100644
--- a/src/utils/socket.js
+++ b/src/utils/socket.js
@@ -4,85 +4,81 @@ let socket = {
ws_url: null,
ws_port: 3333,
-
+
init: (hostname) => {
- socket.ws_url = `ws://${hostname}:${socket.ws_port}/ws`
+ socket.ws_url = `ws://${hostname}:${socket.ws_port}/ws`;
if (!window.WebSocket) {
window.WebSocket = window.MozWebSocket;
}
-
- socket.ws = new WebSocket(socket.ws_url)
+
+ socket.ws = new WebSocket(socket.ws_url);
socket.ws.onmessage = (e) => {
- socket.receive(e)
- }
-
+ socket.receive(e);
+ };
+
// 连接关闭
socket.ws.onclose = () => {
- console.log('ws连接已断开')
- }
-
+ console.log("ws连接已断开");
+ };
+
// 连接成功
socket.ws.onopen = () => {
- console.log('ws连接成功')
- }
+ console.log("ws连接成功");
+ };
// 连接错误
socket.ws.onerror = () => {
- console.log('ws连接发生错误')
- }
+ console.log("ws连接发生错误");
+ };
},
-
/**
* 发送消息
*/
send: (data, callback = null) => {
// 开启状态直接发送
if (socket.ws.readyState === socket.ws.OPEN) {
- socket.ws.send(JSON.stringify(data))
+ socket.ws.send(JSON.stringify(data));
if (callback) {
- callback()
+ callback();
}
- // 正在开启状态,则等待1s后重新调用
+ // 正在开启状态,则等待1s后重新调用
} else if (socket.ws.readyState === socket.ws.CONNECTING) {
setTimeout(function () {
- socket.send(data, callback)
- }, 1000)
-
- // 未开启,则等待1s后重新调用
+ socket.send(data, callback);
+ }, 1000);
+
+ // 未开启,则等待1s后重新调用
} else {
- socket.init()
+ socket.init();
setTimeout(function () {
- socket.send(data, callback)
- }, 1000)
+ socket.send(data, callback);
+ }, 1000);
}
},
-
+
receive: (message) => {
- JSON.parse(message.data)
+ JSON.parse(message.data);
},
-
/**
* 主动关闭连接
*/
close: () => {
- console.log('主动断开连接')
- socket.ws.close()
+ console.log("主动断开连接");
+ socket.ws.close();
},
-
+
/**
* 重新连接
*/
reconnect: () => {
- console.log('重新发起ws连接')
+ console.log("重新发起ws连接");
if (socket.ws) {
- socket.close()
+ socket.close();
}
- socket.init()
+ socket.init();
},
-}
+};
-export {
- socket
-}
\ No newline at end of file
+export { socket };