zy-react-library 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,12 +15,6 @@ export type FormItemRenderType
|
|
|
15
15
|
* 选项项数据类型
|
|
16
16
|
*/
|
|
17
17
|
export interface OptionItem {
|
|
18
|
-
/** 值字段 */
|
|
19
|
-
value?: any;
|
|
20
|
-
/** 标签字段 */
|
|
21
|
-
label?: string;
|
|
22
|
-
/** 字典ID */
|
|
23
|
-
dictionariesId?: any;
|
|
24
18
|
/** ID字段 */
|
|
25
19
|
id?: any;
|
|
26
20
|
/** 名称字段 */
|
|
@@ -32,9 +26,9 @@ export interface OptionItem {
|
|
|
32
26
|
* 字段键配置
|
|
33
27
|
*/
|
|
34
28
|
export interface itemsFieldConfig {
|
|
35
|
-
/** 值字段的键名,默认为 '
|
|
29
|
+
/** 值字段的键名,默认为 'id' */
|
|
36
30
|
valueKey?: string;
|
|
37
|
-
/** 标签字段的键名,默认为 '
|
|
31
|
+
/** 标签字段的键名,默认为 'name' */
|
|
38
32
|
labelKey?: string;
|
|
39
33
|
}
|
|
40
34
|
|
|
@@ -75,8 +75,8 @@ const FormItemsRenderer = ({
|
|
|
75
75
|
// 获取items里的value和label字段key
|
|
76
76
|
const getItemsFieldKey = (option) => {
|
|
77
77
|
return {
|
|
78
|
-
valueKey: option?.itemsField?.valueKey || "
|
|
79
|
-
labelKey: option?.itemsField?.labelKey || "
|
|
78
|
+
valueKey: option?.itemsField?.valueKey || "id",
|
|
79
|
+
labelKey: option?.itemsField?.labelKey || "name",
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
82
|
|
|
@@ -144,8 +144,8 @@ const FormItemsRenderer = ({
|
|
|
144
144
|
return (
|
|
145
145
|
<Select placeholder={placeholder} {...componentProps}>
|
|
146
146
|
{(option.items || []).map((item) => {
|
|
147
|
-
const value = item[itemsFieldKey.valueKey]
|
|
148
|
-
const label = item[itemsFieldKey.labelKey]
|
|
147
|
+
const value = item[itemsFieldKey.valueKey];
|
|
148
|
+
const label = item[itemsFieldKey.labelKey];
|
|
149
149
|
return (
|
|
150
150
|
<Select.Option key={value} value={value}>
|
|
151
151
|
{label}
|
|
@@ -159,8 +159,8 @@ const FormItemsRenderer = ({
|
|
|
159
159
|
return (
|
|
160
160
|
<Radio.Group {...componentProps}>
|
|
161
161
|
{(option.items || []).map((item) => {
|
|
162
|
-
const value = item[itemsFieldKey.valueKey]
|
|
163
|
-
const label = item[itemsFieldKey.labelKey]
|
|
162
|
+
const value = item[itemsFieldKey.valueKey];
|
|
163
|
+
const label = item[itemsFieldKey.labelKey];
|
|
164
164
|
return (
|
|
165
165
|
<Radio key={value} value={value}>
|
|
166
166
|
{label}
|
|
@@ -174,8 +174,8 @@ const FormItemsRenderer = ({
|
|
|
174
174
|
return (
|
|
175
175
|
<Checkbox.Group {...componentProps}>
|
|
176
176
|
{(option.items || []).map((item) => {
|
|
177
|
-
const value = item[itemsFieldKey.valueKey]
|
|
178
|
-
const label = item[itemsFieldKey.labelKey]
|
|
177
|
+
const value = item[itemsFieldKey.valueKey];
|
|
178
|
+
const label = item[itemsFieldKey.labelKey];
|
|
179
179
|
return (
|
|
180
180
|
<Checkbox key={value} value={value}>
|
|
181
181
|
{label}
|
|
@@ -7,10 +7,14 @@ interface UseDownloadBlobOptions {
|
|
|
7
7
|
params?: Record<string, any>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export interface downloadBlobOptions {
|
|
11
|
+
url: string;
|
|
12
|
+
options?: UseDownloadBlobOptions;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type DeleteFileFunction = (options: downloadBlobOptions) => Promise<any>;
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
18
|
* 下载Blob流文件
|
|
12
19
|
*/
|
|
13
|
-
export default function useDownloadBlob(
|
|
14
|
-
url: string,
|
|
15
|
-
options?: UseDownloadBlobOptions
|
|
16
|
-
): Promise<any>;
|
|
20
|
+
export default function useDownloadBlob(): [boolean, DeleteFileFunction];
|
|
@@ -1,52 +1,62 @@
|
|
|
1
1
|
import { message } from "antd";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { getFileUrl } from "../../utils/index.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 下载Blob流文件
|
|
7
8
|
*/
|
|
8
|
-
export default function useDownloadBlob(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
throw new Error("Network response was not ok");
|
|
28
|
-
}
|
|
29
|
-
return response.blob();
|
|
9
|
+
export default function useDownloadBlob() {
|
|
10
|
+
// loading状态
|
|
11
|
+
const [loading, setLoading] = useState(false);
|
|
12
|
+
|
|
13
|
+
// 下载Blob流文件
|
|
14
|
+
const downloadBlob = (url, options = { name: "", type: "", params: {} }) => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
const fileUrl = getFileUrl();
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const finalUrl = !url.includes(fileUrl) ? fileUrl + url : url;
|
|
19
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
20
|
+
finalUrl.searchParams.append(key, value);
|
|
21
|
+
});
|
|
22
|
+
fetch(finalUrl, {
|
|
23
|
+
method: "GET",
|
|
24
|
+
mode: "cors",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
},
|
|
30
28
|
})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
.then((response) => {
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new Error("Network response was not ok");
|
|
32
|
+
}
|
|
33
|
+
return response.blob();
|
|
34
|
+
})
|
|
35
|
+
.then((blob) => {
|
|
36
|
+
const finalBlob = new Blob([blob], {
|
|
37
|
+
type: options.type || "application/vnd.ms-excel",
|
|
38
|
+
});
|
|
39
|
+
const downloadElement = document.createElement("a");
|
|
40
|
+
const href = window.URL.createObjectURL(finalBlob);
|
|
41
|
+
downloadElement.style.display = "none";
|
|
42
|
+
downloadElement.href = href;
|
|
43
|
+
downloadElement.download
|
|
44
|
+
= options.name || dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
45
|
+
document.body.appendChild(downloadElement);
|
|
46
|
+
downloadElement.click();
|
|
47
|
+
document.body.removeChild(downloadElement);
|
|
48
|
+
window.URL.revokeObjectURL(href);
|
|
49
|
+
resolve({ data: finalBlob });
|
|
50
|
+
})
|
|
51
|
+
.catch((err) => {
|
|
52
|
+
message.error("导出失败");
|
|
53
|
+
reject(err);
|
|
54
|
+
})
|
|
55
|
+
.finally(() => {
|
|
56
|
+
setLoading(false);
|
|
34
57
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
downloadElement.download
|
|
40
|
-
= options.name || dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
41
|
-
document.body.appendChild(downloadElement);
|
|
42
|
-
downloadElement.click();
|
|
43
|
-
document.body.removeChild(downloadElement);
|
|
44
|
-
window.URL.revokeObjectURL(href);
|
|
45
|
-
resolve({ data: finalBlob });
|
|
46
|
-
})
|
|
47
|
-
.catch((err) => {
|
|
48
|
-
message.error("导出失败");
|
|
49
|
-
reject(err);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return [loading, downloadBlob];
|
|
52
62
|
}
|