|
@ -1,4 +1,5 @@
|
|
|
import Vue from 'vue'
|
|
|
import { DICT_TYPE_TREE_DATA } from '@/store/mutation-types'
|
|
|
import moment from 'moment'
|
|
|
import 'moment/locale/zh-cn'
|
|
|
moment.locale('zh-cn')
|
|
@ -18,6 +19,13 @@ Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
|
|
Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
|
|
return moment(dataStr).format(pattern)
|
|
|
})
|
|
|
|
|
|
/**
|
|
|
* 金额格式化 ,使用方法:{{ val | Fmoney }}
|
|
|
*
|
|
|
* @author yubaoshan
|
|
|
* @date 2020-9-15 15:02:20
|
|
|
*/
|
|
|
Vue.filter('Fmoney', function (val) {
|
|
|
// eslint-disable-next-line no-useless-escape
|
|
|
val = val.toString().replace(/\$|\,/g, '')
|
|
@ -38,3 +46,46 @@ Vue.filter('Fmoney', function (val) {
|
|
|
}
|
|
|
return (((sign) ? '' : '-') + val + '.' + cents)
|
|
|
})
|
|
|
|
|
|
/**
|
|
|
* 翻译使用方法,直接返回翻译后的name {{ code | dictType(value) }}
|
|
|
*
|
|
|
* @author yubaoshan
|
|
|
* @date 2020-9-15 15:02:20
|
|
|
*/
|
|
|
Vue.filter('dictType', function (code, value) {
|
|
|
const dictTypeTree = Vue.ls.get(DICT_TYPE_TREE_DATA)
|
|
|
if (dictTypeTree === undefined) {
|
|
|
return '需重新登录'
|
|
|
}
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
const tree = dictTypeTree.filter(item => item.code == code)[0].children
|
|
|
if (tree === undefined || tree.length === 0) {
|
|
|
return '无此字典'
|
|
|
}
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
const values = tree.filter(item => item.code == value)
|
|
|
if (values.length === undefined || values.length === 0) {
|
|
|
return '无此字典'
|
|
|
}
|
|
|
return values[0].name
|
|
|
})
|
|
|
|
|
|
/**
|
|
|
* 获取某个code下字典的列表,多用于字典下拉框,使用方法:{{ code | dictData }}
|
|
|
*
|
|
|
* @author yubaoshan
|
|
|
* @date 2020-9-19 22:40:22
|
|
|
*/
|
|
|
Vue.filter('dictData', function (code) {
|
|
|
const dictTypeTree = Vue.ls.get(DICT_TYPE_TREE_DATA)
|
|
|
if (dictTypeTree === undefined) {
|
|
|
return []
|
|
|
}
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
const tree = dictTypeTree.filter(item => item.code == code)[0].children
|
|
|
if (tree === undefined) {
|
|
|
return []
|
|
|
}
|
|
|
return tree
|
|
|
})
|