diff --git a/packages/amis-formula/__tests__/evalute.test.ts b/packages/amis-formula/__tests__/evalute.test.ts index 25a7e875f..151d84a7a 100644 --- a/packages/amis-formula/__tests__/evalute.test.ts +++ b/packages/amis-formula/__tests__/evalute.test.ts @@ -564,7 +564,14 @@ test('evalute:Math', () => { }); test('evalute:UUID', () => { - expect(evaluate('${UUID()}', {}).length).toBe(32); + function isUUIDv4(value: string) { + return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test( + value + ); + } + + expect(isUUIDv4(evaluate('${UUID()}', {}))).toBe(true); + expect(evaluate('${UUID()}', {}).length).toBe(36); expect(evaluate('${UUID(8)}', {}).length).toBe(8); }); diff --git a/packages/amis-formula/src/evalutor.ts b/packages/amis-formula/src/evalutor.ts index e44b570c3..db1d8658d 100644 --- a/packages/amis-formula/src/evalutor.ts +++ b/packages/amis-formula/src/evalutor.ts @@ -1524,8 +1524,8 @@ export class Evaluator { * * @returns {string} 生成的UUID字符串 */ - fnUUID(length: number = 32) { - const len = Math.min(Math.max(length, 0), 32); + fnUUID(length: number = 36) { + const len = Math.min(Math.max(length, 0), 36); return uuidv4().slice(0, len); }