liujq 3 年之前
父节点
当前提交
46dfb7b684
共有 5 个文件被更改,包括 61 次插入7 次删除
  1. 5 0
      src/components/footer/index.js
  2. 1 1
      src/pagesMore/center/index.jsx
  3. 35 2
      src/pagesQa/msg/chat.jsx
  4. 14 4
      src/pagesQa/msg/index.jsx
  5. 6 0
      src/pagesQa/msg/message.jsx

+ 5 - 0
src/components/footer/index.js

@@ -38,6 +38,10 @@ export default class Footer extends Component {
         Taro.removeStorageSync('APP_needUsername')
       })
     }
+    this.getFooterNotifycount()
+  }
+
+  getFooterNotifycount = () => {
     Taro.api.other.notifycount().then(res => {
       const notify = res.count || ''
       const { getNotify } = this.props
@@ -56,6 +60,7 @@ export default class Footer extends Component {
         })
       } else {
         let { tabList } = this.state
+        tabList[4].text = ''
         const newsDot = Taro.getStorageSync('APP_newsDot')
         if (newsDot) {
           tabList[2].dot = true

+ 1 - 1
src/pagesMore/center/index.jsx

@@ -333,7 +333,7 @@ class Index extends Component {
         <LoginPopup show={isLoginPopupShow} close={this.closeLoginPopup.bind(this)} />
         {this.renderHeader()}
         {this.renderEntry()}
-        <Footer current={4} getNotify={this.getNotify.bind(this)} />
+        <Footer current={4} getNotify={this.getNotify.bind(this)} ref="refComFooter" />
       </View>
     )
   }

+ 35 - 2
src/pagesQa/msg/chat.jsx

@@ -23,13 +23,26 @@ class Index extends Component {
       uObj: {},
       chatUserObj: {},
       viewId: '',
+      socketTimer: null
     }
   }
 
   config = {
-    navigationBarTitleText: '在线聊天',
+    navigationBarTitleText: '在线沟通',
   }
 
+  componentWillUnmount () {
+    let pages = getCurrentPages()
+    let prevPage = pages[ pages.length - 2 ]
+    prevPage.$component.getNotifycount()
+    this.closeSocket()
+  }
+
+  closeSocket () {
+    Taro.closeSocket()
+    const { socketTimer } = this.state
+    clearInterval(socketTimer)
+  }
 
   componentDidMount () {
     const that = this
@@ -130,9 +143,12 @@ class Index extends Component {
         // const { to_user_id } = that.$router.params
         let token = Taro.getStorageSync('APP_token')
         task.send({ data: '{"seq":"' + that.sendId() + '","cmd":"login","data":{"userId":"' + uObj.user_id + '","appId":101,"serviceToken":"' + token + '"}}' })
-        setInterval(() => {
+        const socketTimer = setInterval(() => {
           task.send({data: '{"seq":"' + that.sendId() + '","cmd":"heartbeat","data":{}}'});
         }, 30000)
+        that.setState({
+          socketTimer
+        })
       })
       task.onMessage(function (msg) {
         // console.log('onMessage: ', msg)
@@ -158,6 +174,23 @@ class Index extends Component {
             })
           }
         }
+        if (data.cmd === 'heartbeat') {
+          const res = data.response || {}
+          if (res.code !== 200) {
+            msgSocketList.push({msg: res.codeMsg + '|暂无法接收消息,请退出当前页面重新登录~'})
+          }
+          that.setState({
+            msgSocketList
+          }, () => {
+            setTimeout(() => {
+              that.setState({
+                viewId: `item${msgSocketList.length - 1}`
+              }, () => {
+                that.closeSocket()
+              })
+            }, 100)
+          })
+        }
         // task.close()
       })
       task.onError(function () {

+ 14 - 4
src/pagesQa/msg/index.jsx

@@ -26,9 +26,23 @@ class Index extends Component {
     navigationBarTitleText: '我的消息',
   }
 
+  componentWillUnmount () {
+    let pages = getCurrentPages()
+    let prevPage = pages[ pages.length - 2 ]
+    prevPage.$component.refs.refComFooter.getFooterNotifycount()
+  }
+
   componentWillMount () {
     Taro.$AHU(this)
     this.getDataList()
+    this.getNotifycount()
+  }
+
+  componentDidShow () { }
+
+  componentDidHide () { }
+
+  getNotifycount = () => {
     Taro.api.other.notifycount().then(res => {
       const countObj = res || {}
       this.setState({
@@ -37,10 +51,6 @@ class Index extends Component {
     })
   }
 
-  componentDidShow () { }
-
-  componentDidHide () { }
-
   getDataList () {
     let { page_size, page, dataList, isListEmpty } = this.state
     Taro.api.room.apiuserdialoglist({

+ 6 - 0
src/pagesQa/msg/message.jsx

@@ -23,6 +23,12 @@ class Index extends Component {
     navigationBarTitleText: '我的消息',
   }
 
+  componentWillUnmount () {
+    let pages = getCurrentPages()
+    let prevPage = pages[ pages.length - 2 ]
+    prevPage.$component.getNotifycount()
+  }
+
   componentWillMount () {
     Taro.$AHU(this)
     this.getDataList()