commit | author | age
|
9bcb19
|
1 |
import Vue from 'vue' |
I |
2 |
import { DICT_TYPE_TREE_DATA } from '@/store/mutation-types' |
|
3 |
import moment from 'moment' |
|
4 |
import 'moment/locale/zh-cn' |
|
5 |
moment.locale('zh-cn') |
|
6 |
|
|
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 |
|
|
15 |
Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { |
|
16 |
return moment(dataStr).format(pattern) |
|
17 |
}) |
|
18 |
|
|
19 |
Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { |
|
20 |
return moment(dataStr).format(pattern) |
|
21 |
}) |
|
22 |
|
|
23 |
/** |
|
24 |
* 金额格式化 ,使用方法:{{ val | Fmoney }} |
|
25 |
* |
|
26 |
* @author yubaoshan |
|
27 |
* @date 2020-9-15 15:02:20 |
|
28 |
*/ |
|
29 |
Vue.filter('Fmoney', function (val) { |
|
30 |
// eslint-disable-next-line no-useless-escape |
|
31 |
val = val.toString().replace(/\$|\,/g, '') |
|
32 |
if (isNaN(val)) { |
|
33 |
val = '0' |
|
34 |
} |
|
35 |
// eslint-disable-next-line eqeqeq |
|
36 |
const sign = (val == (val = Math.abs(val))) |
|
37 |
val = Math.floor(val * 100 + 0.50000000001) |
|
38 |
let cents = val % 100 |
|
39 |
val = Math.floor(val / 100).toString() |
|
40 |
if (cents < 10) { |
|
41 |
cents = '0' + cents |
|
42 |
} |
|
43 |
// eslint-disable-next-line no-undef |
|
44 |
for (let i = 0; i < Math.floor((val.length - (1 + i)) / 3); I++) { |
|
45 |
val = val.substring(0, val.length - (4 * i + 3)) + ',' + val.substring(val.length - (4 * i + 3)) |
|
46 |
} |
|
47 |
return (((sign) ? '' : '-') + val + '.' + cents) |
|
48 |
}) |
|
49 |
|
|
50 |
/** |
|
51 |
* 翻译使用方法,直接返回翻译后的name {{ code | dictType(value) }} |
|
52 |
* |
|
53 |
* @author yubaoshan |
|
54 |
* @date 2020-9-15 15:02:20 |
|
55 |
*/ |
|
56 |
Vue.filter('dictType', function (code, value) { |
|
57 |
const dictTypeTree = Vue.ls.get(DICT_TYPE_TREE_DATA) |
|
58 |
if (dictTypeTree === undefined) { |
|
59 |
return '需重新登录' |
|
60 |
} |
|
61 |
// eslint-disable-next-line eqeqeq |
|
62 |
const tree = dictTypeTree.filter(item => item.code == code)[0].children |
|
63 |
if (tree === undefined || tree.length === 0) { |
|
64 |
return '无此字典' |
|
65 |
} |
|
66 |
// eslint-disable-next-line eqeqeq |
|
67 |
const values = tree.filter(item => item.code == value) |
|
68 |
if (values.length === undefined || values.length === 0) { |
|
69 |
return '无此字典' |
|
70 |
} |
|
71 |
return values[0].name |
|
72 |
}) |
|
73 |
|
|
74 |
/** |
|
75 |
* 获取某个code下字典的列表,多用于字典下拉框,使用方法:{{ code | dictData }} |
|
76 |
* |
|
77 |
* @author yubaoshan |
|
78 |
* @date 2020-9-19 22:40:22 |
|
79 |
*/ |
|
80 |
Vue.filter('dictData', function (code) { |
|
81 |
const dictTypeTree = Vue.ls.get(DICT_TYPE_TREE_DATA) |
|
82 |
if (dictTypeTree === undefined) { |
|
83 |
return [] |
|
84 |
} |
|
85 |
// eslint-disable-next-line eqeqeq |
|
86 |
const tree = dictTypeTree.filter(item => item.code == code)[0].children |
|
87 |
if (tree === undefined) { |
|
88 |
return [] |
|
89 |
} |
|
90 |
return tree |
|
91 |
}) |
|
92 |
|
|
93 |
/** |
|
94 |
* 获取所有字典数组 |
|
95 |
* |
|
96 |
* @author yubaoshan |
|
97 |
* @date 2021-2-8 01:13 |
|
98 |
*/ |
|
99 |
Vue.filter('dictDataAll', function () { |
|
100 |
return Vue.ls.get(DICT_TYPE_TREE_DATA) |
|
101 |
}) |