@etsoo/appscript 1.2.73 → 1.2.76
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/__tests__/app/CoreApp.ts +7 -1
- package/__tests__/business/BusinessUtils.ts +9 -0
- package/lib/cjs/app/CoreApp.d.ts +44 -12
- package/lib/cjs/app/CoreApp.js +76 -5
- package/lib/cjs/business/BusinessUtils.d.ts +9 -20
- package/lib/cjs/business/BusinessUtils.js +34 -32
- package/lib/cjs/dto/IdLabelDto.d.ts +2 -3
- package/lib/cjs/i18n/en-US.json +3 -0
- package/lib/cjs/i18n/zh-CN.json +3 -0
- package/lib/cjs/i18n/zh-HK.json +3 -0
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/mjs/app/CoreApp.d.ts +44 -12
- package/lib/mjs/app/CoreApp.js +77 -6
- package/lib/mjs/business/BusinessUtils.d.ts +9 -20
- package/lib/mjs/business/BusinessUtils.js +33 -31
- package/lib/mjs/dto/IdLabelDto.d.ts +2 -3
- package/lib/mjs/i18n/en-US.json +3 -0
- package/lib/mjs/i18n/zh-CN.json +3 -0
- package/lib/mjs/i18n/zh-HK.json +3 -0
- package/lib/mjs/index.d.ts +0 -1
- package/lib/mjs/index.js +0 -1
- package/package.json +7 -7
- package/src/app/CoreApp.ts +105 -15
- package/src/business/BusinessUtils.ts +40 -33
- package/src/dto/IdLabelDto.ts +8 -8
- package/src/i18n/en-US.json +3 -0
- package/src/i18n/zh-CN.json +3 -0
- package/src/i18n/zh-HK.json +3 -0
- package/src/index.ts +0 -1
- package/lib/cjs/dto/IdDto.d.ts +0 -10
- package/lib/cjs/dto/IdDto.js +0 -2
- package/lib/mjs/dto/IdDto.d.ts +0 -10
- package/lib/mjs/dto/IdDto.js +0 -1
- package/src/dto/IdDto.ts +0 -11
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
3
3
|
import { ICultureGet } from '../state/Culture';
|
|
4
|
-
import { EntityStatus } from './EntityStatus';
|
|
5
4
|
import { ProductUnit } from './ProductUnit';
|
|
6
5
|
/**
|
|
7
6
|
* Business utils
|
|
8
7
|
*/
|
|
9
8
|
export declare namespace BusinessUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Format avatar title
|
|
11
|
+
* @param title Title
|
|
12
|
+
* @param maxChars Max characters
|
|
13
|
+
* @param defaultTitle Default title
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
|
|
10
17
|
/**
|
|
11
18
|
* Get currency collection
|
|
12
19
|
* @param currencyNames Names like CNY, USD
|
|
@@ -14,31 +21,13 @@ export declare namespace BusinessUtils {
|
|
|
14
21
|
* @returns Collection
|
|
15
22
|
*/
|
|
16
23
|
function getCurrencies(currencyNames: string[], func: ICultureGet): IdLabelDto<string>[];
|
|
17
|
-
/**
|
|
18
|
-
* Get entity status's label
|
|
19
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
20
|
-
* @param unit Unit
|
|
21
|
-
* @param func Label delegate
|
|
22
|
-
* @returns Label
|
|
23
|
-
*/
|
|
24
|
-
function getEntityStatusLabel(status: EntityStatus, func: ICultureGet): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get entity status collection
|
|
27
|
-
* @param unit Unit
|
|
28
|
-
* @param func Label delegate
|
|
29
|
-
* @returns Label
|
|
30
|
-
*/
|
|
31
|
-
function getEntityStatus(func: ICultureGet): {
|
|
32
|
-
id: EntityStatus;
|
|
33
|
-
label: string;
|
|
34
|
-
}[];
|
|
35
24
|
/**
|
|
36
25
|
* Get 12-month items
|
|
37
26
|
* @param monthLabels Month labels
|
|
38
27
|
* @param startMonth Start month, 0 as Jan.
|
|
39
28
|
* @returns 12 months
|
|
40
29
|
*/
|
|
41
|
-
function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
|
|
30
|
+
function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
|
|
42
31
|
/**
|
|
43
32
|
* Get product unit's label
|
|
44
33
|
* Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { RepeatOption } from '..';
|
|
3
|
-
import { EntityStatus } from './EntityStatus';
|
|
4
2
|
import { ProductUnit } from './ProductUnit';
|
|
3
|
+
import { RepeatOption } from './RepeatOption';
|
|
5
4
|
/**
|
|
6
5
|
* Business utils
|
|
7
6
|
*/
|
|
8
7
|
export var BusinessUtils;
|
|
9
8
|
(function (BusinessUtils) {
|
|
9
|
+
/**
|
|
10
|
+
* Format avatar title
|
|
11
|
+
* @param title Title
|
|
12
|
+
* @param maxChars Max characters
|
|
13
|
+
* @param defaultTitle Default title
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
function formatAvatarTitle(title, maxChars = 3, defaultTitle = 'ME') {
|
|
17
|
+
// Just return for empty cases
|
|
18
|
+
if (title == null || title === '')
|
|
19
|
+
return defaultTitle;
|
|
20
|
+
// split with words
|
|
21
|
+
const items = title.trim().split(/\s+/g);
|
|
22
|
+
if (items.length === 1) {
|
|
23
|
+
// 2-3 Chinese names
|
|
24
|
+
const titleLen = title.length;
|
|
25
|
+
if (titleLen <= maxChars)
|
|
26
|
+
return title.toUpperCase();
|
|
27
|
+
// Return default for simplicity
|
|
28
|
+
return defaultTitle;
|
|
29
|
+
}
|
|
30
|
+
// First letter of each item
|
|
31
|
+
var firstLetters = items
|
|
32
|
+
.map((item) => item[0])
|
|
33
|
+
.join('')
|
|
34
|
+
.toUpperCase();
|
|
35
|
+
const flen = firstLetters.length;
|
|
36
|
+
if (flen <= maxChars)
|
|
37
|
+
return firstLetters;
|
|
38
|
+
return defaultTitle;
|
|
39
|
+
}
|
|
40
|
+
BusinessUtils.formatAvatarTitle = formatAvatarTitle;
|
|
10
41
|
/**
|
|
11
42
|
* Get currency collection
|
|
12
43
|
* @param currencyNames Names like CNY, USD
|
|
@@ -23,35 +54,6 @@ export var BusinessUtils;
|
|
|
23
54
|
});
|
|
24
55
|
}
|
|
25
56
|
BusinessUtils.getCurrencies = getCurrencies;
|
|
26
|
-
/**
|
|
27
|
-
* Get entity status's label
|
|
28
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
29
|
-
* @param unit Unit
|
|
30
|
-
* @param func Label delegate
|
|
31
|
-
* @returns Label
|
|
32
|
-
*/
|
|
33
|
-
function getEntityStatusLabel(status, func) {
|
|
34
|
-
var _a;
|
|
35
|
-
const key = EntityStatus[status];
|
|
36
|
-
return (_a = func('status' + key)) !== null && _a !== void 0 ? _a : key;
|
|
37
|
-
}
|
|
38
|
-
BusinessUtils.getEntityStatusLabel = getEntityStatusLabel;
|
|
39
|
-
/**
|
|
40
|
-
* Get entity status collection
|
|
41
|
-
* @param unit Unit
|
|
42
|
-
* @param func Label delegate
|
|
43
|
-
* @returns Label
|
|
44
|
-
*/
|
|
45
|
-
function getEntityStatus(func) {
|
|
46
|
-
return DataTypes.getEnumKeys(EntityStatus).map((key) => {
|
|
47
|
-
const id = DataTypes.getEnumByKey(EntityStatus, key);
|
|
48
|
-
return {
|
|
49
|
-
id,
|
|
50
|
-
label: getEntityStatusLabel(id, func)
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
BusinessUtils.getEntityStatus = getEntityStatus;
|
|
55
57
|
/**
|
|
56
58
|
* Get 12-month items
|
|
57
59
|
* @param monthLabels Month labels
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { IdDto } from './IdDto';
|
|
3
2
|
/**
|
|
4
3
|
* Dto with id and label field
|
|
5
4
|
*/
|
|
6
|
-
export declare type IdLabelDto<T extends DataTypes.IdType = number> =
|
|
5
|
+
export declare type IdLabelDto<T extends DataTypes.IdType = number> = DataTypes.IdItem<T> & {
|
|
7
6
|
/**
|
|
8
7
|
* Label
|
|
9
8
|
*/
|
|
@@ -12,4 +11,4 @@ export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> &
|
|
|
12
11
|
/**
|
|
13
12
|
* Conditional IdLabel type
|
|
14
13
|
*/
|
|
15
|
-
export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto[] : IdLabelDto<string>[];
|
|
14
|
+
export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto<number>[] : IdLabelDto<string>[];
|
package/lib/mjs/i18n/en-US.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "Enabled",
|
|
44
44
|
"entityStatus": "Status",
|
|
45
45
|
"environmentChanged": "The operating environment has changed, please log in again",
|
|
46
|
+
"error": "Error",
|
|
46
47
|
"etsoo": "ETSOO",
|
|
47
48
|
"expiry": "Expiry",
|
|
48
49
|
"failed": "Operation failed",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}' already exists",
|
|
53
54
|
"loading": "Loading...",
|
|
54
55
|
"login": "Login",
|
|
56
|
+
"me": "ME",
|
|
55
57
|
"menuHome": "Home",
|
|
56
58
|
"message": "Message",
|
|
57
59
|
"mobile": "Mobile number",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "Employer identification number",
|
|
140
142
|
"timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
|
|
141
143
|
"tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
|
|
144
|
+
"type": "Type",
|
|
142
145
|
"yes": "Yes",
|
|
143
146
|
"unknownError": "Unknown Error",
|
|
144
147
|
"unitJoin": "per {0}",
|
package/lib/mjs/i18n/zh-CN.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "已启用",
|
|
44
44
|
"entityStatus": "状态",
|
|
45
45
|
"environmentChanged": "运行环境已改变,请重新登录",
|
|
46
|
+
"error": "错误",
|
|
46
47
|
"etsoo": "亿速思维",
|
|
47
48
|
"expiry": "到期时间",
|
|
48
49
|
"failed": "操作失败",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}'已经存在",
|
|
53
54
|
"loading": "正在加载...",
|
|
54
55
|
"login": "登录",
|
|
56
|
+
"me": "我",
|
|
55
57
|
"menuHome": "首页",
|
|
56
58
|
"message": "留言",
|
|
57
59
|
"mobile": "手机号码",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "雇主识别号码(EIN)",
|
|
140
142
|
"timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
|
|
141
143
|
"tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
|
|
144
|
+
"type": "类型",
|
|
142
145
|
"yes": "是",
|
|
143
146
|
"unknownError": "未知错误",
|
|
144
147
|
"unitJoin": "每{0}",
|
package/lib/mjs/i18n/zh-HK.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "已啟用",
|
|
44
44
|
"entityStatus": "狀態",
|
|
45
45
|
"environmentChanged": "運行環境已改變,請重新登錄",
|
|
46
|
+
"error": "錯誤",
|
|
46
47
|
"etsoo": "億速思維",
|
|
47
48
|
"expiry": "到期時間",
|
|
48
49
|
"failed": "操作失敗",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}'已经存在",
|
|
53
54
|
"loading": "正在加載...",
|
|
54
55
|
"login": "登錄",
|
|
56
|
+
"me": "我",
|
|
55
57
|
"menuHome": "首頁",
|
|
56
58
|
"message": "留言",
|
|
57
59
|
"mobilePhone": "手機號碼",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "雇主識別號碼(EIN)",
|
|
140
142
|
"timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
|
|
141
143
|
"tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
|
|
144
|
+
"type": "類型",
|
|
142
145
|
"yes": "是",
|
|
143
146
|
"unknownError": "未知錯誤",
|
|
144
147
|
"unitJoin": "每{0}",
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export * from './business/EntityStatus';
|
|
|
13
13
|
export * from './business/ProductUnit';
|
|
14
14
|
export * from './business/RepeatOption';
|
|
15
15
|
export * from './def/ListItem';
|
|
16
|
-
export * from './dto/IdDto';
|
|
17
16
|
export * from './dto/IdLabelDto';
|
|
18
17
|
export * from './dto/IdLabelPrimaryDto';
|
|
19
18
|
export * from './dto/InitCallDto';
|
package/lib/mjs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.76",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@etsoo/notificationbase": "^1.1.5",
|
|
56
56
|
"@etsoo/restclient": "^1.0.70",
|
|
57
|
-
"@etsoo/shared": "^1.1.
|
|
57
|
+
"@etsoo/shared": "^1.1.45",
|
|
58
58
|
"@types/crypto-js": "^4.1.1",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
65
65
|
"@babel/preset-env": "^7.18.10",
|
|
66
66
|
"@babel/runtime-corejs3": "^7.18.9",
|
|
67
|
-
"@types/jest": "^28.1.
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
69
|
-
"@typescript-eslint/parser": "^5.
|
|
70
|
-
"eslint": "^8.
|
|
67
|
+
"@types/jest": "^28.1.7",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
69
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
70
|
+
"eslint": "^8.22.0",
|
|
71
71
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
72
72
|
"eslint-plugin-import": "^2.26.0",
|
|
73
73
|
"jest": "^28.1.3",
|
|
74
74
|
"jest-environment-jsdom": "^28.1.3",
|
|
75
|
-
"ts-jest": "^28.0.
|
|
75
|
+
"ts-jest": "^28.0.8",
|
|
76
76
|
"typescript": "^4.7.4"
|
|
77
77
|
}
|
|
78
78
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -31,13 +31,14 @@ import { AddressRegion } from '../address/AddressRegion';
|
|
|
31
31
|
import { AddressUtils } from '../address/AddressUtils';
|
|
32
32
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
33
33
|
import { BusinessUtils } from '../business/BusinessUtils';
|
|
34
|
+
import { EntityStatus } from '../business/EntityStatus';
|
|
34
35
|
import { ProductUnit } from '../business/ProductUnit';
|
|
35
36
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
36
37
|
import { InitCallDto } from '../dto/InitCallDto';
|
|
37
38
|
import { ActionResultError } from '../result/ActionResultError';
|
|
38
39
|
import { IActionResult } from '../result/IActionResult';
|
|
39
40
|
import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
|
|
40
|
-
import { IUser
|
|
41
|
+
import { IUser } from '../state/User';
|
|
41
42
|
import { IAppSettings } from './AppSettings';
|
|
42
43
|
import { UserRole } from './UserRole';
|
|
43
44
|
|
|
@@ -374,18 +375,30 @@ export interface ICoreApp<
|
|
|
374
375
|
*/
|
|
375
376
|
getCacheToken(): string | undefined;
|
|
376
377
|
|
|
377
|
-
/**
|
|
378
|
-
* Get entity status label
|
|
379
|
-
* @param data Input data
|
|
380
|
-
*/
|
|
381
|
-
getEntityStatusLabel<D extends { entityStatus?: number }>(data?: D): string;
|
|
382
|
-
|
|
383
378
|
/**
|
|
384
379
|
* Get all regions
|
|
385
380
|
* @returns Regions
|
|
386
381
|
*/
|
|
387
382
|
getRegions(): AddressRegion[];
|
|
388
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Get roles
|
|
386
|
+
* @param role Combination role value
|
|
387
|
+
*/
|
|
388
|
+
getRoles(role: number): IdLabelDto[];
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Get status label
|
|
392
|
+
* @param status Status value
|
|
393
|
+
*/
|
|
394
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Get status list
|
|
398
|
+
* @returns list
|
|
399
|
+
*/
|
|
400
|
+
getStatusList(): IdLabelDto[];
|
|
401
|
+
|
|
389
402
|
/**
|
|
390
403
|
* Get refresh token from response headers
|
|
391
404
|
* @param rawResponse Raw response from API call
|
|
@@ -1592,6 +1605,67 @@ export abstract class CoreApp<
|
|
|
1592
1605
|
return this.storage.getData<string>(this.fields.headerToken);
|
|
1593
1606
|
}
|
|
1594
1607
|
|
|
1608
|
+
/**
|
|
1609
|
+
* Get enum item number id list
|
|
1610
|
+
* @param em Enum
|
|
1611
|
+
* @param prefix Label prefix
|
|
1612
|
+
* @param filter Filter
|
|
1613
|
+
* @returns List
|
|
1614
|
+
*/
|
|
1615
|
+
protected getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
|
|
1616
|
+
em: E,
|
|
1617
|
+
prefix: string,
|
|
1618
|
+
filter?: (
|
|
1619
|
+
id: E[keyof E],
|
|
1620
|
+
key: keyof E & string
|
|
1621
|
+
) => E[keyof E] | undefined
|
|
1622
|
+
): IdLabelDto[] {
|
|
1623
|
+
const list: IdLabelDto<number>[] = [];
|
|
1624
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
1625
|
+
for (const key of keys) {
|
|
1626
|
+
let id = em[key as keyof E];
|
|
1627
|
+
if (filter) {
|
|
1628
|
+
const fid = filter(id, key);
|
|
1629
|
+
if (fid == null) continue;
|
|
1630
|
+
id = fid;
|
|
1631
|
+
}
|
|
1632
|
+
if (typeof id !== 'number') continue;
|
|
1633
|
+
var label = this.get<string>(prefix + key) ?? key;
|
|
1634
|
+
list.push({ id, label });
|
|
1635
|
+
}
|
|
1636
|
+
return list;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
/**
|
|
1640
|
+
* Get enum item string id list
|
|
1641
|
+
* @param em Enum
|
|
1642
|
+
* @param prefix Label prefix
|
|
1643
|
+
* @param filter Filter
|
|
1644
|
+
* @returns List
|
|
1645
|
+
*/
|
|
1646
|
+
protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
|
|
1647
|
+
em: E,
|
|
1648
|
+
prefix: string,
|
|
1649
|
+
filter?: (
|
|
1650
|
+
id: E[keyof E],
|
|
1651
|
+
key: keyof E & string
|
|
1652
|
+
) => E[keyof E] | undefined
|
|
1653
|
+
): IdLabelDto<string>[] {
|
|
1654
|
+
const list: IdLabelDto<string>[] = [];
|
|
1655
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
1656
|
+
for (const key of keys) {
|
|
1657
|
+
let id = em[key as keyof E];
|
|
1658
|
+
if (filter) {
|
|
1659
|
+
const fid = filter(id, key);
|
|
1660
|
+
if (fid == null) continue;
|
|
1661
|
+
id = fid;
|
|
1662
|
+
}
|
|
1663
|
+
var label = this.get<string>(prefix + key) ?? key;
|
|
1664
|
+
list.push({ id: id.toString(), label });
|
|
1665
|
+
}
|
|
1666
|
+
return list;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1595
1669
|
/**
|
|
1596
1670
|
* Get all regions
|
|
1597
1671
|
* @returns Regions
|
|
@@ -1603,15 +1677,31 @@ export abstract class CoreApp<
|
|
|
1603
1677
|
}
|
|
1604
1678
|
|
|
1605
1679
|
/**
|
|
1606
|
-
* Get
|
|
1607
|
-
* @param
|
|
1680
|
+
* Get roles
|
|
1681
|
+
* @param role Combination role value
|
|
1608
1682
|
*/
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1683
|
+
getRoles(role: number) {
|
|
1684
|
+
return this.getEnumList(UserRole, 'role', (id, _key) => {
|
|
1685
|
+
if ((id & role) > 0) return id;
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
/**
|
|
1690
|
+
* Get status list
|
|
1691
|
+
* @returns list
|
|
1692
|
+
*/
|
|
1693
|
+
getStatusList() {
|
|
1694
|
+
return this.getEnumList(EntityStatus, 'status');
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Get status label
|
|
1699
|
+
* @param status Status value
|
|
1700
|
+
*/
|
|
1701
|
+
getStatusLabel(status: number | null | undefined) {
|
|
1702
|
+
if (status == null) return '';
|
|
1703
|
+
const key = EntityStatus[status];
|
|
1704
|
+
return this.get<string>('status' + key) ?? key;
|
|
1615
1705
|
}
|
|
1616
1706
|
|
|
1617
1707
|
/**
|
|
@@ -1,14 +1,52 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { RepeatOption } from '..';
|
|
3
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
4
3
|
import { ICultureGet } from '../state/Culture';
|
|
5
|
-
import { EntityStatus } from './EntityStatus';
|
|
6
4
|
import { ProductUnit } from './ProductUnit';
|
|
5
|
+
import { RepeatOption } from './RepeatOption';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Business utils
|
|
10
9
|
*/
|
|
11
10
|
export namespace BusinessUtils {
|
|
11
|
+
/**
|
|
12
|
+
* Format avatar title
|
|
13
|
+
* @param title Title
|
|
14
|
+
* @param maxChars Max characters
|
|
15
|
+
* @param defaultTitle Default title
|
|
16
|
+
* @returns Result
|
|
17
|
+
*/
|
|
18
|
+
export function formatAvatarTitle(
|
|
19
|
+
title?: string,
|
|
20
|
+
maxChars: number = 3,
|
|
21
|
+
defaultTitle: string = 'ME'
|
|
22
|
+
): string {
|
|
23
|
+
// Just return for empty cases
|
|
24
|
+
if (title == null || title === '') return defaultTitle;
|
|
25
|
+
|
|
26
|
+
// split with words
|
|
27
|
+
const items = title.trim().split(/\s+/g);
|
|
28
|
+
|
|
29
|
+
if (items.length === 1) {
|
|
30
|
+
// 2-3 Chinese names
|
|
31
|
+
const titleLen = title.length;
|
|
32
|
+
if (titleLen <= maxChars) return title.toUpperCase();
|
|
33
|
+
|
|
34
|
+
// Return default for simplicity
|
|
35
|
+
return defaultTitle;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// First letter of each item
|
|
39
|
+
var firstLetters = items
|
|
40
|
+
.map((item) => item[0])
|
|
41
|
+
.join('')
|
|
42
|
+
.toUpperCase();
|
|
43
|
+
|
|
44
|
+
const flen = firstLetters.length;
|
|
45
|
+
if (flen <= maxChars) return firstLetters;
|
|
46
|
+
|
|
47
|
+
return defaultTitle;
|
|
48
|
+
}
|
|
49
|
+
|
|
12
50
|
/**
|
|
13
51
|
* Get currency collection
|
|
14
52
|
* @param currencyNames Names like CNY, USD
|
|
@@ -25,37 +63,6 @@ export namespace BusinessUtils {
|
|
|
25
63
|
}));
|
|
26
64
|
}
|
|
27
65
|
|
|
28
|
-
/**
|
|
29
|
-
* Get entity status's label
|
|
30
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
31
|
-
* @param unit Unit
|
|
32
|
-
* @param func Label delegate
|
|
33
|
-
* @returns Label
|
|
34
|
-
*/
|
|
35
|
-
export function getEntityStatusLabel(
|
|
36
|
-
status: EntityStatus,
|
|
37
|
-
func: ICultureGet
|
|
38
|
-
) {
|
|
39
|
-
const key = EntityStatus[status];
|
|
40
|
-
return func('status' + key) ?? key;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get entity status collection
|
|
45
|
-
* @param unit Unit
|
|
46
|
-
* @param func Label delegate
|
|
47
|
-
* @returns Label
|
|
48
|
-
*/
|
|
49
|
-
export function getEntityStatus(func: ICultureGet) {
|
|
50
|
-
return DataTypes.getEnumKeys(EntityStatus).map((key) => {
|
|
51
|
-
const id = DataTypes.getEnumByKey(EntityStatus, key)!;
|
|
52
|
-
return {
|
|
53
|
-
id,
|
|
54
|
-
label: getEntityStatusLabel(id, func)
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
66
|
/**
|
|
60
67
|
* Get 12-month items
|
|
61
68
|
* @param monthLabels Month labels
|
package/src/dto/IdLabelDto.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { IdDto } from './IdDto';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Dto with id and label field
|
|
6
5
|
*/
|
|
7
|
-
export type IdLabelDto<T extends DataTypes.IdType = number> =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export type IdLabelDto<T extends DataTypes.IdType = number> =
|
|
7
|
+
DataTypes.IdItem<T> & {
|
|
8
|
+
/**
|
|
9
|
+
* Label
|
|
10
|
+
*/
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Conditional IdLabel type
|
|
16
16
|
*/
|
|
17
17
|
export type IdLabelConditional<T extends boolean> = T extends true
|
|
18
|
-
? IdLabelDto[]
|
|
18
|
+
? IdLabelDto<number>[]
|
|
19
19
|
: IdLabelDto<string>[];
|
package/src/i18n/en-US.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "Enabled",
|
|
44
44
|
"entityStatus": "Status",
|
|
45
45
|
"environmentChanged": "The operating environment has changed, please log in again",
|
|
46
|
+
"error": "Error",
|
|
46
47
|
"etsoo": "ETSOO",
|
|
47
48
|
"expiry": "Expiry",
|
|
48
49
|
"failed": "Operation failed",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}' already exists",
|
|
53
54
|
"loading": "Loading...",
|
|
54
55
|
"login": "Login",
|
|
56
|
+
"me": "ME",
|
|
55
57
|
"menuHome": "Home",
|
|
56
58
|
"message": "Message",
|
|
57
59
|
"mobile": "Mobile number",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "Employer identification number",
|
|
140
142
|
"timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
|
|
141
143
|
"tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
|
|
144
|
+
"type": "Type",
|
|
142
145
|
"yes": "Yes",
|
|
143
146
|
"unknownError": "Unknown Error",
|
|
144
147
|
"unitJoin": "per {0}",
|
package/src/i18n/zh-CN.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "已启用",
|
|
44
44
|
"entityStatus": "状态",
|
|
45
45
|
"environmentChanged": "运行环境已改变,请重新登录",
|
|
46
|
+
"error": "错误",
|
|
46
47
|
"etsoo": "亿速思维",
|
|
47
48
|
"expiry": "到期时间",
|
|
48
49
|
"failed": "操作失败",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}'已经存在",
|
|
53
54
|
"loading": "正在加载...",
|
|
54
55
|
"login": "登录",
|
|
56
|
+
"me": "我",
|
|
55
57
|
"menuHome": "首页",
|
|
56
58
|
"message": "留言",
|
|
57
59
|
"mobile": "手机号码",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "雇主识别号码(EIN)",
|
|
140
142
|
"timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
|
|
141
143
|
"tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
|
|
144
|
+
"type": "类型",
|
|
142
145
|
"yes": "是",
|
|
143
146
|
"unknownError": "未知错误",
|
|
144
147
|
"unitJoin": "每{0}",
|
package/src/i18n/zh-HK.json
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"enabled": "已啟用",
|
|
44
44
|
"entityStatus": "狀態",
|
|
45
45
|
"environmentChanged": "運行環境已改變,請重新登錄",
|
|
46
|
+
"error": "錯誤",
|
|
46
47
|
"etsoo": "億速思維",
|
|
47
48
|
"expiry": "到期時間",
|
|
48
49
|
"failed": "操作失敗",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"itemExists": "'{0}'已经存在",
|
|
53
54
|
"loading": "正在加載...",
|
|
54
55
|
"login": "登錄",
|
|
56
|
+
"me": "我",
|
|
55
57
|
"menuHome": "首頁",
|
|
56
58
|
"message": "留言",
|
|
57
59
|
"mobilePhone": "手機號碼",
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
"taxUSEIN": "雇主識別號碼(EIN)",
|
|
140
142
|
"timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
|
|
141
143
|
"tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
|
|
144
|
+
"type": "類型",
|
|
142
145
|
"yes": "是",
|
|
143
146
|
"unknownError": "未知錯誤",
|
|
144
147
|
"unitJoin": "每{0}",
|
package/src/index.ts
CHANGED
package/lib/cjs/dto/IdDto.d.ts
DELETED
package/lib/cjs/dto/IdDto.js
DELETED
package/lib/mjs/dto/IdDto.d.ts
DELETED
package/lib/mjs/dto/IdDto.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|