account-login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!-- 账号密码登录 accountLogin -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <!-- <view class="head-box ss-flex-col">
  6. <view class="ss-flex ss-m-b-20">
  7. <view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
  8. <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
  9. 短信登录
  10. </view>
  11. </view>
  12. <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view>
  13. </view> -->
  14. <!-- 表单项 -->
  15. <uni-forms ref="accountLoginRef" v-model="state.model" :rules="state.rules" validateTrigger="bind"
  16. labelWidth="140" labelAlign="center" class="loginUniForm">
  17. <uni-forms-item name="username" label="用户名" class="loginUniFormItem">
  18. <uni-easyinput placeholder="请输入用户名" v-model="state.model.username" :inputBorder="false">
  19. </uni-easyinput>
  20. </uni-forms-item>
  21. <uni-forms-item name="password" label="密码" class="loginUniFormItem">
  22. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.password" :inputBorder="false">
  23. </uni-easyinput>
  24. </uni-forms-item>
  25. </uni-forms>
  26. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  27. <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  28. 忘记密码
  29. </button>
  30. <button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import {
  36. ref,
  37. reactive,
  38. unref,
  39. computed
  40. } from 'vue';
  41. import sheep from '@/sheep';
  42. import {
  43. username,
  44. password
  45. } from '@/sheep/validate/form';
  46. import {
  47. showAuthModal,
  48. closeAuthModal
  49. } from '@/sheep/hooks/useModal';
  50. import AuthUtil from '@/sheep/api/member/auth';
  51. const accountLoginRef = ref(null);
  52. const emits = defineEmits(['onConfirm']);
  53. const props = defineProps({
  54. agreeStatus: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. });
  59. // 数据
  60. const state = reactive({
  61. model: {
  62. username: '', // 账号
  63. password: '', // 密码
  64. },
  65. rules: {
  66. username,
  67. password,
  68. },
  69. });
  70. // 账号登录
  71. async function accountLoginSubmit() {
  72. // 表单验证
  73. const validate = await unref(accountLoginRef)
  74. .validate()
  75. .catch((error) => {
  76. console.log('error: ', error);
  77. });
  78. if (!validate) return;
  79. // 同意协议
  80. if (!props.agreeStatus) {
  81. emits('onConfirm', true)
  82. sheep.$helper.toast('请勾选同意');
  83. return;
  84. }
  85. // 提交数据
  86. const {
  87. code,
  88. data
  89. } = await AuthUtil.login(state.model);
  90. if (code === 0) {
  91. closeAuthModal();
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. @import '../index.scss';
  97. .login-btn-start {
  98. background: #55b774;
  99. width: 60%;
  100. height: 80rpx;
  101. font-size: 32rpx;
  102. }
  103. .loginUniForm {
  104. border: 1rpx solid #d6d6d6;
  105. padding: 10rpx 15rpx;
  106. border-radius: 10rpx;
  107. }
  108. .loginUniFormItem:first-child {
  109. border-bottom: 1rpx solid #d6d6d6;
  110. padding-bottom: 10rpx;
  111. }
  112. .loginUniFormItem:last-child {
  113. // border-bottom: 1rpx solid #d6d6d6;
  114. padding-top: 10rpx;
  115. }
  116. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  117. padding-bottom: 0;
  118. }
  119. ::v-deep .loginUniFormItem .uni-error-message {
  120. bottom: -20rpx;
  121. }
  122. </style>