保存进度!
This commit is contained in:
29
code/web/IT工具综合平台/src/utils/api/common.js
Normal file
29
code/web/IT工具综合平台/src/utils/api/common.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-22 17:16:53
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-12-22 20:48:03
|
||||
* @FilePath: \admin_system\src\utils\api\common.js
|
||||
* @Description: 通用请求
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
//import axios from "axios";
|
||||
import instance from "@utils/request";
|
||||
|
||||
const URL_GET_VALIDATE_CODE = "";
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
export function GetValidate(data)
|
||||
{
|
||||
return instance.request(
|
||||
{
|
||||
method: "post",
|
||||
url: URL_GET_VALIDATE_CODE,
|
||||
data,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
14
code/web/IT工具综合平台/src/utils/api/config.js
Normal file
14
code/web/IT工具综合平台/src/utils/api/config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-23 11:10:23
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-12-23 11:11:58
|
||||
* @FilePath: \admin_system\src\utils\api\config.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
|
||||
export const API_URL = {
|
||||
URL_LOGIN: process.env.VUE_APP_API_URL_LOGIN,
|
||||
};
|
45
code/web/IT工具综合平台/src/utils/api/info/account.js
Normal file
45
code/web/IT工具综合平台/src/utils/api/info/account.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-22 09:10:20
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-25 00:29:54
|
||||
* @FilePath: \admin_system\src\utils\api\info\account.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
import instance from "@/utils/api/request";
|
||||
import { API_URL } from "@/utils/api/config"; //所有API的地址
|
||||
import router from "../../../router/index";
|
||||
import store from "../../../store/index";
|
||||
|
||||
/**
|
||||
* 登录请求函数
|
||||
* @param {*} userInfo
|
||||
* @returns 返回promise对象
|
||||
*/
|
||||
export function Login(userInfo)
|
||||
{
|
||||
//console.log("登录请求地址:", API_URL.URL_LOGIN);
|
||||
//const url = "http://localhost:8080/admin-system/account/p13_account_check";
|
||||
return instance.request(
|
||||
{
|
||||
method: "post",
|
||||
url: API_URL.URL_LOGIN,
|
||||
data: userInfo,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
export function Logout()
|
||||
{
|
||||
console.log(store);
|
||||
|
||||
window.localStorage.removeItem("token");
|
||||
window.localStorage.removeItem("user_info");
|
||||
|
||||
router.replace("/login");
|
||||
}
|
95
code/web/IT工具综合平台/src/utils/api/request.js
Normal file
95
code/web/IT工具综合平台/src/utils/api/request.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-22 17:18:10
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-12 17:47:39
|
||||
* @FilePath: \admin_system\src\utils\api\request.js
|
||||
* @Description: 配置axios拦截器
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
import axios from "axios";
|
||||
import store from "../../store/index";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
import router from "@/router";
|
||||
|
||||
const service = axios.create(
|
||||
{
|
||||
baseURL: "",
|
||||
timeout: 5000,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* 加上请求拦截器
|
||||
*/
|
||||
service.interceptors.request.use(
|
||||
function (config)
|
||||
{
|
||||
//axios拦截器请求,在请求的header加上用户名和token
|
||||
if (store.state.app.userInfo)
|
||||
{
|
||||
//如果userInfo存在,则加上用户名和token
|
||||
const username = store.state.app.userInfo.user_info.p13uid;
|
||||
const token = store.state.app.userInfo.token;
|
||||
|
||||
config.headers["token"] = token;
|
||||
config.headers["username"] = username;
|
||||
|
||||
console.log("拦截器,加上username和token!", username, token);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("拦截器,userinfo为空!");
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
function (error)
|
||||
{
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
//响应拦截器
|
||||
service.interceptors.response.use(
|
||||
function (response)
|
||||
{
|
||||
//200
|
||||
if (response.status === 200)
|
||||
{
|
||||
console.log("响应拦截器,响应代码", response.status);
|
||||
}
|
||||
|
||||
//401,用户token失效,跳转到
|
||||
if (response.state === 401)
|
||||
{
|
||||
ElMessageBox.confirm(
|
||||
"用户登录超时,请重新登录",
|
||||
"警告",
|
||||
{
|
||||
confirmButtonText: "是",
|
||||
cancelButtonText: "否",
|
||||
type: "warning",
|
||||
},
|
||||
).then(() =>
|
||||
{
|
||||
router.replace("/login");
|
||||
}).catch(() =>
|
||||
{
|
||||
router.replace("/login");
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
},
|
||||
function (error)
|
||||
{
|
||||
console.log("响应拦截器,异常信息:", error);
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
Reference in New Issue
Block a user