account-login.vue 2.9 KB

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