Browse Source

登录方法

milestone-20251117-DeepChart后台一期
liruiqiang 2 months ago
parent
commit
8ad910d8bb
  1. 2
      .env.development
  2. 2
      .env.test
  3. 11
      src/utils/myAxios.js
  4. 17
      src/views/Login.vue

2
.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"
VITE_API_BASE_URL_LINK = "http://39.101.133.168:8828"

2
.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"

11
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 (!isLoginApi) {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`
config.headers.Authorization = `Bearer ${token}`;
} else {
router.push('/login')
router.push('/login');
}
}
return config
},

17
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({

Loading…
Cancel
Save