index.jsx 5.4KB

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