李志伟 3 years ago
parent
commit
d949555d15

+ 11
- 8
src/pages/index/components/User/index.jsx View File

1
 import { useState,useEffect } from "react"
1
 import { useState,useEffect } from "react"
2
+import { useModel } from '@/store'
2
 import Taro from "@tarojs/taro"
3
 import Taro from "@tarojs/taro"
3
 import { View, Image, ScrollView } from "@tarojs/components"
4
 import { View, Image, ScrollView } from "@tarojs/components"
4
 import userBgi from '@/assets/user/userBgi.png'
5
 import userBgi from '@/assets/user/userBgi.png'
16
 import './style.less'
17
 import './style.less'
17
 
18
 
18
 export default (props) => {
19
 export default (props) => {
19
-  const { isLogin } = props
20
+  const { phone,setPhone } = useModel('phone')
21
+
20
   const handleAccount = () => { 
22
   const handleAccount = () => { 
21
     Taro.navigateTo({ url: '/pages/userInfo/index' });
23
     Taro.navigateTo({ url: '/pages/userInfo/index' });
22
    }
24
    }
42
     Taro.navigateTo({ url: '/pages/bankCard/index' });
44
     Taro.navigateTo({ url: '/pages/bankCard/index' });
43
    }
45
    }
44
   const signOut = () => { 
46
   const signOut = () => { 
47
+    setPhone()
45
     Taro.reLaunch({ url: '/pages/index/index?tab=2' });
48
     Taro.reLaunch({ url: '/pages/index/index?tab=2' });
46
   }
49
   }
47
   return (
50
   return (
48
     <ScrollView scrollY style={{ height: '100%' }}>
51
     <ScrollView scrollY style={{ height: '100%' }}>
49
       {
52
       {
50
-        isLogin &&
53
+        phone &&
51
         <View className='personTip'>该账号归张三所属</View>
54
         <View className='personTip'>该账号归张三所属</View>
52
       }
55
       }
53
       <View className='userHead'>
56
       <View className='userHead'>
54
         <Image src={userBgi} className='userBgi' />
57
         <Image src={userBgi} className='userBgi' />
55
-        <View className='headcontent' onClick={handleLogin}>
56
-          <Image src={isLogin ? banner1 : avatar} className='avatar' />
58
+        <View className='headcontent' onClick={phone?'':handleLogin}>
59
+          <Image src={phone ? banner1 : avatar} className='avatar' />
57
           {
60
           {
58
-            isLogin ? <View>
61
+            phone ? <View>
59
               <View>张三</View>
62
               <View>张三</View>
60
-              <View>13612345678</View>
63
+              <View>{phone}</View>
61
             </View> : <View>点击登录</View>
64
             </View> : <View>点击登录</View>
62
           }
65
           }
63
         </View>
66
         </View>
64
       </View>
67
       </View>
65
       {
68
       {
66
-        isLogin &&
69
+        phone &&
67
         <View className='userCard'>
70
         <View className='userCard'>
68
           <View
71
           <View
69
             className='cardItem'
72
             className='cardItem'
103
           <MyCell icon={feedback} action={goto} user handleAction={handleFeedback}>意见反馈</MyCell>
106
           <MyCell icon={feedback} action={goto} user handleAction={handleFeedback}>意见反馈</MyCell>
104
         </View>
107
         </View>
105
         {
108
         {
106
-          isLogin && <View className='signOut' onClick={signOut}>退出登录</View>
109
+          phone && <View className='signOut' onClick={signOut}>退出登录</View>
107
         }
110
         }
108
       </View>
111
       </View>
109
 
112
 

+ 28
- 9
src/pages/login/index.jsx View File

14
 
14
 
15
 export default (props) => {
15
 export default (props) => {
16
   const { person } = useModel('person')
16
   const { person } = useModel('person')
17
+  const { setPhone:setphone } = useModel('phone')
17
 
18
 
18
-  console.log(person)
19
   const [agreement,setAgreement]=useState(false)
19
   const [agreement,setAgreement]=useState(false)
20
   const [phone,setPhone]=useState()
20
   const [phone,setPhone]=useState()
21
   const [qCode,setqCode]=useState()
21
   const [qCode,setqCode]=useState()
28
   }
28
   }
29
   const changeqCode=()=>{
29
   const changeqCode=()=>{
30
     if (rulePhone(phone)) {
30
     if (rulePhone(phone)) {
31
-      setQcode({phone:phone})
31
+      setQcode({phone:phone}).then((res)=>{
32
+        Taro.showToast({
33
+          title: '发送成功,请注意查收',
34
+          icon: 'none',
35
+          duration: 2000
36
+        })
37
+      }).catch(() => {
38
+        Taro.showToast({
39
+          title: '网络异常, 请刷新小程序重试',
40
+          icon: 'none',
41
+        })
42
+      })
32
 
43
 
33
-      let time=10
44
+      let time=60
34
       setDsb(true)
45
       setDsb(true)
35
       // 调接口
46
       // 调接口
36
       let timer = setInterval(() => {
47
       let timer = setInterval(() => {
72
         return false
83
         return false
73
       }
84
       }
74
       // 登录
85
       // 登录
75
-      Taro.showToast({
76
-        title: '登录成功',
77
-        icon: 'none',
78
-        duration: 1000
86
+      updatePhone(person.personId,{phone:phone,captcha:qCode}).then((res)=>{
87
+        Taro.showToast({
88
+          title: '登录成功',
89
+          icon: 'none',
90
+          duration: 1000
91
+        })
92
+        setphone(res.phone)
93
+        Taro.reLaunch({ url: '/pages/index/index?tab=2&&isLogin=true' });
94
+      }).catch((e) => {
95
+        console.log(e)
96
+        Taro.showToast({
97
+          title: '网络异常, 请刷新小程序重试',
98
+          icon: 'none',
99
+        })
79
       })
100
       })
80
-      Taro.reLaunch({ url: '/pages/index/index?tab=2&&isLogin=true' });
81
-
82
     } else {
101
     } else {
83
       Taro.showToast({
102
       Taro.showToast({
84
         title: '请输入正确的手机号和验证码',
103
         title: '请输入正确的手机号和验证码',

+ 1
- 1
src/pages/login/style.less View File

39
       }
39
       }
40
     }
40
     }
41
     .loginAction{
41
     .loginAction{
42
-      width: 9em;
42
+      width: 10em;
43
       background: linear-gradient(0deg, #00AE39,#A0E067);
43
       background: linear-gradient(0deg, #00AE39,#A0E067);
44
       border-radius: 20px;
44
       border-radius: 20px;
45
       line-height: 68px;
45
       line-height: 68px;

+ 1
- 2
src/store/models/person.js View File

8
 
8
 
9
   const login = (params) => {
9
   const login = (params) => {
10
     signIn(params).then((res) => {
10
     signIn(params).then((res) => {
11
-      const { person: taPerson,  sessionKey: skey,  token } = res;
11
+      const { person: taPerson,  sessionKey: skey } = res;
12
       setPerson(taPerson);
12
       setPerson(taPerson);
13
       setSessionKey(skey);
13
       setSessionKey(skey);
14
-      Taro.setStorage({ key: 'token', data: token })
15
     })
14
     })
16
   }
15
   }
17
 
16