|
@@ -1,24 +1,33 @@
|
1
|
1
|
import { useEffect, useState } from 'react'
|
|
2
|
+import classNames from 'classnames'
|
2
|
3
|
import Taro from '@tarojs/taro'
|
3
|
4
|
import { MovableArea, MovableView } from '@tarojs/components'
|
4
|
5
|
import { showSubscribeMessage, MESSAGE_TYPE } from '@/utils/subscribeMessage'
|
|
6
|
+import { API_CHAT_UNREADED } from '@/constants/api'
|
|
7
|
+import { fetch } from '@/utils/request'
|
|
8
|
+import useInterval from '@/utils/hooks/useInterval'
|
5
|
9
|
import './style.scss'
|
6
|
10
|
|
7
|
11
|
export default function ChatIcon(props) {
|
8
|
12
|
|
|
13
|
+ const [unReadNum, setUnReadNum] = useState(0)
|
9
|
14
|
const [PageX] = useState(Taro.getSystemInfoSync().windowWidth - 60)
|
10
|
|
- const [PageY] = useState(Taro.getSystemInfoSync().windowHeight - 60)
|
|
15
|
+ const [PageY] = useState(Taro.getSystemInfoSync().windowHeight - 160)
|
11
|
16
|
|
12
|
17
|
const handleClick = () => {
|
13
|
|
- showSubscribeMessage(MESSAGE_TYPE.NOTICE).then((res) => {
|
14
|
|
- //
|
|
18
|
+ showSubscribeMessage(MESSAGE_TYPE.NOTICE).then(() => {
|
|
19
|
+ Taro.switchTab({ url: '/pages/chat/index' })
|
15
|
20
|
})
|
16
|
21
|
}
|
17
|
22
|
|
|
23
|
+ useInterval(() =>{
|
|
24
|
+ fetch({url: API_CHAT_UNREADED, showToast: false}).then(x => setUnReadNum(x || 0))
|
|
25
|
+ }, 30000, true)
|
|
26
|
+
|
18
|
27
|
return (
|
19
|
|
- <MovableArea className='components ChatIcon'>
|
|
28
|
+ <MovableArea className='components ChatIcon' onClick={handleClick}>
|
20
|
29
|
<MovableView className='MoveItem' x={PageX} y={PageY} direction='all'>
|
21
|
|
- <text className='iconfont icon-xiaoxi centerLabel active'></text>
|
|
30
|
+ <text className={classNames('iconfont icon-xiaoxi centerLabel', { active: unReadNum > 0 })}></text>
|
22
|
31
|
</MovableView>
|
23
|
32
|
</MovableArea>
|
24
|
33
|
)
|