index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="smsLoginSubmit"> 登录/注册 </button>
  48. </view>
  49. </view>
  50. </template>
  51. <script setup>
  52. import { ref } from 'vue'
  53. import { mobile, password, code } from '@/utils/validate'
  54. import { getSmsCode, getSmsTimer } from '@/utils/code'
  55. const items = ['短信登录', '账号登录']
  56. const current = ref(0)
  57. const accountLoginRef = ref()
  58. const smsLoginRef = ref()
  59. const state = ref({
  60. isMobileEnd: false, // 手机号输入完毕
  61. codeText: '获取验证码',
  62. sms: {
  63. phone: '13229740092',
  64. code: ''
  65. },
  66. account: {
  67. phone: '13229740091',
  68. password: 'Citu123'
  69. },
  70. rules: {
  71. phone: mobile,
  72. password,
  73. },
  74. smsRules: {
  75. code,
  76. phone: mobile
  77. }
  78. })
  79. const onClickItem = (e) => {
  80. current.value = e.currentIndex
  81. }
  82. // 获取验证码
  83. const handleCode = () => {
  84. if (!state.value.sms.phone) {
  85. uni.showToast({
  86. title: '请输入手机号',
  87. icon: 'none',
  88. duration: 2000
  89. })
  90. return
  91. }
  92. getSmsCode('smsLogin', state.value.sms.phone)
  93. }
  94. const smsLoginSubmit = () => {}
  95. </script>
  96. <style scoped lang="scss">
  97. .login-code {
  98. width: 73px;
  99. min-width: 73px;
  100. color: var(--v-primary-base);
  101. text-align: center;
  102. font-size: 12px;
  103. cursor: pointer;
  104. border: 1px dashed var(--v-primary-base);
  105. border-radius: 26px;
  106. padding: 0;
  107. }
  108. </style>