n20-common-lib 1.3.29 → 1.3.32
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 +1 -1
- package/src/_qiankun/postMessage.js +10 -34
- package/src/assets/css/el-button.scss +1 -4
- package/src/assets/css/el-table.scss +0 -9
- package/src/components/ChildRange/index.vue +40 -37
- package/src/components/ChildRange/style.scss +28 -28
- package/src/components/EventBubble/index.vue +52 -0
- package/src/components/Filters/form-item-input.vue +186 -0
- package/src/components/Filters/index.vue +90 -246
- package/src/components/InputNumber/index.vue +10 -0
- package/src/components/Layout/SubContent/index.vue +2 -2
- package/src/components/ShowColumn/index.vue +54 -15
- package/src/components/Table/ThSelectHeader.vue +5 -5
- package/src/components/Table/filters.js +60 -0
- package/src/components/Table/index.vue +12 -137
- package/src/components/TableOperateColumn/OperateBtns.vue +73 -0
- package/src/components/TableOperateColumn/index.vue +26 -0
- package/src/directives/VTitle/index.js +5 -0
- package/src/index.js +3 -0
- package/src/plugins/CompatibleOld/index.js +4 -50
- package/src/utils/handleTab.js +109 -0
- package/src/utils/toExcel.js +92 -0
- package/style/index.css +1 -1
- package/style/index.css.map +1 -1
- package/theme/blue.css +1 -1
- package/theme/green.css +1 -1
- package/theme/lightBlue.css +1 -1
- package/theme/orange.css +1 -1
- package/theme/purple.css +1 -1
- package/theme/red.css +1 -1
- package/theme/yellow.css +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<el-table
|
|
3
|
-
v-if="!pageObj"
|
|
4
3
|
ref="el-table"
|
|
5
4
|
:header-cell-style="{ 'text-align': 'center' }"
|
|
6
5
|
:data="data"
|
|
@@ -25,68 +24,23 @@
|
|
|
25
24
|
:filters="item.filters | colftF(filtersMap)"
|
|
26
25
|
v-bind="item"
|
|
27
26
|
>
|
|
28
|
-
<template slot="header">
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/>
|
|
37
|
-
</span>
|
|
27
|
+
<template v-if="item.filterPre" slot="header">
|
|
28
|
+
{{ item.label }}
|
|
29
|
+
<th-select-header
|
|
30
|
+
:property="item.prop"
|
|
31
|
+
:data-list="dataList"
|
|
32
|
+
:check-list="checkList"
|
|
33
|
+
@selectChange="selectChange"
|
|
34
|
+
/>
|
|
38
35
|
</template>
|
|
39
36
|
</el-table-column>
|
|
40
37
|
</template>
|
|
41
38
|
</el-table>
|
|
42
|
-
|
|
43
|
-
<div v-else :style="{ height: heightW }">
|
|
44
|
-
<el-table
|
|
45
|
-
ref="el-table"
|
|
46
|
-
:header-cell-style="{ 'text-align': 'center' }"
|
|
47
|
-
style="width: 100%"
|
|
48
|
-
:data="data"
|
|
49
|
-
v-bind="$attrs"
|
|
50
|
-
:height="heightC"
|
|
51
|
-
v-on="$listeners"
|
|
52
|
-
>
|
|
53
|
-
<template v-for="(item, i) in columns">
|
|
54
|
-
<slot v-if="item.slotName" :name="item.slotName"></slot>
|
|
55
|
-
<el-table-column
|
|
56
|
-
v-else-if="item.render"
|
|
57
|
-
:key="'cl-table-' + i"
|
|
58
|
-
v-bind="item"
|
|
59
|
-
>
|
|
60
|
-
<columnRender
|
|
61
|
-
slot-scope="{ row }"
|
|
62
|
-
:c-render="item.render"
|
|
63
|
-
:row="row"
|
|
64
|
-
/>
|
|
65
|
-
</el-table-column>
|
|
66
|
-
<el-table-column
|
|
67
|
-
v-else
|
|
68
|
-
:key="'cl-table-' + i"
|
|
69
|
-
:formatter="item.formatter | colfF"
|
|
70
|
-
v-bind="item"
|
|
71
|
-
/>
|
|
72
|
-
</template>
|
|
73
|
-
</el-table>
|
|
74
|
-
<div v-if="pageObj" class="flex-box flex-r m-t-s">
|
|
75
|
-
<Pagination
|
|
76
|
-
:page-obj="pageObj"
|
|
77
|
-
:page-key="pageKey"
|
|
78
|
-
@change="(obj) => $emit('pageChange', obj)"
|
|
79
|
-
/>
|
|
80
|
-
</div>
|
|
81
|
-
</div>
|
|
82
39
|
</template>
|
|
83
40
|
|
|
84
41
|
<script>
|
|
85
|
-
import
|
|
86
|
-
import
|
|
87
|
-
import Pagination from '../Pagination/index.vue'
|
|
88
|
-
|
|
89
|
-
import ThSelectHeader from './ThSelectHeader.vue'
|
|
42
|
+
import thSelectHeader from './ThSelectHeader.vue'
|
|
43
|
+
import { colfF, colftF } from './filters'
|
|
90
44
|
|
|
91
45
|
const columnRender = {
|
|
92
46
|
props: {
|
|
@@ -102,69 +56,11 @@ const columnRender = {
|
|
|
102
56
|
}
|
|
103
57
|
}
|
|
104
58
|
|
|
105
|
-
function colfF(colf, map) {
|
|
106
|
-
if (typeof colf !== 'string') return colf
|
|
107
|
-
let sc = colf.split(/{.+?}/g) || []
|
|
108
|
-
let mc = colf.match(/{.+?}/g) || []
|
|
109
|
-
let mck = []
|
|
110
|
-
mc.forEach((t) => {
|
|
111
|
-
t = t.replace(/^{|\s+|}$/g, '').split('|')
|
|
112
|
-
mck.push(t)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
return (row) => tplFn(row, sc, mck, map)
|
|
116
|
-
}
|
|
117
|
-
function tplFn(row, sc, mck, map = {}) {
|
|
118
|
-
let str = ''
|
|
119
|
-
sc.forEach((s, i) => {
|
|
120
|
-
str += s
|
|
121
|
-
let kA = mck[i]
|
|
122
|
-
if (kA && kA.length) {
|
|
123
|
-
let key = kA[0]
|
|
124
|
-
if (kA.length === 1) {
|
|
125
|
-
str += row[key]
|
|
126
|
-
} else {
|
|
127
|
-
let type = kA[1]
|
|
128
|
-
switch (type) {
|
|
129
|
-
case 'money':
|
|
130
|
-
str += numerify(row[key], '0,0.00')
|
|
131
|
-
break
|
|
132
|
-
case 'rate':
|
|
133
|
-
str += numerify(row[key], '0.000000')
|
|
134
|
-
break
|
|
135
|
-
case 'map':
|
|
136
|
-
str += map[row[key]]
|
|
137
|
-
break
|
|
138
|
-
case 'date':
|
|
139
|
-
str += dayjs(row[key]).format('YYYY-MM-DD')
|
|
140
|
-
break
|
|
141
|
-
case 'datetime':
|
|
142
|
-
str += dayjs(row[key]).format('YYYY-MM-DD HH:mm:ss')
|
|
143
|
-
break
|
|
144
|
-
case 'time':
|
|
145
|
-
str += dayjs(row[key]).format('HH:mm:ss')
|
|
146
|
-
break
|
|
147
|
-
default:
|
|
148
|
-
str += row[key]
|
|
149
|
-
break
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
return str
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function colftF(colft, fMap) {
|
|
158
|
-
if (typeof colft !== 'string') return colft
|
|
159
|
-
return fMap[colft]
|
|
160
|
-
}
|
|
161
|
-
|
|
162
59
|
export default {
|
|
163
60
|
name: 'Table',
|
|
164
61
|
components: {
|
|
165
|
-
Pagination,
|
|
166
62
|
columnRender,
|
|
167
|
-
|
|
63
|
+
thSelectHeader
|
|
168
64
|
},
|
|
169
65
|
filters: {
|
|
170
66
|
colfF,
|
|
@@ -208,21 +104,6 @@ export default {
|
|
|
208
104
|
dataList: []
|
|
209
105
|
}
|
|
210
106
|
},
|
|
211
|
-
computed: {
|
|
212
|
-
heightW() {
|
|
213
|
-
if (this.height === undefined) {
|
|
214
|
-
return undefined
|
|
215
|
-
}
|
|
216
|
-
if (/\D/.test(this.height)) {
|
|
217
|
-
return this.height
|
|
218
|
-
} else {
|
|
219
|
-
return this.height + 'px'
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
heightC() {
|
|
223
|
-
return this.pageObj ? 'calc(100% - 38px)' : '100%'
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
107
|
created() {
|
|
227
108
|
this.dataList = JSON.parse(JSON.stringify(this.data))
|
|
228
109
|
for (let k in this.dataList[0]) {
|
|
@@ -230,17 +111,11 @@ export default {
|
|
|
230
111
|
}
|
|
231
112
|
for (let i in this.dataList) {
|
|
232
113
|
for (let k in this.dataList[i]) {
|
|
233
|
-
if (
|
|
234
|
-
this.checkList[k].findIndex((item) => item == this.dataList[i][k]) ==
|
|
235
|
-
-1
|
|
236
|
-
) {
|
|
114
|
+
if (!this.checkList[k].some((item) => item === this.dataList[i][k])) {
|
|
237
115
|
this.checkList[k].push(this.dataList[i][k])
|
|
238
116
|
}
|
|
239
117
|
}
|
|
240
118
|
}
|
|
241
|
-
if (this.column) {
|
|
242
|
-
console.warn('调整列顺序,请使用ShowColumn组件')
|
|
243
|
-
}
|
|
244
119
|
},
|
|
245
120
|
methods: {
|
|
246
121
|
selectChange(val) {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span>
|
|
3
|
+
<el-button
|
|
4
|
+
v-for="item in dfBtns"
|
|
5
|
+
:key="item.label"
|
|
6
|
+
type="text"
|
|
7
|
+
size="mini"
|
|
8
|
+
@click="$emit('command', item.command)"
|
|
9
|
+
>{{ item.label }}</el-button
|
|
10
|
+
>
|
|
11
|
+
<el-dropdown v-if="moreBtns.length" @command="(c) => $emit('command', c)">
|
|
12
|
+
<el-button class="n20-icon-moren" type="text" size="mini" />
|
|
13
|
+
<el-dropdown-menu slot="dropdown" class="text-c">
|
|
14
|
+
<el-dropdown-item
|
|
15
|
+
v-for="item in moreBtns"
|
|
16
|
+
:key="item.label"
|
|
17
|
+
:command="item.command"
|
|
18
|
+
>{{ item.label }}</el-dropdown-item
|
|
19
|
+
>
|
|
20
|
+
</el-dropdown-menu>
|
|
21
|
+
</el-dropdown>
|
|
22
|
+
</span>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script>
|
|
26
|
+
export default {
|
|
27
|
+
props: {
|
|
28
|
+
btnList: {
|
|
29
|
+
type: Array,
|
|
30
|
+
default: () => []
|
|
31
|
+
},
|
|
32
|
+
row: {
|
|
33
|
+
type: Object,
|
|
34
|
+
default: () => ({})
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
data() {
|
|
38
|
+
return {}
|
|
39
|
+
},
|
|
40
|
+
computed: {
|
|
41
|
+
hasBtns() {
|
|
42
|
+
return this.btnList.filter((btn) => this.hasBtn(btn.isHas, this.row))
|
|
43
|
+
},
|
|
44
|
+
dfBtns() {
|
|
45
|
+
if (this.hasBtns.length > 3) {
|
|
46
|
+
return this.hasBtns.slice(0, 2)
|
|
47
|
+
} else {
|
|
48
|
+
return this.hasBtns
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
moreBtns() {
|
|
52
|
+
if (this.hasBtns.length > 3) {
|
|
53
|
+
return this.hasBtns.slice(2)
|
|
54
|
+
} else {
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
methods: {
|
|
60
|
+
hasBtn(isHas, row) {
|
|
61
|
+
if (isHas === undefined || isHas === null) {
|
|
62
|
+
return true
|
|
63
|
+
} else if (typeof isHas === 'boolean') {
|
|
64
|
+
return isHas
|
|
65
|
+
} else if (typeof isHas === 'string' || Array.isArray(isHas)) {
|
|
66
|
+
return this.$has(isHas)
|
|
67
|
+
} else if (typeof isHas === 'function') {
|
|
68
|
+
return isHas(row)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-table-column v-bind="$attrs">
|
|
3
|
+
<OperateBtns
|
|
4
|
+
slot-scope="{ row, $index }"
|
|
5
|
+
:btn-list="btnList"
|
|
6
|
+
:row="row"
|
|
7
|
+
@command="(c) => $emit(c, row, $index)"
|
|
8
|
+
/>
|
|
9
|
+
</el-table-column>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import OperateBtns from './OperateBtns.vue'
|
|
14
|
+
export default {
|
|
15
|
+
name: 'TableOperateColumn',
|
|
16
|
+
components: {
|
|
17
|
+
OperateBtns
|
|
18
|
+
},
|
|
19
|
+
props: {
|
|
20
|
+
btnList: {
|
|
21
|
+
type: Array,
|
|
22
|
+
default: () => []
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Popover as elPopover } from 'element-ui'
|
|
2
|
+
|
|
1
3
|
let timer = undefined
|
|
2
4
|
const popClass = 'at-title-pop-' + Date.now()
|
|
3
5
|
|
|
@@ -44,6 +46,9 @@ TitleDirective.install = (Vue) => {
|
|
|
44
46
|
if (Vue.prototype.$isServer) return
|
|
45
47
|
const tooltip = new Vue({
|
|
46
48
|
el: document.createElement('div'),
|
|
49
|
+
components: {
|
|
50
|
+
elPopover
|
|
51
|
+
},
|
|
47
52
|
data() {
|
|
48
53
|
return {
|
|
49
54
|
visible: false
|
package/src/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import FileUploadTable from './components/FileUploadTable/index.vue'
|
|
|
35
35
|
import FooterBox from './components/FooterBox/index.vue'
|
|
36
36
|
import Filters from './components/Filters/index.vue'
|
|
37
37
|
import Table from './components/Table/index.vue'
|
|
38
|
+
import TableOperateColumn from './components/TableOperateColumn/index.vue'
|
|
38
39
|
import Button from './components/Button/index.vue'
|
|
39
40
|
import ButtonGroup from './components/Button/button-group.vue'
|
|
40
41
|
import ShowColumn from './components/ShowColumn/index.vue'
|
|
@@ -124,6 +125,7 @@ const components = [
|
|
|
124
125
|
FooterBox,
|
|
125
126
|
Filters,
|
|
126
127
|
Table,
|
|
128
|
+
TableOperateColumn,
|
|
127
129
|
Button,
|
|
128
130
|
ButtonGroup,
|
|
129
131
|
ShowColumn,
|
|
@@ -232,6 +234,7 @@ export {
|
|
|
232
234
|
FooterBox,
|
|
233
235
|
Filters,
|
|
234
236
|
Table,
|
|
237
|
+
TableOperateColumn,
|
|
235
238
|
Button,
|
|
236
239
|
ButtonGroup,
|
|
237
240
|
ShowColumn,
|
|
@@ -1,57 +1,11 @@
|
|
|
1
|
+
import { setTabs, closeTag } from '../../utils/handleTab.js'
|
|
2
|
+
|
|
1
3
|
// 老系统子应用调用函数,新增页签的函数接口
|
|
2
4
|
export function setTabsForSub(baseUrl, to, tab = true) {
|
|
3
|
-
|
|
4
|
-
let _path = baseUrl + path
|
|
5
|
-
_path = _path.replace('//', '/')
|
|
6
|
-
let _i18n
|
|
7
|
-
let _title
|
|
8
|
-
|
|
9
|
-
let { title, i18n } = meta
|
|
10
|
-
if (i18n && typeof i18n === 'object') {
|
|
11
|
-
_i18n = i18n
|
|
12
|
-
} else if (title && typeof title === 'object') {
|
|
13
|
-
_i18n = title
|
|
14
|
-
} else if (name && typeof name === 'object') {
|
|
15
|
-
_i18n = name
|
|
16
|
-
}
|
|
17
|
-
if (_i18n && _i18n.zh) {
|
|
18
|
-
_title = _i18n.zh
|
|
19
|
-
} else {
|
|
20
|
-
_title = title
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (tab) {
|
|
24
|
-
window.postMessage({
|
|
25
|
-
addTabO: {
|
|
26
|
-
path: _path,
|
|
27
|
-
title: _title,
|
|
28
|
-
i18n: _i18n,
|
|
29
|
-
query: query
|
|
30
|
-
},
|
|
31
|
-
targetName: 'main',
|
|
32
|
-
originName: name
|
|
33
|
-
})
|
|
34
|
-
} else {
|
|
35
|
-
window.postMessage({
|
|
36
|
-
replaceTab: {
|
|
37
|
-
path: _path,
|
|
38
|
-
title: _title,
|
|
39
|
-
i18n: _i18n,
|
|
40
|
-
query: query
|
|
41
|
-
},
|
|
42
|
-
targetName: 'main',
|
|
43
|
-
originName: name
|
|
44
|
-
})
|
|
45
|
-
}
|
|
5
|
+
setTabs(baseUrl, to, tab)
|
|
46
6
|
}
|
|
47
7
|
|
|
48
8
|
// 老系统子应用调用函数,关闭页签的函数接口
|
|
49
9
|
export function closeTagsForBackPage(url) {
|
|
50
|
-
|
|
51
|
-
closeTab: {
|
|
52
|
-
path: url || window.location.pathname
|
|
53
|
-
},
|
|
54
|
-
targetName: 'main',
|
|
55
|
-
originName: '*'
|
|
56
|
-
})
|
|
10
|
+
closeTag(url)
|
|
57
11
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// 操作切换路由生成的页签
|
|
2
|
+
const dN = process.env.VUE_APP_NAME
|
|
3
|
+
/** 打开页签,push对应路由 */
|
|
4
|
+
export function addTab(opt = {}, name) {
|
|
5
|
+
window.postMessage({
|
|
6
|
+
addTab: opt,
|
|
7
|
+
targetName: 'main',
|
|
8
|
+
originName: name || dN
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
/** 子打开页签,不再push对应路由 */
|
|
12
|
+
export function addTabO(opt = {}, name) {
|
|
13
|
+
window.postMessage({
|
|
14
|
+
addTabO: opt,
|
|
15
|
+
targetName: 'main',
|
|
16
|
+
originName: name || dN
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function closeTab(opt = {}, name) {
|
|
21
|
+
window.postMessage({
|
|
22
|
+
closeTab: opt,
|
|
23
|
+
targetName: 'main',
|
|
24
|
+
originName: name || dN
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function setTabName(opt = {}, name) {
|
|
29
|
+
window.postMessage({
|
|
30
|
+
setTabName: opt,
|
|
31
|
+
targetName: 'main',
|
|
32
|
+
originName: name || dN
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function refreshTab(opt = {}, name) {
|
|
37
|
+
window.postMessage({
|
|
38
|
+
refreshTab: opt,
|
|
39
|
+
targetName: 'main',
|
|
40
|
+
originName: name || dN
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
/** 不打开页签,替换当前页签保存的路由信息 */
|
|
44
|
+
export function replaceTab(opt = {}, name) {
|
|
45
|
+
window.postMessage({
|
|
46
|
+
replaceTab: opt,
|
|
47
|
+
targetName: 'main',
|
|
48
|
+
originName: name || dN
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* 业务应用 */
|
|
53
|
+
// 获取页签名称
|
|
54
|
+
function getI18n(meta = {}, name) {
|
|
55
|
+
let _i18n = undefined
|
|
56
|
+
let { title, i18n } = meta
|
|
57
|
+
|
|
58
|
+
if (i18n && typeof i18n === 'object') {
|
|
59
|
+
_i18n = i18n
|
|
60
|
+
} else if (title && typeof title === 'object') {
|
|
61
|
+
_i18n = title
|
|
62
|
+
} else if (name && typeof name === 'object') {
|
|
63
|
+
_i18n = name
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
i18n: _i18n,
|
|
67
|
+
title: _i18n && _i18n.zh ? _i18n.zh : title
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// 获取绝对路径
|
|
71
|
+
function getPath(baseUrl, path) {
|
|
72
|
+
return (baseUrl + path).replace('//', '/')
|
|
73
|
+
}
|
|
74
|
+
// 获取模块名称
|
|
75
|
+
function getName(baseUrl) {
|
|
76
|
+
return dN || baseUrl.replace('/', '')
|
|
77
|
+
}
|
|
78
|
+
/** 子模块在门户中打开页签 */
|
|
79
|
+
export function setTabs(baseUrl, to, tab = true) {
|
|
80
|
+
let { path, name, meta = {}, query } = to
|
|
81
|
+
let { i18n, title } = getI18n(meta, name)
|
|
82
|
+
let route = getPath(baseUrl, path)
|
|
83
|
+
|
|
84
|
+
if (tab) {
|
|
85
|
+
addTabO(
|
|
86
|
+
{
|
|
87
|
+
path: route,
|
|
88
|
+
title: title,
|
|
89
|
+
i18n: i18n,
|
|
90
|
+
query: query
|
|
91
|
+
},
|
|
92
|
+
getName(baseUrl)
|
|
93
|
+
)
|
|
94
|
+
} else {
|
|
95
|
+
replaceTab(
|
|
96
|
+
{
|
|
97
|
+
path: route,
|
|
98
|
+
title: title,
|
|
99
|
+
i18n: i18n,
|
|
100
|
+
query: query
|
|
101
|
+
},
|
|
102
|
+
getName(baseUrl)
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** 子模块关闭在门户中的页签 */
|
|
107
|
+
export function closeTag(url, name) {
|
|
108
|
+
closeTab({ path: url || window.location.pathname }, name || '*')
|
|
109
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import ExcelJS from 'exceljs'
|
|
2
|
+
|
|
3
|
+
function toExcel({ columns = [], rows = [], name = 'sheet01' }) {
|
|
4
|
+
let cols = []
|
|
5
|
+
columns.forEach((col) => {
|
|
6
|
+
if (!col.static) {
|
|
7
|
+
let _col = {
|
|
8
|
+
header: col.label,
|
|
9
|
+
key: col.prop,
|
|
10
|
+
style: col.style || {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let width = col.width || col.minWidth || col['min-width'] || 0
|
|
14
|
+
width = Math.max(width / 8, col.label.length * 2.2 + 2)
|
|
15
|
+
width > 9 && (_col.width = width)
|
|
16
|
+
|
|
17
|
+
if (col.numFmt) {
|
|
18
|
+
_col.style.numFmt = col.numFmt
|
|
19
|
+
} else if (col.formatter && typeof col.formatter === 'string') {
|
|
20
|
+
if (/\|\s?money/.test(col.formatter)) {
|
|
21
|
+
_col.style.numFmt = '#,##0.00'
|
|
22
|
+
}
|
|
23
|
+
if (/\|\s?rate/.test(col.formatter)) {
|
|
24
|
+
_col.style.numFmt = '0.000000'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
cols.push(_col)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
let cL = cols.length
|
|
33
|
+
let rL = rows.length
|
|
34
|
+
|
|
35
|
+
const workbook = new ExcelJS.Workbook()
|
|
36
|
+
const worksheet = workbook.addWorksheet(name)
|
|
37
|
+
|
|
38
|
+
worksheet.columns = cols
|
|
39
|
+
worksheet.addRows(rows)
|
|
40
|
+
|
|
41
|
+
worksheet.views = [
|
|
42
|
+
{
|
|
43
|
+
state: 'frozen',
|
|
44
|
+
// xSplit: 1,
|
|
45
|
+
ySplit: 1
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < cL; i++) {
|
|
50
|
+
worksheet.getCell(1, i + 1).style = {
|
|
51
|
+
fill: {
|
|
52
|
+
type: 'pattern',
|
|
53
|
+
pattern: 'solid',
|
|
54
|
+
fgColor: { argb: 'FFE1E1E1' }
|
|
55
|
+
},
|
|
56
|
+
alignment: {
|
|
57
|
+
vertical: 'middle',
|
|
58
|
+
horizontal: 'center'
|
|
59
|
+
},
|
|
60
|
+
font: {
|
|
61
|
+
bold: true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < cL; i++) {
|
|
67
|
+
for (let j = 0; j < rL + 1; j++) {
|
|
68
|
+
worksheet.getCell(j + 1, i + 1).border = {
|
|
69
|
+
top: { style: 'thin' },
|
|
70
|
+
left: { style: 'thin' },
|
|
71
|
+
bottom: { style: 'thin' },
|
|
72
|
+
right: { style: 'thin' }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// worksheet.getColumn(1).numFmt = '#,##0.00"%"'
|
|
78
|
+
// worksheet.getColumn(1).numFmt = '#,##0.00'
|
|
79
|
+
// worksheet.getColumn(2).width = 32
|
|
80
|
+
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
workbook.xlsx
|
|
83
|
+
.writeBuffer()
|
|
84
|
+
.then((buffer) => {
|
|
85
|
+
resolve(buffer)
|
|
86
|
+
})
|
|
87
|
+
.catch((err) => {
|
|
88
|
+
reject(err)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
export default toExcel
|