diff --git a/docs/zh-CN/concepts/data-mapping.md b/docs/zh-CN/concepts/data-mapping.md index 3b0ff8d8d..7e2dc7451 100755 --- a/docs/zh-CN/concepts/data-mapping.md +++ b/docs/zh-CN/concepts/data-mapping.md @@ -1306,6 +1306,43 @@ ${xxx | bytes} } ``` +##### 指定换算间隔参数 + +``` +${xxx | bytes[:step]} +``` + +```schema +{ + "type": "page", + "data": { + "bytes1": 2333, + "bytes2": 2333333, + "bytes3": 2333333333 + }, + "body": [ + { + "type": "tpl", + "tpl": "bytes1 is ${bytes1|bytes:1024}" + }, + { + "type": "divider" + }, + { + "type": "tpl", + "tpl": "bytes2 is ${bytes2|bytes:1024}" + }, + { + "type": "divider" + }, + { + "type": "tpl", + "tpl": "bytes3 is ${bytes3|bytes:1024}" + } + ] +} +``` + ### asArray 将数据包成数组 diff --git a/packages/amis-core/__tests__/filter.test.ts b/packages/amis-core/__tests__/filter.test.ts index 217c19142..4c04c553d 100644 --- a/packages/amis-core/__tests__/filter.test.ts +++ b/packages/amis-core/__tests__/filter.test.ts @@ -132,6 +132,15 @@ test(`filter:bytes`, () => { }) ).toBe('234 KB'); }); + +test(`filter:bytes:step`, () => { + expect( + resolveVariableAndFilter('${a|bytes:1024}', { + a: 234343 + }) + ).toBe('229 KB'); +}); + test(`filter:round`, () => { expect( resolveVariableAndFilter('${a|round}', {