index.vue 3.9 KB

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