@tddc/assign-modal 3.1.3 → 3.1.5

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.
@@ -161,7 +161,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
161
161
  import { cloneDeep, debounce } from 'lodash';
162
162
  import './index.less';
163
163
  import { findSameCodePath, preorder, mergeAndDeduplicate, useWindowHeight } from './utils';
164
- import { getText } from '../../locale';
164
+ import { getText } from '../../I18N';
165
165
  var path = []; // 上级机构到当前机构的路径
166
166
 
167
167
  var AssignModal = function AssignModal(props) {
@@ -91,7 +91,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
91
91
  import { debounce } from 'lodash';
92
92
  import './index.less';
93
93
  import { findSameCodePath, preorder } from './utils';
94
- import { getText } from '../../locale';
94
+ import { getText } from '../../I18N';
95
95
  var path = []; // 上级机构到当前机构的路径
96
96
 
97
97
  var AssignModal = function AssignModal(props) {
@@ -42,6 +42,7 @@
42
42
  position: sticky;
43
43
  top: 0px;
44
44
  z-index: 1;
45
+ height: 28px;
45
46
  // background: #f8f9fb;
46
47
  }
47
48
 
@@ -1,11 +1,11 @@
1
1
  import _Drawer from 'tntd/es/drawer';
2
2
  var _excluded = [
3
+ 'lang',
3
4
  'visible',
4
5
  'close',
5
6
  'disabled',
6
7
  'title',
7
8
  'onSubmit',
8
- 'locale',
9
9
  'okText',
10
10
  'cancelText',
11
11
  ];
@@ -109,24 +109,35 @@ function _objectWithoutPropertiesLoose(r, e) {
109
109
  return t;
110
110
  }
111
111
  import React from 'react';
112
+ import mapLocale, { getLang } from '../I18N';
112
113
  import { useState } from 'react';
113
114
  import AssignApp from './AssignApp';
114
115
  import './index.less';
115
- import Cookies from 'universal-cookie';
116
- var cookies = new Cookies();
116
+ import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
117
117
  var AssignModal = function AssignModal(props) {
118
- var visible = props.visible,
118
+ var locale = props.locale;
119
+ var lang = props.lang,
120
+ visible = props.visible,
119
121
  close = props.close,
120
122
  _props$disabled = props.disabled,
121
123
  disabled = _props$disabled === void 0 ? false : _props$disabled,
122
124
  _props$title = props.title,
123
125
  title = _props$title === void 0 ? '' : _props$title,
124
126
  onSubmit = props.onSubmit,
125
- locale = props.locale,
126
127
  _props$okText = props.okText,
127
- okText = _props$okText === void 0 ? '确定' : _props$okText,
128
+ okText =
129
+ _props$okText === void 0
130
+ ? locale === null || locale === void 0
131
+ ? void 0
132
+ : locale.okText
133
+ : _props$okText,
128
134
  _props$cancelText = props.cancelText,
129
- cancelText = _props$cancelText === void 0 ? '取消' : _props$cancelText,
135
+ cancelText =
136
+ _props$cancelText === void 0
137
+ ? locale === null || locale === void 0
138
+ ? void 0
139
+ : locale.cancelText
140
+ : _props$cancelText,
130
141
  restProps = _objectWithoutProperties(props, _excluded);
131
142
  var _useState = useState({}),
132
143
  _useState2 = _slicedToArray(_useState, 2),
@@ -161,10 +172,7 @@ var AssignModal = function AssignModal(props) {
161
172
  setAssignData(data);
162
173
  },
163
174
  disabled: disabled,
164
- lang:
165
- (props === null || props === void 0 ? void 0 : props.lang) ||
166
- cookies.get('lang') ||
167
- 'cn',
175
+ lang: lang,
168
176
  locale: locale,
169
177
  },
170
178
  restProps,
@@ -172,4 +180,23 @@ var AssignModal = function AssignModal(props) {
172
180
  ),
173
181
  );
174
182
  };
175
- export default AssignModal;
183
+ export default (function (props) {
184
+ return /*#__PURE__*/ React.createElement(
185
+ LocaleReceiver,
186
+ {
187
+ componentName: 'AssignModal',
188
+ },
189
+ function (locale, localeCode) {
190
+ var I18N = !!Object.keys(locale).length
191
+ ? locale
192
+ : mapLocale[localeCode] || mapLocale[getLang()];
193
+ return /*#__PURE__*/ React.createElement(
194
+ AssignModal,
195
+ _extends({}, props, {
196
+ locale: I18N,
197
+ lang: localeCode || getLang(),
198
+ }),
199
+ );
200
+ },
201
+ );
202
+ });
@@ -18,50 +18,23 @@ function _typeof(o) {
18
18
  );
19
19
  }
20
20
  import Cookies from 'universal-cookie';
21
+ import zhCN from './.octopus/zh-CN';
22
+ import enUS from './.octopus/en-US';
23
+ import thTH from './.octopus/th-TH';
24
+ import arEG from './.octopus/ar-EG';
25
+ import koKR from './.octopus/ko-KR';
26
+ import esES from './.octopus/es-ES';
21
27
  var cookies = new Cookies();
22
- export var zh_CN = {
23
- authorizesOrgList: '机构列表',
24
- allOrgAvailable: '全部机构',
25
- authorizesAppList: '渠道列表',
26
- allAppAvailable: '全部渠道',
27
- authorizesUserList: '用户列表',
28
- allUserAvailable: '全部用户',
29
- search: '请输入机构名称',
30
- availableOrgs: '可用机构',
31
- availableApps: '可用渠道',
32
- availableUsers: '可用用户',
33
- clear: '清空',
34
- hasBeenSelected: '已选',
35
- numOfOrg: '%s 个机构',
36
- numOfApp: '%s 个渠道',
37
- numOfUser: '%s 个用户',
38
- enterAppName: '请输入渠道名称',
39
- enterUserName: '请输入用户名称',
40
- };
41
- export var en_US = {
42
- authorizesOrgList: 'Organization List',
43
- allOrgAvailable: 'All Organizations',
44
- authorizesAppList: 'Channel List',
45
- allAppAvailable: 'All Channels',
46
- authorizesUserList: 'Account List',
47
- allUserAvailable: 'All Accounts',
48
- search: 'Organization name',
49
- availableOrgs: 'Available Organizations',
50
- availableApps: 'Available Channels',
51
- availableUsers: 'Available Users',
52
- clear: 'Clear',
53
- hasBeenSelected: 'Selected',
54
- numOfOrg: '%s Organizations',
55
- numOfApp: '%s Channels',
56
- numOfUser: '%s Accounts',
57
- enterAppName: 'Enter Channel name',
58
- enterUserName: 'Enter Account name',
59
- };
60
-
61
- // 内置语言包
62
28
  var builtInLocales = {
63
- cn: zh_CN,
64
- en: en_US,
29
+ 'zh-cn': zhCN,
30
+ en: enUS,
31
+ th: thTH,
32
+ // 泰语
33
+ ar: arEG,
34
+ // 阿拉伯语(埃及)
35
+ ko: koKR,
36
+ // 韩语
37
+ es: esES, // 西班牙语
65
38
  };
66
39
 
67
40
  /**
@@ -91,7 +64,7 @@ export var getText = function getText(key, language, locale) {
91
64
  actualParams = locale !== undefined ? [locale].concat(params) : params;
92
65
  }
93
66
  var lang = language || getLanguage();
94
- var builtIn = builtInLocales[lang] || zh_CN;
67
+ var builtIn = builtInLocales[lang] || builtInLocales['zh-cn'];
95
68
 
96
69
  // locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
97
70
  var text =
@@ -112,14 +85,18 @@ export var getText = function getText(key, language, locale) {
112
85
  }
113
86
  return text;
114
87
  };
115
- export var getLanguage = function getLanguage() {
116
- return (
117
- cookies.get('lang', {
118
- path: '/',
119
- }) || 'cn'
120
- );
88
+ export var getLang = function getLang() {
89
+ var lang = cookies.get('lang');
90
+ return lang !== 'cn' ? lang : 'zh-cn';
121
91
  };
122
92
  export default {
123
- en_US: en_US,
124
- zh_CN: zh_CN,
93
+ 'zh-cn': zhCN,
94
+ en: enUS,
95
+ th: thTH,
96
+ // 泰语
97
+ ar: arEG,
98
+ // 阿拉伯语(埃及)
99
+ ko: koKR,
100
+ // 韩语
101
+ es: esES, // 西班牙语
125
102
  };
@@ -0,0 +1,4 @@
1
+ import arEG from '../.octopus/ar-EG';
2
+ export default {
3
+ AssignModal: arEG,
4
+ };
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tddc/assign-modal",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "assign-modal",
5
5
  "author": "zj <jun.zhang002383@tongdun.net>",
6
6
  "license": "ISC",
@@ -18,4 +18,4 @@
18
18
  "jsencrypt": "3.2.1"
19
19
  },
20
20
  "gitHead": "597697f3b6df285679feeabf56b25943a4ec89d4"
21
- }
21
+ }
@@ -0,0 +1,5 @@
1
+ import test from './test';
2
+
3
+ export default {
4
+ ...test,
5
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ a: 'a',
3
+ };
@@ -0,0 +1,19 @@
1
+ export default {
2
+ authorizesOrgList: 'Organization List',
3
+ allOrgAvailable: 'All Organizations',
4
+ authorizesAppList: 'Channel List',
5
+ allAppAvailable: 'All Channels',
6
+ authorizesUserList: 'Account List',
7
+ allUserAvailable: 'All Accounts',
8
+ search: 'Organization name',
9
+ availableOrgs: 'Available Organizations',
10
+ availableApps: 'Available Channels',
11
+ availableUsers: 'Available Users',
12
+ clear: 'Clear',
13
+ hasBeenSelected: 'Selected',
14
+ numOfOrg: '%s Organizations',
15
+ numOfApp: '%s Channels',
16
+ numOfUser: '%s Accounts',
17
+ enterAppName: 'Enter Channel name',
18
+ enterUserName: 'Enter Account name',
19
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ a: 'a',
3
+ };
@@ -0,0 +1,5 @@
1
+ import test from './test';
2
+
3
+ export default {
4
+ ...test,
5
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ a: 'a',
3
+ };
@@ -0,0 +1,5 @@
1
+ import test from './test';
2
+
3
+ export default {
4
+ ...test,
5
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ a: 'a',
3
+ };
@@ -0,0 +1,5 @@
1
+ import test from './test';
2
+
3
+ export default {
4
+ ...test,
5
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ a: 'a',
3
+ };
@@ -0,0 +1,19 @@
1
+ export default {
2
+ authorizesOrgList: '机构列表',
3
+ allOrgAvailable: '全部机构',
4
+ authorizesAppList: '渠道列表',
5
+ allAppAvailable: '全部渠道',
6
+ authorizesUserList: '用户列表',
7
+ allUserAvailable: '全部用户',
8
+ search: '请输入机构名称',
9
+ availableOrgs: '可用机构',
10
+ availableApps: '可用渠道',
11
+ availableUsers: '可用用户',
12
+ clear: '清空',
13
+ hasBeenSelected: '已选',
14
+ numOfOrg: '%s 个机构',
15
+ numOfApp: '%s 个渠道',
16
+ numOfUser: '%s 个用户',
17
+ enterAppName: '请输入渠道名称',
18
+ enterUserName: '请输入用户名称',
19
+ };
@@ -4,7 +4,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
4
4
  import { cloneDeep, debounce } from 'lodash';
5
5
  import './index.less';
6
6
  import { findSameCodePath, preorder, mergeAndDeduplicate, useWindowHeight } from './utils';
7
- import { getText } from '../../locale';
7
+ import { getText } from '../../I18N';
8
8
 
9
9
  let path = []; // 上级机构到当前机构的路径
10
10
 
@@ -4,7 +4,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
4
4
  import { debounce } from 'lodash';
5
5
  import './index.less';
6
6
  import { findSameCodePath, preorder } from './utils';
7
- import { getText } from '../../locale';
7
+ import { getText } from '../../I18N';
8
8
 
9
9
  let path = []; // 上级机构到当前机构的路径
10
10
 
@@ -42,6 +42,7 @@
42
42
  position: sticky;
43
43
  top: 0px;
44
44
  z-index: 1;
45
+ height: 28px;
45
46
  // background: #f8f9fb;
46
47
  }
47
48
 
@@ -1,21 +1,21 @@
1
+ import mapLocale, { getLang } from '../I18N';
1
2
  import { Drawer } from 'tntd';
2
3
  import { useState } from 'react';
3
-
4
4
  import AssignApp from './AssignApp';
5
5
  import './index.less';
6
- import Cookies from 'universal-cookie';
7
- const cookies = new Cookies();
6
+ import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
8
7
 
9
8
  const AssignModal = (props) => {
9
+ const { locale } = props;
10
10
  const {
11
+ lang,
11
12
  visible,
12
13
  close,
13
14
  disabled = false,
14
15
  title = '',
15
16
  onSubmit,
16
- locale,
17
- okText = '确定',
18
- cancelText = '取消',
17
+ okText = locale?.okText,
18
+ cancelText = locale?.cancelText,
19
19
  ...restProps
20
20
  } = props;
21
21
  const [assignData, setAssignData] = useState({});
@@ -44,7 +44,7 @@ const AssignModal = (props) => {
44
44
  setAssignData(data);
45
45
  }}
46
46
  disabled={disabled}
47
- lang={props?.lang || cookies.get('lang') || 'cn'}
47
+ lang={lang}
48
48
  locale={locale}
49
49
  {...restProps}
50
50
  />
@@ -52,4 +52,13 @@ const AssignModal = (props) => {
52
52
  );
53
53
  };
54
54
 
55
- export default AssignModal;
55
+ export default (props) => (
56
+ <LocaleReceiver componentName="AssignModal">
57
+ {(locale, localeCode) => {
58
+ const I18N = !!Object.keys(locale).length
59
+ ? locale
60
+ : mapLocale[localeCode] || mapLocale[getLang()];
61
+ return <AssignModal {...props} locale={I18N} lang={localeCode || getLang()} />;
62
+ }}
63
+ </LocaleReceiver>
64
+ );
package/src/I18N.js ADDED
@@ -0,0 +1,66 @@
1
+ import Cookies from 'universal-cookie';
2
+ import zhCN from './.octopus/zh-CN';
3
+ import enUS from './.octopus/en-US';
4
+ import thTH from './.octopus/th-TH';
5
+ import arEG from './.octopus/ar-EG';
6
+ import koKR from './.octopus/ko-KR';
7
+ import esES from './.octopus/es-ES';
8
+
9
+ const cookies = new Cookies();
10
+
11
+ const builtInLocales = {
12
+ 'zh-cn': zhCN,
13
+ en: enUS,
14
+ th: thTH, // 泰语
15
+ ar: arEG, // 阿拉伯语(埃及)
16
+ ko: koKR, // 韩语
17
+ es: esES, // 西班牙语
18
+ };
19
+
20
+ /**
21
+ * 获取文本,支持外部传入的语言包覆盖
22
+ * @param {string} key - 文本 key
23
+ * @param {string} language - 语言标识
24
+ * @param {Object} locale - 外部传入的语言包(可选),通过 createOtp 生成的扁平对象
25
+ * @param {...any} params - 替换参数
26
+ */
27
+ export const getText = (key, language, locale, ...params) => {
28
+ // 兼容旧的调用方式:getText(key, language, ...params)
29
+ // 新的调用方式:getText(key, language, locale, ...params)
30
+ let actualLocale = locale;
31
+ let actualParams = params;
32
+
33
+ // 如果 locale 不是对象或为 null,则认为是旧的调用方式
34
+ if (typeof locale !== 'object' || locale === null) {
35
+ actualLocale = null;
36
+ actualParams = locale !== undefined ? [locale, ...params] : params;
37
+ }
38
+
39
+ const lang = language || getLanguage();
40
+ const builtIn = builtInLocales[lang] || builtInLocales['zh-cn'];
41
+
42
+ // locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
43
+ const text = actualLocale?.[key] ?? builtIn[key];
44
+
45
+ if (actualParams?.length) {
46
+ return actualParams.reduce((acc, cur) => {
47
+ return acc?.replace(/%s/, cur);
48
+ }, text);
49
+ }
50
+
51
+ return text;
52
+ };
53
+
54
+ export const getLang = () => {
55
+ const lang = cookies.get('lang');
56
+ return lang !== 'cn' ? lang : 'zh-cn';
57
+ };
58
+
59
+ export default {
60
+ 'zh-cn': zhCN,
61
+ en: enUS,
62
+ th: thTH, // 泰语
63
+ ar: arEG, // 阿拉伯语(埃及)
64
+ ko: koKR, // 韩语
65
+ es: esES, // 西班牙语
66
+ };
@@ -0,0 +1,5 @@
1
+ import arEG from '../.octopus/ar-EG';
2
+
3
+ export default {
4
+ AssignModal: arEG,
5
+ };
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/locale.js DELETED
@@ -1,87 +0,0 @@
1
- import Cookies from 'universal-cookie';
2
-
3
- const cookies = new Cookies();
4
-
5
- export const zh_CN = {
6
- authorizesOrgList: '机构列表',
7
- allOrgAvailable: '全部机构',
8
- authorizesAppList: '渠道列表',
9
- allAppAvailable: '全部渠道',
10
- authorizesUserList: '用户列表',
11
- allUserAvailable: '全部用户',
12
- search: '请输入机构名称',
13
- availableOrgs: '可用机构',
14
- availableApps: '可用渠道',
15
- availableUsers: '可用用户',
16
- clear: '清空',
17
- hasBeenSelected: '已选',
18
- numOfOrg: '%s 个机构',
19
- numOfApp: '%s 个渠道',
20
- numOfUser: '%s 个用户',
21
- enterAppName: '请输入渠道名称',
22
- enterUserName: '请输入用户名称',
23
- };
24
-
25
- export const en_US = {
26
- authorizesOrgList: 'Organization List',
27
- allOrgAvailable: 'All Organizations',
28
- authorizesAppList: 'Channel List',
29
- allAppAvailable: 'All Channels',
30
- authorizesUserList: 'Account List',
31
- allUserAvailable: 'All Accounts',
32
- search: 'Organization name',
33
- availableOrgs: 'Available Organizations',
34
- availableApps: 'Available Channels',
35
- availableUsers: 'Available Users',
36
- clear: 'Clear',
37
- hasBeenSelected: 'Selected',
38
- numOfOrg: '%s Organizations',
39
- numOfApp: '%s Channels',
40
- numOfUser: '%s Accounts',
41
- enterAppName: 'Enter Channel name',
42
- enterUserName: 'Enter Account name',
43
- };
44
-
45
- // 内置语言包
46
- const builtInLocales = {
47
- cn: zh_CN,
48
- en: en_US,
49
- };
50
-
51
- /**
52
- * 获取文本,支持外部传入的语言包覆盖
53
- * @param {string} key - 文本 key
54
- * @param {string} language - 语言标识
55
- * @param {Object} locale - 外部传入的语言包(可选),通过 createOtp 生成的扁平对象
56
- * @param {...any} params - 替换参数
57
- */
58
- export const getText = (key, language, locale, ...params) => {
59
- // 兼容旧的调用方式:getText(key, language, ...params)
60
- // 新的调用方式:getText(key, language, locale, ...params)
61
- let actualLocale = locale;
62
- let actualParams = params;
63
-
64
- // 如果 locale 不是对象或为 null,则认为是旧的调用方式
65
- if (typeof locale !== 'object' || locale === null) {
66
- actualLocale = null;
67
- actualParams = locale !== undefined ? [locale, ...params] : params;
68
- }
69
-
70
- const lang = language || getLanguage();
71
- const builtIn = builtInLocales[lang] || zh_CN;
72
-
73
- // locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
74
- const text = actualLocale?.[key] ?? builtIn[key];
75
-
76
- if (actualParams?.length) {
77
- return actualParams.reduce((acc, cur) => {
78
- return acc?.replace(/%s/, cur);
79
- }, text);
80
- }
81
-
82
- return text;
83
- };
84
-
85
- export const getLanguage = () => cookies.get('lang', { path: '/' }) || 'cn';
86
-
87
- export default { en_US, zh_CN };