wujingjing
2025-02-27 f996c7437b0a7d4e7bafeb7c71b7c86b7170c8bd
src/layout/component/login/Login.vue
@@ -57,9 +57,11 @@
<script setup lang="ts">
import { ElMessage, type FormInstance } from 'element-plus';
import { computed, reactive, ref } from 'vue';
import { PostLogin, loginMessageUser, loginVerifyMessage } from '/@/api/ai/user';
import { isLoginStatus, isShowLogin, userInfo } from '/@/stores/chatRoom';
import { LoginInfo } from '/@/utils/storage';
import { ACCOUNT_EXPIRE_DAY, handleAfterLogin, LOGIN_CLIENT, STORED_ACCOUNT_KEY } from './login';
import { loginMessageUser, loginVerifyMessage, PostLogin } from '/@/api/ai/user';
import { isShowLogin } from '/@/stores/chatRoom';
import { encrypt } from '/@/utils/cypto';
import { LocalPlus } from '/@/utils/storage';
const handleClose = () => {
   isShowLogin.value = false;
@@ -91,7 +93,6 @@
   ],
   verifyCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
};
const LOGIN_CLIENT = 'Web端';
const loginFormRef = ref<FormInstance>(null); //账户密码登录
const formPhoneRef = ref(); //手机号登录
const hasSended = computed(() => {
@@ -102,11 +103,12 @@
});
//登录
const onSubmit = async () => {
   let res;
   if (state.activeLoginName === 'accountUser') {
      //账户密码登录
      const isValid = await loginFormRef.value.validate().catch(() => {});
      if (!isValid) return;
      const res = await PostLogin({
      res = await PostLogin({
         user: state.loginForm.account,
         pass: state.loginForm.pwd,
         client: LOGIN_CLIENT,
@@ -114,13 +116,11 @@
      if (!res.json_ok) {
         return ElMessage.error(res.json_msg);
      }
      userInfo.set(res);
      LoginInfo.set(res.hswatersession, state.loginForm.account);
   } else if (state.activeLoginName === 'phoneUser') {
      //手机登录
      const isValid = await formPhoneRef.value.validate().catch(() => {});
      if (!isValid) return;
      const res = await loginMessageUser({
      res = await loginMessageUser({
         phone: state.loginPhoneForm.phoneUser,
         code: state.loginPhoneForm.verifyCode,
         client: LOGIN_CLIENT,
@@ -128,12 +128,16 @@
      if (!res.json_ok) {
         return ElMessage.error(res.json_msg);
      }
      LoginInfo.set(res.hswatersession, state.loginPhoneForm.phoneUser);
      userInfo.set(res);
   }
   isShowLogin.value = false;
   isLoginStatus.value = true;
   window.location.reload();
   if (state.activeLoginName === 'accountUser') {
      const accountEncryptStr = encrypt({
         username: state.loginForm.account,
         password: state.loginForm.pwd,
      });
      LocalPlus.set(STORED_ACCOUNT_KEY, accountEncryptStr, ACCOUNT_EXPIRE_DAY);
   }
   handleAfterLogin(res);
};
const countdown = ref(null);