index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-02-19 11:59:48
  4. * @LastEditTime: 2021-03-01 14:00:50
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \intelligentLock\src\pages\index\index.vue
  8. -->
  9. <template>
  10. <view class="page">
  11. <!-- uerInfo -->
  12. <view class="loginHeader">
  13. <image :src='loginBg'
  14. class="imglogin" />
  15. </view>
  16. <view class="second">
  17. <view class="loginBox">
  18. <AtForm :onSubmit="handleSubmit"
  19. :onReset="handleReset">
  20. <view class="loginItem">
  21. <view class="loginItemImgBox">
  22. <image :src="phonePng"
  23. class="loginItemImg" />
  24. </view>
  25. <AtInput required
  26. class="inputItem"
  27. name="account"
  28. type="phone"
  29. placeholder="请输入手机号"
  30. :value="state.account"
  31. :onChange="handleChange.bind(this, 'account')" />
  32. </view>
  33. <view class="loginItem">
  34. <view class="loginItemImgBox">
  35. <image :src="pwdPng"
  36. class="loginItemImg" />
  37. </view>
  38. <AtInput name="password"
  39. :border="false"
  40. type="phone"
  41. clear
  42. placeholder="请输入验证码"
  43. :value="state.password"
  44. :onChange="handleChange.bind(this, 'password')">
  45. </AtInput>
  46. <view>
  47. <AtButton type="secondary"
  48. size="small"
  49. :disabled="state.isDisabled"
  50. :onClick="sendCode.bind(this)">
  51. {{sentTitle}}
  52. </AtButton>
  53. </view>
  54. </view>
  55. <view class="agree">
  56. <AtCheckbox :options="[
  57. { label: '登录代表您已同意用户协议及隐私条款', value: '1' }
  58. ]"
  59. :selectedList="state.isAgreed"
  60. :onChange="handleChange.bind(this, 'isAgreed')" />
  61. </view>
  62. <AtButton type="primary"
  63. formType="submit"
  64. :onClick="handleSubmit">
  65. 登 录
  66. </AtButton>
  67. <view class="secondaryBox">
  68. <AtButton type="secondary"
  69. :onClick="goToAccount.bind(this)">
  70. 使用账户密码登录
  71. </AtButton>
  72. </view>
  73. </AtForm>
  74. </view>
  75. </view>
  76. <AtToast :text="state.text"
  77. :isOpened="state.isOpened"></AtToast>
  78. <view class="loginFooter">
  79. <image :src='bgfooter'
  80. class="bgFooter" />
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import './index.scss'
  86. import setStateMixin from '../../mixins/setStateMixin'
  87. import loginBg from "../../assets/images/login/loginBg.png"
  88. import bgfooter from "../../assets/images/login/bgfooter.png"
  89. import phonePng from "../../assets/images/login/phone.png"
  90. import pwdPng from "../../assets/images/login/pwd.png"
  91. import { compressImage } from '@tarojs/taro'
  92. export default {
  93. name: 'accountLogin',
  94. mixins: [setStateMixin],
  95. data () {
  96. return {
  97. phonePng,
  98. pwdPng,
  99. loginBg,
  100. bgfooter,
  101. state: {
  102. account: '',
  103. password: '',
  104. isAgreed: [],
  105. isDisabled: false,
  106. second: 10,
  107. isOpened: false,
  108. text: ''
  109. },
  110. sentTitle: '获取验证码'
  111. }
  112. },
  113. created () { },
  114. onShow () { },
  115. onHide () { },
  116. methods: {
  117. handleChange (stateName, value) {
  118. this.setState({
  119. [stateName]: value,
  120. })
  121. },
  122. // showTipText () {
  123. // return this.state.disabled ? `${this.state.second}s后重试` : '发送验证码'
  124. // },
  125. // 发送验证码
  126. sendCode () {
  127. if (!this.state.isDisabled) {
  128. this.setState({
  129. isDisabled: true,
  130. })
  131. console.log("ddd==this.state", this.state.isDisabled)
  132. // 倒计时
  133. const timer = setInterval(() => {
  134. console.log("倒计时--")
  135. if (this.state.second > 0) {
  136. this.sentTitle = `${this.state.second}s后重试`
  137. this.setState({
  138. second: this.state.second - 1,
  139. })
  140. } else {
  141. this.setState({
  142. second: 60,
  143. isDisabled: false,
  144. })
  145. this.sentTitle = "获取验证码"
  146. clearInterval(timer)
  147. }
  148. }, 1000)
  149. } else {
  150. this.sentTitle = "获取验证码"
  151. }
  152. },
  153. handleSubmit () {
  154. const { account, password, isAgreed } = this.state
  155. if (!account) {
  156. this.setState({
  157. isOpened: true,
  158. text: `手机号不能为空`,
  159. })
  160. this.closeToast()
  161. return false
  162. }
  163. if (!password) {
  164. this.setState({
  165. isOpened: true,
  166. text: `验证码不能为空`,
  167. })
  168. this.closeToast()
  169. return false
  170. }
  171. else if (isAgreed.length == 0) {
  172. this.setState({
  173. isOpened: true,
  174. text: "请勾选用户协议"
  175. })
  176. this.closeToast()
  177. return false
  178. } else {
  179. this.$taro.switchTab({
  180. url: '/pages/index/index'
  181. })
  182. }
  183. },
  184. closeToast () {
  185. setTimeout(() => {
  186. this.setState({
  187. isOpened: false,
  188. })
  189. }, 2000)
  190. },
  191. handleReset () {
  192. console.log('handleReset')
  193. this.setState({
  194. isOpened: true,
  195. text: `表单已被重置`,
  196. account: '',
  197. password: '',
  198. isAgreed: [],
  199. })
  200. this.closeToast()
  201. },
  202. // 使用验证码登录
  203. goToAccount () {
  204. this.$taro.navigateTo({
  205. url: '/pages/accountLogin/index'
  206. })
  207. }
  208. }
  209. }
  210. </script>