Browse Source

Merge branch 'main' of http://git.ycjcjy.com/marketing/miniapp into main

1002884655 3 years ago
parent
commit
a6235a8f83
4 changed files with 18 additions and 14 deletions
  1. 14
    5
      src/components/ChatIcon/index.jsx
  2. 2
    0
      src/constants/api.js
  3. 2
    2
      src/pages/index/index.jsx
  4. 0
    7
      src/utils/login.js

+ 14
- 5
src/components/ChatIcon/index.jsx View File

1
 import { useEffect, useState } from 'react'
1
 import { useEffect, useState } from 'react'
2
+import classNames from 'classnames'
2
 import Taro from '@tarojs/taro'
3
 import Taro from '@tarojs/taro'
3
 import { MovableArea, MovableView } from '@tarojs/components'
4
 import { MovableArea, MovableView } from '@tarojs/components'
4
 import { showSubscribeMessage, MESSAGE_TYPE } from '@/utils/subscribeMessage'
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
 import './style.scss'
9
 import './style.scss'
6
 
10
 
7
 export default function ChatIcon(props) {
11
 export default function ChatIcon(props) {
8
 
12
 
13
+  const [unReadNum, setUnReadNum] = useState(0)
9
   const [PageX] = useState(Taro.getSystemInfoSync().windowWidth - 60)
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
   const handleClick = () => {
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
   return (
27
   return (
19
-    <MovableArea className='components ChatIcon'>
28
+    <MovableArea className='components ChatIcon' onClick={handleClick}>
20
       <MovableView className='MoveItem' x={PageX} y={PageY} direction='all'>
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
       </MovableView>
31
       </MovableView>
23
     </MovableArea>
32
     </MovableArea>
24
   )
33
   )

+ 2
- 0
src/constants/api.js View File

72
 export const API_CHAT_FRIENDS = resolvePath('chat/with')
72
 export const API_CHAT_FRIENDS = resolvePath('chat/with')
73
 export const API_UPLOAD_IMAGE = resolvePath('image')
73
 export const API_UPLOAD_IMAGE = resolvePath('image')
74
 export const API_CHAT_READED = resolvePath('chat/message')
74
 export const API_CHAT_READED = resolvePath('chat/message')
75
+export const API_CHAT_UNREADED = resolvePath('chat/unReaded')
76
+
75
 
77
 
76
 // card
78
 // card
77
 export const API_CARDS_LIST = resolvePath('cards')
79
 export const API_CARDS_LIST = resolvePath('cards')

+ 2
- 2
src/pages/index/index.jsx View File

65
 
65
 
66
   return (
66
   return (
67
     <view className='Page Index'>
67
     <view className='Page Index'>
68
-      <ChatIcon></ChatIcon>
69
-      {/* <ShareToCircle visible></ShareToCircle> */}
68
+      <ChatIcon />
69
+
70
       <ScrollView scroll-y>
70
       <ScrollView scroll-y>
71
         <view className='PageContent'>
71
         <view className='PageContent'>
72
 
72
 

+ 0
- 7
src/utils/login.js View File

35
       // 获取人员详细信息
35
       // 获取人员详细信息
36
       // eslint-disable-next-line no-unused-vars
36
       // eslint-disable-next-line no-unused-vars
37
       queryUserInfo().then(info => {
37
       queryUserInfo().then(info => {
38
-        // const { unReadNum } = info
39
-
40
-        // 默认红点开始就有
41
-        dispatch({ type: ASSIGN_UNREADNUM, payload: true });
42
         resolve(data)
38
         resolve(data)
43
       }).catch(reject)
39
       }).catch(reject)
44
 
40
 
51
           }
47
           }
52
         })
48
         })
53
       }
49
       }
54
-
55
-      // 如果通过扫码进入
56
-
57
     }).catch(reject)
50
     }).catch(reject)
58
   
51
   
59
   })
52
   })