zy-react-library 1.0.27 → 1.0.29
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.
|
@@ -21,13 +21,13 @@ const { RangePicker } = DatePicker;
|
|
|
21
21
|
* 表单项渲染器组件
|
|
22
22
|
*/
|
|
23
23
|
const FormItemsRenderer = ({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}) => {
|
|
24
|
+
options,
|
|
25
|
+
labelCol,
|
|
26
|
+
span = 12,
|
|
27
|
+
collapse = false,
|
|
28
|
+
useAutoGenerateRequired = true,
|
|
29
|
+
initialValues,
|
|
30
|
+
}) => {
|
|
31
31
|
const form = Form.useFormInstance();
|
|
32
32
|
|
|
33
33
|
// 获取表单值,优先使用 initialValues
|
|
@@ -297,40 +297,39 @@ const FormItemsRenderer = ({
|
|
|
297
297
|
return (
|
|
298
298
|
option.customizeRender
|
|
299
299
|
? (renderFormControl(option))
|
|
300
|
-
: (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
})()
|
|
300
|
+
: (
|
|
301
|
+
<Form.Item
|
|
302
|
+
key={option.name || index}
|
|
303
|
+
noStyle
|
|
304
|
+
shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
|
|
305
|
+
dependencies={option.dependencies || option?.componentProps?.dependencies}
|
|
306
|
+
>
|
|
307
|
+
{() => {
|
|
308
|
+
// 支持动态计算 hidden
|
|
309
|
+
const hidden = typeof option.hidden === "function"
|
|
310
|
+
? option.hidden(getFormValues())
|
|
311
|
+
: (option.hidden ?? false);
|
|
312
|
+
|
|
313
|
+
if (hidden)
|
|
314
|
+
return null;
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<Col key={option.name || index} span={itemSpan} style={style}>
|
|
318
|
+
<Form.Item
|
|
319
|
+
name={option.name}
|
|
320
|
+
label={renderLabel(option)}
|
|
321
|
+
rules={getRules(option)}
|
|
322
|
+
labelCol={itemLabelCol}
|
|
323
|
+
wrapperCol={itemWrapperCol}
|
|
324
|
+
{...getFormItemProps(option)}
|
|
325
|
+
>
|
|
326
|
+
{renderFormControl(option)}
|
|
327
|
+
</Form.Item>
|
|
328
|
+
</Col>
|
|
329
|
+
);
|
|
330
|
+
}}
|
|
331
|
+
</Form.Item>
|
|
332
|
+
)
|
|
334
333
|
);
|
|
335
334
|
}
|
|
336
335
|
|
|
@@ -349,17 +348,17 @@ const FormItemsRenderer = ({
|
|
|
349
348
|
option.customizeRender
|
|
350
349
|
? (renderFormControl(option))
|
|
351
350
|
: (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
351
|
+
<Form.Item
|
|
352
|
+
name={option.name}
|
|
353
|
+
label={renderLabel(option)}
|
|
354
|
+
rules={getRules(option)}
|
|
355
|
+
labelCol={itemLabelCol}
|
|
356
|
+
wrapperCol={itemWrapperCol}
|
|
357
|
+
{...getFormItemProps(option)}
|
|
358
|
+
>
|
|
359
|
+
{renderFormControl(option)}
|
|
360
|
+
</Form.Item>
|
|
361
|
+
)
|
|
363
362
|
}
|
|
364
363
|
</Col>
|
|
365
364
|
);
|
|
@@ -10,11 +10,13 @@ export default function useDownloadBlob() {
|
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
11
|
|
|
12
12
|
// 下载Blob流文件
|
|
13
|
-
const downloadBlob = (url, options
|
|
13
|
+
const downloadBlob = (url, options) => {
|
|
14
14
|
setLoading(true);
|
|
15
|
+
|
|
15
16
|
return new Promise((resolve, reject) => {
|
|
17
|
+
const { name= "", type= "", params= {} } = options
|
|
16
18
|
const finalUrl = (process.env.app.API_HOST || window.__JJB_ENVIRONMENT__.API_HOST) + url;
|
|
17
|
-
Object.entries(
|
|
19
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
18
20
|
finalUrl.searchParams.append(key, value);
|
|
19
21
|
});
|
|
20
22
|
fetch(finalUrl, {
|
|
@@ -32,14 +34,14 @@ export default function useDownloadBlob() {
|
|
|
32
34
|
})
|
|
33
35
|
.then((blob) => {
|
|
34
36
|
const finalBlob = new Blob([blob], {
|
|
35
|
-
type:
|
|
37
|
+
type: type || "application/vnd.ms-excel",
|
|
36
38
|
});
|
|
37
39
|
const downloadElement = document.createElement("a");
|
|
38
40
|
const href = window.URL.createObjectURL(finalBlob);
|
|
39
41
|
downloadElement.style.display = "none";
|
|
40
42
|
downloadElement.href = href;
|
|
41
43
|
downloadElement.download
|
|
42
|
-
=
|
|
44
|
+
= name || dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
43
45
|
document.body.appendChild(downloadElement);
|
|
44
46
|
downloadElement.click();
|
|
45
47
|
document.body.removeChild(downloadElement);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface UploadFile {
|
|
2
|
+
/** 原始文件对象 */
|
|
3
|
+
originFileObj?: File;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface UseImportFileOptions {
|
|
8
|
+
/** 要上传的文件数组 */
|
|
9
|
+
files: UploadFile[];
|
|
10
|
+
/** 额外携带的参数对象 */
|
|
11
|
+
params?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ImportFileOptions {
|
|
15
|
+
url: string;
|
|
16
|
+
options: UseImportFileOptions;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ImportFileFunction = (url: string, options: UseImportFileOptions) => Promise<any>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 导入文件
|
|
23
|
+
*/
|
|
24
|
+
export default function useImportFile(): [boolean, ImportFileFunction];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {request} from "@cqsjjb/jjb-common-lib/http";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 导入文件
|
|
6
|
+
*/
|
|
7
|
+
export default function useImportFile() {
|
|
8
|
+
// loading状态
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
|
|
11
|
+
// 导入文件
|
|
12
|
+
const importFile = (url, options) => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const { files = [], params = {} } = options
|
|
17
|
+
const formData = new FormData();
|
|
18
|
+
|
|
19
|
+
// 将文件添加到formData中
|
|
20
|
+
files.forEach((f) => {
|
|
21
|
+
f.originFileObj && formData.append("file", f.originFileObj);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// 将额外携带的参数添加到formData中
|
|
25
|
+
Object.keys(params).forEach((key) => {
|
|
26
|
+
formData.append(key, params[key]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 发送请求
|
|
30
|
+
request(url, "post", formData, { "Content-Type": "multipart/form-data" })
|
|
31
|
+
.then((res) => {
|
|
32
|
+
resolve(res);
|
|
33
|
+
})
|
|
34
|
+
.catch((err) => {
|
|
35
|
+
reject(err);
|
|
36
|
+
})
|
|
37
|
+
.finally(() => {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return [loading, importFile];
|
|
44
|
+
}
|