将所有throw new Error改成console.error加return的方式
parent
b04cc6bae3
commit
68a24253e9
|
|
@ -18,8 +18,10 @@ function DictionaryCascader(props) {
|
|||
const [treeData, setTreeData] = useState([]);
|
||||
|
||||
const getData = async () => {
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
|
||||
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
||||
console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
setTreeData([]);
|
||||
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ function DictionaryLeftTree(props) {
|
|||
const [treeData, setTreeData] = useState([]);
|
||||
|
||||
const getData = async () => {
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
|
||||
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
||||
console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
setTreeData([]);
|
||||
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ function DictionarySelect(props) {
|
|||
const [data, setData] = useState([]);
|
||||
|
||||
const getData = async () => {
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
|
||||
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
||||
console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
setData([]);
|
||||
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ function DictionarySelectTree(props) {
|
|||
const [treeData, setTreeData] = useState([]);
|
||||
|
||||
const getData = async () => {
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
|
||||
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
||||
console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
setTreeData([]);
|
||||
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ function useDeleteFile(returnType = "object") {
|
|||
|
||||
// 删除文件
|
||||
const deleteFile = (options) => {
|
||||
if (!options)
|
||||
throw new Error("请传入 options");
|
||||
if (!options) {
|
||||
console.error("请传入 options");
|
||||
return;
|
||||
}
|
||||
|
||||
// 增加请求数量并设置loading状态
|
||||
requestCount++;
|
||||
|
|
@ -24,10 +26,14 @@ function useDeleteFile(returnType = "object") {
|
|||
return new Promise((resolve, reject) => {
|
||||
const { files = [], single = true } = options;
|
||||
|
||||
if (!files)
|
||||
throw new Error("请传入 files");
|
||||
if (!Array.isArray(files))
|
||||
throw new Error("请传入有效的 files");
|
||||
if (!files) {
|
||||
console.error("请传入 files");
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(files)) {
|
||||
console.error("请传入有效的 files");
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有文件则直接返回
|
||||
if (files.length === 0) {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ function useDictionary(returnType = "object") {
|
|||
|
||||
// 获取数据字典
|
||||
const getDictionary = (options) => {
|
||||
if (!options)
|
||||
throw new Error("请传入 options");
|
||||
if (!options) {
|
||||
console.error("请传入 options");
|
||||
return;
|
||||
}
|
||||
|
||||
// 增加请求数量并设置loading状态
|
||||
requestCount++;
|
||||
|
|
@ -25,10 +27,14 @@ function useDictionary(returnType = "object") {
|
|||
return new Promise((resolve, reject) => {
|
||||
const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options;
|
||||
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
|
||||
throw new Error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
if (!dictValue)
|
||||
throw new Error("请传入 options.dictValue");
|
||||
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
||||
console.error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
||||
return;
|
||||
}
|
||||
if (!dictValue) {
|
||||
console.error("请传入 options.dictValue");
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
request(
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ export default function useDownloadBlob(returnType = "object") {
|
|||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
console.error("网络响应异常");
|
||||
return;
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ export default function useDownloadFile(returnType = "object") {
|
|||
}
|
||||
|
||||
const { url, name: fileName } = options;
|
||||
if (!url)
|
||||
throw new Error("请传入 url");
|
||||
if (!url) {
|
||||
console.error("请传入 url");
|
||||
return;
|
||||
}
|
||||
|
||||
Modal.confirm({
|
||||
title: "提示",
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ function useGetFile(returnType = "object") {
|
|||
|
||||
// 获取文件
|
||||
const getFile = (options) => {
|
||||
if (!options)
|
||||
throw new Error("请传入 options");
|
||||
if (!options) {
|
||||
console.error("请传入 options");
|
||||
return;
|
||||
}
|
||||
|
||||
// 增加请求数量并设置loading状态
|
||||
requestCount++;
|
||||
|
|
@ -26,15 +28,21 @@ function useGetFile(returnType = "object") {
|
|||
return new Promise((resolve, reject) => {
|
||||
const { eqType, eqForeignKey } = options;
|
||||
|
||||
if (!eqType)
|
||||
throw new Error("请传入 options.eqType");
|
||||
if (!eqType) {
|
||||
console.error("请传入 options.eqType");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查eqType是否在UPLOAD_FILE_TYPE_ENUM中
|
||||
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType))
|
||||
throw new Error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
||||
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType)) {
|
||||
console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
if (eqForeignKey === undefined || eqForeignKey === null)
|
||||
throw new Error("请传入 options.eqForeignKey");
|
||||
if (eqForeignKey === undefined || eqForeignKey === null) {
|
||||
console.error("请传入 options.eqForeignKey");
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
request(
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ function getService(service, getExtraParams = {}, transform, usePermission) {
|
|||
* 自定义 useTable,继承 ahooks 的 useAntdTable,根据需求进行扩展
|
||||
*/
|
||||
function useTable(service, options) {
|
||||
if (!service)
|
||||
throw new Error("请传入 service");
|
||||
if (!service) {
|
||||
console.error("请传入 service")
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取额外参数和转换函数
|
||||
const { params: extraParams, transform, ...restOptions } = options || {};
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ function useUploadFile(returnType = "object") {
|
|||
|
||||
// 上传文件
|
||||
const uploadFile = (options) => {
|
||||
if (!options)
|
||||
throw new Error("请传入 options");
|
||||
if (!options) {
|
||||
console.error("请传入 options");
|
||||
return;
|
||||
}
|
||||
|
||||
// 增加请求数量并设置loading状态
|
||||
requestCount++;
|
||||
|
|
@ -25,28 +27,42 @@ function useUploadFile(returnType = "object") {
|
|||
return new Promise((resolve, reject) => {
|
||||
const { files = [], single = true, params } = options;
|
||||
|
||||
if (!files)
|
||||
throw new Error("请传入 files");
|
||||
if (!Array.isArray(files))
|
||||
throw new Error("请传入有效的 files");
|
||||
if (!params)
|
||||
throw new Error("请传入 options.params");
|
||||
if (!params.type)
|
||||
throw new Error("请传入 options.params.type");
|
||||
if (!files) {
|
||||
console.error("请传入 files");
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(files)) {
|
||||
console.error("请传入有效的 files");
|
||||
return;
|
||||
}
|
||||
if (!params) {
|
||||
console.error("请传入 options.params");
|
||||
return;
|
||||
}
|
||||
if (!params.type) {
|
||||
console.error("请传入 options.params.type");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查type是否在UPLOAD_FILE_TYPE_ENUM中
|
||||
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type))
|
||||
throw new Error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
||||
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type)) {
|
||||
console.error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据type获取对应的path
|
||||
const path = UPLOAD_FILE_PATH_ENUM[params.type];
|
||||
if (!path)
|
||||
throw new Error(`未找到 type ${params.type} 对应的 path `);
|
||||
if (!path) {
|
||||
console.error(`未找到 type ${params.type} 对应的 path `);
|
||||
return;
|
||||
}
|
||||
|
||||
// 当single为false时,foreignKey是必需的
|
||||
if (!single) {
|
||||
if (!params.hasOwnProperty("foreignKey"))
|
||||
throw new Error("请传入 options.params.foreignKey");
|
||||
if (!params.hasOwnProperty("foreignKey")) {
|
||||
console.error("请传入 options.params.foreignKey");
|
||||
return;
|
||||
}
|
||||
// 如果 foreignKey 是 undefined,设置默认值为空字符串
|
||||
if (params.foreignKey === undefined || params.foreignKey === null)
|
||||
params.foreignKey = "";
|
||||
|
|
|
|||
Loading…
Reference in New Issue