index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view>
  3. <uni-popup ref="popup" background-color="#fff" type="bottom">
  4. <view class="head-box ss-p-30">
  5. <view class="ss-flex ss-m-b-20">
  6. <view class="head-title head-title-line head-title-animation" :class="{ 'head-title-active': type === 'account' }" @tap="type = 'code'">短信登录</view>
  7. <view class="head-title ss-m-r-40" :class="{ 'head-title-active': type === 'code' }" @tap="type = 'account'">账号登录</view>
  8. </view>
  9. <view v-if="type === 'code'" class="head-subtitle">未注册的手机号,验证后自动注册账号</view>
  10. </view>
  11. <view class="ss-p-30 ss-m-b-60">
  12. <!-- 短信验证码登录 -->
  13. <uni-forms
  14. v-if="type === 'code'"
  15. ref="smsLoginRef"
  16. v-model="state.sms"
  17. :rules="state.smsRules"
  18. validateTrigger="bind"
  19. labelWidth="140"
  20. labelAlign="center"
  21. >
  22. <uni-forms-item name="phone" label="手机号">
  23. <uni-easyinput
  24. placeholder="请输入手机号"
  25. v-model="state.sms.phone"
  26. :inputBorder="false"
  27. type="number"
  28. >
  29. <template v-slot:right>
  30. <button
  31. class="ss-reset-button code-btn code-btn-start"
  32. :disabled="state.isMobileEnd"
  33. :class="{ 'code-btn-end': state.isMobileEnd }"
  34. @tap="handleSendCode"
  35. >
  36. <!-- {{ getSmsTimer('smsLogin') }} -->
  37. </button>
  38. </template>
  39. </uni-easyinput>
  40. </uni-forms-item>
  41. <uni-forms-item name="code" label="验证码">
  42. <uni-easyinput
  43. placeholder="请输入验证码"
  44. v-model="state.sms.code"
  45. :inputBorder="false"
  46. type="number"
  47. maxlength="6"
  48. >
  49. <template v-slot:right>
  50. <button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit"> 登录 </button>
  51. </template>
  52. </uni-easyinput>
  53. </uni-forms-item>
  54. </uni-forms>
  55. <!-- 账号密码登录 -->
  56. <uni-forms
  57. v-if="type === 'account'"
  58. ref="accountLoginRef"
  59. v-model="state.account"
  60. :rules="state.rules"
  61. validateTrigger="bind"
  62. labelWidth="140"
  63. labelAlign="center"
  64. >
  65. <uni-forms-item name="phone" label="账号">
  66. <uni-easyinput placeholder="请输入账号" v-model="state.account.phone" :inputBorder="false"></uni-easyinput>
  67. </uni-forms-item>
  68. <uni-forms-item name="password" label="密码">
  69. <uni-easyinput
  70. type="password"
  71. placeholder="请输入密码"
  72. v-model="state.account.password"
  73. :inputBorder="false"
  74. >
  75. <template v-slot:right>
  76. <button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  77. </template>
  78. </uni-easyinput>
  79. </uni-forms-item>
  80. </uni-forms>
  81. </view>
  82. </uni-popup>
  83. </view>
  84. </template>
  85. <script setup>
  86. import { ref } from 'vue'
  87. import { mobile, password, code } from '@/utils/validate'
  88. // import { getSmsTimer } from '@/hooks/useModal'
  89. const popup = ref()
  90. const type = ref('code')
  91. const accountLoginRef = ref()
  92. const smsLoginRef = ref()
  93. const state = ref({
  94. isMobileEnd: false, // 手机号输入完毕
  95. codeText: '获取验证码',
  96. sms: {
  97. phone: '13229740092',
  98. code: ''
  99. },
  100. account: {
  101. phone: '13229740091',
  102. password: 'Citu123'
  103. },
  104. rules: {
  105. phone: mobile,
  106. password,
  107. },
  108. smsRules: {
  109. code,
  110. phone: mobile
  111. }
  112. })
  113. const open = () => {
  114. popup.value.open()
  115. }
  116. const accountLoginSubmit = () => {}
  117. const smsLoginSubmit = () => {}
  118. defineExpose({
  119. open,
  120. popup
  121. })
  122. </script>
  123. <style scoped lang="scss">
  124. </style>