|
@@ -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
|
+})
|