@allahjs/utils 1.8.0 → 1.10.0
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/dist/.tsbuildinfo +1 -1
- package/dist/browser/domUtils/index.cjs +102 -0
- package/dist/browser/domUtils/index.cjs.map +1 -1
- package/dist/browser/domUtils/index.d.ts +24 -0
- package/dist/core/constants/asyncTaskScheduleVo.d.ts +98 -0
- package/dist/core/constants/comm.cjs +25 -0
- package/dist/core/constants/comm.cjs.map +1 -0
- package/dist/core/constants/comm.d.ts +309 -0
- package/dist/core/constants/defaultData.cjs +16 -0
- package/dist/core/constants/defaultData.cjs.map +1 -0
- package/dist/core/constants/defaultData.d.ts +8 -0
- package/dist/core/constants/index.cjs +22 -0
- package/dist/core/constants/index.cjs.map +1 -0
- package/dist/core/constants/index.d.ts +4 -0
- package/dist/core/constants/systemEnum.cjs +25 -0
- package/dist/core/constants/systemEnum.cjs.map +1 -0
- package/dist/core/constants/systemEnum.d.ts +22 -0
- package/dist/core/dateUtils/index.cjs +46 -1
- package/dist/core/dateUtils/index.cjs.map +1 -1
- package/dist/core/dateUtils/index.d.ts +21 -1
- package/dist/core/index.cjs +19 -17
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +10 -0
- package/dist/core/storageUtils/index.cjs +135 -0
- package/dist/core/storageUtils/index.cjs.map +1 -0
- package/dist/core/storageUtils/index.d.ts +54 -0
- package/dist/esm/browser/domUtils/index.d.ts +24 -0
- package/dist/esm/browser/domUtils/index.js +102 -0
- package/dist/esm/browser/domUtils/index.js.map +1 -1
- package/dist/esm/core/constants/asyncTaskScheduleVo.d.ts +98 -0
- package/dist/esm/core/constants/comm.d.ts +309 -0
- package/dist/esm/core/constants/comm.js +25 -0
- package/dist/esm/core/constants/comm.js.map +1 -0
- package/dist/esm/core/constants/defaultData.d.ts +8 -0
- package/dist/esm/core/constants/defaultData.js +14 -0
- package/dist/esm/core/constants/defaultData.js.map +1 -0
- package/dist/esm/core/constants/index.d.ts +4 -0
- package/dist/esm/core/constants/index.js +4 -0
- package/dist/esm/core/constants/index.js.map +1 -0
- package/dist/esm/core/constants/systemEnum.d.ts +22 -0
- package/dist/esm/core/constants/systemEnum.js +25 -0
- package/dist/esm/core/constants/systemEnum.js.map +1 -0
- package/dist/esm/core/dateUtils/index.d.ts +21 -1
- package/dist/esm/core/dateUtils/index.js +46 -2
- package/dist/esm/core/dateUtils/index.js.map +1 -1
- package/dist/esm/core/index.d.ts +10 -0
- package/dist/esm/core/index.js +3 -1
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/storageUtils/index.d.ts +54 -0
- package/dist/esm/core/storageUtils/index.js +131 -0
- package/dist/esm/core/storageUtils/index.js.map +1 -0
- package/dist/esm/form/index.d.ts +1 -0
- package/dist/esm/form/index.js +2 -0
- package/dist/esm/form/index.js.map +1 -0
- package/dist/esm/form/types.d.ts +878 -0
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/data/index.d.ts +22 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/umijs/index.d.ts +1 -0
- package/dist/esm/umijs/index.js +2 -0
- package/dist/esm/umijs/index.js.map +1 -0
- package/dist/esm/umijs/initialUmiState.d.ts +148 -0
- package/dist/esm/umijs/initialUmiState.js +107 -0
- package/dist/esm/umijs/initialUmiState.js.map +1 -0
- package/dist/form/index.cjs +3 -0
- package/dist/form/index.cjs.map +1 -0
- package/dist/form/index.d.ts +1 -0
- package/dist/form/types.d.ts +878 -0
- package/dist/index.cjs +49 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/types/data/index.d.ts +22 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/umijs/index.cjs +13 -0
- package/dist/umijs/index.cjs.map +1 -0
- package/dist/umijs/index.d.ts +1 -0
- package/dist/umijs/initialUmiState.cjs +114 -0
- package/dist/umijs/initialUmiState.cjs.map +1 -0
- package/dist/umijs/initialUmiState.d.ts +148 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index$
|
|
3
|
+
var index$g = require('./core/stringUtils/index.cjs');
|
|
4
4
|
var index$1 = require('./core/arrayUtils/index.cjs');
|
|
5
|
-
var index$
|
|
6
|
-
var index$
|
|
7
|
-
var index$
|
|
8
|
-
var index$
|
|
5
|
+
var index$e = require('./core/objectUtils/index.cjs');
|
|
6
|
+
var index$9 = require('./core/dateUtils/index.cjs');
|
|
7
|
+
var index$d = require('./core/numberUtils/index.cjs');
|
|
8
|
+
var index$i = require('./core/validationUtils/index.cjs');
|
|
9
9
|
var index$2 = require('./core/asyncUtils/index.cjs');
|
|
10
10
|
var index$4 = require('./core/colorUtils/index.cjs');
|
|
11
|
-
var index$
|
|
12
|
-
var index$
|
|
13
|
-
var index$
|
|
14
|
-
var index$5 = require('./
|
|
15
|
-
var index$
|
|
11
|
+
var index$8 = require('./core/cryptoUtils/index.cjs');
|
|
12
|
+
var index$b = require('./core/pageUtils/index.cjs');
|
|
13
|
+
var index$f = require('./core/storageUtils/index.cjs');
|
|
14
|
+
var index$5 = require('./core/constants/index.cjs');
|
|
15
|
+
var index$c = require('./browser/domUtils/index.cjs');
|
|
16
|
+
var index$6 = require('./browser/cookieUtils/index.cjs');
|
|
17
|
+
var index$h = require('./browser/urlUtils/index.cjs');
|
|
16
18
|
var request_index = require('./request/index.cjs');
|
|
17
|
-
var index$
|
|
19
|
+
var index$7 = require('./uniapp/uniUtils/index.cjs');
|
|
18
20
|
var index = require('./uniapp/Tips/index.cjs');
|
|
19
21
|
var index$3 = require('./uniapp/cloudUtils/index.cjs');
|
|
20
|
-
var
|
|
22
|
+
var initialUmiState = require('./umijs/initialUmiState.cjs');
|
|
23
|
+
var index$a = require('./types/data/index.cjs');
|
|
21
24
|
|
|
22
25
|
// 主入口文件 - 导出所有工具函数
|
|
23
26
|
// 核心工具函数(适用于 Node.js、UniApp、React Native 等)
|
|
24
27
|
// 版本信息
|
|
25
28
|
const version = '1.0.0';
|
|
26
29
|
|
|
27
|
-
exports.stringUtils = index$
|
|
30
|
+
exports.stringUtils = index$g.default;
|
|
28
31
|
exports.arrayUtils = index$1.default;
|
|
29
|
-
exports.objectUtils = index$
|
|
30
|
-
exports.dateUtils = index$
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
32
|
+
exports.objectUtils = index$e.default;
|
|
33
|
+
exports.dateUtils = index$9.default;
|
|
34
|
+
exports.templateObj = index$9.templateObj;
|
|
35
|
+
exports.numberUtils = index$d.default;
|
|
36
|
+
exports.validationUtils = index$i.default;
|
|
33
37
|
exports.asyncUtils = index$2.default;
|
|
34
38
|
exports.colorUtils = index$4.default;
|
|
35
|
-
exports.cryptoUtils = index$
|
|
36
|
-
exports.defTableData = index$
|
|
37
|
-
exports.pageUtils = index$
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
39
|
+
exports.cryptoUtils = index$8.default;
|
|
40
|
+
exports.defTableData = index$b.defTableData;
|
|
41
|
+
exports.pageUtils = index$b.default;
|
|
42
|
+
exports.storageUtils = index$f.default;
|
|
43
|
+
exports.constants = index$5;
|
|
44
|
+
exports.domUtils = index$c.default;
|
|
45
|
+
exports.cookieUtils = index$6.default;
|
|
46
|
+
exports.urlUtils = index$h.default;
|
|
41
47
|
exports.request = request_index.default;
|
|
42
|
-
exports.createTimestampedData = index$
|
|
43
|
-
exports.createUpdateData = index$
|
|
44
|
-
exports.deepClone = index$
|
|
45
|
-
exports.ensureArray = index$
|
|
46
|
-
exports.findById = index$
|
|
47
|
-
exports.formatDate = index$
|
|
48
|
-
exports.formatRelativeTime = index$
|
|
49
|
-
exports.handleError = index$
|
|
50
|
-
exports.handleSuccess = index$
|
|
51
|
-
exports.isDataExists = index$
|
|
52
|
-
exports.isValidFamilyMember = index$
|
|
53
|
-
exports.safeGetResponseData = index$
|
|
54
|
-
exports.validateRequiredFields = index$
|
|
48
|
+
exports.createTimestampedData = index$7.createTimestampedData;
|
|
49
|
+
exports.createUpdateData = index$7.createUpdateData;
|
|
50
|
+
exports.deepClone = index$7.deepClone;
|
|
51
|
+
exports.ensureArray = index$7.ensureArray;
|
|
52
|
+
exports.findById = index$7.findById;
|
|
53
|
+
exports.formatDate = index$7.formatDate;
|
|
54
|
+
exports.formatRelativeTime = index$7.formatRelativeTime;
|
|
55
|
+
exports.handleError = index$7.handleError;
|
|
56
|
+
exports.handleSuccess = index$7.handleSuccess;
|
|
57
|
+
exports.isDataExists = index$7.isDataExists;
|
|
58
|
+
exports.isValidFamilyMember = index$7.isValidFamilyMember;
|
|
59
|
+
exports.safeGetResponseData = index$7.safeGetResponseData;
|
|
60
|
+
exports.validateRequiredFields = index$7.validateRequiredFields;
|
|
55
61
|
exports.BatchOperationTips = index.BatchOperationTips;
|
|
56
62
|
exports.Tips = index.Tips;
|
|
57
63
|
Object.defineProperty(exports, "ToastPosition", {
|
|
@@ -83,6 +89,12 @@ exports.showToast = index.showToast;
|
|
|
83
89
|
exports.showUpdateDialog = index.showUpdateDialog;
|
|
84
90
|
exports.showWarningToast = index.showWarningToast;
|
|
85
91
|
exports.cloudUtils = index$3.cloudUtils;
|
|
86
|
-
exports.
|
|
92
|
+
exports.buildLoginPath = initialUmiState.buildLoginPath;
|
|
93
|
+
exports.getJwtToken = initialUmiState.getJwtToken;
|
|
94
|
+
exports.initialUmiState = initialUmiState.initialUmiState;
|
|
95
|
+
exports.isLogin = initialUmiState.isLogin;
|
|
96
|
+
exports.loginOk = initialUmiState.loginOk;
|
|
97
|
+
exports.toLogin = initialUmiState.toLogin;
|
|
98
|
+
exports.defBaseFilter = index$a.defBaseFilter;
|
|
87
99
|
exports.version = version;
|
|
88
100
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AAoCA;AACO,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { default as stringUtils } from './core/stringUtils/index.js';
|
|
2
2
|
export { default as arrayUtils } from './core/arrayUtils/index.js';
|
|
3
3
|
export { default as objectUtils } from './core/objectUtils/index.js';
|
|
4
|
-
export { default as dateUtils } from './core/dateUtils/index.js';
|
|
4
|
+
export { default as dateUtils, templateObj } from './core/dateUtils/index.js';
|
|
5
5
|
export { default as numberUtils } from './core/numberUtils/index.js';
|
|
6
6
|
export { default as validationUtils } from './core/validationUtils/index.js';
|
|
7
7
|
export { default as asyncUtils } from './core/asyncUtils/index.js';
|
|
8
8
|
export { default as colorUtils } from './core/colorUtils/index.js';
|
|
9
9
|
export { default as cryptoUtils } from './core/cryptoUtils/index.js';
|
|
10
10
|
export { ITablePage, defTableData, default as pageUtils } from './core/pageUtils/index.js';
|
|
11
|
+
export { default as storageUtils } from './core/storageUtils/index.js';
|
|
12
|
+
import * as index from './core/constants/index.js';
|
|
13
|
+
export { index as constants };
|
|
11
14
|
export { default as domUtils } from './browser/domUtils/index.js';
|
|
12
15
|
export { default as cookieUtils } from './browser/cookieUtils/index.js';
|
|
13
16
|
export { default as urlUtils } from './browser/urlUtils/index.js';
|
|
@@ -15,7 +18,9 @@ export { IZlResponse, default as request } from './request/index.js';
|
|
|
15
18
|
export { ExistenceValidationResponse, FamilyValidationResponse, StandardResponse, createTimestampedData, createUpdateData, deepClone, ensureArray, findById, formatDate, formatRelativeTime, handleError, handleSuccess, isDataExists, isValidFamilyMember, safeGetResponseData, validateRequiredFields } from './uniapp/uniUtils/index.js';
|
|
16
19
|
export { ActionSheetItem, ActionSheetOptions, BatchOperationTips, ModalButton, ModalOptions, Tips, ToastPosition, ToastType, hideLoading, hideToast, showActionSheet, showConfirmDialog, showDeleteConfirm, showErrorToast, showErrorToastDebounced, showErrorToastWithCallback, showInputDialog, showLoading, showLoadingWithAsync, showModal, showNetworkError, showPermissionRequest, showSuccessToast, showSuccessToastDebounced, showSuccessToastWithCallback, showToast, showUpdateDialog, showWarningToast } from './uniapp/Tips/index.js';
|
|
17
20
|
export { cloudUtils } from './uniapp/cloudUtils/index.js';
|
|
18
|
-
export {
|
|
21
|
+
export { IInitialUmiState, IInitialUmiStateParams, buildLoginPath, getJwtToken, initialUmiState, isLogin, loginOk, toLogin } from './umijs/initialUmiState.js';
|
|
22
|
+
export { FieldData, FieldError, FilterFunc, FormFieldType, FormInstance, FormItemLabelProps, FormItemProps, GetFieldsValueConfig, IDependent, IEnumObj, IEnumObjAll, IFormColumns, IJsonRuleItem, IJsonRuleListItem, ISizeType, IUploadProps, IValueType, IZlCascaderProps, IZlFormColumns, IZlFormItemProps, InternalFieldData, InternalNamePath, Meta, NamePath, ProFieldValueType, ProFieldValueTypeWithFieldProps, ProFormInstance, ProFormInstanceType, ProSchemaValueEnumMap, ProSchemaValueEnumObj, ProSchemaValueEnumType, RcFormInstance, RequiredMark, RuleType, TooltipProps, ValidateFields, ValidateOptions, ValidateStatus, WrapperTooltipProps } from './form/types.js';
|
|
23
|
+
export { IBaseFilter, IOptions, IOptions2, IOptions61, ITreeNode, IValidityNum, IWaterInfo, IWaterLives, defBaseFilter } from './types/data/index.js';
|
|
19
24
|
export { ICacheData, ICallBack, IRequestOption } from './request/typings/index.js';
|
|
20
25
|
|
|
21
26
|
declare const version = "1.0.0";
|
|
@@ -183,6 +183,27 @@ interface IWaterLives {
|
|
|
183
183
|
*/
|
|
184
184
|
reporttime: string;
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* antd的tree组件的节点数据
|
|
188
|
+
*/
|
|
189
|
+
interface ITreeNode {
|
|
190
|
+
title: string | any;
|
|
191
|
+
label: string | any;
|
|
192
|
+
key: string;
|
|
193
|
+
value: string;
|
|
194
|
+
/**
|
|
195
|
+
* 父编码
|
|
196
|
+
*/
|
|
197
|
+
pcode: string;
|
|
198
|
+
/**
|
|
199
|
+
* 是否是叶子节点 true 是叶子节点 false 不是叶子节点
|
|
200
|
+
*/
|
|
201
|
+
isLeaf: boolean;
|
|
202
|
+
other?: Record<string, any>;
|
|
203
|
+
children?: ITreeNode[];
|
|
204
|
+
loading?: boolean;
|
|
205
|
+
disabled?: boolean;
|
|
206
|
+
}
|
|
186
207
|
|
|
187
208
|
export { defBaseFilter };
|
|
188
|
-
export type { IBaseFilter, IOptions, IOptions2, IOptions61, IValidityNum, IWaterInfo, IWaterLives };
|
|
209
|
+
export type { IBaseFilter, IOptions, IOptions2, IOptions61, ITreeNode, IValidityNum, IWaterInfo, IWaterLives };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { IBaseFilter, IOptions, IOptions2, IOptions61, IValidityNum, IWaterInfo, IWaterLives, defBaseFilter } from './data/index.js';
|
|
1
|
+
export { IBaseFilter, IOptions, IOptions2, IOptions61, ITreeNode, IValidityNum, IWaterInfo, IWaterLives, defBaseFilter } from './data/index.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var initialUmiState = require('./initialUmiState.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.buildLoginPath = initialUmiState.buildLoginPath;
|
|
8
|
+
exports.getJwtToken = initialUmiState.getJwtToken;
|
|
9
|
+
exports.initialUmiState = initialUmiState.initialUmiState;
|
|
10
|
+
exports.isLogin = initialUmiState.isLogin;
|
|
11
|
+
exports.loginOk = initialUmiState.loginOk;
|
|
12
|
+
exports.toLogin = initialUmiState.toLogin;
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IInitialUmiState, IInitialUmiStateParams, buildLoginPath, getJwtToken, initialUmiState, isLogin, loginOk, toLogin } from './initialUmiState.js';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var systemEnum = require('../core/constants/systemEnum.cjs');
|
|
4
|
+
var index = require('../core/storageUtils/index.cjs');
|
|
5
|
+
|
|
6
|
+
const loginPath = '/user/login';
|
|
7
|
+
const getJwtToken = () => {
|
|
8
|
+
return sessionStorage.getItem('jwtToken') || localStorage.getItem('jwtToken');
|
|
9
|
+
};
|
|
10
|
+
// 生成登录地址
|
|
11
|
+
const buildLoginPath = (isHash, path = loginPath) => {
|
|
12
|
+
if (isHash) {
|
|
13
|
+
return `${window?.location.origin}${window?.location.pathname}#${path}`;
|
|
14
|
+
}
|
|
15
|
+
return `${window?.location.origin}${path}`;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 登录成功后跳转页面
|
|
19
|
+
* @param isHash 是否是hash
|
|
20
|
+
* @param url 地址
|
|
21
|
+
*/
|
|
22
|
+
const loginOk = (isHash, url) => {
|
|
23
|
+
if (isHash) {
|
|
24
|
+
const path = window.location.href.replace(window.location.hash, '');
|
|
25
|
+
url = `${path}#${url}`;
|
|
26
|
+
}
|
|
27
|
+
window.location.href = url;
|
|
28
|
+
};
|
|
29
|
+
const isLogin = () => {
|
|
30
|
+
return window.location.pathname.includes(loginPath);
|
|
31
|
+
};
|
|
32
|
+
// 去登录页面
|
|
33
|
+
const toLogin = (isHash, path) => {
|
|
34
|
+
if (!isLogin()) {
|
|
35
|
+
window.location.replace(buildLoginPath(isHash, path));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* <h3>初始化页面全局状态的方法</h3>
|
|
40
|
+
* <br />
|
|
41
|
+
* 当页面第一次打开的时候,会调用改方法,用于获取用户信息,并且初始化全局状态
|
|
42
|
+
* <br />
|
|
43
|
+
* 获取token的方法会从sessionStorage和localStorage中获取,如果获取不到,则会初始化空的用户信息。
|
|
44
|
+
* <br />
|
|
45
|
+
* 存储的token如果过期了,那么就会触发errCallback的回调,以便对过期的token进行处理。
|
|
46
|
+
* <br />
|
|
47
|
+
* 当然,如果页面是在白名单里面的,代码不会进行任何额外的操作。
|
|
48
|
+
* <br />
|
|
49
|
+
* 方法支持以下参数
|
|
50
|
+
* <br />
|
|
51
|
+
* @param queryCurrent 查用户信息的方法
|
|
52
|
+
* <br />
|
|
53
|
+
* @param defaultSettings 默认的全局配置
|
|
54
|
+
* <br />
|
|
55
|
+
* @param isHash 是否是hash路由
|
|
56
|
+
* <br />
|
|
57
|
+
* @param whiteReg 白名单正则
|
|
58
|
+
* <br />
|
|
59
|
+
* @param errCallback 异常的回调,一般是用户信息获取失败的时候触发
|
|
60
|
+
* <br />
|
|
61
|
+
* @param autoToLogin 是否自动跳转登录页面:默认值:true
|
|
62
|
+
* <br />
|
|
63
|
+
* @param autoLoginPath 登录页面地址 - 默认值:/user/login
|
|
64
|
+
* <br />
|
|
65
|
+
* @param defaultTheme 默认的主题配置
|
|
66
|
+
* <br />
|
|
67
|
+
* @param appInfo 应用的信息
|
|
68
|
+
*/
|
|
69
|
+
const initialUmiState = async ({ queryCurrent, defaultSettings, isHash, whiteReg = '/user/login', errCallback, autoToLogin = true, autoLoginPath = loginPath, defaultTheme = {}, appInfo = {} }) => {
|
|
70
|
+
// 白名单正则,用于判断是否需要跳转到登录页面
|
|
71
|
+
const whiteRegExp = new RegExp(whiteReg);
|
|
72
|
+
// 定义变量,判断是否是白名单地址
|
|
73
|
+
const fetchUserInfo = async () => {
|
|
74
|
+
try {
|
|
75
|
+
return await queryCurrent();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
if (errCallback) {
|
|
80
|
+
errCallback(error);
|
|
81
|
+
return Promise.resolve({});
|
|
82
|
+
}
|
|
83
|
+
else if (!whiteRegExp.test(window.location.href)) {
|
|
84
|
+
// 如果不在白名单里面,并且开启了自动跳转登录页面,那么就会跳转到登录页面
|
|
85
|
+
if (autoToLogin) {
|
|
86
|
+
toLogin(isHash, autoLoginPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const currentUser = await fetchUserInfo();
|
|
92
|
+
// 设置当前的应用模式
|
|
93
|
+
const appRunMode = index.default.getItem(systemEnum.StorageKeyEnum.APP_RUN_MODE) || systemEnum.AppRunModeEnum.normal;
|
|
94
|
+
return {
|
|
95
|
+
fetchUserInfo,
|
|
96
|
+
currentUser,
|
|
97
|
+
isLogin: !!currentUser?.userName,
|
|
98
|
+
settings: defaultSettings,
|
|
99
|
+
theme: defaultTheme,
|
|
100
|
+
appInfo,
|
|
101
|
+
APP_RUN_MODE: appRunMode,
|
|
102
|
+
isAdvancedMode: appRunMode === systemEnum.AppRunModeEnum.advanced,
|
|
103
|
+
isDevMode: appRunMode === systemEnum.AppRunModeEnum.dev,
|
|
104
|
+
otherInfo: {}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
exports.buildLoginPath = buildLoginPath;
|
|
109
|
+
exports.getJwtToken = getJwtToken;
|
|
110
|
+
exports.initialUmiState = initialUmiState;
|
|
111
|
+
exports.isLogin = isLogin;
|
|
112
|
+
exports.loginOk = loginOk;
|
|
113
|
+
exports.toLogin = toLogin;
|
|
114
|
+
//# sourceMappingURL=initialUmiState.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialUmiState.cjs","sources":["../../src/umijs/initialUmiState.ts"],"sourcesContent":[null],"names":["storageUtils","StorageKeyEnum","AppRunModeEnum"],"mappings":";;;;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;;;;;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { AppRunModeEnum } from '../core/constants/systemEnum.js';
|
|
2
|
+
|
|
3
|
+
declare const getJwtToken: () => string | null;
|
|
4
|
+
declare const buildLoginPath: (isHash: boolean, path?: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* 登录成功后跳转页面
|
|
7
|
+
* @param isHash 是否是hash
|
|
8
|
+
* @param url 地址
|
|
9
|
+
*/
|
|
10
|
+
declare const loginOk: (isHash: boolean, url: string) => void;
|
|
11
|
+
declare const isLogin: () => boolean;
|
|
12
|
+
declare const toLogin: (isHash: boolean, path: string) => void;
|
|
13
|
+
interface IInitialUmiState<U = any> {
|
|
14
|
+
settings: Partial<any>;
|
|
15
|
+
currentUser: U;
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
fetchUserInfo: () => Promise<U>;
|
|
18
|
+
loginVisible?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 是否需要修改密码
|
|
21
|
+
*/
|
|
22
|
+
padVisible?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 是否是登录状态
|
|
25
|
+
*/
|
|
26
|
+
isLogin?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 当前的主题配置
|
|
29
|
+
*/
|
|
30
|
+
theme: any;
|
|
31
|
+
/**
|
|
32
|
+
* 当前的应用信息
|
|
33
|
+
*/
|
|
34
|
+
appInfo: IInitialUmiStateParams['appInfo'];
|
|
35
|
+
/**
|
|
36
|
+
* 当前应用运行的模式 - 正常模式,开发者模式 - 抢先体验模式
|
|
37
|
+
*/
|
|
38
|
+
APP_RUN_MODE: IInitialUmiStateParams['otherInfo'];
|
|
39
|
+
/**
|
|
40
|
+
* 其他信息
|
|
41
|
+
*/
|
|
42
|
+
otherInfo: IInitialUmiStateParams['otherInfo'];
|
|
43
|
+
/**
|
|
44
|
+
* 是否是开发者模式
|
|
45
|
+
*/
|
|
46
|
+
isDevMode?: IInitialUmiStateParams['isDevMode'];
|
|
47
|
+
/**
|
|
48
|
+
* 是否是体验版模式
|
|
49
|
+
*/
|
|
50
|
+
isAdvancedMode?: IInitialUmiStateParams['isAdvancedMode'];
|
|
51
|
+
}
|
|
52
|
+
type IInitialUmiStateParams = {
|
|
53
|
+
/**
|
|
54
|
+
* 获取用户信息的方法
|
|
55
|
+
*/
|
|
56
|
+
queryCurrent: () => Promise<any | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* 默认的全局配置
|
|
59
|
+
*/
|
|
60
|
+
defaultSettings: any;
|
|
61
|
+
/**
|
|
62
|
+
* 是否是hash路由
|
|
63
|
+
*/
|
|
64
|
+
isHash: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 白名单正则表达式,如果页面地址包含这个白名单,就不会提示进行登录
|
|
67
|
+
* <br />
|
|
68
|
+
* 默认值:/user/login
|
|
69
|
+
*/
|
|
70
|
+
whiteReg?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 触发登录的回调函数
|
|
73
|
+
* <br />
|
|
74
|
+
* 默认值:toLogin 跳转到登录页面
|
|
75
|
+
*/
|
|
76
|
+
errCallback?: (e: any) => void;
|
|
77
|
+
/**
|
|
78
|
+
* 是否自动跳转登录页面:默认值:true
|
|
79
|
+
*/
|
|
80
|
+
autoToLogin?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 登录页面地址 - 默认值:/user/login
|
|
83
|
+
*/
|
|
84
|
+
autoLoginPath?: string;
|
|
85
|
+
/**
|
|
86
|
+
* 默认的主题配置
|
|
87
|
+
*/
|
|
88
|
+
defaultTheme?: any;
|
|
89
|
+
/**
|
|
90
|
+
* 当前的应用信息
|
|
91
|
+
*/
|
|
92
|
+
appInfo: {
|
|
93
|
+
name: string;
|
|
94
|
+
version: string;
|
|
95
|
+
buildTime: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* 当前应用运行的模式 - 正常模式,开发者模式 - 抢先体验模式
|
|
99
|
+
*/
|
|
100
|
+
APP_RUN_MODE?: AppRunModeEnum;
|
|
101
|
+
/**
|
|
102
|
+
* 是否是开发者模式
|
|
103
|
+
*/
|
|
104
|
+
isDevMode?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* 是否是体验版模式
|
|
107
|
+
*/
|
|
108
|
+
isAdvancedMode?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* 其他信息
|
|
111
|
+
*/
|
|
112
|
+
otherInfo?: any;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* <h3>初始化页面全局状态的方法</h3>
|
|
116
|
+
* <br />
|
|
117
|
+
* 当页面第一次打开的时候,会调用改方法,用于获取用户信息,并且初始化全局状态
|
|
118
|
+
* <br />
|
|
119
|
+
* 获取token的方法会从sessionStorage和localStorage中获取,如果获取不到,则会初始化空的用户信息。
|
|
120
|
+
* <br />
|
|
121
|
+
* 存储的token如果过期了,那么就会触发errCallback的回调,以便对过期的token进行处理。
|
|
122
|
+
* <br />
|
|
123
|
+
* 当然,如果页面是在白名单里面的,代码不会进行任何额外的操作。
|
|
124
|
+
* <br />
|
|
125
|
+
* 方法支持以下参数
|
|
126
|
+
* <br />
|
|
127
|
+
* @param queryCurrent 查用户信息的方法
|
|
128
|
+
* <br />
|
|
129
|
+
* @param defaultSettings 默认的全局配置
|
|
130
|
+
* <br />
|
|
131
|
+
* @param isHash 是否是hash路由
|
|
132
|
+
* <br />
|
|
133
|
+
* @param whiteReg 白名单正则
|
|
134
|
+
* <br />
|
|
135
|
+
* @param errCallback 异常的回调,一般是用户信息获取失败的时候触发
|
|
136
|
+
* <br />
|
|
137
|
+
* @param autoToLogin 是否自动跳转登录页面:默认值:true
|
|
138
|
+
* <br />
|
|
139
|
+
* @param autoLoginPath 登录页面地址 - 默认值:/user/login
|
|
140
|
+
* <br />
|
|
141
|
+
* @param defaultTheme 默认的主题配置
|
|
142
|
+
* <br />
|
|
143
|
+
* @param appInfo 应用的信息
|
|
144
|
+
*/
|
|
145
|
+
declare const initialUmiState: ({ queryCurrent, defaultSettings, isHash, whiteReg, errCallback, autoToLogin, autoLoginPath, defaultTheme, appInfo }: IInitialUmiStateParams) => Promise<IInitialUmiState>;
|
|
146
|
+
|
|
147
|
+
export { buildLoginPath, getJwtToken, initialUmiState, isLogin, loginOk, toLogin };
|
|
148
|
+
export type { IInitialUmiState, IInitialUmiStateParams };
|