index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view class="ss-p-30 head-box">
  3. <view>欢迎来到门墩儿招聘</view>
  4. <uni-segmented-control class="ss-m-t-60" :current="current" :values="items" style-type="text" active-color="#00897B" @clickItem="onClickItem" />
  5. <view class="head-subtitle ss-m-t-10">未注册的手机号,验证后自动注册账号</view>
  6. <view class="ss-m-t-30">
  7. <!-- 短信验证码登录 -->
  8. <uni-forms
  9. v-if="current === 0"
  10. ref="smsLoginRef"
  11. v-model="state.sms"
  12. :rules="state.smsRules"
  13. validateTrigger="bind"
  14. labelWidth="140"
  15. labelAlign="center"
  16. >
  17. <uni-forms-item name="phone" label="手机号">
  18. <uni-easyinput placeholder="请输入手机号" v-model="state.sms.phone" :inputBorder="false" type="number">
  19. <template v-slot:right>
  20. <button class="login-code" :disabled="state.isMobileEnd" :class="{ 'code-btn-end': state.isMobileEnd }" @tap="handleCode">
  21. {{ getSmsTimer('smsLogin') }}
  22. </button>
  23. </template>
  24. </uni-easyinput>
  25. </uni-forms-item>
  26. <uni-forms-item name="code" label="验证码">
  27. <uni-easyinput placeholder="请输入验证码" v-model="state.sms.code" :inputBorder="false" type="number" maxlength="6"></uni-easyinput>
  28. </uni-forms-item>
  29. </uni-forms>
  30. <!-- 账号密码登录 -->
  31. <uni-forms
  32. v-else
  33. ref="accountLoginRef"
  34. v-model="state.account"
  35. :rules="state.rules"
  36. validateTrigger="bind"
  37. labelWidth="140"
  38. labelAlign="center"
  39. >
  40. <uni-forms-item name="phone" label="账号">
  41. <uni-easyinput placeholder="请输入账号" v-model="state.account.phone" :inputBorder="false"></uni-easyinput>
  42. </uni-forms-item>
  43. <uni-forms-item name="password" label="密码">
  44. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.account.password" :inputBorder="false"></uni-easyinput>
  45. </uni-forms-item>
  46. </uni-forms>
  47. <button class="send-button" @tap="handleLogin"> 登录/注册 </button>
  48. </view>
  49. </view>
  50. </template>
  51. <script setup>
  52. import { ref, unref } from 'vue'
  53. import { mobile, password, code } from '@/utils/validate'
  54. import { getSmsCode, getSmsTimer } from '@/utils/code'
  55. import { userStore } from '@/store/user'
  56. const useUserStore = userStore()
  57. const items = ['短信登录', '账号登录']
  58. const current = ref(1)
  59. const accountLoginRef = ref()
  60. const smsLoginRef = ref()
  61. const state = ref({
  62. isMobileEnd: false, // 手机号输入完毕
  63. codeText: '获取验证码',
  64. sms: {
  65. phone: '13229740092',
  66. code: ''
  67. },
  68. account: {
  69. phone: '13229740091',
  70. password: 'Citu123'
  71. },
  72. rules: {
  73. phone: mobile,
  74. password,
  75. },
  76. smsRules: {
  77. code,
  78. phone: mobile
  79. }
  80. })
  81. const onClickItem = (e) => {
  82. current.value = e.currentIndex
  83. }
  84. // 获取验证码
  85. const handleCode = () => {
  86. if (!state.value.sms.phone) {
  87. uni.showToast({
  88. title: '请输入手机号',
  89. icon: 'none',
  90. duration: 2000
  91. })
  92. return
  93. }
  94. getSmsCode('smsLogin', state.value.sms.phone)
  95. }
  96. // 登录
  97. const handleLogin = async () => {
  98. const validate = await unref(current.value === 0 ? smsLoginRef : accountLoginRef).validate()
  99. if (!validate) return
  100. await useUserStore.handleSmsLogin(current.value === 0 ? state.value.sms : state.value.account, current.value === 0 ? true : false)
  101. }
  102. </script>
  103. <style scoped lang="scss">
  104. .login-code {
  105. width: 73px;
  106. min-width: 73px;
  107. color: var(--v-primary-base);
  108. text-align: center;
  109. font-size: 12px;
  110. cursor: pointer;
  111. border: 1px dashed var(--v-primary-base);
  112. border-radius: 26px;
  113. padding: 0;
  114. }
  115. </style>