xianniu-ui 0.3.15 → 0.3.17
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/lib/xianniu-ui.common.js +41 -22
- package/lib/xianniu-ui.umd.js +41 -22
- package/lib/xianniu-ui.umd.min.js +1 -1
- package/package.json +1 -1
- package/packages/table/main.vue +0 -1
- package/src/utils/math.js +24 -5
package/package.json
CHANGED
package/packages/table/main.vue
CHANGED
package/src/utils/math.js
CHANGED
|
@@ -21,16 +21,32 @@ class Math {
|
|
|
21
21
|
const list = args[0]
|
|
22
22
|
const fieldKey = args[1]
|
|
23
23
|
return list.map(item => item[fieldKey]).reduce((pre, cur) => {
|
|
24
|
-
let val = new Decimal(pre)
|
|
25
|
-
return val[this.type](new Decimal(cur)).toNumber()
|
|
24
|
+
let val = new Decimal(pre - 0)
|
|
25
|
+
return val[this.type](new Decimal(cur - 0)).toNumber()
|
|
26
26
|
})
|
|
27
27
|
} else {
|
|
28
|
-
return args.reduce((pre, cur) =>
|
|
28
|
+
return args.reduce((pre, cur) => {
|
|
29
|
+
return new Decimal(pre - 0)[this.type](new Decimal(cur - 0)).toNumber()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
autoComputed(fields = [], fieldsRules = {}, field = '', value) {
|
|
34
|
+
if (!fields.length || !Object.keys(fieldsRules).length) {
|
|
35
|
+
throw new Error('error arguments: fields or fieldsRules')
|
|
29
36
|
}
|
|
37
|
+
const _fields = fields
|
|
38
|
+
const _fieldsRules = fieldsRules
|
|
39
|
+
const idx = _fields.indexOf(field)
|
|
40
|
+
if (idx !== -1) {
|
|
41
|
+
_fields.splice(idx, 1)
|
|
42
|
+
}
|
|
43
|
+
_fields.push(field)
|
|
44
|
+
_fieldsRules[_fields[0]](value)
|
|
45
|
+
return { fields: _fields, fieldsRules: _fieldsRules, field, value }
|
|
30
46
|
}
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
// 加法 (1,2,3) = 6
|
|
49
|
+
// 加法 (1,2,3) = 6 or ([{a:1},{a:2}],'a') = 3
|
|
34
50
|
const add = function (...args) {
|
|
35
51
|
return new Math('add').result(...args)
|
|
36
52
|
}
|
|
@@ -45,11 +61,14 @@ const mul = function (...args) {
|
|
|
45
61
|
const div = function (...args) {
|
|
46
62
|
return new Math('div').result(...args)
|
|
47
63
|
}
|
|
48
|
-
|
|
64
|
+
const autoComputed = function (fields = [], fieldsRules = {}, field = '', value) {
|
|
65
|
+
return new Math().autoComputed(fields, fieldsRules, field, value)
|
|
66
|
+
}
|
|
49
67
|
export default {
|
|
50
68
|
add,
|
|
51
69
|
sub,
|
|
52
70
|
mul,
|
|
53
71
|
div,
|
|
72
|
+
autoComputed,
|
|
54
73
|
D: Decimal
|
|
55
74
|
}
|