张延森 5 lat temu
rodzic
commit
d53a4f22d4
5 zmienionych plików z 91 dodań i 22 usunięć
  1. 6
    2
      src/app.js
  2. 29
    2
      src/pages/card/index.js
  3. 27
    14
      src/pages/project/detail/index.js
  4. 17
    4
      src/utils/login.js
  5. 12
    0
      src/utils/tools.js

+ 6
- 2
src/app.js Wyświetl plik

@@ -164,6 +164,10 @@ class App extends Component {
164 164
         console.info('router2:', router)
165 165
         console.info('-----------')
166 166
         const { query: payload } = router
167
+
168
+        payload.path = router.path
169
+        payload.scene = router.scene
170
+
167 171
         // login
168 172
         login(payload, res => {
169 173
           // 获取未读消息
@@ -209,8 +213,8 @@ class App extends Component {
209 213
   componentDidMount() {
210 214
     console.info('app componentDidMount')
211 215
   }
212
-  componentWillMount() {
213
-    console.info('app componentWillMount')
216
+  componentWillMount(params) {
217
+    console.info('app componentWillMount', params)
214 218
   }
215 219
 
216 220
   getRouterParams() {

+ 29
- 2
src/pages/card/index.js Wyświetl plik

@@ -8,6 +8,7 @@ import BackHomeBtn from '@components/BackHomeBtn'
8 8
 import getUserPhone from '@utils/getUserPhone'
9 9
 import AchievePhone from '@components/achievePhone'
10 10
 import ready from '@utils/ready'
11
+import { sceneInShare } from '@utils/tools'
11 12
 
12 13
 import { ROLE_CODE } from '@constants/user'
13 14
 import { addCardUv, addCardShareNum, favorCard, cancelFavorCard } from '@services/card'
@@ -42,12 +43,27 @@ export default class Index extends Component {
42 43
 
43 44
   componentWillMount() {
44 45
     ready.queue(() => {
46
+
47
+      // 分享场景需要先授权手机, 再授权头像
48
+      const options = wx.getLaunchOptionsSync()
49
+      if (sceneInShare(options.scene)) {
50
+        const { person = {} } = this.props.userInfo || {}
51
+        if ((person.tel || person.phone) && (person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
52
+          Taro.reLaunch({ url: '/pages/auth/index' })
53
+          return
54
+        }
55
+
56
+        this.setState({
57
+          grantPhoneVisible: true,
58
+        })
59
+      }
60
+
45 61
       this.initPageData()
46 62
     })
47 63
   }
48 64
   initPageData() {
49 65
     const router = Taro.getStorageSync('router')
50
-    const id = this.$router.params.id || router.query.id || '4604a792d575eb8187711625bd88832c'
66
+    const id = this.$router.params.id || router.query.id
51 67
 
52 68
     if (router.query.id) {
53 69
       this.setState({
@@ -402,6 +418,17 @@ export default class Index extends Component {
402 418
       modalStatus: false
403 419
     })
404 420
   }
421
+  
422
+  handleAuthPhoneSuccess = () => {
423
+    const { person = {} } = this.props.userInfo || {}
424
+    if ((person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
425
+      Taro.reLaunch({ url: '/pages/auth/index' })
426
+      return
427
+    }
428
+
429
+    this.initPageData()
430
+  }
431
+
405 432
   render() {
406 433
     const { makePosterStatus, posterData, modalStatus, grantPhoneVisible } = this.state
407 434
     const { userInfo, cardInfo, projectDetail } = this.props
@@ -423,7 +450,7 @@ export default class Index extends Component {
423 450
         {makePosterStatus && (<Poster data={posterData} toggle={this.toggleVisiblePoster}></Poster>)}
424 451
         {
425 452
           (grantPhoneVisible && userInfo.person.personId && !userInfo.person.phone) &&
426
-          <AchievePhone user={userInfo.person} onSuccess={this.initPageData}></AchievePhone>
453
+          <AchievePhone user={userInfo.person} onSuccess={this.handleAuthPhoneSuccess}></AchievePhone>
427 454
         }
428 455
         {
429 456
           visibleConfirmModal && (

+ 27
- 14
src/pages/project/detail/index.js Wyświetl plik

@@ -21,7 +21,7 @@ import dayjs from 'dayjs'
21 21
 import 'dayjs/locale/zh-cn' // 按需加载
22 22
 import ready from '@utils/ready'
23 23
 import Notice from '@components/Notice'
24
-import { getDownloadURL, getThumbnail } from '@utils/tools'
24
+import { getDownloadURL, getThumbnail, sceneInShare } from '@utils/tools'
25 25
 import { connect } from '@tarojs/redux'
26 26
 import { dispatchProjectDetail } from '@actions/project'
27 27
 import getUserPhone from '@utils/getUserPhone'
@@ -62,9 +62,22 @@ export default class Index extends Component {
62 62
   }
63 63
 
64 64
   componentWillMount() {
65
-    // const { id = '78c3dd489791dc1d29472fa344b08c45' } = this.$router.params
66
-
67 65
     ready.queue(() => {
66
+    
67
+      // 分享场景需要先授权手机, 再授权头像
68
+      const options = wx.getLaunchOptionsSync()
69
+      if (sceneInShare(options.scene)) {
70
+        const { person = {} } = this.props.userInfo || {}
71
+        if ((person.tel || person.phone) && (person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
72
+          Taro.reLaunch({ url: '/pages/auth/index' })
73
+          return
74
+        }
75
+
76
+        this.setState({
77
+          grantPhoneVisible: true,
78
+        })
79
+      }
80
+
68 81
       this.initPageData()
69 82
     })
70 83
   }
@@ -102,16 +115,6 @@ export default class Index extends Component {
102 115
       })
103 116
     })
104 117
   }
105
-  componentDidMount() {
106
-    const options = wx.getLaunchOptionsSync()
107
-    const sceneList = [1011, 1012, 1013, 1031, 1032, 1036, 1047, 1048]
108
-
109
-    if (sceneList.indexOf(options.scene) != -1) {
110
-      this.setState({
111
-        grantPhoneVisible: true,
112
-      })
113
-    }
114
-  }
115 118
 
116 119
   loadHelpGroupList() {
117 120
     const { buildingId } = this.state
@@ -488,6 +491,16 @@ export default class Index extends Component {
488 491
     })
489 492
   }
490 493
 
494
+  handleAuthPhoneSuccess = () => {
495
+    const { person = {} } = this.props.userInfo || {}
496
+    if ((person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
497
+      Taro.reLaunch({ url: '/pages/auth/index' })
498
+      return
499
+    }
500
+
501
+    this.initPageData()
502
+  }
503
+
491 504
   renderBottomMenu() {
492 505
     const { userInfo: { person: { personType } } } = this.props
493 506
     const { posterShow } = this.state
@@ -1045,7 +1058,7 @@ export default class Index extends Component {
1045 1058
       <Block>
1046 1059
         {
1047 1060
           (grantPhoneVisible && userInfo.person.personId && !userInfo.person.phone) &&
1048
-          <AchievePhone user={userInfo.person} onSuccess={this.initPageData}></AchievePhone>
1061
+          <AchievePhone user={userInfo.person} onSuccess={this.handleAuthPhoneSuccess}></AchievePhone>
1049 1062
         }
1050 1063
         {
1051 1064
           loaded && (

+ 17
- 4
src/utils/login.js Wyświetl plik

@@ -2,9 +2,12 @@ import Taro from '@tarojs/taro';
2 2
 import { getStore } from '@tarojs/redux'
3 3
 import { USER_INFO } from '@constants/user'
4 4
 import { wxLogin } from '@services/login'
5
+import { sceneInShare } from '@utils/tools'
5 6
 import ready from '@utils/ready'
6 7
 let loading = false
7
-export default function (params, callback) {
8
+export default function (payload, callback) {
9
+  const { path, scene, ...params } = payload
10
+
8 11
   if (loading) {
9 12
     return
10 13
   }
@@ -34,9 +37,19 @@ export default function (params, callback) {
34 37
           callback && callback(data)
35 38
 
36 39
         } else {
37
-          Taro.reLaunch({
38
-            url: '/pages/auth/index'
39
-          })
40
+
41
+          // 非扫码进入项目详情或者卡片主页, 跳转到授权头像
42
+          // 否则不跳
43
+          const noAuthPages = [
44
+            'pages/project/detail/index',
45
+            'pages/card/index',
46
+          ]
47
+
48
+          if (noAuthPages.indexOf(path) === -1 || !sceneInShare(scene)) {
49
+            Taro.reLaunch({
50
+              url: '/pages/auth/index'
51
+            })
52
+          }
40 53
         }
41 54
         ready.open()
42 55
 

+ 12
- 0
src/utils/tools.js Wyświetl plik

@@ -1,5 +1,17 @@
1 1
 import Taro from '@tarojs/taro';
2 2
 
3
+/**
4
+ * 是否分享场景(含扫码)
5
+ * @param {*} scene 
6
+ */
7
+export function sceneInShare(scene) {
8
+  return [1011, 1012, 1013, 1031, 1032, 1036, 1047, 1048].indexOf(scene) > -1
9
+}
10
+
11
+/**
12
+ * 造空数组
13
+ * @param {int}} n 
14
+ */
3 15
 export function times(n) {
4 16
   return n > 0 ? '*'.repeat(n - 1).split('*') : []
5 17
 }