index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="ss-p-30 head-box">
  3. <view class="head-title">欢迎来到门墩儿招聘</view>
  4. <uni-segmented-control class="ss-m-t-30" :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 class="agreement-box ss-flex ss-row-center">
  49. <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00897B' : '#ccc'" @tap.stop="protocol = !protocol"></uni-icons>
  50. <view class="color-999 ss-flex ss-col-center ss-m-l-8 font-size-13">
  51. 我已阅读并遵守
  52. <view class="color-primary" @tap.stop="handleToDetail('user')">
  53. 《用户协议》
  54. </view>
  55. <view class="agreement-text">与</view>
  56. <view class="color-primary" @tap.stop="handleToDetail('privacy')">
  57. 《隐私协议》
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script setup>
  65. import { ref, unref } from 'vue'
  66. import { mobile, password, code } from '@/utils/validate'
  67. import { getSmsCode, getSmsTimer } from '@/utils/code'
  68. import { userStore } from '@/store/user'
  69. const useUserStore = userStore()
  70. const items = ['短信登录', '账号登录']
  71. const current = ref(1)
  72. const accountLoginRef = ref()
  73. const smsLoginRef = ref()
  74. const protocol = ref(false)
  75. const state = ref({
  76. isMobileEnd: false, // 手机号输入完毕
  77. codeText: '获取验证码',
  78. sms: {
  79. phone: '13229740092',
  80. code: ''
  81. },
  82. account: {
  83. phone: '13229740091',
  84. password: 'Citu123'
  85. },
  86. rules: {
  87. phone: mobile,
  88. password,
  89. },
  90. smsRules: {
  91. code,
  92. phone: mobile
  93. }
  94. })
  95. // 登录成功后的返回页面
  96. // const backUrl = getCurrentPages().length ? getCurrentPages()[getCurrentPages().length - 2].route : ''
  97. const onClickItem = (e) => {
  98. current.value = e.currentIndex
  99. }
  100. // 获取验证码
  101. const handleCode = () => {
  102. if (!state.value.sms.phone) {
  103. uni.showToast({
  104. title: '请输入手机号',
  105. icon: 'none',
  106. duration: 2000
  107. })
  108. return
  109. }
  110. getSmsCode('smsLogin', state.value.sms.phone)
  111. }
  112. // 查看协议详情
  113. const handleToDetail = (type) => {
  114. const url = type === 'user' ? '/pagesB/agreement/user' : '/pagesB/agreement/privacy'
  115. uni.navigateTo({
  116. url
  117. })
  118. }
  119. // 登录
  120. const handleLogin = async () => {
  121. if (!protocol.value) return uni.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
  122. const validate = await unref(current.value === 0 ? smsLoginRef : accountLoginRef).validate()
  123. if (!validate) return
  124. const query = current.value === 0 ? state.value.sms : state.value.account
  125. Object.assign(query, {
  126. account: query.phone
  127. })
  128. await useUserStore.handleSmsLogin(query, current.value === 0 ? true : false)
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .login-code {
  133. width: 73px;
  134. min-width: 73px;
  135. color: #00897B;
  136. text-align: center;
  137. font-size: 12px;
  138. cursor: pointer;
  139. border: 1px dashed #00897B;
  140. border-radius: 26px;
  141. padding: 0;
  142. }
  143. .head-title {
  144. font-size: 40rpx;
  145. text-align: center;
  146. color: #00897B;
  147. margin-top: 30rpx;
  148. }
  149. </style>