zy-react-library 1.0.30 → 1.0.32
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DownOutlined, UpOutlined } from "@ant-design/icons";
|
|
1
|
+
import { DownOutlined, SearchOutlined, UndoOutlined, UpOutlined } from "@ant-design/icons";
|
|
2
2
|
import { Button, Col, Form, Row } from "antd";
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import FormItemsRenderer from "../FormBuilder/FormItemsRenderer";
|
|
@@ -87,14 +87,14 @@ const Search = (props) => {
|
|
|
87
87
|
initialValues={values}
|
|
88
88
|
/>
|
|
89
89
|
<Col span={showCollapseButton ? (collapse ? 6 : span) : span}>
|
|
90
|
-
<Form.Item label=" " colon={false} style={{ textAlign: "right" }}>
|
|
90
|
+
<Form.Item label=" " labelCol={{ span: 2 }} colon={false} style={{ textAlign: "right" }}>
|
|
91
91
|
{showSearchButton && (
|
|
92
|
-
<Button type="primary" onClick={handleSubmit}>
|
|
92
|
+
<Button type="primary" icon={<SearchOutlined />} onClick={handleSubmit}>
|
|
93
93
|
{searchText}
|
|
94
94
|
</Button>
|
|
95
95
|
)}
|
|
96
96
|
{showResetButton && (
|
|
97
|
-
<Button style={{ marginLeft: 8 }} onClick={handleReset}>
|
|
97
|
+
<Button style={{ marginLeft: 8 }} icon={<UndoOutlined />} onClick={handleReset}>
|
|
98
98
|
{resetText}
|
|
99
99
|
</Button>
|
|
100
100
|
)}
|
|
@@ -14,6 +14,9 @@ export default function useDownloadBlob(returnType = "object") {
|
|
|
14
14
|
setLoading(true);
|
|
15
15
|
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
+
if (!url)
|
|
18
|
+
return reject(new Error("请传入 url"));
|
|
19
|
+
|
|
17
20
|
const { name = "", type = "", params = {} } = options;
|
|
18
21
|
const finalUrl = (process.env.app.API_HOST || window.__JJB_ENVIRONMENT__.API_HOST) + url;
|
|
19
22
|
Object.entries(params).forEach(([key, value]) => {
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
export interface DownloadFileOptions {
|
|
2
|
+
/** 下载文件的URL */
|
|
3
|
+
url: string;
|
|
4
|
+
/** 下载文件的自定义文件名 */
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type DownloadFileFunction = (options: DownloadFileOptions) => void;
|
|
9
|
+
|
|
1
10
|
/**
|
|
2
11
|
* 下载文件
|
|
3
12
|
*/
|
|
4
|
-
export default function useDownloadFile(
|
|
13
|
+
export default function useDownloadFile(returnType: "array"): [boolean, DownloadFileFunction];
|
|
14
|
+
export default function useDownloadFile(returnType?: "object"): { loading: boolean; downloadFile: DownloadFileFunction };
|
|
@@ -1,36 +1,62 @@
|
|
|
1
1
|
import { message, Modal } from "antd";
|
|
2
|
-
import {
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { getFileName, getFileSuffix, getFileUrl } from "../../utils";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 下载文件
|
|
6
7
|
*/
|
|
7
|
-
export default function useDownloadFile(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
export default function useDownloadFile(returnType = "object") {
|
|
9
|
+
// loading状态
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
|
|
12
|
+
// 下载文件
|
|
13
|
+
const downloadFile = (options) => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
|
|
16
|
+
const { url, name: fileName } = options;
|
|
17
|
+
if (!url)
|
|
18
|
+
throw new Error("请传入 url");
|
|
19
|
+
|
|
20
|
+
Modal.confirm({
|
|
21
|
+
title: "提示",
|
|
22
|
+
content: "确定要下载此文件吗?",
|
|
23
|
+
onOk: () => {
|
|
24
|
+
const fileUrl = getFileUrl();
|
|
25
|
+
let name = fileName;
|
|
26
|
+
|
|
27
|
+
if (name) {
|
|
28
|
+
if (!getFileSuffix(name) && getFileSuffix(url)) {
|
|
29
|
+
name = `${name}.${getFileSuffix(url)}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
name = getFileName(url);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fetch(!url.includes(fileUrl) ? fileUrl + url : url)
|
|
37
|
+
.then(res => res.blob())
|
|
38
|
+
.then((blob) => {
|
|
39
|
+
const a = document.createElement("a");
|
|
40
|
+
document.body.appendChild(a);
|
|
41
|
+
a.style.display = "none";
|
|
42
|
+
const urlObject = window.URL.createObjectURL(blob);
|
|
43
|
+
a.href = urlObject;
|
|
44
|
+
a.download = `${name}`;
|
|
45
|
+
a.click();
|
|
46
|
+
document.body.removeChild(a);
|
|
47
|
+
window.URL.revokeObjectURL(urlObject);
|
|
48
|
+
})
|
|
49
|
+
.catch(() => {
|
|
50
|
+
message.error("下载失败");
|
|
51
|
+
})
|
|
52
|
+
.finally(() => {
|
|
53
|
+
setLoading(false);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (returnType === "array")
|
|
60
|
+
return [loading, downloadFile];
|
|
61
|
+
return { loading, downloadFile };
|
|
36
62
|
}
|
|
@@ -13,6 +13,9 @@ export default function useImportFile(returnType = "object") {
|
|
|
13
13
|
setLoading(true);
|
|
14
14
|
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
16
|
+
if (!url)
|
|
17
|
+
return reject(new Error("请传入 url"));
|
|
18
|
+
|
|
16
19
|
const { files = [], params = {} } = options;
|
|
17
20
|
const formData = new FormData();
|
|
18
21
|
|
package/hooks/useTable/index.js
CHANGED
|
@@ -101,6 +101,9 @@ function getQuery(keysStr, valuesStr) {
|
|
|
101
101
|
* 自定义 useTable,继承 ahooks 的 useAntdTable,根据需求进行扩展
|
|
102
102
|
*/
|
|
103
103
|
function useTable(service, options) {
|
|
104
|
+
if (!service)
|
|
105
|
+
throw new Error("请传入 service");
|
|
106
|
+
|
|
104
107
|
// 获取额外参数和转换函数
|
|
105
108
|
const { params: extraParams, transform, ...restOptions } = options || {};
|
|
106
109
|
|