@freelog/tools-lib 0.1.152 → 0.1.154
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/i18n/I18nNext.d.ts +4 -1
- package/dist/service-API/collections.d.ts +1 -0
- package/dist/service-API/resources.d.ts +17 -4
- package/dist/tools-lib.cjs.development.js +110 -46
- package/dist/tools-lib.cjs.development.js.map +1 -1
- package/dist/tools-lib.cjs.production.min.js +1 -1
- package/dist/tools-lib.cjs.production.min.js.map +1 -1
- package/dist/tools-lib.esm.js +110 -46
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/hooks.d.ts +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/linkTo.d.ts +10 -0
- package/dist/utils/regexp.d.ts +2 -0
- package/package.json +5 -2
- package/src/i18n/I18nNext.ts +12 -5
- package/src/service-API/collections.ts +1 -3
- package/src/service-API/resources.ts +26 -4
- package/src/utils/hooks.ts +17 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/linkTo.ts +27 -1
- package/src/utils/regexp.ts +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useGetState<T>(initVal: T): [T, (newVal: T) => void, () => T];
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as LinkTo from './linkTo';
|
|
|
4
4
|
import * as Predefined from './predefined';
|
|
5
5
|
import { request } from './axios';
|
|
6
6
|
import * as Tool from './tools';
|
|
7
|
+
import * as Hook from './hooks';
|
|
7
8
|
declare const FUtil: {
|
|
8
9
|
Format: typeof Format;
|
|
9
10
|
Regexp: typeof Regexp;
|
|
@@ -12,5 +13,6 @@ declare const FUtil: {
|
|
|
12
13
|
Axios: import("axios").AxiosStatic;
|
|
13
14
|
Request: typeof request;
|
|
14
15
|
Tool: typeof Tool;
|
|
16
|
+
Hook: typeof Hook;
|
|
15
17
|
};
|
|
16
18
|
export default FUtil;
|
package/dist/utils/linkTo.d.ts
CHANGED
|
@@ -119,6 +119,10 @@ interface ResourceFreezeParamsType {
|
|
|
119
119
|
resourceID: string;
|
|
120
120
|
}
|
|
121
121
|
export declare function resourceFreeze({ resourceID }: ResourceFreezeParamsType): string;
|
|
122
|
+
interface GlobalSearchParamsType {
|
|
123
|
+
search: string;
|
|
124
|
+
}
|
|
125
|
+
export declare function globalSearch({ search }: GlobalSearchParamsType): string;
|
|
122
126
|
/************** console End ******************************************************/
|
|
123
127
|
/************** user Start ******************************************************/
|
|
124
128
|
interface LoginParamsType {
|
|
@@ -130,6 +134,12 @@ interface LoginParamsType {
|
|
|
130
134
|
invitationCode?: string;
|
|
131
135
|
}
|
|
132
136
|
export declare function logon({ goTo, ...params }?: LoginParamsType): string;
|
|
137
|
+
interface LoginParamsType {
|
|
138
|
+
goTo?: string;
|
|
139
|
+
identityId?: string;
|
|
140
|
+
returnUrl?: string;
|
|
141
|
+
}
|
|
142
|
+
export declare function bind({ goTo, returnUrl, ...params }?: LoginParamsType): string;
|
|
133
143
|
interface RetrieveUserPasswordParamsType {
|
|
134
144
|
goTo?: string;
|
|
135
145
|
}
|
package/dist/utils/regexp.d.ts
CHANGED
|
@@ -14,3 +14,5 @@ export declare const POSITIVE_INTEGER: RegExp;
|
|
|
14
14
|
export declare const MAX_2_DECIMAL_POSITIVE_NUMBER: RegExp;
|
|
15
15
|
export declare const BUCKET_NAME: RegExp;
|
|
16
16
|
export declare const JS_VARIABLE_NAME: RegExp;
|
|
17
|
+
export declare const DATE: RegExp;
|
|
18
|
+
export declare const DATE_TIME: RegExp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@freelog/tools-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.154",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@types/js-cookie": "^3.0.2",
|
|
49
49
|
"@types/node": "^18.7.16",
|
|
50
50
|
"@types/nprogress": "^0.2.0",
|
|
51
|
+
"@types/react": "^18.2.17",
|
|
51
52
|
"husky": "^6.0.0",
|
|
52
53
|
"size-limit": "^4.11.0",
|
|
53
54
|
"tsdx": "^0.14.1",
|
|
@@ -58,9 +59,11 @@
|
|
|
58
59
|
"@freelog/resource-policy-lang": "1.1.26",
|
|
59
60
|
"axios": "^0.21.1",
|
|
60
61
|
"crypto-js": "^4.0.0",
|
|
62
|
+
"html-react-parser": "^4.2.0",
|
|
61
63
|
"i18next": "^21.8.10",
|
|
62
64
|
"js-cookie": "^3.0.1",
|
|
63
65
|
"moment": "^2.29.1",
|
|
64
|
-
"nprogress": "^0.2.0"
|
|
66
|
+
"nprogress": "^0.2.0",
|
|
67
|
+
"react": "^18.2.0"
|
|
65
68
|
}
|
|
66
69
|
}
|
package/src/i18n/I18nNext.ts
CHANGED
|
@@ -2,6 +2,8 @@ import i18next, {Resource} from 'i18next';
|
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import FUtil from '../utils';
|
|
5
|
+
// import * as React from 'react';
|
|
6
|
+
import htmlReactParser from 'html-react-parser';
|
|
5
7
|
|
|
6
8
|
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
7
9
|
|
|
@@ -32,7 +34,7 @@ class I18nNext {
|
|
|
32
34
|
this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
async ready(this: I18nNext) {
|
|
37
|
+
async ready(this: I18nNext): Promise<void> {
|
|
36
38
|
const exc = () => {
|
|
37
39
|
while (this._taskQueue.length > 0) {
|
|
38
40
|
const task = this._taskQueue.shift();
|
|
@@ -56,18 +58,23 @@ class I18nNext {
|
|
|
56
58
|
// console.log('######');
|
|
57
59
|
exc();
|
|
58
60
|
};
|
|
59
|
-
const promise = new Promise((resolve) => {
|
|
61
|
+
const promise = new Promise<void>((resolve) => {
|
|
60
62
|
this._taskQueue.push(resolve);
|
|
61
63
|
});
|
|
62
64
|
handleTasks();
|
|
63
65
|
return promise;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
t(this: I18nNext, key: string, options?: { [key: string]: any }) {
|
|
68
|
+
t(this: I18nNext, key: string, options?: { [key: string]: any }): string {
|
|
67
69
|
return i18next.t(key.trim(), options);
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
tJSXElement(this: I18nNext, key: string, options?: { [key: string]: any }): string | JSX.Element | JSX.Element[] {
|
|
73
|
+
return htmlReactParser(i18next.t(key.trim(), options));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
changeLanguage(this: I18nNext, lng: LanguageKeyType): void {
|
|
71
78
|
// return i18next.changeLanguage(lng);
|
|
72
79
|
// window.localStorage.setItem(localStorage_i18nextLng_key, lng)
|
|
73
80
|
Cookies.set(localStorage_i18nextLng_key, lng, {
|
|
@@ -84,7 +91,7 @@ class I18nNext {
|
|
|
84
91
|
return this._currentLanguage;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
private async _handleData(this: I18nNext) {
|
|
94
|
+
private async _handleData(this: I18nNext): Promise<void> {
|
|
88
95
|
|
|
89
96
|
const lng: string = this._currentLanguage;
|
|
90
97
|
const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
|
|
@@ -21,14 +21,12 @@ interface CollectionResourcesParamsType {
|
|
|
21
21
|
keywords?: string;
|
|
22
22
|
resourceType?: string;
|
|
23
23
|
resourceTypeCode?: string;
|
|
24
|
+
resourceTypeCategory?: 1 | 2;
|
|
24
25
|
omitResourceType?: string;
|
|
25
26
|
resourceStatus?: 0 | 1 | 2 | 4;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export function collectionResources(params: CollectionResourcesParamsType) {
|
|
29
|
-
// return FUtil.Axios.get('/v2/collections/resources', {
|
|
30
|
-
// params
|
|
31
|
-
// });
|
|
32
30
|
return FUtil.Request({
|
|
33
31
|
method: 'GET',
|
|
34
32
|
url: `/v2/collections/resources`,
|
|
@@ -83,6 +83,7 @@ interface ListParamsType {
|
|
|
83
83
|
keywords?: string;
|
|
84
84
|
resourceType?: string;
|
|
85
85
|
resourceTypeCode?: string;
|
|
86
|
+
resourceTypeCategory?: 1 | 2; // 资源类型分类,1:基础类型,2:自定义类型,其实只有2时生效,生效时,resourceTypeCode为父类类型
|
|
86
87
|
omitResourceType?: string;
|
|
87
88
|
isSelf?: 0 | 1;
|
|
88
89
|
userId?: number;
|
|
@@ -215,6 +216,10 @@ interface CreateVersionParamsType {
|
|
|
215
216
|
policyId: string;
|
|
216
217
|
}[];
|
|
217
218
|
}[];
|
|
219
|
+
inputAttrs: {
|
|
220
|
+
key: string;
|
|
221
|
+
value: string;
|
|
222
|
+
}[];
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
export function createVersion({resourceId, ...params}: CreateVersionParamsType) {
|
|
@@ -307,6 +312,10 @@ interface UpdateResourceVersionInfoParamsType {
|
|
|
307
312
|
policyId: string;
|
|
308
313
|
}[];
|
|
309
314
|
}[];
|
|
315
|
+
inputAttrs: {
|
|
316
|
+
key: string;
|
|
317
|
+
value: string;
|
|
318
|
+
}[];
|
|
310
319
|
}
|
|
311
320
|
|
|
312
321
|
export function updateResourceVersionInfo(params: UpdateResourceVersionInfoParamsType) {
|
|
@@ -597,11 +606,11 @@ export function getResourceTypeInfoByCode({...params}: GetResourceTypeInfoByCode
|
|
|
597
606
|
}
|
|
598
607
|
|
|
599
608
|
//
|
|
600
|
-
interface
|
|
609
|
+
interface GetResourceAttrListSimpleParamsType {
|
|
601
610
|
|
|
602
611
|
}
|
|
603
612
|
|
|
604
|
-
export function getResourceAttrListSimple({...params}:
|
|
613
|
+
export function getResourceAttrListSimple({...params}: GetResourceAttrListSimpleParamsType) {
|
|
605
614
|
return FUtil.Request({
|
|
606
615
|
method: 'GET',
|
|
607
616
|
url: `/v2/resources/attrs/listSimple`,
|
|
@@ -609,14 +618,27 @@ export function getResourceAttrListSimple({...params}: GetResourceAttrListSimple
|
|
|
609
618
|
});
|
|
610
619
|
}
|
|
611
620
|
|
|
612
|
-
interface
|
|
621
|
+
interface ListSimple4RecentlyParamsType {
|
|
613
622
|
|
|
614
623
|
}
|
|
615
624
|
|
|
616
|
-
export function listSimple4Recently({...params}:
|
|
625
|
+
export function listSimple4Recently({...params}: ListSimple4RecentlyParamsType = {}) {
|
|
617
626
|
return FUtil.Request({
|
|
618
627
|
method: 'GET',
|
|
619
628
|
url: `/v2/resources/types/listSimple4Recently`,
|
|
620
629
|
params: params,
|
|
621
630
|
});
|
|
622
631
|
}
|
|
632
|
+
|
|
633
|
+
// 通过key取资源属性
|
|
634
|
+
interface GetAttrsInfoByKeyParamsType {
|
|
635
|
+
key: string;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export function getAttrsInfoByKey({...params}: GetAttrsInfoByKeyParamsType) {
|
|
639
|
+
return FUtil.Request({
|
|
640
|
+
method: 'GET',
|
|
641
|
+
url: `/v2/resources/attrs/getInfoByKey`,
|
|
642
|
+
params: params,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export function useGetState<T>(initVal: T): [T, (newVal: T) => void, () => T] {
|
|
4
|
+
const [state, setState] = React.useState<T>(initVal);
|
|
5
|
+
const ref = React.useRef<T>(initVal);
|
|
6
|
+
|
|
7
|
+
function setStateCopy(newVal: T): void {
|
|
8
|
+
ref.current = newVal;
|
|
9
|
+
setState(newVal);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getState(): T {
|
|
13
|
+
return ref.current;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return [state, setStateCopy, getState];
|
|
17
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as LinkTo from './linkTo';
|
|
|
4
4
|
import * as Predefined from './predefined';
|
|
5
5
|
import Axios, {request} from './axios';
|
|
6
6
|
import * as Tool from './tools';
|
|
7
|
+
import * as Hook from './hooks';
|
|
7
8
|
// import I18n from '../i18n';
|
|
8
9
|
|
|
9
10
|
const FUtil = {
|
|
@@ -14,6 +15,7 @@ const FUtil = {
|
|
|
14
15
|
Axios,
|
|
15
16
|
Request: request,
|
|
16
17
|
Tool,
|
|
18
|
+
Hook,
|
|
17
19
|
// i18n: new I18n(),
|
|
18
20
|
};
|
|
19
21
|
|
package/src/utils/linkTo.ts
CHANGED
|
@@ -290,6 +290,17 @@ export function resourceFreeze({resourceID}: ResourceFreezeParamsType) {
|
|
|
290
290
|
return `/result/resource/freeze/${resourceID}`;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
// 站内搜索
|
|
294
|
+
interface GlobalSearchParamsType {
|
|
295
|
+
search: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function globalSearch({search}: GlobalSearchParamsType) {
|
|
299
|
+
return `/search${handleQuery({
|
|
300
|
+
search,
|
|
301
|
+
})}`;
|
|
302
|
+
}
|
|
303
|
+
|
|
293
304
|
/************** console End ******************************************************/
|
|
294
305
|
|
|
295
306
|
|
|
@@ -318,6 +329,21 @@ export function logon({goTo, ...params}: LoginParamsType = {}) {
|
|
|
318
329
|
})}`;
|
|
319
330
|
}
|
|
320
331
|
|
|
332
|
+
// 绑定账户
|
|
333
|
+
interface LoginParamsType {
|
|
334
|
+
goTo?: string;
|
|
335
|
+
identityId?: string;
|
|
336
|
+
returnUrl?: string;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function bind({goTo, returnUrl, ...params}: LoginParamsType = {}) {
|
|
340
|
+
return `/bind${handleQuery({
|
|
341
|
+
goTo: goTo ? encodeURIComponent(goTo) : undefined,
|
|
342
|
+
returnUrl: returnUrl ? encodeURIComponent(returnUrl) : undefined,
|
|
343
|
+
...params,
|
|
344
|
+
})}`;
|
|
345
|
+
}
|
|
346
|
+
|
|
321
347
|
// 找回密码
|
|
322
348
|
interface RetrieveUserPasswordParamsType {
|
|
323
349
|
goTo?: string;
|
|
@@ -380,7 +406,7 @@ export function setting({}: SettingParamsType = {}) {
|
|
|
380
406
|
}
|
|
381
407
|
|
|
382
408
|
|
|
383
|
-
//
|
|
409
|
+
// 绑定
|
|
384
410
|
interface BindingParamsType {
|
|
385
411
|
}
|
|
386
412
|
|
package/src/utils/regexp.ts
CHANGED
|
@@ -51,3 +51,10 @@ export const BUCKET_NAME: RegExp = new RegExp(/^([a-z0-9][a-z0-9-]{0,61})?[a-z0-
|
|
|
51
51
|
|
|
52
52
|
// JS变量名称
|
|
53
53
|
export const JS_VARIABLE_NAME: RegExp = new RegExp(/^[A-Za-z$_][\w$_]*$/);
|
|
54
|
+
|
|
55
|
+
// 日期
|
|
56
|
+
export const DATE: RegExp = new RegExp(/(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/);
|
|
57
|
+
|
|
58
|
+
// 日期时间
|
|
59
|
+
export const DATE_TIME: RegExp = new RegExp(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
60
|
+
|