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,537 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import { hasClass, addClass, removeClass } from '../../tools/utils/dom';
|
|
3
|
+
import ElCheckbox from '../../checkbox';
|
|
4
|
+
import FilterPanel from './filter-panel.vue';
|
|
5
|
+
import LayoutObserver from './layout-observer';
|
|
6
|
+
import { mapStates } from './store/helper';
|
|
7
|
+
|
|
8
|
+
const getAllColumns = (columns) => {
|
|
9
|
+
const result = [];
|
|
10
|
+
columns.forEach((column) => {
|
|
11
|
+
if (column.children) {
|
|
12
|
+
result.push(column);
|
|
13
|
+
result.push.apply(result, getAllColumns(column.children));
|
|
14
|
+
} else {
|
|
15
|
+
result.push(column);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const convertToRows = (originColumns) => {
|
|
22
|
+
let maxLevel = 1;
|
|
23
|
+
const traverse = (column, parent) => {
|
|
24
|
+
if (parent) {
|
|
25
|
+
column.level = parent.level + 1;
|
|
26
|
+
if (maxLevel < column.level) {
|
|
27
|
+
maxLevel = column.level;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (column.children) {
|
|
31
|
+
let colSpan = 0;
|
|
32
|
+
column.children.forEach((subColumn) => {
|
|
33
|
+
traverse(subColumn, column);
|
|
34
|
+
colSpan += subColumn.colSpan;
|
|
35
|
+
});
|
|
36
|
+
column.colSpan = colSpan;
|
|
37
|
+
} else {
|
|
38
|
+
column.colSpan = 1;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
originColumns.forEach((column) => {
|
|
43
|
+
column.level = 1;
|
|
44
|
+
traverse(column);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const rows = [];
|
|
48
|
+
for (let i = 0; i < maxLevel; i++) {
|
|
49
|
+
rows.push([]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const allColumns = getAllColumns(originColumns);
|
|
53
|
+
|
|
54
|
+
allColumns.forEach((column) => {
|
|
55
|
+
if (!column.children) {
|
|
56
|
+
column.rowSpan = maxLevel - column.level + 1;
|
|
57
|
+
} else {
|
|
58
|
+
column.rowSpan = 1;
|
|
59
|
+
}
|
|
60
|
+
rows[column.level - 1].push(column);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return rows;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
name: 'ElTableHeader',
|
|
68
|
+
|
|
69
|
+
mixins: [LayoutObserver],
|
|
70
|
+
|
|
71
|
+
render(h) {
|
|
72
|
+
const originColumns = this.store.states.originColumns;
|
|
73
|
+
const columnRows = convertToRows(originColumns, this.columns);
|
|
74
|
+
// 是否拥有多级表头
|
|
75
|
+
const isGroup = columnRows.length > 1;
|
|
76
|
+
if (isGroup) this.$parent.isGroup = true;
|
|
77
|
+
return (
|
|
78
|
+
<table
|
|
79
|
+
class="el-table__header"
|
|
80
|
+
cellspacing="0"
|
|
81
|
+
cellpadding="0"
|
|
82
|
+
border="0">
|
|
83
|
+
<colgroup>
|
|
84
|
+
{
|
|
85
|
+
this.columns.map(column => <col name={ column.id } key={column.id} />)
|
|
86
|
+
}
|
|
87
|
+
{
|
|
88
|
+
this.hasGutter ? <col name="gutter" /> : ''
|
|
89
|
+
}
|
|
90
|
+
</colgroup>
|
|
91
|
+
<thead class={ [{ 'is-group': isGroup, 'has-gutter': this.hasGutter }] }>
|
|
92
|
+
{
|
|
93
|
+
this._l(columnRows, (columns, rowIndex) =>
|
|
94
|
+
<tr
|
|
95
|
+
style={ this.getHeaderRowStyle(rowIndex) }
|
|
96
|
+
class={ this.getHeaderRowClass(rowIndex) }
|
|
97
|
+
>
|
|
98
|
+
{
|
|
99
|
+
columns.map((column, cellIndex) => (<th
|
|
100
|
+
colspan={ column.colSpan }
|
|
101
|
+
rowspan={ column.rowSpan }
|
|
102
|
+
on-mousemove={ ($event) => this.handleMouseMove($event, column) }
|
|
103
|
+
on-mouseout={ this.handleMouseOut }
|
|
104
|
+
on-mousedown={ ($event) => this.handleMouseDown($event, column) }
|
|
105
|
+
on-click={ ($event) => this.handleHeaderClick($event, column) }
|
|
106
|
+
on-contextmenu={ ($event) => this.handleHeaderContextMenu($event, column) }
|
|
107
|
+
style={ this.getHeaderCellStyle(rowIndex, cellIndex, columns, column) }
|
|
108
|
+
class={ this.getHeaderCellClass(rowIndex, cellIndex, columns, column) }
|
|
109
|
+
key={ column.id }>
|
|
110
|
+
{/*修改源码 添加拖动图标*/}
|
|
111
|
+
{
|
|
112
|
+
this.$parent.headerDragStyle && column.borderLine
|
|
113
|
+
? <span class={!column.resizable ? 'pltableDragIcon': 'pltableDragIconHover pltableDragIcon'}> <i></i> </span>
|
|
114
|
+
: ''
|
|
115
|
+
}
|
|
116
|
+
{/*修改源码 当列的宽度小于内容了,不要换行显示,超出就省略符合 所以添加了个类pl-table-beyond*/}
|
|
117
|
+
<div
|
|
118
|
+
title={[column.label && this.$parent.showHeaderOverflow === 'title' ? column.label : '']}
|
|
119
|
+
class={[
|
|
120
|
+
'cell',
|
|
121
|
+
this.$parent.showHeaderOverflow ? 'umy-table-beyond' : '',
|
|
122
|
+
column.filteredValue && column.filteredValue.length > 0 ? 'highlight' : '',
|
|
123
|
+
column.labelClassName] }>
|
|
124
|
+
{
|
|
125
|
+
column.renderHeader
|
|
126
|
+
? column.renderHeader.call(this._renderProxy, h, { column, $index: cellIndex, store: this.store, _self: this.$parent.$vnode.context })
|
|
127
|
+
: column.label
|
|
128
|
+
}
|
|
129
|
+
{
|
|
130
|
+
column.sortable ? (<span
|
|
131
|
+
class="caret-wrapper"
|
|
132
|
+
on-click={ ($event) => this.handleSortClick($event, column) }>
|
|
133
|
+
<i class="sort-caret ascending"
|
|
134
|
+
on-click={ ($event) => this.handleSortClick($event, column, 'ascending') }>
|
|
135
|
+
</i>
|
|
136
|
+
<i class="sort-caret descending"
|
|
137
|
+
on-click={ ($event) => this.handleSortClick($event, column, 'descending') }>
|
|
138
|
+
</i>
|
|
139
|
+
</span>) : ''
|
|
140
|
+
}
|
|
141
|
+
{
|
|
142
|
+
column.filterable ? (<span
|
|
143
|
+
class="el-table__column-filter-trigger"
|
|
144
|
+
on-click={ ($event) => this.handleFilterClick($event, column) }>
|
|
145
|
+
<i class={ ['el-icon-arrow-down', column.filterOpened ? 'el-icon-arrow-up' : ''] }></i>
|
|
146
|
+
</span>) : ''
|
|
147
|
+
}
|
|
148
|
+
</div>
|
|
149
|
+
</th>))
|
|
150
|
+
}
|
|
151
|
+
{
|
|
152
|
+
this.hasGutter ? <th class="gutter"></th> : ''
|
|
153
|
+
}
|
|
154
|
+
</tr>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
</thead>
|
|
158
|
+
</table>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
props: {
|
|
163
|
+
fixed: String,
|
|
164
|
+
store: {
|
|
165
|
+
required: true
|
|
166
|
+
},
|
|
167
|
+
border: Boolean,
|
|
168
|
+
defaultSort: {
|
|
169
|
+
type: Object,
|
|
170
|
+
default() {
|
|
171
|
+
return {
|
|
172
|
+
prop: '',
|
|
173
|
+
order: ''
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
components: {
|
|
180
|
+
ElCheckbox
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
computed: {
|
|
184
|
+
table() {
|
|
185
|
+
return this.$parent;
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
hasGutter() {
|
|
189
|
+
return !this.fixed && this.tableLayout.gutterWidth;
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
...mapStates({
|
|
193
|
+
columns: 'columns',
|
|
194
|
+
isAllSelected: 'isAllSelected',
|
|
195
|
+
leftFixedLeafCount: 'fixedLeafColumnsLength',
|
|
196
|
+
rightFixedLeafCount: 'rightFixedLeafColumnsLength',
|
|
197
|
+
columnsCount: states => states.columns.length,
|
|
198
|
+
leftFixedCount: states => states.fixedColumns.length,
|
|
199
|
+
rightFixedCount: states => states.rightFixedColumns.length
|
|
200
|
+
})
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
created() {
|
|
204
|
+
this.filterPanels = {};
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
mounted() {
|
|
208
|
+
// nextTick 是有必要的 https://github.com/ElemeFE/element/pull/11311
|
|
209
|
+
this.$nextTick(() => {
|
|
210
|
+
const { prop, order } = this.defaultSort;
|
|
211
|
+
const init = true;
|
|
212
|
+
this.store.commit('sort', { prop, order, init });
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
beforeDestroy() {
|
|
217
|
+
const panels = this.filterPanels;
|
|
218
|
+
for (let prop in panels) {
|
|
219
|
+
if (panels.hasOwnProperty(prop) && panels[prop]) {
|
|
220
|
+
panels[prop].$destroy(true);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
methods: {
|
|
226
|
+
isCellHidden(index, columns) {
|
|
227
|
+
let start = 0;
|
|
228
|
+
for (let i = 0; i < index; i++) {
|
|
229
|
+
start += columns[i].colSpan;
|
|
230
|
+
}
|
|
231
|
+
const after = start + columns[index].colSpan - 1;
|
|
232
|
+
if (this.fixed === true || this.fixed === 'left') {
|
|
233
|
+
return after >= this.leftFixedLeafCount;
|
|
234
|
+
} else if (this.fixed === 'right') {
|
|
235
|
+
return start < this.columnsCount - this.rightFixedLeafCount;
|
|
236
|
+
} else {
|
|
237
|
+
return (after < this.leftFixedLeafCount) || (start >= this.columnsCount - this.rightFixedLeafCount);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
getHeaderRowStyle(rowIndex) {
|
|
242
|
+
const headerRowStyle = this.table.headerRowStyle;
|
|
243
|
+
if (typeof headerRowStyle === 'function') {
|
|
244
|
+
return headerRowStyle.call(null, { rowIndex });
|
|
245
|
+
}
|
|
246
|
+
return headerRowStyle;
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
getHeaderRowClass(rowIndex) {
|
|
250
|
+
const classes = [];
|
|
251
|
+
|
|
252
|
+
const headerRowClassName = this.table.headerRowClassName;
|
|
253
|
+
if (typeof headerRowClassName === 'string') {
|
|
254
|
+
classes.push(headerRowClassName);
|
|
255
|
+
} else if (typeof headerRowClassName === 'function') {
|
|
256
|
+
classes.push(headerRowClassName.call(null, { rowIndex }));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return classes.join(' ');
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
getHeaderCellStyle(rowIndex, columnIndex, row, column) {
|
|
263
|
+
const headerCellStyle = this.table.headerCellStyle;
|
|
264
|
+
if (typeof headerCellStyle === 'function') {
|
|
265
|
+
return headerCellStyle.call(null, {
|
|
266
|
+
rowIndex,
|
|
267
|
+
columnIndex,
|
|
268
|
+
row,
|
|
269
|
+
column
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return headerCellStyle;
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
getHeaderCellClass(rowIndex, columnIndex, row, column) {
|
|
276
|
+
const classes = [column.id, column.order, column.headerAlign, column.className, column.labelClassName];
|
|
277
|
+
|
|
278
|
+
if (rowIndex === 0 && this.isCellHidden(columnIndex, row)) {
|
|
279
|
+
classes.push('is-hidden');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// 修改源码头部右边的边框线
|
|
283
|
+
if (this.$parent.headerDragStyle) {
|
|
284
|
+
classes.push('umy-table-header-border-right-none-th');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!column.children) {
|
|
288
|
+
classes.push('is-leaf');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (column.sortable) {
|
|
292
|
+
classes.push('is-sortable');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const headerCellClassName = this.table.headerCellClassName;
|
|
296
|
+
if (typeof headerCellClassName === 'string') {
|
|
297
|
+
classes.push(headerCellClassName);
|
|
298
|
+
} else if (typeof headerCellClassName === 'function') {
|
|
299
|
+
classes.push(headerCellClassName.call(null, {
|
|
300
|
+
rowIndex,
|
|
301
|
+
columnIndex,
|
|
302
|
+
row,
|
|
303
|
+
column
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return classes.join(' ');
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
toggleAllSelection(event) {
|
|
311
|
+
event.stopPropagation();
|
|
312
|
+
this.store.commit('toggleAllSelection');
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
handleFilterClick(event, column) {
|
|
316
|
+
event.stopPropagation();
|
|
317
|
+
const target = event.target;
|
|
318
|
+
let cell = target.tagName === 'TH' ? target : target.parentNode;
|
|
319
|
+
cell = cell.querySelector('.el-table__column-filter-trigger') || cell;
|
|
320
|
+
const table = this.$parent;
|
|
321
|
+
|
|
322
|
+
let filterPanel = this.filterPanels[column.id];
|
|
323
|
+
|
|
324
|
+
if (filterPanel && column.filterOpened) {
|
|
325
|
+
filterPanel.showPopper = false;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (!filterPanel) {
|
|
330
|
+
filterPanel = new Vue(FilterPanel);
|
|
331
|
+
this.filterPanels[column.id] = filterPanel;
|
|
332
|
+
if (column.filterPlacement) {
|
|
333
|
+
filterPanel.placement = column.filterPlacement;
|
|
334
|
+
}
|
|
335
|
+
filterPanel.table = table;
|
|
336
|
+
filterPanel.cell = cell;
|
|
337
|
+
filterPanel.column = column;
|
|
338
|
+
!this.$isServer && filterPanel.$mount(document.createElement('div'));
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
setTimeout(() => {
|
|
342
|
+
filterPanel.showPopper = true;
|
|
343
|
+
}, 16);
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
handleHeaderClick(event, column) {
|
|
347
|
+
if (!column.filters && column.sortable) {
|
|
348
|
+
this.handleSortClick(event, column);
|
|
349
|
+
} else if (column.filterable && !column.sortable) {
|
|
350
|
+
this.handleFilterClick(event, column);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
this.$parent.$emit('header-click', column, event);
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
handleHeaderContextMenu(event, column) {
|
|
357
|
+
this.$parent.$emit('header-contextmenu', column, event);
|
|
358
|
+
},
|
|
359
|
+
// 修改源码: ele拖动bug, 当设置column.resizable = false 的时候不让拖动
|
|
360
|
+
handleMouseDown(event, column) {
|
|
361
|
+
if (this.$isServer) return;
|
|
362
|
+
if (column.children && column.children.length > 0) return;
|
|
363
|
+
/* istanbul ignore if */
|
|
364
|
+
// 修改源码: ele拖动bug, 当设置column.resizable = false 的时候不让拖动
|
|
365
|
+
if (this.draggingColumn && this.border && column.resizable) {
|
|
366
|
+
this.dragging = true;
|
|
367
|
+
|
|
368
|
+
this.$parent.resizeProxyVisible = true;
|
|
369
|
+
|
|
370
|
+
const table = this.$parent;
|
|
371
|
+
const tableEl = table.$el;
|
|
372
|
+
const tableLeft = tableEl.getBoundingClientRect().left;
|
|
373
|
+
const columnEl = this.$el.querySelector(`th.${column.id}`);
|
|
374
|
+
const columnRect = columnEl.getBoundingClientRect();
|
|
375
|
+
const minLeft = columnRect.left - tableLeft + 30;
|
|
376
|
+
|
|
377
|
+
addClass(columnEl, 'noclick');
|
|
378
|
+
|
|
379
|
+
this.dragState = {
|
|
380
|
+
startMouseLeft: event.clientX,
|
|
381
|
+
startLeft: columnRect.right - tableLeft,
|
|
382
|
+
startColumnLeft: columnRect.left - tableLeft,
|
|
383
|
+
tableLeft
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const resizeProxy = table.$refs.resizeProxy;
|
|
387
|
+
resizeProxy.style.left = this.dragState.startLeft + 'px';
|
|
388
|
+
|
|
389
|
+
document.onselectstart = function() { return false; };
|
|
390
|
+
document.ondragstart = function() { return false; };
|
|
391
|
+
|
|
392
|
+
const handleMouseMove = (event) => {
|
|
393
|
+
const deltaLeft = event.clientX - this.dragState.startMouseLeft;
|
|
394
|
+
const proxyLeft = this.dragState.startLeft + deltaLeft;
|
|
395
|
+
|
|
396
|
+
resizeProxy.style.left = Math.max(minLeft, proxyLeft) + 'px';
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const handleMouseUp = () => {
|
|
400
|
+
if (this.dragging) {
|
|
401
|
+
const {
|
|
402
|
+
startColumnLeft,
|
|
403
|
+
startLeft
|
|
404
|
+
} = this.dragState;
|
|
405
|
+
const finalLeft = parseInt(resizeProxy.style.left, 10);
|
|
406
|
+
const columnWidth = finalLeft - startColumnLeft;
|
|
407
|
+
column.width = column.realWidth = columnWidth;
|
|
408
|
+
table.$emit('header-dragend', column.width, startLeft - startColumnLeft, column, event);
|
|
409
|
+
|
|
410
|
+
this.store.scheduleLayout();
|
|
411
|
+
|
|
412
|
+
document.body.style.cursor = '';
|
|
413
|
+
this.dragging = false;
|
|
414
|
+
this.draggingColumn = null;
|
|
415
|
+
this.dragState = {};
|
|
416
|
+
|
|
417
|
+
table.resizeProxyVisible = false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
421
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
422
|
+
document.onselectstart = null;
|
|
423
|
+
document.ondragstart = null;
|
|
424
|
+
|
|
425
|
+
setTimeout(function() {
|
|
426
|
+
removeClass(columnEl, 'noclick');
|
|
427
|
+
}, 0);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
431
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
// 修改源码: ele头部拖动方法(改变拖动手指样式)
|
|
435
|
+
handleMouseMove(event, column) {
|
|
436
|
+
const { table } = this
|
|
437
|
+
if (column.children && column.children.length > 0) return;
|
|
438
|
+
let target = event.target;
|
|
439
|
+
while (target && target.tagName !== 'TH') {
|
|
440
|
+
target = target.parentNode;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!column || !column.resizable) return;
|
|
444
|
+
|
|
445
|
+
if (!this.dragging && this.border) {
|
|
446
|
+
let rect = target.getBoundingClientRect();
|
|
447
|
+
|
|
448
|
+
const bodyStyle = document.body.style;
|
|
449
|
+
if (rect.width > 12 && rect.right - event.pageX < 8) {
|
|
450
|
+
// 修改源码: 是否修改ele头部拖动方法(改变拖动手指样式) 通过pl-table插件传递
|
|
451
|
+
if (table.headerDragStyle) {
|
|
452
|
+
bodyStyle.cursor = 'ew-resize';
|
|
453
|
+
if (hasClass(target, 'is-sortable')) {
|
|
454
|
+
target.style.cursor = 'ew-resize';
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
bodyStyle.cursor = 'col-resize';
|
|
458
|
+
if (hasClass(target, 'is-sortable')) {
|
|
459
|
+
target.style.cursor = 'col-resize';
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
this.draggingColumn = column;
|
|
463
|
+
} else if (!this.dragging) {
|
|
464
|
+
bodyStyle.cursor = '';
|
|
465
|
+
if (hasClass(target, 'is-sortable')) {
|
|
466
|
+
target.style.cursor = 'pointer';
|
|
467
|
+
}
|
|
468
|
+
this.draggingColumn = null;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
handleMouseOut() {
|
|
474
|
+
if (this.$isServer) return;
|
|
475
|
+
document.body.style.cursor = '';
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
toggleOrder({ order, sortOrders }) {
|
|
479
|
+
if (order === '') return sortOrders[0];
|
|
480
|
+
const index = sortOrders.indexOf(order || null);
|
|
481
|
+
return sortOrders[index > sortOrders.length - 2 ? 0 : index + 1];
|
|
482
|
+
},
|
|
483
|
+
|
|
484
|
+
handleSortClick(event, column, givenOrder) {
|
|
485
|
+
event.stopPropagation();
|
|
486
|
+
let order = column.order === givenOrder
|
|
487
|
+
? null
|
|
488
|
+
: (givenOrder || this.toggleOrder(column));
|
|
489
|
+
|
|
490
|
+
let target = event.target;
|
|
491
|
+
while (target && target.tagName !== 'TH') {
|
|
492
|
+
target = target.parentNode;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (target && target.tagName === 'TH') {
|
|
496
|
+
if (hasClass(target, 'noclick')) {
|
|
497
|
+
removeClass(target, 'noclick');
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (!column.sortable) return;
|
|
503
|
+
|
|
504
|
+
const states = this.store.states;
|
|
505
|
+
let sortProp = states.sortProp;
|
|
506
|
+
let sortOrder;
|
|
507
|
+
const sortingColumn = states.sortingColumn;
|
|
508
|
+
|
|
509
|
+
if (sortingColumn !== column || (sortingColumn === column && sortingColumn.order === null)) {
|
|
510
|
+
if (sortingColumn) {
|
|
511
|
+
sortingColumn.order = null;
|
|
512
|
+
}
|
|
513
|
+
states.sortingColumn = column;
|
|
514
|
+
sortProp = column.property;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (!order) {
|
|
518
|
+
sortOrder = column.order = null;
|
|
519
|
+
} else {
|
|
520
|
+
sortOrder = column.order = order;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
states.sortProp = sortProp;
|
|
524
|
+
states.sortOrder = sortOrder;
|
|
525
|
+
|
|
526
|
+
this.store.commit('changeSortCondition');
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
|
|
530
|
+
data() {
|
|
531
|
+
return {
|
|
532
|
+
draggingColumn: null,
|
|
533
|
+
dragging: false,
|
|
534
|
+
dragState: {}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
};
|