Pārlūkot izejas kodu

设置会话已读

baichun 5 gadi atpakaļ
vecāks
revīzija
4ee6d28907

+ 8 - 1
_src/components/panel/sessionItem.vue

@@ -29,7 +29,7 @@
 </template>
 
 <script>
-import { mapState } from 'vuex'
+import { mapState, mapMutations } from 'vuex'
 import API from '@/api'
 import { confirmPopup } from '@/util/util'
 
@@ -54,6 +54,7 @@ export default {
   },
   computed: {
     ...mapState(['curSession', 'userId']),
+    ...mapMutations(['setSessionItemUnread']),
     userInfo () {
       return this.$store.state.userInfo
     }
@@ -62,6 +63,12 @@ export default {
     changeSessionId (item) {
       let path = item.is_group == 1 ? `/group/${item.session_id}` : `/pm/${item.session_id}`
       this.$router.push({ path })
+
+      this.$store.commit('setSessionItemUnread', {
+        session_id: item.session_id,
+        unread: 0,
+        curSession: this.curSession
+      })
     },
     bgColorNum (str) {
       if (str.match('-')) {

+ 0 - 5
_src/mixins/chat.js

@@ -107,11 +107,6 @@ export const chatMixin = {
       } else {
         this.initGroupChat()
       }
-      this.$store.commit('setSessionItemUnread', {
-        session_id: this.curSession,
-        unread: 0,
-        curSession: this.curSession
-      })
     },
     /**
      * @des 私聊初始化处理

+ 7 - 7
_src/store/module/chat.js

@@ -31,18 +31,18 @@ const mutations = {
   },
   setSessionItemUnread (state, data) {
     console.log('进来寻找session', data.unread, data, data.cont)
-    state.sessionList.forEach((item, index) => {
+    state.sessionList.forEach((item) => {
       if (item.session_id == `${data.session_id}`) {
-        if (!data.unread) {
-          item.unread = 0
-        } else if (data.curSession != data.session_id) {
-          item.unread += data.unread
+        let unread = item.unread
+        if (data.unread && data.curSession != data.session_id) {
+          unread += data.unread
         } else {
-          item.unread = 0
+          unread = 0
         }
 
+        Vue.set(item, 'unread', unread)
         Vue.set(item, 'cont', data.cont ? data.cont : item.cont)
-        objSession.setUnread(item.session_id, item.unread)
+        objSession.setUnread(item.session_id, unread)
       }
     })
   },