diff --git a/README.md b/README.md index 2f202c9a..a2548db7 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,6 @@ server { access_log on; } } -``` \ No newline at end of file +``` + +非专业前端开发,项目中若有不足的地方,请多多指教。 \ No newline at end of file diff --git a/src/components/chat/TalkEditorPanel.vue b/src/components/chat/TalkEditorPanel.vue index 6b515a00..217e8e08 100644 --- a/src/components/chat/TalkEditorPanel.vue +++ b/src/components/chat/TalkEditorPanel.vue @@ -976,11 +976,11 @@ //修改群聊免打扰状态 disturbChange(detail) { - let key = this.$store.state.talkItems.items.findIndex(item => item.index_name == `2_${this.params.receiveId}`); + let key = this.$store.state.talks.items.findIndex(item => item.index_name == `2_${this.params.receiveId}`); if (key == -0) return false; this.$store.commit({ - type: "updateItem", + type: "UPDATE_TALK_ITEM", key: key, item: { not_disturb: parseInt(detail.status) diff --git a/src/components/user/UserCard.vue b/src/components/user/UserCard.vue index e141d2c2..05d94505 100644 --- a/src/components/user/UserCard.vue +++ b/src/components/user/UserCard.vue @@ -110,7 +110,7 @@ }, methods: { logout() { - this.$store.dispatch("logout", this.$router); + this.$store.dispatch("ACT_USER_LOGOUT", this.$router); }, user() { findUserDetailServ().then(res => { diff --git a/src/components/user/UserSetup.vue b/src/components/user/UserSetup.vue index 21046603..a7b0aaf6 100644 --- a/src/components/user/UserSetup.vue +++ b/src/components/user/UserSetup.vue @@ -90,7 +90,7 @@ }).then((res) => { if (res.code == 200) { that.buttonText = '修改完成'; - that.$store.dispatch('setAvatar', that.userInfo.avatar); + that.$store.dispatch('dispatch("ACT_USER_UPDATE_AVATAR"', that.userInfo.avatar); } else { that.buttonText = '修改失败,请稍后再试 ...'; } diff --git a/src/plugins/socket/event/talk-event.js b/src/plugins/socket/event/talk-event.js index b4567679..da47cb76 100644 --- a/src/plugins/socket/event/talk-event.js +++ b/src/plugins/socket/event/talk-event.js @@ -57,7 +57,7 @@ class TalkEvent extends AppMessageEvent { this.vm.$store.commit('setScrollHeight'); this.vm.$store.commit({ - type: 'updateItem', + type: 'UPDATE_TALK_ITEM', key: idx, item: { msg_text: this.getTalkText(), @@ -80,12 +80,12 @@ class TalkEvent extends AppMessageEvent { updateTalkItem(idx) { this.vm.$store.commit('incrUnreadNum'); if (idx == -1) { - this.vm.$store.commit('setHeavyLoad', true); + this.vm.$store.commit('TRIGGER_TALK_ITEMS_LOAD', true); return; } this.vm.$store.commit({ - type: 'updateUnreadInfo', + type: 'UPDATE_TALK_MESSAGE', key: idx, item: { msg_text: this.getTalkText(), @@ -125,7 +125,7 @@ class TalkEvent extends AppMessageEvent { * @param {string} index_name */ getIndex(index_name) { - return this.vm.$store.state.talkItems.items.findIndex(item => item.index_name == index_name); + return this.vm.$store.state.talks.items.findIndex(item => item.index_name == index_name); } /** diff --git a/src/store/index.js b/src/store/index.js index 6181bea7..356ac1e3 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import Vuex from 'vuex'; import user from './modules/user'; -import talkItems from './modules/talkItems'; +import talks from './modules/talk'; import notify from './modules/notify'; import states from './states'; import getters from './getters'; @@ -12,12 +12,12 @@ Vue.use(Vuex); const store = new Vuex.Store({ modules: { user, - talkItems, - notify + notify, + talks }, // 根级别的 state - state:states, + state: states, getters, diff --git a/src/store/modules/talkItems.js b/src/store/modules/talk.js similarity index 63% rename from src/store/modules/talkItems.js rename to src/store/modules/talk.js index c35d21ce..ea738a0a 100644 --- a/src/store/modules/talkItems.js +++ b/src/store/modules/talk.js @@ -1,5 +1,6 @@ const talkItems = { state: { + //用户对话列表 items: [], @@ -7,20 +8,21 @@ const talkItems = { heavyLoad: false, }, mutations: { - //设置对话列表 - setItems(state, payload) { + + // 设置对话列表 + SET_TALK_ITEM(state, payload) { state.items = payload.items; }, - //更新对话信息 - updateItem(state, payload) { + // 更新对话节点 + UPDATE_TALK_ITEM(state, payload) { if (state.items[payload.key]) { state.items[payload.key] = Object.assign(state.items[payload.key], payload.item) } }, - //移除聊天对话 - removeItem(state, index_name) { + // 移除对话节点 + REMOVE_TALK_ITEM(state, index_name) { for (let i in state.items) { if (state.items[i].index_name === index_name) { state.items.splice(i, 1); @@ -29,34 +31,31 @@ const talkItems = { } }, - //清空消息未读数据 - clearUnreadNum(state, index) { - state.items[index].unread_num = 0; + // 更新对话节点在线状态 + UPDATE_TALK_ONLINE_STATUS(state, data) { + if (!state.items[data.key]) return false; + + state.items[data.key].online = parseInt(data.status); }, - //更新未读信息 - updateUnreadInfo(state, payload) { + // 更新对话消息 + UPDATE_TALK_MESSAGE(state, payload) { if (!state.items[payload.key]) return false; - state.items[payload.key].msg_text = payload.item.msg_text.replace(/<\/?.+?>/g,"") || '[表情]'; + state.items[payload.key].msg_text = payload.item.msg_text.replace(/<\/?.+?>/g, "") || '[表情]'; state.items[payload.key].unread_num++; state.items[payload.key].updated_at = payload.item.updated_at; }, - //更新用户在线状态 - updateOnlineStatus(state, data) { - if (!state.items[data.key]) return false; - - state.items[data.key].online = parseInt(data.status); + // 清空对话的未读数 + CLEAR_TLAK_UNREAD_NUM(state, index) { + state.items[index].unread_num = 0; }, - //设置对话列表重载状态 - setHeavyLoad(state, status = false) { + // 触发对话列表重新加载 + TRIGGER_TALK_ITEMS_LOAD(state, status = false) { state.heavyLoad = status; } - }, - actions: { - } } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 9c8d16dc..3e99ab25 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -51,7 +51,7 @@ const user = { }, actions: { //设置头像信息 - setAvatar({ + ACT_USER_UPDATE_AVATAR({ commit, state }, avatar) { @@ -62,18 +62,17 @@ const user = { }, //用户登录处理 - login({ + ACT_USER_LOGIN({ commit, state }, user) { setToken(user.authInfo.access_token, user.authInfo.expires_in); - setUserInfo(user.userInfo); commit('login', user.userInfo); }, //退出登录处理操作 - logout({ + ACT_USER_LOGOUT({ commit, state }, $router) { diff --git a/src/utils/auth.js b/src/utils/auth.js index a1176742..aafa2dd4 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -1,8 +1,8 @@ import Cookies from 'js-cookie'; import JsBase64 from 'js-base64'; -const TokenKey = 'On-LineIM-TOKEN'; -const UserKey = 'On-LineIM-USERINFO'; +const TokenKey = 'LUMNEIM-TOKEN'; +const UserKey = 'LUMNEIM-USERINFO'; // 设置授权token export function setToken(token, expires) { diff --git a/src/views/MessagePage.vue b/src/views/MessagePage.vue index d7d24491..a1b461ce 100644 --- a/src/views/MessagePage.vue +++ b/src/views/MessagePage.vue @@ -16,12 +16,12 @@ -
暂时没有新的消息 +
暂时没有新的消息
-
+
{ if (res.code == 200) { this.$store.commit({ - type: "setItems", + type: "SET_TALK_ITEM", items: res.data.map(item => packTalkItem(item)) }); @@ -251,7 +251,7 @@ //根据用户对话索引获取对话数组对应的key getIndex(index_name) { - return this.$store.state.talkItems.items.findIndex( + return this.$store.state.talks.items.findIndex( item => item.index_name == index_name ); }, @@ -262,7 +262,7 @@ if (idx == -1) return; - let item = this.$store.state.talkItems.items[idx]; + let item = this.$store.state.talks.items[idx]; let [source, receive_id] = index_name.split("_"); this.index_name = item.index_name; this.params = { @@ -275,7 +275,7 @@ this.$nextTick(function () { if (index_name == this.$root.message.index_name) { //清空对话的未读数 - this.$store.commit("clearUnreadNum", idx); + this.$store.commit("CLEAR_TLAK_UNREAD_NUM", idx); //清空消息未读数(后期改成websocket发送消息) clearChatUnreadNumServ({ @@ -383,7 +383,7 @@ }).then(res => { if (res.code == 200) { this.$store.commit({ - type: "updateItem", + type: "UPDATE_TALK_ITEM", key: this.getIndex(item.index_name), item: { not_disturb: item.not_disturb == 0 ? 1 : 0 @@ -398,7 +398,7 @@ list_id: item.id }).then(res => { if (res.code == 200) { - this.$store.commit("removeItem", item.index_name); + this.$store.commit("REMOVE_TALK_ITEM", item.index_name); } }); }, diff --git a/src/views/NewMessagePage.vue b/src/views/NewMessagePage.vue index fad1af84..00f607e4 100644 --- a/src/views/NewMessagePage.vue +++ b/src/views/NewMessagePage.vue @@ -34,7 +34,7 @@ -
@@ -51,11 +51,11 @@ -
@@ -198,7 +198,7 @@ computed: { // 计算置顶数量 topNum() { - return this.$store.state.talkItems.items.filter((item) => { + return this.$store.state.talks.items.filter((item) => { return item.is_top == 1; }).length; }, @@ -206,8 +206,8 @@ // 置顶栏目的高度 subHeaderPx() { let num = this.topNum, - len = 65; - let n = 6; // 一排能显示的用户数 + len = 65, + n = 6; // 一排能显示的用户数 if (num > n) { let y = (num % n) > 0 ? 1 : 0; @@ -218,10 +218,10 @@ }, reloadDialogues() { - return this.$store.state.talkItems.heavyLoad; + return this.$store.state.talks.heavyLoad; }, unreadNum() { - return this.$store.state.talkItems.items.reduce(function (total, item) { + return this.$store.state.talks.items.reduce(function (total, item) { return total + parseInt(item.unread_num); }, 0); }, @@ -234,7 +234,7 @@ isFriendOnline() { let i = this.getIndex(this.index_name); if (i == -1) return 0; - return this.$store.state.talkItems.items[i].online == 1; + return this.$store.state.talks.items[i].online == 1; } }, watch: { @@ -249,7 +249,7 @@ if (key == -1) return; this.$store.commit({ - type: "updateOnlineStatus", + type: "UPDATE_TALK_ONLINE_STATUS", key, status }); @@ -264,7 +264,7 @@ reloadDialogues(n, o) { if (n) { this.loadChatList(); - this.$store.commit("setHeavyLoad", false); + this.$store.commit("TRIGGER_TALK_ITEMS_LOAD", false); } } }, @@ -358,14 +358,14 @@ // 获取用户对话列表 loadChatList() { - if (this.$store.state.talkItems.items.length == 0) { + if (this.$store.state.talks.items.length == 0) { this.dataStatus = 0; } chatListsServ().then(res => { if (res.code == 200) { this.$store.commit({ - type: "setItems", + type: "SET_TALK_ITEM", items: res.data.map(item => packTalkItem(item)) }); @@ -396,7 +396,7 @@ // 根据用户对话索引获取对话数组对应的key getIndex(index_name) { - return this.$store.state.talkItems.items.findIndex( + return this.$store.state.talks.items.findIndex( item => item.index_name == index_name ); }, @@ -407,7 +407,7 @@ if (idx == -1) return; - let item = this.$store.state.talkItems.items[idx]; + let item = this.$store.state.talks.items[idx]; let [source, receive_id] = index_name.split("_"); this.index_name = item.index_name; this.params = { @@ -421,7 +421,7 @@ this.$nextTick(function () { if (index_name == this.$root.message.index_name) { //清空对话的未读数 - this.$store.commit("clearUnreadNum", idx); + this.$store.commit("CLEAR_TLAK_UNREAD_NUM", idx); //清空消息未读数(后期改成websocket发送消息) clearChatUnreadNumServ({ @@ -516,7 +516,7 @@ }).then(res => { if (res.code == 200) { this.$store.commit({ - type: "updateItem", + type: "UPDATE_TALK_ITEM", key: this.getIndex(item.index_name), item: { is_top: item.is_top == 0 ? 1 : 0 @@ -535,7 +535,7 @@ }).then(res => { if (res.code == 200) { this.$store.commit({ - type: "updateItem", + type: "UPDATE_TALK_ITEM", key: this.getIndex(item.index_name), item: { not_disturb: item.not_disturb == 0 ? 1 : 0 @@ -551,7 +551,7 @@ list_id: item.id }).then(res => { if (res.code == 200) { - this.$store.commit("removeItem", item.index_name); + this.$store.commit("REMOVE_TALK_ITEM", item.index_name); } }); }, @@ -565,9 +565,8 @@ if (this.index_name == item.index_name) { this.index_name = null; } - this.loadChatList(); - } else { - alert('解除好友失败...'); + + this.$store.commit('REMOVE_TALK_ITEM', item.index_name); } }); }, @@ -582,9 +581,7 @@ this.index_name = null; } - this.loadChatList(); - } else { - alert('退出群聊失败...'); + this.$store.commit('REMOVE_TALK_ITEM', item.index_name); } }); } diff --git a/src/views/auth/NewLogin.vue b/src/views/auth/NewLogin.vue index ea48e74d..8292ae83 100644 --- a/src/views/auth/NewLogin.vue +++ b/src/views/auth/NewLogin.vue @@ -120,7 +120,7 @@ }).then(res => { this.loginLoading = false; if (res.code == 200) { - this.$store.dispatch("login", { + this.$store.dispatch("ACT_USER_LOGIN", { authInfo: { access_token: res.data.access_token, expires_in: res.data.expires_in diff --git a/src/views/layout/MainLayout.vue b/src/views/layout/MainLayout.vue index d313c0c6..2849f75b 100644 --- a/src/views/layout/MainLayout.vue +++ b/src/views/layout/MainLayout.vue @@ -2,7 +2,7 @@
- + @@ -14,25 +14,32 @@
- + @@ -94,15 +101,7 @@ } }, methods: { - //菜单链接跳转 - toLink(i) { - let links = ["/message", "/friends", "/notes", '/schedule']; - if (this.idx !== i) { - this.$router.push({ - path: links[i] - }); - } - }, + // 播放消息提示音 play() { this.lastRunTime = Date.now(); let audio = document.querySelector("#audio"); @@ -114,6 +113,7 @@ this.stop(timeOut); }, 1000); }, + // 停止消息提示音 stop(timeOut) { this.currentTime = Date.now(); let audio = document.querySelector("#audio"); @@ -127,7 +127,7 @@ clearTimeout(timeOut); }, logout() { - this.$store.dispatch("logout", this.$router); + this.$store.dispatch("ACT_USER_LOGOUT", this.$router); } } };