zy-react-library 1.0.4 → 1.0.6

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.
@@ -38,6 +38,7 @@ const FormBuilder = (props) => {
38
38
  onFinish={onFinish}
39
39
  initialValues={values}
40
40
  form={form}
41
+ style={{ width: `calc(100% - ${gutter * 2}px)`, margin: `0 auto` }}
41
42
  {...restProps}
42
43
  >
43
44
  <Row gutter={gutter}>
@@ -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
 
@@ -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}
@@ -6,6 +6,7 @@ function TablePro(props) {
6
6
  columns = [],
7
7
  showIndex = true,
8
8
  useAlignCenter = true,
9
+ rowKey = 'id',
9
10
  ...restProps
10
11
  } = props;
11
12
  const storeIndex = props.storeIndex || `${window.process.env.app.antd["ant-prefix"]}_${Math.random().toString(36).substring(2)}`;
@@ -13,7 +14,7 @@ function TablePro(props) {
13
14
  showIndex && columns.unshift(getIndexColumn(props.pagination));
14
15
  return columns.map(item => ({ align: useAlignCenter ? "center" : "left", ...item }));
15
16
  }
16
- return <Table storeIndex={storeIndex} columns={calcColumns()} {...restProps} />;
17
+ return <Table rowKey={rowKey} storeIndex={storeIndex} columns={calcColumns()} {...restProps} />;
17
18
  }
18
19
 
19
20
  export default TablePro;
@@ -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.4",
4
+ "version": "1.0.6",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",
@@ -24,6 +24,7 @@
24
24
  "@ant-design/icons": "^6.1.0",
25
25
  "@ant-design/pro-components": "^2.8.10",
26
26
  "@cqsjjb/jjb-common-lib": "latest",
27
+ "@cqsjjb/jjb-react-admin-component": "latest",
27
28
  "ahooks": "^3.9.5",
28
29
  "antd": "^5.27.6",
29
30
  "dayjs": "^1.11.18",