66 getContentByMsgId ,
77 hasRead ,
88 removeReaded ,
9- restoreTrash
9+ restoreTrash ,
10+ getUnreadCount
1011} from '@/api/user'
1112import { setToken , getToken } from '@/libs/util'
1213
@@ -18,6 +19,7 @@ export default {
1819 token : getToken ( ) ,
1920 access : '' ,
2021 hasGetInfo : false ,
22+ unreadCount : 0 ,
2123 messageUnreadList : [ ] ,
2224 messageReadedList : [ ] ,
2325 messageTrashList : [ ] ,
@@ -43,6 +45,9 @@ export default {
4345 setHasGetInfo ( state , status ) {
4446 state . hasGetInfo = status
4547 } ,
48+ setMessageCount ( state , count ) {
49+ state . unreadCount = count
50+ } ,
4651 setMessageUnreadList ( state , list ) {
4752 state . messageUnreadList = list
4853 } ,
@@ -120,6 +125,13 @@ export default {
120125 }
121126 } )
122127 } ,
128+ // 此方法用来获取未读消息条数,接口只返回数值,不返回消息列表
129+ getUnreadMessageCount ( { state, commit } ) {
130+ getUnreadCount ( ) . then ( res => {
131+ const { data } = res
132+ commit ( 'setMessageCount' , data )
133+ } )
134+ } ,
123135 // 获取消息列表,其中包含未读、已读、回收站三个列表
124136 getMessageList ( { state, commit } ) {
125137 return new Promise ( ( resolve , reject ) => {
@@ -156,14 +168,15 @@ export default {
156168 } )
157169 } ,
158170 // 把一个未读消息标记为已读
159- hasRead ( { commit } , { msg_id } ) {
171+ hasRead ( { state , commit } , { msg_id } ) {
160172 return new Promise ( ( resolve , reject ) => {
161173 hasRead ( msg_id ) . then ( ( ) => {
162174 commit ( 'moveMsg' , {
163175 from : 'messageUnreadList' ,
164176 to : 'messageReadedList' ,
165177 msg_id
166178 } )
179+ commit ( 'setMessageCount' , state . unreadCount - 1 )
167180 resolve ( )
168181 } ) . catch ( error => {
169182 reject ( error )
0 commit comments