xianniu-ui 0.3.14 → 0.3.16

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.3.14",
3
+ "version": "0.3.16",
4
4
  "private": false,
5
5
  "main": "lib/xianniu-ui.umd.min.js",
6
6
  "scripts": {
@@ -263,14 +263,8 @@ export default {
263
263
  },
264
264
  })
265
265
  .then((res) => {
266
- const { name, size, ext, imgFlag, url } = res.data.data;
267
- var obj = {};
268
- obj.name = name;
269
- obj.size = size;
270
- obj.ext = ext;
271
- obj.imgFlag = imgFlag;
272
- obj.url = url;
273
- this.successFiles.push(obj);
266
+ const { name, size, ext, imgFlag, url,fileId } = res.data.data;
267
+ this.successFiles.push({name,size,ext,imgFlag,url,fileId});
274
268
  file.onSuccess();
275
269
  this.$emit("update:fileList", this.successFiles);
276
270
  this.$emit("on-success", this.successFiles);
package/src/index.js CHANGED
@@ -31,9 +31,6 @@ const components = [
31
31
  XnFooter
32
32
  ]
33
33
  const version = require('../package.json').version
34
- if (process.env.NODE_ENV && process.env.NODE_ENV === 'development') {
35
- console.log(`doc:${doc}`);
36
- }
37
34
  const install = function (Vue) {
38
35
  if (install.installed) return
39
36
  if (!Vue.prototype.$ELEMENT) throw new Error('缺失 element-ui,请进行安装')
@@ -6,7 +6,6 @@ import storage from './storage'
6
6
  import utils from './utils'
7
7
  import lodash from 'lodash'
8
8
  import math from './math'
9
- console.log('math: ', math);
10
9
  const version = () => {
11
10
  return `xianniu-tools@${require('./package.json').version}`
12
11
  }
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) => new Decimal(pre)[this.type](new Decimal(cur)).toNumber())
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 = '') {
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]]()
45
+ return { fields: _fields, fieldsRules: _fieldsRules, field }
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 = '') {
65
+ return new Math().autoComputed(fields, fieldsRules, field)
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
  }