xianniu-ui 0.3.11 → 0.3.12
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 +6509 -386
- package/lib/xianniu-ui.umd.js +6509 -386
- package/lib/xianniu-ui.umd.min.js +9 -2
- package/package.json +2 -1
- package/packages/download/index.js +7 -0
- package/packages/download/main.vue +47 -0
- package/src/index.js +4 -1
- package/src/utils/format.js +1 -0
- package/src/utils/index.js +4 -1
- package/src/utils/math.js +55 -0
- package/src/utils/utils.js +11 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xianniu-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "lib/xianniu-ui.umd.min.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"axios": "^0.26.0",
|
|
25
25
|
"core-js": "^3.6.5",
|
|
26
26
|
"dayjs": "^1.10.7",
|
|
27
|
+
"decimal.js": "^10.4.2",
|
|
27
28
|
"good-storage": "^1.1.1",
|
|
28
29
|
"lodash": "^4.17.21",
|
|
29
30
|
"vue": "2.6.11",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-link type="primary" icon="el-icon-download" @click="onDownload">{{
|
|
3
|
+
name
|
|
4
|
+
}}</el-link>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
name: "XnDownload",
|
|
10
|
+
props: {
|
|
11
|
+
url: {
|
|
12
|
+
type: String,
|
|
13
|
+
// default: "https://xianniu-file.oss-cn-beijing.aliyuncs.com/2022/10/28/a8b0cdfb63ce4a60981f4f5693f136a2.pdf",
|
|
14
|
+
default:
|
|
15
|
+
"https://xianniu-file.oss-cn-beijing.aliyuncs.com/2022/10/19/b2fc8900eac145a48d6f0b93ef1665fa.jpg",
|
|
16
|
+
},
|
|
17
|
+
name: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: "下载文件1",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
created() {
|
|
23
|
+
const arr = [{ num: 0.1 }, { num: 0.2 }];
|
|
24
|
+
console.log("aaaaa", this.$math.sub(arr, "num"));
|
|
25
|
+
console.log("aaaaa", this.$math.add(1, 2, 3, 4, 5, 345, 2, 23, 324, 5));
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
onDownload() {
|
|
29
|
+
return new Promise((res, rej) => {
|
|
30
|
+
try {
|
|
31
|
+
const config = {
|
|
32
|
+
url: this.url,
|
|
33
|
+
name: this.name,
|
|
34
|
+
};
|
|
35
|
+
this.$utils.download(config);
|
|
36
|
+
res();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
rej();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<style>
|
|
47
|
+
</style>
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import XnTree from '../packages/tree/index'
|
|
|
12
12
|
import XnImport from '../packages/import/index'
|
|
13
13
|
import XnExport from '../packages/export/index'
|
|
14
14
|
import XnFooter from '../packages/footer/index'
|
|
15
|
+
import XnDownload from '../packages/download/index'
|
|
15
16
|
|
|
16
17
|
import Utils from 'xn-ui/src/utils/index'
|
|
17
18
|
const doc = 'http://lzwr.gitee.io/xn-ui/#/'
|
|
@@ -28,7 +29,8 @@ const components = [
|
|
|
28
29
|
XnTree,
|
|
29
30
|
XnImport,
|
|
30
31
|
XnExport,
|
|
31
|
-
XnFooter
|
|
32
|
+
XnFooter,
|
|
33
|
+
XnDownload
|
|
32
34
|
]
|
|
33
35
|
const version = require('../package.json').version
|
|
34
36
|
if (process.env.NODE_ENV && process.env.NODE_ENV === 'development') {
|
|
@@ -51,6 +53,7 @@ const install = function (Vue) {
|
|
|
51
53
|
Vue.prototype.$dayjs = Utils.$dayjs
|
|
52
54
|
Vue.prototype.$storage = Utils.$storage
|
|
53
55
|
Vue.prototype.$lodash = Utils.$lodash
|
|
56
|
+
Vue.prototype.$math = Utils.$math
|
|
54
57
|
|
|
55
58
|
}
|
|
56
59
|
if (typeof window !== 'undefined' && window.Vue) {
|
package/src/utils/format.js
CHANGED
package/src/utils/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import dayjs from './dayjs'
|
|
|
5
5
|
import storage from './storage'
|
|
6
6
|
import utils from './utils'
|
|
7
7
|
import lodash from 'lodash'
|
|
8
|
+
import math from './math'
|
|
9
|
+
console.log('math: ', math);
|
|
8
10
|
const version = () => {
|
|
9
11
|
return `xianniu-tools@${require('./package.json').version}`
|
|
10
12
|
}
|
|
@@ -16,5 +18,6 @@ export default {
|
|
|
16
18
|
$dayjs: dayjs,
|
|
17
19
|
$lodash: lodash,
|
|
18
20
|
$storage: storage,
|
|
19
|
-
$utils: utils
|
|
21
|
+
$utils: utils,
|
|
22
|
+
$math: math
|
|
20
23
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
/*
|
|
3
|
+
方式一
|
|
4
|
+
@params 0 array 要计算的数组
|
|
5
|
+
@params 1 string 需要计算的key
|
|
6
|
+
return number 最终结果
|
|
7
|
+
方式二
|
|
8
|
+
@params number/string 需要计算的数值
|
|
9
|
+
return number 最终结果
|
|
10
|
+
*/
|
|
11
|
+
class Math {
|
|
12
|
+
constructor(type) {
|
|
13
|
+
this.type = type
|
|
14
|
+
}
|
|
15
|
+
result(...args) {
|
|
16
|
+
if (!args) {
|
|
17
|
+
throw new Error('error arguments')
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(args[0]) && args[1]) {
|
|
20
|
+
if (!args[0].length) return 0
|
|
21
|
+
const list = args[0]
|
|
22
|
+
const fieldKey = args[1]
|
|
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()
|
|
26
|
+
})
|
|
27
|
+
} else {
|
|
28
|
+
return args.reduce((pre, cur) => new Decimal(pre)[this.type](new Decimal(cur)).toNumber())
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 加法 (1,2,3) = 6
|
|
34
|
+
const add = function (...args) {
|
|
35
|
+
return new Math('add').result(...args)
|
|
36
|
+
}
|
|
37
|
+
// 减法
|
|
38
|
+
const sub = function (...args) {
|
|
39
|
+
return new Math('sub').result(...args)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const mul = function (...args) {
|
|
43
|
+
return new Math('mul').result(...args)
|
|
44
|
+
}
|
|
45
|
+
const div = function (...args) {
|
|
46
|
+
return new Math('div').result(...args)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
add,
|
|
51
|
+
sub,
|
|
52
|
+
mul,
|
|
53
|
+
div,
|
|
54
|
+
D: Decimal
|
|
55
|
+
}
|
package/src/utils/utils.js
CHANGED
|
@@ -69,11 +69,19 @@ const download = (params = { name: '', url: '' }) => {
|
|
|
69
69
|
var x = new XMLHttpRequest()
|
|
70
70
|
x.open('GET', url, true)
|
|
71
71
|
// x.responseType = 'blob'
|
|
72
|
+
// x.responseType = 'blob'
|
|
73
|
+
x.onprogress = function(){
|
|
74
|
+
}
|
|
72
75
|
x.onload = function () {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
var _url = ''
|
|
77
|
+
try {
|
|
78
|
+
_url = window.URL.createObjectURL(x.response)
|
|
79
|
+
} catch (error) {
|
|
80
|
+
_url = url
|
|
81
|
+
}
|
|
75
82
|
var a = document.createElement('a')
|
|
76
|
-
a.href =
|
|
83
|
+
a.href = _url
|
|
84
|
+
a.target = '_blank'
|
|
77
85
|
a.download = name
|
|
78
86
|
a.click()
|
|
79
87
|
}
|