Browse Source

new feats

张延森 5 years ago
parent
commit
d53a4f22d4
5 changed files with 91 additions and 22 deletions
  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 View File

164
         console.info('router2:', router)
164
         console.info('router2:', router)
165
         console.info('-----------')
165
         console.info('-----------')
166
         const { query: payload } = router
166
         const { query: payload } = router
167
+
168
+        payload.path = router.path
169
+        payload.scene = router.scene
170
+
167
         // login
171
         // login
168
         login(payload, res => {
172
         login(payload, res => {
169
           // 获取未读消息
173
           // 获取未读消息
209
   componentDidMount() {
213
   componentDidMount() {
210
     console.info('app componentDidMount')
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
   getRouterParams() {
220
   getRouterParams() {

+ 29
- 2
src/pages/card/index.js View File

8
 import getUserPhone from '@utils/getUserPhone'
8
 import getUserPhone from '@utils/getUserPhone'
9
 import AchievePhone from '@components/achievePhone'
9
 import AchievePhone from '@components/achievePhone'
10
 import ready from '@utils/ready'
10
 import ready from '@utils/ready'
11
+import { sceneInShare } from '@utils/tools'
11
 
12
 
12
 import { ROLE_CODE } from '@constants/user'
13
 import { ROLE_CODE } from '@constants/user'
13
 import { addCardUv, addCardShareNum, favorCard, cancelFavorCard } from '@services/card'
14
 import { addCardUv, addCardShareNum, favorCard, cancelFavorCard } from '@services/card'
42
 
43
 
43
   componentWillMount() {
44
   componentWillMount() {
44
     ready.queue(() => {
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
       this.initPageData()
61
       this.initPageData()
46
     })
62
     })
47
   }
63
   }
48
   initPageData() {
64
   initPageData() {
49
     const router = Taro.getStorageSync('router')
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
     if (router.query.id) {
68
     if (router.query.id) {
53
       this.setState({
69
       this.setState({
402
       modalStatus: false
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
   render() {
432
   render() {
406
     const { makePosterStatus, posterData, modalStatus, grantPhoneVisible } = this.state
433
     const { makePosterStatus, posterData, modalStatus, grantPhoneVisible } = this.state
407
     const { userInfo, cardInfo, projectDetail } = this.props
434
     const { userInfo, cardInfo, projectDetail } = this.props
423
         {makePosterStatus && (<Poster data={posterData} toggle={this.toggleVisiblePoster}></Poster>)}
450
         {makePosterStatus && (<Poster data={posterData} toggle={this.toggleVisiblePoster}></Poster>)}
424
         {
451
         {
425
           (grantPhoneVisible && userInfo.person.personId && !userInfo.person.phone) &&
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
           visibleConfirmModal && (
456
           visibleConfirmModal && (

+ 27
- 14
src/pages/project/detail/index.js View File

21
 import 'dayjs/locale/zh-cn' // 按需加载
21
 import 'dayjs/locale/zh-cn' // 按需加载
22
 import ready from '@utils/ready'
22
 import ready from '@utils/ready'
23
 import Notice from '@components/Notice'
23
 import Notice from '@components/Notice'
24
-import { getDownloadURL, getThumbnail } from '@utils/tools'
24
+import { getDownloadURL, getThumbnail, sceneInShare } from '@utils/tools'
25
 import { connect } from '@tarojs/redux'
25
 import { connect } from '@tarojs/redux'
26
 import { dispatchProjectDetail } from '@actions/project'
26
 import { dispatchProjectDetail } from '@actions/project'
27
 import getUserPhone from '@utils/getUserPhone'
27
 import getUserPhone from '@utils/getUserPhone'
62
   }
62
   }
63
 
63
 
64
   componentWillMount() {
64
   componentWillMount() {
65
-    // const { id = '78c3dd489791dc1d29472fa344b08c45' } = this.$router.params
66
-
67
     ready.queue(() => {
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
       this.initPageData()
81
       this.initPageData()
69
     })
82
     })
70
   }
83
   }
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
   loadHelpGroupList() {
119
   loadHelpGroupList() {
117
     const { buildingId } = this.state
120
     const { buildingId } = this.state
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
   renderBottomMenu() {
504
   renderBottomMenu() {
492
     const { userInfo: { person: { personType } } } = this.props
505
     const { userInfo: { person: { personType } } } = this.props
493
     const { posterShow } = this.state
506
     const { posterShow } = this.state
1045
       <Block>
1058
       <Block>
1046
         {
1059
         {
1047
           (grantPhoneVisible && userInfo.person.personId && !userInfo.person.phone) &&
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
           loaded && (
1064
           loaded && (

+ 17
- 4
src/utils/login.js View File

2
 import { getStore } from '@tarojs/redux'
2
 import { getStore } from '@tarojs/redux'
3
 import { USER_INFO } from '@constants/user'
3
 import { USER_INFO } from '@constants/user'
4
 import { wxLogin } from '@services/login'
4
 import { wxLogin } from '@services/login'
5
+import { sceneInShare } from '@utils/tools'
5
 import ready from '@utils/ready'
6
 import ready from '@utils/ready'
6
 let loading = false
7
 let loading = false
7
-export default function (params, callback) {
8
+export default function (payload, callback) {
9
+  const { path, scene, ...params } = payload
10
+
8
   if (loading) {
11
   if (loading) {
9
     return
12
     return
10
   }
13
   }
34
           callback && callback(data)
37
           callback && callback(data)
35
 
38
 
36
         } else {
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
         ready.open()
54
         ready.open()
42
 
55
 

+ 12
- 0
src/utils/tools.js View File

1
 import Taro from '@tarojs/taro';
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
 export function times(n) {
15
 export function times(n) {
4
   return n > 0 ? '*'.repeat(n - 1).split('*') : []
16
   return n > 0 ? '*'.repeat(n - 1).split('*') : []
5
 }
17
 }