gant-core 0.1.28 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1984,6 +1984,7 @@ interface GlobalOptions {
1984
1984
  base?: string;
1985
1985
  menuData?: ServerMenuData | ((res: UserAggregateInfo) => ServerMenuData);
1986
1986
  loginSuccessCallback?: () => void;
1987
+ ssoCallback?: () => boolean;
1987
1988
  }
1988
1989
 
1989
1990
  declare const MENU_HISTORY_UPDATE = "MENU_HISTORY_UPDATE";
@@ -2065,7 +2066,7 @@ declare class BaseLogin {
2065
2066
  declare class SSOLogin {
2066
2067
  init(ssoConfig?: SSOConfigType): void;
2067
2068
  private ssoConfig;
2068
- isSso: () => Promise<boolean>;
2069
+ isSso: (ssoCallback?: () => boolean) => Promise<boolean>;
2069
2070
  ssoLogin: () => boolean;
2070
2071
  ssoLoginOut: () => void;
2071
2072
  }
@@ -2080,8 +2081,9 @@ declare class LoginStore extends BaseLogin {
2080
2081
  ssoLogin: SSOLogin;
2081
2082
  validate: ValidateLogin;
2082
2083
  noCheckPermissionsPath?: string[];
2084
+ ssoCallback?: () => boolean;
2083
2085
  constructor();
2084
- init: (loginConfig?: LOGIN_CONFIG, base?: string) => void;
2086
+ init: (loginConfig?: LOGIN_CONFIG, base?: string, ssoCallback?: () => boolean) => void;
2085
2087
  isNoLoginRequiredPage: () => boolean;
2086
2088
  loginOut: () => Promise<void>;
2087
2089
  loginAuthentication: (params: BeforeLoginCheckCodeParams) => Promise<void>;
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios__default from 'axios';
2
2
  export * from 'axios';
3
- import { forEach, groupBy, reduce, find, pick, get as get$1, uniqueId, omit, isEmpty, findIndex, cloneDeep, mapValues, uniqBy, toLower, isObject, mergeWith, has, join } from 'lodash-es';
3
+ import { forEach, groupBy, reduce, find, pick, get as get$1, uniqueId, omit, isEmpty, findIndex, isPlainObject, cloneDeep, mapValues, uniqBy, toLower, isObject, mergeWith, has, join } from 'lodash-es';
4
4
  import mitt from 'mitt';
5
5
 
6
6
  class InterceptorManager {
@@ -723,7 +723,7 @@ class UserStore {
723
723
  const userInfo = userLoginName
724
724
  ? await getUserByUserLoginNameApi(userId)
725
725
  : await getUserByIdApi(userId);
726
- this.users.push(userInfo);
726
+ isPlainObject(userInfo) && this.users.push(userInfo);
727
727
  return userInfo;
728
728
  };
729
729
  }
@@ -1045,28 +1045,31 @@ class BaseLogin {
1045
1045
 
1046
1046
  const defaultSsoConfig = {
1047
1047
  sso: false,
1048
- ssoUrlSearchParams: ['ticket'],
1049
- ssoCheckTokenUrl: '',
1050
- ssoSuccessUrlkey: 'successUrl',
1051
- ssoLoginUrl: window.location.origin + '/fwSecurity/ssoAuth/login.api',
1052
- ssologinOutUrl: window.location.origin + 'fwSecurity/ssoAuth/logout.api',
1048
+ ssoUrlSearchParams: ["ticket"],
1049
+ ssoCheckTokenUrl: "",
1050
+ ssoSuccessUrlkey: "successUrl",
1051
+ ssoLoginUrl: window.location.origin + "/fwSecurity/ssoAuth/login.api",
1052
+ ssologinOutUrl: window.location.origin + "fwSecurity/ssoAuth/logout.api",
1053
1053
  };
1054
1054
  class SSOLogin {
1055
1055
  init(ssoConfig) {
1056
1056
  this.ssoConfig = { ...this.ssoConfig, ...ssoConfig };
1057
1057
  }
1058
1058
  ssoConfig = defaultSsoConfig;
1059
- isSso = async () => {
1059
+ isSso = async (ssoCallback) => {
1060
1060
  if (!this.ssoConfig.sso)
1061
- return;
1061
+ return false;
1062
+ let sso = false;
1062
1063
  try {
1063
- const onlyRedirect = await checkAuthConfigApi();
1064
- return !!onlyRedirect;
1064
+ sso = await checkAuthConfigApi();
1065
1065
  }
1066
1066
  catch (error) {
1067
- console.error('sso', error);
1067
+ console.error("sso", error);
1068
1068
  }
1069
- return false;
1069
+ if (ssoCallback) {
1070
+ sso = await ssoCallback();
1071
+ }
1072
+ return !!sso;
1070
1073
  };
1071
1074
  ssoLogin = () => {
1072
1075
  //在检测cookie中是否包含userIdentity信息
@@ -1105,16 +1108,18 @@ class LoginStore extends BaseLogin {
1105
1108
  ssoLogin;
1106
1109
  validate;
1107
1110
  noCheckPermissionsPath = [];
1111
+ ssoCallback;
1108
1112
  constructor() {
1109
1113
  super();
1110
1114
  this.ssoLogin = new SSOLogin();
1111
1115
  this.validate = new ValidateLogin();
1112
1116
  }
1113
- init = (loginConfig, base = '/') => {
1117
+ init = (loginConfig, base = "/", ssoCallback) => {
1114
1118
  this.BASE = base;
1119
+ this.ssoCallback = ssoCallback;
1115
1120
  this.noCheckPermissionsPath = loginConfig?.noCheckPermissionsPath;
1116
1121
  this.ssoLogin.init(loginConfig);
1117
- this.loginPathname = loginConfig?.loginPathname || '/login';
1122
+ this.loginPathname = loginConfig?.loginPathname || "/login";
1118
1123
  };
1119
1124
  isNoLoginRequiredPage = () => {
1120
1125
  const pathname = window.location.pathname;
@@ -1124,7 +1129,7 @@ class LoginStore extends BaseLogin {
1124
1129
  return isNoLogin;
1125
1130
  };
1126
1131
  loginOut = async () => {
1127
- const isSSO = await this.ssoLogin.isSso();
1132
+ const isSSO = await this.ssoLogin.isSso(this.ssoCallback);
1128
1133
  if (isSSO)
1129
1134
  this.ssoLogin.ssoLoginOut();
1130
1135
  await this.baseLoginOut();
@@ -1137,7 +1142,7 @@ class LoginStore extends BaseLogin {
1137
1142
  redirectLogin = async () => {
1138
1143
  if (this.isNoLoginRequiredPage())
1139
1144
  return true;
1140
- const isSSO = await this.ssoLogin.isSso();
1145
+ const isSSO = await this.ssoLogin.isSso(this.ssoCallback);
1141
1146
  if (isSSO) {
1142
1147
  this.ssoLogin.ssoLogin();
1143
1148
  return false;
@@ -1188,8 +1193,8 @@ class GlobalStoreClass {
1188
1193
  this.menuStore.init(isEmpty(localeMenus) ? startMenus : localeMenus, currentUser.id);
1189
1194
  };
1190
1195
  init = async (options) => {
1191
- const { base = "/", menuData, loginSuccessCallback } = options;
1192
- this.loginStore.init(options?.loginConfig, base);
1196
+ const { base = "/", menuData, loginSuccessCallback, ssoCallback } = options;
1197
+ this.loginStore.init(options?.loginConfig, base, ssoCallback);
1193
1198
  try {
1194
1199
  //检查token
1195
1200
  const res = await this.loginStore.chekToken();