inleft
2022-02-16 0613f2f9107a082e3f5467dfde2438ab5ec83479
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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')
 
Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  return intPartFormat
})
 
Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
 
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, '')
  if (isNaN(val)) {
    val = '0'
  }
  // eslint-disable-next-line eqeqeq
  const sign = (val == (val = Math.abs(val)))
  val = Math.floor(val * 100 + 0.50000000001)
  let cents = val % 100
  val = Math.floor(val / 100).toString()
  if (cents < 10) {
    cents = '0' + cents
  }
  // eslint-disable-next-line no-undef
  for (let i = 0; i < Math.floor((val.length - (1 + i)) / 3); I++) {
    val = val.substring(0, val.length - (4 * i + 3)) + ',' + val.substring(val.length - (4 * i + 3))
  }
  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
})
 
/**
 * 获取所有字典数组
 *
 * @author yubaoshan
 * @date 2021-2-8 01:13
 */
Vue.filter('dictDataAll', function () {
  return Vue.ls.get(DICT_TYPE_TREE_DATA)
})