@freelog/tools-lib 0.1.199 → 0.2.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/i18n/I18nNext.d.ts +3 -0
- package/dist/service-API/captcha.d.ts +2 -2
- package/dist/service-API/payment.d.ts +2 -1
- package/dist/tools-lib.cjs.development.js +7 -0
- 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 +7 -0
- package/dist/tools-lib.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/i18n/I18nNext.ts +164 -156
- package/src/service-API/captcha.ts +30 -30
- package/src/service-API/payment.ts +3 -1
package/package.json
CHANGED
package/src/i18n/I18nNext.ts
CHANGED
|
@@ -1,156 +1,164 @@
|
|
|
1
|
-
import i18next, {Resource} from 'i18next';
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import Cookies from 'js-cookie';
|
|
4
|
-
import FUtil from '../utils';
|
|
5
|
-
// import * as React from 'react';
|
|
6
|
-
import htmlReactParser from 'html-react-parser';
|
|
7
|
-
|
|
8
|
-
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
9
|
-
|
|
10
|
-
const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
|
|
11
|
-
const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
|
|
12
|
-
const localStorage_i18nextLng_key: string = 'locale';
|
|
13
|
-
const localStorage_i18nextResources_key: string = 'i18nextResources';
|
|
14
|
-
|
|
15
|
-
const allLanguage = [
|
|
16
|
-
{value: 'en_US', label: 'English'},
|
|
17
|
-
{value: 'zh_CN', label: '简体中文'},
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
class I18nNext {
|
|
21
|
-
|
|
22
|
-
private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
|
|
23
|
-
private _taskQueue: Function[] = [];
|
|
24
|
-
// private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
|
|
25
|
-
private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
|
|
26
|
-
|
|
27
|
-
constructor() {
|
|
28
|
-
this.ready();
|
|
29
|
-
|
|
30
|
-
this.ready = this.ready.bind(this);
|
|
31
|
-
this.t = this.t.bind(this);
|
|
32
|
-
this.changeLanguage = this.changeLanguage.bind(this);
|
|
33
|
-
this.getAllLanguage = this.getAllLanguage.bind(this);
|
|
34
|
-
this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async ready(this: I18nNext): Promise<void> {
|
|
38
|
-
const exc = () => {
|
|
39
|
-
while (this._taskQueue.length > 0) {
|
|
40
|
-
const task = this._taskQueue.shift();
|
|
41
|
-
task && task();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const handleTasks = async () => {
|
|
45
|
-
// console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
|
|
46
|
-
if (this._loadingData === 'End') {
|
|
47
|
-
exc();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (this._loadingData === 'Start') {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// NO_START
|
|
55
|
-
this._loadingData = 'Start';
|
|
56
|
-
|
|
57
|
-
await this._handleData();
|
|
58
|
-
// console.log('######');
|
|
59
|
-
exc();
|
|
60
|
-
};
|
|
61
|
-
const promise = new Promise<void>((resolve) => {
|
|
62
|
-
this._taskQueue.push(resolve);
|
|
63
|
-
});
|
|
64
|
-
handleTasks();
|
|
65
|
-
return promise;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
t(this: I18nNext, key: string, options?: { [key: string]: any }): string {
|
|
69
|
-
return i18next.t(key.trim(), options);
|
|
70
|
-
}
|
|
71
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
import i18next, {Resource} from 'i18next';
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import Cookies from 'js-cookie';
|
|
4
|
+
import FUtil from '../utils';
|
|
5
|
+
// import * as React from 'react';
|
|
6
|
+
import htmlReactParser from 'html-react-parser';
|
|
7
|
+
|
|
8
|
+
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
9
|
+
|
|
10
|
+
const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
|
|
11
|
+
const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
|
|
12
|
+
const localStorage_i18nextLng_key: string = 'locale';
|
|
13
|
+
const localStorage_i18nextResources_key: string = 'i18nextResources';
|
|
14
|
+
|
|
15
|
+
const allLanguage = [
|
|
16
|
+
{value: 'en_US', label: 'English'},
|
|
17
|
+
{value: 'zh_CN', label: '简体中文'},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
class I18nNext {
|
|
21
|
+
|
|
22
|
+
private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
|
|
23
|
+
private _taskQueue: Function[] = [];
|
|
24
|
+
// private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
|
|
25
|
+
private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
this.ready();
|
|
29
|
+
|
|
30
|
+
this.ready = this.ready.bind(this);
|
|
31
|
+
this.t = this.t.bind(this);
|
|
32
|
+
this.changeLanguage = this.changeLanguage.bind(this);
|
|
33
|
+
this.getAllLanguage = this.getAllLanguage.bind(this);
|
|
34
|
+
this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async ready(this: I18nNext): Promise<void> {
|
|
38
|
+
const exc = () => {
|
|
39
|
+
while (this._taskQueue.length > 0) {
|
|
40
|
+
const task = this._taskQueue.shift();
|
|
41
|
+
task && task();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const handleTasks = async () => {
|
|
45
|
+
// console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
|
|
46
|
+
if (this._loadingData === 'End') {
|
|
47
|
+
exc();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (this._loadingData === 'Start') {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// NO_START
|
|
55
|
+
this._loadingData = 'Start';
|
|
56
|
+
|
|
57
|
+
await this._handleData();
|
|
58
|
+
// console.log('######');
|
|
59
|
+
exc();
|
|
60
|
+
};
|
|
61
|
+
const promise = new Promise<void>((resolve) => {
|
|
62
|
+
this._taskQueue.push(resolve);
|
|
63
|
+
});
|
|
64
|
+
handleTasks();
|
|
65
|
+
return promise;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
t(this: I18nNext, key: string, options?: { [key: string]: any }): string {
|
|
69
|
+
return i18next.t(key.trim(), options);
|
|
70
|
+
}
|
|
71
|
+
|
|
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
|
+
tAuto(this: I18nNext, key: string, options?: { [key: string]: any }): string | JSX.Element | JSX.Element[] {
|
|
77
|
+
const i18n_str: string = i18next.t(key.trim(), options);
|
|
78
|
+
if (!i18n_str.startsWith('<div class="i18n"')) {
|
|
79
|
+
return i18n_str;
|
|
80
|
+
}
|
|
81
|
+
return htmlReactParser(i18n_str);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
changeLanguage(this: I18nNext, lng: LanguageKeyType): void {
|
|
86
|
+
// return i18next.changeLanguage(lng);
|
|
87
|
+
// window.localStorage.setItem(localStorage_i18nextLng_key, lng)
|
|
88
|
+
Cookies.set(localStorage_i18nextLng_key, lng, {
|
|
89
|
+
expires: 36525,
|
|
90
|
+
domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getAllLanguage(this: I18nNext): typeof allLanguage {
|
|
95
|
+
return allLanguage;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getCurrentLanguage(this: I18nNext): LanguageKeyType {
|
|
99
|
+
return this._currentLanguage;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async _handleData(this: I18nNext): Promise<void> {
|
|
103
|
+
|
|
104
|
+
const lng: string = this._currentLanguage;
|
|
105
|
+
const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
|
|
106
|
+
// const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
|
|
107
|
+
let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
|
|
108
|
+
|
|
109
|
+
if (!i18nextResources) {
|
|
110
|
+
// console.log('######892io3jlkl')
|
|
111
|
+
i18nextResources = await this._fetchData();
|
|
112
|
+
} else {
|
|
113
|
+
this._fetchData();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await i18next
|
|
117
|
+
.init({
|
|
118
|
+
// the translations
|
|
119
|
+
// (tip move them in a JSON file and import them,
|
|
120
|
+
// or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
|
|
121
|
+
resources: i18nextResources,
|
|
122
|
+
lng: lng, // if you're using a language detector, do not define the lng option
|
|
123
|
+
fallbackLng: 'zh_CN',
|
|
124
|
+
|
|
125
|
+
interpolation: {
|
|
126
|
+
escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
|
|
127
|
+
prefix: '{',
|
|
128
|
+
suffix: '}',
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
this._loadingData = 'End';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private async _fetchData(this: I18nNext): Promise<Resource> {
|
|
135
|
+
const url: string = window.location.origin.includes('.freelog.com') ? ossJsonUrl : ossJsonUrl_Test;
|
|
136
|
+
const res: any = await axios.get(url + '?timestamp=' + Date.now(), {
|
|
137
|
+
withCredentials: false,
|
|
138
|
+
});
|
|
139
|
+
// console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
|
|
140
|
+
|
|
141
|
+
const en_US: { [key: string]: string } = {};
|
|
142
|
+
const zh_CN: { [key: string]: string } = {};
|
|
143
|
+
|
|
144
|
+
for (const [key, value] of Object.entries(res)) {
|
|
145
|
+
// console.log(key, value, 'key, value90iowsldfjlsdkj');
|
|
146
|
+
en_US[key] = (value as any)['en_US'];
|
|
147
|
+
zh_CN[key] = (value as any)['zh_CN'];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const result: Resource = {
|
|
151
|
+
en_US: {
|
|
152
|
+
translation: en_US,
|
|
153
|
+
},
|
|
154
|
+
zh_CN: {
|
|
155
|
+
translation: zh_CN,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default I18nNext;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import FUtil from '../utils';
|
|
2
|
-
|
|
3
|
-
// 发送短信或邮件验证码
|
|
4
|
-
interface SendVerificationCodeParamsType {
|
|
5
|
-
loginName: string;
|
|
6
|
-
authCodeType: 'register' | 'resetPassword' | 'activateTransactionAccount' | 'updateTransactionAccountPwd' | 'updateMobileOrEmail';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function sendVerificationCode(params: SendVerificationCodeParamsType) {
|
|
10
|
-
return FUtil.Request({
|
|
11
|
-
method: 'POST',
|
|
12
|
-
url: `/v2/messages/send`,
|
|
13
|
-
data: params,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 校验短信或邮件验证码
|
|
18
|
-
interface VerifyVerificationCodeParamsType {
|
|
19
|
-
authCode: string;
|
|
20
|
-
address: string;
|
|
21
|
-
authCodeType: 'register' | 'resetPassword' | 'activateTransactionAccount' | 'updateTransactionAccountPwd' | 'updateMobileOrEmail';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function verifyVerificationCode(params: VerifyVerificationCodeParamsType): Promise<any> {
|
|
25
|
-
return FUtil.Request({
|
|
26
|
-
method: 'GET',
|
|
27
|
-
url: `/v2/messages/verify`,
|
|
28
|
-
params: params,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
1
|
+
import FUtil from '../utils';
|
|
2
|
+
|
|
3
|
+
// 发送短信或邮件验证码
|
|
4
|
+
interface SendVerificationCodeParamsType {
|
|
5
|
+
loginName: string;
|
|
6
|
+
authCodeType: 'register' | 'resetPassword' | 'activateTransactionAccount' | 'updateTransactionAccountPwd' | 'updateMobileOrEmail' | 'activateTransactionAccount';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function sendVerificationCode(params: SendVerificationCodeParamsType) {
|
|
10
|
+
return FUtil.Request({
|
|
11
|
+
method: 'POST',
|
|
12
|
+
url: `/v2/messages/send`,
|
|
13
|
+
data: params,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 校验短信或邮件验证码
|
|
18
|
+
interface VerifyVerificationCodeParamsType {
|
|
19
|
+
authCode: string;
|
|
20
|
+
address: string;
|
|
21
|
+
authCodeType: 'register' | 'resetPassword' | 'activateTransactionAccount' | 'updateTransactionAccountPwd' | 'updateMobileOrEmail' | 'activateTransactionAccount';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function verifyVerificationCode(params: VerifyVerificationCodeParamsType): Promise<any> {
|
|
25
|
+
return FUtil.Request({
|
|
26
|
+
method: 'GET',
|
|
27
|
+
url: `/v2/messages/verify`,
|
|
28
|
+
params: params,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -70,7 +70,7 @@ export function updateFinancialAccount({accountId, ...params}: UpdateFinancialAc
|
|
|
70
70
|
interface BindWithdrawCardParamsType {
|
|
71
71
|
accountId: string; // 金融账户ID
|
|
72
72
|
cardType: 0 | 1 | 2 | 4; // 0:对公,1:对私法人,2:对私非法人,4:对公非同名;个人商户/用户不支持对公类型,对私非法人类型;
|
|
73
|
-
bankName: string; // 开户行名称
|
|
73
|
+
// bankName: string; // 开户行名称
|
|
74
74
|
// cardName: string; // 持卡人姓名
|
|
75
75
|
cardNo: string; // 卡号
|
|
76
76
|
provId: string; // 银行所在省ID
|
|
@@ -202,6 +202,8 @@ export function queryTransactionList(params: QueryTransactionListParamsType, con
|
|
|
202
202
|
interface QueryStatisticsParamsType {
|
|
203
203
|
ownerId: number; // 交易记录所属者ID; 根据所属者类型动态赋值userId或nodeId
|
|
204
204
|
ownerType: 1 | 2; // 交易记录所属者类型; 1:资源创作者用户id 2:节点
|
|
205
|
+
startTransactionDate: string;
|
|
206
|
+
endTransactionDate: string;
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
export function queryStatistics(params: QueryStatisticsParamsType, config?: AxiosRequestConfig) {
|