feat: 接入 UserHome 前端业务代码(含真实 src/依赖,保留 projman 标准 CI)
This commit is contained in:
@@ -85,6 +85,71 @@ class Abstract {
|
||||
protected deleteRequest<T>({ url, params, data, isMsg = true }: BschResult): Promise<T> {
|
||||
return this.apiAxios<T>({ method: "DELETE", url, params, data, isMsg });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get转发类型的网络请求
|
||||
* @param
|
||||
* @returns
|
||||
*/
|
||||
protected getRelayRequest<T>({ baseHost, url, params }: any): Promise<T> {
|
||||
const tempConfig = _.cloneDeep(baseConfig);
|
||||
const header = tempConfig.headers;
|
||||
|
||||
tempConfig.headers = {
|
||||
...header,
|
||||
RelayUrl: baseHost + url,
|
||||
};
|
||||
const instance = initAxiosInstance(tempConfig);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
instance({
|
||||
method: "GET",
|
||||
url: "/api/relay/doGet",
|
||||
params,
|
||||
})
|
||||
.then(res => {
|
||||
let { data } = res;
|
||||
resolve(data as T);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
// throw err;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Post转发类型的网络请求
|
||||
* @param
|
||||
* @returns
|
||||
*/
|
||||
protected postRelayRequest<T>({ baseHost, url, params, data }: any): Promise<T> {
|
||||
const tempConfig = _.cloneDeep(baseConfig);
|
||||
const header = tempConfig.headers;
|
||||
tempConfig.headers = {
|
||||
...header,
|
||||
RelayUrl: baseHost + url,
|
||||
};
|
||||
const instance = initAxiosInstance(tempConfig);
|
||||
let apiUrl = !!data ? "/api/relay/doPost" : "/api/relay/doPost2";
|
||||
return new Promise((resolve, reject) => {
|
||||
instance({
|
||||
method: "POST",
|
||||
url: apiUrl,
|
||||
params,
|
||||
data,
|
||||
})
|
||||
.then(res => {
|
||||
let { data } = res.data;
|
||||
console.log(data);
|
||||
resolve(data as T);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
// throw err;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Abstract;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { AxiosResponse, BschResponse } from "axios";
|
||||
|
||||
function formrHandle(response: AxiosResponse) {
|
||||
let errorMsg: string = "";
|
||||
let { data, status } = response;
|
||||
@@ -14,7 +13,6 @@ function formrHandle(response: AxiosResponse) {
|
||||
errorMsg = "redirect";
|
||||
window.location.href = data.urlToRedirectTo;
|
||||
break;
|
||||
// errorMsg = "redirect";
|
||||
default:
|
||||
errorMsg = data.msg;
|
||||
}
|
||||
|
||||
@@ -2,25 +2,24 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosRequestHe
|
||||
import formrHandle from "./format-handle";
|
||||
import { debugUser } from "@/assets/config/api.config";
|
||||
import conf from "@/assets/config/host.config";
|
||||
import Utils from "@/utils";
|
||||
|
||||
export const initAxiosInstance: (config: AxiosRequestConfig) => AxiosInstance = config => {
|
||||
let axiosInstance: AxiosInstance = axios.create(config);
|
||||
|
||||
axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {
|
||||
// if (config.params && typeof config.params != "string") config.params = utils.filterNull(config.params);
|
||||
// 通用请求头:yschapirequest 标识 API 请求,yschreferer 记录来源页面(十六进制)
|
||||
(config.headers as AxiosRequestHeaders)["yschapirequest"] = "1";
|
||||
(config.headers as AxiosRequestHeaders)["yschreferer"] = Utils.strToHexCharCode(window.location.href);
|
||||
|
||||
if (localStorage.getItem("currentRole") != null) {
|
||||
(config.headers as AxiosRequestHeaders)["currentRole"] = localStorage.getItem("currentRole") as string;
|
||||
}
|
||||
//@ts-ignore
|
||||
const bschUtil = BschLoadUtil.getInstance();
|
||||
if (!bschUtil.getIsSelf()) {
|
||||
(config.headers as AxiosRequestHeaders)["ticket"] = sessionStorage.getItem("bschTicket") as string;
|
||||
(config.headers as AxiosRequestHeaders)["platform"] = "grzx";
|
||||
}
|
||||
|
||||
if (!!conf.isDebug) {
|
||||
//如果是开发环境
|
||||
for (const key in debugUser) (config.headers as AxiosRequestHeaders)[key] = (debugUser as any)[key];
|
||||
// (config.headers as AxiosRequestHeaders)["yschapirequest"] = "1";
|
||||
}
|
||||
|
||||
return config;
|
||||
@@ -32,7 +31,7 @@ export const initAxiosInstance: (config: AxiosRequestConfig) => AxiosInstance =
|
||||
},
|
||||
error => {
|
||||
return formrHandle(error.response);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return axiosInstance;
|
||||
|
||||
Vendored
+13
-13
@@ -2,22 +2,22 @@ import * as axios from "axios";
|
||||
|
||||
declare module "axios" {
|
||||
// 定制业务相关的网络请求响应格式, T 是具体的接口返回类型数据
|
||||
// export interface BschResponse<T> {
|
||||
// code: number;
|
||||
// msg?: string;
|
||||
// data?: T;
|
||||
// [keys: string]: any; //任意属性
|
||||
// }
|
||||
|
||||
export interface BschResponse {
|
||||
State: boolean;
|
||||
Data: any;
|
||||
Message: string;
|
||||
OtherData: any;
|
||||
Page: any;
|
||||
export interface BschResponse<T> {
|
||||
code: number;
|
||||
msg?: string;
|
||||
data?: T;
|
||||
[keys: string]: any; //任意属性
|
||||
}
|
||||
|
||||
// export interface BschResponse {
|
||||
// State: boolean;
|
||||
// Data: any;
|
||||
// Message: string;
|
||||
// OtherData: any;
|
||||
// Page: any;
|
||||
// [keys: string]: any; //任意属性
|
||||
// }
|
||||
|
||||
export interface BschResult {
|
||||
url: string;
|
||||
params?: object;
|
||||
|
||||
Reference in New Issue
Block a user