plain-design 1.0.0-beta.49 → 1.0.0-beta.50
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/plain-design.commonjs.min.js +3 -3
- package/dist/plain-design.min.js +3 -3
- package/dist/report.html +2 -2
- package/package.json +1 -1
- package/src/packages/components/$file/index.tsx +1 -1
- package/src/packages/components/$message/image.service.utils.tsx +2 -2
- package/src/packages/components/$object/createObjectService.tsx +3 -3
- package/src/packages/components/$upload/createUploadService.tsx +1 -1
- package/src/packages/components/Application/theme/theme.ts +1 -1
- package/src/packages/components/AutoTable/filter/useTableOption.filter.form.tsx +3 -3
- package/src/packages/components/AutoTable/filter/useTableOption.filter.search.tsx +2 -2
- package/src/packages/components/AutoTable/setting/useTableOption.setting.all.fitler.tsx +4 -4
- package/src/packages/components/AutoTable/setting/useTableOption.setting.cache.tsx +16 -16
- package/src/packages/components/AutoTable/setting/useTableOption.setting.config.tsx +11 -11
- package/src/packages/components/AutoTable/setting/useTableOption.setting.export.tsx +20 -20
- package/src/packages/components/AutoTable/setting/useTableOption.setting.import.tsx +1 -1
- package/src/packages/components/AutoTable/setting/useTableOption.setting.senior.filter.tsx +10 -10
- package/src/packages/components/AutoTable/setting/useTableOption.setting.senior.sort.tsx +7 -7
- package/src/packages/components/AutoTable/setting/useTableOption.setting.tsx +2 -2
- package/src/packages/components/AutoTable/use/useTableOption.buttons.tsx +18 -18
- package/src/packages/components/AutoTable/use/useTableOption.cache.ts +1 -1
- package/src/packages/components/AutoTable/use/useTableOption.check.tsx +1 -1
- package/src/packages/components/AutoTable/use/useTableOption.column.popper.tsx +8 -8
- package/src/packages/components/AutoTable/use/useTableOption.confirm.tsx +3 -3
- package/src/packages/components/AutoTable/use/useTableOption.loading.tsx +1 -1
- package/src/packages/components/AutoTable/use/useTableOption.methods.tsx +17 -17
- package/src/packages/components/AutoTable/use/useTableOption.pagination.tsx +3 -3
- package/src/packages/components/AutoTable/use/useTableOption.sort.ts +5 -5
- package/src/packages/components/AutoTable/use/useTableOption.tips.tsx +1 -1
- package/src/packages/components/Cascade/createMultipleCascadeRender.tsx +1 -1
- package/src/packages/components/Cascade/createSingleCascadeRender.tsx +1 -1
- package/src/packages/components/CascadePanel/flat/createCascadeFlatRender.tsx +1 -1
- package/src/packages/components/Checkbox/index.tsx +1 -1
- package/src/packages/components/CheckboxGroup/index.tsx +2 -2
- package/src/packages/components/DatePicker/date.utils.tsx +2 -2
- package/src/packages/components/DatePicker/panel/DatePanelDate.tsx +7 -7
- package/src/packages/components/DatePicker/panel/DatePanelMonth.tsx +12 -12
- package/src/packages/components/Dialog/index.tsx +3 -3
- package/src/packages/components/Empty/index.tsx +1 -1
- package/src/packages/components/FilterFormMultiple/index.tsx +2 -2
- package/src/packages/components/FilterFormSingle/index.tsx +2 -2
- package/src/packages/components/FilterService/filter/filter.city.tsx +4 -4
- package/src/packages/components/FilterService/filter/filter.date.tsx +4 -4
- package/src/packages/components/FilterService/filter/filter.datetime.tsx +2 -2
- package/src/packages/components/FilterService/filter/filter.district.tsx +4 -4
- package/src/packages/components/FilterService/filter/filter.number.tsx +1 -1
- package/src/packages/components/FilterService/filter/filter.province.tsx +4 -4
- package/src/packages/components/FilterService/filter/filter.select.tsx +3 -3
- package/src/packages/components/FilterService/filter/filter.text.tsx +4 -4
- package/src/packages/components/FilterService/filter/fitler.object.tsx +4 -4
- package/src/packages/components/FilterService/index.tsx +7 -7
- package/src/packages/components/Form/types/any.tsx +6 -6
- package/src/packages/components/Form/types/array.tsx +7 -7
- package/src/packages/components/Form/types/date.tsx +6 -6
- package/src/packages/components/Form/types/email.tsx +1 -1
- package/src/packages/components/Form/types/idcard.tsx +1 -1
- package/src/packages/components/Form/types/number.tsx +7 -7
- package/src/packages/components/Form/types/phone.tsx +1 -1
- package/src/packages/components/Form/types/qq.tsx +1 -1
- package/src/packages/components/Form/types/string.tsx +7 -7
- package/src/packages/components/Formatter/index.tsx +1 -1
- package/src/packages/components/Image/index.tsx +3 -3
- package/src/packages/components/ImageUploader/index.tsx +2 -2
- package/src/packages/components/Object/createObjectRender.multiple.tsx +1 -1
- package/src/packages/components/Object/createObjectRender.single.tsx +1 -1
- package/src/packages/components/PageThemeUtils/deepmerge.ts +21 -0
- package/src/packages/components/PageThemeUtils/index.tsx +108 -53
- package/src/packages/components/Pagination/index.tsx +4 -4
- package/src/packages/components/Select/SelectPanel.tsx +1 -1
- package/src/packages/components/Select/createMultipleSelectRender.tsx +4 -4
- package/src/packages/components/Table/editor/PlcAddress.tsx +4 -4
- package/src/packages/components/Table/standard/PlcCheck/PlcCheck.multiple.tsx +4 -4
- package/src/packages/components/Table/standard/PlcExpand.tsx +2 -2
- package/src/packages/components/Table/standard/PlcIndex.tsx +1 -1
- package/src/packages/components/Table/standard/PlcOperation/OuterOperation.tsx +1 -1
- package/src/packages/components/Table/standard/PlcOperation/PlcOperation.tsx +4 -4
- package/src/packages/components/Table/standard/PlcTree/PlcTree.renderNode.tsx +4 -4
- package/src/packages/components/Table/table/use/useTableFormEditor.tsx +2 -2
- package/src/packages/components/Table/table/use/useTableModifyEditor.tsx +6 -6
- package/src/packages/components/ThemeEditor/index.tsx +32 -27
- package/src/packages/components/Tree/RenderTreeNode.tsx +1 -1
- package/src/packages/components/Upload/index.tsx +12 -12
- package/src/packages/components/VirtualTable/index.tsx +1 -1
- package/src/packages/components/useDialog/DialogService.tsx +2 -2
- package/src/packages/components/useImage/ImageService.tsx +8 -8
- package/src/packages/components/useNotice/index.tsx +1 -1
- package/src/packages/i18n/i18n.utils.ts +172 -120
- package/src/packages/i18n/index.ts +4 -3
- package/src/packages/i18n/lang/en-us.ts +4 -3
- package/src/packages/i18n/lang/zh-cn.ts +1 -0
@@ -1,164 +1,216 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import {createSyncHooks, reactive} from "plain-design-composition";
|
2
|
+
import {ZhCnLocale} from './lang/zh-cn';
|
3
|
+
import {deepmerge} from "../components/PageThemeUtils/deepmerge";
|
3
4
|
|
4
5
|
/**
|
5
|
-
|
6
|
-
*
|
7
|
-
* base:{
|
8
|
-
* confirm:'确定',
|
9
|
-
* cancel:'取消',
|
10
|
-
* },
|
11
|
-
* date:{
|
12
|
-
* year:'年',
|
13
|
-
* month:'月',
|
14
|
-
* date:'日',
|
15
|
-
* },
|
16
|
-
* }
|
17
|
-
* 得到的联合类型是:'base.confirm'|'base.cancel'|'date.year'|'date.month'|'date.date'
|
6
|
+
/**
|
7
|
+
* 默认语言为中文
|
18
8
|
* @author 韦胜健
|
19
|
-
* @date
|
9
|
+
* @date 2023/10/12 15:14
|
20
10
|
*/
|
21
|
-
|
22
|
-
K extends keyof T ? (
|
23
|
-
K extends string ? (
|
24
|
-
T[K] extends Record<string, any> ? ObjectAccessPaths<T[K], `${Prev}.${K}`> : (
|
25
|
-
`${Prev}.${K}` extends `.${infer L}` ? L : `${Prev}.${K}`
|
26
|
-
)
|
27
|
-
) : never
|
28
|
-
) :
|
29
|
-
never;
|
30
|
-
// type A = ObjectAccessPaths<tZhCnLocale>
|
11
|
+
const DEFAULT_LANG = 'zh-cn';
|
31
12
|
|
32
13
|
/**
|
33
|
-
*
|
34
|
-
* base.select.reverse => ['base','select','reverse']
|
14
|
+
* 组件内置中文以及英文
|
35
15
|
* @author 韦胜健
|
36
|
-
* @date
|
16
|
+
* @date 2023/10/12 15:14
|
37
17
|
*/
|
38
|
-
|
39
|
-
|
18
|
+
const LANGS = {
|
19
|
+
[DEFAULT_LANG]: ZhCnLocale,
|
20
|
+
};
|
40
21
|
|
41
22
|
/**
|
42
|
-
*
|
43
|
-
* AccessObjectValue<A,['base','confirm']> 得到的类型是 `确定`
|
23
|
+
* 根据中文解析出来允许访问的编码类型
|
44
24
|
* @author 韦胜健
|
45
|
-
* @date
|
25
|
+
* @date 2023/10/12 15:14
|
46
26
|
*/
|
47
|
-
type
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
type iFormat<
|
28
|
+
T extends Record<string, any>,
|
29
|
+
PREV extends string = '',
|
30
|
+
K = keyof T
|
31
|
+
> = K extends keyof T
|
32
|
+
? T[K] extends Record<any, any>
|
33
|
+
? iFormat<T[K], K extends string ? (PREV extends '' ? K : `${PREV}.${K}`) : ''>
|
34
|
+
: [PREV] extends ['']
|
35
|
+
? K
|
36
|
+
: K extends string
|
37
|
+
? `${PREV}.${K}`
|
38
|
+
: never
|
39
|
+
: never;
|
51
40
|
|
52
41
|
/**
|
53
|
-
*
|
54
|
-
* {
|
55
|
-
* "base.confirm":"确定",
|
56
|
-
* "base.cancel":"取消",
|
57
|
-
* "base.year":"年",
|
58
|
-
* "base.month":"月",
|
59
|
-
* "base.date":"日",
|
60
|
-
* }
|
42
|
+
* 允许访问的编码类型
|
61
43
|
* @author 韦胜健
|
62
|
-
* @date
|
44
|
+
* @date 2023/10/12 15:14
|
63
45
|
*/
|
64
|
-
type
|
65
|
-
// type O = ObjectMap<tZhCnLocale>
|
66
|
-
|
67
|
-
/**
|
68
|
-
* 联合类型转换为交叉类型(函数重载类型就是交叉类型)
|
69
|
-
* @author 韦胜健
|
70
|
-
* @date 2022.5.2 11:50
|
71
|
-
*/
|
72
|
-
type UnionToIntersection<T> = (T extends any ? ((t: T) => void) : never) extends ((r: infer R) => any) ? R : never
|
73
|
-
|
74
|
-
/**
|
75
|
-
* 创建i18n对象
|
76
|
-
* @author 韦胜健
|
77
|
-
* @date 2022.5.2 10:34
|
78
|
-
*/
|
79
|
-
export function createI18n<Locale extends Record<string, any>, OM = ObjectMap<Locale>, K extends keyof OM = keyof OM>(defaultLocale: Locale): UnionToIntersection<K extends keyof OM ? ((k: K, params?: Record<string, any>) => { d: <D = unknown>(defaultLang?: D) => OM[K] | D }) : never> & {
|
80
|
-
setLocale: (locale: any) => void,
|
81
|
-
setDefaultLocale: (defaultLocale: any) => void,
|
82
|
-
getLocale: () => Locale,
|
83
|
-
getDefaultLocale: () => Locale,
|
84
|
-
} {
|
46
|
+
type iStandardLangPath = iFormat<typeof ZhCnLocale>;
|
85
47
|
|
48
|
+
export const i18n = (() => {
|
86
49
|
const state = reactive({
|
87
|
-
|
88
|
-
|
89
|
-
/*从当前语言中取不到值得时候,从这个默认语言中取值*/
|
90
|
-
defaultLocale,
|
50
|
+
currentLang: DEFAULT_LANG,
|
51
|
+
langs: LANGS as any
|
91
52
|
});
|
92
53
|
|
54
|
+
const hooks = {
|
55
|
+
onChangeLang: createSyncHooks<() => void>(),
|
56
|
+
onUpdateLangs: createSyncHooks<() => void>()
|
57
|
+
};
|
58
|
+
|
93
59
|
/**
|
94
|
-
*
|
60
|
+
* 使用指定的语言转化编码
|
95
61
|
* @author 韦胜健
|
96
|
-
* @date
|
62
|
+
* @date 2023/10/11 9:28
|
63
|
+
* @param lang 指定的域名名字
|
64
|
+
* @param path 要转换的编码
|
65
|
+
* @param options 转换编码时的格式化参数
|
97
66
|
*/
|
98
|
-
const
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
67
|
+
const intlWithLang = (lang: string, path: string, options: any): string | undefined => {
|
68
|
+
if (!state.langs[lang]) {
|
69
|
+
console.log({ langs: state.langs, lang });
|
70
|
+
throw new Error(`不存在多语言:${lang}`);
|
71
|
+
}
|
72
|
+
const array = path.split('.');
|
73
|
+
let current = state.langs[lang];
|
74
|
+
for (let i = 0, j = array.length; i < j; i++) {
|
75
|
+
const property = array[i];
|
76
|
+
let value = current[property];
|
77
|
+
if (i === j - 1) return !options ? value : formatLang(value, options);
|
78
|
+
if (!value) return '';
|
79
|
+
current = value;
|
80
|
+
}
|
81
|
+
return '';
|
106
82
|
};
|
107
83
|
|
108
|
-
const map = computed(() => ({
|
109
|
-
locale: getMapObject(state.locale),
|
110
|
-
defaultLocale: getMapObject(state.defaultLocale)
|
111
|
-
}));
|
112
|
-
|
113
84
|
/**
|
114
|
-
*
|
85
|
+
* 使用当前语言转换编码
|
115
86
|
* @author 韦胜健
|
116
|
-
* @date
|
87
|
+
* @date 2023/10/11 9:29
|
117
88
|
*/
|
118
|
-
const
|
89
|
+
const $t = (path: string, options?: Record<string, any>) => {
|
90
|
+
let { currentLang } = state;
|
91
|
+
if (!state.langs[currentLang]) {
|
92
|
+
currentLang = DEFAULT_LANG;
|
93
|
+
}
|
94
|
+
const isDefaultLang = currentLang === DEFAULT_LANG;
|
95
|
+
|
96
|
+
let valString = intlWithLang(currentLang, path, options);
|
97
|
+
|
98
|
+
if (!valString) {
|
99
|
+
if (!isDefaultLang) {
|
100
|
+
valString = intlWithLang(DEFAULT_LANG, path, options);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
return valString;
|
105
|
+
};
|
106
|
+
|
119
107
|
/**
|
120
|
-
*
|
108
|
+
* 类似于$t, 可以指定默认展示文本,当多语言配置即使默认语言也没有办法转化这个编码时
|
121
109
|
* @author 韦胜健
|
122
|
-
* @date
|
110
|
+
* @date 2023/10/12 15:12
|
123
111
|
*/
|
124
|
-
const
|
112
|
+
const $intl = (path: string, options?: Record<string, any>) => {
|
113
|
+
return {
|
114
|
+
d: (desc: string) => {
|
115
|
+
const valString = $t(path, options);
|
116
|
+
if (!!valString) {
|
117
|
+
return valString;
|
118
|
+
}
|
119
|
+
return desc;
|
120
|
+
}
|
121
|
+
};
|
122
|
+
};
|
123
|
+
|
124
|
+
const $it = (path: iStandardLangPath, options?: Record<string, any>) => {
|
125
|
+
return $intl(path, options);
|
126
|
+
};
|
125
127
|
|
126
128
|
/**
|
127
|
-
*
|
129
|
+
* 应用指定语言
|
128
130
|
* @author 韦胜健
|
129
|
-
* @date
|
131
|
+
* @date 2023/10/11 9:29
|
130
132
|
*/
|
131
|
-
const
|
132
|
-
|
133
|
+
const use = (lang: string, locale: any) => {
|
134
|
+
state.currentLang = lang;
|
135
|
+
state.langs[lang] = locale;
|
136
|
+
hooks.onChangeLang.exec(undefined);
|
137
|
+
};
|
133
138
|
/**
|
134
|
-
*
|
139
|
+
* 切换至指定语言
|
135
140
|
* @author 韦胜健
|
136
|
-
* @date
|
141
|
+
* @date 2023/10/11 9:30
|
137
142
|
*/
|
138
|
-
const
|
139
|
-
|
143
|
+
const switchTo = async (lang: string, loadMethod?: () => any) => {
|
144
|
+
let locale = !loadMethod ? state.langs[lang] : await loadMethod();
|
145
|
+
use(lang, locale);
|
146
|
+
};
|
147
|
+
/**
|
148
|
+
* 获取当前使用的语言
|
149
|
+
* @author 韦胜健
|
150
|
+
* @date 2023/10/11 9:30
|
151
|
+
*/
|
152
|
+
const getCurrentLanguage = () => {
|
153
|
+
return state.currentLang;
|
154
|
+
};
|
140
155
|
/**
|
141
|
-
*
|
156
|
+
* 设置语言
|
142
157
|
* @author 韦胜健
|
143
|
-
* @date
|
158
|
+
* @date 2023/10/11 9:30
|
144
159
|
*/
|
145
|
-
const
|
146
|
-
|
147
|
-
|
148
|
-
|
160
|
+
const setLangs = (langs: any) => {
|
161
|
+
state.langs = deepmerge(state.langs, langs);
|
162
|
+
hooks.onUpdateLangs.exec(undefined);
|
163
|
+
};
|
164
|
+
|
165
|
+
return {
|
166
|
+
$t,
|
167
|
+
$intl,
|
168
|
+
$it,
|
169
|
+
use,
|
170
|
+
switchTo,
|
171
|
+
getCurrentLanguage,
|
172
|
+
setLangs,
|
173
|
+
DEFAULT_LANG,
|
174
|
+
state,
|
175
|
+
hooks,
|
176
|
+
};
|
177
|
+
})();
|
178
|
+
|
179
|
+
const formatLang = (() => {
|
180
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
181
|
+
|
182
|
+
function hasOwn(obj: any, key: string) {
|
183
|
+
return hasOwnProperty.call(obj, key);
|
184
|
+
}
|
185
|
+
|
186
|
+
const RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
|
187
|
+
|
188
|
+
const format = (string: string | null | undefined, ...args: any) => {
|
189
|
+
if (string == null || string.length === 0) {
|
190
|
+
return null;
|
149
191
|
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
192
|
+
if (args.length === 1 && typeof args[0] === 'object') {
|
193
|
+
args = args[0];
|
194
|
+
}
|
195
|
+
|
196
|
+
if (!args || !args.hasOwnProperty) {
|
197
|
+
args = {};
|
198
|
+
}
|
199
|
+
|
200
|
+
return string.replace(RE_NARGS, (match, prefix, i, index) => {
|
201
|
+
let result;
|
202
|
+
|
203
|
+
if (string[index - 1] === '{' && string[index + match.length] === '}') {
|
204
|
+
return i;
|
205
|
+
} else {
|
206
|
+
result = hasOwn(args, i) ? args[i] : null;
|
207
|
+
if (result === null || result === undefined) {
|
208
|
+
return '';
|
157
209
|
}
|
158
|
-
return defaultString || '';
|
159
|
-
},
|
160
|
-
};
|
161
|
-
};
|
162
210
|
|
163
|
-
|
164
|
-
}
|
211
|
+
return result;
|
212
|
+
}
|
213
|
+
});
|
214
|
+
};
|
215
|
+
return format;
|
216
|
+
})();
|
@@ -190,10 +190,11 @@ export const EnUsLocale: tZhCnLocale = {
|
|
190
190
|
alignLeft: 'left',
|
191
191
|
alignCenter: 'center',
|
192
192
|
alignRight: 'right',
|
193
|
-
exportCurrentPageData: '
|
194
|
-
exportDataInTable: '
|
193
|
+
exportCurrentPageData: 'Export current page data',
|
194
|
+
exportDataInTable: 'Export data showed in table',
|
195
|
+
exportCurrentAllData: 'Export current all data',
|
195
196
|
exportAllDataWithFilterSortMaybeFailedWithLargeData: 'export all data by sort and filter condition(maybe failed with latge data)',
|
196
|
-
selectDataToExport: '
|
197
|
+
selectDataToExport: 'Select data to export',
|
197
198
|
customSelectDataToExport: 'custom select data to export',
|
198
199
|
selectExportType: 'select export type',
|
199
200
|
selectExportFields: 'select export fields',
|
@@ -190,6 +190,7 @@ export const ZhCnLocale = {
|
|
190
190
|
alignRight: '右对齐',
|
191
191
|
exportCurrentPageData: '导出当前页数据',
|
192
192
|
exportDataInTable: '导出表格当前显示的数据',
|
193
|
+
exportCurrentAllData: '导出当前所有数据',
|
193
194
|
exportAllDataWithFilterSortMaybeFailedWithLargeData: '根据当前的筛选排序条件导出所有数据(数据量比较大的话可能会导出失败)',
|
194
195
|
selectDataToExport: '选择需要导出的数据',
|
195
196
|
customSelectDataToExport: '自定义选择导出需要的数据',
|