index.jsx 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { useState } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { getUserQcode, setUserPhone } from '@/services/login'
  4. import { View, Image, Input, Text, Form } from '@tarojs/components'
  5. import CustomNav from '@/components/CustomNav'
  6. import ButtontWX from '@/components/ButtontWX'
  7. import checkedImg from '@/assets/lolginImages/checkedImg.png'
  8. import unselectedImg from '@/assets/lolginImages/unselectedImg.png'
  9. import { useModel } from '@/store'
  10. import './style.less'
  11. export default (props) => {
  12. const { isLoginVisible } = props
  13. const { person, setPerson } = useModel('userData')
  14. const [countCenter, setCountCenter] = useState({
  15. count: 60,
  16. toast: false,
  17. show_btn: false,
  18. code_ts: '获取验证码'
  19. })
  20. const [checkImage, setCheckImage] = useState(false)
  21. const [InputPhoneValue, setInputPhoneValue] = useState('18082043755')
  22. const [InputCodeValue, setInputCodeValue] = useState('375501')
  23. const onInputPhone = (r) => {
  24. setInputPhoneValue(r?.detail?.value)
  25. console.log("🚀 ~ file: index.jsx ~ line 26 ~ InputCodeValue", InputPhoneValue)
  26. }
  27. const onInputCode = (r) => {
  28. setInputCodeValue(r?.detail?.value)
  29. }
  30. //获取验证码
  31. const getCode = (r) => {
  32. if (InputPhoneValue === '' || !(/^1[3456789]\d{9}$/.test(InputPhoneValue))) {
  33. console.log('提示')
  34. Taro.showToast({
  35. title: '手机号码有误',
  36. icon: 'none',
  37. duration: 2000
  38. })
  39. } else {
  40. getUserQcode({ phone: InputPhoneValue }).then(() => {
  41. Taro.showToast({
  42. title: '验证码发送成功',
  43. icon: 'none',
  44. duration: 2000
  45. })
  46. })
  47. let count = countCenter.count
  48. const timer = setInterval(() => {
  49. setCountCenter({
  50. count: (count--),
  51. show_btn: true,
  52. code_ts: count + '秒后重发'
  53. })
  54. if (count == 0) {
  55. setCountCenter({
  56. show_btn: false,
  57. count: 60,
  58. code_ts: '获取验证码'
  59. })
  60. clearInterval(timer)
  61. }
  62. }, 1000)
  63. }
  64. }
  65. const getUserLogin = () => {
  66. if (InputPhoneValue === '' || !(/^1[3456789]\d{9}$/.test(InputPhoneValue))) {
  67. console.log('提示')
  68. Taro.showToast({
  69. title: '手机号或验证码有误',
  70. icon: 'none',
  71. duration: 2000
  72. })
  73. } else {
  74. if (!checkImage) {
  75. Taro.showToast({
  76. title: '下方协议未勾选',
  77. icon: 'none',
  78. duration: 2000
  79. })
  80. } else {
  81. setUserPhone(person.personId, { captcha: InputCodeValue, phone: InputPhoneValue }).then((e) => {
  82. console.log('e', e);
  83. setPerson({ ...person, phone: InputPhoneValue })
  84. Taro.reLaunch({ url: '/pages/index/index' });
  85. })
  86. // console.log('person', person);
  87. }
  88. }
  89. }
  90. return (
  91. <>
  92. {
  93. isLoginVisible ? <View className='page-index ' style={{ position: 'absolute', zIndex: '29999' }
  94. } >
  95. <View className='index-navbar'>
  96. <CustomNav title='登陆' home />
  97. </View>
  98. <View className='loginBackImg-box' >
  99. <Image src={require("@/assets/lolginImages/backLogin.png")} />
  100. <View className='loginhallo-text'>
  101. <View>您好!</View>
  102. <View>欢迎进入农户端小程序!</View>
  103. </View>
  104. <View>
  105. <View className='loginPhone-box' >
  106. <View className='loginPhone-box-loginPhoneView'>+86</View>
  107. <Input maxlength={11} placeholder='请输入手机号码' type={Number} value={InputPhoneValue} onInput={onInputPhone} />
  108. <ButtontWX opacity={countCenter.show_btn ? '0.7' : '11'} disabled={countCenter.show_btn} onClick={getCode} butText={countCenter.code_ts} butWidth={94} butHeight={34} butFontSize={15} butBorderRadius={10} />
  109. </View>
  110. <View className='loginPhone-box'>
  111. <View className='loginPhone-box-loginPhoneView'>
  112. <Image style={{ width: '16px', height: '20px', margin: 'auto 2.8vw auto 2.8vw' }} src={require("@/assets/lolginImages/phoneCode.png")} />
  113. </View>
  114. <Input maxlength={10} placeholder='请输入验证码' value={InputCodeValue} onInput={onInputCode} />
  115. </View>
  116. </View>
  117. </View>
  118. <View className='BottomtButrelative' >
  119. <ButtontWX onClick={getUserLogin} butText='登陆' butWidth={315} butHeight={49} butFontSize={16} butBorderRadius={49} />
  120. </View>
  121. <View className='bottom-agreement'>
  122. <Image src={!checkImage ? checkedImg : unselectedImg} onClick={() => { setCheckImage(!checkImage) }} />
  123. <View>
  124. 请认真查看<Text style={{ color: '#CE3800' }}>文本协议/隐私政策</Text>,确认之后选择此项!
  125. </View>
  126. </View>
  127. </View >
  128. : <></>
  129. }
  130. </>
  131. )
  132. }