@freelog/tools-lib 0.1.148 → 0.1.151

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freelog/tools-lib",
3
- "version": "0.1.148",
3
+ "version": "0.1.151",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,155 +1,155 @@
1
- import i18next, {Resource} from 'i18next';
2
- import axios from "axios";
3
- import Cookies from 'js-cookie';
4
- import FUtil from '../utils';
5
-
6
- type LanguageKeyType = 'zh_CN' | 'en_US';
7
-
8
- const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
9
- const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
10
- const localStorage_i18nextLng_key: string = 'locale';
11
- const localStorage_i18nextResources_key: string = 'i18nextResources';
12
-
13
- const allLanguage = [
14
- {value: 'en_US', label: 'English'},
15
- {value: 'zh_CN', label: '简体中文'},
16
- ];
17
-
18
- class I18nNext {
19
-
20
- private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
21
- private _taskQueue: Function[] = [];
22
- // private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
23
- private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
24
-
25
- constructor() {
26
- this.ready();
27
-
28
- this.ready = this.ready.bind(this);
29
- this.t = this.t.bind(this);
30
- this.changeLanguage = this.changeLanguage.bind(this);
31
- this.getAllLanguage = this.getAllLanguage.bind(this);
32
- this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
33
- }
34
-
35
- async ready(this: I18nNext) {
36
- const exc = () => {
37
- while (this._taskQueue.length > 0) {
38
- const task = this._taskQueue.shift();
39
- task && task();
40
- }
41
- };
42
- const handleTasks = async () => {
43
- // console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
44
- if (this._loadingData === 'End') {
45
- exc();
46
- return;
47
- }
48
- if (this._loadingData === 'Start') {
49
- return;
50
- }
51
-
52
- // NO_START
53
- this._loadingData = 'Start';
54
-
55
- await this._handleData();
56
- // console.log('######');
57
- exc();
58
- };
59
- const promise = new Promise((resolve) => {
60
- this._taskQueue.push(resolve);
61
- });
62
- handleTasks();
63
- return promise;
64
- }
65
-
66
- t(this: I18nNext, key: string, options?: { [key: string]: any }) {
67
- return i18next.t(key.trim(), options);
68
- }
69
-
70
- changeLanguage(this: I18nNext, lng: LanguageKeyType) {
71
- // return i18next.changeLanguage(lng);
72
- // window.localStorage.setItem(localStorage_i18nextLng_key, lng)
73
- Cookies.set(localStorage_i18nextLng_key, lng, {
74
- expires: 36525,
75
- domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
76
- });
77
- }
78
-
79
- getAllLanguage(this: I18nNext): typeof allLanguage {
80
- return allLanguage;
81
- }
82
-
83
- getCurrentLanguage(this: I18nNext): LanguageKeyType {
84
- return this._currentLanguage;
85
- }
86
-
87
- private async _handleData(this: I18nNext) {
88
-
89
- const lng: string = this._currentLanguage;
90
- const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
91
- // const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
92
- let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
93
-
94
- if (!i18nextResources) {
95
- // console.log('######892io3jlkl')
96
- i18nextResources = await this._fetchData();
97
- } else {
98
- this._fetchData();
99
- }
100
-
101
- await i18next
102
- .init({
103
- // the translations
104
- // (tip move them in a JSON file and import them,
105
- // or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
106
- resources: i18nextResources,
107
- lng: lng, // if you're using a language detector, do not define the lng option
108
- fallbackLng: 'zh_CN',
109
-
110
- interpolation: {
111
- escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
112
- prefix: '{',
113
- suffix: '}',
114
- },
115
- });
116
- this._loadingData = 'End';
117
- }
118
-
119
- private async _fetchData(this: I18nNext): Promise<Resource> {
120
- const url: string = window.location.origin.includes('.freelog.com') ? ossJsonUrl : ossJsonUrl_Test;
121
- const res: any = await axios.get(url + '?timestamp=' + Date.now(), {
122
- withCredentials: false,
123
- });
124
- // console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
125
-
126
- const en_US: { [key: string]: string } = {};
127
- const zh_CN: { [key: string]: string } = {};
128
-
129
- for (const [key, value] of Object.entries(res)) {
130
- // console.log(key, value, 'key, value90iowsldfjlsdkj');
131
- en_US[key] = (value as any)['en_US'];
132
- zh_CN[key] = (value as any)['zh_CN'];
133
- }
134
-
135
- const result: Resource = {
136
- en_US: {
137
- translation: en_US,
138
- },
139
- zh_CN: {
140
- translation: zh_CN,
141
- },
142
- };
143
-
144
- // console.log(result, 'result093sdolkfjlsdkjl');
145
- window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
146
- // Cookies.set(localStorage_i18nextResources_key, encodeURIComponent(JSON.stringify(result)), {
147
- // expires: 36525,
148
- // domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
149
- // });
150
-
151
- return result;
152
- }
153
- }
154
-
155
- export default I18nNext;
1
+ import i18next, {Resource} from 'i18next';
2
+ import axios from "axios";
3
+ import Cookies from 'js-cookie';
4
+ import FUtil from '../utils';
5
+
6
+ type LanguageKeyType = 'zh_CN' | 'en_US';
7
+
8
+ const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
9
+ const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
10
+ const localStorage_i18nextLng_key: string = 'locale';
11
+ const localStorage_i18nextResources_key: string = 'i18nextResources';
12
+
13
+ const allLanguage = [
14
+ {value: 'en_US', label: 'English'},
15
+ {value: 'zh_CN', label: '简体中文'},
16
+ ];
17
+
18
+ class I18nNext {
19
+
20
+ private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
21
+ private _taskQueue: Function[] = [];
22
+ // private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
23
+ private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
24
+
25
+ constructor() {
26
+ this.ready();
27
+
28
+ this.ready = this.ready.bind(this);
29
+ this.t = this.t.bind(this);
30
+ this.changeLanguage = this.changeLanguage.bind(this);
31
+ this.getAllLanguage = this.getAllLanguage.bind(this);
32
+ this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
33
+ }
34
+
35
+ async ready(this: I18nNext) {
36
+ const exc = () => {
37
+ while (this._taskQueue.length > 0) {
38
+ const task = this._taskQueue.shift();
39
+ task && task();
40
+ }
41
+ };
42
+ const handleTasks = async () => {
43
+ // console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
44
+ if (this._loadingData === 'End') {
45
+ exc();
46
+ return;
47
+ }
48
+ if (this._loadingData === 'Start') {
49
+ return;
50
+ }
51
+
52
+ // NO_START
53
+ this._loadingData = 'Start';
54
+
55
+ await this._handleData();
56
+ // console.log('######');
57
+ exc();
58
+ };
59
+ const promise = new Promise((resolve) => {
60
+ this._taskQueue.push(resolve);
61
+ });
62
+ handleTasks();
63
+ return promise;
64
+ }
65
+
66
+ t(this: I18nNext, key: string, options?: { [key: string]: any }) {
67
+ return i18next.t(key.trim(), options);
68
+ }
69
+
70
+ changeLanguage(this: I18nNext, lng: LanguageKeyType) {
71
+ // return i18next.changeLanguage(lng);
72
+ // window.localStorage.setItem(localStorage_i18nextLng_key, lng)
73
+ Cookies.set(localStorage_i18nextLng_key, lng, {
74
+ expires: 36525,
75
+ domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
76
+ });
77
+ }
78
+
79
+ getAllLanguage(this: I18nNext): typeof allLanguage {
80
+ return allLanguage;
81
+ }
82
+
83
+ getCurrentLanguage(this: I18nNext): LanguageKeyType {
84
+ return this._currentLanguage;
85
+ }
86
+
87
+ private async _handleData(this: I18nNext) {
88
+
89
+ const lng: string = this._currentLanguage;
90
+ const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
91
+ // const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
92
+ let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
93
+
94
+ if (!i18nextResources) {
95
+ // console.log('######892io3jlkl')
96
+ i18nextResources = await this._fetchData();
97
+ } else {
98
+ this._fetchData();
99
+ }
100
+
101
+ await i18next
102
+ .init({
103
+ // the translations
104
+ // (tip move them in a JSON file and import them,
105
+ // or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
106
+ resources: i18nextResources,
107
+ lng: lng, // if you're using a language detector, do not define the lng option
108
+ fallbackLng: 'zh_CN',
109
+
110
+ interpolation: {
111
+ escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
112
+ prefix: '{',
113
+ suffix: '}',
114
+ },
115
+ });
116
+ this._loadingData = 'End';
117
+ }
118
+
119
+ private async _fetchData(this: I18nNext): Promise<Resource> {
120
+ const url: string = window.location.origin.includes('.freelog.com') ? ossJsonUrl : ossJsonUrl_Test;
121
+ const res: any = await axios.get(url + '?timestamp=' + Date.now(), {
122
+ withCredentials: false,
123
+ });
124
+ // console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
125
+
126
+ const en_US: { [key: string]: string } = {};
127
+ const zh_CN: { [key: string]: string } = {};
128
+
129
+ for (const [key, value] of Object.entries(res)) {
130
+ // console.log(key, value, 'key, value90iowsldfjlsdkj');
131
+ en_US[key] = (value as any)['en_US'];
132
+ zh_CN[key] = (value as any)['zh_CN'];
133
+ }
134
+
135
+ const result: Resource = {
136
+ en_US: {
137
+ translation: en_US,
138
+ },
139
+ zh_CN: {
140
+ translation: zh_CN,
141
+ },
142
+ };
143
+
144
+ // console.log(result, 'result093sdolkfjlsdkjl');
145
+ window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
146
+ // Cookies.set(localStorage_i18nextResources_key, encodeURIComponent(JSON.stringify(result)), {
147
+ // expires: 36525,
148
+ // domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
149
+ // });
150
+
151
+ return result;
152
+ }
153
+ }
154
+
155
+ export default I18nNext;
@@ -20,6 +20,7 @@ interface CollectionResourcesParamsType {
20
20
  limit?: number;
21
21
  keywords?: string;
22
22
  resourceType?: string;
23
+ resourceTypeCode?: string;
23
24
  omitResourceType?: string;
24
25
  resourceStatus?: 0 | 1 | 2 | 4;
25
26
  }
@@ -15,6 +15,7 @@ import * as Statistic from './statistics';
15
15
  import * as I18n from './i18n';
16
16
  import * as Policy from './policies';
17
17
  import * as recombination from './recombinations';
18
+ import * as Operation from './operation';
18
19
 
19
20
  const FServiceAPI = {
20
21
  Node,
@@ -34,6 +35,7 @@ const FServiceAPI = {
34
35
  I18n,
35
36
  Policy,
36
37
  recombination,
38
+ Operation,
37
39
  };
38
40
 
39
41
  export default FServiceAPI;
@@ -1,65 +1,81 @@
1
- import FUtil from '../utils';
2
-
3
- // 创建节点
4
- export interface CreateParamsType {
5
- nodeName: string;
6
- nodeDomain: string;
7
- }
8
-
9
- export function create(params: CreateParamsType) {
10
- // return FUtil.Axios.post('/v2/nodes', params);
11
- return FUtil.Request({
12
- method: 'POST',
13
- url: `/v2/nodes`,
14
- data: params,
15
- });
16
- }
17
-
18
- // 查看节点详情
19
- interface NodeDetailParamsType1 {
20
- nodeId: number;
21
- }
22
-
23
- interface NodeDetailParamsType2 {
24
- nodeName?: string;
25
- nodeDomain?: string;
26
- }
27
-
28
- export function details(params: NodeDetailParamsType1 | NodeDetailParamsType2) {
29
- if ((params as NodeDetailParamsType1).nodeId) {
30
- // return FUtil.Axios.get(`/v2/nodes/${(params as NodeDetailParamsType1).nodeId}`);
31
- return FUtil.Request({
32
- method: 'GET',
33
- url: `/v2/nodes/${(params as NodeDetailParamsType1).nodeId}`,
34
- // params: params,
35
- });
36
- }
37
- // return FUtil.Axios.get(`/v2/nodes/detail`, {
38
- // params,
39
- // });
40
- return FUtil.Request({
41
- method: 'GET',
42
- url: `/v2/nodes/detail`,
43
- params: params,
44
- });
45
- }
46
-
47
- // 查看节点列表
48
- interface NodesParamsType {
49
- skip?: number;
50
- limit?: number;
51
- status?: 0 | 1 | 2; // 0:正常 1:未审核 2:冻结
52
- projection?: string;
53
- }
54
-
55
- export function nodes(params: NodesParamsType) {
56
- // return FUtil.Axios.get('/v2/nodes', {
57
- // params
58
- // });
59
- return FUtil.Request({
60
- method: 'GET',
61
- url: `/v2/nodes`,
62
- params: params,
63
- });
64
- }
65
-
1
+ import FUtil from '../utils';
2
+
3
+ // 创建节点
4
+ export interface CreateParamsType {
5
+ nodeName: string;
6
+ nodeDomain: string;
7
+ }
8
+
9
+ export function create(params: CreateParamsType) {
10
+ // return FUtil.Axios.post('/v2/nodes', params);
11
+ return FUtil.Request({
12
+ method: 'POST',
13
+ url: `/v2/nodes`,
14
+ data: params,
15
+ });
16
+ }
17
+
18
+ // 查看节点详情
19
+ interface NodeDetailParamsType1 {
20
+ nodeId: number;
21
+ }
22
+
23
+ interface NodeDetailParamsType2 {
24
+ nodeName?: string;
25
+ nodeDomain?: string;
26
+ }
27
+
28
+ export function details(params: NodeDetailParamsType1 | NodeDetailParamsType2) {
29
+ if ((params as NodeDetailParamsType1).nodeId) {
30
+ // return FUtil.Axios.get(`/v2/nodes/${(params as NodeDetailParamsType1).nodeId}`);
31
+ return FUtil.Request({
32
+ method: 'GET',
33
+ url: `/v2/nodes/${(params as NodeDetailParamsType1).nodeId}`,
34
+ // params: params,
35
+ });
36
+ }
37
+ // return FUtil.Axios.get(`/v2/nodes/detail`, {
38
+ // params,
39
+ // });
40
+ return FUtil.Request({
41
+ method: 'GET',
42
+ url: `/v2/nodes/detail`,
43
+ params: params,
44
+ });
45
+ }
46
+
47
+ // 查看节点列表
48
+ interface NodesParamsType {
49
+ skip?: number;
50
+ limit?: number;
51
+ status?: 0 | 1 | 2; // 0:正常 1:未审核 2:冻结
52
+ projection?: string;
53
+ }
54
+
55
+ export function nodes(params: NodesParamsType) {
56
+ return FUtil.Request({
57
+ method: 'GET',
58
+ url: `/v2/nodes`,
59
+ params: params,
60
+ });
61
+ }
62
+
63
+ // 设置节点信息
64
+ interface SetNodeInfoParamsType {
65
+ nodeId: number;
66
+ nodeLogo: string;
67
+ nodeTitle: string;
68
+ nodeShortDescription: string;
69
+ // nodeVisibility: 1 | 2 | 3; // 可见性 1:公开 2:私密 3:暂停
70
+ status: 1 | 2 | 8; // 可见性 1:公开 2:私密 3:暂停
71
+ nodeSuspendInfo: string;
72
+ }
73
+
74
+ export function setNodeInfo(params: SetNodeInfoParamsType) {
75
+ return FUtil.Request({
76
+ method: 'POST',
77
+ url: `/v2/nodes/setNodeInfo`,
78
+ data: params,
79
+ });
80
+ }
81
+
@@ -0,0 +1,14 @@
1
+ import FUtil from '../utils';
2
+
3
+ // 列出运营分类分组排序
4
+ interface OperationCategoriesParamsType {
5
+ name?: string;
6
+ }
7
+
8
+ export function operationCategories({...params}: OperationCategoriesParamsType = {}) {
9
+ return FUtil.Request({
10
+ method: 'GET',
11
+ url: `/v2/resources/operation-categories/listSimpleByGroup`,
12
+ params: params,
13
+ });
14
+ }
@@ -131,6 +131,7 @@ interface PresentablesParamsType {
131
131
  skip?: number;
132
132
  limit?: number;
133
133
  resourceType?: string;
134
+ resourceTypeCode?: string;
134
135
  omitResourceType?: string;
135
136
  onlineStatus?: number;
136
137
  tags?: string;