@freelog/tools-lib 0.1.100 → 0.1.105
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 +21 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/index.d.ts +2 -1
- package/dist/service-API/i18n.d.ts +8 -0
- package/dist/service-API/index.d.ts +2 -0
- package/dist/service-API/resources.d.ts +1 -0
- package/dist/service-API/user.d.ts +2 -1
- package/dist/tools-lib.cjs.development.js +980 -291
- 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 +980 -292
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/linkTo.d.ts +4 -0
- package/package.json +65 -64
- package/src/i18n/I18nNext.ts +134 -0
- package/src/i18n/index.ts +7 -0
- package/src/index.ts +9 -7
- package/src/service-API/i18n.ts +35 -0
- package/src/service-API/index.ts +2 -0
- package/src/service-API/resources.ts +1 -0
- package/src/service-API/user.ts +4 -2
- package/src/utils/index.ts +20 -18
- package/src/utils/linkTo.ts +12 -0
package/dist/utils/linkTo.d.ts
CHANGED
|
@@ -95,6 +95,10 @@ interface NodeCreateSuccessParamsType {
|
|
|
95
95
|
nodeID: number;
|
|
96
96
|
}
|
|
97
97
|
export declare function nodeCreateSuccess({ nodeID }: NodeCreateSuccessParamsType): string;
|
|
98
|
+
interface InvitationParamsType {
|
|
99
|
+
goTo?: string;
|
|
100
|
+
}
|
|
101
|
+
export declare function invitation({ ...params }?: InvitationParamsType): string;
|
|
98
102
|
interface Exception403ParamsType {
|
|
99
103
|
from?: string;
|
|
100
104
|
}
|
package/package.json
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@freelog/tools-lib",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"typings": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"src"
|
|
10
|
-
],
|
|
11
|
-
"engines": {
|
|
12
|
-
"node": ">=10"
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"start": "tsdx watch",
|
|
16
|
-
"build": "tsdx build",
|
|
17
|
-
"test": "tsdx test",
|
|
18
|
-
"lint": "tsdx lint",
|
|
19
|
-
"prepare": "tsdx build",
|
|
20
|
-
"size": "size-limit",
|
|
21
|
-
"analyze": "size-limit --why",
|
|
22
|
-
"publish": "npm publish --access public"
|
|
23
|
-
},
|
|
24
|
-
"peerDependencies": {},
|
|
25
|
-
"husky": {
|
|
26
|
-
"hooks": {}
|
|
27
|
-
},
|
|
28
|
-
"prettier": {
|
|
29
|
-
"printWidth": 80,
|
|
30
|
-
"semi": true,
|
|
31
|
-
"singleQuote": true,
|
|
32
|
-
"trailingComma": "es5"
|
|
33
|
-
},
|
|
34
|
-
"author": "liu-kai-github",
|
|
35
|
-
"module": "dist/tools-lib.esm.js",
|
|
36
|
-
"size-limit": [
|
|
37
|
-
{
|
|
38
|
-
"path": "dist/tools-lib.cjs.production.min.js",
|
|
39
|
-
"limit": "10 KB"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"path": "dist/tools-lib.esm.js",
|
|
43
|
-
"limit": "10 KB"
|
|
44
|
-
}
|
|
45
|
-
],
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@size-limit/preset-small-lib": "^4.11.0",
|
|
48
|
-
"@types/crypto-js": "^4.0.1",
|
|
49
|
-
"@types/nprogress": "^0.2.0",
|
|
50
|
-
"husky": "^6.0.0",
|
|
51
|
-
"size-limit": "^4.11.0",
|
|
52
|
-
"tsdx": "^0.14.1",
|
|
53
|
-
"tslib": "^2.2.0",
|
|
54
|
-
"typescript": "^4.3.2"
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@freelog/resource-policy-lang": "1.1.26",
|
|
58
|
-
"@freelog/tools-lib": "^0.1.43",
|
|
59
|
-
"axios": "^0.21.1",
|
|
60
|
-
"crypto-js": "^4.0.0",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@freelog/tools-lib",
|
|
3
|
+
"version": "0.1.105",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=10"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "tsdx watch",
|
|
16
|
+
"build": "tsdx build",
|
|
17
|
+
"test": "tsdx test",
|
|
18
|
+
"lint": "tsdx lint",
|
|
19
|
+
"prepare": "tsdx build",
|
|
20
|
+
"size": "size-limit",
|
|
21
|
+
"analyze": "size-limit --why",
|
|
22
|
+
"publish": "npm publish --access public"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {},
|
|
25
|
+
"husky": {
|
|
26
|
+
"hooks": {}
|
|
27
|
+
},
|
|
28
|
+
"prettier": {
|
|
29
|
+
"printWidth": 80,
|
|
30
|
+
"semi": true,
|
|
31
|
+
"singleQuote": true,
|
|
32
|
+
"trailingComma": "es5"
|
|
33
|
+
},
|
|
34
|
+
"author": "liu-kai-github",
|
|
35
|
+
"module": "dist/tools-lib.esm.js",
|
|
36
|
+
"size-limit": [
|
|
37
|
+
{
|
|
38
|
+
"path": "dist/tools-lib.cjs.production.min.js",
|
|
39
|
+
"limit": "10 KB"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "dist/tools-lib.esm.js",
|
|
43
|
+
"limit": "10 KB"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@size-limit/preset-small-lib": "^4.11.0",
|
|
48
|
+
"@types/crypto-js": "^4.0.1",
|
|
49
|
+
"@types/nprogress": "^0.2.0",
|
|
50
|
+
"husky": "^6.0.0",
|
|
51
|
+
"size-limit": "^4.11.0",
|
|
52
|
+
"tsdx": "^0.14.1",
|
|
53
|
+
"tslib": "^2.2.0",
|
|
54
|
+
"typescript": "^4.3.2"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@freelog/resource-policy-lang": "1.1.26",
|
|
58
|
+
"@freelog/tools-lib": "^0.1.43",
|
|
59
|
+
"axios": "^0.21.1",
|
|
60
|
+
"crypto-js": "^4.0.0",
|
|
61
|
+
"i18next": "^21.8.10",
|
|
62
|
+
"moment": "^2.29.1",
|
|
63
|
+
"nprogress": "^0.2.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import i18next, {Resource} from 'i18next';
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
5
|
+
|
|
6
|
+
const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
|
|
7
|
+
const localStorage_i18nextLng_key: string = 'i18nextLng';
|
|
8
|
+
const localStorage_i18nextResources_key: string = 'i18nextResources';
|
|
9
|
+
|
|
10
|
+
const allLanguage = [
|
|
11
|
+
{value: 'en_US', label: 'English'},
|
|
12
|
+
{value: 'zh_CN', label: '简体中文'},
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
let self: I18nNext;
|
|
16
|
+
|
|
17
|
+
class I18nNext {
|
|
18
|
+
|
|
19
|
+
private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
|
|
20
|
+
private _taskQueue: Function[] = [];
|
|
21
|
+
private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
self = this;
|
|
25
|
+
self.ready();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async ready() {
|
|
29
|
+
const exc = () => {
|
|
30
|
+
while (self._taskQueue.length > 0) {
|
|
31
|
+
const task = self._taskQueue.shift();
|
|
32
|
+
task && task();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const handleTasks = async () => {
|
|
36
|
+
if (self._loadingData === 'End') {
|
|
37
|
+
exc();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (self._loadingData === 'Start') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// NO_START
|
|
45
|
+
self._loadingData = 'Start';
|
|
46
|
+
|
|
47
|
+
await self._handleData();
|
|
48
|
+
// console.log('######');
|
|
49
|
+
exc();
|
|
50
|
+
};
|
|
51
|
+
const promise = new Promise((resolve) => {
|
|
52
|
+
self._taskQueue.push(resolve);
|
|
53
|
+
});
|
|
54
|
+
handleTasks();
|
|
55
|
+
return promise;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
t(key: string, options?: { [key: string]: any }) {
|
|
59
|
+
return i18next.t(key, options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
changeLanguage(lng: LanguageKeyType) {
|
|
63
|
+
// return i18next.changeLanguage(lng);
|
|
64
|
+
window.localStorage.setItem(localStorage_i18nextLng_key, lng)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getAllLanguage(): typeof allLanguage {
|
|
68
|
+
return allLanguage;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getCurrentLanguage(): LanguageKeyType {
|
|
72
|
+
return self._currentLanguage;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private async _handleData() {
|
|
76
|
+
|
|
77
|
+
const lng: string = self._currentLanguage;
|
|
78
|
+
const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
|
|
79
|
+
let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
|
|
80
|
+
|
|
81
|
+
if (!i18nextResources) {
|
|
82
|
+
// console.log('######892io3jlkl')
|
|
83
|
+
i18nextResources = await self._fetchData();
|
|
84
|
+
} else {
|
|
85
|
+
self._fetchData();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await i18next
|
|
89
|
+
.init({
|
|
90
|
+
// the translations
|
|
91
|
+
// (tip move them in a JSON file and import them,
|
|
92
|
+
// or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
|
|
93
|
+
resources: i18nextResources,
|
|
94
|
+
lng: lng, // if you're using a language detector, do not define the lng option
|
|
95
|
+
fallbackLng: 'zh_CN',
|
|
96
|
+
|
|
97
|
+
interpolation: {
|
|
98
|
+
escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private async _fetchData(): Promise<Resource> {
|
|
104
|
+
const res: any = await axios.get(ossJsonUrl, {
|
|
105
|
+
withCredentials: false,
|
|
106
|
+
});
|
|
107
|
+
// console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
|
|
108
|
+
|
|
109
|
+
const en_US: { [key: string]: string } = {};
|
|
110
|
+
const zh_CN: { [key: string]: string } = {};
|
|
111
|
+
|
|
112
|
+
for (const [key, value] of Object.entries(res)) {
|
|
113
|
+
// console.log(key, value, 'key, value90iowsldfjlsdkj');
|
|
114
|
+
en_US[key] = (value as any)['en_US'];
|
|
115
|
+
zh_CN[key] = (value as any)['zh_CN'];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const result: Resource = {
|
|
119
|
+
en_US: {
|
|
120
|
+
translation: en_US,
|
|
121
|
+
},
|
|
122
|
+
zh_CN: {
|
|
123
|
+
translation: zh_CN,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// console.log(result, 'result093sdolkfjlsdkjl');
|
|
128
|
+
window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export default I18nNext;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import FUtil from './utils';
|
|
2
|
-
import FServiceAPI from './service-API';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import FUtil from './utils';
|
|
2
|
+
import FServiceAPI from './service-API';
|
|
3
|
+
import FI18n from './i18n';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
FUtil,
|
|
7
|
+
FServiceAPI,
|
|
8
|
+
FI18n,
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import FUtil from '../utils';
|
|
2
|
+
|
|
3
|
+
// 列出翻译
|
|
4
|
+
interface ConfigsListParamsType {
|
|
5
|
+
key: string;
|
|
6
|
+
content: string;
|
|
7
|
+
tagIds: string[];
|
|
8
|
+
status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function configsList(params: ConfigsListParamsType) {
|
|
12
|
+
// console.log('####@30984i2o3jdsjflfkjsdl')
|
|
13
|
+
return FUtil.Request({
|
|
14
|
+
method: 'POST',
|
|
15
|
+
url: `/v2/i18n/configs/list`,
|
|
16
|
+
data: params,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// oss保存的翻译
|
|
21
|
+
// interface ConfigsListParamsType {
|
|
22
|
+
// key: string;
|
|
23
|
+
// content: string;
|
|
24
|
+
// tagIds: string[];
|
|
25
|
+
// status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
|
|
26
|
+
// }
|
|
27
|
+
//
|
|
28
|
+
// export function configsList(params: ConfigsListParamsType) {
|
|
29
|
+
// // console.log('####@30984i2o3jdsjflfkjsdl')
|
|
30
|
+
// return FUtil.Request({
|
|
31
|
+
// method: 'POST',
|
|
32
|
+
// url: `/v2/i18n/configs/list`,
|
|
33
|
+
// data: params,
|
|
34
|
+
// });
|
|
35
|
+
// }
|
package/src/service-API/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import * as Event from './events';
|
|
|
12
12
|
import * as Activity from './activities';
|
|
13
13
|
import * as TestQualification from './testQualifications';
|
|
14
14
|
import * as Statistic from './statistics';
|
|
15
|
+
import * as I18n from './i18n';
|
|
15
16
|
|
|
16
17
|
const FServiceAPI = {
|
|
17
18
|
Node,
|
|
@@ -28,6 +29,7 @@ const FServiceAPI = {
|
|
|
28
29
|
Activity,
|
|
29
30
|
TestQualification,
|
|
30
31
|
Statistic,
|
|
32
|
+
I18n,
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
export default FServiceAPI;
|
package/src/service-API/user.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import FUtil from '../utils';
|
|
2
|
+
import {AxiosRequestConfig} from "axios";
|
|
2
3
|
|
|
3
4
|
// 用户登录
|
|
4
5
|
interface LoginParamsType {
|
|
@@ -114,7 +115,7 @@ interface UploadHeadImgParamsType {
|
|
|
114
115
|
file: File;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export function uploadHeadImg(params: UploadHeadImgParamsType) {
|
|
118
|
+
export function uploadHeadImg(params: UploadHeadImgParamsType, config?: AxiosRequestConfig) {
|
|
118
119
|
|
|
119
120
|
const formData = new FormData();
|
|
120
121
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -126,7 +127,8 @@ export function uploadHeadImg(params: UploadHeadImgParamsType) {
|
|
|
126
127
|
return FUtil.Request({
|
|
127
128
|
method: 'POST',
|
|
128
129
|
url: `/v2/users/current/uploadHeadImg`,
|
|
129
|
-
data:
|
|
130
|
+
data: formData,
|
|
131
|
+
...config,
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
134
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import * as Format from './format';
|
|
2
|
-
import * as Regexp from './regexp';
|
|
3
|
-
import * as LinkTo from './linkTo';
|
|
4
|
-
import * as Predefined from './predefined';
|
|
5
|
-
import Axios, {request} from './axios';
|
|
6
|
-
import * as Tool from './tools';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import * as Format from './format';
|
|
2
|
+
import * as Regexp from './regexp';
|
|
3
|
+
import * as LinkTo from './linkTo';
|
|
4
|
+
import * as Predefined from './predefined';
|
|
5
|
+
import Axios, {request} from './axios';
|
|
6
|
+
import * as Tool from './tools';
|
|
7
|
+
// import I18n from '../i18n';
|
|
8
|
+
|
|
9
|
+
const FUtil = {
|
|
10
|
+
Format,
|
|
11
|
+
Regexp,
|
|
12
|
+
LinkTo,
|
|
13
|
+
Predefined,
|
|
14
|
+
Axios,
|
|
15
|
+
Request: request,
|
|
16
|
+
Tool,
|
|
17
|
+
// i18n: new I18n(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default FUtil;
|
package/src/utils/linkTo.ts
CHANGED
|
@@ -228,6 +228,18 @@ export function nodeCreateSuccess({nodeID}: NodeCreateSuccessParamsType) {
|
|
|
228
228
|
return `/result/node/create/success/${nodeID}`;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
// 节点创建成功
|
|
232
|
+
interface InvitationParamsType {
|
|
233
|
+
goTo?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function invitation({...params}: InvitationParamsType = {}) {
|
|
237
|
+
// console.log(params.goTo, 'goTo9iowjefklsdj;flksdjflk')
|
|
238
|
+
return `/invitation${handleQuery({
|
|
239
|
+
returnUrl: params.goTo ? encodeURIComponent(params.goTo) : undefined,
|
|
240
|
+
})}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
231
243
|
// 403
|
|
232
244
|
interface Exception403ParamsType {
|
|
233
245
|
from?: string;
|