@faasjs/ant-design 0.0.3-development → 0.0.4-beta.10
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/LICENSE +6 -6
- package/README.md +954 -5
- package/dist/index.d.mts +545 -0
- package/dist/index.d.ts +545 -0
- package/dist/index.js +1626 -0
- package/dist/index.mjs +1582 -0
- package/package.json +31 -60
- package/lib/components/Button.d.ts +0 -60
- package/lib/components/Button.stories.d.ts +0 -36
- package/lib/components/Description.d.ts +0 -11
- package/lib/components/Description.stories.d.ts +0 -6
- package/lib/components/Form.d.ts +0 -7
- package/lib/components/Form.stories.d.ts +0 -7
- package/lib/components/FormItem.d.ts +0 -7
- package/lib/components/FormItem.stories.d.ts +0 -11
- package/lib/components/Header.d.ts +0 -19
- package/lib/components/Header.stories.d.ts +0 -24
- package/lib/components/Page.d.ts +0 -22
- package/lib/components/Page.stories.d.ts +0 -24
- package/lib/components/Table.d.ts +0 -8
- package/lib/components/Table.stories.d.ts +0 -6
- package/lib/components/__tests__/Form.test.d.ts +0 -1
- package/lib/components/__tests__/FormItem.test.d.ts +0 -1
- package/lib/components/data.d.ts +0 -17
- package/lib/index.d.ts +0 -2
- package/lib/index.esm.js +0 -57
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js +0 -62
- package/lib/index.js.map +0 -1
- package/lib/jest.setup.d.ts +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1582 @@
|
|
|
1
|
+
import { FaasDataWrapper as FaasDataWrapper$1, ErrorBoundary as ErrorBoundary$1, faas } from '@faasjs/react';
|
|
2
|
+
export { faas, useFaas } from '@faasjs/react';
|
|
3
|
+
import { Form as Form$1, Modal, Drawer, message, notification, ConfigProvider, Typography, Spin, Descriptions, Input, Button, Row, Col, TimePicker, DatePicker, Switch, Select, InputNumber, Radio, Result, Skeleton, Table as Table$1, Tabs as Tabs$1, Space, Alert } from 'antd';
|
|
4
|
+
export { Drawer, Modal } from 'antd';
|
|
5
|
+
import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs';
|
|
6
|
+
import { createContext, useState, useMemo, useContext, useEffect, cloneElement, useCallback, isValidElement, Suspense } from 'react';
|
|
7
|
+
export { lazy } from 'react';
|
|
8
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
|
+
import { BrowserRouter, useNavigate, Link as Link$1, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
|
|
10
|
+
import { defaultsDeep, isNil, upperFirst, isFunction, uniqBy } from 'lodash-es';
|
|
11
|
+
import dayjs2 from 'dayjs';
|
|
12
|
+
import { PlusOutlined, MinusCircleOutlined, CheckOutlined, CloseOutlined } from '@ant-design/icons';
|
|
13
|
+
|
|
14
|
+
// src/index.ts
|
|
15
|
+
function useModal(init) {
|
|
16
|
+
const [props, setProps] = useState({
|
|
17
|
+
open: false,
|
|
18
|
+
onCancel: () => setProps((prev) => ({
|
|
19
|
+
...prev,
|
|
20
|
+
open: false
|
|
21
|
+
})),
|
|
22
|
+
...init
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
modal: /* @__PURE__ */ jsx(Modal, { ...props }),
|
|
26
|
+
modalProps: props,
|
|
27
|
+
setModalProps(changes) {
|
|
28
|
+
setProps((prev) => ({
|
|
29
|
+
...prev,
|
|
30
|
+
...changes
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useDrawer(init) {
|
|
36
|
+
const [props, setProps] = useState({
|
|
37
|
+
open: false,
|
|
38
|
+
onClose: () => setProps((prev) => ({
|
|
39
|
+
...prev,
|
|
40
|
+
open: false
|
|
41
|
+
})),
|
|
42
|
+
...init
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
drawer: /* @__PURE__ */ jsx(Drawer, { ...props }),
|
|
46
|
+
drawerProps: props,
|
|
47
|
+
setDrawerProps(changes) {
|
|
48
|
+
setProps((prev) => ({
|
|
49
|
+
...prev,
|
|
50
|
+
...changes
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var AppContext = createContext({
|
|
56
|
+
message: {},
|
|
57
|
+
notification: {},
|
|
58
|
+
setModalProps: () => void 0,
|
|
59
|
+
setDrawerProps: () => void 0
|
|
60
|
+
});
|
|
61
|
+
function RoutesApp(props) {
|
|
62
|
+
const location = useLocation();
|
|
63
|
+
const { setDrawerProps, setModalProps } = useApp();
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
console.debug("location", location);
|
|
66
|
+
setDrawerProps({ open: false });
|
|
67
|
+
setModalProps({ open: false });
|
|
68
|
+
}, [location]);
|
|
69
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
70
|
+
}
|
|
71
|
+
function App(props) {
|
|
72
|
+
const [messageApi, messageContextHolder] = message.useMessage();
|
|
73
|
+
const [notificationApi, notificationContextHolder] = notification.useNotification();
|
|
74
|
+
const { modal, setModalProps } = useModal();
|
|
75
|
+
const { drawer, setDrawerProps } = useDrawer();
|
|
76
|
+
const memoizedContextValue = useMemo(
|
|
77
|
+
() => ({
|
|
78
|
+
message: messageApi,
|
|
79
|
+
notification: notificationApi,
|
|
80
|
+
setModalProps,
|
|
81
|
+
setDrawerProps
|
|
82
|
+
}),
|
|
83
|
+
[messageApi, notificationApi, setModalProps, setDrawerProps]
|
|
84
|
+
);
|
|
85
|
+
return /* @__PURE__ */ jsx(
|
|
86
|
+
StyleProvider,
|
|
87
|
+
{
|
|
88
|
+
...Object.assign(props.styleProviderProps || {}, {
|
|
89
|
+
hashPriority: "high",
|
|
90
|
+
transformers: [legacyLogicalPropertiesTransformer]
|
|
91
|
+
}),
|
|
92
|
+
children: /* @__PURE__ */ jsx(ConfigProvider, { ...props.configProviderProps, children: /* @__PURE__ */ jsx(AppContext.Provider, { value: memoizedContextValue, children: /* @__PURE__ */ jsxs(BrowserRouter, { ...props.browserRouterProps, children: [
|
|
93
|
+
messageContextHolder,
|
|
94
|
+
notificationContextHolder,
|
|
95
|
+
modal,
|
|
96
|
+
drawer,
|
|
97
|
+
/* @__PURE__ */ jsx(RoutesApp, { children: props.children })
|
|
98
|
+
] }) }) })
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function useApp() {
|
|
103
|
+
return useContext(AppContext);
|
|
104
|
+
}
|
|
105
|
+
App.useApp = useApp;
|
|
106
|
+
var isZH = /^zh/i.test(navigator.language);
|
|
107
|
+
var zh = {
|
|
108
|
+
lang: "zh",
|
|
109
|
+
blank: "\u7A7A",
|
|
110
|
+
all: "\u5168\u90E8",
|
|
111
|
+
submit: "\u63D0\u4EA4",
|
|
112
|
+
pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
|
|
113
|
+
add: "\u6DFB\u52A0",
|
|
114
|
+
delete: "\u5220\u9664",
|
|
115
|
+
required: "\u5FC5\u586B",
|
|
116
|
+
search: "\u641C\u7D22",
|
|
117
|
+
reset: "\u91CD\u7F6E"
|
|
118
|
+
};
|
|
119
|
+
var en = {
|
|
120
|
+
lang: "en",
|
|
121
|
+
blank: "Empty",
|
|
122
|
+
all: "All",
|
|
123
|
+
submit: "Submit",
|
|
124
|
+
pageNotFound: "Page Not Found",
|
|
125
|
+
add: "Add",
|
|
126
|
+
delete: "Delete",
|
|
127
|
+
required: "is required",
|
|
128
|
+
search: "Search",
|
|
129
|
+
reset: "Reset"
|
|
130
|
+
};
|
|
131
|
+
var common = isZH ? zh : en;
|
|
132
|
+
var baseConfig = {
|
|
133
|
+
antd: {},
|
|
134
|
+
lang: "en",
|
|
135
|
+
common,
|
|
136
|
+
Blank: { text: common.blank },
|
|
137
|
+
Form: { submit: { text: common.submit } },
|
|
138
|
+
Title: {
|
|
139
|
+
separator: " - ",
|
|
140
|
+
suffix: ""
|
|
141
|
+
},
|
|
142
|
+
Link: { style: {} }
|
|
143
|
+
};
|
|
144
|
+
var ConfigContext = createContext(baseConfig);
|
|
145
|
+
function ConfigProvider2({
|
|
146
|
+
config,
|
|
147
|
+
children
|
|
148
|
+
}) {
|
|
149
|
+
const [values, setValues] = useState(baseConfig);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (config.lang === "zh") {
|
|
152
|
+
setValues(
|
|
153
|
+
defaultsDeep(
|
|
154
|
+
config,
|
|
155
|
+
{
|
|
156
|
+
lang: "zh",
|
|
157
|
+
common: zh,
|
|
158
|
+
Blank: { text: zh.blank },
|
|
159
|
+
Form: { submit: { text: zh.submit } }
|
|
160
|
+
},
|
|
161
|
+
baseConfig
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
} else
|
|
165
|
+
setValues(defaultsDeep(config, values));
|
|
166
|
+
}, []);
|
|
167
|
+
return /* @__PURE__ */ jsx(ConfigContext.Provider, { value: values, children });
|
|
168
|
+
}
|
|
169
|
+
function useConfigContext() {
|
|
170
|
+
return useContext(ConfigContext);
|
|
171
|
+
}
|
|
172
|
+
function Blank(options) {
|
|
173
|
+
const { Blank: Blank2 } = useConfigContext();
|
|
174
|
+
return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ jsx(Typography.Text, { disabled: true, children: (options == null ? void 0 : options.text) || Blank2.text }) : options.value;
|
|
175
|
+
}
|
|
176
|
+
function transferOptions(options) {
|
|
177
|
+
if (!options)
|
|
178
|
+
return [];
|
|
179
|
+
return options.map(
|
|
180
|
+
(item) => typeof item === "object" ? item : {
|
|
181
|
+
label: upperFirst(item.toString()),
|
|
182
|
+
value: item
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
function transferValue(type, value) {
|
|
187
|
+
if (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined")
|
|
188
|
+
return null;
|
|
189
|
+
if (!type)
|
|
190
|
+
type = "string";
|
|
191
|
+
if (type.endsWith("[]") && typeof value === "string")
|
|
192
|
+
value = value.split(",").filter(Boolean);
|
|
193
|
+
if (["date", "time"].includes(type)) {
|
|
194
|
+
if (typeof value === "number" && value.toString().length === 10)
|
|
195
|
+
value = value * 1e3;
|
|
196
|
+
if (!dayjs2.isDayjs(value))
|
|
197
|
+
value = dayjs2(value);
|
|
198
|
+
}
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
function Loading(props) {
|
|
202
|
+
if (props.loading === false)
|
|
203
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
204
|
+
return /* @__PURE__ */ jsx(
|
|
205
|
+
"div",
|
|
206
|
+
{
|
|
207
|
+
style: {
|
|
208
|
+
...props.style || {},
|
|
209
|
+
...!props.size || props.size === "large" ? {
|
|
210
|
+
margin: "20vh auto",
|
|
211
|
+
textAlign: "center"
|
|
212
|
+
} : {}
|
|
213
|
+
},
|
|
214
|
+
children: /* @__PURE__ */ jsx(Spin, { size: props.size || "large" })
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
function FaasDataWrapper(props) {
|
|
219
|
+
return /* @__PURE__ */ jsx(
|
|
220
|
+
FaasDataWrapper$1,
|
|
221
|
+
{
|
|
222
|
+
fallback: props.loading || /* @__PURE__ */ jsx(Loading, { ...props.loadingProps }),
|
|
223
|
+
...props
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
function DescriptionItemContent(props) {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
const [computedProps, setComputedProps] = useState();
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
var _a2, _b2;
|
|
232
|
+
const propsCopy = { ...props };
|
|
233
|
+
if (!propsCopy.item.title)
|
|
234
|
+
propsCopy.item.title = upperFirst(propsCopy.item.id);
|
|
235
|
+
if (!propsCopy.item.type)
|
|
236
|
+
propsCopy.item.type = "string";
|
|
237
|
+
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
238
|
+
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
239
|
+
}
|
|
240
|
+
propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
|
|
241
|
+
if (propsCopy.item.options && propsCopy.value !== null) {
|
|
242
|
+
if (propsCopy.item.type.endsWith("[]"))
|
|
243
|
+
propsCopy.value = propsCopy.value.map(
|
|
244
|
+
(v) => {
|
|
245
|
+
var _a3;
|
|
246
|
+
return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
else if (["string", "number", "boolean"].includes(propsCopy.item.type))
|
|
250
|
+
propsCopy.value = ((_b2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b2.label) || props.value;
|
|
251
|
+
}
|
|
252
|
+
setComputedProps(propsCopy);
|
|
253
|
+
}, [props]);
|
|
254
|
+
if (!computedProps)
|
|
255
|
+
return null;
|
|
256
|
+
if ((_a = computedProps.extendTypes) == null ? void 0 : _a[computedProps.item.type])
|
|
257
|
+
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
258
|
+
return cloneElement(
|
|
259
|
+
computedProps.extendTypes[computedProps.item.type].children,
|
|
260
|
+
{
|
|
261
|
+
scene: "description",
|
|
262
|
+
value: computedProps.value,
|
|
263
|
+
values: computedProps.values
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
else if (computedProps.extendTypes[computedProps.item.type].render)
|
|
267
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.extendTypes[computedProps.item.type].render(
|
|
268
|
+
computedProps.value,
|
|
269
|
+
computedProps.values,
|
|
270
|
+
0,
|
|
271
|
+
"description"
|
|
272
|
+
) });
|
|
273
|
+
else
|
|
274
|
+
throw Error(`${computedProps.item.type} requires children or render`);
|
|
275
|
+
if (computedProps.item.descriptionChildren === null)
|
|
276
|
+
return null;
|
|
277
|
+
if (computedProps.item.descriptionChildren)
|
|
278
|
+
return cloneElement(computedProps.item.descriptionChildren, {
|
|
279
|
+
scene: "description",
|
|
280
|
+
value: computedProps.value,
|
|
281
|
+
values: computedProps.values
|
|
282
|
+
});
|
|
283
|
+
if (computedProps.item.children === null)
|
|
284
|
+
return null;
|
|
285
|
+
if (computedProps.item.children)
|
|
286
|
+
return cloneElement(computedProps.item.children, {
|
|
287
|
+
scene: "description",
|
|
288
|
+
value: computedProps.value,
|
|
289
|
+
values: computedProps.values
|
|
290
|
+
});
|
|
291
|
+
if (computedProps.item.descriptionRender)
|
|
292
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.item.descriptionRender(
|
|
293
|
+
computedProps.value,
|
|
294
|
+
computedProps.values,
|
|
295
|
+
0,
|
|
296
|
+
"description"
|
|
297
|
+
) });
|
|
298
|
+
if (computedProps.item.render)
|
|
299
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.item.render(
|
|
300
|
+
computedProps.value,
|
|
301
|
+
computedProps.values,
|
|
302
|
+
0,
|
|
303
|
+
"description"
|
|
304
|
+
) });
|
|
305
|
+
if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
|
|
306
|
+
return /* @__PURE__ */ jsx(Blank, {});
|
|
307
|
+
switch (computedProps.item.type) {
|
|
308
|
+
case "string[]":
|
|
309
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.value.join(", ") });
|
|
310
|
+
case "number":
|
|
311
|
+
return computedProps.value || null;
|
|
312
|
+
case "number[]":
|
|
313
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.value.join(", ") });
|
|
314
|
+
case "boolean":
|
|
315
|
+
return computedProps.value ? /* @__PURE__ */ jsx(
|
|
316
|
+
CheckOutlined,
|
|
317
|
+
{
|
|
318
|
+
style: {
|
|
319
|
+
marginTop: "4px",
|
|
320
|
+
color: "#52c41a"
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
) : /* @__PURE__ */ jsx(
|
|
324
|
+
CloseOutlined,
|
|
325
|
+
{
|
|
326
|
+
style: {
|
|
327
|
+
marginTop: "4px",
|
|
328
|
+
color: "#ff4d4f"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
case "time":
|
|
333
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.value.format("YYYY-MM-DD HH:mm:ss") });
|
|
334
|
+
case "date":
|
|
335
|
+
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
|
|
336
|
+
case "object":
|
|
337
|
+
if (!computedProps.value)
|
|
338
|
+
return /* @__PURE__ */ jsx(Blank, {});
|
|
339
|
+
return /* @__PURE__ */ jsx(
|
|
340
|
+
Description,
|
|
341
|
+
{
|
|
342
|
+
items: computedProps.item.object,
|
|
343
|
+
dataSource: computedProps.value,
|
|
344
|
+
column: 1
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
case "object[]":
|
|
348
|
+
if (!((_b = computedProps.value) == null ? void 0 : _b.length))
|
|
349
|
+
return /* @__PURE__ */ jsx(Blank, {});
|
|
350
|
+
return /* @__PURE__ */ jsx(Space, { direction: "vertical", children: computedProps.value.map(
|
|
351
|
+
(value, index) => /* @__PURE__ */ jsx(
|
|
352
|
+
Description,
|
|
353
|
+
{
|
|
354
|
+
items: computedProps.item.object,
|
|
355
|
+
dataSource: value,
|
|
356
|
+
column: 1
|
|
357
|
+
},
|
|
358
|
+
index
|
|
359
|
+
)
|
|
360
|
+
) });
|
|
361
|
+
default:
|
|
362
|
+
return computedProps.value || null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function Description(props) {
|
|
366
|
+
if (props.faasData && !props.dataSource)
|
|
367
|
+
return /* @__PURE__ */ jsx(
|
|
368
|
+
FaasDataWrapper,
|
|
369
|
+
{
|
|
370
|
+
render: ({ data }) => /* @__PURE__ */ jsx(Description, { ...props, dataSource: data }),
|
|
371
|
+
...props.faasData
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
return /* @__PURE__ */ jsx(
|
|
375
|
+
Descriptions,
|
|
376
|
+
{
|
|
377
|
+
...props,
|
|
378
|
+
title: isFunction(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
|
|
379
|
+
items: props.items.filter((item) => item && (!item.if || item.if(props.dataSource))).map((item) => ({
|
|
380
|
+
...item,
|
|
381
|
+
key: item.id,
|
|
382
|
+
label: item.title || upperFirst(item.id),
|
|
383
|
+
children: /* @__PURE__ */ jsx(
|
|
384
|
+
DescriptionItemContent,
|
|
385
|
+
{
|
|
386
|
+
item,
|
|
387
|
+
value: props.dataSource ? props.dataSource[item.id] : null,
|
|
388
|
+
values: props.dataSource,
|
|
389
|
+
extendTypes: props.extendTypes
|
|
390
|
+
}
|
|
391
|
+
)
|
|
392
|
+
}))
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
function ErrorChildren(props) {
|
|
397
|
+
return /* @__PURE__ */ jsx(
|
|
398
|
+
Alert,
|
|
399
|
+
{
|
|
400
|
+
type: "error",
|
|
401
|
+
message: props.errorMessage,
|
|
402
|
+
description: /* @__PURE__ */ jsx(
|
|
403
|
+
"pre",
|
|
404
|
+
{
|
|
405
|
+
style: {
|
|
406
|
+
fontSize: "0.9em",
|
|
407
|
+
overflowX: "auto"
|
|
408
|
+
},
|
|
409
|
+
children: props.errorDescription
|
|
410
|
+
}
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
function ErrorBoundary(props) {
|
|
416
|
+
return /* @__PURE__ */ jsx(ErrorBoundary$1, { errorChildren: /* @__PURE__ */ jsx(ErrorChildren, {}), ...props });
|
|
417
|
+
}
|
|
418
|
+
function processProps(propsCopy, config) {
|
|
419
|
+
if (!propsCopy.title)
|
|
420
|
+
propsCopy.title = upperFirst(propsCopy.id);
|
|
421
|
+
if (!propsCopy.label && propsCopy.label !== false)
|
|
422
|
+
propsCopy.label = propsCopy.title;
|
|
423
|
+
if (!propsCopy.name)
|
|
424
|
+
propsCopy.name = propsCopy.id;
|
|
425
|
+
if (!propsCopy.type)
|
|
426
|
+
propsCopy.type = "string";
|
|
427
|
+
if (!propsCopy.rules)
|
|
428
|
+
propsCopy.rules = [];
|
|
429
|
+
if (propsCopy.required) {
|
|
430
|
+
if (propsCopy.type.endsWith("[]"))
|
|
431
|
+
propsCopy.rules.push({
|
|
432
|
+
required: true,
|
|
433
|
+
validator: async (_, values) => {
|
|
434
|
+
if (!values || values.length < 1)
|
|
435
|
+
return Promise.reject(
|
|
436
|
+
Error(`${propsCopy.label || propsCopy.title} ${config.required}`)
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
else
|
|
441
|
+
propsCopy.rules.push({
|
|
442
|
+
required: true,
|
|
443
|
+
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
if (!propsCopy.input)
|
|
447
|
+
propsCopy.input = {};
|
|
448
|
+
if (propsCopy.options)
|
|
449
|
+
propsCopy.input.options = transferOptions(
|
|
450
|
+
propsCopy.options
|
|
451
|
+
);
|
|
452
|
+
switch (propsCopy.type) {
|
|
453
|
+
case "boolean":
|
|
454
|
+
propsCopy.valuePropName = "checked";
|
|
455
|
+
break;
|
|
456
|
+
case "object":
|
|
457
|
+
if (!Array.isArray(propsCopy.name))
|
|
458
|
+
propsCopy.name = [propsCopy.name];
|
|
459
|
+
for (const sub of propsCopy.object) {
|
|
460
|
+
if (!sub.name)
|
|
461
|
+
sub.name = propsCopy.name.concat(sub.id);
|
|
462
|
+
processProps(sub, config);
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
return propsCopy;
|
|
467
|
+
}
|
|
468
|
+
function FormItem(props) {
|
|
469
|
+
var _a;
|
|
470
|
+
const [computedProps, setComputedProps] = useState();
|
|
471
|
+
const [extendTypes, setExtendTypes] = useState();
|
|
472
|
+
const { common: common2 } = useConfigContext();
|
|
473
|
+
const [hidden, setHidden] = useState(props.hidden || false);
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
const propsCopy = { ...props };
|
|
476
|
+
if (propsCopy.extendTypes) {
|
|
477
|
+
setExtendTypes(propsCopy.extendTypes);
|
|
478
|
+
delete propsCopy.extendTypes;
|
|
479
|
+
}
|
|
480
|
+
if (propsCopy.if) {
|
|
481
|
+
const condition = propsCopy.if;
|
|
482
|
+
const originShouldUpdate = propsCopy.shouldUpdate;
|
|
483
|
+
propsCopy.shouldUpdate = (prev, cur) => {
|
|
484
|
+
const show = condition(cur);
|
|
485
|
+
const shouldUpdate = hidden !== show;
|
|
486
|
+
setHidden(!show);
|
|
487
|
+
const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
|
|
488
|
+
return shouldUpdate || origin;
|
|
489
|
+
};
|
|
490
|
+
delete propsCopy.if;
|
|
491
|
+
delete propsCopy.hidden;
|
|
492
|
+
}
|
|
493
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
494
|
+
}, [props]);
|
|
495
|
+
if (!computedProps)
|
|
496
|
+
return null;
|
|
497
|
+
if (hidden)
|
|
498
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, noStyle: true, rules: [], children: /* @__PURE__ */ jsx(Input, { hidden: true }) });
|
|
499
|
+
if (extendTypes == null ? void 0 : extendTypes[computedProps.type])
|
|
500
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
|
|
501
|
+
if (computedProps.formChildren === null)
|
|
502
|
+
return null;
|
|
503
|
+
if (computedProps.formChildren)
|
|
504
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.formChildren, { scene: "form" }) });
|
|
505
|
+
if (computedProps.children === null)
|
|
506
|
+
return null;
|
|
507
|
+
if (computedProps.children)
|
|
508
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.children, { scene: "form" }) });
|
|
509
|
+
if (computedProps.formRender)
|
|
510
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.formRender(null, null, 0, "form") });
|
|
511
|
+
if (computedProps.render)
|
|
512
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
|
|
513
|
+
switch (computedProps.type) {
|
|
514
|
+
case "string":
|
|
515
|
+
if (computedProps.options)
|
|
516
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsx(Select, { ...computedProps.input }) : /* @__PURE__ */ jsx(Radio.Group, { ...computedProps.input }) });
|
|
517
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Input, { ...computedProps.input }) });
|
|
518
|
+
case "string[]":
|
|
519
|
+
if (computedProps.options)
|
|
520
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Select, { mode: "multiple", ...computedProps.input }) });
|
|
521
|
+
return /* @__PURE__ */ jsx(
|
|
522
|
+
Form$1.List,
|
|
523
|
+
{
|
|
524
|
+
name: computedProps.name,
|
|
525
|
+
rules: computedProps.rules,
|
|
526
|
+
children: (fields, { add, remove }, { errors }) => {
|
|
527
|
+
var _a2;
|
|
528
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
529
|
+
computedProps.label && /* @__PURE__ */ jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsx(
|
|
530
|
+
"label",
|
|
531
|
+
{
|
|
532
|
+
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required",
|
|
533
|
+
children: computedProps.label
|
|
534
|
+
}
|
|
535
|
+
) }),
|
|
536
|
+
fields.map((field) => {
|
|
537
|
+
var _a3;
|
|
538
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { children: /* @__PURE__ */ jsxs(Row, { gutter: 24, style: { flexFlow: "row nowrap" }, children: [
|
|
539
|
+
/* @__PURE__ */ jsx(Col, { span: 23, children: /* @__PURE__ */ jsx(Form$1.Item, { ...field, noStyle: true, children: /* @__PURE__ */ jsx(Input, { ...computedProps.input }) }) }),
|
|
540
|
+
/* @__PURE__ */ jsx(Col, { span: 1, children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsx(
|
|
541
|
+
Button,
|
|
542
|
+
{
|
|
543
|
+
danger: true,
|
|
544
|
+
type: "link",
|
|
545
|
+
style: { float: "right" },
|
|
546
|
+
icon: /* @__PURE__ */ jsx(MinusCircleOutlined, {}),
|
|
547
|
+
onClick: () => remove(field.name)
|
|
548
|
+
}
|
|
549
|
+
) })
|
|
550
|
+
] }) }, field.key);
|
|
551
|
+
}),
|
|
552
|
+
/* @__PURE__ */ jsxs(Form$1.Item, { children: [
|
|
553
|
+
!((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsx(
|
|
554
|
+
Button,
|
|
555
|
+
{
|
|
556
|
+
type: "dashed",
|
|
557
|
+
block: true,
|
|
558
|
+
onClick: () => add(),
|
|
559
|
+
icon: /* @__PURE__ */ jsx(PlusOutlined, {})
|
|
560
|
+
}
|
|
561
|
+
),
|
|
562
|
+
computedProps.extra && /* @__PURE__ */ jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
|
|
563
|
+
/* @__PURE__ */ jsx(Form$1.ErrorList, { errors })
|
|
564
|
+
] })
|
|
565
|
+
] });
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
case "number":
|
|
570
|
+
if (computedProps.options)
|
|
571
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsx(Select, { ...computedProps.input }) : /* @__PURE__ */ jsx(Radio.Group, { ...computedProps.input }) });
|
|
572
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(
|
|
573
|
+
InputNumber,
|
|
574
|
+
{
|
|
575
|
+
style: { width: "100%" },
|
|
576
|
+
...computedProps.input
|
|
577
|
+
}
|
|
578
|
+
) });
|
|
579
|
+
case "number[]":
|
|
580
|
+
if (computedProps.options)
|
|
581
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Select, { mode: "multiple", ...computedProps.input }) });
|
|
582
|
+
return /* @__PURE__ */ jsx(
|
|
583
|
+
Form$1.List,
|
|
584
|
+
{
|
|
585
|
+
name: computedProps.name,
|
|
586
|
+
rules: computedProps.rules,
|
|
587
|
+
children: (fields, { add, remove }, { errors }) => {
|
|
588
|
+
var _a2, _b;
|
|
589
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
590
|
+
computedProps.label && /* @__PURE__ */ jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsx(
|
|
591
|
+
"label",
|
|
592
|
+
{
|
|
593
|
+
className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find(
|
|
594
|
+
(r) => r.required
|
|
595
|
+
)) && "ant-form-item-required",
|
|
596
|
+
children: computedProps.label
|
|
597
|
+
}
|
|
598
|
+
) }),
|
|
599
|
+
fields.map((field) => {
|
|
600
|
+
var _a3;
|
|
601
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { children: /* @__PURE__ */ jsxs(Row, { gutter: 24, style: { flexFlow: "row nowrap" }, children: [
|
|
602
|
+
/* @__PURE__ */ jsx(Col, { span: 23, children: /* @__PURE__ */ jsx(Form$1.Item, { ...field, noStyle: true, children: /* @__PURE__ */ jsx(
|
|
603
|
+
InputNumber,
|
|
604
|
+
{
|
|
605
|
+
style: { width: "100%" },
|
|
606
|
+
...computedProps.input
|
|
607
|
+
}
|
|
608
|
+
) }) }),
|
|
609
|
+
/* @__PURE__ */ jsx(Col, { span: 1, children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsx(
|
|
610
|
+
Button,
|
|
611
|
+
{
|
|
612
|
+
danger: true,
|
|
613
|
+
type: "link",
|
|
614
|
+
style: { float: "right" },
|
|
615
|
+
icon: /* @__PURE__ */ jsx(MinusCircleOutlined, {}),
|
|
616
|
+
onClick: () => remove(field.name)
|
|
617
|
+
}
|
|
618
|
+
) })
|
|
619
|
+
] }) }, field.key);
|
|
620
|
+
}),
|
|
621
|
+
/* @__PURE__ */ jsxs(Form$1.Item, { children: [
|
|
622
|
+
!((_b = computedProps.input) == null ? void 0 : _b.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsx(
|
|
623
|
+
Button,
|
|
624
|
+
{
|
|
625
|
+
type: "dashed",
|
|
626
|
+
block: true,
|
|
627
|
+
onClick: () => add(),
|
|
628
|
+
icon: /* @__PURE__ */ jsx(PlusOutlined, {})
|
|
629
|
+
}
|
|
630
|
+
),
|
|
631
|
+
computedProps.extra && /* @__PURE__ */ jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
|
|
632
|
+
/* @__PURE__ */ jsx(Form$1.ErrorList, { errors })
|
|
633
|
+
] })
|
|
634
|
+
] });
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
case "boolean":
|
|
639
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Switch, { ...computedProps.input }) });
|
|
640
|
+
case "date":
|
|
641
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(DatePicker, { ...computedProps.input }) });
|
|
642
|
+
case "time":
|
|
643
|
+
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(TimePicker, { ...computedProps.input }) });
|
|
644
|
+
case "object":
|
|
645
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
646
|
+
computedProps.label && /* @__PURE__ */ jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsx(
|
|
647
|
+
"label",
|
|
648
|
+
{
|
|
649
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required",
|
|
650
|
+
children: computedProps.label
|
|
651
|
+
}
|
|
652
|
+
) }),
|
|
653
|
+
computedProps.object.map((o) => /* @__PURE__ */ jsx(FormItem, { ...o }, o.id))
|
|
654
|
+
] });
|
|
655
|
+
case "object[]":
|
|
656
|
+
return /* @__PURE__ */ jsx(
|
|
657
|
+
Form$1.List,
|
|
658
|
+
{
|
|
659
|
+
name: computedProps.name,
|
|
660
|
+
rules: computedProps.rules,
|
|
661
|
+
children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
662
|
+
fields.map((field) => /* @__PURE__ */ jsxs(Form$1.Item, { style: { marginBottom: 0 }, children: [
|
|
663
|
+
/* @__PURE__ */ jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxs("label", { children: [
|
|
664
|
+
computedProps.label,
|
|
665
|
+
" ",
|
|
666
|
+
field.name + 1,
|
|
667
|
+
!computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsx(
|
|
668
|
+
Button,
|
|
669
|
+
{
|
|
670
|
+
danger: true,
|
|
671
|
+
type: "link",
|
|
672
|
+
onClick: () => remove(field.name),
|
|
673
|
+
children: common2.delete
|
|
674
|
+
}
|
|
675
|
+
)
|
|
676
|
+
] }) }),
|
|
677
|
+
/* @__PURE__ */ jsx(Row, { gutter: 24, children: computedProps.object.map((o) => /* @__PURE__ */ jsx(Col, { span: o.col || 24, children: /* @__PURE__ */ jsx(FormItem, { ...o, name: [field.name, o.id] }) }, o.id)) })
|
|
678
|
+
] }, field.key)),
|
|
679
|
+
/* @__PURE__ */ jsxs(Form$1.Item, { children: [
|
|
680
|
+
!computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxs(
|
|
681
|
+
Button,
|
|
682
|
+
{
|
|
683
|
+
type: "dashed",
|
|
684
|
+
block: true,
|
|
685
|
+
onClick: () => add(),
|
|
686
|
+
icon: /* @__PURE__ */ jsx(PlusOutlined, {}),
|
|
687
|
+
children: [
|
|
688
|
+
common2.add,
|
|
689
|
+
" ",
|
|
690
|
+
computedProps.label
|
|
691
|
+
]
|
|
692
|
+
}
|
|
693
|
+
),
|
|
694
|
+
computedProps.extra && /* @__PURE__ */ jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
|
|
695
|
+
/* @__PURE__ */ jsx(Form$1.ErrorList, { errors })
|
|
696
|
+
] })
|
|
697
|
+
] })
|
|
698
|
+
}
|
|
699
|
+
);
|
|
700
|
+
default:
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
FormItem.useStatus = Form$1.Item.useStatus;
|
|
705
|
+
function Form(props) {
|
|
706
|
+
var _a, _b;
|
|
707
|
+
const [loading, setLoading] = useState(false);
|
|
708
|
+
const [computedProps, setComputedProps] = useState();
|
|
709
|
+
const config = useConfigContext();
|
|
710
|
+
const [extendTypes, setExtendTypes] = useState();
|
|
711
|
+
const [form] = Form$1.useForm(props.form);
|
|
712
|
+
const [initialValues, setInitialValues] = useState(
|
|
713
|
+
props.initialValues
|
|
714
|
+
);
|
|
715
|
+
useEffect(() => {
|
|
716
|
+
var _a2, _b2, _c;
|
|
717
|
+
const propsCopy = {
|
|
718
|
+
...props,
|
|
719
|
+
form
|
|
720
|
+
};
|
|
721
|
+
if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
|
|
722
|
+
for (const key in propsCopy.initialValues) {
|
|
723
|
+
propsCopy.initialValues[key] = transferValue(
|
|
724
|
+
(_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
|
|
725
|
+
propsCopy.initialValues[key]
|
|
726
|
+
);
|
|
727
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
728
|
+
if (item == null ? void 0 : item.if)
|
|
729
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
730
|
+
}
|
|
731
|
+
for (const item of propsCopy.items) {
|
|
732
|
+
if (item.if)
|
|
733
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
734
|
+
}
|
|
735
|
+
setInitialValues(propsCopy.initialValues);
|
|
736
|
+
delete propsCopy.initialValues;
|
|
737
|
+
}
|
|
738
|
+
if (propsCopy.onFinish) {
|
|
739
|
+
propsCopy.onFinish = async (values) => {
|
|
740
|
+
var _a3, _b3;
|
|
741
|
+
setLoading(true);
|
|
742
|
+
try {
|
|
743
|
+
if ((_b3 = (_a3 = propsCopy.submit) == null ? void 0 : _a3.to) == null ? void 0 : _b3.action) {
|
|
744
|
+
await props.onFinish(
|
|
745
|
+
values,
|
|
746
|
+
async (values2) => faas(
|
|
747
|
+
propsCopy.submit.to.action,
|
|
748
|
+
propsCopy.submit.to.params ? {
|
|
749
|
+
...values2,
|
|
750
|
+
...propsCopy.submit.to.params
|
|
751
|
+
} : values2
|
|
752
|
+
)
|
|
753
|
+
);
|
|
754
|
+
} else
|
|
755
|
+
await props.onFinish(values);
|
|
756
|
+
} catch (error) {
|
|
757
|
+
console.error(error);
|
|
758
|
+
}
|
|
759
|
+
setLoading(false);
|
|
760
|
+
};
|
|
761
|
+
} else if (propsCopy.submit && ((_c = propsCopy.submit.to) == null ? void 0 : _c.action)) {
|
|
762
|
+
propsCopy.onFinish = async (values) => {
|
|
763
|
+
setLoading(true);
|
|
764
|
+
return faas(
|
|
765
|
+
propsCopy.submit.to.action,
|
|
766
|
+
propsCopy.submit.to.params ? {
|
|
767
|
+
...values,
|
|
768
|
+
...propsCopy.submit.to.params
|
|
769
|
+
} : values
|
|
770
|
+
).then((result) => {
|
|
771
|
+
if (propsCopy.submit.to.then)
|
|
772
|
+
propsCopy.submit.to.then(result);
|
|
773
|
+
return result;
|
|
774
|
+
}).catch((error) => {
|
|
775
|
+
if (propsCopy.submit.to.catch)
|
|
776
|
+
propsCopy.submit.to.catch(error);
|
|
777
|
+
return Promise.reject(error);
|
|
778
|
+
}).finally(() => {
|
|
779
|
+
if (propsCopy.submit.to.finally)
|
|
780
|
+
propsCopy.submit.to.finally();
|
|
781
|
+
setLoading(false);
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
if (propsCopy.extendTypes) {
|
|
786
|
+
setExtendTypes(propsCopy.extendTypes);
|
|
787
|
+
delete propsCopy.extendTypes;
|
|
788
|
+
}
|
|
789
|
+
setComputedProps(propsCopy);
|
|
790
|
+
}, [props]);
|
|
791
|
+
const onValuesChange = useCallback(
|
|
792
|
+
(changedValues, allValues) => {
|
|
793
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
794
|
+
if (props.onValuesChange) {
|
|
795
|
+
props.onValuesChange(changedValues, allValues);
|
|
796
|
+
}
|
|
797
|
+
if (!props.items)
|
|
798
|
+
return;
|
|
799
|
+
for (const key in changedValues) {
|
|
800
|
+
const item = computedProps.items.find((i) => i.id === key);
|
|
801
|
+
if (item == null ? void 0 : item.onValueChange)
|
|
802
|
+
item.onValueChange(changedValues[key], allValues, form);
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
[computedProps]
|
|
806
|
+
);
|
|
807
|
+
useEffect(() => {
|
|
808
|
+
if (!initialValues)
|
|
809
|
+
return;
|
|
810
|
+
console.debug("Form:initialValues", initialValues);
|
|
811
|
+
form.setFieldsValue(initialValues);
|
|
812
|
+
setInitialValues(null);
|
|
813
|
+
}, [computedProps]);
|
|
814
|
+
if (!computedProps)
|
|
815
|
+
return null;
|
|
816
|
+
return /* @__PURE__ */ jsxs(Form$1, { ...computedProps, onValuesChange, children: [
|
|
817
|
+
computedProps.beforeItems,
|
|
818
|
+
(_a = computedProps.items) == null ? void 0 : _a.map(
|
|
819
|
+
(item) => isValidElement(item) ? item : /* @__PURE__ */ jsx(
|
|
820
|
+
FormItem,
|
|
821
|
+
{
|
|
822
|
+
...item,
|
|
823
|
+
extendTypes
|
|
824
|
+
},
|
|
825
|
+
item.id
|
|
826
|
+
)
|
|
827
|
+
),
|
|
828
|
+
computedProps.children,
|
|
829
|
+
computedProps.submit !== false && /* @__PURE__ */ jsx(Button, { htmlType: "submit", type: "primary", loading, children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text }),
|
|
830
|
+
computedProps.footer
|
|
831
|
+
] });
|
|
832
|
+
}
|
|
833
|
+
Form.useForm = Form$1.useForm;
|
|
834
|
+
Form.useFormInstance = Form$1.useFormInstance;
|
|
835
|
+
Form.useWatch = Form$1.useWatch;
|
|
836
|
+
Form.Item = FormItem;
|
|
837
|
+
Form.List = Form$1.List;
|
|
838
|
+
Form.ErrorList = Form$1.ErrorList;
|
|
839
|
+
Form.Provider = Form$1.Provider;
|
|
840
|
+
function Link(props) {
|
|
841
|
+
var _a, _b;
|
|
842
|
+
const { Link: Config } = useConfigContext();
|
|
843
|
+
const navigate = useNavigate();
|
|
844
|
+
let computedStyle = {
|
|
845
|
+
...Config.style || {},
|
|
846
|
+
cursor: "pointer",
|
|
847
|
+
...props.style
|
|
848
|
+
};
|
|
849
|
+
if (props.block)
|
|
850
|
+
computedStyle = Object.assign(
|
|
851
|
+
{
|
|
852
|
+
display: "block",
|
|
853
|
+
width: "100%"
|
|
854
|
+
},
|
|
855
|
+
computedStyle
|
|
856
|
+
);
|
|
857
|
+
if (props.href.startsWith("http")) {
|
|
858
|
+
if (props.button)
|
|
859
|
+
return /* @__PURE__ */ jsx(
|
|
860
|
+
Button,
|
|
861
|
+
{
|
|
862
|
+
...props.button,
|
|
863
|
+
target: props.target || (Config == null ? void 0 : Config.target) || "_blank",
|
|
864
|
+
style: computedStyle,
|
|
865
|
+
href: props.href,
|
|
866
|
+
onClick: props.onClick,
|
|
867
|
+
children: (_a = props.text) != null ? _a : props.children
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
if (props.children)
|
|
871
|
+
return (
|
|
872
|
+
// biome-ignore lint/a11y/useValidAnchor: <explanation>
|
|
873
|
+
/* @__PURE__ */ jsx(
|
|
874
|
+
"a",
|
|
875
|
+
{
|
|
876
|
+
href: props.href,
|
|
877
|
+
target: props.target || (Config == null ? void 0 : Config.target),
|
|
878
|
+
style: computedStyle,
|
|
879
|
+
onClick: props.onClick,
|
|
880
|
+
children: props.children
|
|
881
|
+
}
|
|
882
|
+
)
|
|
883
|
+
);
|
|
884
|
+
return /* @__PURE__ */ jsx(
|
|
885
|
+
Typography.Link,
|
|
886
|
+
{
|
|
887
|
+
href: props.href,
|
|
888
|
+
target: props.target || (Config == null ? void 0 : Config.target) || "_blank",
|
|
889
|
+
style: computedStyle,
|
|
890
|
+
copyable: props.copyable,
|
|
891
|
+
onClick: props.onClick,
|
|
892
|
+
children: props.text
|
|
893
|
+
}
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
if (props.button)
|
|
897
|
+
return /* @__PURE__ */ jsx(
|
|
898
|
+
Button,
|
|
899
|
+
{
|
|
900
|
+
...props.button,
|
|
901
|
+
style: computedStyle,
|
|
902
|
+
onClick: (e) => props.onClick ? props.onClick(e) : (props.target || (Config == null ? void 0 : Config.target)) === "_blank" ? window.open(props.href) : navigate(props.href),
|
|
903
|
+
children: (_b = props.text) != null ? _b : props.children
|
|
904
|
+
}
|
|
905
|
+
);
|
|
906
|
+
if (props.children)
|
|
907
|
+
return /* @__PURE__ */ jsx(
|
|
908
|
+
Link$1,
|
|
909
|
+
{
|
|
910
|
+
to: props.href,
|
|
911
|
+
target: props.target || (Config == null ? void 0 : Config.target),
|
|
912
|
+
style: computedStyle,
|
|
913
|
+
onClick: props.onClick,
|
|
914
|
+
children: props.children
|
|
915
|
+
}
|
|
916
|
+
);
|
|
917
|
+
return /* @__PURE__ */ jsx(
|
|
918
|
+
Typography.Link,
|
|
919
|
+
{
|
|
920
|
+
href: props.href,
|
|
921
|
+
target: props.target || (Config == null ? void 0 : Config.target),
|
|
922
|
+
style: computedStyle,
|
|
923
|
+
copyable: props.copyable,
|
|
924
|
+
onClick: (e) => {
|
|
925
|
+
if (props.onClick) {
|
|
926
|
+
props.onClick(e);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
if ((props.target || (Config == null ? void 0 : Config.target)) !== "_blank") {
|
|
930
|
+
e.preventDefault();
|
|
931
|
+
navigate(props.href);
|
|
932
|
+
}
|
|
933
|
+
},
|
|
934
|
+
children: props.text
|
|
935
|
+
}
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
function PageNotFound() {
|
|
939
|
+
const config = useConfigContext();
|
|
940
|
+
return /* @__PURE__ */ jsx(Result, { status: "404", title: config.common.pageNotFound });
|
|
941
|
+
}
|
|
942
|
+
function Routes(props) {
|
|
943
|
+
return /* @__PURE__ */ jsxs(Routes$1, { children: [
|
|
944
|
+
props.routes.map((r) => /* @__PURE__ */ jsx(
|
|
945
|
+
Route,
|
|
946
|
+
{
|
|
947
|
+
...r,
|
|
948
|
+
element: r.element || /* @__PURE__ */ jsx(
|
|
949
|
+
Suspense,
|
|
950
|
+
{
|
|
951
|
+
fallback: props.fallback || /* @__PURE__ */ jsx("div", { style: { padding: "24px" }, children: /* @__PURE__ */ jsx(Skeleton, { active: true }) }),
|
|
952
|
+
children: /* @__PURE__ */ jsx(r.page, {})
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
},
|
|
956
|
+
r.path
|
|
957
|
+
)),
|
|
958
|
+
/* @__PURE__ */ jsx(Route, { path: "*", element: props.notFound || /* @__PURE__ */ jsx(PageNotFound, {}) }, "*")
|
|
959
|
+
] });
|
|
960
|
+
}
|
|
961
|
+
function processValue(item, value) {
|
|
962
|
+
var _a;
|
|
963
|
+
const transferred = transferValue(item.type, value);
|
|
964
|
+
if (transferred === null || Array.isArray(transferred) && transferred.length === 0)
|
|
965
|
+
return /* @__PURE__ */ jsx(Blank, {});
|
|
966
|
+
if (item.options) {
|
|
967
|
+
if (item.type.endsWith("[]"))
|
|
968
|
+
return transferred.map(
|
|
969
|
+
(v) => {
|
|
970
|
+
var _a2;
|
|
971
|
+
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
972
|
+
}
|
|
973
|
+
).join(", ");
|
|
974
|
+
if (["string", "number", "boolean"].includes(item.type))
|
|
975
|
+
return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
|
|
976
|
+
}
|
|
977
|
+
if (item.type.endsWith("[]"))
|
|
978
|
+
return transferred.join(", ");
|
|
979
|
+
if (["date", "time"].includes(item.type))
|
|
980
|
+
return transferred.format(
|
|
981
|
+
item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"
|
|
982
|
+
);
|
|
983
|
+
return value;
|
|
984
|
+
}
|
|
985
|
+
function Table(props) {
|
|
986
|
+
const [columns, setColumns] = useState();
|
|
987
|
+
const { common: common2 } = useConfigContext();
|
|
988
|
+
const generateFilterDropdown = (item) => {
|
|
989
|
+
if (typeof item.filterDropdown !== "undefined")
|
|
990
|
+
return;
|
|
991
|
+
if (item.options.length < 11) {
|
|
992
|
+
if (!item.filters)
|
|
993
|
+
item.filters = item.options.map((o) => ({
|
|
994
|
+
text: o.label,
|
|
995
|
+
value: o.value
|
|
996
|
+
}));
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ jsx(
|
|
1000
|
+
"div",
|
|
1001
|
+
{
|
|
1002
|
+
style: {
|
|
1003
|
+
padding: 8,
|
|
1004
|
+
width: "200px"
|
|
1005
|
+
},
|
|
1006
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
1007
|
+
children: /* @__PURE__ */ jsx(
|
|
1008
|
+
Select,
|
|
1009
|
+
{
|
|
1010
|
+
options: item.options,
|
|
1011
|
+
allowClear: true,
|
|
1012
|
+
showSearch: true,
|
|
1013
|
+
style: { width: "100%" },
|
|
1014
|
+
placeholder: `${common2.search} ${item.title}`,
|
|
1015
|
+
value: selectedKeys,
|
|
1016
|
+
onChange: (v) => {
|
|
1017
|
+
setSelectedKeys((v == null ? void 0 : v.length) ? v : []);
|
|
1018
|
+
confirm();
|
|
1019
|
+
},
|
|
1020
|
+
mode: "multiple",
|
|
1021
|
+
filterOption: (input, option) => {
|
|
1022
|
+
if (!input || !option || !option.label)
|
|
1023
|
+
return true;
|
|
1024
|
+
input = input.trim();
|
|
1025
|
+
return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
)
|
|
1029
|
+
}
|
|
1030
|
+
);
|
|
1031
|
+
return item;
|
|
1032
|
+
};
|
|
1033
|
+
useEffect(() => {
|
|
1034
|
+
var _a, _b;
|
|
1035
|
+
for (const item of props.items) {
|
|
1036
|
+
if (!item.key)
|
|
1037
|
+
item.key = item.id;
|
|
1038
|
+
if (!item.dataIndex)
|
|
1039
|
+
item.dataIndex = item.id;
|
|
1040
|
+
if (!item.title)
|
|
1041
|
+
item.title = upperFirst(item.id);
|
|
1042
|
+
if (!item.type)
|
|
1043
|
+
item.type = "string";
|
|
1044
|
+
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
1045
|
+
item.options = transferOptions(item.options);
|
|
1046
|
+
item.filters = item.options.map((o) => ({
|
|
1047
|
+
text: o.label,
|
|
1048
|
+
value: o.value
|
|
1049
|
+
})).concat({
|
|
1050
|
+
text: /* @__PURE__ */ jsx(Blank, {}),
|
|
1051
|
+
value: null
|
|
1052
|
+
});
|
|
1053
|
+
generateFilterDropdown(item);
|
|
1054
|
+
}
|
|
1055
|
+
if (item.tableChildren === null)
|
|
1056
|
+
item.render = () => null;
|
|
1057
|
+
else if (item.tableChildren)
|
|
1058
|
+
item.render = (value, values) => cloneElement(item.tableChildren, {
|
|
1059
|
+
scene: "table",
|
|
1060
|
+
value,
|
|
1061
|
+
values
|
|
1062
|
+
});
|
|
1063
|
+
else if (item.children === null)
|
|
1064
|
+
item.render = () => null;
|
|
1065
|
+
else if (item.children)
|
|
1066
|
+
item.render = (value, values) => cloneElement(item.children, {
|
|
1067
|
+
scene: "table",
|
|
1068
|
+
value,
|
|
1069
|
+
values
|
|
1070
|
+
});
|
|
1071
|
+
if ((_b = props.extendTypes) == null ? void 0 : _b[item.type]) {
|
|
1072
|
+
if (props.extendTypes[item.type].children)
|
|
1073
|
+
item.render = (value, values) => cloneElement(props.extendTypes[item.type].children, {
|
|
1074
|
+
scene: "table",
|
|
1075
|
+
value,
|
|
1076
|
+
values
|
|
1077
|
+
});
|
|
1078
|
+
else if (props.extendTypes[item.type].render)
|
|
1079
|
+
item.render = props.extendTypes[item.type].render;
|
|
1080
|
+
else
|
|
1081
|
+
throw Error(`${item.type} requires children or render`);
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
switch (item.type) {
|
|
1085
|
+
case "string":
|
|
1086
|
+
if (!item.render)
|
|
1087
|
+
item.render = (value) => processValue(item, value);
|
|
1088
|
+
if (!item.onFilter)
|
|
1089
|
+
item.onFilter = (value, row) => {
|
|
1090
|
+
if (!value || isNil(value))
|
|
1091
|
+
return true;
|
|
1092
|
+
if (isNil(row[item.id]))
|
|
1093
|
+
return false;
|
|
1094
|
+
return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
|
|
1095
|
+
};
|
|
1096
|
+
if (item.filterDropdown === false || item.filterDropdown)
|
|
1097
|
+
break;
|
|
1098
|
+
if (!item.filters && item.optionsType !== "auto")
|
|
1099
|
+
item.filterDropdown = ({
|
|
1100
|
+
setSelectedKeys,
|
|
1101
|
+
confirm,
|
|
1102
|
+
clearFilters
|
|
1103
|
+
}) => /* @__PURE__ */ jsx(
|
|
1104
|
+
Input.Search,
|
|
1105
|
+
{
|
|
1106
|
+
placeholder: `${common2.search} ${item.title}`,
|
|
1107
|
+
allowClear: true,
|
|
1108
|
+
onSearch: (v) => {
|
|
1109
|
+
if (v) {
|
|
1110
|
+
setSelectedKeys([v]);
|
|
1111
|
+
} else {
|
|
1112
|
+
setSelectedKeys([]);
|
|
1113
|
+
clearFilters();
|
|
1114
|
+
}
|
|
1115
|
+
confirm();
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
);
|
|
1119
|
+
break;
|
|
1120
|
+
case "string[]":
|
|
1121
|
+
if (!item.render)
|
|
1122
|
+
item.render = (value) => processValue(item, value);
|
|
1123
|
+
if (!item.onFilter)
|
|
1124
|
+
item.onFilter = (value, row) => {
|
|
1125
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1126
|
+
return true;
|
|
1127
|
+
if (!row[item.id] || !row[item.id].length || !value)
|
|
1128
|
+
return false;
|
|
1129
|
+
return row[item.id].some(
|
|
1130
|
+
(v) => v.trim().toLowerCase().includes(value.trim().toLowerCase())
|
|
1131
|
+
);
|
|
1132
|
+
};
|
|
1133
|
+
if (item.filterDropdown === false || item.filterDropdown)
|
|
1134
|
+
break;
|
|
1135
|
+
if (!item.filters && item.optionsType !== "auto")
|
|
1136
|
+
item.filterDropdown = ({
|
|
1137
|
+
setSelectedKeys,
|
|
1138
|
+
confirm,
|
|
1139
|
+
clearFilters
|
|
1140
|
+
}) => /* @__PURE__ */ jsx(
|
|
1141
|
+
Input.Search,
|
|
1142
|
+
{
|
|
1143
|
+
placeholder: `${common2.search} ${item.title}`,
|
|
1144
|
+
allowClear: true,
|
|
1145
|
+
onSearch: (v) => {
|
|
1146
|
+
if (v) {
|
|
1147
|
+
setSelectedKeys([v]);
|
|
1148
|
+
} else {
|
|
1149
|
+
setSelectedKeys([]);
|
|
1150
|
+
clearFilters();
|
|
1151
|
+
}
|
|
1152
|
+
confirm();
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
);
|
|
1156
|
+
break;
|
|
1157
|
+
case "number":
|
|
1158
|
+
if (!item.render)
|
|
1159
|
+
item.render = (value) => processValue(item, value);
|
|
1160
|
+
if (!item.sorter)
|
|
1161
|
+
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1162
|
+
if (!item.onFilter)
|
|
1163
|
+
item.onFilter = (value, row) => {
|
|
1164
|
+
if (value === null)
|
|
1165
|
+
return true;
|
|
1166
|
+
if (isNil(row[item.id]))
|
|
1167
|
+
return false;
|
|
1168
|
+
return value == row[item.id];
|
|
1169
|
+
};
|
|
1170
|
+
if (item.filterDropdown === false || item.filterDropdown)
|
|
1171
|
+
break;
|
|
1172
|
+
if (!item.filters)
|
|
1173
|
+
item.filterDropdown = ({
|
|
1174
|
+
setSelectedKeys,
|
|
1175
|
+
confirm,
|
|
1176
|
+
clearFilters
|
|
1177
|
+
}) => /* @__PURE__ */ jsx(
|
|
1178
|
+
Input.Search,
|
|
1179
|
+
{
|
|
1180
|
+
placeholder: `${common2.search} ${item.title}`,
|
|
1181
|
+
allowClear: true,
|
|
1182
|
+
onSearch: (v) => {
|
|
1183
|
+
if (v) {
|
|
1184
|
+
setSelectedKeys([Number(v)]);
|
|
1185
|
+
} else {
|
|
1186
|
+
setSelectedKeys([]);
|
|
1187
|
+
clearFilters();
|
|
1188
|
+
}
|
|
1189
|
+
confirm();
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
);
|
|
1193
|
+
break;
|
|
1194
|
+
case "number[]":
|
|
1195
|
+
if (!item.render)
|
|
1196
|
+
item.render = (value) => processValue(item, value).join(", ");
|
|
1197
|
+
if (!item.onFilter)
|
|
1198
|
+
item.onFilter = (value, row) => {
|
|
1199
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1200
|
+
return true;
|
|
1201
|
+
if (!row[item.id] || !row[item.id].length)
|
|
1202
|
+
return false;
|
|
1203
|
+
return row[item.id].includes(Number(value));
|
|
1204
|
+
};
|
|
1205
|
+
if (item.filterDropdown === false || item.filterDropdown)
|
|
1206
|
+
break;
|
|
1207
|
+
if (!item.filters)
|
|
1208
|
+
item.filterDropdown = ({
|
|
1209
|
+
setSelectedKeys,
|
|
1210
|
+
confirm,
|
|
1211
|
+
clearFilters
|
|
1212
|
+
}) => /* @__PURE__ */ jsx(
|
|
1213
|
+
Input.Search,
|
|
1214
|
+
{
|
|
1215
|
+
placeholder: `${common2.search} ${item.title}`,
|
|
1216
|
+
allowClear: true,
|
|
1217
|
+
onSearch: (v) => {
|
|
1218
|
+
if (v) {
|
|
1219
|
+
setSelectedKeys([Number(v)]);
|
|
1220
|
+
} else {
|
|
1221
|
+
setSelectedKeys([]);
|
|
1222
|
+
clearFilters();
|
|
1223
|
+
}
|
|
1224
|
+
confirm();
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
);
|
|
1228
|
+
break;
|
|
1229
|
+
case "boolean":
|
|
1230
|
+
if (!item.render)
|
|
1231
|
+
item.render = (value) => isNil(value) ? /* @__PURE__ */ jsx(Blank, {}) : value ? /* @__PURE__ */ jsx(
|
|
1232
|
+
CheckOutlined,
|
|
1233
|
+
{
|
|
1234
|
+
style: {
|
|
1235
|
+
marginTop: "4px",
|
|
1236
|
+
color: "#52c41a"
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
) : /* @__PURE__ */ jsx(
|
|
1240
|
+
CloseOutlined,
|
|
1241
|
+
{
|
|
1242
|
+
style: {
|
|
1243
|
+
marginTop: "4px",
|
|
1244
|
+
color: "#ff4d4f"
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
);
|
|
1248
|
+
if (item.filterDropdown !== false)
|
|
1249
|
+
item.filterDropdown = ({
|
|
1250
|
+
setSelectedKeys,
|
|
1251
|
+
selectedKeys,
|
|
1252
|
+
confirm
|
|
1253
|
+
}) => /* @__PURE__ */ jsxs(
|
|
1254
|
+
Radio.Group,
|
|
1255
|
+
{
|
|
1256
|
+
style: { padding: 8 },
|
|
1257
|
+
buttonStyle: "solid",
|
|
1258
|
+
value: JSON.stringify(selectedKeys[0]),
|
|
1259
|
+
onChange: (e) => {
|
|
1260
|
+
const Values = {
|
|
1261
|
+
true: true,
|
|
1262
|
+
false: false,
|
|
1263
|
+
null: null
|
|
1264
|
+
};
|
|
1265
|
+
setSelectedKeys(
|
|
1266
|
+
e.target.value ? [Values[e.target.value]] : []
|
|
1267
|
+
);
|
|
1268
|
+
confirm();
|
|
1269
|
+
},
|
|
1270
|
+
children: [
|
|
1271
|
+
/* @__PURE__ */ jsx(Radio.Button, { children: common2.all }),
|
|
1272
|
+
/* @__PURE__ */ jsx(Radio.Button, { value: "true", children: /* @__PURE__ */ jsx(
|
|
1273
|
+
CheckOutlined,
|
|
1274
|
+
{
|
|
1275
|
+
style: {
|
|
1276
|
+
color: "#52c41a",
|
|
1277
|
+
verticalAlign: "middle"
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
) }),
|
|
1281
|
+
/* @__PURE__ */ jsx(Radio.Button, { value: "false", children: /* @__PURE__ */ jsx(
|
|
1282
|
+
CloseOutlined,
|
|
1283
|
+
{
|
|
1284
|
+
style: {
|
|
1285
|
+
verticalAlign: "middle",
|
|
1286
|
+
color: "#ff4d4f"
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
) }),
|
|
1290
|
+
/* @__PURE__ */ jsx(Radio.Button, { value: "null", children: common2.blank })
|
|
1291
|
+
]
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
if (!item.onFilter)
|
|
1295
|
+
item.onFilter = (value, row) => {
|
|
1296
|
+
switch (value) {
|
|
1297
|
+
case true:
|
|
1298
|
+
return !isNil(row[item.id]) && row[item.id] !== false;
|
|
1299
|
+
case false:
|
|
1300
|
+
return !isNil(row[item.id]) && !row[item.id];
|
|
1301
|
+
default:
|
|
1302
|
+
return isNil(row[item.id]);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
break;
|
|
1306
|
+
case "date":
|
|
1307
|
+
if (!item.render)
|
|
1308
|
+
item.render = (value) => processValue(item, value);
|
|
1309
|
+
if (!item.sorter)
|
|
1310
|
+
item.sorter = (a, b, order) => {
|
|
1311
|
+
if (isNil(a[item.id]))
|
|
1312
|
+
return order === "ascend" ? 1 : -1;
|
|
1313
|
+
if (isNil(b[item.id]))
|
|
1314
|
+
return order === "ascend" ? -1 : 1;
|
|
1315
|
+
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1316
|
+
};
|
|
1317
|
+
if (!item.filterDropdown)
|
|
1318
|
+
item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ jsx(
|
|
1319
|
+
DatePicker.RangePicker,
|
|
1320
|
+
{
|
|
1321
|
+
onChange: (dates) => {
|
|
1322
|
+
setSelectedKeys(
|
|
1323
|
+
(dates == null ? void 0 : dates[0]) && dates[1] ? [
|
|
1324
|
+
[
|
|
1325
|
+
dates[0].startOf("day").toISOString(),
|
|
1326
|
+
dates[1].endOf("day").toISOString()
|
|
1327
|
+
]
|
|
1328
|
+
] : []
|
|
1329
|
+
);
|
|
1330
|
+
confirm();
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
if (!item.onFilter)
|
|
1335
|
+
item.onFilter = (value, row) => {
|
|
1336
|
+
if (isNil(value[0]))
|
|
1337
|
+
return true;
|
|
1338
|
+
if (isNil(row[item.id]))
|
|
1339
|
+
return false;
|
|
1340
|
+
return dayjs2(row[item.id]) >= dayjs2(value[0]) && dayjs2(row[item.id]) <= dayjs2(value[1]);
|
|
1341
|
+
};
|
|
1342
|
+
break;
|
|
1343
|
+
case "time":
|
|
1344
|
+
if (!item.render)
|
|
1345
|
+
item.render = (value) => processValue(item, value);
|
|
1346
|
+
if (!item.sorter)
|
|
1347
|
+
item.sorter = (a, b, order) => {
|
|
1348
|
+
if (isNil(a[item.id]))
|
|
1349
|
+
return order === "ascend" ? 1 : -1;
|
|
1350
|
+
if (isNil(b[item.id]))
|
|
1351
|
+
return order === "ascend" ? -1 : 1;
|
|
1352
|
+
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1353
|
+
};
|
|
1354
|
+
if (!item.filterDropdown)
|
|
1355
|
+
item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ jsx(
|
|
1356
|
+
DatePicker.RangePicker,
|
|
1357
|
+
{
|
|
1358
|
+
onChange: (dates) => {
|
|
1359
|
+
setSelectedKeys(
|
|
1360
|
+
(dates == null ? void 0 : dates[0]) && dates[1] ? [
|
|
1361
|
+
[
|
|
1362
|
+
dates[0].startOf("day").toISOString(),
|
|
1363
|
+
dates[1].endOf("day").toISOString()
|
|
1364
|
+
]
|
|
1365
|
+
] : []
|
|
1366
|
+
);
|
|
1367
|
+
confirm();
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
);
|
|
1371
|
+
if (!item.onFilter)
|
|
1372
|
+
item.onFilter = (value, row) => {
|
|
1373
|
+
if (isNil(value[0]))
|
|
1374
|
+
return true;
|
|
1375
|
+
if (isNil(row[item.id]))
|
|
1376
|
+
return false;
|
|
1377
|
+
return dayjs2(row[item.id]) >= dayjs2(value[0]) && dayjs2(row[item.id]) <= dayjs2(value[1]);
|
|
1378
|
+
};
|
|
1379
|
+
break;
|
|
1380
|
+
case "object":
|
|
1381
|
+
if (!item.render)
|
|
1382
|
+
item.render = (value) => /* @__PURE__ */ jsx(
|
|
1383
|
+
Description,
|
|
1384
|
+
{
|
|
1385
|
+
items: item.object,
|
|
1386
|
+
dataSource: value || {},
|
|
1387
|
+
column: 1
|
|
1388
|
+
}
|
|
1389
|
+
);
|
|
1390
|
+
break;
|
|
1391
|
+
case "object[]":
|
|
1392
|
+
if (!item.render)
|
|
1393
|
+
item.render = (value) => /* @__PURE__ */ jsx(Fragment, { children: value.map((v, i) => /* @__PURE__ */ jsx(
|
|
1394
|
+
Description,
|
|
1395
|
+
{
|
|
1396
|
+
items: item.object,
|
|
1397
|
+
dataSource: v || [],
|
|
1398
|
+
column: 1
|
|
1399
|
+
},
|
|
1400
|
+
i
|
|
1401
|
+
)) });
|
|
1402
|
+
break;
|
|
1403
|
+
default:
|
|
1404
|
+
if (!item.render)
|
|
1405
|
+
item.render = (value) => processValue(item, value);
|
|
1406
|
+
if (!item.onFilter)
|
|
1407
|
+
item.onFilter = (value, row) => {
|
|
1408
|
+
if (value === null && isNil(row[item.id]))
|
|
1409
|
+
return true;
|
|
1410
|
+
return value === row[item.id];
|
|
1411
|
+
};
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
setColumns(props.items);
|
|
1416
|
+
}, [JSON.stringify(props.items)]);
|
|
1417
|
+
useEffect(() => {
|
|
1418
|
+
if (!props.dataSource || !columns)
|
|
1419
|
+
return;
|
|
1420
|
+
for (const column of columns) {
|
|
1421
|
+
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1422
|
+
const options = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
1423
|
+
label: v[column.id],
|
|
1424
|
+
value: v[column.id]
|
|
1425
|
+
}));
|
|
1426
|
+
if (options.length)
|
|
1427
|
+
setColumns((prev) => {
|
|
1428
|
+
const newColumns = [...prev];
|
|
1429
|
+
const index = newColumns.findIndex((item) => item.id === column.id);
|
|
1430
|
+
newColumns[index].options = options;
|
|
1431
|
+
generateFilterDropdown(newColumns[index]);
|
|
1432
|
+
return newColumns;
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}, [props.dataSource, columns]);
|
|
1437
|
+
if (!columns)
|
|
1438
|
+
return null;
|
|
1439
|
+
if (props.dataSource)
|
|
1440
|
+
return /* @__PURE__ */ jsx(
|
|
1441
|
+
Table$1,
|
|
1442
|
+
{
|
|
1443
|
+
...props,
|
|
1444
|
+
rowKey: props.rowKey || "id",
|
|
1445
|
+
columns,
|
|
1446
|
+
dataSource: props.dataSource
|
|
1447
|
+
}
|
|
1448
|
+
);
|
|
1449
|
+
return /* @__PURE__ */ jsx(FaasDataWrapper, { ...props.faasData, children: /* @__PURE__ */ jsx(FaasDataTable, { props, columns }) });
|
|
1450
|
+
}
|
|
1451
|
+
function FaasDataTable({
|
|
1452
|
+
props,
|
|
1453
|
+
columns,
|
|
1454
|
+
data,
|
|
1455
|
+
params,
|
|
1456
|
+
reload
|
|
1457
|
+
}) {
|
|
1458
|
+
const [currentColumns, setCurrentColumns] = useState(columns);
|
|
1459
|
+
useEffect(() => {
|
|
1460
|
+
if (!data || Array.isArray(data))
|
|
1461
|
+
return;
|
|
1462
|
+
setCurrentColumns((prev) => {
|
|
1463
|
+
var _a;
|
|
1464
|
+
const newColumns = [...prev];
|
|
1465
|
+
for (const column of newColumns) {
|
|
1466
|
+
if ((_a = data.options) == null ? void 0 : _a[column.id]) {
|
|
1467
|
+
column.options = transferOptions(data.options[column.id]);
|
|
1468
|
+
column.filters = column.options.map((v) => ({
|
|
1469
|
+
text: v.label,
|
|
1470
|
+
value: v.value
|
|
1471
|
+
})).concat({
|
|
1472
|
+
text: /* @__PURE__ */ jsx(Blank, {}),
|
|
1473
|
+
value: null
|
|
1474
|
+
});
|
|
1475
|
+
column.render = (value) => processValue(column, value);
|
|
1476
|
+
if (column.filterDropdown)
|
|
1477
|
+
delete column.filterDropdown;
|
|
1478
|
+
continue;
|
|
1479
|
+
}
|
|
1480
|
+
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1481
|
+
const filters = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
1482
|
+
text: v[column.id],
|
|
1483
|
+
value: v[column.id]
|
|
1484
|
+
}));
|
|
1485
|
+
if (filters.length)
|
|
1486
|
+
column.filters = filters.concat({
|
|
1487
|
+
text: /* @__PURE__ */ jsx(Blank, {}),
|
|
1488
|
+
value: null
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return newColumns;
|
|
1493
|
+
});
|
|
1494
|
+
}, [columns, data]);
|
|
1495
|
+
if (!data)
|
|
1496
|
+
return /* @__PURE__ */ jsx(
|
|
1497
|
+
Table$1,
|
|
1498
|
+
{
|
|
1499
|
+
...props,
|
|
1500
|
+
loading: props.loading,
|
|
1501
|
+
rowKey: props.rowKey || "id",
|
|
1502
|
+
columns: currentColumns,
|
|
1503
|
+
dataSource: []
|
|
1504
|
+
}
|
|
1505
|
+
);
|
|
1506
|
+
if (Array.isArray(data))
|
|
1507
|
+
return /* @__PURE__ */ jsx(
|
|
1508
|
+
Table$1,
|
|
1509
|
+
{
|
|
1510
|
+
...props,
|
|
1511
|
+
loading: props.loading,
|
|
1512
|
+
rowKey: props.rowKey || "id",
|
|
1513
|
+
columns: currentColumns,
|
|
1514
|
+
dataSource: data
|
|
1515
|
+
}
|
|
1516
|
+
);
|
|
1517
|
+
return /* @__PURE__ */ jsx(
|
|
1518
|
+
Table$1,
|
|
1519
|
+
{
|
|
1520
|
+
...props,
|
|
1521
|
+
loading: props.loading,
|
|
1522
|
+
rowKey: props.rowKey || "id",
|
|
1523
|
+
columns: currentColumns,
|
|
1524
|
+
dataSource: data.rows,
|
|
1525
|
+
pagination: {
|
|
1526
|
+
...props.pagination,
|
|
1527
|
+
...data.pagination
|
|
1528
|
+
},
|
|
1529
|
+
onChange: (pagination, filters, sorter, extra) => {
|
|
1530
|
+
if (props.onChange) {
|
|
1531
|
+
const processed = props.onChange(pagination, filters, sorter, extra);
|
|
1532
|
+
reload({
|
|
1533
|
+
...params,
|
|
1534
|
+
pagination: processed.pagination,
|
|
1535
|
+
filters: processed.filters,
|
|
1536
|
+
sorter: processed.sorter,
|
|
1537
|
+
extra: processed.extra
|
|
1538
|
+
});
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
reload({
|
|
1542
|
+
...params,
|
|
1543
|
+
pagination,
|
|
1544
|
+
filters,
|
|
1545
|
+
sorter
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
function Tabs(props) {
|
|
1552
|
+
return /* @__PURE__ */ jsx(
|
|
1553
|
+
Tabs$1,
|
|
1554
|
+
{
|
|
1555
|
+
...props,
|
|
1556
|
+
items: props.items.filter(Boolean).map((i) => ({
|
|
1557
|
+
...i,
|
|
1558
|
+
key: i.key || i.id,
|
|
1559
|
+
label: i.label || i.title || i.id
|
|
1560
|
+
}))
|
|
1561
|
+
}
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1564
|
+
function Title(props) {
|
|
1565
|
+
const { Title: Title2 } = useConfigContext();
|
|
1566
|
+
useEffect(() => {
|
|
1567
|
+
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
1568
|
+
document.title = title.concat(props.suffix || Title2.suffix).filter((t) => !!t).join(props.separator || Title2.separator);
|
|
1569
|
+
}, [props]);
|
|
1570
|
+
if (props.h1) {
|
|
1571
|
+
if (typeof props.h1 === "boolean")
|
|
1572
|
+
return /* @__PURE__ */ jsx("h1", { children: Array.isArray(props.title) ? props.title[0] : props.title });
|
|
1573
|
+
return /* @__PURE__ */ jsx("h1", { className: props.h1.className, style: props.h1.style, children: Array.isArray(props.title) ? props.title[0] : props.title });
|
|
1574
|
+
}
|
|
1575
|
+
if (props.plain)
|
|
1576
|
+
return /* @__PURE__ */ jsx(Fragment, { children: Array.isArray(props.title) ? props.title[0] : props.title });
|
|
1577
|
+
if (props.children)
|
|
1578
|
+
return cloneElement(props.children, { title: props.title });
|
|
1579
|
+
return null;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
export { App, Blank, ConfigContext, ConfigProvider2 as ConfigProvider, Description, ErrorBoundary, FaasDataWrapper, Form, FormItem, Link, Loading, PageNotFound, Routes, Table, Tabs, Title, transferOptions, transferValue, useApp, useConfigContext, useDrawer, useModal };
|