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="account" label="账号">
  24. <uni-easyinput placeholder="请输入账号" v-model="state.model.account" :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 { computed, watch, ref, reactive, unref } from 'vue';
  49. import sheep from '@/sheep';
  50. import { account, password } from '@/sheep/validate/form';
  51. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  52. const accountLoginRef = ref(null);
  53. const emits = defineEmits(['onConfirm']);
  54. const props = defineProps({
  55. agreeStatus: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. });
  60. // 数据
  61. const state = reactive({
  62. model: {
  63. account: '', // 账号
  64. password: '', // 密码
  65. },
  66. rules: {
  67. account,
  68. password,
  69. },
  70. });
  71. // 1.账号登录
  72. async function accountLoginSubmit() {
  73. // 表单验证
  74. const validate = await unref(accountLoginRef)
  75. .validate()
  76. .catch((error) => {
  77. console.log('error: ', error);
  78. });
  79. if (!validate) return;
  80. // 同意协议
  81. if (!props.agreeStatus) {
  82. emits('onConfirm', true)
  83. sheep.$helper.toast('请勾选同意');
  84. return;
  85. }
  86. // 提交数据
  87. sheep.$api.user.accountLogin(state.model).then((res) => {
  88. if (res.error === 0) {
  89. // sheep.$store('user').getInfo();
  90. closeAuthModal();
  91. }
  92. });
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. @import '../index.scss';
  97. </style>