diff --git a/components/FormBuilder/FormBuilder.js b/components/FormBuilder/FormBuilder.js index 638269d..8d63e89 100644 --- a/components/FormBuilder/FormBuilder.js +++ b/components/FormBuilder/FormBuilder.js @@ -1,4 +1,4 @@ -import { Button, Col, Form, Row, Space, Spin } from "antd"; +import { Button, Col, Form, Row, Space, Spin, message } from "antd"; import FormItemsRenderer from "./FormItemsRenderer"; /** @@ -34,6 +34,9 @@ const FormBuilder = (props) => { scrollToFirstError wrapperCol={{ span: 24 - labelCol.span }} initialValues={values} + onFinishFailed={() => { + message.error("请补全必填项"); + }} style={{ width: `calc(100% - ${gutter * 2}px)`, margin: `0 auto` }} {...restProps} > diff --git a/hooks/useDeleteFile/index.js b/hooks/useDeleteFile/index.js index 3f76c07..5592bcd 100644 --- a/hooks/useDeleteFile/index.js +++ b/hooks/useDeleteFile/index.js @@ -7,13 +7,19 @@ import { useState } from "react"; function useDeleteFile(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 删除文件 const deleteFile = (options) => { if (!options) throw new Error("请传入 options"); - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { const { files = [], single = true } = options; @@ -25,7 +31,10 @@ function useDeleteFile(returnType = "object") { // 如果没有文件则直接返回 if (files.length === 0) { - setLoading(false); + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } resolve(); return; } @@ -34,7 +43,10 @@ function useDeleteFile(returnType = "object") { if (single) { const firstFile = files[0]; if (!firstFile.filePath) { - setLoading(false); + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } resolve(); return; } @@ -43,7 +55,10 @@ function useDeleteFile(returnType = "object") { else { const validFiles = files.filter(f => f.id); if (validFiles.length === 0) { - setLoading(false); + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } resolve(); return; } @@ -63,7 +78,11 @@ function useDeleteFile(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useDictionary/index.js b/hooks/useDictionary/index.js index 4dd102d..d7c586f 100644 --- a/hooks/useDictionary/index.js +++ b/hooks/useDictionary/index.js @@ -8,13 +8,19 @@ import { DICTIONARY_APP_KEY_ENUM } from "../../enum/dictionary"; function useDictionary(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 获取数据字典 const getDictionary = (options) => { if (!options) throw new Error("请传入 options"); - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options; @@ -37,7 +43,11 @@ function useDictionary(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useDownloadBlob/index.js b/hooks/useDownloadBlob/index.js index 137e1b4..a556368 100644 --- a/hooks/useDownloadBlob/index.js +++ b/hooks/useDownloadBlob/index.js @@ -8,10 +8,16 @@ import { useState } from "react"; export default function useDownloadBlob(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 下载Blob流文件 const downloadBlob = (url, options) => { - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { if (!url) @@ -57,7 +63,11 @@ export default function useDownloadBlob(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useDownloadFile/index.js b/hooks/useDownloadFile/index.js index 8cf2738..47744d6 100644 --- a/hooks/useDownloadFile/index.js +++ b/hooks/useDownloadFile/index.js @@ -8,10 +8,16 @@ import { getFileName, getFileSuffix, getFileUrl } from "../../utils"; export default function useDownloadFile(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 下载文件 const downloadFile = (options) => { - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } const { url, name: fileName } = options; if (!url) @@ -50,9 +56,20 @@ export default function useDownloadFile(returnType = "object") { message.error("下载失败"); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }, + onCancel: () => { + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } + }, }); }; diff --git a/hooks/useGetFile/index.js b/hooks/useGetFile/index.js index 35bcdf9..bad0269 100644 --- a/hooks/useGetFile/index.js +++ b/hooks/useGetFile/index.js @@ -9,13 +9,19 @@ import { addingPrefixToFile } from "../../utils"; function useGetFile(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 获取文件 const getFile = (options) => { if (!options) throw new Error("请传入 options"); - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { const { eqType, eqForeignKey } = options; @@ -43,7 +49,11 @@ function useGetFile(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useGetUserInfo/index.js b/hooks/useGetUserInfo/index.js index 3ac40a5..c791407 100644 --- a/hooks/useGetUserInfo/index.js +++ b/hooks/useGetUserInfo/index.js @@ -7,10 +7,16 @@ import { useState } from "react"; function useGetUserInfo(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 获取用户信息 const getUserInfo = () => { - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { // 发送请求 @@ -26,7 +32,11 @@ function useGetUserInfo(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useImportFile/index.js b/hooks/useImportFile/index.js index 6059235..25d71a8 100644 --- a/hooks/useImportFile/index.js +++ b/hooks/useImportFile/index.js @@ -7,10 +7,16 @@ import { useState } from "react"; export default function useImportFile(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 导入文件 const importFile = (url, options) => { - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { if (!url) @@ -38,7 +44,11 @@ export default function useImportFile(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); }; diff --git a/hooks/useUploadFile/index.js b/hooks/useUploadFile/index.js index 9e21595..7b82029 100644 --- a/hooks/useUploadFile/index.js +++ b/hooks/useUploadFile/index.js @@ -8,13 +8,19 @@ import { UPLOAD_FILE_PATH_ENUM, UPLOAD_FILE_TYPE_ENUM } from "../../enum/uploadF function useUploadFile(returnType = "object") { // loading状态 const [loading, setLoading] = useState(false); + // 用于跟踪进行中的请求数量(不暴露给外部) + let requestCount = 0; // 上传文件 const uploadFile = (options) => { if (!options) throw new Error("请传入 options"); - setLoading(true); + // 增加请求数量并设置loading状态 + requestCount++; + if (requestCount > 0) { + setLoading(true); + } return new Promise((resolve, reject) => { const { files = [], single = true, params } = options; @@ -48,7 +54,10 @@ function useUploadFile(returnType = "object") { // 如果没有文件则直接返回 if (files.length === 0) { - setLoading(false); + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } resolve( single ? { filePath: "" } @@ -77,7 +86,10 @@ function useUploadFile(returnType = "object") { // 如果没有文件则返回老文件 if (filesLength === 0) { - setLoading(false); + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } resolve( single ? { filePath: files[0].filePath } @@ -104,7 +116,11 @@ function useUploadFile(returnType = "object") { reject(err); }) .finally(() => { - setLoading(false); + // 减少请求数量并在没有进行中的请求时设置loading为false + requestCount--; + if (requestCount <= 0) { + setLoading(false); + } }); }); };