feat(filter): 更新日期和金额格式化过滤器

This commit is contained in:
2026-02-05 16:11:09 +08:00
parent 290e47911a
commit 0eb0e61b16
2 changed files with 61 additions and 27 deletions
+60 -26
View File
@@ -31,7 +31,8 @@ import store from './store'
import router from './router/routers' import router from './router/routers'
import './assets/icons' // icon import './assets/icons' // icon
import './router/index' // permission control import './router/index'
import dayjs from 'dayjs' // permission control
Vue.use(checkPer) Vue.use(checkPer)
Vue.use(permission) Vue.use(permission)
@@ -46,44 +47,77 @@ Vue.component('split-pane', SplitPane)
/** /**
* 日期格式化<br/> * 日期格式化<br/>
* 例子: <el-tag>{{ scope.row.createTime | dateFormat }}</el-tag> * 例子: <el-tag>{{ scope.row.createTime | formatDate }}</el-tag>
*/ */
Vue.filter('dateFormat', function(originVal) { Vue.filter('formatDate', function(originVal) {
if (originVal === undefined) { if (originVal) {
return '' return dayjs(originVal).format('YY-MM-DD')
} else {
return '-'
} }
const dt = new Date(originVal) // const dt = new Date(originVal)
const y = dt.getFullYear() // const y = dt.getFullYear()
const m = (dt.getMonth() + 1 + '').padStart(2, '0') // const m = (dt.getMonth() + 1 + '').padStart(2, '0')
const d = (dt.getDate() + '').padStart(2, '0') // const d = (dt.getDate() + '').padStart(2, '0')
return `${y}-${m}-${d}` // return `${y}-${m}-${d}`
}) })
/** /**
* 日期时间格式化 * 日期时间格式化<br/>
* 例子: <el-tag>{{ scope.row.createTime | formatDateTime }}</el-tag>
*/ */
Vue.filter('dateTimeFormat', function(originVal) { Vue.filter('formatDateTime', function(originVal) {
if (originVal === undefined) { if (originVal) {
return '' return dayjs(originVal).format('YY-MM-DD HH:mm:ss')
} else {
return '-'
} }
const dt = new Date(originVal) // const dt = new Date(originVal)
const y = dt.getFullYear() // const y = dt.getFullYear()
const m = (dt.getMonth() + 1 + '').padStart(2, '0') // const m = (dt.getMonth() + 1 + '').padStart(2, '0')
const d = (dt.getDate() + '').padStart(2, '0') // const d = (dt.getDate() + '').padStart(2, '0')
const hh = (dt.getHours() + '').padStart(2, '0') // const hh = (dt.getHours() + '').padStart(2, '0')
const mm = (dt.getMinutes() + '').padStart(2, '0') // const mm = (dt.getMinutes() + '').padStart(2, '0')
const ss = (dt.getSeconds() + '').padStart(2, '0') // const ss = (dt.getSeconds() + '').padStart(2, '0')
return `${y}-${m}-${d} ${hh}:${mm}:${ss}` // return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}) })
/** /**
* 金额格式化 * 金额格式化,并保留2位小数<br/>
* 例子: <el-tag>{{ scope.row.totalAmount | formatAmount2 }}</el-tag>
*/ */
Vue.filter('priceFormat', function(data) { Vue.filter('formatAmount2', function(data) {
if (data !== undefined && data != null) { if (data) {
return data.toFixed(2) 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 Vue.config.productionTip = false
+1 -1
View File
@@ -38,7 +38,7 @@ module.exports = {
/** /**
* 底部文字,支持html语法 * 底部文字,支持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>',
/** /**
* 备案号 * 备案号
*/ */