张延森 3 years ago
parent
commit
3aeefd347d

+ 9
- 1
src/components/Auth/AuthAvatar.jsx View File

@@ -6,6 +6,8 @@ import useAuth from './useAuth'
6 6
 import './style.scss'
7 7
 
8 8
 export default (props) => {
9
+  const { onCancel = (x => x) } = props;
10
+
9 11
   const [loading, setLoading] = useState(false)
10 12
   const { updateUserInfo } = useAuth()
11 13
 
@@ -30,7 +32,13 @@ export default (props) => {
30 32
   }
31 33
 
32 34
   return (
33
-    <AuthBox title='授权头像' openType='getUserInfo' loading={loading} onGetUserInfo={handleUserProfile}>
35
+    <AuthBox
36
+      title='授权头像'
37
+      openType='getUserInfo'
38
+      loading={loading}
39
+      onGetUserInfo={handleUserProfile}
40
+      onCancel={onCancel}
41
+    >
34 42
       <View className='auth-avatar'>
35 43
         <OpenData type='userAvatarUrl' />
36 44
       </View>

+ 2
- 2
src/components/Auth/AuthBox.jsx View File

@@ -4,7 +4,7 @@ import { View, Button } from '@tarojs/components'
4 4
 import './style.scss'
5 5
 
6 6
 export default (props) => {
7
-  const { loading, title, openType, onGetUserInfo, onGetPhoneNumber } = props
7
+  const { loading, title, openType, onGetUserInfo, onGetPhoneNumber, onCancel = (x => x) } = props
8 8
 
9 9
   const handleGetUserInfo = () => {
10 10
     Taro.getUserProfile({
@@ -30,7 +30,7 @@ export default (props) => {
30 30
         {props.children}
31 31
       </View>
32 32
       <View className='auth-footer'>
33
-        <Button className='auth-btn' type='default' plain>取消</Button>
33
+        <Button className='auth-btn' type='default' plain onClick={onCancel}>取消</Button>
34 34
         {
35 35
           openType === 'getUserInfo' ? (
36 36
             <Button

+ 10
- 0
src/components/Auth/AuthPage.jsx View File

@@ -0,0 +1,10 @@
1
+import React from 'react'
2
+import './style.scss'
3
+
4
+export default (props) => {
5
+  return (
6
+    <View>
7
+
8
+    </View>
9
+  )
10
+}

+ 9
- 1
src/components/Auth/AuthPhone.jsx View File

@@ -6,6 +6,8 @@ import useAuth from './useAuth'
6 6
 import './style.scss'
7 7
 
8 8
 export default (props) => {
9
+  const { onCancel = (x => x) } = props;
10
+
9 11
   const [loading, setLoading] = useState(false)
10 12
   const { updatePhoneNumber } = useAuth()
11 13
 
@@ -30,7 +32,13 @@ export default (props) => {
30 32
   }
31 33
 
32 34
   return (
33
-    <AuthBox title='授权手机' openType='getPhoneNumber' loading={loading} onGetPhoneNumber={handlePhoneNumber}>
35
+    <AuthBox
36
+      title='授权手机'
37
+      openType='getPhoneNumber'
38
+      loading={loading}
39
+      onGetPhoneNumber={handlePhoneNumber}
40
+      onCancel={onCancel}
41
+    >
34 42
       <View>请确认授权手机号,以便为您提供更优质的服务内容。</View>
35 43
     </AuthBox>
36 44
   )

+ 46
- 2
src/components/Auth/style.scss View File

@@ -33,7 +33,7 @@
33 33
     display: inline-block;
34 34
     font-size: 30rpx;
35 35
     background: #193C83;
36
-    border-radius: 39px;
36
+    border-radius: 39rpx;
37 37
     color: #fff;
38 38
     width: 236rpx;
39 39
     height: 78rpx;
@@ -42,4 +42,48 @@
42 42
       margin-left: 80rpx;
43 43
     }
44 44
   }
45
-}
45
+}
46
+
47
+.auth-page {
48
+  width: 100vw;
49
+  height: 100vw;
50
+  position: fixed;
51
+  z-index: 2000;
52
+  left: 0;
53
+  top: 0;
54
+  background: #fff;
55
+  display: flex;
56
+  padding: 40rpx 30rpx;
57
+  box-sizing: border-box;
58
+
59
+  .auth-header {
60
+    flex: none;
61
+    margin-top: 78rpx;
62
+
63
+    .auth-logo {
64
+      width: 128rpx;
65
+      margin: 0 auto;
66
+    }
67
+  }
68
+
69
+  .auth-body {
70
+    flex: auto;
71
+    margin-top: 195rpx;
72
+
73
+    .auth-btn {
74
+      width: 100%;
75
+      height: 92rpx;
76
+      background: #193C83;
77
+      border-radius: 44px;
78
+    }
79
+  }
80
+
81
+  .auth-footer {
82
+    flex: none;
83
+    height: 321rpx;
84
+    background: #F8F8F8;
85
+    border-radius: 8rpx;
86
+    box-sizing: border-box;
87
+    padding: 32rpx 40rpx;
88
+  }
89
+}

+ 21
- 7
src/utils/im/sdk.js View File

@@ -56,26 +56,26 @@ export default function IMSDK() {
56 56
         ...paramsRef.current,
57 57
         fail: (err) => reject(err),
58 58
       }).then((task) => {
59
-        console.log('[WS][connect]', task)
59
+        console.log(`[${now()}]`, '[WS] [connect]', task)
60 60
         instanceRef.current = task
61 61
   
62 62
         task.onOpen(function () {
63
-          console.log('[WS][onOpen]', paramsRef.current)
63
+          console.log(`[${now()}]`, '[WS] [onOpen]', paramsRef.current)
64 64
           resolve()
65 65
         })
66 66
 
67 67
         task.onMessage(function (msg) {
68
-          console.info('[WS][onMessage]', msg)
68
+          console.info(`[${now()}]`, '[WS] [onMessage]', msg)
69 69
           instanceRef.onMessage().forEach((f) => f(msg))
70 70
         })
71 71
 
72 72
         task.onError(function (error) {
73
-          console.error('[WS][onError]', error)
73
+          console.error(`[${now()}]`, '[WS] [onError]', error)
74 74
           instanceRef.onError().forEach((f) => f(error))
75 75
         })
76 76
 
77 77
         task.onClose(function (res) {
78
-          console.warn('[WS][onClose]', res)
78
+          console.warn(`[${now()}]`, '[WS] [onClose]', res)
79 79
           instanceRef.onClose().forEach((f) => f(res))
80 80
         })
81 81
       })
@@ -83,14 +83,14 @@ export default function IMSDK() {
83 83
   }
84 84
 
85 85
   function send(data) {
86
-    console.log('[WS][SEND]', data)
86
+    console.log(`[${now()}]`, '[WS] [SEND]', data)
87 87
     return new Promise((resovle, reject) => {
88 88
       if (instanceRef.current) {
89 89
         instanceRef.current.send({
90 90
           data,
91 91
           success: resovle,
92 92
           fail: (err) => {
93
-            console.error('[WS][SEND]', err)
93
+            console.error(`[${now()}]`, '[WS] [SEND]', err)
94 94
             reject(err)
95 95
           },
96 96
         })
@@ -99,4 +99,18 @@ export default function IMSDK() {
99 99
       }
100 100
     })
101 101
   }
102
+
103
+  function now() {
104
+    const dt = new Date()
105
+    const year = dt.getFullYear()
106
+    const month = dt.getMonth() + 1
107
+    const day = dt.getDate()
108
+    const hour = dt.getHours()
109
+    const minutes = dt.getMinutes()
110
+    const seconds = dt.getSeconds()
111
+
112
+    const formate = n => n >= 10 ? n : `0${n}`
113
+
114
+    return `${year}-${formate(month)}-${formate(day)} ${formate(hour)}:${formate(minutes)}:${formate(seconds)}`
115
+  }
102 116
 }