feat(filter): 更新日期和金额格式化过滤器
This commit is contained in:
+60
-26
@@ -31,7 +31,8 @@ import store from './store'
|
||||
import router from './router/routers'
|
||||
|
||||
import './assets/icons' // icon
|
||||
import './router/index' // permission control
|
||||
import './router/index'
|
||||
import dayjs from 'dayjs' // permission control
|
||||
|
||||
Vue.use(checkPer)
|
||||
Vue.use(permission)
|
||||
@@ -46,44 +47,77 @@ Vue.component('split-pane', SplitPane)
|
||||
|
||||
/**
|
||||
* 日期格式化<br/>
|
||||
* 例子: <el-tag>{{ scope.row.createTime | dateFormat }}</el-tag>
|
||||
* 例子: <el-tag>{{ scope.row.createTime | formatDate }}</el-tag>
|
||||
*/
|
||||
Vue.filter('dateFormat', function(originVal) {
|
||||
if (originVal === undefined) {
|
||||
return ''
|
||||
Vue.filter('formatDate', function(originVal) {
|
||||
if (originVal) {
|
||||
return dayjs(originVal).format('YY-MM-DD')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
const dt = new Date(originVal)
|
||||
const y = dt.getFullYear()
|
||||
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
|
||||
const d = (dt.getDate() + '').padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
// const dt = new Date(originVal)
|
||||
// const y = dt.getFullYear()
|
||||
// const m = (dt.getMonth() + 1 + '').padStart(2, '0')
|
||||
// const d = (dt.getDate() + '').padStart(2, '0')
|
||||
// return `${y}-${m}-${d}`
|
||||
})
|
||||
|
||||
/**
|
||||
* 日期时间格式化
|
||||
* 日期时间格式化<br/>
|
||||
* 例子: <el-tag>{{ scope.row.createTime | formatDateTime }}</el-tag>
|
||||
*/
|
||||
Vue.filter('dateTimeFormat', function(originVal) {
|
||||
if (originVal === undefined) {
|
||||
return ''
|
||||
Vue.filter('formatDateTime', function(originVal) {
|
||||
if (originVal) {
|
||||
return dayjs(originVal).format('YY-MM-DD HH:mm:ss')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
const dt = new Date(originVal)
|
||||
const y = dt.getFullYear()
|
||||
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
|
||||
const d = (dt.getDate() + '').padStart(2, '0')
|
||||
const hh = (dt.getHours() + '').padStart(2, '0')
|
||||
const mm = (dt.getMinutes() + '').padStart(2, '0')
|
||||
const ss = (dt.getSeconds() + '').padStart(2, '0')
|
||||
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
|
||||
// const dt = new Date(originVal)
|
||||
// const y = dt.getFullYear()
|
||||
// const m = (dt.getMonth() + 1 + '').padStart(2, '0')
|
||||
// const d = (dt.getDate() + '').padStart(2, '0')
|
||||
// const hh = (dt.getHours() + '').padStart(2, '0')
|
||||
// const mm = (dt.getMinutes() + '').padStart(2, '0')
|
||||
// const ss = (dt.getSeconds() + '').padStart(2, '0')
|
||||
// return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
|
||||
})
|
||||
|
||||
/**
|
||||
* 金额格式化
|
||||
* 金额格式化,并保留2位小数<br/>
|
||||
* 例子: <el-tag>{{ scope.row.totalAmount | formatAmount2 }}</el-tag>
|
||||
*/
|
||||
Vue.filter('priceFormat', function(data) {
|
||||
if (data !== undefined && data != null) {
|
||||
Vue.filter('formatAmount2', function(data) {
|
||||
if (data) {
|
||||
return data.toFixed(2)
|
||||
}
|
||||
return 0.00
|
||||
return '-'
|
||||
})
|
||||
|
||||
/**
|
||||
* 金额格式化,并保留1位小数<br/>
|
||||
* 例子: <el-tag>{{ scope.row.totalAmount | formatAmount1 }}</el-tag>
|
||||
*/
|
||||
Vue.filter('formatAmount1', function(data) {
|
||||
if (data) {
|
||||
return data.toFixed(1)
|
||||
}
|
||||
return '-'
|
||||
})
|
||||
|
||||
/**
|
||||
* 千分位数值格式化,并保留dot位小数<br/>
|
||||
* data是value, dot是param1
|
||||
* 例子: <el-tag>{{ scope.row.totalAmount | formatNumber(2) }}</el-tag>
|
||||
*/
|
||||
Vue.filter('formatNumber', function(data, dot) {
|
||||
if (data) {
|
||||
const formatter = new Intl.NumberFormat('zh-CN', {
|
||||
minimumFractionDigits: dot || 0,
|
||||
maximumFractionDigits: dot || 0
|
||||
})
|
||||
return formatter.format(Number(data))
|
||||
}
|
||||
return '-'
|
||||
})
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
/**
|
||||
* 底部文字,支持html语法
|
||||
*/
|
||||
footerTxt: '© 2022-2025 Odboy <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>',
|
||||
footerTxt: '© 2022-2026 Odboy <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>',
|
||||
/**
|
||||
* 备案号
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user