zy-react-library 1.0.175 → 1.0.176

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.
@@ -18,8 +18,10 @@ function DictionaryCascader(props) {
18
18
  const [treeData, setTreeData] = useState([]);
19
19
 
20
20
  const getData = async () => {
21
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
- throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
22
+ console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+ return;
24
+ }
23
25
 
24
26
  setTreeData([]);
25
27
  const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
@@ -32,6 +32,22 @@ export interface itemsFieldConfig {
32
32
  */
33
33
  export type FormValues = Record<string, any>;
34
34
 
35
+ /**
36
+ * Form.List 操作项
37
+ */
38
+ export interface FormListOperations {
39
+ /** 当前表单项的数据字段信息 */
40
+ field: FormListFieldData;
41
+ /** 当前项在列表中的索引位置 */
42
+ index: number;
43
+ /** 新增方法 */
44
+ add: (defaultValue?: FormValues, insertIndex?: number) => void;
45
+ /** 删除方法 */
46
+ remove: (index: number | number[]) => void;
47
+ /** 移动方法 */
48
+ move: (from: number, to: number) => void;
49
+ }
50
+
35
51
  /**
36
52
  * Form.List 独有的属性
37
53
  */
@@ -45,7 +61,7 @@ export interface FormListUniqueProps {
45
61
  /** 删除按钮的文本,默认 '删除' */
46
62
  removeButtonText?: string;
47
63
  /** 表单配置项 */
48
- options: (field: FormListFieldData, index: number) => FormOption[];
64
+ options: (operations: FormListOperations) => FormOption[];
49
65
  /** 点击新增按钮时的默认值 */
50
66
  addDefaultValue?: FormValues;
51
67
  /** 点击新增按钮时插入的索引位置 */
@@ -223,9 +223,9 @@ const FormItemsRenderer = ({
223
223
  };
224
224
 
225
225
  // 获取 listOptions
226
- const getListOptions = (listOptions, field, fieldIndex) => {
226
+ const getListOptions = (listOptions, field, fieldIndex, add, remove, move) => {
227
227
  return typeof listOptions === "function"
228
- ? listOptions(field, fieldIndex)
228
+ ? listOptions(field, fieldIndex, add, remove, move)
229
229
  : (listOptions ?? []);
230
230
  };
231
231
 
@@ -453,10 +453,10 @@ const FormItemsRenderer = ({
453
453
  return (
454
454
  <Col key={getKey(option) || index} span={col.span} style={style}>
455
455
  <Form.List name={option.name} {...componentProps}>
456
- {(fields, { add, remove }) => (
456
+ {(fields, { add, remove, move }) => (
457
457
  <>
458
458
  {fields.map((field, fieldIndex) => {
459
- const listOptions = getListOptions(option.formListUniqueProps.options, field, fieldIndex);
459
+ const listOptions = getListOptions(option.formListUniqueProps.options, field, fieldIndex, add, remove, move);
460
460
  return (
461
461
  <Row gutter={gutter} key={field.key}>
462
462
  {listOptions.map((listOption, listIndex) => {
@@ -64,17 +64,21 @@ function HiddenInfo(props) {
64
64
 
65
65
  if (info.hiddenRectifyUserCO && info.hiddenRectifyUserCO.length > 0) {
66
66
  for (let i = 0; i < info.hiddenRectifyUserCO.length; i++) {
67
- const afterRectificationImageFiles = await getFile({
68
- eqType: UPLOAD_FILE_TYPE_ENUM["4"],
69
- eqForeignKey: info.hiddenRectifyUserCO[i].hiddenUserId,
70
- });
71
- setAfterRectificationImageFiles(prevState => [...prevState, afterRectificationImageFiles]);
72
- if (info.hiddenRectifyUserCO[i].isRectificationScheme === 1 && info.hiddenRectifyUserCO[i].hiddenSchemeCO && Object.keys(info.hiddenRectifyUserCO[i].hiddenSchemeCO).length > 0) {
73
- const rectificationPlanImageFiles = await getFile({
74
- eqType: UPLOAD_FILE_TYPE_ENUM["8"],
75
- eqForeignKey: info.hiddenRectifyUserCO[i].hiddenSchemeCO.hiddenSchemeId,
67
+ if (info.hiddenRectifyUserCO[i].hiddenUserId) {
68
+ const afterRectificationImageFiles = await getFile({
69
+ eqType: UPLOAD_FILE_TYPE_ENUM["4"],
70
+ eqForeignKey: info.hiddenRectifyUserCO[i].hiddenUserId,
76
71
  });
77
- setRectificationPlanImageFiles(prevState => [...prevState, rectificationPlanImageFiles]);
72
+ setAfterRectificationImageFiles(prevState => [...prevState, afterRectificationImageFiles]);
73
+ }
74
+ if (info.hiddenRectifyUserCO[i].isRectificationScheme === 1 && info.hiddenRectifyUserCO[i].hiddenSchemeCO && Object.keys(info.hiddenRectifyUserCO[i].hiddenSchemeCO).length > 0) {
75
+ if (info.hiddenRectifyUserCO[i].hiddenSchemeCO.hiddenSchemeId) {
76
+ const rectificationPlanImageFiles = await getFile({
77
+ eqType: UPLOAD_FILE_TYPE_ENUM["8"],
78
+ eqForeignKey: info.hiddenRectifyUserCO[i].hiddenSchemeCO.hiddenSchemeId,
79
+ });
80
+ setRectificationPlanImageFiles(prevState => [...prevState, rectificationPlanImageFiles]);
81
+ }
78
82
  }
79
83
  }
80
84
  }
@@ -126,7 +130,7 @@ function HiddenInfo(props) {
126
130
  { label: "隐患级别", children: info.hiddenLevelName },
127
131
  { label: "隐患状态", children: getLabelName({ list: HIDDEN_STATE_ENUM, status: info.state }) },
128
132
  { label: "隐患描述", children: info.hiddenDesc },
129
- { label: "隐患部位", children: info.hiddenPartName },
133
+ ...(info.hiddenPartName ? [{ label: "隐患部位", children: info.hiddenPartName }] : []),
130
134
  ...(
131
135
  (info.source === 2 || info.source === 3) && (info.hiddenCheckListCO && Object.keys(info.hiddenCheckListCO).length > 0)
132
136
  ? [
@@ -139,11 +143,11 @@ function HiddenInfo(props) {
139
143
  ]
140
144
  : []
141
145
  ),
142
- {
146
+ ...(info.longitude ? [{
143
147
  label: "隐患上报位置(经纬度)",
144
148
  children: [info.longitude && `经度:${info.longitude}`, info.latitude && `纬度:${info.latitude}`].filter(Boolean).join(" "),
145
- },
146
- { label: "隐患位置描述", children: info.positionDesc },
149
+ }] : []),
150
+ ...(info.positionDesc ? [{ label: "隐患位置描述", children: info.positionDesc }] : []),
147
151
  { label: "隐患发现人", children: info.creatorName },
148
152
  { label: "隐患发现时间", children: dayjs(info.hiddenFindTime).format("YYYY-MM-DD HH:mm:ss") },
149
153
  {
@@ -213,18 +217,18 @@ function HiddenInfo(props) {
213
217
  column={1}
214
218
  styles={{ label: { width: 200 } }}
215
219
  items={[
216
- { label: "隐患级别", children: item.hiddenLevelName },
217
- { label: "隐患确认人", children: item.userName },
218
- { label: "隐患确认时间", children: item.rectificationTime },
219
- { label: "整改负责人部门", children: item.rectifyDeptName },
220
- { label: "整改负责人", children: item.rectifyUserName },
221
- { label: "整改完成期限", children: item.rectificationDeadline },
222
- { label: "验收部门", children: item.checkDeptName },
223
- { label: "验收人", children: item.checkUserName },
220
+ ...(item.hiddenLevelName ? [{ label: "隐患级别", children: item.hiddenLevelName }] : []),
221
+ ...(item.userName ? [{ label: "隐患确认人", children: item.userName }] : []),
222
+ ...(item.rectificationTime ? [{ label: "隐患确认时间", children: item.rectificationTime }] : []),
223
+ ...(item.rectifyDeptName ? [{ label: "整改负责人部门", children: item.rectifyDeptName }] : []),
224
+ ...(item.rectifyUserName ? [{ label: "整改负责人", children: item.rectifyUserName }] : []),
225
+ ...(item.rectificationDeadline ? [{ label: "整改完成期限", children: item.rectificationDeadline }] : []),
226
+ ...(item.checkDeptName ? [{ label: "验收部门", children: item.checkDeptName }] : []),
227
+ ...(item.checkUserName ? [{ label: "验收人", children: item.checkUserName }] : []),
224
228
  ...(item.repulseCause
225
229
  ? [
226
- { label: "打回意见", children: item.repulseCause },
227
- { label: "打回时间", children: item.rectificationTime },
230
+ ...(item.repulseCause ? [{ label: "打回意见", children: item.repulseCause }] : []),
231
+ ...(item.rectificationTime ? [{ label: "打回时间", children: item.rectificationTime }] : []),
228
232
  ]
229
233
  : []),
230
234
  ]}
@@ -246,13 +250,13 @@ function HiddenInfo(props) {
246
250
  column={1}
247
251
  styles={{ label: { width: 200 } }}
248
252
  items={[
249
- { label: "申请延期日期", children: item.createTime },
250
- { label: "延期日期", children: item.delayTime },
251
- { label: "审核人", children: item.updateName },
253
+ ...(item.createTime ? [{ label: "申请延期日期", children: item.createTime }] : []),
254
+ ...(item.delayTime ? [{ label: "延期日期", children: item.delayTime }] : []),
255
+ ...(item.updateName ? [{ label: "审核人", children: item.updateName }] : []),
252
256
  ...(item.state === 3
253
257
  ? [
254
- { label: "处置方案", children: item.disposalPlan },
255
- {
258
+ ...(item.disposalPlan ? [{ label: "处置方案", children: item.disposalPlan }] : []),
259
+ ...(item.disposalFile ? [{
256
260
  label: "处置方案附件",
257
261
  children: (
258
262
  getFileSuffix(item.disposalFile) === "pdf"
@@ -265,12 +269,12 @@ function HiddenInfo(props) {
265
269
  size="small"
266
270
  onClick={() => downloadFile(item.disposalFile)}
267
271
  >
268
- 预览
272
+ 下载
269
273
  </Button>
270
274
  </Space>
271
275
  )
272
276
  ),
273
- },
277
+ }] : []),
274
278
  ]
275
279
  : []),
276
280
  {
@@ -313,15 +317,15 @@ function HiddenInfo(props) {
313
317
  items={[
314
318
  ...((item.state === 3 || item.state === 4)
315
319
  ? [
316
- { label: "审核人", children: item.updateName },
317
- { label: "审核时间", children: item.updateTime },
320
+ ...(item.updateName ? [{ label: "审核人", children: item.updateName }] : []),
321
+ ...(item.updateTime ? [{ label: "审核时间", children: item.updateTime }] : []),
318
322
  ]
319
323
  : []),
320
324
  { label: "无法整改原因", children: item.examine },
321
325
  ...(item.state === 3
322
326
  ? [
323
- { label: "处置方案", children: item.disposalPlan },
324
- {
327
+ ...(item.disposalPlan ? [{ label: "处置方案", children: item.disposalPlan }] : []),
328
+ ...(item.disposalFile ? [{
325
329
  label: "处置方案附件",
326
330
  children: (
327
331
  getFileSuffix(item.disposalFile) === "pdf"
@@ -334,12 +338,12 @@ function HiddenInfo(props) {
334
338
  size="small"
335
339
  onClick={() => downloadFile(item.disposalFile)}
336
340
  >
337
- 预览
341
+ 下载
338
342
  </Button>
339
343
  </Space>
340
344
  )
341
345
  ),
342
- },
346
+ }] : []),
343
347
  {
344
348
  label: "是否更换整改负责人",
345
349
  children: item.rectifyUserCO && Object.keys(item.rectifyUserCO).length > 0 ? "是" : "否",
@@ -382,14 +386,21 @@ function HiddenInfo(props) {
382
386
  column={1}
383
387
  styles={{ label: { width: 200 } }}
384
388
  items={[
385
- { label: "整改部门", children: item.deptName },
386
- { label: "整改人", children: item.userName },
387
- { label: "整改时间", children: item.rectificationTime },
388
- { label: "整改描述", children: item.descr },
389
+ ...(item.deptName ? [{ label: "整改部门", children: item.deptName }] : []),
390
+ ...(item.userName ? [{ label: "整改人", children: item.userName }] : []),
391
+ ...(item.rectificationTime ? [{ label: "整改时间", children: item.rectificationTime }] : []),
392
+ ...(item.descr ? [{ label: "整改描述", children: item.descr }] : []),
389
393
  ...(item.investmentFunds ? [{ label: "投入资金", children: `${item.investmentFunds}元` }] : []),
390
394
  ...(info.tempSafeMeasure ? [{ label: "临时安全措施", children: info.tempSafeMeasure }] : []),
391
395
  { label: "整改后图片", children: <PreviewImg files={afterRectificationImageFiles[index]} /> },
392
- { label: "整改方案", children: item.isRectificationScheme === 0 ? "无" : "有" },
396
+ {
397
+ label: "整改方案", children: (
398
+ <>
399
+ {item.isRectificationScheme === 0 && <span>无</span>}
400
+ {item.isRectificationScheme === 1 && <span>有</span>}
401
+ </>
402
+ )
403
+ },
393
404
  ...((item.isRectificationScheme === 1 && item.hiddenSchemeCO && Object.keys(item.hiddenSchemeCO).length > 0)
394
405
  ? [
395
406
  { label: "治理标准", children: item.hiddenSchemeCO.governStanDards },
@@ -429,7 +440,7 @@ function HiddenInfo(props) {
429
440
  { label: "验收人", children: item.userName },
430
441
  { label: "验收时间", children: item.rectificationTime },
431
442
  ...(item.repulseCause ? [{ label: "验收打回意见", children: item.repulseCause }] : []),
432
- { label: "是否合格", children: "合格" },
443
+ { label: "是否合格", children: item.rectificationTime ? "合格" : "" },
433
444
  ...(item.descr ? [{ label: "验收描述", children: item.descr }] : []),
434
445
  ...((acceptImageFiles[index] && acceptImageFiles[index].length > 0) ? [{ label: "验收图片", children: <PreviewImg files={acceptImageFiles[index]} /> }] : []),
435
446
  ]}
@@ -18,8 +18,10 @@ function DictionaryLeftTree(props) {
18
18
  const [treeData, setTreeData] = useState([]);
19
19
 
20
20
  const getData = async () => {
21
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
- throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
22
+ console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+ return;
24
+ }
23
25
 
24
26
  setTreeData([]);
25
27
  const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
@@ -1,8 +1,12 @@
1
- import { message, Modal, Spin } from "antd";
2
- import { useState } from "react";
1
+ import { useFullscreen } from "ahooks";
2
+ import { Button, message, Modal, Spin } from "antd";
3
+ import { useRef, useState } from "react";
3
4
  import { Document, Page, pdfjs } from "react-pdf";
4
5
  import useDownloadFile from "../../hooks/useDownloadFile";
5
- import { getFileUrl } from "../../utils/index";
6
+ import { getFileUrl } from "../../utils";
7
+ import "react-pdf/dist/Page/AnnotationLayer.css";
8
+ import "react-pdf/dist/Page/TextLayer.css";
9
+ import "./index.less";
6
10
 
7
11
  /**
8
12
  * PDF查看组件
@@ -22,6 +26,11 @@ function Pdf(props) {
22
26
  const [pdfWidth, setPdfWidth] = useState(600);
23
27
  const [loading, setLoading] = useState(true);
24
28
 
29
+ const fullscreenRef = useRef(null);
30
+
31
+ const [isFullscreen, { enterFullscreen, exitFullscreen }] = useFullscreen(fullscreenRef);
32
+ const { downloadFile } = useDownloadFile();
33
+
25
34
  pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
26
35
 
27
36
  const onDocumentLoadSuccess = ({ numPages }) => {
@@ -48,14 +57,14 @@ function Pdf(props) {
48
57
  <Spin size="large" />
49
58
  </div>
50
59
  )}
51
- <div style={{ height: "88vh", overflowY: "auto", padding: "24px", ...style }}>
60
+ <div style={{ height: isFullscreen ? "calc(100vh - 40px - 24px - 8px - 32px - 12px)" : "72vh", overflowY: "auto", padding: "24px", ...style }}>
52
61
  <Document
53
62
  file={!file.includes(fileUrl) ? fileUrl + file : file}
54
63
  onLoadSuccess={onDocumentLoadSuccess}
55
64
  onLoadError={onDocumentLoadError}
56
65
  >
57
66
  {
58
- Array.from({ length: numPages }).map((el, index) => (
67
+ Array.from({ length: numPages }).map((_, index) => (
59
68
  <Page key={`page_${index + 1}`} pageNumber={index + 1} onLoadSuccess={onPageLoadSuccess} />
60
69
  ))
61
70
  }
@@ -69,36 +78,52 @@ function Pdf(props) {
69
78
  return renderPdfContent();
70
79
  }
71
80
 
72
- const { loading: downloadFileLoading, downloadFile } = useDownloadFile();
73
-
74
81
  const onDownloadFile = () => {
75
- Modal.confirm({
76
- title: "提示",
77
- content: "确定要下载此文件吗?",
78
- onOk: () => {
79
- downloadFile({
80
- url: fileUrl,
81
- name,
82
- });
83
- },
82
+ isFullscreen && exitFullscreen();
83
+ downloadFile({
84
+ url: file,
85
+ name,
84
86
  });
85
87
  };
86
88
 
87
89
  // 默认弹窗模式
88
90
  return (
89
- <Modal
90
- open={visible}
91
- maskClosable={false}
92
- width={pdfWidth + 100}
93
- title="PDF预览"
94
- onCancel={onCancel}
95
- cancelText="关闭"
96
- okText="下载"
97
- onOk={onDownloadFile}
98
- loading={downloadFileLoading}
99
- >
100
- {renderPdfContent()}
101
- </Modal>
91
+ <div ref={fullscreenRef}>
92
+ <Modal
93
+ style={{ top: isFullscreen ? 0 : 100, maxWidth: isFullscreen ? "100vw" : "calc(100vw - 32px)", paddingBottom: isFullscreen ? 0 : 24 }}
94
+ open={visible}
95
+ maskClosable={false}
96
+ width={isFullscreen ? "100vw" : pdfWidth + 100}
97
+ title="PDF预览"
98
+ onCancel={() => {
99
+ isFullscreen && exitFullscreen();
100
+ onCancel();
101
+ }}
102
+ getContainer={false}
103
+ footer={[
104
+ <Button
105
+ key="cancel"
106
+ onClick={() => {
107
+ isFullscreen && exitFullscreen();
108
+ onCancel();
109
+ }}
110
+ >
111
+ 关闭
112
+ </Button>,
113
+ <Button
114
+ key="fullScreen"
115
+ onClick={() => {
116
+ isFullscreen ? exitFullscreen() : enterFullscreen();
117
+ }}
118
+ >
119
+ {isFullscreen ? "退出全屏" : "全屏"}
120
+ </Button>,
121
+ <Button key="download" type="primary" onClick={onDownloadFile}>下载</Button>,
122
+ ]}
123
+ >
124
+ {renderPdfContent()}
125
+ </Modal>
126
+ </div>
102
127
  );
103
128
  }
104
129
 
@@ -0,0 +1,3 @@
1
+ .react-pdf__Page__canvas{
2
+ margin: 0 auto;
3
+ }
@@ -18,8 +18,10 @@ function DictionarySelect(props) {
18
18
  const [data, setData] = useState([]);
19
19
 
20
20
  const getData = async () => {
21
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
- throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
22
+ console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+ return;
24
+ }
23
25
 
24
26
  setData([]);
25
27
  const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
@@ -18,8 +18,10 @@ function DictionarySelectTree(props) {
18
18
  const [treeData, setTreeData] = useState([]);
19
19
 
20
20
  const getData = async () => {
21
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
- throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
22
+ console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+ return;
24
+ }
23
25
 
24
26
  setTreeData([]);
25
27
  const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
@@ -12,8 +12,10 @@ function useDeleteFile(returnType = "object") {
12
12
 
13
13
  // 删除文件
14
14
  const deleteFile = (options) => {
15
- if (!options)
16
- throw new Error("请传入 options");
15
+ if (!options) {
16
+ console.error("请传入 options");
17
+ return;
18
+ }
17
19
 
18
20
  // 增加请求数量并设置loading状态
19
21
  requestCount++;
@@ -24,10 +26,14 @@ function useDeleteFile(returnType = "object") {
24
26
  return new Promise((resolve, reject) => {
25
27
  const { files = [], single = true } = options;
26
28
 
27
- if (!files)
28
- throw new Error("请传入 files");
29
- if (!Array.isArray(files))
30
- throw new Error("请传入有效的 files");
29
+ if (!files) {
30
+ console.error("请传入 files");
31
+ return;
32
+ }
33
+ if (!Array.isArray(files)) {
34
+ console.error("请传入有效的 files");
35
+ return;
36
+ }
31
37
 
32
38
  // 如果没有文件则直接返回
33
39
  if (files.length === 0) {
@@ -13,8 +13,10 @@ function useDictionary(returnType = "object") {
13
13
 
14
14
  // 获取数据字典
15
15
  const getDictionary = (options) => {
16
- if (!options)
17
- throw new Error("请传入 options");
16
+ if (!options) {
17
+ console.error("请传入 options");
18
+ return;
19
+ }
18
20
 
19
21
  // 增加请求数量并设置loading状态
20
22
  requestCount++;
@@ -25,10 +27,14 @@ function useDictionary(returnType = "object") {
25
27
  return new Promise((resolve, reject) => {
26
28
  const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options;
27
29
 
28
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
29
- throw new Error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
30
- if (!dictValue)
31
- throw new Error("请传入 options.dictValue");
30
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
31
+ console.error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
32
+ return;
33
+ }
34
+ if (!dictValue) {
35
+ console.error("请传入 options.dictValue");
36
+ return;
37
+ }
32
38
 
33
39
  // 发送请求
34
40
  request(
@@ -38,7 +38,8 @@ export default function useDownloadBlob(returnType = "object") {
38
38
  })
39
39
  .then((response) => {
40
40
  if (!response.ok) {
41
- throw new Error("Network response was not ok");
41
+ console.error("网络响应异常");
42
+ return;
42
43
  }
43
44
  return response.blob();
44
45
  })
@@ -20,8 +20,10 @@ export default function useDownloadFile(returnType = "object") {
20
20
  }
21
21
 
22
22
  const { url, name: fileName } = options;
23
- if (!url)
24
- throw new Error("请传入 url");
23
+ if (!url) {
24
+ console.error("请传入 url");
25
+ return;
26
+ }
25
27
 
26
28
  Modal.confirm({
27
29
  title: "提示",
@@ -14,8 +14,10 @@ function useGetFile(returnType = "object") {
14
14
 
15
15
  // 获取文件
16
16
  const getFile = (options) => {
17
- if (!options)
18
- throw new Error("请传入 options");
17
+ if (!options) {
18
+ console.error("请传入 options");
19
+ return;
20
+ }
19
21
 
20
22
  // 增加请求数量并设置loading状态
21
23
  requestCount++;
@@ -26,15 +28,21 @@ function useGetFile(returnType = "object") {
26
28
  return new Promise((resolve, reject) => {
27
29
  const { eqType, eqForeignKey } = options;
28
30
 
29
- if (!eqType)
30
- throw new Error("请传入 options.eqType");
31
+ if (!eqType) {
32
+ console.error("请传入 options.eqType");
33
+ return;
34
+ }
31
35
 
32
36
  // 检查eqType是否在UPLOAD_FILE_TYPE_ENUM中
33
- if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType))
34
- throw new Error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
37
+ if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType)) {
38
+ console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
39
+ return;
40
+ }
35
41
 
36
- if (eqForeignKey === undefined || eqForeignKey === null)
37
- throw new Error("请传入 options.eqForeignKey");
42
+ if (eqForeignKey === undefined || eqForeignKey === null) {
43
+ console.error("请传入 options.eqForeignKey");
44
+ return;
45
+ }
38
46
 
39
47
  // 发送请求
40
48
  request(
@@ -44,8 +44,10 @@ function getService(service, getExtraParams = {}, transform, usePermission) {
44
44
  * 自定义 useTable,继承 ahooks 的 useAntdTable,根据需求进行扩展
45
45
  */
46
46
  function useTable(service, options) {
47
- if (!service)
48
- throw new Error("请传入 service");
47
+ if (!service) {
48
+ console.error("请传入 service")
49
+ return;
50
+ }
49
51
 
50
52
  // 获取额外参数和转换函数
51
53
  const { params: extraParams, transform, ...restOptions } = options || {};
@@ -13,8 +13,10 @@ function useUploadFile(returnType = "object") {
13
13
 
14
14
  // 上传文件
15
15
  const uploadFile = (options) => {
16
- if (!options)
17
- throw new Error("请传入 options");
16
+ if (!options) {
17
+ console.error("请传入 options");
18
+ return;
19
+ }
18
20
 
19
21
  // 增加请求数量并设置loading状态
20
22
  requestCount++;
@@ -25,28 +27,42 @@ function useUploadFile(returnType = "object") {
25
27
  return new Promise((resolve, reject) => {
26
28
  const { files = [], single = true, params } = options;
27
29
 
28
- if (!files)
29
- throw new Error("请传入 files");
30
- if (!Array.isArray(files))
31
- throw new Error("请传入有效的 files");
32
- if (!params)
33
- throw new Error("请传入 options.params");
34
- if (!params.type)
35
- throw new Error("请传入 options.params.type");
30
+ if (!files) {
31
+ console.error("请传入 files");
32
+ return;
33
+ }
34
+ if (!Array.isArray(files)) {
35
+ console.error("请传入有效的 files");
36
+ return;
37
+ }
38
+ if (!params) {
39
+ console.error("请传入 options.params");
40
+ return;
41
+ }
42
+ if (!params.type) {
43
+ console.error("请传入 options.params.type");
44
+ return;
45
+ }
36
46
 
37
47
  // 检查type是否在UPLOAD_FILE_TYPE_ENUM中
38
- if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type))
39
- throw new Error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
48
+ if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type)) {
49
+ console.error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
50
+ return;
51
+ }
40
52
 
41
53
  // 根据type获取对应的path
42
54
  const path = UPLOAD_FILE_PATH_ENUM[params.type];
43
- if (!path)
44
- throw new Error(`未找到 type ${params.type} 对应的 path `);
55
+ if (!path) {
56
+ console.error(`未找到 type ${params.type} 对应的 path `);
57
+ return;
58
+ }
45
59
 
46
60
  // 当single为false时,foreignKey是必需的
47
61
  if (!single) {
48
- if (!params.hasOwnProperty("foreignKey"))
49
- throw new Error("请传入 options.params.foreignKey");
62
+ if (!params.hasOwnProperty("foreignKey")) {
63
+ console.error("请传入 options.params.foreignKey");
64
+ return;
65
+ }
50
66
  // 如果 foreignKey 是 undefined,设置默认值为空字符串
51
67
  if (params.foreignKey === undefined || params.foreignKey === null)
52
68
  params.foreignKey = "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.175",
4
+ "version": "1.0.176",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",