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 @@
-