xianniu-ui 0.8.11 → 0.8.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xianniu-ui",
3
- "version": "0.8.11",
3
+ "version": "0.8.13",
4
4
  "private": false,
5
5
  "main": "lib/xianniu-ui.umd.min.js",
6
6
  "scripts": {
package/src/utils/math.js CHANGED
@@ -12,21 +12,40 @@ class Math {
12
12
  constructor(type) {
13
13
  this.type = type
14
14
  }
15
- result(...args) {
16
- if (!args) {
15
+ result(..._args) {
16
+ if (!_args) {
17
17
  throw new Error('error arguments')
18
18
  }
19
+
20
+ let args = [..._args];
21
+ let isUnFixed = false; // 是否不需要fixed
22
+ const lastArgs = args[args.length-1];
23
+ if(lastArgs&&lastArgs.constructor===Object){
24
+ args.pop();
25
+ if('unFixed' in lastArgs){
26
+ isUnFixed = lastArgs.unFixed;
27
+ }
28
+ }
29
+
19
30
  if (Array.isArray(args[0]) && args[1]) {
20
31
  if (!args[0].length) return 0
21
32
  const list = args[0]
22
33
  const fieldKey = args[1]
23
34
  return list.map(item => item[fieldKey]).reduce((pre, cur) => {
24
35
  let val = new Decimal(pre - 0)
25
- return val[this.type](new Decimal(cur - 0)).toNumber()
36
+ let res = val[this.type](new Decimal(cur - 0))
37
+ if(!isUnFixed){
38
+ res = res.toFixed(2)
39
+ }
40
+ return new Decimal(res).toNumber()
26
41
  })
27
42
  } else {
28
43
  return args.reduce((pre, cur) => {
29
- return new Decimal(pre - 0)[this.type](new Decimal(cur - 0)).toNumber()
44
+ let res = new Decimal(pre - 0)[this.type](new Decimal(cur - 0))
45
+ if(!isUnFixed){
46
+ res = res.toFixed(2)
47
+ }
48
+ return new Decimal(res).toNumber()
30
49
  })
31
50
  }
32
51
  }