iov-design 2.15.60 → 2.15.61

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 (234) 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/button.css +1 -1
  88. package/lib/theme-chalk/calendar.css +1 -1
  89. package/lib/theme-chalk/dropdown.css +1 -1
  90. package/lib/theme-chalk/index.css +1 -1
  91. package/lib/theme-chalk/link.css +1 -1
  92. package/lib/theme-chalk/message-box.css +1 -1
  93. package/lib/theme-chalk/transfer.css +1 -1
  94. package/lib/time-picker.js +58 -820
  95. package/lib/time-select.js +42 -303
  96. package/lib/timeline-item.js +29 -75
  97. package/lib/timeline.js +21 -20
  98. package/lib/tooltip.js +1 -0
  99. package/lib/transfer.js +36 -299
  100. package/lib/tree.js +54 -243
  101. package/lib/upload.js +86 -654
  102. package/lib/utils/clickoutside.js +7 -7
  103. package/lib/utils/vue-popper.js +7 -7
  104. package/package.json +154 -154
  105. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  106. package/packages/autocomplete/src/autocomplete.vue +285 -285
  107. package/packages/button/src/button.vue +90 -90
  108. package/packages/calendar/src/date-table.vue +200 -200
  109. package/packages/calendar/src/main.vue +280 -280
  110. package/packages/carousel/src/item.vue +138 -138
  111. package/packages/carousel/src/main.vue +315 -315
  112. package/packages/cascader/src/cascader.vue +776 -776
  113. package/packages/cascader-panel/src/cascader-menu.vue +138 -138
  114. package/packages/cascader-panel/src/cascader-node.vue +246 -246
  115. package/packages/cascader-panel/src/cascader-panel.vue +391 -391
  116. package/packages/cascader-panel/src/node.js +166 -166
  117. package/packages/cascader-panel/src/store.js +58 -58
  118. package/packages/checkbox/src/checkbox-button.vue +199 -199
  119. package/packages/checkbox/src/checkbox-group.vue +49 -49
  120. package/packages/checkbox/src/checkbox.vue +225 -225
  121. package/packages/collapse/src/collapse-item.vue +114 -114
  122. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  123. package/packages/color-picker/src/main.vue +188 -188
  124. package/packages/date-picker/src/basic/date-table.vue +441 -441
  125. package/packages/date-picker/src/basic/month-table.vue +269 -269
  126. package/packages/date-picker/src/basic/time-spinner.vue +304 -304
  127. package/packages/date-picker/src/basic/year-table.vue +111 -111
  128. package/packages/date-picker/src/panel/date-range.vue +680 -680
  129. package/packages/date-picker/src/panel/date.vue +609 -609
  130. package/packages/date-picker/src/panel/month-range.vue +289 -289
  131. package/packages/date-picker/src/panel/time-range.vue +248 -248
  132. package/packages/date-picker/src/panel/time-select.vue +178 -178
  133. package/packages/date-picker/src/panel/time.vue +186 -186
  134. package/packages/date-picker/src/picker.vue +967 -967
  135. package/packages/descriptions/src/index.js +180 -180
  136. package/packages/dialog/src/component.vue +262 -262
  137. package/packages/drawer/src/main.vue +205 -205
  138. package/packages/dropdown/src/dropdown-item.vue +37 -37
  139. package/packages/dropdown/src/dropdown-menu.vue +63 -63
  140. package/packages/dropdown/src/dropdown.vue +293 -293
  141. package/packages/empty/src/index.vue +70 -70
  142. package/packages/form/src/form-item.vue +324 -324
  143. package/packages/form/src/form.vue +182 -182
  144. package/packages/image/src/image-viewer.vue +330 -330
  145. package/packages/image/src/main.vue +249 -249
  146. package/packages/infinite-scroll/src/main.js +150 -150
  147. package/packages/input/src/input.vue +477 -477
  148. package/packages/input-number/src/input-number.vue +283 -283
  149. package/packages/loading/src/directive.js +133 -133
  150. package/packages/loading/src/index.js +106 -106
  151. package/packages/menu/src/menu-item.vue +112 -112
  152. package/packages/menu/src/menu.vue +325 -325
  153. package/packages/menu/src/submenu.vue +349 -349
  154. package/packages/message/src/main.js +91 -91
  155. package/packages/message-box/src/main.js +216 -216
  156. package/packages/message-box/src/main.vue +333 -333
  157. package/packages/notification/src/main.js +94 -94
  158. package/packages/page-header/src/main.vue +30 -30
  159. package/packages/pagination/src/pagination.js +390 -390
  160. package/packages/popconfirm/src/main.vue +104 -104
  161. package/packages/popover/src/main.vue +239 -239
  162. package/packages/radio/src/radio-button.vue +115 -115
  163. package/packages/radio/src/radio-group.vue +115 -115
  164. package/packages/radio/src/radio.vue +148 -148
  165. package/packages/rate/src/main.vue +348 -348
  166. package/packages/scrollbar/src/bar.js +92 -92
  167. package/packages/scrollbar/src/main.js +130 -130
  168. package/packages/select/src/option-group.vue +60 -60
  169. package/packages/select/src/option.vue +171 -171
  170. package/packages/select/src/select-dropdown.vue +74 -74
  171. package/packages/select/src/select.vue +979 -979
  172. package/packages/slider/src/button.vue +238 -238
  173. package/packages/slider/src/main.vue +427 -427
  174. package/packages/statistic/src/main.vue +204 -204
  175. package/packages/steps/src/steps.vue +68 -68
  176. package/packages/switch/src/component.vue +182 -182
  177. package/packages/table/src/config.js +153 -153
  178. package/packages/table/src/filter-panel.vue +194 -194
  179. package/packages/table/src/store/current.js +76 -76
  180. package/packages/table/src/store/helper.js +41 -41
  181. package/packages/table/src/store/index.js +147 -147
  182. package/packages/table/src/store/watcher.js +502 -502
  183. package/packages/table/src/table-body.js +469 -469
  184. package/packages/table/src/table-column.js +328 -328
  185. package/packages/table/src/table-header.js +571 -571
  186. package/packages/table/src/table-layout.js +249 -249
  187. package/packages/table/src/table-row.js +101 -101
  188. package/packages/table/src/table.vue +740 -740
  189. package/packages/table/src/util.js +273 -273
  190. package/packages/tabs/src/tab-bar.vue +57 -57
  191. package/packages/tabs/src/tab-nav.vue +294 -294
  192. package/packages/tabs/src/tabs.vue +201 -201
  193. package/packages/theme-chalk/src/button.scss +416 -416
  194. package/packages/theme-chalk/src/cascader.scss +252 -252
  195. package/packages/theme-chalk/src/checkbox.scss +419 -419
  196. package/packages/theme-chalk/src/common/var.scss +795 -795
  197. package/packages/theme-chalk/src/form.scss +201 -201
  198. package/packages/theme-chalk/src/input.scss +591 -591
  199. package/packages/theme-chalk/src/iovfont.scss +803 -803
  200. package/packages/theme-chalk/src/link.scss +8 -8
  201. package/packages/theme-chalk/src/message-box.scss +207 -207
  202. package/packages/theme-chalk/src/mixins/_button.scss +136 -136
  203. package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
  204. package/packages/theme-chalk/src/radio-button.scss +115 -115
  205. package/packages/theme-chalk/src/select.scss +270 -270
  206. package/packages/theme-chalk/src/tabs.scss +755 -755
  207. package/packages/theme-chalk/src/upload.scss +568 -568
  208. package/packages/tooltip/src/main.js +242 -242
  209. package/packages/transfer/src/main.vue +231 -231
  210. package/packages/transfer/src/transfer-panel.vue +251 -251
  211. package/packages/tree/src/model/node.js +484 -484
  212. package/packages/tree/src/tree-node.vue +279 -279
  213. package/packages/tree/src/tree.vue +496 -496
  214. package/packages/upload/src/index.vue +420 -420
  215. package/packages/upload/src/upload-file.vue +98 -98
  216. package/packages/upload/src/upload-list.vue +115 -115
  217. package/packages/upload/src/upload-picture.vue +98 -98
  218. package/packages/upload/src/upload.vue +231 -231
  219. package/packages/upload/src/utils.js +31 -31
  220. package/src/directives/repeat-click.js +26 -26
  221. package/src/index.js +259 -259
  222. package/src/locale/format.js +46 -46
  223. package/src/locale/index.js +48 -48
  224. package/src/locale/lang/lo-LA.js +126 -126
  225. package/src/mixins/locale.js +9 -9
  226. package/src/mixins/migrating.js +54 -54
  227. package/src/transitions/collapse-transition.js +77 -77
  228. package/src/utils/clickoutside.js +76 -76
  229. package/src/utils/date-util.js +282 -282
  230. package/src/utils/popup/index.js +218 -218
  231. package/src/utils/popup/popup-manager.js +194 -194
  232. package/src/utils/util.js +245 -245
  233. package/src/utils/vdom.js +5 -5
  234. package/src/utils/vue-popper.js +198 -198
@@ -1,328 +1,328 @@
1
- import { cellStarts, cellForced, defaultRenderCell, treeCellPrefix } from './config';
2
- import { mergeOptions, parseWidth, parseMinWidth, compose } from './util';
3
- import ElCheckbox from 'iov-design/packages/checkbox';
4
-
5
- let columnIdSeed = 1;
6
-
7
- export default {
8
- name: 'ElTableColumn',
9
-
10
- props: {
11
- type: {
12
- type: String,
13
- default: 'default'
14
- },
15
- label: String,
16
- className: String,
17
- labelClassName: String,
18
- property: String,
19
- prop: String,
20
- width: {},
21
- minWidth: {},
22
- renderHeader: Function,
23
- sortable: {
24
- type: [Boolean, String],
25
- default: false
26
- },
27
- sortMethod: Function,
28
- sortBy: [String, Function, Array],
29
- resizable: {
30
- type: Boolean,
31
- default: true
32
- },
33
- columnKey: String,
34
- align: String,
35
- verticalAlign: String,
36
- headerAlign: String,
37
- showTooltipWhenOverflow: Boolean,
38
- showOverflowTooltip: Boolean,
39
- fixed: [Boolean, String],
40
- formatter: Function,
41
- selectable: Function,
42
- reserveSelection: Boolean,
43
- filterMethod: Function,
44
- filteredValue: Array,
45
- filters: Array,
46
- filterPlacement: String,
47
- filterMultiple: {
48
- type: Boolean,
49
- default: true
50
- },
51
- index: [Number, Function],
52
- sortOrders: {
53
- type: Array,
54
- default() {
55
- return ['ascending', 'descending', null];
56
- },
57
- validator(val) {
58
- return val.every(order => ['ascending', 'descending', null].indexOf(order) > -1);
59
- }
60
- },
61
- emptyValuePlaceholder: String
62
- },
63
-
64
- data() {
65
- return {
66
- isSubColumn: false,
67
- columns: []
68
- };
69
- },
70
-
71
- computed: {
72
- owner() {
73
- let parent = this.$parent;
74
- while (parent && !parent.tableId) {
75
- parent = parent.$parent;
76
- }
77
- return parent;
78
- },
79
-
80
- columnOrTableParent() {
81
- let parent = this.$parent;
82
- while (parent && !parent.tableId && !parent.columnId) {
83
- parent = parent.$parent;
84
- }
85
- return parent;
86
- },
87
-
88
- realWidth() {
89
- return parseWidth(this.width);
90
- },
91
-
92
- realMinWidth() {
93
- return parseMinWidth(this.minWidth);
94
- },
95
-
96
- realAlign() {
97
- return this.align ? 'is-' + this.align : null;
98
- },
99
-
100
- realVerticalAlign() {
101
- return this.verticalAlign ? 'is-' + this.verticalAlign : null;
102
- },
103
-
104
- realHeaderAlign() {
105
- return this.headerAlign ? 'is-' + this.headerAlign : this.realAlign;
106
- }
107
- },
108
-
109
- methods: {
110
- getPropsData(...props) {
111
- return props.reduce((prev, cur) => {
112
- if (Array.isArray(cur)) {
113
- cur.forEach((key) => {
114
- prev[key] = this[key];
115
- });
116
- }
117
- return prev;
118
- }, {});
119
- },
120
-
121
- getColumnElIndex(children, child) {
122
- return [].indexOf.call(children, child);
123
- },
124
-
125
- setColumnWidth(column) {
126
- if (this.realWidth) {
127
- column.width = this.realWidth;
128
- }
129
- if (this.realMinWidth) {
130
- column.minWidth = this.realMinWidth;
131
- }
132
- if (!column.minWidth) {
133
- column.minWidth = 80;
134
- }
135
- column.realWidth = column.width === undefined ? column.minWidth : column.width;
136
- return column;
137
- },
138
-
139
- setColumnForcedProps(column) {
140
- // 对于特定类型的 column,某些属性不允许设置
141
- const type = column.type;
142
- const source = cellForced[type] || {};
143
- Object.keys(source).forEach(prop => {
144
- let value = source[prop];
145
- if (value !== undefined) {
146
- column[prop] = prop === 'className' ? `${column[prop]} ${value}` : value;
147
- }
148
- });
149
- return column;
150
- },
151
-
152
- setColumnRenders(column) {
153
- // renderHeader 属性不推荐使用。
154
- if (this.renderHeader) {
155
- console.warn('[Element Warn][TableColumn]Comparing to render-header, scoped-slot header is easier to use. We recommend users to use scoped-slot header.');
156
- } else if (column.type !== 'selection') {
157
- column.renderHeader = (h, scope) => {
158
- const renderHeader = this.$scopedSlots.header;
159
- return renderHeader ? renderHeader(scope) : column.label;
160
- };
161
- }
162
-
163
- let originRenderCell = column.renderCell;
164
- // TODO: 这里的实现调整
165
- if (column.type === 'expand') {
166
- // 对于展开行,renderCell 不允许配置的。在上一步中已经设置过,这里需要简单封装一下。
167
- column.renderCell = (h, data) => (<div class="cell">
168
- { originRenderCell(h, data) }
169
- </div>);
170
- this.owner.renderExpanded = (h, data) => {
171
- return this.$scopedSlots.default
172
- ? this.$scopedSlots.default(data)
173
- : this.$slots.default;
174
- };
175
- } else {
176
- originRenderCell = originRenderCell || defaultRenderCell;
177
- // 对 renderCell 进行包装
178
- column.renderCell = (h, data) => {
179
- let children = null;
180
- if (this.$scopedSlots.default) {
181
- children = this.$scopedSlots.default(data);
182
- } else {
183
- children = originRenderCell(h, data);
184
- }
185
- const prefix = treeCellPrefix(h, data);
186
- const props = {
187
- class: 'cell',
188
- style: {}
189
- };
190
- if (column.showOverflowTooltip) {
191
- props.class += ' el-tooltip';
192
- props.style = {width: (data.column.realWidth || data.column.width) - 1 + 'px'};
193
- }
194
- return (<div { ...props }>
195
- { prefix }
196
- { children }
197
- </div>);
198
- };
199
- }
200
- return column;
201
- },
202
-
203
- registerNormalWatchers() {
204
- const props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip'];
205
- // 一些属性具有别名
206
- const aliases = {
207
- prop: 'property',
208
- realAlign: 'align',
209
- realVerticalAlign: 'verticalAlign',
210
- realHeaderAlign: 'headerAlign',
211
- realWidth: 'width'
212
- };
213
- const allAliases = props.reduce((prev, cur) => {
214
- prev[cur] = cur;
215
- return prev;
216
- }, aliases);
217
-
218
- Object.keys(allAliases).forEach(key => {
219
- const columnKey = aliases[key];
220
-
221
- this.$watch(key, (newVal) => {
222
- this.columnConfig[columnKey] = newVal;
223
- });
224
- });
225
- },
226
-
227
- registerComplexWatchers() {
228
- const props = ['fixed'];
229
- const aliases = {
230
- realWidth: 'width',
231
- realMinWidth: 'minWidth'
232
- };
233
- const allAliases = props.reduce((prev, cur) => {
234
- prev[cur] = cur;
235
- return prev;
236
- }, aliases);
237
-
238
- Object.keys(allAliases).forEach(key => {
239
- const columnKey = aliases[key];
240
-
241
- this.$watch(key, (newVal) => {
242
- this.columnConfig[columnKey] = newVal;
243
- const updateColumns = columnKey === 'fixed';
244
- this.owner.store.scheduleLayout(updateColumns);
245
- });
246
- });
247
- }
248
- },
249
-
250
- components: {
251
- ElCheckbox
252
- },
253
-
254
- beforeCreate() {
255
- this.row = {};
256
- this.column = {};
257
- this.$index = 0;
258
- this.columnId = '';
259
- },
260
-
261
- created() {
262
- const parent = this.columnOrTableParent;
263
- this.isSubColumn = this.owner !== parent;
264
- this.columnId = (parent.tableId || parent.columnId) + '_column_' + columnIdSeed++;
265
-
266
- const type = this.type || 'default';
267
- const sortable = this.sortable === '' ? true : this.sortable;
268
- const defaults = {
269
- ...cellStarts[type],
270
- id: this.columnId,
271
- type: type,
272
- property: this.prop || this.property,
273
- align: this.realAlign,
274
- verticalAlign: this.realVerticalAlign,
275
- headerAlign: this.realHeaderAlign,
276
- showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
277
- // filter 相关属性
278
- filterable: this.filters || this.filterMethod,
279
- filteredValue: [],
280
- filterPlacement: '',
281
- isColumnGroup: false,
282
- filterOpened: false,
283
- // sort 相关属性
284
- sortable: sortable,
285
- // index 列
286
- index: this.index,
287
- emptyValuePlaceholder: this.emptyValuePlaceholder || ''
288
- };
289
-
290
- const basicProps = ['columnKey', 'label', 'className', 'labelClassName', 'type', 'renderHeader', 'formatter', 'fixed', 'resizable'];
291
- const sortProps = ['sortMethod', 'sortBy', 'sortOrders'];
292
- const selectProps = ['selectable', 'reserveSelection'];
293
- const filterProps = ['filterMethod', 'filters', 'filterMultiple', 'filterOpened', 'filteredValue', 'filterPlacement'];
294
-
295
- let column = this.getPropsData(basicProps, sortProps, selectProps, filterProps);
296
- column = mergeOptions(defaults, column);
297
-
298
- // 注意 compose 中函数执行的顺序是从右到左
299
- const chains = compose(this.setColumnRenders, this.setColumnWidth, this.setColumnForcedProps);
300
- column = chains(column);
301
-
302
- this.columnConfig = column;
303
-
304
- // 注册 watcher
305
- this.registerNormalWatchers();
306
- this.registerComplexWatchers();
307
- },
308
-
309
- mounted() {
310
- const owner = this.owner;
311
- const parent = this.columnOrTableParent;
312
- const children = this.isSubColumn ? parent.$el.children : parent.$refs.hiddenColumns.children;
313
- const columnIndex = this.getColumnElIndex(children, this.$el);
314
-
315
- owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
316
- },
317
-
318
- destroyed() {
319
- if (!this.$parent) return;
320
- const parent = this.$parent;
321
- this.owner.store.commit('removeColumn', this.columnConfig, this.isSubColumn ? parent.columnConfig : null);
322
- },
323
-
324
- render(h) {
325
- // slots 也要渲染,需要计算合并表头
326
- return h('div', this.$slots.default);
327
- }
328
- };
1
+ import { cellStarts, cellForced, defaultRenderCell, treeCellPrefix } from './config';
2
+ import { mergeOptions, parseWidth, parseMinWidth, compose } from './util';
3
+ import ElCheckbox from 'iov-design/packages/checkbox';
4
+
5
+ let columnIdSeed = 1;
6
+
7
+ export default {
8
+ name: 'ElTableColumn',
9
+
10
+ props: {
11
+ type: {
12
+ type: String,
13
+ default: 'default'
14
+ },
15
+ label: String,
16
+ className: String,
17
+ labelClassName: String,
18
+ property: String,
19
+ prop: String,
20
+ width: {},
21
+ minWidth: {},
22
+ renderHeader: Function,
23
+ sortable: {
24
+ type: [Boolean, String],
25
+ default: false
26
+ },
27
+ sortMethod: Function,
28
+ sortBy: [String, Function, Array],
29
+ resizable: {
30
+ type: Boolean,
31
+ default: true
32
+ },
33
+ columnKey: String,
34
+ align: String,
35
+ verticalAlign: String,
36
+ headerAlign: String,
37
+ showTooltipWhenOverflow: Boolean,
38
+ showOverflowTooltip: Boolean,
39
+ fixed: [Boolean, String],
40
+ formatter: Function,
41
+ selectable: Function,
42
+ reserveSelection: Boolean,
43
+ filterMethod: Function,
44
+ filteredValue: Array,
45
+ filters: Array,
46
+ filterPlacement: String,
47
+ filterMultiple: {
48
+ type: Boolean,
49
+ default: true
50
+ },
51
+ index: [Number, Function],
52
+ sortOrders: {
53
+ type: Array,
54
+ default() {
55
+ return ['ascending', 'descending', null];
56
+ },
57
+ validator(val) {
58
+ return val.every(order => ['ascending', 'descending', null].indexOf(order) > -1);
59
+ }
60
+ },
61
+ emptyValuePlaceholder: String
62
+ },
63
+
64
+ data() {
65
+ return {
66
+ isSubColumn: false,
67
+ columns: []
68
+ };
69
+ },
70
+
71
+ computed: {
72
+ owner() {
73
+ let parent = this.$parent;
74
+ while (parent && !parent.tableId) {
75
+ parent = parent.$parent;
76
+ }
77
+ return parent;
78
+ },
79
+
80
+ columnOrTableParent() {
81
+ let parent = this.$parent;
82
+ while (parent && !parent.tableId && !parent.columnId) {
83
+ parent = parent.$parent;
84
+ }
85
+ return parent;
86
+ },
87
+
88
+ realWidth() {
89
+ return parseWidth(this.width);
90
+ },
91
+
92
+ realMinWidth() {
93
+ return parseMinWidth(this.minWidth);
94
+ },
95
+
96
+ realAlign() {
97
+ return this.align ? 'is-' + this.align : null;
98
+ },
99
+
100
+ realVerticalAlign() {
101
+ return this.verticalAlign ? 'is-' + this.verticalAlign : null;
102
+ },
103
+
104
+ realHeaderAlign() {
105
+ return this.headerAlign ? 'is-' + this.headerAlign : this.realAlign;
106
+ }
107
+ },
108
+
109
+ methods: {
110
+ getPropsData(...props) {
111
+ return props.reduce((prev, cur) => {
112
+ if (Array.isArray(cur)) {
113
+ cur.forEach((key) => {
114
+ prev[key] = this[key];
115
+ });
116
+ }
117
+ return prev;
118
+ }, {});
119
+ },
120
+
121
+ getColumnElIndex(children, child) {
122
+ return [].indexOf.call(children, child);
123
+ },
124
+
125
+ setColumnWidth(column) {
126
+ if (this.realWidth) {
127
+ column.width = this.realWidth;
128
+ }
129
+ if (this.realMinWidth) {
130
+ column.minWidth = this.realMinWidth;
131
+ }
132
+ if (!column.minWidth) {
133
+ column.minWidth = 80;
134
+ }
135
+ column.realWidth = column.width === undefined ? column.minWidth : column.width;
136
+ return column;
137
+ },
138
+
139
+ setColumnForcedProps(column) {
140
+ // 对于特定类型的 column,某些属性不允许设置
141
+ const type = column.type;
142
+ const source = cellForced[type] || {};
143
+ Object.keys(source).forEach(prop => {
144
+ let value = source[prop];
145
+ if (value !== undefined) {
146
+ column[prop] = prop === 'className' ? `${column[prop]} ${value}` : value;
147
+ }
148
+ });
149
+ return column;
150
+ },
151
+
152
+ setColumnRenders(column) {
153
+ // renderHeader 属性不推荐使用。
154
+ if (this.renderHeader) {
155
+ console.warn('[Element Warn][TableColumn]Comparing to render-header, scoped-slot header is easier to use. We recommend users to use scoped-slot header.');
156
+ } else if (column.type !== 'selection') {
157
+ column.renderHeader = (h, scope) => {
158
+ const renderHeader = this.$scopedSlots.header;
159
+ return renderHeader ? renderHeader(scope) : column.label;
160
+ };
161
+ }
162
+
163
+ let originRenderCell = column.renderCell;
164
+ // TODO: 这里的实现调整
165
+ if (column.type === 'expand') {
166
+ // 对于展开行,renderCell 不允许配置的。在上一步中已经设置过,这里需要简单封装一下。
167
+ column.renderCell = (h, data) => (<div class="cell">
168
+ { originRenderCell(h, data) }
169
+ </div>);
170
+ this.owner.renderExpanded = (h, data) => {
171
+ return this.$scopedSlots.default
172
+ ? this.$scopedSlots.default(data)
173
+ : this.$slots.default;
174
+ };
175
+ } else {
176
+ originRenderCell = originRenderCell || defaultRenderCell;
177
+ // 对 renderCell 进行包装
178
+ column.renderCell = (h, data) => {
179
+ let children = null;
180
+ if (this.$scopedSlots.default) {
181
+ children = this.$scopedSlots.default(data);
182
+ } else {
183
+ children = originRenderCell(h, data);
184
+ }
185
+ const prefix = treeCellPrefix(h, data);
186
+ const props = {
187
+ class: 'cell',
188
+ style: {}
189
+ };
190
+ if (column.showOverflowTooltip) {
191
+ props.class += ' el-tooltip';
192
+ props.style = {width: (data.column.realWidth || data.column.width) - 1 + 'px'};
193
+ }
194
+ return (<div { ...props }>
195
+ { prefix }
196
+ { children }
197
+ </div>);
198
+ };
199
+ }
200
+ return column;
201
+ },
202
+
203
+ registerNormalWatchers() {
204
+ const props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip'];
205
+ // 一些属性具有别名
206
+ const aliases = {
207
+ prop: 'property',
208
+ realAlign: 'align',
209
+ realVerticalAlign: 'verticalAlign',
210
+ realHeaderAlign: 'headerAlign',
211
+ realWidth: 'width'
212
+ };
213
+ const allAliases = props.reduce((prev, cur) => {
214
+ prev[cur] = cur;
215
+ return prev;
216
+ }, aliases);
217
+
218
+ Object.keys(allAliases).forEach(key => {
219
+ const columnKey = aliases[key];
220
+
221
+ this.$watch(key, (newVal) => {
222
+ this.columnConfig[columnKey] = newVal;
223
+ });
224
+ });
225
+ },
226
+
227
+ registerComplexWatchers() {
228
+ const props = ['fixed'];
229
+ const aliases = {
230
+ realWidth: 'width',
231
+ realMinWidth: 'minWidth'
232
+ };
233
+ const allAliases = props.reduce((prev, cur) => {
234
+ prev[cur] = cur;
235
+ return prev;
236
+ }, aliases);
237
+
238
+ Object.keys(allAliases).forEach(key => {
239
+ const columnKey = aliases[key];
240
+
241
+ this.$watch(key, (newVal) => {
242
+ this.columnConfig[columnKey] = newVal;
243
+ const updateColumns = columnKey === 'fixed';
244
+ this.owner.store.scheduleLayout(updateColumns);
245
+ });
246
+ });
247
+ }
248
+ },
249
+
250
+ components: {
251
+ ElCheckbox
252
+ },
253
+
254
+ beforeCreate() {
255
+ this.row = {};
256
+ this.column = {};
257
+ this.$index = 0;
258
+ this.columnId = '';
259
+ },
260
+
261
+ created() {
262
+ const parent = this.columnOrTableParent;
263
+ this.isSubColumn = this.owner !== parent;
264
+ this.columnId = (parent.tableId || parent.columnId) + '_column_' + columnIdSeed++;
265
+
266
+ const type = this.type || 'default';
267
+ const sortable = this.sortable === '' ? true : this.sortable;
268
+ const defaults = {
269
+ ...cellStarts[type],
270
+ id: this.columnId,
271
+ type: type,
272
+ property: this.prop || this.property,
273
+ align: this.realAlign,
274
+ verticalAlign: this.realVerticalAlign,
275
+ headerAlign: this.realHeaderAlign,
276
+ showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
277
+ // filter 相关属性
278
+ filterable: this.filters || this.filterMethod,
279
+ filteredValue: [],
280
+ filterPlacement: '',
281
+ isColumnGroup: false,
282
+ filterOpened: false,
283
+ // sort 相关属性
284
+ sortable: sortable,
285
+ // index 列
286
+ index: this.index,
287
+ emptyValuePlaceholder: this.emptyValuePlaceholder || ''
288
+ };
289
+
290
+ const basicProps = ['columnKey', 'label', 'className', 'labelClassName', 'type', 'renderHeader', 'formatter', 'fixed', 'resizable'];
291
+ const sortProps = ['sortMethod', 'sortBy', 'sortOrders'];
292
+ const selectProps = ['selectable', 'reserveSelection'];
293
+ const filterProps = ['filterMethod', 'filters', 'filterMultiple', 'filterOpened', 'filteredValue', 'filterPlacement'];
294
+
295
+ let column = this.getPropsData(basicProps, sortProps, selectProps, filterProps);
296
+ column = mergeOptions(defaults, column);
297
+
298
+ // 注意 compose 中函数执行的顺序是从右到左
299
+ const chains = compose(this.setColumnRenders, this.setColumnWidth, this.setColumnForcedProps);
300
+ column = chains(column);
301
+
302
+ this.columnConfig = column;
303
+
304
+ // 注册 watcher
305
+ this.registerNormalWatchers();
306
+ this.registerComplexWatchers();
307
+ },
308
+
309
+ mounted() {
310
+ const owner = this.owner;
311
+ const parent = this.columnOrTableParent;
312
+ const children = this.isSubColumn ? parent.$el.children : parent.$refs.hiddenColumns.children;
313
+ const columnIndex = this.getColumnElIndex(children, this.$el);
314
+
315
+ owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
316
+ },
317
+
318
+ destroyed() {
319
+ if (!this.$parent) return;
320
+ const parent = this.$parent;
321
+ this.owner.store.commit('removeColumn', this.columnConfig, this.isSubColumn ? parent.columnConfig : null);
322
+ },
323
+
324
+ render(h) {
325
+ // slots 也要渲染,需要计算合并表头
326
+ return h('div', this.$slots.default);
327
+ }
328
+ };