xujing 5 years ago
parent
commit
0d30ebba24
5 changed files with 34 additions and 7 deletions
  1. 5
    0
      config/dev.js
  2. 3
    2
      src/components/Notice/index.js
  3. 4
    2
      src/pages/im/index.js
  4. 14
    2
      src/pages/im/list/index.js
  5. 8
    1
      src/reducers/user.js

+ 5
- 0
config/dev.js View File

9
     WSS_HOST: '"wss://dev.jinchengjiaye.com"',
9
     WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10
     // HOST: '"https://lt.pawoma.cn"',
10
     // HOST: '"https://lt.pawoma.cn"',
11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
12
+<<<<<<< HEAD
12
     // HOST: '"http://192.168.2.52:8080"',
13
     // HOST: '"http://192.168.2.52:8080"',
13
     // WSS_HOST: '"ws://192.168.2.52:8080"',
14
     // WSS_HOST: '"ws://192.168.2.52:8080"',
15
+=======
16
+    HOST: '"http://192.168.2.52:8080"',
17
+    WSS_HOST: '"ws://192.168.2.52:8080"',
18
+>>>>>>> 6d2db04a857d72bc8504b0f061c8baf8a3c98aba
14
   },
19
   },
15
   weapp: {},
20
   weapp: {},
16
   h5: {}
21
   h5: {}

+ 3
- 2
src/components/Notice/index.js View File

10
   }
10
   }
11
 
11
 
12
   handleClick() {
12
   handleClick() {
13
-    const { dispatch } = getStore()
14
-    dispatch({ type: DECREASE_UNREADNUM })
13
+    // toFix #5922
14
+    // const { dispatch } = getStore()
15
+    // dispatch({ type: DECREASE_UNREADNUM })
15
     Taro.navigateTo({
16
     Taro.navigateTo({
16
       url: '/pages/im/list/index'
17
       url: '/pages/im/list/index'
17
     })
18
     })

+ 4
- 2
src/pages/im/index.js View File

183
       const chattingName = res.name || chatting.nickname
183
       const chattingName = res.name || chatting.nickname
184
 
184
 
185
       // 发送 卡片 消息
185
       // 发送 卡片 消息
186
-      socket.sendNotice({
186
+      const payload = {
187
         sendPerson: chatting.personId,
187
         sendPerson: chatting.personId,
188
         receivePerson: me.personId,
188
         receivePerson: me.personId,
189
         message: `您好,我是${chattingName},有什么可以帮助您的吗?您可以在这里跟我实时沟通哦~`,
189
         message: `您好,我是${chattingName},有什么可以帮助您的吗?您可以在这里跟我实时沟通哦~`,
190
         messageType: MESSAGETYPE.CARD,
190
         messageType: MESSAGETYPE.CARD,
191
         createDate: new Date().valueOf(),
191
         createDate: new Date().valueOf(),
192
-      }, res => {
192
+      }
193
+
194
+      socket.sendNotice(payload, res => {
193
         console.log('发送成功')
195
         console.log('发送成功')
194
         this.appendData(payload)
196
         this.appendData(payload)
195
       })
197
       })

+ 14
- 2
src/pages/im/list/index.js View File

6
 import EmptyPage from '@components/empty-page'
6
 import EmptyPage from '@components/empty-page'
7
 import Item from './item'
7
 import Item from './item'
8
 import ready from '@utils/ready'
8
 import ready from '@utils/ready'
9
-import { connect } from '@tarojs/redux'
9
+
10
+import { DECREASE_UNREADNUM } from '@constants/user'
11
+import { getStore, connect } from '@tarojs/redux'
12
+
10
 @connect(state => state.user)
13
 @connect(state => state.user)
11
 export default class Index extends Component {
14
 export default class Index extends Component {
12
   config = {
15
   config = {
61
     })
64
     })
62
   }
65
   }
63
 
66
 
67
+  handleItemClick = ({ unReadNum }) => {
68
+    if (unReadNum > 0) {
69
+      const { dispatch } = getStore()
70
+      dispatch({ type: DECREASE_UNREADNUM, payload: unReadNum })
71
+    }
72
+
73
+    return this.toChat.bind(this);
74
+  }
75
+
64
   render() {
76
   render() {
65
     const { list } = this.state
77
     const { list } = this.state
66
     return (
78
     return (
73
           height: getWindowHeight()
85
           height: getWindowHeight()
74
         }}>
86
         }}>
75
 
87
 
76
-        {(loaded && list.length === 0) ? <EmptyPage text="暂无好友哦~" /> : list.map(item => <Item key={item.sendPerson} data={item} onClick={this.toChat.bind(this)} />)}
88
+        {(loaded && list.length === 0) ? <EmptyPage text="暂无好友哦~" /> : list.map(item => <Item key={item.sendPerson} data={item} onClick={this.handleItemClick(item)} />)}
77
 
89
 
78
         {/* <Loadmore nodata={!list.length} loading={loading} loadend={loadend}></Loadmore> */}
90
         {/* <Loadmore nodata={!list.length} loading={loading} loadend={loadend}></Loadmore> */}
79
       </ScrollView>
91
       </ScrollView>

+ 8
- 1
src/reducers/user.js View File

87
       }
87
       }
88
     }
88
     }
89
     case DECREASE_UNREADNUM: {
89
     case DECREASE_UNREADNUM: {
90
+      let { unReadNum } = state
91
+      unReadNum = unReadNum - action.payload
92
+
93
+      if (unReadNum < 0) {
94
+        unReadNum = 0
95
+      }
96
+
90
       return {
97
       return {
91
         ...state,
98
         ...state,
92
-        unReadNum: 0
99
+        unReadNum,
93
       }
100
       }
94
     }
101
     }
95
     default:
102
     default: