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,740 +1,740 @@
1
- <template>
2
- <div class="el-table"
3
- :class="[{
4
- 'el-table--fit': fit,
5
- 'el-table--striped': stripe,
6
- 'el-table--border': border || isGroup,
7
- 'el-table--outer-border': isGroup ? false : outerBorder,
8
- 'el-table--hidden': isHidden,
9
- 'el-table--group': isGroup,
10
- 'el-table--fluid-height': maxHeight,
11
- 'el-table--scrollable-x': layout.scrollX,
12
- 'el-table--scrollable-y': layout.scrollY,
13
- 'el-table--enable-row-hover': !store.states.isComplex,
14
- 'el-table--enable-row-transition': (store.states.data || []).length !== 0 && (store.states.data || []).length < 100
15
- }, tableSize ? `el-table--${ tableSize }` : '']"
16
- @mouseleave="handleMouseLeave($event)">
17
- <div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
18
- <div
19
- v-if="showHeader"
20
- v-mousewheel="handleHeaderFooterMousewheel"
21
- class="el-table__header-wrapper"
22
- ref="headerWrapper">
23
- <table-header
24
- ref="tableHeader"
25
- :store="store"
26
- :border="border"
27
- :default-sort="defaultSort"
28
- :style="{
29
- width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
30
- }">
31
- </table-header>
32
- </div>
33
- <div
34
- class="el-table__body-wrapper"
35
- ref="bodyWrapper"
36
- :class="[layout.scrollX ? `is-scrolling-${scrollPosition}` : 'is-scrolling-none']"
37
- :style="[bodyHeight]">
38
- <table-body
39
- :context="context"
40
- :store="store"
41
- :stripe="stripe"
42
- :row-class-name="rowClassName"
43
- :row-style="rowStyle"
44
- :highlight="highlightCurrentRow"
45
- :style="{
46
- width: bodyWidth
47
- }">
48
- </table-body>
49
- <div
50
- v-if="!data || data.length === 0"
51
- class="el-table__empty-block"
52
- ref="emptyBlock"
53
- :style="emptyBlockStyle">
54
- <div class="el-table__empty-text" >
55
- <slot name="empty">
56
- <el-empty ref="emptyText" :description="emptyText || t('el.table.emptyText')" :type="1" :image-size="emptySize"></el-empty>
57
- </slot>
58
- </div>
59
- </div>
60
- <div
61
- v-if="$slots.append"
62
- class="el-table__append-wrapper"
63
- ref="appendWrapper">
64
- <slot name="append"></slot>
65
- </div>
66
- </div>
67
- <div
68
- v-if="showSummary"
69
- v-show="data && data.length > 0"
70
- v-mousewheel="handleHeaderFooterMousewheel"
71
- class="el-table__footer-wrapper"
72
- ref="footerWrapper">
73
- <table-footer
74
- :store="store"
75
- :border="border"
76
- :sum-text="sumText || t('el.table.sumText')"
77
- :summary-method="summaryMethod"
78
- :default-sort="defaultSort"
79
- :style="{
80
- width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
81
- }">
82
- </table-footer>
83
- </div>
84
- <div
85
- v-if="fixedColumns.length > 0"
86
- v-mousewheel="handleFixedMousewheel"
87
- class="el-table__fixed"
88
- ref="fixedWrapper"
89
- :style="[{
90
- width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
91
- },
92
- fixedHeight]">
93
- <div
94
- v-if="showHeader"
95
- class="el-table__fixed-header-wrapper"
96
- ref="fixedHeaderWrapper" >
97
- <table-header
98
- ref="fixedTableHeader"
99
- fixed="left"
100
- :border="border"
101
- :store="store"
102
- :style="{
103
- width: bodyWidth
104
- }"></table-header>
105
- </div>
106
- <div
107
- class="el-table__fixed-body-wrapper"
108
- ref="fixedBodyWrapper"
109
- :style="[{
110
- top: layout.headerHeight + 'px'
111
- },
112
- fixedBodyHeight]">
113
- <table-body
114
- fixed="left"
115
- :store="store"
116
- :stripe="stripe"
117
- :highlight="highlightCurrentRow"
118
- :row-class-name="rowClassName"
119
- :row-style="rowStyle"
120
- :style="{
121
- width: bodyWidth
122
- }">
123
- </table-body>
124
- <div
125
- v-if="$slots.append"
126
- class="el-table__append-gutter"
127
- :style="{ height: layout.appendHeight + 'px'}"></div>
128
- </div>
129
- <div
130
- v-if="showSummary"
131
- v-show="data && data.length > 0"
132
- class="el-table__fixed-footer-wrapper"
133
- ref="fixedFooterWrapper">
134
- <table-footer
135
- fixed="left"
136
- :border="border"
137
- :sum-text="sumText || t('el.table.sumText')"
138
- :summary-method="summaryMethod"
139
- :store="store"
140
- :style="{
141
- width: bodyWidth
142
- }"></table-footer>
143
- </div>
144
- </div>
145
- <div
146
- v-if="rightFixedColumns.length > 0"
147
- v-mousewheel="handleFixedMousewheel"
148
- class="el-table__fixed-right"
149
- ref="rightFixedWrapper"
150
- :style="[{
151
- width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
152
- right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : ''
153
- },
154
- fixedHeight]">
155
- <div v-if="showHeader"
156
- class="el-table__fixed-header-wrapper"
157
- ref="rightFixedHeaderWrapper">
158
- <table-header
159
- ref="rightFixedTableHeader"
160
- fixed="right"
161
- :border="border"
162
- :store="store"
163
- :style="{
164
- width: bodyWidth
165
- }"></table-header>
166
- </div>
167
- <div
168
- class="el-table__fixed-body-wrapper"
169
- ref="rightFixedBodyWrapper"
170
- :style="[{
171
- top: layout.headerHeight + 'px'
172
- },
173
- fixedBodyHeight]">
174
- <table-body
175
- fixed="right"
176
- :store="store"
177
- :stripe="stripe"
178
- :row-class-name="rowClassName"
179
- :row-style="rowStyle"
180
- :highlight="highlightCurrentRow"
181
- :style="{
182
- width: bodyWidth
183
- }">
184
- </table-body>
185
- <div
186
- v-if="$slots.append"
187
- class="el-table__append-gutter"
188
- :style="{ height: layout.appendHeight + 'px' }"></div>
189
- </div>
190
- <div
191
- v-if="showSummary"
192
- v-show="data && data.length > 0"
193
- class="el-table__fixed-footer-wrapper"
194
- ref="rightFixedFooterWrapper">
195
- <table-footer
196
- fixed="right"
197
- :border="border"
198
- :sum-text="sumText || t('el.table.sumText')"
199
- :summary-method="summaryMethod"
200
- :store="store"
201
- :style="{
202
- width: bodyWidth
203
- }"></table-footer>
204
- </div>
205
- </div>
206
- <div
207
- v-if="rightFixedColumns.length > 0"
208
- class="el-table__fixed-right-patch"
209
- ref="rightFixedPatch"
210
- :style="{
211
- width: layout.scrollY ? layout.gutterWidth + 'px' : '0',
212
- height: layout.headerHeight + 'px'
213
- }"></div>
214
- <div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
215
- </div>
216
- </template>
217
-
218
- <script type="text/babel">
219
- import ElCheckbox from 'iov-design/packages/checkbox';
220
- import ElEmpty from 'iov-design/packages/empty';
221
- import { debounce, throttle } from 'throttle-debounce';
222
- import { addResizeListener, removeResizeListener } from 'iov-design/src/utils/resize-event';
223
- import Mousewheel from 'iov-design/src/directives/mousewheel';
224
- import Locale from 'iov-design/src/mixins/locale';
225
- import Migrating from 'iov-design/src/mixins/migrating';
226
- import { createStore, mapStates } from './store/helper';
227
- import TableLayout from './table-layout';
228
- import TableBody from './table-body';
229
- import TableHeader from './table-header';
230
- import TableFooter from './table-footer';
231
- import { parseHeight } from './util';
232
-
233
- let tableIdSeed = 1;
234
-
235
- export default {
236
- name: 'ElTable',
237
-
238
- mixins: [Locale, Migrating],
239
-
240
- directives: {
241
- Mousewheel
242
- },
243
-
244
- props: {
245
- data: {
246
- type: Array,
247
- default: function() {
248
- return [];
249
- }
250
- },
251
-
252
- size: String,
253
-
254
- width: [String, Number],
255
-
256
- height: [String, Number],
257
-
258
- maxHeight: [String, Number],
259
-
260
- fit: {
261
- type: Boolean,
262
- default: true
263
- },
264
-
265
- stripe: Boolean,
266
-
267
- border: Boolean,
268
-
269
- outerBorder: Boolean,
270
-
271
- rowKey: [String, Function],
272
-
273
- context: {},
274
-
275
- showHeader: {
276
- type: Boolean,
277
- default: true
278
- },
279
-
280
- showSummary: Boolean,
281
-
282
- sumText: String,
283
-
284
- summaryMethod: Function,
285
-
286
- rowClassName: [String, Function],
287
-
288
- rowStyle: [Object, Function],
289
-
290
- cellClassName: [String, Function],
291
-
292
- cellStyle: [Object, Function],
293
-
294
- headerRowClassName: [String, Function],
295
-
296
- headerRowStyle: [Object, Function],
297
-
298
- headerCellClassName: [String, Function],
299
-
300
- headerCellStyle: [Object, Function],
301
-
302
- highlightCurrentRow: Boolean,
303
-
304
- highlightSelectionRow: {
305
- type: Boolean,
306
- default: false
307
- },
308
-
309
- currentRowKey: [String, Number],
310
-
311
- emptyText: String,
312
-
313
- expandRowKeys: Array,
314
-
315
- defaultExpandAll: Boolean,
316
-
317
- defaultSort: Object,
318
-
319
- tooltipEffect: String,
320
-
321
- spanMethod: Function,
322
-
323
- selectOnIndeterminate: {
324
- type: Boolean,
325
- default: true
326
- },
327
-
328
- crossPageSelection: {
329
- type: Boolean,
330
- default: false
331
- },
332
-
333
- indent: {
334
- type: Number,
335
- default: 16
336
- },
337
-
338
- treeProps: {
339
- type: Object,
340
- default() {
341
- return {
342
- hasChildren: 'hasChildren',
343
- children: 'children'
344
- };
345
- }
346
- },
347
-
348
- lazy: Boolean,
349
-
350
- load: Function
351
- },
352
-
353
- components: {
354
- TableHeader,
355
- TableFooter,
356
- TableBody,
357
- ElCheckbox,
358
- ElEmpty
359
- },
360
-
361
- methods: {
362
- getMigratingConfig() {
363
- return {
364
- events: {
365
- expand: 'expand is renamed to expand-change'
366
- }
367
- };
368
- },
369
-
370
- setCurrentRow(row) {
371
- this.store.commit('setCurrentRow', row);
372
- },
373
-
374
- toggleRowSelection(row, selected) {
375
- this.store.toggleRowSelection(row, selected, false);
376
- this.store.updateAllSelected();
377
- },
378
-
379
- toggleRowExpansion(row, expanded) {
380
- this.store.toggleRowExpansionAdapter(row, expanded);
381
- },
382
-
383
- clearSelection() {
384
- this.store.clearSelection();
385
- },
386
-
387
- clearFilter(columnKeys) {
388
- this.store.clearFilter(columnKeys);
389
- },
390
-
391
- clearSort() {
392
- this.store.clearSort();
393
- },
394
-
395
- handleMouseLeave() {
396
- this.store.commit('setHoverRow', null);
397
- if (this.hoverState) this.hoverState = null;
398
- },
399
-
400
- updateScrollY() {
401
- const changed = this.layout.updateScrollY();
402
- if (changed) {
403
- this.layout.notifyObservers('scrollable');
404
- this.layout.updateColumnsWidth();
405
- }
406
- },
407
-
408
- handleFixedMousewheel(event, data) {
409
- const bodyWrapper = this.bodyWrapper;
410
- if (Math.abs(data.spinY) > 0) {
411
- const currentScrollTop = bodyWrapper.scrollTop;
412
- if (data.pixelY < 0 && currentScrollTop !== 0) {
413
- event.preventDefault();
414
- }
415
- if (data.pixelY > 0 && bodyWrapper.scrollHeight - bodyWrapper.clientHeight > currentScrollTop) {
416
- event.preventDefault();
417
- }
418
- bodyWrapper.scrollTop += Math.ceil(data.pixelY / 5);
419
- } else {
420
- bodyWrapper.scrollLeft += Math.ceil(data.pixelX / 5);
421
- }
422
- },
423
-
424
- handleHeaderFooterMousewheel(event, data) {
425
- const { pixelX, pixelY } = data;
426
- if (Math.abs(pixelX) >= Math.abs(pixelY)) {
427
- this.bodyWrapper.scrollLeft += data.pixelX / 5;
428
- }
429
- },
430
-
431
- // TODO 使用 CSS transform
432
- syncPostion() {
433
- const { scrollLeft, scrollTop, offsetWidth, scrollWidth } = this.bodyWrapper;
434
- const { headerWrapper, footerWrapper, fixedBodyWrapper, rightFixedBodyWrapper } = this.$refs;
435
- if (headerWrapper) headerWrapper.scrollLeft = scrollLeft;
436
- if (footerWrapper) footerWrapper.scrollLeft = scrollLeft;
437
- if (fixedBodyWrapper) fixedBodyWrapper.scrollTop = scrollTop;
438
- if (rightFixedBodyWrapper) rightFixedBodyWrapper.scrollTop = scrollTop;
439
- const maxScrollLeftPosition = scrollWidth - offsetWidth - 1;
440
- if (scrollLeft >= maxScrollLeftPosition) {
441
- this.scrollPosition = 'right';
442
- } else if (scrollLeft === 0) {
443
- this.scrollPosition = 'left';
444
- } else {
445
- this.scrollPosition = 'middle';
446
- }
447
- },
448
-
449
- throttleSyncPostion: throttle(16, function() {
450
- this.syncPostion();
451
- }),
452
-
453
- onScroll(evt) {
454
- let raf = window.requestAnimationFrame;
455
- if (!raf) {
456
- this.throttleSyncPostion();
457
- } else {
458
- raf(this.syncPostion);
459
- }
460
- },
461
-
462
- bindEvents() {
463
- this.bodyWrapper.addEventListener('scroll', this.onScroll, { passive: true });
464
- if (this.fit) {
465
- addResizeListener(this.$el, this.resizeListener);
466
- }
467
- },
468
-
469
- unbindEvents() {
470
- this.bodyWrapper.removeEventListener('scroll', this.onScroll, { passive: true });
471
- if (this.fit) {
472
- removeResizeListener(this.$el, this.resizeListener);
473
- }
474
- },
475
-
476
- resizeListener() {
477
- if (!this.$ready) return;
478
- let shouldUpdateLayout = false;
479
- const el = this.$el;
480
- const { width: oldWidth, height: oldHeight } = this.resizeState;
481
-
482
- const width = el.offsetWidth;
483
- if (oldWidth !== width) {
484
- shouldUpdateLayout = true;
485
- }
486
-
487
- const height = el.offsetHeight;
488
- if ((this.height || this.shouldUpdateHeight) && oldHeight !== height) {
489
- shouldUpdateLayout = true;
490
- }
491
-
492
- if (shouldUpdateLayout) {
493
- this.resizeState.width = width;
494
- this.resizeState.height = height;
495
- this.doLayout();
496
- }
497
- },
498
-
499
- doLayout() {
500
- if (this.shouldUpdateHeight) {
501
- this.layout.updateElsHeight();
502
- }
503
- this.layout.updateColumnsWidth();
504
- },
505
-
506
- sort(prop, order) {
507
- this.store.commit('sort', { prop, order });
508
- },
509
-
510
- toggleAllSelection() {
511
- this.store.commit('toggleAllSelection');
512
- }
513
- },
514
-
515
- computed: {
516
- tableSize() {
517
- return this.size || (this.$ELEMENT || {}).size;
518
- },
519
-
520
- emptySize() {
521
- const sizeMap = {
522
- mini: 70,
523
- small: 86,
524
- medium: 86,
525
- large: 108
526
- };
527
- return sizeMap[this.tableSize] || 108;
528
- },
529
-
530
- bodyWrapper() {
531
- return this.$refs.bodyWrapper;
532
- },
533
-
534
- shouldUpdateHeight() {
535
- return this.height ||
536
- this.maxHeight ||
537
- this.fixedColumns.length > 0 ||
538
- this.rightFixedColumns.length > 0;
539
- },
540
-
541
- bodyWidth() {
542
- const { bodyWidth, scrollY, gutterWidth } = this.layout;
543
- return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : '';
544
- },
545
-
546
- bodyHeight() {
547
- const { headerHeight = 0, bodyHeight, footerHeight = 0} = this.layout;
548
- if (this.height) {
549
- return {
550
- height: bodyHeight ? bodyHeight + 'px' : ''
551
- };
552
- } else if (this.maxHeight) {
553
- const maxHeight = parseHeight(this.maxHeight);
554
- if (typeof maxHeight === 'number') {
555
- return {
556
- 'max-height': (maxHeight - footerHeight - (this.showHeader ? headerHeight : 0)) + 'px'
557
- };
558
- }
559
- }
560
- return {};
561
- },
562
-
563
- fixedBodyHeight() {
564
- if (this.height) {
565
- return {
566
- height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : ''
567
- };
568
- } else if (this.maxHeight) {
569
- let maxHeight = parseHeight(this.maxHeight);
570
- if (typeof maxHeight === 'number') {
571
- maxHeight = this.layout.scrollX ? maxHeight - this.layout.gutterWidth : maxHeight;
572
- if (this.showHeader) {
573
- maxHeight -= this.layout.headerHeight;
574
- }
575
- maxHeight -= this.layout.footerHeight;
576
- return {
577
- 'max-height': maxHeight + 'px'
578
- };
579
- }
580
- }
581
- return {};
582
- },
583
-
584
- fixedHeight() {
585
- if (this.maxHeight) {
586
- if (this.showSummary) {
587
- return {
588
- bottom: 0
589
- };
590
- }
591
- return {
592
- bottom: (this.layout.scrollX && this.data.length) ? this.layout.gutterWidth + 'px' : ''
593
- };
594
- } else {
595
- if (this.showSummary) {
596
- return {
597
- height: this.layout.tableHeight ? this.layout.tableHeight + 'px' : ''
598
- };
599
- }
600
- return {
601
- height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : ''
602
- };
603
- }
604
- },
605
-
606
- emptyBlockStyle() {
607
- if (this.data && this.data.length) return null;
608
- const heightMap = {
609
- large: '153px',
610
- medium: '153px',
611
- small: '131px',
612
- mini: '99px'
613
- };
614
- let height = heightMap[this.tableSize] || '153px';
615
- if (this.layout.appendHeight) {
616
- height = `calc(100% - ${this.layout.appendHeight}px)`;
617
- }
618
- return {
619
- width: this.bodyWidth,
620
- height
621
- };
622
- },
623
-
624
- ...mapStates({
625
- selection: 'selection',
626
- columns: 'columns',
627
- tableData: 'data',
628
- fixedColumns: 'fixedColumns',
629
- rightFixedColumns: 'rightFixedColumns'
630
- })
631
- },
632
-
633
- watch: {
634
- height: {
635
- immediate: true,
636
- handler(value) {
637
- this.layout.setHeight(value);
638
- }
639
- },
640
-
641
- maxHeight: {
642
- immediate: true,
643
- handler(value) {
644
- this.layout.setMaxHeight(value);
645
- }
646
- },
647
-
648
- currentRowKey: {
649
- immediate: true,
650
- handler(value) {
651
- if (!this.rowKey) return;
652
- this.store.setCurrentRowKey(value);
653
- }
654
- },
655
-
656
- data: {
657
- immediate: true,
658
- handler(value) {
659
- this.store.commit('setData', value);
660
- }
661
- },
662
-
663
- expandRowKeys: {
664
- immediate: true,
665
- handler(newVal) {
666
- if (newVal) {
667
- this.store.setExpandRowKeysAdapter(newVal);
668
- }
669
- }
670
- }
671
- },
672
-
673
- created() {
674
- this.tableId = 'el-table_' + tableIdSeed++;
675
- this.debouncedUpdateLayout = debounce(50, () => this.doLayout());
676
- },
677
-
678
- mounted() {
679
- this.bindEvents();
680
- this.store.updateColumns();
681
- this.doLayout();
682
-
683
- this.resizeState = {
684
- width: this.$el.offsetWidth,
685
- height: this.$el.offsetHeight
686
- };
687
-
688
- // init filters
689
- this.store.states.columns.forEach(column => {
690
- if (column.filteredValue && column.filteredValue.length) {
691
- this.store.commit('filterChange', {
692
- column,
693
- values: column.filteredValue,
694
- silent: true
695
- });
696
- }
697
- });
698
-
699
- this.$ready = true;
700
-
701
- },
702
-
703
- destroyed() {
704
- this.unbindEvents();
705
- },
706
-
707
- data() {
708
- const { hasChildren = 'hasChildren', children = 'children' } = this.treeProps;
709
- this.store = createStore(this, {
710
- rowKey: this.rowKey,
711
- defaultExpandAll: this.defaultExpandAll,
712
- selectOnIndeterminate: this.selectOnIndeterminate,
713
- // TreeTable 的相关配置
714
- indent: this.indent,
715
- lazy: this.lazy,
716
- lazyColumnIdentifier: hasChildren,
717
- childrenColumnName: children
718
- });
719
- const layout = new TableLayout({
720
- store: this.store,
721
- table: this,
722
- fit: this.fit,
723
- showHeader: this.showHeader
724
- });
725
- return {
726
- layout,
727
- isHidden: false,
728
- renderExpanded: null,
729
- resizeProxyVisible: false,
730
- resizeState: {
731
- width: null,
732
- height: null
733
- },
734
- // 是否拥有多级表头
735
- isGroup: false,
736
- scrollPosition: 'left'
737
- };
738
- }
739
- };
740
- </script>
1
+ <template>
2
+ <div class="el-table"
3
+ :class="[{
4
+ 'el-table--fit': fit,
5
+ 'el-table--striped': stripe,
6
+ 'el-table--border': border || isGroup,
7
+ 'el-table--outer-border': isGroup ? false : outerBorder,
8
+ 'el-table--hidden': isHidden,
9
+ 'el-table--group': isGroup,
10
+ 'el-table--fluid-height': maxHeight,
11
+ 'el-table--scrollable-x': layout.scrollX,
12
+ 'el-table--scrollable-y': layout.scrollY,
13
+ 'el-table--enable-row-hover': !store.states.isComplex,
14
+ 'el-table--enable-row-transition': (store.states.data || []).length !== 0 && (store.states.data || []).length < 100
15
+ }, tableSize ? `el-table--${ tableSize }` : '']"
16
+ @mouseleave="handleMouseLeave($event)">
17
+ <div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
18
+ <div
19
+ v-if="showHeader"
20
+ v-mousewheel="handleHeaderFooterMousewheel"
21
+ class="el-table__header-wrapper"
22
+ ref="headerWrapper">
23
+ <table-header
24
+ ref="tableHeader"
25
+ :store="store"
26
+ :border="border"
27
+ :default-sort="defaultSort"
28
+ :style="{
29
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
30
+ }">
31
+ </table-header>
32
+ </div>
33
+ <div
34
+ class="el-table__body-wrapper"
35
+ ref="bodyWrapper"
36
+ :class="[layout.scrollX ? `is-scrolling-${scrollPosition}` : 'is-scrolling-none']"
37
+ :style="[bodyHeight]">
38
+ <table-body
39
+ :context="context"
40
+ :store="store"
41
+ :stripe="stripe"
42
+ :row-class-name="rowClassName"
43
+ :row-style="rowStyle"
44
+ :highlight="highlightCurrentRow"
45
+ :style="{
46
+ width: bodyWidth
47
+ }">
48
+ </table-body>
49
+ <div
50
+ v-if="!data || data.length === 0"
51
+ class="el-table__empty-block"
52
+ ref="emptyBlock"
53
+ :style="emptyBlockStyle">
54
+ <div class="el-table__empty-text" >
55
+ <slot name="empty">
56
+ <el-empty ref="emptyText" :description="emptyText || t('el.table.emptyText')" :type="1" :image-size="emptySize"></el-empty>
57
+ </slot>
58
+ </div>
59
+ </div>
60
+ <div
61
+ v-if="$slots.append"
62
+ class="el-table__append-wrapper"
63
+ ref="appendWrapper">
64
+ <slot name="append"></slot>
65
+ </div>
66
+ </div>
67
+ <div
68
+ v-if="showSummary"
69
+ v-show="data && data.length > 0"
70
+ v-mousewheel="handleHeaderFooterMousewheel"
71
+ class="el-table__footer-wrapper"
72
+ ref="footerWrapper">
73
+ <table-footer
74
+ :store="store"
75
+ :border="border"
76
+ :sum-text="sumText || t('el.table.sumText')"
77
+ :summary-method="summaryMethod"
78
+ :default-sort="defaultSort"
79
+ :style="{
80
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
81
+ }">
82
+ </table-footer>
83
+ </div>
84
+ <div
85
+ v-if="fixedColumns.length > 0"
86
+ v-mousewheel="handleFixedMousewheel"
87
+ class="el-table__fixed"
88
+ ref="fixedWrapper"
89
+ :style="[{
90
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
91
+ },
92
+ fixedHeight]">
93
+ <div
94
+ v-if="showHeader"
95
+ class="el-table__fixed-header-wrapper"
96
+ ref="fixedHeaderWrapper" >
97
+ <table-header
98
+ ref="fixedTableHeader"
99
+ fixed="left"
100
+ :border="border"
101
+ :store="store"
102
+ :style="{
103
+ width: bodyWidth
104
+ }"></table-header>
105
+ </div>
106
+ <div
107
+ class="el-table__fixed-body-wrapper"
108
+ ref="fixedBodyWrapper"
109
+ :style="[{
110
+ top: layout.headerHeight + 'px'
111
+ },
112
+ fixedBodyHeight]">
113
+ <table-body
114
+ fixed="left"
115
+ :store="store"
116
+ :stripe="stripe"
117
+ :highlight="highlightCurrentRow"
118
+ :row-class-name="rowClassName"
119
+ :row-style="rowStyle"
120
+ :style="{
121
+ width: bodyWidth
122
+ }">
123
+ </table-body>
124
+ <div
125
+ v-if="$slots.append"
126
+ class="el-table__append-gutter"
127
+ :style="{ height: layout.appendHeight + 'px'}"></div>
128
+ </div>
129
+ <div
130
+ v-if="showSummary"
131
+ v-show="data && data.length > 0"
132
+ class="el-table__fixed-footer-wrapper"
133
+ ref="fixedFooterWrapper">
134
+ <table-footer
135
+ fixed="left"
136
+ :border="border"
137
+ :sum-text="sumText || t('el.table.sumText')"
138
+ :summary-method="summaryMethod"
139
+ :store="store"
140
+ :style="{
141
+ width: bodyWidth
142
+ }"></table-footer>
143
+ </div>
144
+ </div>
145
+ <div
146
+ v-if="rightFixedColumns.length > 0"
147
+ v-mousewheel="handleFixedMousewheel"
148
+ class="el-table__fixed-right"
149
+ ref="rightFixedWrapper"
150
+ :style="[{
151
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
152
+ right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : ''
153
+ },
154
+ fixedHeight]">
155
+ <div v-if="showHeader"
156
+ class="el-table__fixed-header-wrapper"
157
+ ref="rightFixedHeaderWrapper">
158
+ <table-header
159
+ ref="rightFixedTableHeader"
160
+ fixed="right"
161
+ :border="border"
162
+ :store="store"
163
+ :style="{
164
+ width: bodyWidth
165
+ }"></table-header>
166
+ </div>
167
+ <div
168
+ class="el-table__fixed-body-wrapper"
169
+ ref="rightFixedBodyWrapper"
170
+ :style="[{
171
+ top: layout.headerHeight + 'px'
172
+ },
173
+ fixedBodyHeight]">
174
+ <table-body
175
+ fixed="right"
176
+ :store="store"
177
+ :stripe="stripe"
178
+ :row-class-name="rowClassName"
179
+ :row-style="rowStyle"
180
+ :highlight="highlightCurrentRow"
181
+ :style="{
182
+ width: bodyWidth
183
+ }">
184
+ </table-body>
185
+ <div
186
+ v-if="$slots.append"
187
+ class="el-table__append-gutter"
188
+ :style="{ height: layout.appendHeight + 'px' }"></div>
189
+ </div>
190
+ <div
191
+ v-if="showSummary"
192
+ v-show="data && data.length > 0"
193
+ class="el-table__fixed-footer-wrapper"
194
+ ref="rightFixedFooterWrapper">
195
+ <table-footer
196
+ fixed="right"
197
+ :border="border"
198
+ :sum-text="sumText || t('el.table.sumText')"
199
+ :summary-method="summaryMethod"
200
+ :store="store"
201
+ :style="{
202
+ width: bodyWidth
203
+ }"></table-footer>
204
+ </div>
205
+ </div>
206
+ <div
207
+ v-if="rightFixedColumns.length > 0"
208
+ class="el-table__fixed-right-patch"
209
+ ref="rightFixedPatch"
210
+ :style="{
211
+ width: layout.scrollY ? layout.gutterWidth + 'px' : '0',
212
+ height: layout.headerHeight + 'px'
213
+ }"></div>
214
+ <div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
215
+ </div>
216
+ </template>
217
+
218
+ <script type="text/babel">
219
+ import ElCheckbox from 'iov-design/packages/checkbox';
220
+ import ElEmpty from 'iov-design/packages/empty';
221
+ import { debounce, throttle } from 'throttle-debounce';
222
+ import { addResizeListener, removeResizeListener } from 'iov-design/src/utils/resize-event';
223
+ import Mousewheel from 'iov-design/src/directives/mousewheel';
224
+ import Locale from 'iov-design/src/mixins/locale';
225
+ import Migrating from 'iov-design/src/mixins/migrating';
226
+ import { createStore, mapStates } from './store/helper';
227
+ import TableLayout from './table-layout';
228
+ import TableBody from './table-body';
229
+ import TableHeader from './table-header';
230
+ import TableFooter from './table-footer';
231
+ import { parseHeight } from './util';
232
+
233
+ let tableIdSeed = 1;
234
+
235
+ export default {
236
+ name: 'ElTable',
237
+
238
+ mixins: [Locale, Migrating],
239
+
240
+ directives: {
241
+ Mousewheel
242
+ },
243
+
244
+ props: {
245
+ data: {
246
+ type: Array,
247
+ default: function() {
248
+ return [];
249
+ }
250
+ },
251
+
252
+ size: String,
253
+
254
+ width: [String, Number],
255
+
256
+ height: [String, Number],
257
+
258
+ maxHeight: [String, Number],
259
+
260
+ fit: {
261
+ type: Boolean,
262
+ default: true
263
+ },
264
+
265
+ stripe: Boolean,
266
+
267
+ border: Boolean,
268
+
269
+ outerBorder: Boolean,
270
+
271
+ rowKey: [String, Function],
272
+
273
+ context: {},
274
+
275
+ showHeader: {
276
+ type: Boolean,
277
+ default: true
278
+ },
279
+
280
+ showSummary: Boolean,
281
+
282
+ sumText: String,
283
+
284
+ summaryMethod: Function,
285
+
286
+ rowClassName: [String, Function],
287
+
288
+ rowStyle: [Object, Function],
289
+
290
+ cellClassName: [String, Function],
291
+
292
+ cellStyle: [Object, Function],
293
+
294
+ headerRowClassName: [String, Function],
295
+
296
+ headerRowStyle: [Object, Function],
297
+
298
+ headerCellClassName: [String, Function],
299
+
300
+ headerCellStyle: [Object, Function],
301
+
302
+ highlightCurrentRow: Boolean,
303
+
304
+ highlightSelectionRow: {
305
+ type: Boolean,
306
+ default: false
307
+ },
308
+
309
+ currentRowKey: [String, Number],
310
+
311
+ emptyText: String,
312
+
313
+ expandRowKeys: Array,
314
+
315
+ defaultExpandAll: Boolean,
316
+
317
+ defaultSort: Object,
318
+
319
+ tooltipEffect: String,
320
+
321
+ spanMethod: Function,
322
+
323
+ selectOnIndeterminate: {
324
+ type: Boolean,
325
+ default: true
326
+ },
327
+
328
+ crossPageSelection: {
329
+ type: Boolean,
330
+ default: false
331
+ },
332
+
333
+ indent: {
334
+ type: Number,
335
+ default: 16
336
+ },
337
+
338
+ treeProps: {
339
+ type: Object,
340
+ default() {
341
+ return {
342
+ hasChildren: 'hasChildren',
343
+ children: 'children'
344
+ };
345
+ }
346
+ },
347
+
348
+ lazy: Boolean,
349
+
350
+ load: Function
351
+ },
352
+
353
+ components: {
354
+ TableHeader,
355
+ TableFooter,
356
+ TableBody,
357
+ ElCheckbox,
358
+ ElEmpty
359
+ },
360
+
361
+ methods: {
362
+ getMigratingConfig() {
363
+ return {
364
+ events: {
365
+ expand: 'expand is renamed to expand-change'
366
+ }
367
+ };
368
+ },
369
+
370
+ setCurrentRow(row) {
371
+ this.store.commit('setCurrentRow', row);
372
+ },
373
+
374
+ toggleRowSelection(row, selected) {
375
+ this.store.toggleRowSelection(row, selected, false);
376
+ this.store.updateAllSelected();
377
+ },
378
+
379
+ toggleRowExpansion(row, expanded) {
380
+ this.store.toggleRowExpansionAdapter(row, expanded);
381
+ },
382
+
383
+ clearSelection() {
384
+ this.store.clearSelection();
385
+ },
386
+
387
+ clearFilter(columnKeys) {
388
+ this.store.clearFilter(columnKeys);
389
+ },
390
+
391
+ clearSort() {
392
+ this.store.clearSort();
393
+ },
394
+
395
+ handleMouseLeave() {
396
+ this.store.commit('setHoverRow', null);
397
+ if (this.hoverState) this.hoverState = null;
398
+ },
399
+
400
+ updateScrollY() {
401
+ const changed = this.layout.updateScrollY();
402
+ if (changed) {
403
+ this.layout.notifyObservers('scrollable');
404
+ this.layout.updateColumnsWidth();
405
+ }
406
+ },
407
+
408
+ handleFixedMousewheel(event, data) {
409
+ const bodyWrapper = this.bodyWrapper;
410
+ if (Math.abs(data.spinY) > 0) {
411
+ const currentScrollTop = bodyWrapper.scrollTop;
412
+ if (data.pixelY < 0 && currentScrollTop !== 0) {
413
+ event.preventDefault();
414
+ }
415
+ if (data.pixelY > 0 && bodyWrapper.scrollHeight - bodyWrapper.clientHeight > currentScrollTop) {
416
+ event.preventDefault();
417
+ }
418
+ bodyWrapper.scrollTop += Math.ceil(data.pixelY / 5);
419
+ } else {
420
+ bodyWrapper.scrollLeft += Math.ceil(data.pixelX / 5);
421
+ }
422
+ },
423
+
424
+ handleHeaderFooterMousewheel(event, data) {
425
+ const { pixelX, pixelY } = data;
426
+ if (Math.abs(pixelX) >= Math.abs(pixelY)) {
427
+ this.bodyWrapper.scrollLeft += data.pixelX / 5;
428
+ }
429
+ },
430
+
431
+ // TODO 使用 CSS transform
432
+ syncPostion() {
433
+ const { scrollLeft, scrollTop, offsetWidth, scrollWidth } = this.bodyWrapper;
434
+ const { headerWrapper, footerWrapper, fixedBodyWrapper, rightFixedBodyWrapper } = this.$refs;
435
+ if (headerWrapper) headerWrapper.scrollLeft = scrollLeft;
436
+ if (footerWrapper) footerWrapper.scrollLeft = scrollLeft;
437
+ if (fixedBodyWrapper) fixedBodyWrapper.scrollTop = scrollTop;
438
+ if (rightFixedBodyWrapper) rightFixedBodyWrapper.scrollTop = scrollTop;
439
+ const maxScrollLeftPosition = scrollWidth - offsetWidth - 1;
440
+ if (scrollLeft >= maxScrollLeftPosition) {
441
+ this.scrollPosition = 'right';
442
+ } else if (scrollLeft === 0) {
443
+ this.scrollPosition = 'left';
444
+ } else {
445
+ this.scrollPosition = 'middle';
446
+ }
447
+ },
448
+
449
+ throttleSyncPostion: throttle(16, function() {
450
+ this.syncPostion();
451
+ }),
452
+
453
+ onScroll(evt) {
454
+ let raf = window.requestAnimationFrame;
455
+ if (!raf) {
456
+ this.throttleSyncPostion();
457
+ } else {
458
+ raf(this.syncPostion);
459
+ }
460
+ },
461
+
462
+ bindEvents() {
463
+ this.bodyWrapper.addEventListener('scroll', this.onScroll, { passive: true });
464
+ if (this.fit) {
465
+ addResizeListener(this.$el, this.resizeListener);
466
+ }
467
+ },
468
+
469
+ unbindEvents() {
470
+ this.bodyWrapper.removeEventListener('scroll', this.onScroll, { passive: true });
471
+ if (this.fit) {
472
+ removeResizeListener(this.$el, this.resizeListener);
473
+ }
474
+ },
475
+
476
+ resizeListener() {
477
+ if (!this.$ready) return;
478
+ let shouldUpdateLayout = false;
479
+ const el = this.$el;
480
+ const { width: oldWidth, height: oldHeight } = this.resizeState;
481
+
482
+ const width = el.offsetWidth;
483
+ if (oldWidth !== width) {
484
+ shouldUpdateLayout = true;
485
+ }
486
+
487
+ const height = el.offsetHeight;
488
+ if ((this.height || this.shouldUpdateHeight) && oldHeight !== height) {
489
+ shouldUpdateLayout = true;
490
+ }
491
+
492
+ if (shouldUpdateLayout) {
493
+ this.resizeState.width = width;
494
+ this.resizeState.height = height;
495
+ this.doLayout();
496
+ }
497
+ },
498
+
499
+ doLayout() {
500
+ if (this.shouldUpdateHeight) {
501
+ this.layout.updateElsHeight();
502
+ }
503
+ this.layout.updateColumnsWidth();
504
+ },
505
+
506
+ sort(prop, order) {
507
+ this.store.commit('sort', { prop, order });
508
+ },
509
+
510
+ toggleAllSelection() {
511
+ this.store.commit('toggleAllSelection');
512
+ }
513
+ },
514
+
515
+ computed: {
516
+ tableSize() {
517
+ return this.size || (this.$ELEMENT || {}).size;
518
+ },
519
+
520
+ emptySize() {
521
+ const sizeMap = {
522
+ mini: 70,
523
+ small: 86,
524
+ medium: 86,
525
+ large: 108
526
+ };
527
+ return sizeMap[this.tableSize] || 108;
528
+ },
529
+
530
+ bodyWrapper() {
531
+ return this.$refs.bodyWrapper;
532
+ },
533
+
534
+ shouldUpdateHeight() {
535
+ return this.height ||
536
+ this.maxHeight ||
537
+ this.fixedColumns.length > 0 ||
538
+ this.rightFixedColumns.length > 0;
539
+ },
540
+
541
+ bodyWidth() {
542
+ const { bodyWidth, scrollY, gutterWidth } = this.layout;
543
+ return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : '';
544
+ },
545
+
546
+ bodyHeight() {
547
+ const { headerHeight = 0, bodyHeight, footerHeight = 0} = this.layout;
548
+ if (this.height) {
549
+ return {
550
+ height: bodyHeight ? bodyHeight + 'px' : ''
551
+ };
552
+ } else if (this.maxHeight) {
553
+ const maxHeight = parseHeight(this.maxHeight);
554
+ if (typeof maxHeight === 'number') {
555
+ return {
556
+ 'max-height': (maxHeight - footerHeight - (this.showHeader ? headerHeight : 0)) + 'px'
557
+ };
558
+ }
559
+ }
560
+ return {};
561
+ },
562
+
563
+ fixedBodyHeight() {
564
+ if (this.height) {
565
+ return {
566
+ height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : ''
567
+ };
568
+ } else if (this.maxHeight) {
569
+ let maxHeight = parseHeight(this.maxHeight);
570
+ if (typeof maxHeight === 'number') {
571
+ maxHeight = this.layout.scrollX ? maxHeight - this.layout.gutterWidth : maxHeight;
572
+ if (this.showHeader) {
573
+ maxHeight -= this.layout.headerHeight;
574
+ }
575
+ maxHeight -= this.layout.footerHeight;
576
+ return {
577
+ 'max-height': maxHeight + 'px'
578
+ };
579
+ }
580
+ }
581
+ return {};
582
+ },
583
+
584
+ fixedHeight() {
585
+ if (this.maxHeight) {
586
+ if (this.showSummary) {
587
+ return {
588
+ bottom: 0
589
+ };
590
+ }
591
+ return {
592
+ bottom: (this.layout.scrollX && this.data.length) ? this.layout.gutterWidth + 'px' : ''
593
+ };
594
+ } else {
595
+ if (this.showSummary) {
596
+ return {
597
+ height: this.layout.tableHeight ? this.layout.tableHeight + 'px' : ''
598
+ };
599
+ }
600
+ return {
601
+ height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : ''
602
+ };
603
+ }
604
+ },
605
+
606
+ emptyBlockStyle() {
607
+ if (this.data && this.data.length) return null;
608
+ const heightMap = {
609
+ large: '153px',
610
+ medium: '153px',
611
+ small: '131px',
612
+ mini: '99px'
613
+ };
614
+ let height = heightMap[this.tableSize] || '153px';
615
+ if (this.layout.appendHeight) {
616
+ height = `calc(100% - ${this.layout.appendHeight}px)`;
617
+ }
618
+ return {
619
+ width: this.bodyWidth,
620
+ height
621
+ };
622
+ },
623
+
624
+ ...mapStates({
625
+ selection: 'selection',
626
+ columns: 'columns',
627
+ tableData: 'data',
628
+ fixedColumns: 'fixedColumns',
629
+ rightFixedColumns: 'rightFixedColumns'
630
+ })
631
+ },
632
+
633
+ watch: {
634
+ height: {
635
+ immediate: true,
636
+ handler(value) {
637
+ this.layout.setHeight(value);
638
+ }
639
+ },
640
+
641
+ maxHeight: {
642
+ immediate: true,
643
+ handler(value) {
644
+ this.layout.setMaxHeight(value);
645
+ }
646
+ },
647
+
648
+ currentRowKey: {
649
+ immediate: true,
650
+ handler(value) {
651
+ if (!this.rowKey) return;
652
+ this.store.setCurrentRowKey(value);
653
+ }
654
+ },
655
+
656
+ data: {
657
+ immediate: true,
658
+ handler(value) {
659
+ this.store.commit('setData', value);
660
+ }
661
+ },
662
+
663
+ expandRowKeys: {
664
+ immediate: true,
665
+ handler(newVal) {
666
+ if (newVal) {
667
+ this.store.setExpandRowKeysAdapter(newVal);
668
+ }
669
+ }
670
+ }
671
+ },
672
+
673
+ created() {
674
+ this.tableId = 'el-table_' + tableIdSeed++;
675
+ this.debouncedUpdateLayout = debounce(50, () => this.doLayout());
676
+ },
677
+
678
+ mounted() {
679
+ this.bindEvents();
680
+ this.store.updateColumns();
681
+ this.doLayout();
682
+
683
+ this.resizeState = {
684
+ width: this.$el.offsetWidth,
685
+ height: this.$el.offsetHeight
686
+ };
687
+
688
+ // init filters
689
+ this.store.states.columns.forEach(column => {
690
+ if (column.filteredValue && column.filteredValue.length) {
691
+ this.store.commit('filterChange', {
692
+ column,
693
+ values: column.filteredValue,
694
+ silent: true
695
+ });
696
+ }
697
+ });
698
+
699
+ this.$ready = true;
700
+
701
+ },
702
+
703
+ destroyed() {
704
+ this.unbindEvents();
705
+ },
706
+
707
+ data() {
708
+ const { hasChildren = 'hasChildren', children = 'children' } = this.treeProps;
709
+ this.store = createStore(this, {
710
+ rowKey: this.rowKey,
711
+ defaultExpandAll: this.defaultExpandAll,
712
+ selectOnIndeterminate: this.selectOnIndeterminate,
713
+ // TreeTable 的相关配置
714
+ indent: this.indent,
715
+ lazy: this.lazy,
716
+ lazyColumnIdentifier: hasChildren,
717
+ childrenColumnName: children
718
+ });
719
+ const layout = new TableLayout({
720
+ store: this.store,
721
+ table: this,
722
+ fit: this.fit,
723
+ showHeader: this.showHeader
724
+ });
725
+ return {
726
+ layout,
727
+ isHidden: false,
728
+ renderExpanded: null,
729
+ resizeProxyVisible: false,
730
+ resizeState: {
731
+ width: null,
732
+ height: null
733
+ },
734
+ // 是否拥有多级表头
735
+ isGroup: false,
736
+ scrollPosition: 'left'
737
+ };
738
+ }
739
+ };
740
+ </script>