|
|
@@ -1,7 +1,6 @@
|
|
|
-
|
|
|
-import '@unocss/reset/sanitize/sanitize.css';
|
|
|
-import { message } from 'antd';
|
|
|
-import type { RequestConfig } from 'umi';
|
|
|
+import "@unocss/reset/sanitize/sanitize.css";
|
|
|
+import { message } from "antd";
|
|
|
+import type { RequestConfig } from "umi";
|
|
|
|
|
|
// 与后端约定的响应数据格式
|
|
|
interface ResponseStructure {
|
|
|
@@ -18,19 +17,19 @@ export const request: RequestConfig = {
|
|
|
timeout: 10000,
|
|
|
// other axios options you want
|
|
|
errorConfig: {
|
|
|
- errorThrower(res){
|
|
|
+ errorThrower(res) {
|
|
|
const { code, error: errorMsg, errorCode, isSuccess } = res;
|
|
|
if (!isSuccess) {
|
|
|
const error: any = new Error(errorMsg);
|
|
|
- error.name = 'BizError';
|
|
|
+ error.name = "BizError";
|
|
|
error.info = { errorCode, errorMessage: errorMsg };
|
|
|
throw error; // 抛出自制的错误
|
|
|
}
|
|
|
},
|
|
|
- errorHandler(error: any, opts: any){
|
|
|
+ errorHandler(error: any, opts: any) {
|
|
|
if (opts?.skipErrorHandler) throw error;
|
|
|
// 我们的 errorThrower 抛出的错误。
|
|
|
- if (error.name === 'BizError') {
|
|
|
+ if (error.name === "BizError") {
|
|
|
const errorInfo: ResponseStructure | undefined = error.info;
|
|
|
if (errorInfo) {
|
|
|
const { error: errorMessage } = errorInfo;
|
|
|
@@ -44,42 +43,49 @@ export const request: RequestConfig = {
|
|
|
// 请求已经成功发起,但没有收到响应
|
|
|
// \`error.request\` 在浏览器中是 XMLHttpRequest 的实例,
|
|
|
// 而在node.js中是 http.ClientRequest 的实例
|
|
|
- message.error('请求无响应,请稍后再试!');
|
|
|
+ message.error("请求无响应,请稍后再试!");
|
|
|
} else {
|
|
|
// 发送请求时出了点问题
|
|
|
- message.error(error || '请求错误,请稍后再试!');
|
|
|
+ message.error(error || "请求错误,请稍后再试!");
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
requestInterceptors: [
|
|
|
(url, options) => {
|
|
|
- const baseUrl = process.env.NODE_ENV === 'production' ? '' : '/api'//'http://ab.dev.jbpm.shalu.com' // https://edesign.shalu.com'
|
|
|
+ const baseUrl = process.env.NODE_ENV === "production" ? "" : "/api"; //'http://ab.dev.jbpm.shalu.com' // https://edesign.shalu.com'
|
|
|
// const enterpriseCode = sessionStorage.getItem('enterpriseCode');
|
|
|
- const enterpriseCode = 'a';
|
|
|
- const token = localStorage.getItem('token_' + enterpriseCode);
|
|
|
-
|
|
|
- if(token) {
|
|
|
- if(!options.headers) {
|
|
|
- options.headers = {}
|
|
|
+ const enterpriseCode = "a";
|
|
|
+ const token = localStorage.getItem("token_" + enterpriseCode);
|
|
|
+
|
|
|
+ if (token) {
|
|
|
+ if (!options.headers) {
|
|
|
+ options.headers = {};
|
|
|
}
|
|
|
- options.headers.Authorization = token
|
|
|
+ options.headers.Authorization = token;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
url: baseUrl + url,
|
|
|
- options
|
|
|
- }
|
|
|
- }
|
|
|
+ options,
|
|
|
+ };
|
|
|
+ },
|
|
|
],
|
|
|
responseInterceptors: [
|
|
|
(response) => {
|
|
|
- const {data = {} as any, config} = response;
|
|
|
- if(data?.error) {
|
|
|
+ // ai路径跳转
|
|
|
+ const { data = {} as any, config } = response;
|
|
|
+ if (data?.isAuthorized === false && config.url?.includes('/api/ai')) {
|
|
|
+ const url = window?.parent
|
|
|
+ ? `/Account?ReturnUrl=${window.parent.location.pathname}`
|
|
|
+ : `/Account?ReturnUrl=/App/SysPages/views/system/appstore/index.html${location.hash}`;
|
|
|
+ (window?.parent || window).open(url, "_self");
|
|
|
+ }
|
|
|
+ if (data?.error) {
|
|
|
// message.error(data.error);
|
|
|
return Promise.reject(data.error);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return response;
|
|
|
- }
|
|
|
- ]
|
|
|
-};
|
|
|
+ },
|
|
|
+ ],
|
|
|
+};
|