Zone 底座:格式化函数
Methods
(static) formatCurrency(value) → {String}
「标准」Ux.formatCurrency
将传入值格式化成货币格式,该方法不带货币符号。
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String | 输入的数值。 |
Returns:
返回最终格式化过后的货币格式,可以和货币单位连用,取2位小数。
- Type
- String
(static) formatDate(value, pattern) → {string}
「标准」Ux.formatDate
格式化时间字符串或时间值。
Parameters:
Name | Type | Description |
---|---|---|
value |
Dayjs | String | 被格式化的字符串或Moment对象。 |
pattern |
String | 时间使用的模式如: |
Returns:
返回格式化过后的标准时间格式。
- Type
- string
(static) formatExpr(input, params, keep) → {String}
「标准」Ux.formatExpr
格式化字符串,将:x,:y使用params进行参数替换 比如:/api/test/:name和{name:"lang"}两个合并成 => /api/test/lang
Parameters:
Name | Type | Default | Description |
---|---|---|---|
input |
String | Object | 原始字符串。 |
|
params |
Object | 传入参数。 |
|
keep |
Boolean |
false
|
是否保持原始key。 |
Returns:
格式化表达式过后的值。
- Type
- String
(static) formatNow(pattern) → {string}
「标准」Ux.formatNow
按模式格式化当前时间。
Parameters:
Name | Type | Description |
---|---|---|
pattern |
String | 时间使用的模式如: |
Returns:
返回格式化过后的标准时间格式。
- Type
- string
(static) formatObject(expr, appendKey) → {Object}
「标准」Ux.formatObject
将表达式k1=value1,k2=value2,k3=value3
解析成对象。
Parameters:
Name | Type | Default | Description |
---|---|---|---|
expr |
String | 表达式相关信息。 |
|
appendKey |
boolean |
false
|
解析过程中是否追加 |
Returns:
解析好的对象信息。
- Type
- Object
(static) formatPercent(value) → {String}
「标准」Ux.formatPercent
将传入值格式化成带百分比的字符串,该方法返回结果带百分号。
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String | 输入的将要被格式化的值。 |
Returns:
返回最终格式化的结果(百分比)。
- Type
- String
(static) formatQuery(uri, params, encode) → {String}
「标准」Ux.formatQuery
将参数追加到Query String中生成完整的uri链接。
Parameters:
Name | Type | Default | Description |
---|---|---|---|
uri |
String | 被格式化编码的Uri |
|
params |
Object | 将要追加的Query参数值 |
|
encode |
Boolean |
true
|
是否针对参数进行uri encode编码,默认是需编码的 |
Returns:
- Type
- String
(static) formatTpl(data, tpl) → {any|*}
「标准」Ux.formatTpl
使用数据填充模板生成最终带数据的合并格式。
const state = {};
const user = Ux.isLogged();
const config = Ux.fromHoc(reference, "account");
if (!user.icon) user.icon = `image:${ImgPhoto}`;
const empty = Ux.fromHoc(reference, "empty");
if (!user.workNumber) user.workNumber = empty;
if (!user.workTitle) user.workTitle = empty;
if (!user.workLocation) user.workLocation = empty;
// 根据模板格式化相关数据
const data = Ux.formatTpl(user, config);
state.$data = Ux.clone(data);
state.$ready = true;
reference.setState(state);
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | 数据基础信息。 |
tpl |
Object | 模板信息。 |
Returns:
返回最终生成结果。
- Type
- any | *