diff --git a/.env.development b/.env.development index 873f221..0b58d27 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ VITE_API_BASE_URL = "http://u92a9b3d.natappfree.cc" -VITE_API_BASE_URL_LINK = "http://121.89.234.155:8807" \ No newline at end of file +VITE_API_BASE_URL_LINK = "http://39.101.133.168:8828" \ No newline at end of file diff --git a/.env.test b/.env.test index 8d68c14..e5846c2 100644 --- a/.env.test +++ b/.env.test @@ -1,2 +1,2 @@ VITE_API_BASE_URL = "http://u92a9b3d.natappfree.cc" -VITE_API_BASE_URL_LINK = "http://121.89.234.155:8807" +VITE_API_BASE_URL_LINK = "http://39.101.133.168:8828" diff --git a/src/utils/myAxios.js b/src/utils/myAxios.js index 0c60344..f2db34a 100644 --- a/src/utils/myAxios.js +++ b/src/utils/myAxios.js @@ -1,7 +1,7 @@ // src/utils/myAxios.js import axios from 'axios' import { ElMessage } from 'element-plus' -import {createRouter as router} from "vue-router"; // 假设使用 Element Plus 的提示组件(可替换为其他 UI 库) +import router from '../router/index'; // 创建 axios 实例 const myAxios = axios.create({ @@ -15,12 +15,15 @@ const myAxios = axios.create({ // 请求拦截器:添加 token、处理请求前逻辑 myAxios.interceptors.request.use( (config) => { + const isLoginApi = config.url === '/login'; // 示例:从本地存储获取 token 并添加到请求头 - const token = localStorage.getItem('token') - if (token) { - config.headers.Authorization = `Bearer ${token}` - }else { - router.push('/login') + if (!isLoginApi) { + const token = localStorage.getItem('token'); + if (token) { + config.headers.Authorization = `Bearer ${token}`; + } else { + router.push('/login'); + } } return config }, diff --git a/src/views/Login.vue b/src/views/Login.vue index 3a4e20e..c4b0f97 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -65,7 +65,7 @@ const clearErrorMsg = () => { }; // 登录逻辑:包含表单校验、消息提醒、记住密码存储 -const handleLogin = () => { +const handleLogin = async() => { // 先清空之前的错误提示 errorMsg.value = ''; @@ -83,13 +83,14 @@ const handleLogin = () => { return; } - // 模拟接口登录 - const isAccountCorrect = loginForm.value.username === '90042088'; - const isPasswordCorrect = loginForm.value.password === '123456'; - - if (isAccountCorrect && isPasswordCorrect) { - // 登录成功 - localStorage.setItem('token', '9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs'); + // 登录 + const data = await loginApi({ + username: Number(loginForm.value.username), + password: loginForm.value.password, + app_from: 'en' + }); + if( data ){ + localStorage.setItem('token', data.token); // 处理“记住密码”存储 if (loginForm.value.remember) { localStorage.setItem('deepchart_login', JSON.stringify({