diff --git a/src/componentsCodegen/createDefinitionEnum.ts b/src/componentsCodegen/createDefinitionEnum.ts index 67cec01..0537b25 100644 --- a/src/componentsCodegen/createDefinitionEnum.ts +++ b/src/componentsCodegen/createDefinitionEnum.ts @@ -7,15 +7,12 @@ import { IEnumDef } from "../baseInterfaces"; * @param type 枚举的类型 */ export function createDefinitionEnum(className: string, enumArray: any[], type: string): IEnumDef { - let result = '' - if (type === 'string') { - result = enumArray.map(item => `'${item}'='${item}'`).join(',') - } - else { - result = type === 'string' ? - enumArray.map(item => `'${item}'`).join('|') : - enumArray.join('|') - } - + const result = type === 'string' + ? enumArray + .map(item => Number.isNaN(item) + ? `'${item}'='${item}'` + : `'KEY_${item}'='${item}'`) + .join(',') + : enumArray.join('|') return { name: className, enumProps: result, type: type } } diff --git a/src/componentsCodegen/propTrueType.ts b/src/componentsCodegen/propTrueType.ts index dbc7fc4..1963ffc 100644 --- a/src/componentsCodegen/propTrueType.ts +++ b/src/componentsCodegen/propTrueType.ts @@ -53,7 +53,12 @@ export function propTrueType(v: IDefinitionProperty): { // 是枚举 并且是字符串类型 else if (v.enum && v.type === 'string') { result.isEnum = true - result.propType = getEnums(v.enum).map(item => `'${item}'='${item}'`).join(',') + result.propType = getEnums(v.enum) + .map(item => + isNaN(item) + ? `'${item}'='${item}'` + : `'KEY_${item}'='${item}'`) + .join(',') } else if (v.enum) { result.isType = true diff --git a/src/definitionCodegen/createDefinitionEnum.ts b/src/definitionCodegen/createDefinitionEnum.ts index 67cec01..0537b25 100644 --- a/src/definitionCodegen/createDefinitionEnum.ts +++ b/src/definitionCodegen/createDefinitionEnum.ts @@ -7,15 +7,12 @@ import { IEnumDef } from "../baseInterfaces"; * @param type 枚举的类型 */ export function createDefinitionEnum(className: string, enumArray: any[], type: string): IEnumDef { - let result = '' - if (type === 'string') { - result = enumArray.map(item => `'${item}'='${item}'`).join(',') - } - else { - result = type === 'string' ? - enumArray.map(item => `'${item}'`).join('|') : - enumArray.join('|') - } - + const result = type === 'string' + ? enumArray + .map(item => Number.isNaN(item) + ? `'${item}'='${item}'` + : `'KEY_${item}'='${item}'`) + .join(',') + : enumArray.join('|') return { name: className, enumProps: result, type: type } } diff --git a/src/definitionCodegen/propTrueType.ts b/src/definitionCodegen/propTrueType.ts index cf094e5..0829efd 100644 --- a/src/definitionCodegen/propTrueType.ts +++ b/src/definitionCodegen/propTrueType.ts @@ -39,12 +39,12 @@ export function propTrueType(v: IDefinitionProperty): { // 是枚举 并且是字符串类型 else if (v.enum && v.type === 'string') { result.isEnum = true - result.propType = getEnums(v.enum).map(item => { - if (isNaN(item)){ - return `'${item}'='${item}'`; - } - return `'KEY_${item}'='${item}'`; - }).join(',') + result.propType = getEnums(v.enum) + .map(item => + isNaN(item) + ? `'${item}'='${item}'` + : `'KEY_${item}'='${item}'`) + .join(',') } else if (v.enum) { result.isType = true