umy-ui-table 1.2.0
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/LICENSE +21 -0
- package/README.md +111 -0
- package/lib/button.js +1 -0
- package/lib/icon.js +1 -0
- package/lib/index.js +1 -0
- package/lib/locale/format.js +56 -0
- package/lib/locale/index.js +72 -0
- package/lib/locale/lang/en.js +123 -0
- package/lib/locale/lang/zh-CN.js +119 -0
- package/lib/mixins/locale.js +17 -0
- package/lib/theme-chalk/base.css +0 -0
- package/lib/theme-chalk/button.css +1 -0
- package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
- package/lib/theme-chalk/fonts/element-icons.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
- package/lib/theme-chalk/icon.css +1 -0
- package/lib/theme-chalk/index.css +1 -0
- package/lib/theme-chalk/u-table-column.css +0 -0
- package/lib/theme-chalk/u-table.css +1 -0
- package/lib/theme-chalk/ux-grid.css +1 -0
- package/lib/theme-chalk/ux-table-column.css +0 -0
- package/lib/u-table-column.js +1 -0
- package/lib/u-table.js +1 -0
- package/lib/umd/locale/en.js +139 -0
- package/lib/umd/locale/zh-CN.js +135 -0
- package/lib/umy-ui.common.js +1 -0
- package/lib/utils/svg.js +33 -0
- package/lib/utils/types.js +35 -0
- package/lib/utils/util.js +268 -0
- package/lib/ux-grid.js +1 -0
- package/lib/ux-table-column.js +1 -0
- package/package.json +117 -0
- package/packages/button/index.js +7 -0
- package/packages/button/src/button-group.vue +10 -0
- package/packages/button/src/button.vue +166 -0
- package/packages/checkbox/index.js +8 -0
- package/packages/checkbox/src/checkbox-button.vue +199 -0
- package/packages/checkbox/src/checkbox-group.vue +48 -0
- package/packages/checkbox/src/checkbox.vue +222 -0
- package/packages/checkbox-button/index.js +8 -0
- package/packages/checkbox-group/index.js +8 -0
- package/packages/icon/index.js +7 -0
- package/packages/icon/src/icon.vue +40 -0
- package/packages/input/index.js +2 -0
- package/packages/input/src/calcTextareaHeight.js +104 -0
- package/packages/input/src/input.vue +424 -0
- package/packages/option/index.js +2 -0
- package/packages/pagination/index.js +2 -0
- package/packages/pagination/src/pager.vue +163 -0
- package/packages/pagination/src/pagination.js +386 -0
- package/packages/scrollbar/index.js +8 -0
- package/packages/scrollbar/src/bar.js +92 -0
- package/packages/scrollbar/src/main.js +130 -0
- package/packages/scrollbar/src/util.js +34 -0
- package/packages/select/index.js +2 -0
- package/packages/select/src/navigation-mixin.js +54 -0
- package/packages/select/src/option-group.vue +60 -0
- package/packages/select/src/option.vue +163 -0
- package/packages/select/src/select-dropdown.vue +74 -0
- package/packages/select/src/select.vue +889 -0
- package/packages/table/index.js +8 -0
- package/packages/table/src/config.js +123 -0
- package/packages/table/src/dropdown.js +28 -0
- package/packages/table/src/filter-panel.vue +194 -0
- package/packages/table/src/layout-observer.js +68 -0
- package/packages/table/src/store/current.js +71 -0
- package/packages/table/src/store/expand.js +65 -0
- package/packages/table/src/store/helper.js +37 -0
- package/packages/table/src/store/index.js +145 -0
- package/packages/table/src/store/tree.js +208 -0
- package/packages/table/src/store/watcher.js +448 -0
- package/packages/table/src/table-body.js +493 -0
- package/packages/table/src/table-column.js +381 -0
- package/packages/table/src/table-footer.js +174 -0
- package/packages/table/src/table-header.js +537 -0
- package/packages/table/src/table-layout.js +231 -0
- package/packages/table/src/table.vue +741 -0
- package/packages/table/src/util.js +256 -0
- package/packages/tag/index.js +8 -0
- package/packages/tag/src/tag.vue +58 -0
- package/packages/tools/directives/mousewheel.js +18 -0
- package/packages/tools/directives/repeat-click.js +24 -0
- package/packages/tools/locale/format.js +46 -0
- package/packages/tools/locale/index.js +48 -0
- package/packages/tools/locale/lang/en.js +120 -0
- package/packages/tools/locale/lang/zh-CN.js +116 -0
- package/packages/tools/mixins/emitter.js +33 -0
- package/packages/tools/mixins/focus.js +9 -0
- package/packages/tools/mixins/locale.js +9 -0
- package/packages/tools/mixins/migrating.js +54 -0
- package/packages/tools/transitions/collapse-transition.js +77 -0
- package/packages/tools/utils/after-leave.js +27 -0
- package/packages/tools/utils/aria-dialog.js +90 -0
- package/packages/tools/utils/aria-utils.js +122 -0
- package/packages/tools/utils/clickoutside.js +76 -0
- package/packages/tools/utils/date-util.js +292 -0
- package/packages/tools/utils/date.js +368 -0
- package/packages/tools/utils/dom.js +227 -0
- package/packages/tools/utils/menu/aria-menubar.js +14 -0
- package/packages/tools/utils/menu/aria-menuitem.js +49 -0
- package/packages/tools/utils/menu/aria-submenu.js +59 -0
- package/packages/tools/utils/merge.js +15 -0
- package/packages/tools/utils/popper.js +1276 -0
- package/packages/tools/utils/popup/index.js +218 -0
- package/packages/tools/utils/popup/popup-manager.js +194 -0
- package/packages/tools/utils/resize-event.js +35 -0
- package/packages/tools/utils/scroll-into-view.js +27 -0
- package/packages/tools/utils/scrollbar-width.js +29 -0
- package/packages/tools/utils/shared.js +7 -0
- package/packages/tools/utils/svg.js +1 -0
- package/packages/tools/utils/types.js +28 -0
- package/packages/tools/utils/util.js +241 -0
- package/packages/tools/utils/vdom.js +5 -0
- package/packages/tools/utils/vue-popper.js +198 -0
- package/packages/tooltip/index.js +8 -0
- package/packages/tooltip/src/main.js +241 -0
- package/packages/u-table/index.js +4 -0
- package/packages/u-table/revise-el-table-mixins/index.js +10 -0
- package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
- package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
- package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
- package/packages/u-table/src/u-table.vue +248 -0
- package/packages/u-table/u-table-mixins/index.js +483 -0
- package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
- package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
- package/packages/u-table-column/index.js +8 -0
- package/packages/utils/common.js +27 -0
- package/packages/ux-grid/index.js +6 -0
- package/packages/ux-grid/mixins/index.js +707 -0
- package/packages/ux-grid/src/interceptor.js +6 -0
- package/packages/ux-grid/src/ux-grid.vue +301 -0
- package/packages/ux-table-column/index.js +10 -0
- package/tools/locale/format.js +46 -0
- package/tools/locale/index.js +54 -0
- package/tools/locale/lang/en.js +120 -0
- package/tools/locale/lang/zh-CN.js +116 -0
- package/tools/mixins/locale.js +9 -0
- package/tools/utils/svg.js +1 -0
- package/tools/utils/types.js +28 -0
- package/tools/utils/util.js +241 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { cellStarts, cellForced, defaultRenderCell, treeCellPrefix } from './config';
|
|
2
|
+
import { mergeOptions, parseWidth, parseMinWidth, compose } from './util';
|
|
3
|
+
import ElCheckbox from '../../checkbox';
|
|
4
|
+
|
|
5
|
+
let columnIdSeed = 1;
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: 'UTableColumn',
|
|
9
|
+
props: {
|
|
10
|
+
type: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: 'default'
|
|
13
|
+
},
|
|
14
|
+
borderLine: {
|
|
15
|
+
type: Boolean,
|
|
16
|
+
default: true
|
|
17
|
+
}, // 修改源码 表格右边线框
|
|
18
|
+
// 修改源码在某一列上加上展开树形数据的标识
|
|
19
|
+
treeNode: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
default: false
|
|
22
|
+
},
|
|
23
|
+
label: String,
|
|
24
|
+
className: String,
|
|
25
|
+
labelClassName: String,
|
|
26
|
+
property: String,
|
|
27
|
+
prop: String,
|
|
28
|
+
width: {},
|
|
29
|
+
minWidth: {},
|
|
30
|
+
renderHeader: Function,
|
|
31
|
+
sortable: {
|
|
32
|
+
type: [Boolean, String],
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
sortMethod: Function,
|
|
36
|
+
sortBy: [String, Function, Array],
|
|
37
|
+
resizable: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: true
|
|
40
|
+
},
|
|
41
|
+
columnKey: String,
|
|
42
|
+
align: String,
|
|
43
|
+
headerAlign: String,
|
|
44
|
+
showTooltipWhenOverflow: Boolean,
|
|
45
|
+
showOverflowTooltip: Boolean,
|
|
46
|
+
fixed: [Boolean, String],
|
|
47
|
+
formatter: Function,
|
|
48
|
+
selectable: Function,
|
|
49
|
+
reserveSelection: Boolean,
|
|
50
|
+
filterMethod: Function,
|
|
51
|
+
filteredValue: Array,
|
|
52
|
+
filters: Array,
|
|
53
|
+
filterPlacement: String,
|
|
54
|
+
filterMultiple: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: true
|
|
57
|
+
},
|
|
58
|
+
index: [Number, Function],
|
|
59
|
+
sortOrders: {
|
|
60
|
+
type: Array,
|
|
61
|
+
default() {
|
|
62
|
+
return ['ascending', 'descending', null];
|
|
63
|
+
},
|
|
64
|
+
validator(val) {
|
|
65
|
+
return val.every(order => ['ascending', 'descending', null].indexOf(order) > -1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
data() {
|
|
71
|
+
return {
|
|
72
|
+
isSubColumn: false,
|
|
73
|
+
columns: []
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
computed: {
|
|
78
|
+
owner() {
|
|
79
|
+
let parent = this.$parent;
|
|
80
|
+
while (parent && !parent.tableId) {
|
|
81
|
+
parent = parent.$parent;
|
|
82
|
+
}
|
|
83
|
+
return parent;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
columnOrTableParent() {
|
|
87
|
+
let parent = this.$parent;
|
|
88
|
+
while (parent && !parent.tableId && !parent.columnId) {
|
|
89
|
+
parent = parent.$parent;
|
|
90
|
+
}
|
|
91
|
+
return parent;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
realWidth() {
|
|
95
|
+
return parseWidth(this.width);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
realMinWidth() {
|
|
99
|
+
return parseMinWidth(this.minWidth);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
realAlign() {
|
|
103
|
+
return this.align ? 'is-' + this.align : null;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
realHeaderAlign() {
|
|
107
|
+
return this.headerAlign ? 'is-' + this.headerAlign : this.realAlign;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
methods: {
|
|
112
|
+
getPropsData(...props) {
|
|
113
|
+
return props.reduce((prev, cur) => {
|
|
114
|
+
if (Array.isArray(cur)) {
|
|
115
|
+
cur.forEach((key) => {
|
|
116
|
+
prev[key] = this[key];
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return prev;
|
|
120
|
+
}, {});
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
getColumnElIndex(children, child) {
|
|
124
|
+
return [].indexOf.call(children, child);
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
setColumnWidth(column) {
|
|
128
|
+
if (this.realWidth) {
|
|
129
|
+
column.width = this.realWidth;
|
|
130
|
+
}
|
|
131
|
+
if (this.realMinWidth) {
|
|
132
|
+
column.minWidth = this.realMinWidth;
|
|
133
|
+
}
|
|
134
|
+
if (!column.minWidth) {
|
|
135
|
+
column.minWidth = 80;
|
|
136
|
+
}
|
|
137
|
+
column.realWidth = column.width === undefined ? column.minWidth : column.width;
|
|
138
|
+
return column;
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
setColumnForcedProps(column) {
|
|
142
|
+
// 对于特定类型的 column,某些属性不允许设置
|
|
143
|
+
const type = column.type;
|
|
144
|
+
const source = cellForced[type] || {};
|
|
145
|
+
Object.keys(source).forEach(prop => {
|
|
146
|
+
let value = source[prop];
|
|
147
|
+
if (value !== undefined) {
|
|
148
|
+
column[prop] = prop === 'className' ? `${column[prop]} ${value}` : value;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return column;
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
setColumnRenders(column) {
|
|
155
|
+
const specialTypes = Object.keys(cellForced);
|
|
156
|
+
// renderHeader 属性不推荐使用。
|
|
157
|
+
if (this.renderHeader) {
|
|
158
|
+
console.warn('[Element Warn][TableColumn]Comparing to render-header, scoped-slot header is easier to use. We recommend users to use scoped-slot header.');
|
|
159
|
+
} else if (specialTypes.indexOf(column.type) === -1) {
|
|
160
|
+
column.renderHeader = (h, scope) => {
|
|
161
|
+
const renderHeader = this.$scopedSlots.header;
|
|
162
|
+
return renderHeader ? renderHeader(scope) : column.label;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let originRenderCell = column.renderCell;
|
|
167
|
+
// TODO: 这里的实现调整
|
|
168
|
+
if (column.type === 'expand') {
|
|
169
|
+
// 对于展开行,renderCell 不允许配置的。在上一步中已经设置过,这里需要简单封装一下。
|
|
170
|
+
column.renderCell = (h, data) => (<div class="cell">
|
|
171
|
+
{ originRenderCell(h, data) }
|
|
172
|
+
</div>);
|
|
173
|
+
this.owner.renderExpanded = (h, data) => {
|
|
174
|
+
return this.$scopedSlots.default
|
|
175
|
+
? this.$scopedSlots.default(data)
|
|
176
|
+
: this.$slots.default;
|
|
177
|
+
};
|
|
178
|
+
} else {
|
|
179
|
+
// 如果列存在cell渲染就使用originRenderCell,如果不存在就使用默认的取值
|
|
180
|
+
originRenderCell = originRenderCell || defaultRenderCell;
|
|
181
|
+
// 对 renderCell 进行包装
|
|
182
|
+
column.renderCell = (h, data) => {
|
|
183
|
+
let children = null;
|
|
184
|
+
// 是否列上存在插槽
|
|
185
|
+
if (this.$scopedSlots.default) {
|
|
186
|
+
children = this.$scopedSlots.default(data);
|
|
187
|
+
} else {
|
|
188
|
+
children = originRenderCell(h, data);
|
|
189
|
+
}
|
|
190
|
+
// console.log(data.column)
|
|
191
|
+
const prefix = treeCellPrefix(h, data);
|
|
192
|
+
const props = {
|
|
193
|
+
class: 'cell',
|
|
194
|
+
style: {}
|
|
195
|
+
};
|
|
196
|
+
let showEllipsis = ''
|
|
197
|
+
if (this.owner.showBodyOverflow) {
|
|
198
|
+
showEllipsis = this.owner.showBodyOverflow
|
|
199
|
+
// 如何开启了虚拟,虚拟滚动不支持动态高度
|
|
200
|
+
} else if (this.owner.useVirtual) {
|
|
201
|
+
showEllipsis = true
|
|
202
|
+
}
|
|
203
|
+
// 修改源码如下if语句,开启了超出隐藏
|
|
204
|
+
if (showEllipsis === 'tooltip' || column.showOverflowTooltip) {
|
|
205
|
+
props.class += ' el-tooltip';
|
|
206
|
+
props.style = {width: (data.column.realWidth || data.column.width) - 1 + 'px'};
|
|
207
|
+
} else if (showEllipsis) {
|
|
208
|
+
props.class += ' umy-table-beyond';
|
|
209
|
+
props.style = {width: (data.column.realWidth || data.column.width) - 1 + 'px'};
|
|
210
|
+
}
|
|
211
|
+
// 修改源码, 如果存在树点击,开启了树,那么久渲染展开图标
|
|
212
|
+
let row = data.row
|
|
213
|
+
const plTreeTable = this.owner
|
|
214
|
+
let {iconOpen, iconClose, iconLoaded = 'el-icon-loading'} = plTreeTable.treeOpts
|
|
215
|
+
let iconshow = false
|
|
216
|
+
// 如果不存在图标,就给默认值
|
|
217
|
+
if (!iconOpen && !iconClose) {
|
|
218
|
+
iconshow = true
|
|
219
|
+
iconOpen = 'el-icon-arrow-right'
|
|
220
|
+
iconClose = 'el-icon-arrow-right'
|
|
221
|
+
} else if (iconOpen && !iconClose) {
|
|
222
|
+
iconClose = 'el-icon-arrow-right'
|
|
223
|
+
} else if (!iconOpen && iconClose) {
|
|
224
|
+
iconOpen = 'el-icon-arrow-right'
|
|
225
|
+
}
|
|
226
|
+
if (plTreeTable.rowId && column.treeNode && plTreeTable.useVirtual) {
|
|
227
|
+
return (<div { ...props }>
|
|
228
|
+
<div class="cell--tree-node"
|
|
229
|
+
style={[{paddingLeft: (row.pl_table_level * plTreeTable.treeOpts.indent) + 'px'}]}>
|
|
230
|
+
{
|
|
231
|
+
(plTreeTable.treeOpts.lazy && plTreeTable.plTreeloading && row[plTreeTable.treeOpts.hasChildren])
|
|
232
|
+
? <div class="pltree-loading"><i class={[iconLoaded]}></i></div>
|
|
233
|
+
: (row[plTreeTable.treeOpts.children] && row[plTreeTable.treeOpts.children].length > 0) ||
|
|
234
|
+
(plTreeTable.treeOpts.lazy && row[plTreeTable.treeOpts.hasChildren])
|
|
235
|
+
? <div class={[{'tree--btn-wrapper-show': row.pl_table_expand && iconshow}, 'tree--btn-wrapper']}
|
|
236
|
+
on-click={($event) => this.owner.triggerTreeExpandEvent(row, 'default', $event)}>
|
|
237
|
+
{
|
|
238
|
+
(iconOpen && row.pl_table_expand) ? <i class={[iconOpen]}></i> : <i class={[iconClose]}></i>
|
|
239
|
+
}
|
|
240
|
+
</div>
|
|
241
|
+
: null
|
|
242
|
+
}
|
|
243
|
+
<div class="pl-tree-cell">{prefix}{children}</div>
|
|
244
|
+
</div>
|
|
245
|
+
</div>)
|
|
246
|
+
} else {
|
|
247
|
+
// 原始的el-table处理单元格信息
|
|
248
|
+
return (<div { ...props } title={[showEllipsis === 'title' && children ? children : '']}>
|
|
249
|
+
{ prefix }
|
|
250
|
+
{ children }
|
|
251
|
+
</div>)
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return column;
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
registerNormalWatchers() {
|
|
259
|
+
const props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip'];
|
|
260
|
+
// 一些属性具有别名
|
|
261
|
+
const aliases = {
|
|
262
|
+
prop: 'property',
|
|
263
|
+
realAlign: 'align',
|
|
264
|
+
realHeaderAlign: 'headerAlign',
|
|
265
|
+
realWidth: 'width'
|
|
266
|
+
};
|
|
267
|
+
const allAliases = props.reduce((prev, cur) => {
|
|
268
|
+
prev[cur] = cur;
|
|
269
|
+
return prev;
|
|
270
|
+
}, aliases);
|
|
271
|
+
|
|
272
|
+
Object.keys(allAliases).forEach(key => {
|
|
273
|
+
const columnKey = aliases[key];
|
|
274
|
+
|
|
275
|
+
this.$watch(key, (newVal) => {
|
|
276
|
+
this.columnConfig[columnKey] = newVal;
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
registerComplexWatchers() {
|
|
282
|
+
const props = ['fixed'];
|
|
283
|
+
const aliases = {
|
|
284
|
+
realWidth: 'width',
|
|
285
|
+
realMinWidth: 'minWidth'
|
|
286
|
+
};
|
|
287
|
+
const allAliases = props.reduce((prev, cur) => {
|
|
288
|
+
prev[cur] = cur;
|
|
289
|
+
return prev;
|
|
290
|
+
}, aliases);
|
|
291
|
+
|
|
292
|
+
Object.keys(allAliases).forEach(key => {
|
|
293
|
+
const columnKey = aliases[key];
|
|
294
|
+
|
|
295
|
+
this.$watch(key, (newVal) => {
|
|
296
|
+
this.columnConfig[columnKey] = newVal;
|
|
297
|
+
const updateColumns = columnKey === 'fixed';
|
|
298
|
+
this.owner.store.scheduleLayout(updateColumns);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
components: {
|
|
305
|
+
ElCheckbox
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
beforeCreate() {
|
|
309
|
+
this.row = {};
|
|
310
|
+
this.column = {};
|
|
311
|
+
this.$index = 0;
|
|
312
|
+
this.columnId = '';
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
created() {
|
|
316
|
+
const parent = this.columnOrTableParent;
|
|
317
|
+
this.isSubColumn = this.owner !== parent;
|
|
318
|
+
this.columnId = (parent.tableId || parent.columnId) + '_column_' + columnIdSeed++;
|
|
319
|
+
|
|
320
|
+
const type = this.type || 'default';
|
|
321
|
+
const sortable = this.sortable === '' ? true : this.sortable;
|
|
322
|
+
const defaults = {
|
|
323
|
+
...cellStarts[type],
|
|
324
|
+
id: this.columnId,
|
|
325
|
+
type: type,
|
|
326
|
+
property: this.prop || this.property,
|
|
327
|
+
align: this.realAlign,
|
|
328
|
+
headerAlign: this.realHeaderAlign,
|
|
329
|
+
showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
|
|
330
|
+
// filter 相关属性
|
|
331
|
+
filterable: this.filters || this.filterMethod,
|
|
332
|
+
filteredValue: [],
|
|
333
|
+
filterPlacement: '',
|
|
334
|
+
isColumnGroup: false,
|
|
335
|
+
filterOpened: false,
|
|
336
|
+
// sort 相关属性
|
|
337
|
+
sortable: sortable,
|
|
338
|
+
// index 列
|
|
339
|
+
index: this.index,
|
|
340
|
+
borderLine: this.borderLine,
|
|
341
|
+
treeNode: this.treeNode
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const basicProps = ['columnKey', 'label', 'className', 'labelClassName', 'type', 'renderHeader', 'formatter', 'fixed', 'resizable'];
|
|
345
|
+
const sortProps = ['sortMethod', 'sortBy', 'sortOrders'];
|
|
346
|
+
const selectProps = ['selectable', 'reserveSelection'];
|
|
347
|
+
const filterProps = ['filterMethod', 'filters', 'filterMultiple', 'filterOpened', 'filteredValue', 'filterPlacement'];
|
|
348
|
+
|
|
349
|
+
let column = this.getPropsData(basicProps, sortProps, selectProps, filterProps);
|
|
350
|
+
column = mergeOptions(defaults, column);
|
|
351
|
+
|
|
352
|
+
// 注意 compose 中函数执行的顺序是从右到左
|
|
353
|
+
const chains = compose(this.setColumnRenders, this.setColumnWidth, this.setColumnForcedProps);
|
|
354
|
+
column = chains(column);
|
|
355
|
+
|
|
356
|
+
this.columnConfig = column;
|
|
357
|
+
|
|
358
|
+
// 注册 watcher
|
|
359
|
+
this.registerNormalWatchers();
|
|
360
|
+
this.registerComplexWatchers();
|
|
361
|
+
},
|
|
362
|
+
|
|
363
|
+
mounted() {
|
|
364
|
+
const owner = this.owner;
|
|
365
|
+
const parent = this.columnOrTableParent;
|
|
366
|
+
const children = this.isSubColumn ? parent.$el.children : parent.$refs.hiddenColumns.children;
|
|
367
|
+
const columnIndex = this.getColumnElIndex(children, this.$el);
|
|
368
|
+
owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
destroyed() {
|
|
372
|
+
if (!this.$parent) return;
|
|
373
|
+
const parent = this.$parent;
|
|
374
|
+
this.owner.store.commit('removeColumn', this.columnConfig, this.isSubColumn ? parent.columnConfig : null);
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
render(h) {
|
|
378
|
+
// slots 也要渲染,需要计算合并表头
|
|
379
|
+
return h('div', this.$slots.default);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import LayoutObserver from './layout-observer';
|
|
2
|
+
import { mapStates } from './store/helper';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 字符串是否含有html标签的检测
|
|
6
|
+
* @param htmlStr
|
|
7
|
+
*/
|
|
8
|
+
function checkHtml (htmlStr) {
|
|
9
|
+
let reg = /<[^>]+>/g;
|
|
10
|
+
return reg.test(htmlStr);
|
|
11
|
+
}
|
|
12
|
+
export default {
|
|
13
|
+
name: 'ElTableFooter',
|
|
14
|
+
|
|
15
|
+
mixins: [LayoutObserver],
|
|
16
|
+
|
|
17
|
+
render(h) {
|
|
18
|
+
let sums = [];
|
|
19
|
+
if (this.summaryMethod) {
|
|
20
|
+
sums = this.summaryMethod({ columns: this.columns, data: this.store.states.data });
|
|
21
|
+
} else {
|
|
22
|
+
this.columns.forEach((column, index) => {
|
|
23
|
+
if (index === 0) {
|
|
24
|
+
sums[index] = this.sumText;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const values = this.store.states.data.map(item => Number(item[column.property]));
|
|
28
|
+
const precisions = [];
|
|
29
|
+
let notNumber = true;
|
|
30
|
+
values.forEach(value => {
|
|
31
|
+
if (!isNaN(value)) {
|
|
32
|
+
notNumber = false;
|
|
33
|
+
let decimal = ('' + value).split('.')[1];
|
|
34
|
+
precisions.push(decimal ? decimal.length : 0);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const precision = Math.max.apply(null, precisions);
|
|
38
|
+
if (!notNumber) {
|
|
39
|
+
sums[index] = values.reduce((prev, curr) => {
|
|
40
|
+
const value = Number(curr);
|
|
41
|
+
if (!isNaN(value)) {
|
|
42
|
+
return parseFloat((prev + curr).toFixed(Math.min(precision, 20)));
|
|
43
|
+
} else {
|
|
44
|
+
return prev;
|
|
45
|
+
}
|
|
46
|
+
}, 0);
|
|
47
|
+
} else {
|
|
48
|
+
sums[index] = '';
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return (
|
|
53
|
+
<table
|
|
54
|
+
class="el-table__footer"
|
|
55
|
+
cellspacing="0"
|
|
56
|
+
cellpadding="0"
|
|
57
|
+
border="0">
|
|
58
|
+
<colgroup>
|
|
59
|
+
{
|
|
60
|
+
this.columns.map(column => <col name={ column.id } key={column.id} />)
|
|
61
|
+
}
|
|
62
|
+
{
|
|
63
|
+
this.hasGutter ? <col name="gutter" /> : ''
|
|
64
|
+
}
|
|
65
|
+
</colgroup>
|
|
66
|
+
<tbody class={ [{ 'has-gutter': this.hasGutter }] }>
|
|
67
|
+
{
|
|
68
|
+
sums.map((itemSum, index) =>
|
|
69
|
+
<tr class={ index === sums.length - 1 ? '' : 'lineFooter' }>
|
|
70
|
+
{
|
|
71
|
+
this.columns.map((column, cellIndex) => <td
|
|
72
|
+
key={cellIndex}
|
|
73
|
+
colSpan={column.colSpan}
|
|
74
|
+
rowSpan={column.rowSpan}
|
|
75
|
+
class={this.getRowClasses(column, cellIndex)}>
|
|
76
|
+
{
|
|
77
|
+
checkHtml(itemSum[cellIndex])
|
|
78
|
+
? h(
|
|
79
|
+
'div',
|
|
80
|
+
{
|
|
81
|
+
class: ['cell', column.labelClassName],
|
|
82
|
+
// DOM 属性
|
|
83
|
+
domProps: {
|
|
84
|
+
innerHTML: itemSum[cellIndex]
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
[]
|
|
88
|
+
)
|
|
89
|
+
: <div class={['cell', column.labelClassName]}>{itemSum[cellIndex]}</div>
|
|
90
|
+
}
|
|
91
|
+
</td>)
|
|
92
|
+
}
|
|
93
|
+
{
|
|
94
|
+
this.hasGutter ? <th class="gutter"></th> : ''
|
|
95
|
+
}
|
|
96
|
+
</tr>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
</tbody>
|
|
100
|
+
</table>
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
props: {
|
|
105
|
+
fixed: String,
|
|
106
|
+
store: {
|
|
107
|
+
required: true
|
|
108
|
+
},
|
|
109
|
+
summaryMethod: Function,
|
|
110
|
+
sumText: String,
|
|
111
|
+
border: Boolean,
|
|
112
|
+
defaultSort: {
|
|
113
|
+
type: Object,
|
|
114
|
+
default() {
|
|
115
|
+
return {
|
|
116
|
+
prop: '',
|
|
117
|
+
order: ''
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
computed: {
|
|
124
|
+
table() {
|
|
125
|
+
return this.$parent;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
hasGutter() {
|
|
129
|
+
return !this.fixed && this.tableLayout.gutterWidth;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
...mapStates({
|
|
133
|
+
columns: 'columns',
|
|
134
|
+
isAllSelected: 'isAllSelected',
|
|
135
|
+
leftFixedLeafCount: 'fixedLeafColumnsLength',
|
|
136
|
+
rightFixedLeafCount: 'rightFixedLeafColumnsLength',
|
|
137
|
+
columnsCount: states => states.columns.length,
|
|
138
|
+
leftFixedCount: states => states.fixedColumns.length,
|
|
139
|
+
rightFixedCount: states => states.rightFixedColumns.length
|
|
140
|
+
})
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
methods: {
|
|
144
|
+
isCellHidden(index, columns, column) {
|
|
145
|
+
if (this.fixed === true || this.fixed === 'left') {
|
|
146
|
+
return index >= this.leftFixedLeafCount;
|
|
147
|
+
} else if (this.fixed === 'right') {
|
|
148
|
+
let before = 0;
|
|
149
|
+
for (let i = 0; i < index; i++) {
|
|
150
|
+
before += columns[i].colSpan;
|
|
151
|
+
}
|
|
152
|
+
return before < this.columnsCount - this.rightFixedLeafCount;
|
|
153
|
+
} else if (!this.fixed && column.fixed) { // hide cell when footer instance is not fixed and column is fixed
|
|
154
|
+
return true;
|
|
155
|
+
} else {
|
|
156
|
+
return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
getRowClasses(column, cellIndex) {
|
|
161
|
+
const classes = [column.id, column.align, column.labelClassName];
|
|
162
|
+
if (column.className) {
|
|
163
|
+
classes.push(column.className);
|
|
164
|
+
}
|
|
165
|
+
if (this.isCellHidden(cellIndex, this.columns, column)) {
|
|
166
|
+
classes.push('is-hidden');
|
|
167
|
+
}
|
|
168
|
+
if (!column.children) {
|
|
169
|
+
classes.push('is-leaf');
|
|
170
|
+
}
|
|
171
|
+
return classes;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|