login2.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="layout-box">
  3. <view class="login-bg pr">
  4. <image src="/modules/common/static/images/login/login-sw.jpg" mode="widthFix" style="width: 100%;"></image>
  5. <view class="bg-text">
  6. <view class="bg-text-hd">您好</view>
  7. <view class="bg-text-bd">欢迎登录</view>
  8. </view>
  9. </view>
  10. <view class="login-shadow">
  11. <fs-tab :tabs="tabs" v-model="curTab" barWidth="96rpx"></fs-tab>
  12. <fs-form ref="loginRef" :model="curLoginModel">
  13. <view v-show="curTab === 0">
  14. <fs-form-item>
  15. <fs-field placeholder="请输入手机号" type="number" v-model="loginModel1.phone" maxlength="11"></fs-field>
  16. </fs-form-item>
  17. <fs-form-item>
  18. <fs-field type="number" placeholder="请输入验证码" v-model="loginModel1.code" maxlength="6">
  19. <template #after>
  20. <fs-captcha :mobile="loginModel1.phone" @start="sendCaptcha" @end="endCaptcha"></fs-captcha>
  21. </template>
  22. </fs-field>
  23. </fs-form-item>
  24. </view>
  25. <view v-show="curTab === 1">
  26. <fs-form-item>
  27. <fs-field placeholder="账号" v-model="loginModel2.name" maxlength="11"></fs-field>
  28. </fs-form-item>
  29. <fs-form-item>
  30. <fs-field placeholder="密码" type="password" v-model="loginModel2.password" maxlength="20"></fs-field>
  31. </fs-form-item>
  32. </view>
  33. </fs-form>
  34. <fs-cell justify="right">
  35. <navigator class="primary fs12" slot="title" url="./forgetPwd" v-show="curTab === 1">忘记密码?</navigator>
  36. <navigator class="primary fs12" slot="value" url="./register">去注册</navigator>
  37. </fs-cell>
  38. </view>
  39. <view class="login-btn"><fs-button block round type="primary" @click="handleLogin">登录</fs-button></view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import { ref, reactive, computed, watch } from 'vue'
  44. import useForm from '@/hooks/useForm'
  45. import useValidator from '@/hooks/useValidator'
  46. import { useUserStore } from '@/stores/user'
  47. const user = useUserStore()
  48. const tabs = [
  49. {
  50. name: '验证码登录'
  51. },
  52. {
  53. name: '密码登录'
  54. }
  55. ]
  56. const curTab = ref(0)
  57. const validator = useValidator()
  58. const loginRules1 = {
  59. phone: { validator: validator.mobile },
  60. code: { required: true, message: '请输入验证码' }
  61. }
  62. const loginModel1 = reactive({
  63. phone: '',
  64. code: ''
  65. })
  66. const loginRules2 = {
  67. name: { required: true, message: '请输入账号' },
  68. password: { required: true, message: '请输入密码' }
  69. }
  70. const loginModel2 = reactive({
  71. name: '',
  72. password: ''
  73. })
  74. const curLoginModel = computed(() => (curTab.value === 0 ? loginModel1 : loginModel2))
  75. const loginRef = ref(null)
  76. const loginForm = useForm(loginRules1, 'loginRef')
  77. watch(curTab, () => {
  78. loginForm.setRules(curTab.value === 0 ? loginRules1 : loginRules2)
  79. })
  80. const handleLogin = () => {
  81. loginForm.validate().then(() => {
  82. user
  83. .login({
  84. ...loginModel
  85. })
  86. .then(res => {
  87. uni.navigateBack()
  88. })
  89. })
  90. }
  91. const sendCaptcha = () => {
  92. console.log('sendCaptcha')
  93. }
  94. const endCaptcha = () => {
  95. console.log('endCaptcha')
  96. }
  97. </script>
  98. <style>
  99. page {
  100. background-color: #fff;
  101. }
  102. </style>
  103. <style lang="scss" scoped>
  104. .login-bg {
  105. margin-top: 20rpx;
  106. }
  107. .bg-text {
  108. position: absolute;
  109. left: 80rpx;
  110. top: 0;
  111. &-hd {
  112. font-size: 25px;
  113. line-height: 20px;
  114. margin-bottom: 20rpx;
  115. }
  116. &-bd {
  117. font-size: 16px;
  118. }
  119. }
  120. .login-shadow {
  121. border-radius: 40rpx;
  122. overflow: hidden;
  123. padding-bottom: 60rpx;
  124. // box-shadow: 0 0 8px 1px rgba(65, 65, 70, 0.2);
  125. }
  126. .login-btn {
  127. padding: 0 100rpx;
  128. margin-top: -50rpx;
  129. }
  130. </style>