|
@@ -4,6 +4,18 @@ import { message } from "antd";
|
|
|
import { NoticeType } from "antd/es/message/interface";
|
|
|
import { ResponseStatusCode } from "./types";
|
|
|
|
|
|
+/**
|
|
|
+ * 定义请求元数据
|
|
|
+ */
|
|
|
+declare global {
|
|
|
+ interface DageRequestMeta {
|
|
|
+ /**
|
|
|
+ * 显示全局 错误信息, 默认为 false
|
|
|
+ */
|
|
|
+ showError?: boolean;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const showMessage = (msg: string, type: NoticeType = "error") => {
|
|
|
message.open({
|
|
|
type,
|
|
@@ -26,6 +38,7 @@ initial({
|
|
|
// 登陆失效
|
|
|
async (request, next) => {
|
|
|
const response = await next();
|
|
|
+ const { showError = true } = request.meta;
|
|
|
|
|
|
if (
|
|
|
[
|
|
@@ -36,6 +49,13 @@ initial({
|
|
|
showMessage("登录失效!");
|
|
|
removeTokenInfo();
|
|
|
globalThis.location.href = "#/login";
|
|
|
+ } else if (response.code !== ResponseStatusCode.SUCCESS) {
|
|
|
+ const message = response.__raw__.data.msg ?? "系统出差中";
|
|
|
+ // 错误信息映射
|
|
|
+ response.errorMessage = message;
|
|
|
+ if (showError) {
|
|
|
+ showMessage(message);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return response;
|