From 7202da8cecfda38f39b3e99f9fde1039ea17190d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=84=89?= <30541930+duqingyu@users.noreply.github.com> Date: Thu, 1 Dec 2022 10:20:28 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E8=BF=87=E6=BB=A4=E5=99=A8bytes?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E5=8F=82step=20(#5760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: duqingyu --- docs/zh-CN/concepts/data-mapping.md | 37 +++++++++++++++++++++ packages/amis-core/__tests__/filter.test.ts | 9 +++++ 2 files changed, 46 insertions(+) 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}', {