filter.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Vue from 'vue'
  2. import moment from 'moment'
  3. import { Constant } from '@/constant'
  4. import 'moment/locale/zh-cn'
  5. import DictCache from '@/utils/dict'
  6. moment.locale('zh-cn')
  7. Vue.filter('NumberFormat', function (value) {
  8. if (!value) {
  9. return '0'
  10. }
  11. const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  12. return intPartFormat
  13. })
  14. Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  15. return moment(dataStr).format(pattern)
  16. })
  17. Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  18. return moment(dataStr).format(pattern)
  19. })
  20. Vue.filter('statusConstantText', function (val, type) {
  21. return Constant[type][val].text
  22. })
  23. Vue.filter('statusConstantStatus', function (val, type) {
  24. return Constant[type][val].status
  25. })
  26. Vue.filter('statusDictText', function (val, type) {
  27. // return '成功'
  28. return DictCache.getLabelByValue(type, val)
  29. })
  30. Vue.filter('statusDictStatus', function (val, color) {
  31. return DictCache.COLOR[color][val]
  32. })