account-login.vue 2.8 KB

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