Files
vxe-table/examples/plugins/xtable/formatter.js
xuliangzhan dda6c36581 优化重构
2020-02-26 18:39:20 +08:00

32 lines
1019 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import VXETable from '../../../packages/v-x-e-table'
import XEUtils from 'xe-utils'
// 自定义全局的格式化处理函数
VXETable.formats.mixin({
// 格式化下拉选项
select (cellValue, list) {
const item = list.find(item => item.value === cellValue)
return item ? item.label : ''
},
// 格式化日期,默认 yyyy-MM-dd HH:mm:ss
date (cellValue, format) {
return XEUtils.toDateString(cellValue, format || 'yyyy-MM-dd HH:mm:ss')
},
// 格式金额默认2位数
amount (cellValue, digits) {
return XEUtils.commafy(cellValue, { digits: digits || 2 })
},
// 格式化银行卡默认每4位隔开
bankcard (cellValue) {
return XEUtils.commafy(cellValue, { spaceNumber: 4, separator: ' ' })
},
// 四舍五入,默认两位数
fixedNumber (cellValue, digits) {
return XEUtils.toNumber(cellValue).toFixed(digits || 2)
},
// 截取小数,默认两位数
cutNumber (cellValue, digits) {
return XEUtils.toFixedString(cellValue, digits || 2)
}
})