李志伟 3 年前
父节点
当前提交
dc93315bc9

+ 7
- 0
src/pages/Login/index.config.js 查看文件

@@ -0,0 +1,7 @@
1
+export default {
2
+  navigationBarTitleText: '登录',
3
+  navigationStyle: 'custom',
4
+  styleIsolation: 'shared',
5
+  enableShareAppMessage: true,
6
+  disableScroll: true,
7
+}

+ 144
- 0
src/pages/Login/index.jsx 查看文件

@@ -0,0 +1,144 @@
1
+import Taro from "@tarojs/taro"
2
+import { useState } from "react"
3
+import { useModel } from '@/store'
4
+import { View, Image, Input, Text, Button } from "@tarojs/components"
5
+import CustomNav from "@/components/CustomNav"
6
+import MyButton from "@/components/MyButton"
7
+import {updatePhone, setQcode } from '@/services/login'
8
+import withLayout from '@/layouts'
9
+import bgi from '@/assets/login/loginImg.png'
10
+import vCode from '@/assets/login/VerificationCode.png'
11
+import checkedImg from '@/assets/login/checkedImg.png'
12
+import unChecked from '@/assets/login/unChecked.png'
13
+
14
+import './style.less'
15
+
16
+export default withLayout((props) => {
17
+  const { router } = props
18
+  let { tab } = router.params
19
+  const { person,setPerson } = useModel('person')
20
+  const [agreement,setAgreement]=useState(false)
21
+  const [phone,setPhone]=useState()
22
+  const [qCode,setqCode]=useState()
23
+  const [qCodeBtn,setqCodeBtn]=useState('获取验证码')
24
+  const [dsb,setDsb]=useState(false)
25
+  const handlePhone=(e)=>{
26
+    if (e.detail.value) {
27
+      setPhone(e.detail.value)
28
+    }
29
+  }
30
+  const changeqCode=()=>{
31
+    if (rulePhone(phone)) {
32
+      setQcode({phone:phone}).then((res)=>{
33
+        Taro.showToast({
34
+          title: '发送成功,请注意查收',
35
+          icon: 'none',
36
+          duration: 2000
37
+        })
38
+      }).catch(() => {
39
+        Taro.showToast({
40
+          title: '网络异常, 请刷新小程序重试',
41
+          icon: 'none',
42
+        })
43
+      })
44
+
45
+      let time=60
46
+      setDsb(true)
47
+      // 调接口
48
+      let timer = setInterval(() => {
49
+        time-- //倒计时递减
50
+        setqCodeBtn(`${time}s后重新发送`)
51
+        if (time === 0) {
52
+          setDsb(false)
53
+          setqCodeBtn('重新发送')
54
+          time=60
55
+          clearInterval(timer)
56
+        }
57
+      }, 1000)
58
+
59
+    }
60
+  }
61
+  const rulePhone=(val)=>{
62
+    if (!/^1[0-9]{10}$/.test(val)) {
63
+      Taro.showToast({
64
+        title: '请输入正确的11位手机号',
65
+        icon: 'none',
66
+        duration: 2000
67
+      })
68
+      return false
69
+    } else return true
70
+  }
71
+  const handleqCode=(e)=>{
72
+    if (e.detail.value) {
73
+      setqCode(e.detail.value)
74
+    }
75
+  }
76
+  const onLogin = () => { 
77
+    if (rulePhone(phone)&&qCode) {
78
+      if (!agreement) {
79
+        Taro.showToast({
80
+          title: '请确认下方协议',
81
+          icon: 'none',
82
+          duration: 2000
83
+        })
84
+        return false
85
+      }
86
+      // 登录
87
+      updatePhone(person.personId,{phone:phone,captcha:qCode}).then((res)=>{
88
+        setPerson({...person,phone:phone})
89
+        Taro.showToast({
90
+          title: '登录成功',
91
+          icon: 'none',
92
+          duration: 1000
93
+        })
94
+        if (tab) {
95
+          setTimeout(()=>{
96
+            Taro.redirectTo({ url: `/pages/index/index?tab=${tab}` });
97
+          },1000)
98
+        }
99
+      }).catch((e) => {
100
+        console.log(e.message)
101
+        Taro.showToast({
102
+          title: '手机号或者验证码不正确',
103
+          icon: 'none',
104
+        })
105
+      })
106
+    } else {
107
+      Taro.showToast({
108
+        title: '请输入正确的手机号和验证码',
109
+        icon: 'none',
110
+        duration: 2000
111
+      })
112
+    }
113
+  }
114
+  return (
115
+    <View className='page-index'>
116
+      <View className='index-navbar'>
117
+        <CustomNav home title='登录' />
118
+      </View>
119
+      <Image src={bgi} className='loginBgi' />
120
+      <View className='index-container loginContent'>
121
+        <View className='title1'>您好!</View>
122
+        <View className='title2'>欢迎进入农机手端小程序!</View>
123
+        <View className='loginCell'>
124
+          <View className='loginHeader'>+86</View>
125
+          <Input type='number' maxlength='11' placeholder='请输入手机号' value={phone} onInput={handlePhone} />
126
+          <Button  className={['loginAction',dsb?'qCodeActive':'']} disabled={dsb} onClick={dsb?'':changeqCode}>{qCodeBtn}</Button>
127
+        </View>
128
+        <View className='loginCell'>
129
+          <View className='loginHeader'>
130
+            <Image src={vCode} className='headerImg' />
131
+          </View>
132
+          <Input type='text' value={qCode} onInput={handleqCode} placeholder='请输入验证码' />
133
+        </View>
134
+        <View className='footer'>
135
+          <MyButton value='登录' onClick={onLogin} />
136
+          <View className='agreement' onClick={()=>setAgreement(!agreement)}>
137
+              <Image src={agreement?checkedImg:unChecked} className='footerCheckbox' />
138
+              请认真查看<Text>文本协议/隐私政策</Text>,确认之后选择此项!
139
+          </View>
140
+        </View>
141
+      </View>
142
+    </View>
143
+  )
144
+})

+ 87
- 0
src/pages/Login/style.less 查看文件

@@ -0,0 +1,87 @@
1
+.loginBgi{
2
+  width: 100%;
3
+  height: 100%;
4
+  position: absolute;
5
+  top: 0;
6
+}
7
+.goback{
8
+  width: 19px;
9
+  height: 35px;
10
+  position: absolute;
11
+  left: 30px;
12
+  top: 67.5px;
13
+}
14
+.loginContent{
15
+  padding: 60px 30px;
16
+  color: #333333;
17
+  font-weight: bold;
18
+  input{
19
+    font-size: 34px;
20
+  }
21
+  .title1{
22
+    padding: 40px 0;
23
+    font-size: 66px;
24
+    letter-spacing: 10px;
25
+  }
26
+  .title2{
27
+    font-size: 54px;
28
+    letter-spacing: 10px;
29
+  }
30
+  .loginCell{
31
+    display: flex;
32
+    align-items: center;
33
+    height: 108px;
34
+    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.12);
35
+    .loginHeader,.loginAction{
36
+      flex: none;
37
+    }
38
+    .loginHeader{
39
+      font-size: 38px;
40
+      font-weight: 500;
41
+      color: #333333;
42
+      width: 106px;
43
+      border-right: 1px solid #333;
44
+      display: flex;
45
+      .headerImg{
46
+        width: 32px;
47
+        height: 40px;
48
+        margin-left: 19px;
49
+      }
50
+    }
51
+    .loginAction{
52
+      width: 10em;
53
+      background: linear-gradient(0deg, #00AE39,#A0E067);
54
+      border-radius: 20px;
55
+      line-height: 68px;
56
+      color: #fff;
57
+      font-size: 30px;
58
+    }
59
+    .qCodeActive{
60
+      opacity: 0.5;
61
+    }
62
+    input{
63
+      flex: 1;
64
+      padding: 0 0 0 31px;
65
+    }
66
+  }
67
+  .footer{
68
+    position: absolute;
69
+    bottom: 60px;
70
+    .agreement{
71
+      font-size: 26px;
72
+      font-weight: 400;
73
+      color: #999;
74
+      margin-top: 42px;
75
+      display: flex;
76
+      align-items: center;
77
+      .footerCheckbox{
78
+        width: 28px;
79
+        height: 28px;
80
+        margin-right: 11px;
81
+      }
82
+      Text{
83
+        color: #02902E
84
+      }
85
+    }
86
+  }
87
+}

+ 2
- 8
src/pages/index/index.jsx 查看文件

@@ -25,14 +25,11 @@ export default withLayout((props) => {
25 25
   const { location, setLocation, setAddress } = useModel('location')
26 26
   const { person } = useModel('person')
27 27
   const [currentTab, setCurrentTab] = useState(0)
28
-  const [show, setShow] = useState(false)
29
-  const [path, setPath] = useState()
30 28
   const handleClick = (val) => {
31 29
     if (!person.phone && val != 0) {
32
-      setShow(true)
33
-      setPath(`/pages/index/index?tab=${val}`)
30
+      Taro.navigateTo({url:`/pages/Login/index?tab=${val}`})
34 31
     } else {
35
-      setCurrentTab(val)
32
+      Taro.redirectTo({ url: `/pages/index/index?tab=${val}` });
36 33
     }
37 34
   };
38 35
   useEffect(() => {
@@ -61,9 +58,6 @@ export default withLayout((props) => {
61 58
   }, [tab])
62 59
   return (
63 60
     <View className='page-index'>
64
-      {
65
-        show && <LoginModel path={path} />
66
-      }
67 61
       <View className='index-navbar'>
68 62
         <CustomNav home title={currentTab == 0 ? '首页' : currentTab == 1 ? '订单列表' : '我的'} />
69 63
       </View>

+ 7
- 0
src/pages/userInfo/index.jsx 查看文件

@@ -33,6 +33,13 @@ export default withLayout((props) => {
33 33
     } else return true
34 34
   }
35 35
   const handleSave = () => {
36
+    if (!name) {
37
+      Taro.showToast({
38
+        title: '请输入您的姓名',
39
+        icon: 'none',
40
+      })
41
+      return
42
+    }
36 43
     if (rulePhone(phone)) {
37 44
       updateInfo(person.personId, { ...person, avatar: avatar, phone: phone, nickName: name }).then((res) => {
38 45
         setPerson(res)

+ 4
- 0
src/routes.js 查看文件

@@ -26,6 +26,10 @@ const mainPages = [
26 26
     title: '我的钱包',
27 27
     page: 'pages/wallet/index',
28 28
   },
29
+  {
30
+    title: '登录',
31
+    page: 'pages/Login/index',
32
+  },
29 33
   {
30 34
     title: '提现',
31 35
     page: 'pages/withdrawal/index',

+ 1
- 1
src/store/models/person.js 查看文件

@@ -8,7 +8,7 @@ export default () => {
8 8
   const login = (params) => {
9 9
     signIn(params).then((res) => {
10 10
       const { person: taPerson,  sessionKey: skey } = res;
11
-      // taPerson.phone=null
11
+      taPerson.phone=null
12 12
       setPerson(taPerson);
13 13
       setSessionKey(skey);
14 14
     })

+ 2
- 1
src/utils/hooks/useLogin.js 查看文件

@@ -3,7 +3,8 @@ import { useModel } from '@/store'
3 3
 import { useMemo, useState, useEffect } from "react";
4 4
 
5 5
 const whiteList = [
6
-  "/pages/index/index"
6
+  "/pages/index/index",
7
+  "/pages/Login/index"
7 8
 ]
8 9
 
9 10
 export default () => {