account-login.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!-- 账号密码登录 accountLogin -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60 ss-flex-col">
  6. <view class="ss-flex ss-m-b-20">
  7. <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
  8. 短信登录
  9. </view>
  10. <view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
  11. </view>
  12. <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view>
  13. </view>
  14. <!-- 表单项 -->
  15. <uni-forms
  16. ref="accountLoginRef"
  17. v-model="state.model"
  18. :rules="state.rules"
  19. validateTrigger="bind"
  20. labelWidth="140"
  21. labelAlign="center"
  22. >
  23. <uni-forms-item name="mobile" label="账号">
  24. <uni-easyinput placeholder="请输入账号" v-model="state.model.mobile" :inputBorder="false">
  25. <template v-slot:right>
  26. <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  27. 忘记密码
  28. </button>
  29. </template>
  30. </uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="password" label="密码">
  33. <uni-easyinput
  34. type="password"
  35. placeholder="请输入密码"
  36. v-model="state.model.password"
  37. :inputBorder="false"
  38. >
  39. <template v-slot:right>
  40. <button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  41. </template>
  42. </uni-easyinput>
  43. </uni-forms-item>
  44. </uni-forms>
  45. </view>
  46. </template>
  47. <script setup>
  48. import { ref, reactive, unref } from 'vue';
  49. import sheep from '@/sheep';
  50. import { mobile, password } from '@/sheep/validate/form';
  51. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  52. import AuthUtil from '@/sheep/api/member/auth';
  53. const accountLoginRef = ref(null);
  54. const emits = defineEmits(['onConfirm']);
  55. const props = defineProps({
  56. agreeStatus: {
  57. type: Boolean,
  58. default: false,
  59. },
  60. });
  61. // 数据
  62. const state = reactive({
  63. model: {
  64. mobile: '', // 账号
  65. password: '', // 密码
  66. },
  67. rules: {
  68. mobile,
  69. password,
  70. },
  71. });
  72. // 账号登录
  73. async function accountLoginSubmit() {
  74. // 表单验证
  75. const validate = await unref(accountLoginRef)
  76. .validate()
  77. .catch((error) => {
  78. console.log('error: ', error);
  79. });
  80. if (!validate) return;
  81. // 同意协议
  82. if (!props.agreeStatus) {
  83. emits('onConfirm', true)
  84. sheep.$helper.toast('请勾选同意');
  85. return;
  86. }
  87. // 提交数据
  88. const { code, data } = await AuthUtil.login(state.model);
  89. if (code === 0) {
  90. closeAuthModal();
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. @import '../index.scss';
  96. </style>