张延森 il y a 3 ans
Parent
révision
9003d5fcec

+ 1
- 1
src/app.js Voir le fichier

@@ -7,7 +7,7 @@ import './app.less'
7 7
 class App extends Component {
8 8
 
9 9
   onLaunch(options) {
10
-    const [,, setPerson, login] = store.getModel('person').getState()
10
+    const {setPerson, login} = store.getModel('person').getState()
11 11
 
12 12
     // 预拉取数据
13 13
     preFetchData().then((fetchData) => {

+ 52
- 0
src/components/AuthPage/index.jsx Voir le fichier

@@ -0,0 +1,52 @@
1
+import React, { useState } from 'react'
2
+import Taro from '@tarojs/taro'
3
+import { useModel } from '@/store'
4
+import { Label, RadioGroup } from '@tarojs/components'
5
+import index from '@/assets/icons/login/LOGO.png'
6
+import './login.less'
7
+
8
+
9
+export default (props) => {
10
+  const { getPhone } = useModel('person')
11
+
12
+  const [loading, setLoading] = useState(false)
13
+  const [checked, setChecked] = useState(false)
14
+
15
+  const handleChange = () => {
16
+    setChecked(true)
17
+  }
18
+
19
+  const handlePhoneNumber = (e) => {
20
+    const { errMsg, ...data } = e.detail || {}
21
+    if (errMsg === 'getPhoneNumber:ok') {
22
+      const sessionKey = Taro.getStorageSync('sessionKey')
23
+      getPhone({ ...data, sessionKey }).then(() => {
24
+        setLoading(false)
25
+      }).catch(() => setLoading(false))
26
+    }
27
+  }
28
+
29
+  return (
30
+    <view>
31
+      <image className='logo' src={index} />
32
+      <view className='v1'>登录后可继续当前操作</view>
33
+      <button
34
+        disabled={!checked}
35
+        loading={loading}
36
+        className='login'
37
+        openType='getPhoneNumber'
38
+        onGetPhoneNumber={handlePhoneNumber}
39
+      >微信手机号一键登录</button>
40
+      <view className='buttom'>
41
+        <Label>
42
+          <RadioGroup onChange={handleChange}>
43
+            <radio checked={checked} />
44
+          </RadioGroup>
45
+          <view>
46
+            我已阅读知晓并同意 <text>《平台用户服务协议》</text>
47
+          </view>
48
+        </Label>
49
+      </view>
50
+    </view>
51
+  )
52
+}

src/pages/login/login.less → src/components/AuthPage/login.less Voir le fichier

@@ -1,4 +1,5 @@
1 1
 .logo{
2
+  display: block;
2 3
   width: 320px;
3 4
   height: 320px;
4 5
   margin: 21px auto;
@@ -6,7 +7,7 @@
6 7
 }
7 8
 .v1{
8 9
   font-size: 28px;
9
-   line-height: 0;
10
+  line-height: 0;
10 11
   color: #999;
11 12
   text-align: center;
12 13
 }
@@ -28,15 +29,24 @@
28 29
   text-align: center;
29 30
   bottom: 80px;
30 31
   width: 100%;
31
-  radio{
32
-    transform:scale(0.5);
33
-    margin-right: -9px;
34
-    position: relative;
35
-    bottom: 4px;
36
-    right: -8px;
32
+  vertical-align: middle;
33
+
34
+  radio-group {
35
+    display: inline-block;
36
+    vertical-align: middle;
37 37
   }
38
-  text{
39
-    color: #274190;
40
-    text-decoration: underline;
38
+
39
+  radio {
40
+    transform: scale(.8);
41
+  }
42
+
43
+  view {
44
+    display: inline-block;
45
+    vertical-align: middle;
46
+
47
+    text{
48
+      color: #274190;
49
+      text-decoration: underline;
50
+    }
41 51
   }
42 52
 }

+ 1
- 1
src/layouts/index.jsx Voir le fichier

@@ -7,7 +7,7 @@ import Loading from './Loading'
7 7
 import { getPageBy, getIndexPageOf } from '../routes'
8 8
 
9 9
 export default (Child) => (props) => {
10
-  const [person] = useModel('person')
10
+  const { person } = useModel('person')
11 11
   const router = useRouter()
12 12
 
13 13
   // 确保人员信息到位

+ 7
- 15
src/pages/index/index.jsx Voir le fichier

@@ -1,27 +1,19 @@
1
-import React, { Suspense, useState, useEffect, lazy } from 'react'
2
-import { useRouter } from '@tarojs/taro'
1
+import React, { useState, useEffect } from 'react'
2
+import Taro from '@tarojs/taro'
3 3
 import CustomNav from '@/components/CustomNav'
4
-import { useModel } from '@/store'
5 4
 import logo from '@/assets/icons/comm/logo_small.png'
6 5
 import withLayout from '@/layouts'
7 6
 import tabList from './tabbar'
8
-import './index.less'
9 7
 import Guide from './tabs/Guide'
10 8
 import Mine from './tabs/Mine'
11 9
 import Recommend from './tabs/Recommend'
12
-// import Strategy from './tabs/Strategy'
13
-
14
-// const Recommend = lazy(() => import('./tabs/Recommend'))
15
-// const Guide = lazy(() => import('./tabs/Guide'))
16
-// const Strategy = lazy(() => import('./tabs/Strategy'))
17
-// const Mine =  import'./tabs/Mine'
18
-
10
+import './index.less'
19 11
 
20 12
 export default withLayout((props) => {
21
-  const { params } = useRouter()
13
+  const { router, person } = props
14
+  const { params, path } = router
22 15
   const { tab } = params || {}
23 16
 
24
-  const [person] = useModel('person')
25 17
   const [currentTab, setCurrentTab] = useState(0)
26 18
 
27 19
 
@@ -34,8 +26,8 @@ export default withLayout((props) => {
34 26
     if (tab) {
35 27
       setCurrentTab(tab - 0)
36 28
     }
37
-
38 29
   }, [tab])
30
+
39 31
   return (
40 32
     <view className='page-index'>
41 33
       <view className='index-navbar'>
@@ -45,7 +37,7 @@ export default withLayout((props) => {
45 37
         {currentTab === 0 && <Recommend />}
46 38
         {currentTab === 1 && <Guide />}
47 39
         {/* {currentTab === 2 && <Strategy />} */}
48
-        {currentTab === 2 && <Mine />}
40
+        {currentTab === 2 && <Mine person={person} />}
49 41
       </view>
50 42
       <view className='index-tabbar'>
51 43
         <mp-tabbar extClass='custom-tabbar' current={currentTab} list={tabList} onChange={handleTabChange}></mp-tabbar>

+ 1
- 0
src/pages/index/index.less Voir le fichier

@@ -17,6 +17,7 @@
17 17
   .index-container {
18 18
     flex: auto;
19 19
     overflow: hidden;
20
+    position: relative;
20 21
   }
21 22
 }
22 23
 

+ 4
- 8
src/pages/index/tabs/Mine.jsx Voir le fichier

@@ -1,7 +1,7 @@
1 1
 import React from 'react'
2 2
 import Taro from '@tarojs/taro'
3 3
 
4
-import girl from '@/assets/icons/UserCenter/girl.png'
4
+import AuthPage from '@/components/AuthPage'
5 5
 import boy from '@/assets/icons/UserCenter/boy.png'
6 6
 import awaitPay from '@/assets/icons/UserCenter/awaitPay.png'
7 7
 import AllOrder from '@/assets/icons/UserCenter/AllOrder.png'
@@ -10,15 +10,15 @@ import ToShop from '@/assets/icons/UserCenter/ToShop.png'
10 10
 import HomeLogo from '@/assets/icons/UserCenter/HomeLogo.png'
11 11
 import ContactMe from '@/assets/icons/UserCenter/ContactMe.png'
12 12
 import collect from '@/assets/icons/UserCenter/collect.png'
13
-import MyTravel from '@/assets/icons/UserCenter/MyTravel.png'
14 13
 import Rules from '@/assets/icons/UserCenter/Rules.png'
15 14
 import Userrrrrrr from '@/assets/icons/ProCard/8kb.jpg'
16
-// import Tbas2 from '@/pages/index/tabs/Guide'
17 15
 import './MineCss/style.less'
18 16
 
19 17
 
20 18
 
21 19
 export default (props) => {
20
+  const { person } = props
21
+
22 22
   // // 我的行程 
23 23
   // const HomeLogo = () => {
24 24
   //   Taro.navigateTo({ url: '/pages/MineUserAll/Rules/index' })
@@ -59,11 +59,7 @@ export default (props) => {
59 59
     Taro.navigateTo({ url: '/pages/MineUserAll/Rules/index' })
60 60
   }
61 61
 
62
-
63
-
64
-
65
-
66
-  return (
62
+  return !person.phone ? <AuthPage /> : (
67 63
     <scroll-view scroll-y style='height: 77vh;' >
68 64
       <view className='User-box'>
69 65
         <view className='User-info'>

+ 0
- 4
src/pages/login/login.config.js Voir le fichier

@@ -1,4 +0,0 @@
1
-export default {
2
-  navigationBarTitleText: '登录',
3
-  navigationStyle: 'custom',
4
-}

+ 0
- 23
src/pages/login/login.jsx Voir le fichier

@@ -1,23 +0,0 @@
1
-import React from 'react'
2
-import CustomNav from '@/components/CustomNav'
3
-import index from '../../assets/icons/login/LOGO.png'
4
-import '../index/index.less'
5
-import './login.less'
6
-
7
-
8
-export default (props) => {
9
-return (
10
-  <view className='page-index'>
11
-    <view className='index-navbar'>
12
-        <CustomNav title='登录' />                 
13
-    </view>
14
-    <image className='logo' src={index} />
15
-    <view className='v1'>登录后可继续当前操作</view>
16
-    <view className='login'>微信手机号一键登录</view>
17
-    <view className='buttom'>
18
-      <radio />
19
-    我已阅读知晓并同意 <text>《平台用户服务协议》</text>
20
-    </view>
21
-  </view>
22
-  
23
-)}

+ 13
- 1
src/services/person.js Voir le fichier

@@ -1,3 +1,15 @@
1 1
 import request from '@/utils/request'
2 2
 
3
-export const login = (params) => request('/login', { params, method: 'post' })
3
+/**
4
+ * 登录
5
+ * @param {*} params 
6
+ * @returns 
7
+ */
8
+export const signIn = (params) => request('/login', { params, method: 'post' })
9
+
10
+/**
11
+ * 授权手机
12
+ * @param {*} data 
13
+ * @returns 
14
+ */
15
+export const authPhone = (data) => request('/auth-user', { data, method: 'put' })

+ 16
- 4
src/store/models/person.js Voir le fichier

@@ -1,13 +1,13 @@
1 1
 import { useState } from "react"
2 2
 import Taro from '@tarojs/taro'
3
-import { login } from '@/services/person'
3
+import { signIn, authPhone } from '@/services/person'
4 4
 
5 5
 export default () => {
6 6
   const [person, setPerson] = useState()
7 7
   const [peronRoles, setPersonRoles] = useState([])
8 8
 
9
-  const personLogin = (params) => {
10
-    login(params).then((res) => {
9
+  const login = (params) => {
10
+    signIn(params).then((res) => {
11 11
       const { person : taPerson, personRoleList, sessionKey } = res;
12 12
       setPerson(taPerson);
13 13
       setPersonRoles(personRoleList);
@@ -15,5 +15,17 @@ export default () => {
15 15
     })
16 16
   }
17 17
 
18
-  return [person, peronRoles, setPerson, personLogin]
18
+  const getPhone = (data) => {
19
+    return authPhone(data).then((res) => {
20
+      setPerson(res);
21
+    })
22
+  }
23
+
24
+  return {
25
+    person,
26
+    peronRoles,
27
+    setPerson,
28
+    login,
29
+    getPhone,
30
+  }
19 31
 }