zy-react-library 1.0.3 → 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
- /** 值字段的键名,默认为 'value' */
29
+ /** 值字段的键名,默认为 'id' */
36
30
  valueKey?: string;
37
- /** 标签字段的键名,默认为 'label' */
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 || "value",
79
- labelKey: option?.itemsField?.labelKey || "label",
78
+ valueKey: option?.itemsField?.valueKey || "id",
79
+ labelKey: option?.itemsField?.labelKey || "name",
80
80
  };
81
81
  };
82
82
 
@@ -90,7 +90,7 @@ const FormItemsRenderer = ({
90
90
  // 支持动态计算 required
91
91
  const required = typeof option.required === "function"
92
92
  ? option.required(form.getFieldsValue())
93
- : (option.required || true);
93
+ : (option.required ?? true);
94
94
 
95
95
  if (required) {
96
96
  const isBlurTrigger = !option.render || [
@@ -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] ?? item.dictionariesId ?? item.id;
148
- const label = item[itemsFieldKey.labelKey] ?? item.name;
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] ?? item.dictionariesId ?? item.id;
163
- const label = item[itemsFieldKey.labelKey] ?? item.name;
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] ?? item.dictionariesId ?? item.id;
178
- const label = item[itemsFieldKey.labelKey] ?? item.name;
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}
@@ -274,7 +274,7 @@ const FormItemsRenderer = ({
274
274
  }
275
275
 
276
276
  // 如果配置了 shouldUpdate 或 dependencies,使用 Form.Item 的联动机制
277
- if (option.shouldUpdate || option.dependencies || option?.componentProps?.shouldUpdate || option?.componentProps?.dependencies) {
277
+ if ((option.shouldUpdate ?? option.dependencies) || (option?.componentProps?.shouldUpdate ?? option?.componentProps?.dependencies)) {
278
278
  return (
279
279
  option.customizeRender
280
280
  ? (renderFormControl(option))
@@ -282,14 +282,14 @@ const FormItemsRenderer = ({
282
282
  <Col key={option.name || index} span={itemSpan} style={style}>
283
283
  <Form.Item
284
284
  noStyle
285
- shouldUpdate={option.shouldUpdate || option?.componentProps?.shouldUpdate}
285
+ shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
286
286
  dependencies={option.dependencies || option?.componentProps?.dependencies}
287
287
  >
288
288
  {(form) => {
289
289
  // 支持动态计算 hidden
290
290
  const hidden = typeof option.hidden === "function"
291
291
  ? option.hidden(form.getFieldsValue())
292
- : (option.hidden || false);
292
+ : (option.hidden ?? false);
293
293
 
294
294
  if (hidden)
295
295
  return null;
@@ -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
- url,
10
- options = { name: "", type: "", params: {} },
11
- ) {
12
- const fileUrl = getFileUrl();
13
- return new Promise((resolve, reject) => {
14
- const finalUrl = !url.includes(fileUrl) ? fileUrl + url : url;
15
- Object.entries(options.params).forEach(([key, value]) => {
16
- finalUrl.searchParams.append(key, value);
17
- });
18
- fetch(finalUrl, {
19
- method: "GET",
20
- mode: "cors",
21
- headers: {
22
- "Content-Type": "application/json",
23
- },
24
- })
25
- .then((response) => {
26
- if (!response.ok) {
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
- .then((blob) => {
32
- const finalBlob = new Blob([blob], {
33
- type: options.type || "application/vnd.ms-excel",
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
- const downloadElement = document.createElement("a");
36
- const href = window.URL.createObjectURL(finalBlob);
37
- downloadElement.style.display = "none";
38
- downloadElement.href = href;
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",