iov-design 2.15.60 → 2.15.62

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.
Files changed (242) hide show
  1. package/README.md +148 -148
  2. package/lib/alert.js +24 -105
  3. package/lib/aside.js +24 -34
  4. package/lib/autocomplete.js +36 -240
  5. package/lib/avatar.js +21 -20
  6. package/lib/backtop.js +27 -52
  7. package/lib/badge.js +30 -58
  8. package/lib/breadcrumb-item.js +24 -53
  9. package/lib/breadcrumb.js +24 -37
  10. package/lib/button-group.js +24 -29
  11. package/lib/button.js +38 -60
  12. package/lib/calendar.js +29 -146
  13. package/lib/card.js +24 -51
  14. package/lib/carousel-item.js +30 -68
  15. package/lib/carousel.js +27 -159
  16. package/lib/cascader-panel.js +41 -64
  17. package/lib/cascader.js +37 -470
  18. package/lib/checkbox-button.js +28 -164
  19. package/lib/checkbox-group.js +24 -37
  20. package/lib/checkbox.js +35 -189
  21. package/lib/col.js +1 -0
  22. package/lib/collapse-item.js +27 -125
  23. package/lib/collapse.js +24 -37
  24. package/lib/color-picker.js +104 -424
  25. package/lib/container.js +24 -34
  26. package/lib/date-picker.js +126 -1981
  27. package/lib/descriptions-item.js +1 -0
  28. package/lib/descriptions.js +1 -0
  29. package/lib/dialog.js +24 -137
  30. package/lib/divider.js +29 -64
  31. package/lib/drawer.js +24 -139
  32. package/lib/dropdown-item.js +27 -45
  33. package/lib/dropdown-menu.js +24 -51
  34. package/lib/dropdown.js +21 -20
  35. package/lib/empty.js +24 -61
  36. package/lib/footer.js +24 -34
  37. package/lib/form-item.js +42 -128
  38. package/lib/form.js +27 -40
  39. package/lib/header.js +24 -34
  40. package/lib/icon.js +24 -29
  41. package/lib/image.js +36 -220
  42. package/lib/index.js +1 -1
  43. package/lib/infinite-scroll.js +1 -0
  44. package/lib/input-number.js +30 -163
  45. package/lib/input.js +42 -274
  46. package/lib/iov-design.common.js +1635 -11132
  47. package/lib/link.js +31 -56
  48. package/lib/loading.js +24 -77
  49. package/lib/locale/format.js +10 -10
  50. package/lib/main.js +24 -29
  51. package/lib/menu-item-group.js +24 -40
  52. package/lib/menu-item.js +27 -83
  53. package/lib/menu.js +21 -20
  54. package/lib/message-box.js +24 -321
  55. package/lib/message.js +30 -82
  56. package/lib/mixins/migrating.js +20 -20
  57. package/lib/notification.js +24 -109
  58. package/lib/option-group.js +24 -50
  59. package/lib/option.js +27 -76
  60. package/lib/page-header.js +24 -56
  61. package/lib/pagination.js +24 -97
  62. package/lib/popconfirm.js +24 -97
  63. package/lib/popover.js +24 -89
  64. package/lib/progress.js +30 -133
  65. package/lib/radio-button.js +29 -111
  66. package/lib/radio-group.js +24 -39
  67. package/lib/radio.js +36 -152
  68. package/lib/rate.js +24 -94
  69. package/lib/result.js +72 -187
  70. package/lib/row.js +1 -0
  71. package/lib/scrollbar.js +1 -0
  72. package/lib/select.js +48 -637
  73. package/lib/skeleton-item.js +36 -68
  74. package/lib/skeleton.js +28 -70
  75. package/lib/slider.js +36 -267
  76. package/lib/spinner.js +24 -51
  77. package/lib/statistic.js +24 -76
  78. package/lib/step.js +29 -118
  79. package/lib/steps.js +27 -40
  80. package/lib/submenu.js +21 -20
  81. package/lib/switch.js +24 -130
  82. package/lib/tab-pane.js +24 -52
  83. package/lib/table-column.js +1 -0
  84. package/lib/table.js +93 -633
  85. package/lib/tabs.js +34 -49
  86. package/lib/tag.js +21 -20
  87. package/lib/theme-chalk/autocomplete.css +1 -1
  88. package/lib/theme-chalk/base.css +1 -1
  89. package/lib/theme-chalk/cascader.css +1 -1
  90. package/lib/theme-chalk/date-picker.css +1 -1
  91. package/lib/theme-chalk/index.css +1 -1
  92. package/lib/theme-chalk/input-number.css +1 -1
  93. package/lib/theme-chalk/input.css +1 -1
  94. package/lib/theme-chalk/iovfont.css +1 -1
  95. package/lib/theme-chalk/link.css +1 -1
  96. package/lib/theme-chalk/message-box.css +1 -1
  97. package/lib/theme-chalk/pagination.css +1 -1
  98. package/lib/theme-chalk/select.css +1 -1
  99. package/lib/theme-chalk/slider.css +1 -1
  100. package/lib/theme-chalk/time-picker.css +1 -1
  101. package/lib/theme-chalk/transfer.css +1 -1
  102. package/lib/time-picker.js +58 -820
  103. package/lib/time-select.js +42 -303
  104. package/lib/timeline-item.js +29 -75
  105. package/lib/timeline.js +21 -20
  106. package/lib/tooltip.js +1 -0
  107. package/lib/transfer.js +36 -299
  108. package/lib/tree.js +54 -243
  109. package/lib/upload.js +86 -654
  110. package/lib/utils/clickoutside.js +7 -7
  111. package/lib/utils/vue-popper.js +7 -7
  112. package/package.json +154 -154
  113. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  114. package/packages/autocomplete/src/autocomplete.vue +285 -285
  115. package/packages/button/src/button.vue +90 -90
  116. package/packages/calendar/src/date-table.vue +200 -200
  117. package/packages/calendar/src/main.vue +280 -280
  118. package/packages/carousel/src/item.vue +138 -138
  119. package/packages/carousel/src/main.vue +315 -315
  120. package/packages/cascader/src/cascader.vue +776 -776
  121. package/packages/cascader-panel/src/cascader-menu.vue +138 -138
  122. package/packages/cascader-panel/src/cascader-node.vue +246 -246
  123. package/packages/cascader-panel/src/cascader-panel.vue +391 -391
  124. package/packages/cascader-panel/src/node.js +166 -166
  125. package/packages/cascader-panel/src/store.js +58 -58
  126. package/packages/checkbox/src/checkbox-button.vue +199 -199
  127. package/packages/checkbox/src/checkbox-group.vue +49 -49
  128. package/packages/checkbox/src/checkbox.vue +225 -225
  129. package/packages/collapse/src/collapse-item.vue +114 -114
  130. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  131. package/packages/color-picker/src/main.vue +188 -188
  132. package/packages/date-picker/src/basic/date-table.vue +441 -441
  133. package/packages/date-picker/src/basic/month-table.vue +269 -269
  134. package/packages/date-picker/src/basic/time-spinner.vue +304 -304
  135. package/packages/date-picker/src/basic/year-table.vue +111 -111
  136. package/packages/date-picker/src/panel/date-range.vue +680 -680
  137. package/packages/date-picker/src/panel/date.vue +609 -609
  138. package/packages/date-picker/src/panel/month-range.vue +289 -289
  139. package/packages/date-picker/src/panel/time-range.vue +248 -248
  140. package/packages/date-picker/src/panel/time-select.vue +178 -178
  141. package/packages/date-picker/src/panel/time.vue +186 -186
  142. package/packages/date-picker/src/picker.vue +967 -967
  143. package/packages/descriptions/src/index.js +180 -180
  144. package/packages/dialog/src/component.vue +262 -262
  145. package/packages/drawer/src/main.vue +205 -205
  146. package/packages/dropdown/src/dropdown-item.vue +37 -37
  147. package/packages/dropdown/src/dropdown-menu.vue +63 -63
  148. package/packages/dropdown/src/dropdown.vue +293 -293
  149. package/packages/empty/src/index.vue +70 -70
  150. package/packages/form/src/form-item.vue +324 -324
  151. package/packages/form/src/form.vue +182 -182
  152. package/packages/image/src/image-viewer.vue +330 -330
  153. package/packages/image/src/main.vue +249 -249
  154. package/packages/infinite-scroll/src/main.js +150 -150
  155. package/packages/input/src/input.vue +477 -477
  156. package/packages/input-number/src/input-number.vue +283 -283
  157. package/packages/loading/src/directive.js +133 -133
  158. package/packages/loading/src/index.js +106 -106
  159. package/packages/menu/src/menu-item.vue +112 -112
  160. package/packages/menu/src/menu.vue +325 -325
  161. package/packages/menu/src/submenu.vue +349 -349
  162. package/packages/message/src/main.js +91 -91
  163. package/packages/message-box/src/main.js +216 -216
  164. package/packages/message-box/src/main.vue +333 -333
  165. package/packages/notification/src/main.js +94 -94
  166. package/packages/page-header/src/main.vue +30 -30
  167. package/packages/pagination/src/pagination.js +390 -390
  168. package/packages/popconfirm/src/main.vue +104 -104
  169. package/packages/popover/src/main.vue +239 -239
  170. package/packages/radio/src/radio-button.vue +115 -115
  171. package/packages/radio/src/radio-group.vue +115 -115
  172. package/packages/radio/src/radio.vue +148 -148
  173. package/packages/rate/src/main.vue +348 -348
  174. package/packages/scrollbar/src/bar.js +92 -92
  175. package/packages/scrollbar/src/main.js +130 -130
  176. package/packages/select/src/option-group.vue +60 -60
  177. package/packages/select/src/option.vue +171 -171
  178. package/packages/select/src/select-dropdown.vue +74 -74
  179. package/packages/select/src/select.vue +979 -979
  180. package/packages/slider/src/button.vue +238 -238
  181. package/packages/slider/src/main.vue +427 -427
  182. package/packages/statistic/src/main.vue +204 -204
  183. package/packages/steps/src/steps.vue +68 -68
  184. package/packages/switch/src/component.vue +182 -182
  185. package/packages/table/src/config.js +153 -153
  186. package/packages/table/src/filter-panel.vue +194 -194
  187. package/packages/table/src/store/current.js +76 -76
  188. package/packages/table/src/store/helper.js +41 -41
  189. package/packages/table/src/store/index.js +147 -147
  190. package/packages/table/src/store/watcher.js +502 -502
  191. package/packages/table/src/table-body.js +469 -469
  192. package/packages/table/src/table-column.js +328 -328
  193. package/packages/table/src/table-header.js +571 -571
  194. package/packages/table/src/table-layout.js +249 -249
  195. package/packages/table/src/table-row.js +101 -101
  196. package/packages/table/src/table.vue +740 -740
  197. package/packages/table/src/util.js +273 -273
  198. package/packages/tabs/src/tab-bar.vue +57 -57
  199. package/packages/tabs/src/tab-nav.vue +294 -294
  200. package/packages/tabs/src/tabs.vue +201 -201
  201. package/packages/theme-chalk/src/button.scss +416 -416
  202. package/packages/theme-chalk/src/cascader.scss +252 -252
  203. package/packages/theme-chalk/src/checkbox.scss +419 -419
  204. package/packages/theme-chalk/src/common/var.scss +795 -795
  205. package/packages/theme-chalk/src/form.scss +201 -201
  206. package/packages/theme-chalk/src/input.scss +591 -591
  207. package/packages/theme-chalk/src/iovfont.scss +818 -803
  208. package/packages/theme-chalk/src/link.scss +8 -8
  209. package/packages/theme-chalk/src/message-box.scss +207 -207
  210. package/packages/theme-chalk/src/mixins/_button.scss +136 -136
  211. package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
  212. package/packages/theme-chalk/src/radio-button.scss +115 -115
  213. package/packages/theme-chalk/src/select.scss +270 -270
  214. package/packages/theme-chalk/src/tabs.scss +755 -755
  215. package/packages/theme-chalk/src/upload.scss +568 -568
  216. package/packages/tooltip/src/main.js +242 -242
  217. package/packages/transfer/src/main.vue +231 -231
  218. package/packages/transfer/src/transfer-panel.vue +251 -251
  219. package/packages/tree/src/model/node.js +484 -484
  220. package/packages/tree/src/tree-node.vue +279 -279
  221. package/packages/tree/src/tree.vue +496 -496
  222. package/packages/upload/src/index.vue +420 -420
  223. package/packages/upload/src/upload-file.vue +98 -98
  224. package/packages/upload/src/upload-list.vue +115 -115
  225. package/packages/upload/src/upload-picture.vue +98 -98
  226. package/packages/upload/src/upload.vue +231 -231
  227. package/packages/upload/src/utils.js +31 -31
  228. package/src/directives/repeat-click.js +26 -26
  229. package/src/index.js +259 -259
  230. package/src/locale/format.js +46 -46
  231. package/src/locale/index.js +48 -48
  232. package/src/locale/lang/lo-LA.js +126 -126
  233. package/src/mixins/locale.js +9 -9
  234. package/src/mixins/migrating.js +54 -54
  235. package/src/transitions/collapse-transition.js +77 -77
  236. package/src/utils/clickoutside.js +76 -76
  237. package/src/utils/date-util.js +282 -282
  238. package/src/utils/popup/index.js +218 -218
  239. package/src/utils/popup/popup-manager.js +194 -194
  240. package/src/utils/util.js +245 -245
  241. package/src/utils/vdom.js +5 -5
  242. package/src/utils/vue-popper.js +198 -198
@@ -1,469 +1,469 @@
1
- import { arrayFindIndex } from 'iov-design/src/utils/util';
2
- import { getCell, getColumnByCell, getRowIdentity, objectEquals } from './util';
3
- import { getStyle, hasClass, removeClass, addClass } from 'iov-design/src/utils/dom';
4
- import ElCheckbox from 'iov-design/packages/checkbox';
5
- import ElTooltip from 'iov-design/packages/tooltip';
6
- import debounce from 'throttle-debounce/debounce';
7
- import LayoutObserver from './layout-observer';
8
- import { mapStates } from './store/helper';
9
- import TableRow from './table-row.js';
10
-
11
- export default {
12
- name: 'ElTableBody',
13
-
14
- mixins: [LayoutObserver],
15
-
16
- components: {
17
- ElCheckbox,
18
- ElTooltip,
19
- TableRow
20
- },
21
-
22
- props: {
23
- store: {
24
- required: true
25
- },
26
- stripe: Boolean,
27
- context: {},
28
- rowClassName: [String, Function],
29
- rowStyle: [Object, Function],
30
- fixed: String,
31
- highlight: Boolean
32
- },
33
-
34
- render(h) {
35
- const data = this.data || [];
36
- return (
37
- <table
38
- class="el-table__body"
39
- cellspacing="0"
40
- cellpadding="0"
41
- border="0">
42
- <colgroup>
43
- {
44
- this.columns.map(column => <col name={column.id} key={column.id} />)
45
- }
46
- </colgroup>
47
- <tbody>
48
- {
49
- data.reduce((acc, row) => {
50
- return acc.concat(this.wrappedRowRender(row, acc.length));
51
- }, [])
52
- }
53
- <el-tooltip effect={this.table.tooltipEffect} placement="top" ref="tooltip" content={this.tooltipContent}></el-tooltip>
54
- </tbody>
55
- </table>
56
- );
57
- },
58
-
59
- computed: {
60
- table() {
61
- return this.$parent;
62
- },
63
-
64
- ...mapStates({
65
- data: 'data',
66
- columns: 'columns',
67
- treeIndent: 'indent',
68
- leftFixedLeafCount: 'fixedLeafColumnsLength',
69
- rightFixedLeafCount: 'rightFixedLeafColumnsLength',
70
- columnsCount: states => states.columns.length,
71
- leftFixedCount: states => states.fixedColumns.length,
72
- rightFixedCount: states => states.rightFixedColumns.length,
73
- hasExpandColumn: states => states.columns.some(({ type }) => type === 'expand')
74
- }),
75
-
76
- columnsHidden() {
77
- return this.columns.map((column, index) => this.isColumnHidden(index));
78
- },
79
-
80
- firstDefaultColumnIndex() {
81
- return arrayFindIndex(this.columns, ({ type }) => type === 'default');
82
- }
83
- },
84
-
85
- watch: {
86
- // don't trigger getter of currentRow in getCellClass. see https://jsfiddle.net/oe2b4hqt/
87
- // update DOM manually. see https://github.com/ElemeFE/element/pull/13954/files#diff-9b450c00d0a9dec0ffad5a3176972e40
88
- 'store.states.hoverRow'(newVal, oldVal) {
89
- if (!this.store.states.isComplex || this.$isServer) return;
90
- let raf = window.requestAnimationFrame;
91
- if (!raf) {
92
- raf = (fn) => setTimeout(fn, 16);
93
- }
94
- raf(() => {
95
- const rows = this.$el.querySelectorAll('.el-table__row');
96
- const oldRow = rows[oldVal];
97
- const newRow = rows[newVal];
98
- if (oldRow) {
99
- removeClass(oldRow, 'hover-row');
100
- }
101
- if (newRow) {
102
- addClass(newRow, 'hover-row');
103
- }
104
- });
105
- }
106
- },
107
-
108
- data() {
109
- return {
110
- tooltipContent: ''
111
- };
112
- },
113
-
114
- created() {
115
- this.activateTooltip = debounce(50, tooltip => tooltip.handleShowPopper());
116
- },
117
-
118
- methods: {
119
- getKeyOfRow(row, index) {
120
- const rowKey = this.table.rowKey;
121
- if (rowKey) {
122
- return getRowIdentity(row, rowKey);
123
- }
124
- return index;
125
- },
126
-
127
- isColumnHidden(index) {
128
- if (this.fixed === true || this.fixed === 'left') {
129
- return index >= this.leftFixedLeafCount;
130
- } else if (this.fixed === 'right') {
131
- return index < this.columnsCount - this.rightFixedLeafCount;
132
- } else {
133
- return (index < this.leftFixedLeafCount) || (index >= this.columnsCount - this.rightFixedLeafCount);
134
- }
135
- },
136
-
137
- getSpan(row, column, rowIndex, columnIndex) {
138
- let rowspan = 1;
139
- let colspan = 1;
140
- const fn = this.table.spanMethod;
141
- if (typeof fn === 'function') {
142
- const result = fn({
143
- row,
144
- column,
145
- rowIndex,
146
- columnIndex
147
- });
148
- if (Array.isArray(result)) {
149
- rowspan = result[0];
150
- colspan = result[1];
151
- } else if (typeof result === 'object') {
152
- rowspan = result.rowspan;
153
- colspan = result.colspan;
154
- }
155
- }
156
- return { rowspan, colspan };
157
- },
158
-
159
- getRowStyle(row, rowIndex) {
160
- const rowStyle = this.table.rowStyle;
161
- if (typeof rowStyle === 'function') {
162
- return rowStyle.call(null, {
163
- row,
164
- rowIndex
165
- });
166
- }
167
- return rowStyle || null;
168
- },
169
-
170
- getRowClass(row, rowIndex) {
171
- let selection = this.store.states.selection;
172
- const classes = ['el-table__row'];
173
- if (this.table.highlightCurrentRow && row === this.store.states.currentRow) {
174
- classes.push('current-row');
175
- }
176
-
177
- if (this.table.highlightSelectionRow) {
178
- for (let i = 0; i < selection.length; i++) {
179
- if (objectEquals(row, selection[i])) {
180
- classes.push('selection-row');
181
- }
182
- };
183
- }
184
-
185
- if (this.stripe && rowIndex % 2 === 1) {
186
- classes.push('el-table__row--striped');
187
- }
188
- const rowClassName = this.table.rowClassName;
189
- if (typeof rowClassName === 'string') {
190
- classes.push(rowClassName);
191
- } else if (typeof rowClassName === 'function') {
192
- classes.push(rowClassName.call(null, {
193
- row,
194
- rowIndex
195
- }));
196
- }
197
-
198
- if (this.store.states.expandRows.indexOf(row) > -1) {
199
- classes.push('expanded');
200
- }
201
-
202
- return classes;
203
- },
204
-
205
- getCellStyle(rowIndex, columnIndex, row, column) {
206
- const cellStyle = this.table.cellStyle;
207
- if (typeof cellStyle === 'function') {
208
- return cellStyle.call(null, {
209
- rowIndex,
210
- columnIndex,
211
- row,
212
- column
213
- });
214
- }
215
- return cellStyle;
216
- },
217
-
218
- getCellClass(rowIndex, columnIndex, row, column) {
219
- const classes = [column.id, column.align, column.verticalAlign, column.className];
220
-
221
- if (this.isColumnHidden(columnIndex)) {
222
- classes.push('is-hidden');
223
- }
224
-
225
- const cellClassName = this.table.cellClassName;
226
- if (typeof cellClassName === 'string') {
227
- classes.push(cellClassName);
228
- } else if (typeof cellClassName === 'function') {
229
- classes.push(cellClassName.call(null, {
230
- rowIndex,
231
- columnIndex,
232
- row,
233
- column
234
- }));
235
- }
236
-
237
- classes.push('el-table__cell');
238
-
239
- return classes.join(' ');
240
- },
241
-
242
- getColspanRealWidth(columns, colspan, index) {
243
- if (colspan < 1) {
244
- return columns[index].realWidth;
245
- }
246
- const widthArr = columns.map(({ realWidth }) => realWidth).slice(index, index + colspan);
247
- return widthArr.reduce((acc, width) => acc + width, -1);
248
- },
249
-
250
- handleCellMouseEnter(event, row) {
251
- const table = this.table;
252
- const cell = getCell(event);
253
-
254
- if (cell) {
255
- const column = getColumnByCell(table, cell);
256
- const hoverState = table.hoverState = { cell, column, row };
257
- table.$emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, event);
258
- }
259
-
260
- // 判断是否text-overflow, 如果是就显示tooltip
261
- const cellChild = event.target.querySelector('.cell');
262
- if (!(hasClass(cellChild, 'el-tooltip') && cellChild.childNodes.length)) {
263
- return;
264
- }
265
- // use range width instead of scrollWidth to determine whether the text is overflowing
266
- // to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3
267
- const range = document.createRange();
268
- range.setStart(cellChild, 0);
269
- range.setEnd(cellChild, cellChild.childNodes.length);
270
- const rangeWidth = range.getBoundingClientRect().width;
271
- const padding = (parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) +
272
- (parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0);
273
- if ((rangeWidth + padding > cellChild.offsetWidth || cellChild.scrollWidth > cellChild.offsetWidth) && this.$refs.tooltip) {
274
- const tooltip = this.$refs.tooltip;
275
- // TODO 会引起整个 Table 的重新渲染,需要优化
276
- this.tooltipContent = cell.innerText || cell.textContent;
277
- tooltip.referenceElm = cell;
278
- tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none');
279
- tooltip.doDestroy();
280
- tooltip.setExpectedState(true);
281
- this.activateTooltip(tooltip);
282
- }
283
- },
284
-
285
- handleCellMouseLeave(event) {
286
- const tooltip = this.$refs.tooltip;
287
- if (tooltip) {
288
- tooltip.setExpectedState(false);
289
- tooltip.handleClosePopper();
290
- }
291
- const cell = getCell(event);
292
- if (!cell) return;
293
-
294
- const oldHoverState = this.table.hoverState || {};
295
- this.table.$emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
296
- },
297
-
298
- handleMouseEnter: debounce(30, function(index) {
299
- this.store.commit('setHoverRow', index);
300
- }),
301
-
302
- handleMouseLeave: debounce(30, function() {
303
- this.store.commit('setHoverRow', null);
304
- }),
305
-
306
- handleContextMenu(event, row) {
307
- this.handleEvent(event, row, 'contextmenu');
308
- },
309
-
310
- handleDoubleClick(event, row) {
311
- this.handleEvent(event, row, 'dblclick');
312
- },
313
-
314
- handleClick(event, row) {
315
- this.store.commit('setCurrentRow', row);
316
- this.handleEvent(event, row, 'click');
317
- },
318
-
319
- handleEvent(event, row, name) {
320
- const table = this.table;
321
- const cell = getCell(event);
322
- let column;
323
- if (cell) {
324
- column = getColumnByCell(table, cell);
325
- if (column) {
326
- table.$emit(`cell-${name}`, row, column, cell, event);
327
- }
328
- }
329
- table.$emit(`row-${name}`, row, column, event);
330
- },
331
-
332
- rowRender(row, $index, treeRowData) {
333
- const { treeIndent, columns, firstDefaultColumnIndex } = this;
334
- const rowClasses = this.getRowClass(row, $index);
335
- let display = true;
336
- if (treeRowData) {
337
- rowClasses.push('el-table__row--level-' + treeRowData.level);
338
- display = treeRowData.display;
339
- }
340
- // 指令 v-show 会覆盖 row-style 中 display
341
- // 使用 :style 代替 v-show https://github.com/ElemeFE/element/issues/16995
342
- let displayStyle = display ? null : {
343
- display: 'none'
344
- };
345
- return (
346
- <TableRow
347
- style={[displayStyle, this.getRowStyle(row, $index)]}
348
- class={rowClasses}
349
- key={this.getKeyOfRow(row, $index)}
350
- nativeOn-dblclick={($event) => this.handleDoubleClick($event, row)}
351
- nativeOn-click={($event) => this.handleClick($event, row)}
352
- nativeOn-contextmenu={($event) => this.handleContextMenu($event, row)}
353
- nativeOn-mouseenter={_ => this.handleMouseEnter($index)}
354
- nativeOn-mouseleave={this.handleMouseLeave}
355
- columns={columns}
356
- row={row}
357
- index={$index}
358
- store={this.store}
359
- context={this.context || this.table.$vnode.context}
360
- firstDefaultColumnIndex={firstDefaultColumnIndex}
361
- treeRowData={treeRowData}
362
- treeIndent={treeIndent}
363
- columnsHidden={this.columnsHidden}
364
- getSpan={this.getSpan}
365
- getColspanRealWidth={this.getColspanRealWidth}
366
- getCellStyle={this.getCellStyle}
367
- getCellClass={this.getCellClass}
368
- handleCellMouseEnter={this.handleCellMouseEnter}
369
- handleCellMouseLeave={this.handleCellMouseLeave}
370
- isSelected={this.store.isSelected(row)}
371
- isExpanded={this.store.states.expandRows.indexOf(row) > -1}
372
- fixed={this.fixed}
373
- >
374
- </TableRow>
375
- );
376
- },
377
-
378
- wrappedRowRender(row, $index) {
379
- const store = this.store;
380
- const { isRowExpanded, assertRowKey } = store;
381
- const { treeData, lazyTreeNodeMap, childrenColumnName, rowKey } = store.states;
382
- if (this.hasExpandColumn && isRowExpanded(row)) {
383
- const renderExpanded = this.table.renderExpanded;
384
- const tr = this.rowRender(row, $index);
385
- if (!renderExpanded) {
386
- console.error('[Element Error]renderExpanded is required.');
387
- return tr;
388
- }
389
- // 使用二维数组,避免修改 $index
390
- return [[
391
- tr,
392
- <tr key={'expanded-row__' + tr.key}>
393
- <td colspan={ this.columnsCount } class="el-table__cell el-table__expanded-cell">
394
- { renderExpanded(this.$createElement, { row, $index, store: this.store }) }
395
- </td>
396
- </tr>]];
397
- } else if (Object.keys(treeData).length) {
398
- assertRowKey();
399
- // TreeTable 时,rowKey 必须由用户设定,不使用 getKeyOfRow 计算
400
- // 在调用 rowRender 函数时,仍然会计算 rowKey,不太好的操作
401
- const key = getRowIdentity(row, rowKey);
402
- let cur = treeData[key];
403
- let treeRowData = null;
404
- if (cur) {
405
- treeRowData = {
406
- expanded: cur.expanded,
407
- level: cur.level,
408
- display: true
409
- };
410
- if (typeof cur.lazy === 'boolean') {
411
- if (typeof cur.loaded === 'boolean' && cur.loaded) {
412
- treeRowData.noLazyChildren = !(cur.children && cur.children.length);
413
- }
414
- treeRowData.loading = cur.loading;
415
- }
416
- }
417
- const tmp = [this.rowRender(row, $index, treeRowData)];
418
- // 渲染嵌套数据
419
- if (cur) {
420
- // currentRow 记录的是 index,所以还需主动增加 TreeTable 的 index
421
- let i = 0;
422
- const traverse = (children, parent) => {
423
- if (!(children && children.length && parent)) return;
424
- children.forEach(node => {
425
- // 父节点的 display 状态影响子节点的显示状态
426
- const innerTreeRowData = {
427
- display: parent.display && parent.expanded,
428
- level: parent.level + 1
429
- };
430
- const childKey = getRowIdentity(node, rowKey);
431
- if (childKey === undefined || childKey === null) {
432
- throw new Error('for nested data item, row-key is required.');
433
- }
434
- cur = { ...treeData[childKey] };
435
- // 对于当前节点,分成有无子节点两种情况。
436
- // 如果包含子节点的,设置 expanded 属性。
437
- // 对于它子节点的 display 属性由它本身的 expanded 与 display 共同决定。
438
- if (cur) {
439
- innerTreeRowData.expanded = cur.expanded;
440
- // 懒加载的某些节点,level 未知
441
- cur.level = cur.level || innerTreeRowData.level;
442
- cur.display = !!(cur.expanded && innerTreeRowData.display);
443
- if (typeof cur.lazy === 'boolean') {
444
- if (typeof cur.loaded === 'boolean' && cur.loaded) {
445
- innerTreeRowData.noLazyChildren = !(cur.children && cur.children.length);
446
- }
447
- innerTreeRowData.loading = cur.loading;
448
- }
449
- }
450
- i++;
451
- tmp.push(this.rowRender(node, $index + i, innerTreeRowData));
452
- if (cur) {
453
- const nodes = lazyTreeNodeMap[childKey] || node[childrenColumnName];
454
- traverse(nodes, cur);
455
- }
456
- });
457
- };
458
- // 对于 root 节点,display 一定为 true
459
- cur.display = true;
460
- const nodes = lazyTreeNodeMap[key] || row[childrenColumnName];
461
- traverse(nodes, cur);
462
- }
463
- return tmp;
464
- } else {
465
- return this.rowRender(row, $index);
466
- }
467
- }
468
- }
469
- };
1
+ import { arrayFindIndex } from 'iov-design/src/utils/util';
2
+ import { getCell, getColumnByCell, getRowIdentity, objectEquals } from './util';
3
+ import { getStyle, hasClass, removeClass, addClass } from 'iov-design/src/utils/dom';
4
+ import ElCheckbox from 'iov-design/packages/checkbox';
5
+ import ElTooltip from 'iov-design/packages/tooltip';
6
+ import debounce from 'throttle-debounce/debounce';
7
+ import LayoutObserver from './layout-observer';
8
+ import { mapStates } from './store/helper';
9
+ import TableRow from './table-row.js';
10
+
11
+ export default {
12
+ name: 'ElTableBody',
13
+
14
+ mixins: [LayoutObserver],
15
+
16
+ components: {
17
+ ElCheckbox,
18
+ ElTooltip,
19
+ TableRow
20
+ },
21
+
22
+ props: {
23
+ store: {
24
+ required: true
25
+ },
26
+ stripe: Boolean,
27
+ context: {},
28
+ rowClassName: [String, Function],
29
+ rowStyle: [Object, Function],
30
+ fixed: String,
31
+ highlight: Boolean
32
+ },
33
+
34
+ render(h) {
35
+ const data = this.data || [];
36
+ return (
37
+ <table
38
+ class="el-table__body"
39
+ cellspacing="0"
40
+ cellpadding="0"
41
+ border="0">
42
+ <colgroup>
43
+ {
44
+ this.columns.map(column => <col name={column.id} key={column.id} />)
45
+ }
46
+ </colgroup>
47
+ <tbody>
48
+ {
49
+ data.reduce((acc, row) => {
50
+ return acc.concat(this.wrappedRowRender(row, acc.length));
51
+ }, [])
52
+ }
53
+ <el-tooltip effect={this.table.tooltipEffect} placement="top" ref="tooltip" content={this.tooltipContent}></el-tooltip>
54
+ </tbody>
55
+ </table>
56
+ );
57
+ },
58
+
59
+ computed: {
60
+ table() {
61
+ return this.$parent;
62
+ },
63
+
64
+ ...mapStates({
65
+ data: 'data',
66
+ columns: 'columns',
67
+ treeIndent: 'indent',
68
+ leftFixedLeafCount: 'fixedLeafColumnsLength',
69
+ rightFixedLeafCount: 'rightFixedLeafColumnsLength',
70
+ columnsCount: states => states.columns.length,
71
+ leftFixedCount: states => states.fixedColumns.length,
72
+ rightFixedCount: states => states.rightFixedColumns.length,
73
+ hasExpandColumn: states => states.columns.some(({ type }) => type === 'expand')
74
+ }),
75
+
76
+ columnsHidden() {
77
+ return this.columns.map((column, index) => this.isColumnHidden(index));
78
+ },
79
+
80
+ firstDefaultColumnIndex() {
81
+ return arrayFindIndex(this.columns, ({ type }) => type === 'default');
82
+ }
83
+ },
84
+
85
+ watch: {
86
+ // don't trigger getter of currentRow in getCellClass. see https://jsfiddle.net/oe2b4hqt/
87
+ // update DOM manually. see https://github.com/ElemeFE/element/pull/13954/files#diff-9b450c00d0a9dec0ffad5a3176972e40
88
+ 'store.states.hoverRow'(newVal, oldVal) {
89
+ if (!this.store.states.isComplex || this.$isServer) return;
90
+ let raf = window.requestAnimationFrame;
91
+ if (!raf) {
92
+ raf = (fn) => setTimeout(fn, 16);
93
+ }
94
+ raf(() => {
95
+ const rows = this.$el.querySelectorAll('.el-table__row');
96
+ const oldRow = rows[oldVal];
97
+ const newRow = rows[newVal];
98
+ if (oldRow) {
99
+ removeClass(oldRow, 'hover-row');
100
+ }
101
+ if (newRow) {
102
+ addClass(newRow, 'hover-row');
103
+ }
104
+ });
105
+ }
106
+ },
107
+
108
+ data() {
109
+ return {
110
+ tooltipContent: ''
111
+ };
112
+ },
113
+
114
+ created() {
115
+ this.activateTooltip = debounce(50, tooltip => tooltip.handleShowPopper());
116
+ },
117
+
118
+ methods: {
119
+ getKeyOfRow(row, index) {
120
+ const rowKey = this.table.rowKey;
121
+ if (rowKey) {
122
+ return getRowIdentity(row, rowKey);
123
+ }
124
+ return index;
125
+ },
126
+
127
+ isColumnHidden(index) {
128
+ if (this.fixed === true || this.fixed === 'left') {
129
+ return index >= this.leftFixedLeafCount;
130
+ } else if (this.fixed === 'right') {
131
+ return index < this.columnsCount - this.rightFixedLeafCount;
132
+ } else {
133
+ return (index < this.leftFixedLeafCount) || (index >= this.columnsCount - this.rightFixedLeafCount);
134
+ }
135
+ },
136
+
137
+ getSpan(row, column, rowIndex, columnIndex) {
138
+ let rowspan = 1;
139
+ let colspan = 1;
140
+ const fn = this.table.spanMethod;
141
+ if (typeof fn === 'function') {
142
+ const result = fn({
143
+ row,
144
+ column,
145
+ rowIndex,
146
+ columnIndex
147
+ });
148
+ if (Array.isArray(result)) {
149
+ rowspan = result[0];
150
+ colspan = result[1];
151
+ } else if (typeof result === 'object') {
152
+ rowspan = result.rowspan;
153
+ colspan = result.colspan;
154
+ }
155
+ }
156
+ return { rowspan, colspan };
157
+ },
158
+
159
+ getRowStyle(row, rowIndex) {
160
+ const rowStyle = this.table.rowStyle;
161
+ if (typeof rowStyle === 'function') {
162
+ return rowStyle.call(null, {
163
+ row,
164
+ rowIndex
165
+ });
166
+ }
167
+ return rowStyle || null;
168
+ },
169
+
170
+ getRowClass(row, rowIndex) {
171
+ let selection = this.store.states.selection;
172
+ const classes = ['el-table__row'];
173
+ if (this.table.highlightCurrentRow && row === this.store.states.currentRow) {
174
+ classes.push('current-row');
175
+ }
176
+
177
+ if (this.table.highlightSelectionRow) {
178
+ for (let i = 0; i < selection.length; i++) {
179
+ if (objectEquals(row, selection[i])) {
180
+ classes.push('selection-row');
181
+ }
182
+ };
183
+ }
184
+
185
+ if (this.stripe && rowIndex % 2 === 1) {
186
+ classes.push('el-table__row--striped');
187
+ }
188
+ const rowClassName = this.table.rowClassName;
189
+ if (typeof rowClassName === 'string') {
190
+ classes.push(rowClassName);
191
+ } else if (typeof rowClassName === 'function') {
192
+ classes.push(rowClassName.call(null, {
193
+ row,
194
+ rowIndex
195
+ }));
196
+ }
197
+
198
+ if (this.store.states.expandRows.indexOf(row) > -1) {
199
+ classes.push('expanded');
200
+ }
201
+
202
+ return classes;
203
+ },
204
+
205
+ getCellStyle(rowIndex, columnIndex, row, column) {
206
+ const cellStyle = this.table.cellStyle;
207
+ if (typeof cellStyle === 'function') {
208
+ return cellStyle.call(null, {
209
+ rowIndex,
210
+ columnIndex,
211
+ row,
212
+ column
213
+ });
214
+ }
215
+ return cellStyle;
216
+ },
217
+
218
+ getCellClass(rowIndex, columnIndex, row, column) {
219
+ const classes = [column.id, column.align, column.verticalAlign, column.className];
220
+
221
+ if (this.isColumnHidden(columnIndex)) {
222
+ classes.push('is-hidden');
223
+ }
224
+
225
+ const cellClassName = this.table.cellClassName;
226
+ if (typeof cellClassName === 'string') {
227
+ classes.push(cellClassName);
228
+ } else if (typeof cellClassName === 'function') {
229
+ classes.push(cellClassName.call(null, {
230
+ rowIndex,
231
+ columnIndex,
232
+ row,
233
+ column
234
+ }));
235
+ }
236
+
237
+ classes.push('el-table__cell');
238
+
239
+ return classes.join(' ');
240
+ },
241
+
242
+ getColspanRealWidth(columns, colspan, index) {
243
+ if (colspan < 1) {
244
+ return columns[index].realWidth;
245
+ }
246
+ const widthArr = columns.map(({ realWidth }) => realWidth).slice(index, index + colspan);
247
+ return widthArr.reduce((acc, width) => acc + width, -1);
248
+ },
249
+
250
+ handleCellMouseEnter(event, row) {
251
+ const table = this.table;
252
+ const cell = getCell(event);
253
+
254
+ if (cell) {
255
+ const column = getColumnByCell(table, cell);
256
+ const hoverState = table.hoverState = { cell, column, row };
257
+ table.$emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, event);
258
+ }
259
+
260
+ // 判断是否text-overflow, 如果是就显示tooltip
261
+ const cellChild = event.target.querySelector('.cell');
262
+ if (!(hasClass(cellChild, 'el-tooltip') && cellChild.childNodes.length)) {
263
+ return;
264
+ }
265
+ // use range width instead of scrollWidth to determine whether the text is overflowing
266
+ // to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3
267
+ const range = document.createRange();
268
+ range.setStart(cellChild, 0);
269
+ range.setEnd(cellChild, cellChild.childNodes.length);
270
+ const rangeWidth = range.getBoundingClientRect().width;
271
+ const padding = (parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) +
272
+ (parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0);
273
+ if ((rangeWidth + padding > cellChild.offsetWidth || cellChild.scrollWidth > cellChild.offsetWidth) && this.$refs.tooltip) {
274
+ const tooltip = this.$refs.tooltip;
275
+ // TODO 会引起整个 Table 的重新渲染,需要优化
276
+ this.tooltipContent = cell.innerText || cell.textContent;
277
+ tooltip.referenceElm = cell;
278
+ tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none');
279
+ tooltip.doDestroy();
280
+ tooltip.setExpectedState(true);
281
+ this.activateTooltip(tooltip);
282
+ }
283
+ },
284
+
285
+ handleCellMouseLeave(event) {
286
+ const tooltip = this.$refs.tooltip;
287
+ if (tooltip) {
288
+ tooltip.setExpectedState(false);
289
+ tooltip.handleClosePopper();
290
+ }
291
+ const cell = getCell(event);
292
+ if (!cell) return;
293
+
294
+ const oldHoverState = this.table.hoverState || {};
295
+ this.table.$emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
296
+ },
297
+
298
+ handleMouseEnter: debounce(30, function(index) {
299
+ this.store.commit('setHoverRow', index);
300
+ }),
301
+
302
+ handleMouseLeave: debounce(30, function() {
303
+ this.store.commit('setHoverRow', null);
304
+ }),
305
+
306
+ handleContextMenu(event, row) {
307
+ this.handleEvent(event, row, 'contextmenu');
308
+ },
309
+
310
+ handleDoubleClick(event, row) {
311
+ this.handleEvent(event, row, 'dblclick');
312
+ },
313
+
314
+ handleClick(event, row) {
315
+ this.store.commit('setCurrentRow', row);
316
+ this.handleEvent(event, row, 'click');
317
+ },
318
+
319
+ handleEvent(event, row, name) {
320
+ const table = this.table;
321
+ const cell = getCell(event);
322
+ let column;
323
+ if (cell) {
324
+ column = getColumnByCell(table, cell);
325
+ if (column) {
326
+ table.$emit(`cell-${name}`, row, column, cell, event);
327
+ }
328
+ }
329
+ table.$emit(`row-${name}`, row, column, event);
330
+ },
331
+
332
+ rowRender(row, $index, treeRowData) {
333
+ const { treeIndent, columns, firstDefaultColumnIndex } = this;
334
+ const rowClasses = this.getRowClass(row, $index);
335
+ let display = true;
336
+ if (treeRowData) {
337
+ rowClasses.push('el-table__row--level-' + treeRowData.level);
338
+ display = treeRowData.display;
339
+ }
340
+ // 指令 v-show 会覆盖 row-style 中 display
341
+ // 使用 :style 代替 v-show https://github.com/ElemeFE/element/issues/16995
342
+ let displayStyle = display ? null : {
343
+ display: 'none'
344
+ };
345
+ return (
346
+ <TableRow
347
+ style={[displayStyle, this.getRowStyle(row, $index)]}
348
+ class={rowClasses}
349
+ key={this.getKeyOfRow(row, $index)}
350
+ nativeOn-dblclick={($event) => this.handleDoubleClick($event, row)}
351
+ nativeOn-click={($event) => this.handleClick($event, row)}
352
+ nativeOn-contextmenu={($event) => this.handleContextMenu($event, row)}
353
+ nativeOn-mouseenter={_ => this.handleMouseEnter($index)}
354
+ nativeOn-mouseleave={this.handleMouseLeave}
355
+ columns={columns}
356
+ row={row}
357
+ index={$index}
358
+ store={this.store}
359
+ context={this.context || this.table.$vnode.context}
360
+ firstDefaultColumnIndex={firstDefaultColumnIndex}
361
+ treeRowData={treeRowData}
362
+ treeIndent={treeIndent}
363
+ columnsHidden={this.columnsHidden}
364
+ getSpan={this.getSpan}
365
+ getColspanRealWidth={this.getColspanRealWidth}
366
+ getCellStyle={this.getCellStyle}
367
+ getCellClass={this.getCellClass}
368
+ handleCellMouseEnter={this.handleCellMouseEnter}
369
+ handleCellMouseLeave={this.handleCellMouseLeave}
370
+ isSelected={this.store.isSelected(row)}
371
+ isExpanded={this.store.states.expandRows.indexOf(row) > -1}
372
+ fixed={this.fixed}
373
+ >
374
+ </TableRow>
375
+ );
376
+ },
377
+
378
+ wrappedRowRender(row, $index) {
379
+ const store = this.store;
380
+ const { isRowExpanded, assertRowKey } = store;
381
+ const { treeData, lazyTreeNodeMap, childrenColumnName, rowKey } = store.states;
382
+ if (this.hasExpandColumn && isRowExpanded(row)) {
383
+ const renderExpanded = this.table.renderExpanded;
384
+ const tr = this.rowRender(row, $index);
385
+ if (!renderExpanded) {
386
+ console.error('[Element Error]renderExpanded is required.');
387
+ return tr;
388
+ }
389
+ // 使用二维数组,避免修改 $index
390
+ return [[
391
+ tr,
392
+ <tr key={'expanded-row__' + tr.key}>
393
+ <td colspan={ this.columnsCount } class="el-table__cell el-table__expanded-cell">
394
+ { renderExpanded(this.$createElement, { row, $index, store: this.store }) }
395
+ </td>
396
+ </tr>]];
397
+ } else if (Object.keys(treeData).length) {
398
+ assertRowKey();
399
+ // TreeTable 时,rowKey 必须由用户设定,不使用 getKeyOfRow 计算
400
+ // 在调用 rowRender 函数时,仍然会计算 rowKey,不太好的操作
401
+ const key = getRowIdentity(row, rowKey);
402
+ let cur = treeData[key];
403
+ let treeRowData = null;
404
+ if (cur) {
405
+ treeRowData = {
406
+ expanded: cur.expanded,
407
+ level: cur.level,
408
+ display: true
409
+ };
410
+ if (typeof cur.lazy === 'boolean') {
411
+ if (typeof cur.loaded === 'boolean' && cur.loaded) {
412
+ treeRowData.noLazyChildren = !(cur.children && cur.children.length);
413
+ }
414
+ treeRowData.loading = cur.loading;
415
+ }
416
+ }
417
+ const tmp = [this.rowRender(row, $index, treeRowData)];
418
+ // 渲染嵌套数据
419
+ if (cur) {
420
+ // currentRow 记录的是 index,所以还需主动增加 TreeTable 的 index
421
+ let i = 0;
422
+ const traverse = (children, parent) => {
423
+ if (!(children && children.length && parent)) return;
424
+ children.forEach(node => {
425
+ // 父节点的 display 状态影响子节点的显示状态
426
+ const innerTreeRowData = {
427
+ display: parent.display && parent.expanded,
428
+ level: parent.level + 1
429
+ };
430
+ const childKey = getRowIdentity(node, rowKey);
431
+ if (childKey === undefined || childKey === null) {
432
+ throw new Error('for nested data item, row-key is required.');
433
+ }
434
+ cur = { ...treeData[childKey] };
435
+ // 对于当前节点,分成有无子节点两种情况。
436
+ // 如果包含子节点的,设置 expanded 属性。
437
+ // 对于它子节点的 display 属性由它本身的 expanded 与 display 共同决定。
438
+ if (cur) {
439
+ innerTreeRowData.expanded = cur.expanded;
440
+ // 懒加载的某些节点,level 未知
441
+ cur.level = cur.level || innerTreeRowData.level;
442
+ cur.display = !!(cur.expanded && innerTreeRowData.display);
443
+ if (typeof cur.lazy === 'boolean') {
444
+ if (typeof cur.loaded === 'boolean' && cur.loaded) {
445
+ innerTreeRowData.noLazyChildren = !(cur.children && cur.children.length);
446
+ }
447
+ innerTreeRowData.loading = cur.loading;
448
+ }
449
+ }
450
+ i++;
451
+ tmp.push(this.rowRender(node, $index + i, innerTreeRowData));
452
+ if (cur) {
453
+ const nodes = lazyTreeNodeMap[childKey] || node[childrenColumnName];
454
+ traverse(nodes, cur);
455
+ }
456
+ });
457
+ };
458
+ // 对于 root 节点,display 一定为 true
459
+ cur.display = true;
460
+ const nodes = lazyTreeNodeMap[key] || row[childrenColumnName];
461
+ traverse(nodes, cur);
462
+ }
463
+ return tmp;
464
+ } else {
465
+ return this.rowRender(row, $index);
466
+ }
467
+ }
468
+ }
469
+ };