From bbb3e7c3c5c89153aac5581d56f0eef007345e66 Mon Sep 17 00:00:00 2001 From: xingyuv Date: Thu, 13 Apr 2023 10:43:06 +0800 Subject: [PATCH] fix: dict bugs --- src/utils/dict.ts | 51 ++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/utils/dict.ts b/src/utils/dict.ts index fc36523..f6f40c0 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -26,12 +26,14 @@ export const getDictOptions = (dictType: string) => { export const getIntDictOptions = (dictType: string) => { const dictOption: DictDataType[] = [] const dictOptions: DictDataType[] = getDictOptions(dictType) - dictOptions.forEach((dict: DictDataType) => { - dictOption.push({ - ...dict, - value: parseInt(dict.value + '') + if (dictOptions && dictOptions.length > 0) { + dictOptions.forEach((dict: DictDataType) => { + dictOption.push({ + ...dict, + value: parseInt(dict.value + '') + }) }) - }) + } return dictOption } @@ -39,34 +41,42 @@ export const getIntDictOptions = (dictType: string) => { export const getStrDictOptions = (dictType: string) => { const dictOption: DictDataType[] = [] const dictOptions: DictDataType[] = getDictOptions(dictType) - dictOptions.forEach((dict: DictDataType) => { - dictOption.push({ - ...dict, - value: dict.value + '' + if (dictOptions && dictOptions.length > 0) { + dictOptions.forEach((dict: DictDataType) => { + dictOption.push({ + ...dict, + value: dict.value + '' + }) }) - }) + } return dictOption } export const getBoolDictOptions = (dictType: string) => { const dictOption: DictDataType[] = [] const dictOptions: DictDataType[] = getDictOptions(dictType) - dictOptions.forEach((dict: DictDataType) => { - dictOption.push({ - ...dict, - value: dict.value + '' === 'true' ? true : false + if (dictOptions && dictOptions.length > 0) { + dictOptions.forEach((dict: DictDataType) => { + dictOption.push({ + ...dict, + value: dict.value + '' === 'true' ? true : false + }) }) - }) + } return dictOption } export const getDictObj = (dictType: string, value: any) => { const dictOptions: DictDataType[] = getDictOptions(dictType) - dictOptions.forEach((dict: DictDataType) => { - if (dict.value === value.toString()) { - return dict - } - }) + if (dictOptions && dictOptions.length > 0) { + dictOptions.forEach((dict: DictDataType) => { + if (dict.value === value.toString()) { + return dict + } + }) + } else { + return null + } } export enum DICT_TYPE { @@ -100,6 +110,7 @@ export enum DICT_TYPE { INFRA_API_ERROR_LOG_PROCESS_STATUS = 'infra_api_error_log_process_status', INFRA_CONFIG_TYPE = 'infra_config_type', INFRA_CODEGEN_TEMPLATE_TYPE = 'infra_codegen_template_type', + INFRA_CODEGEN_FRONT_TYPE = 'infra_codegen_front_type', INFRA_CODEGEN_SCENE = 'infra_codegen_scene', INFRA_FILE_STORAGE = 'infra_file_storage',