login3.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view>
  3. <image src="/modules/common/static/images/login/login-car.png" mode="widthFix" style="width: 100vw;"></image>
  4. <view class="login-box">
  5. <view class="login-box-top">手机号登录</view>
  6. <fs-form ref="loginRef" :model="loginModel">
  7. <fs-form-item><fs-field placeholder="请输入手机号" v-model="loginModel.phone"></fs-field></fs-form-item>
  8. <fs-form-item>
  9. <fs-field placeholder="请输入验证码" v-model="loginModel.code">
  10. <template #after>
  11. <fs-captcha :mobile="loginModel.phone" @start="sendCaptcha" @end="endCaptcha"></fs-captcha>
  12. </template>
  13. </fs-field>
  14. </fs-form-item>
  15. <fs-gutter height="160rpx" bgColor="#fff"></fs-gutter>
  16. <fs-button full round @click="handleLogin">登录</fs-button>
  17. <fs-gutter height="60rpx" bgColor="#fff"></fs-gutter>
  18. </fs-form>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { ref, reactive } from 'vue'
  24. import useForm from '@/hooks/useForm'
  25. import useValidator from '@/hooks/useValidator'
  26. import { useUserStore } from '@/stores/user'
  27. const user = useUserStore()
  28. const validator = useValidator()
  29. const loginRules = {
  30. phone: { validator: validator.mobile },
  31. code: {
  32. required: true,
  33. message: '请输入密码'
  34. }
  35. }
  36. const loginModel = reactive({
  37. phone: '',
  38. code: ''
  39. })
  40. const loginRef = ref(null)
  41. const loginForm = useForm(loginRules, 'loginRef')
  42. const handleLogin = () => {
  43. loginForm.validate().then(() => {
  44. user
  45. .login({
  46. ...loginModel
  47. })
  48. .then(res => {
  49. uni.navigateBack()
  50. })
  51. })
  52. }
  53. const sendCaptcha = () => {
  54. console.log('sendCaptcha')
  55. }
  56. const endCaptcha = () => {
  57. console.log('endCaptcha')
  58. }
  59. </script>
  60. <style>
  61. page {
  62. background-color: #fff;
  63. height: 100%;
  64. overflow: hidden;
  65. }
  66. </style>
  67. <style lang="scss" scoped>
  68. .login-box {
  69. position: fixed;
  70. left: 40rpx;
  71. right: 40rpx;
  72. top: 260rpx;
  73. background-color: #fff;
  74. border-radius: 20rpx;
  75. padding: 60rpx;
  76. overflow: hidden;
  77. &-top {
  78. font-size: 20px;
  79. color: #222;
  80. font-weight: 500;
  81. margin: 40rpx 0;
  82. }
  83. }
  84. .login-top {
  85. color: #222222;
  86. font-size: 30px;
  87. font-weight: bold;
  88. margin: 100rpx 0;
  89. }
  90. </style>