Your Name 3 years ago
parent
commit
ef7d837679
6 changed files with 109 additions and 78 deletions
  1. 1
    1
      config/prod.js
  2. 38
    12
      src/app.jsx
  3. 19
    8
      src/layout/index.js
  4. 8
    7
      src/pages/index/index.jsx
  5. 1
    0
      src/routes.js
  6. 42
    50
      src/utils/login.js

+ 1
- 1
config/prod.js View File

@@ -10,7 +10,7 @@ module.exports = {
10 10
     OSS_PATH: '"https://xlk-assets.oss-accelerate.aliyuncs.com/"',
11 11
     OSS_FAST_PATH: '"https://xlk-assets.oss-accelerate.aliyuncs.com/"',
12 12
     ICON_FONT: '"https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/css/iconfont.ttf"',
13
-    Version: '"V0.0.27-20210808"'
13
+    Version: '"V0.0.28-20210808"'
14 14
   },
15 15
   mini: {},
16 16
   h5: {

+ 38
- 12
src/app.jsx View File

@@ -11,9 +11,10 @@ import './app.scss'
11 11
 
12 12
 class App extends Component {
13 13
   // 是否登录
14
-  logged;
14
+  logged = false;
15
+
15 16
   // 更新埋点
16
-  updateTracking;
17
+  updateTracking = () => undefined;
17 18
 
18 19
   componentDidMount () {}
19 20
 
@@ -46,6 +47,11 @@ class App extends Component {
46 47
   }
47 48
   
48 49
   onLaunch (options) {
50
+
51
+    console.log('【onLaunch】:', JSON.stringify(options))
52
+    const { mode } = options
53
+    Taro.setStorageSync('mode', mode)
54
+
49 55
     // 加载远程字体
50 56
     this.loadFontFace()
51 57
 
@@ -59,6 +65,7 @@ class App extends Component {
59 65
     getLocation().then((loc) => {
60 66
       getRouterParams(options).then(router => {
61 67
         Taro.setStorageSync('router', router)
68
+
62 69
         const { query: payload } = router
63 70
 
64 71
         payload.path = router.path
@@ -69,18 +76,37 @@ class App extends Component {
69 76
           payload.lat = loc.lat
70 77
         }
71 78
 
72
-        // login
73
-        login(payload).then((res) => {
74
-          const { person: { personId } } = res
75
-          
76
-          // 初始化 im
77
-          im.init(personId)
79
+        const { path, scene, ...params } = payload
78 80
 
79
-          this.logged = true
81
+        if (mode === 'singlePage') {
82
+          // 分享朋友圈的单页模式
83
+          params.singleMode = true
80 84
 
81
-          // 埋点
82
-          trackUserSource(options).then((x) => (this.updateTracking = x))
83
-        })
85
+          // login
86
+          login(params).then(() => {
87
+            this.logged = true
88
+          })
89
+        } else {
90
+          // 非单页模式
91
+          Taro.login({
92
+            success: ({ code }) => {
93
+              params.code = code
94
+
95
+              // login
96
+              login(params).then((res) => {
97
+                const { person: { personId } } = res
98
+                
99
+                // 初始化 im
100
+                im.init(personId)
101
+
102
+                this.logged = true
103
+
104
+                // 埋点
105
+                trackUserSource(options).then((x) => (this.updateTracking = x))
106
+              })
107
+            }
108
+          })
109
+        }
84 110
       })
85 111
     })
86 112
   }

+ 19
- 8
src/layout/index.js View File

@@ -21,6 +21,9 @@ import { routes } from '../routes'
21 21
 import './style.scss'
22 22
 
23 23
 export default (ChildComponent) => (props) => {
24
+  const mode = Taro.getStorageSync('mode')
25
+  const isSinglePage = mode === 'singlePage'
26
+
24 27
   const consultant = useSelector(s => s.system.consultant)
25 28
   const city = useSelector(s => s.city.curCity)
26 29
   const { spinning, userInfo } = useSelector(s => s.user)
@@ -31,6 +34,7 @@ export default (ChildComponent) => (props) => {
31 34
   const [authPhone, authAvatar, authPage] = useAuth(person, page)
32 35
   const [shareTimelineVisible, setShareTimelineVisible] = useState(false)
33 36
 
37
+
34 38
   const { id } = router.params
35 39
   const showConsultant = page.shortcut && page.shortcut.consultant
36 40
 
@@ -60,18 +64,24 @@ export default (ChildComponent) => (props) => {
60 64
 
61 65
   // 报备客户
62 66
   useEffect(() => {
67
+    if (isSinglePage) return;
68
+
63 69
     reportCustomer(person, consultant, false).catch(() => {})
64
-  }, [person, consultant])
70
+  }, [person, consultant, isSinglePage])
65 71
 
66 72
   // 请求埋点设置
67 73
   useEffect(() => {
74
+    if (isSinglePage) return;
75
+
68 76
     if (id) {
69 77
       setShareContent({})
70 78
     }
71
-  } ,[id, page.type])
79
+  } ,[id, page.type, isSinglePage])
72 80
 
73 81
   // 埋点数据
74 82
   useEffect(() => {
83
+    if (isSinglePage) return;
84
+
75 85
     const consultantId = person?.personType === ROLE_CODE.CONSULTANT ? person.personId : undefined
76 86
 
77 87
     setTrackData({
@@ -81,7 +91,7 @@ export default (ChildComponent) => (props) => {
81 91
       sharePersonId: person?.personId,
82 92
       targetId: id,
83 93
     })
84
-  }, [person, page, id])
94
+  }, [person, page, id, isSinglePage])
85 95
 
86 96
   // 主要用于埋点
87 97
   useEffect(() => {
@@ -101,24 +111,24 @@ export default (ChildComponent) => (props) => {
101 111
       </Overlay>
102 112
 
103 113
       {/* 授权手机 */}
104
-      <Overlay visible={authPhone} aligin='bottom'>
114
+      <Overlay visible={authPhone && !isSinglePage} aligin='bottom'>
105 115
         <View className='auth-wrapper'>
106 116
           <AuthPhone consultant={consultant} router={router} page={page} />
107 117
         </View>
108 118
       </Overlay>
109 119
 
110 120
       {/* 授权头像 */}
111
-      <Overlay visible={!authPhone && authAvatar} aligin='bottom'>
121
+      <Overlay visible={!authPhone && authAvatar && !isSinglePage} aligin='bottom'>
112 122
         <View className='auth-wrapper'>
113 123
           <AuthAvatar />
114 124
         </View>
115 125
       </Overlay>
116 126
 
117 127
       {/* 授权头像-全屏 */}
118
-      { authPage && <AuthPage /> }
128
+      { authPage && !isSinglePage && <AuthPage /> }
119 129
 
120 130
       {/* 显示分享朋友圈 */}
121
-      <ShareToCircle visible={shareTimelineVisible} onClose={() => setShareTimelineVisible(false)} />
131
+      <ShareToCircle visible={shareTimelineVisible && !isSinglePage} onClose={() => setShareTimelineVisible(false)} />
122 132
 
123 133
       {/* 页面内容 */}
124 134
       <Spin size={32} spinning={spinning} />
@@ -130,6 +140,7 @@ export default (ChildComponent) => (props) => {
130 140
             consultant={consultant}
131 141
             page={page}
132 142
             city={city}
143
+            mode={mode}
133 144
             shareContent={shareContent}
134 145
             trackData={trackData}
135 146
             showShareTimeline={showShareTimeline}
@@ -148,7 +159,7 @@ export default (ChildComponent) => (props) => {
148 159
       {/* 开屏广告 */}
149 160
       <FirstScreen
150 161
         info={screenInfo}
151
-        visible={screenVisible}
162
+        visible={screenVisible && !isSinglePage}
152 163
         onClick={handleScreen}
153 164
         onClose={toggleShowScreen}
154 165
       />

+ 8
- 7
src/pages/index/index.jsx View File

@@ -34,13 +34,6 @@ export default withLayout((props) => {
34 34
   // 分享
35 35
   useShare(shareContent, trackData)
36 36
 
37
-  useEffect(() => {
38
-    if (city?.id) {
39
-      GetBanner()
40
-      GetProjectList()
41
-    }
42
-  }, [city?.id])
43
-
44 37
   const GetBanner = () => { // 获取banner
45 38
     fetch({ url: `${API_BANNER_LIST}/banner`, method: 'get', payload: { cityId: city.id, showPosition: 'index' } }).then((res) => {
46 39
       setBannerList(res || [])
@@ -61,6 +54,14 @@ export default withLayout((props) => {
61 54
     setShowLive(e)
62 55
   }
63 56
 
57
+  useEffect(() => {
58
+    if (city?.id) {
59
+      GetBanner()
60
+      GetProjectList()
61
+    }
62
+  }, [city?.id])
63
+
64
+
64 65
   return (
65 66
     <view className='Page Index'>
66 67
       {/* <ShareToCircle visible></ShareToCircle> */}

+ 1
- 0
src/routes.js View File

@@ -29,6 +29,7 @@ const routes = [
29 29
     pkg: 'main',
30 30
     isTab: true,
31 31
     type: 'chat',
32
+    auth: ['page'],
32 33
   },
33 34
   {
34 35
     name: '我是',

+ 42
- 50
src/utils/login.js View File

@@ -7,61 +7,53 @@ import { wxLogin } from '@/services/login'
7 7
 import { getCardDetail } from '@/services/card'
8 8
 import { queryUserInfo } from '@/services/user'
9 9
 
10
-export default (payload) => {
11
-  return new Promise((resolve, reject) => {
12
-    const { path, scene, ...params } = payload
13
-  
14
-    // 获取 code
15
-    Taro.login({
16
-      success: ({ code }) => {
17
-        params.code = code
18
-  
19
-        // 转换 undefined 为 ''
20
-        const loginParams = Object.keys(params).reduce((acc, k) => ({ ...acc, [`${k}`]: ifNull(params[k], '') }), {})
21
-  
22
-        // 远程登录获取人员
23
-        wxLogin(loginParams, false).then(data => {
24
-  
25
-          const { extraInfo, miniApp, person, city } = data
26
-          const { token, sessionKey } = miniApp
27
-          const { dispatch, getState } = store
28
-  
29
-          Taro.setStorageSync('token', token)
30
-          Taro.setStorageSync('sessionKey', sessionKey)
31
-  
32
-          dispatch({ type: USER_INFO, payload: { extraInfo, person, miniApp } })
33
-          const { city: { curCity } } = getState()
34
-  
35
-          if (!curCity || Object.keys(curCity).length == 0) {
36
-            if (city) {
37
-              dispatchCitySelected(city)(dispatch)
38
-            }
39
-          }
10
+export default (params) => {
11
+  return new Promise((resolve, reject) => {  
12
+    // 转换 undefined 为 ''
13
+    const loginParams = Object.keys(params).reduce((acc, k) => ({ ...acc, [`${k}`]: ifNull(params[k], '') }), {})
40 14
 
41
-          // 获取人员详细信息
42
-          // eslint-disable-next-line no-unused-vars
43
-          queryUserInfo().then(info => {
44
-            // const { unReadNum } = info
15
+    // 远程登录获取人员
16
+    wxLogin(loginParams, false).then(data => {
45 17
 
46
-            // 默认红点开始就有
47
-            dispatch({ type: ASSIGN_UNREADNUM, payload: true });
48
-            resolve(data)
49
-          }).catch(reject)
18
+      const { extraInfo, miniApp, person, city } = data
19
+      const { token, sessionKey } = miniApp
20
+      const { dispatch, getState } = store
50 21
 
51
-          // 如果有推荐人信息
52
-          if (loginParams.recommender && loginParams.recommender !== person.personId) {
53
-            getCardDetail(loginParams.recommender).then((res) => {
54
-              dispatch({ type: 'SYNC_RECOMMENDER', payload: res });
55
-              if (res.personType === ROLE_CODE.CONSULTANT) {
56
-                dispatch({ type: 'SYNC_CONSULTANT', payload: res });
57
-              }
58
-            })
59
-          }
22
+      Taro.setStorageSync('token', token)
23
+      Taro.setStorageSync('sessionKey', sessionKey)
60 24
 
61
-          // 如果通过扫码进入
25
+      dispatch({ type: USER_INFO, payload: { extraInfo, person, miniApp } })
26
+      const { city: { curCity } } = getState()
62 27
 
63
-        }).catch(reject)
28
+      if (!curCity || Object.keys(curCity).length == 0) {
29
+        if (city) {
30
+          dispatchCitySelected(city)(dispatch)
31
+        }
64 32
       }
65
-    })
33
+
34
+      // 获取人员详细信息
35
+      // eslint-disable-next-line no-unused-vars
36
+      queryUserInfo().then(info => {
37
+        // const { unReadNum } = info
38
+
39
+        // 默认红点开始就有
40
+        dispatch({ type: ASSIGN_UNREADNUM, payload: true });
41
+        resolve(data)
42
+      }).catch(reject)
43
+
44
+      // 如果有推荐人信息
45
+      if (loginParams.recommender && loginParams.recommender !== person.personId) {
46
+        getCardDetail(loginParams.recommender).then((res) => {
47
+          dispatch({ type: 'SYNC_RECOMMENDER', payload: res });
48
+          if (res.personType === ROLE_CODE.CONSULTANT) {
49
+            dispatch({ type: 'SYNC_CONSULTANT', payload: res });
50
+          }
51
+        })
52
+      }
53
+
54
+      // 如果通过扫码进入
55
+
56
+    }).catch(reject)
57
+  
66 58
   })
67 59
 }