mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
feat: tpl 过滤器增加 fromNow 方法 (#2723)
* feat: tpl 过滤器增加 fromNow 方法 * feat: tpl 过滤器增加 fromNow 方法
This commit is contained in:
parent
f04b4fa738
commit
f83af09a94
@ -46,6 +46,8 @@ order: 32
|
||||
|
||||
## 带单位数字
|
||||
|
||||
> 1.3.5 及以上版本
|
||||
|
||||
可以通过 `unitOptions` 设置数字的单位选项,和前面的前后缀不同,它的输出结果也将会是字符串,包含单位,默认取选项的第一个。
|
||||
|
||||
```schema: scope="body"
|
||||
|
@ -624,6 +624,34 @@ ${xxx | dateModify:subtract:-7:day}
|
||||
}
|
||||
```
|
||||
|
||||
### fromNow
|
||||
|
||||
> 1.3.5 及以上版本
|
||||
|
||||
显示日期和现在的相对时间
|
||||
|
||||
```schema
|
||||
{
|
||||
"type": "page",
|
||||
"data": {
|
||||
"oldDate": "2021-10-01"
|
||||
},
|
||||
"body": "${oldDate|fromNow}"
|
||||
}
|
||||
```
|
||||
|
||||
可以设置日期数据的格式,比如 X 是秒,其它格式细节参考 [moment](https://momentjs.com/docs/)。
|
||||
|
||||
```schema
|
||||
{
|
||||
"type": "page",
|
||||
"data": {
|
||||
"oldDate": 1586865590
|
||||
},
|
||||
"body": "${oldDate|fromNow:X}"
|
||||
}
|
||||
```
|
||||
|
||||
### number
|
||||
|
||||
自动给数字加千分位。
|
||||
|
@ -220,6 +220,8 @@ export const filters: {
|
||||
data.add();
|
||||
return data.isValid() ? data.toDate() : undefined;
|
||||
},
|
||||
fromNow: (input: any, inputFormat = '') =>
|
||||
moment(input, inputFormat).fromNow(),
|
||||
dateModify: (
|
||||
input: any,
|
||||
modifier: 'add' | 'subtract' | 'endOf' | 'startOf' = 'add',
|
||||
|
Loading…
Reference in New Issue
Block a user