同步操作将从 Bill/quick-admin 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import type { RequestOptions } from '@@/plugin-request/request';import type { RequestConfig } from '@umijs/max';import { message, notification } from 'antd';// 错误处理方案: 错误类型enum ErrorShowType {SILENT = 0,WARN_MESSAGE = 1,ERROR_MESSAGE = 2,NOTIFICATION = 3,REDIRECT = 9,}// 与后端约定的响应数据格式interface ResponseStructure {status?: number;data: any;msg?: string;showType?: ErrorShowType;}/*** @name 错误处理* pro 自带的错误处理, 可以在这里做自己的改动* @doc https://umijs.org/docs/max/request#配置*/export const errorConfig: RequestConfig = {// 错误处理: umi@3 的错误处理方案。errorConfig: {// 错误抛出errorThrower: (res) => {//const { success, data, errorCode, errorMessage, showType } =const { status, data, msg, showType} =res as unknown as ResponseStructure;if (status!==0) {const error: any = new Error(msg);error.name = 'BizError';error.info = { status, msg, data, showType};throw error; // 抛出自制的错误}},// 错误接收及处理errorHandler: (error: any, opts: any) => {if (opts?.skipErrorHandler) throw error;// 我们的 errorThrower 抛出的错误。if (error.name === 'BizError') {const errorInfo: ResponseStructure | undefined = error.info;if (errorInfo) {const { msg, status } = errorInfo;switch (errorInfo.showType) {case ErrorShowType.SILENT:// do nothingbreak;case ErrorShowType.WARN_MESSAGE:message.warning(msg);break;case ErrorShowType.ERROR_MESSAGE:message.error(msg);break;case ErrorShowType.NOTIFICATION:notification.open({description: msg,message: status,});break;case ErrorShowType.REDIRECT:// TODO: redirectbreak;default:message.error(msg);}}} else if (error.response) {// Axios 的错误// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围message.error(`Response status:${error.response.status}`);} else if (error.request) {// 请求已经成功发起,但没有收到响应// \`error.request\` 在浏览器中是 XMLHttpRequest 的实例,// 而在node.js中是 http.ClientRequest 的实例message.error('None response! Please retry.');} else {// 发送请求时出了点问题message.error('Request error, please retry.');}},},// 请求拦截器requestInterceptors: [(config: RequestOptions) => {// 拦截请求配置,进行个性化处理。const url = config?.url;const tenant = localStorage.getItem("X-Tenant-Id")const token = localStorage.getItem('X-Access-Token');config.headers = { ...config?.headers, "X-Tenant-Id": tenant??"1" };config.headers = { ...config?.headers, "X-Access-Token": token };return { ...config, url };},],// 响应拦截器responseInterceptors: [(response) => {// 拦截响应数据,进行个性化处理const { data } = response as unknown as ResponseStructure;if (data?.status !== 0) {message.error('请求失败!');}return response;},],};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。