2 changed files with 0 additions and 75 deletions
@ -1,48 +0,0 @@
|
||||
import axios from "axios"; |
||||
const token=sessionStorage.getItem("token") |
||||
const requst=axios.create({ |
||||
baseURL:"http://121.36.37.70:8906/", |
||||
timeout: 60000, // 请求超时时间毫秒
|
||||
withCredentials: true, // 异步请求携带cookie
|
||||
headers: { |
||||
// 设置后端需要的传参类型
|
||||
'Content-Type': 'application/json', |
||||
'Authorization': 'Bearer '+token, |
||||
'X-Requested-With': 'XMLHttpRequest', |
||||
}, |
||||
|
||||
}) |
||||
|
||||
// 添加请求拦截器
|
||||
requst.interceptors.request.use( |
||||
function (config) { |
||||
// 在发送请求之前做些什么
|
||||
return config |
||||
}, |
||||
function (error) { |
||||
// 对请求错误做些什么
|
||||
console.log(error) |
||||
return Promise.reject(error) |
||||
} |
||||
) |
||||
|
||||
// 添加响应拦截器
|
||||
requst.interceptors.response.use( |
||||
function (response) { |
||||
// console.log(response)
|
||||
// 2xx 范围内的状态码都会触发该函数。
|
||||
// 对响应数据做点什么
|
||||
// dataAxios 是 axios 返回数据中的 data
|
||||
const dataAxios = response.data |
||||
// 这个状态码是和后端约定的
|
||||
const code = dataAxios.reset |
||||
return dataAxios |
||||
}, |
||||
function (error) { |
||||
// 超出 2xx 范围的状态码都会触发该函数。
|
||||
// 对响应错误做点什么
|
||||
console.log(error) |
||||
return Promise.reject(error) |
||||
} |
||||
) |
||||
export default requst |
@ -1,27 +0,0 @@
|
||||
// 导入axios实例
|
||||
import httpRequest from "./index"; |
||||
|
||||
// 定义接口的传参
|
||||
interface UserInfoParam { |
||||
userNameOrEmailAddress: string; |
||||
password: string; |
||||
} |
||||
|
||||
// 获取用户信息
|
||||
export function apiGetToken(param: UserInfoParam) { |
||||
return httpRequest({ |
||||
url: "/api/TokenAuth/Authenticate", |
||||
method: "post", |
||||
data: param, |
||||
}); |
||||
} |
||||
|
||||
export function apiGetUserInfo() { |
||||
return httpRequest({ |
||||
url: "/api/services/app/Session/GetCurrentLoginInformations", |
||||
method: "get", |
||||
data: null, |
||||
}); |
||||
} |
||||
export default apiGetUserInfo; |
||||
apiGetToken; |
Loading…
Reference in new issue