umy-ui-table 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/lib/button.js +1 -0
  4. package/lib/icon.js +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/locale/format.js +56 -0
  7. package/lib/locale/index.js +72 -0
  8. package/lib/locale/lang/en.js +123 -0
  9. package/lib/locale/lang/zh-CN.js +119 -0
  10. package/lib/mixins/locale.js +17 -0
  11. package/lib/theme-chalk/base.css +0 -0
  12. package/lib/theme-chalk/button.css +1 -0
  13. package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
  14. package/lib/theme-chalk/fonts/element-icons.woff +0 -0
  15. package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
  16. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
  17. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
  18. package/lib/theme-chalk/icon.css +1 -0
  19. package/lib/theme-chalk/index.css +1 -0
  20. package/lib/theme-chalk/u-table-column.css +0 -0
  21. package/lib/theme-chalk/u-table.css +1 -0
  22. package/lib/theme-chalk/ux-grid.css +1 -0
  23. package/lib/theme-chalk/ux-table-column.css +0 -0
  24. package/lib/u-table-column.js +1 -0
  25. package/lib/u-table.js +1 -0
  26. package/lib/umd/locale/en.js +139 -0
  27. package/lib/umd/locale/zh-CN.js +135 -0
  28. package/lib/umy-ui.common.js +1 -0
  29. package/lib/utils/svg.js +33 -0
  30. package/lib/utils/types.js +35 -0
  31. package/lib/utils/util.js +268 -0
  32. package/lib/ux-grid.js +1 -0
  33. package/lib/ux-table-column.js +1 -0
  34. package/package.json +117 -0
  35. package/packages/button/index.js +7 -0
  36. package/packages/button/src/button-group.vue +10 -0
  37. package/packages/button/src/button.vue +166 -0
  38. package/packages/checkbox/index.js +8 -0
  39. package/packages/checkbox/src/checkbox-button.vue +199 -0
  40. package/packages/checkbox/src/checkbox-group.vue +48 -0
  41. package/packages/checkbox/src/checkbox.vue +222 -0
  42. package/packages/checkbox-button/index.js +8 -0
  43. package/packages/checkbox-group/index.js +8 -0
  44. package/packages/icon/index.js +7 -0
  45. package/packages/icon/src/icon.vue +40 -0
  46. package/packages/input/index.js +2 -0
  47. package/packages/input/src/calcTextareaHeight.js +104 -0
  48. package/packages/input/src/input.vue +424 -0
  49. package/packages/option/index.js +2 -0
  50. package/packages/pagination/index.js +2 -0
  51. package/packages/pagination/src/pager.vue +163 -0
  52. package/packages/pagination/src/pagination.js +386 -0
  53. package/packages/scrollbar/index.js +8 -0
  54. package/packages/scrollbar/src/bar.js +92 -0
  55. package/packages/scrollbar/src/main.js +130 -0
  56. package/packages/scrollbar/src/util.js +34 -0
  57. package/packages/select/index.js +2 -0
  58. package/packages/select/src/navigation-mixin.js +54 -0
  59. package/packages/select/src/option-group.vue +60 -0
  60. package/packages/select/src/option.vue +163 -0
  61. package/packages/select/src/select-dropdown.vue +74 -0
  62. package/packages/select/src/select.vue +889 -0
  63. package/packages/table/index.js +8 -0
  64. package/packages/table/src/config.js +123 -0
  65. package/packages/table/src/dropdown.js +28 -0
  66. package/packages/table/src/filter-panel.vue +194 -0
  67. package/packages/table/src/layout-observer.js +68 -0
  68. package/packages/table/src/store/current.js +71 -0
  69. package/packages/table/src/store/expand.js +65 -0
  70. package/packages/table/src/store/helper.js +37 -0
  71. package/packages/table/src/store/index.js +145 -0
  72. package/packages/table/src/store/tree.js +208 -0
  73. package/packages/table/src/store/watcher.js +448 -0
  74. package/packages/table/src/table-body.js +493 -0
  75. package/packages/table/src/table-column.js +381 -0
  76. package/packages/table/src/table-footer.js +174 -0
  77. package/packages/table/src/table-header.js +537 -0
  78. package/packages/table/src/table-layout.js +231 -0
  79. package/packages/table/src/table.vue +741 -0
  80. package/packages/table/src/util.js +256 -0
  81. package/packages/tag/index.js +8 -0
  82. package/packages/tag/src/tag.vue +58 -0
  83. package/packages/tools/directives/mousewheel.js +18 -0
  84. package/packages/tools/directives/repeat-click.js +24 -0
  85. package/packages/tools/locale/format.js +46 -0
  86. package/packages/tools/locale/index.js +48 -0
  87. package/packages/tools/locale/lang/en.js +120 -0
  88. package/packages/tools/locale/lang/zh-CN.js +116 -0
  89. package/packages/tools/mixins/emitter.js +33 -0
  90. package/packages/tools/mixins/focus.js +9 -0
  91. package/packages/tools/mixins/locale.js +9 -0
  92. package/packages/tools/mixins/migrating.js +54 -0
  93. package/packages/tools/transitions/collapse-transition.js +77 -0
  94. package/packages/tools/utils/after-leave.js +27 -0
  95. package/packages/tools/utils/aria-dialog.js +90 -0
  96. package/packages/tools/utils/aria-utils.js +122 -0
  97. package/packages/tools/utils/clickoutside.js +76 -0
  98. package/packages/tools/utils/date-util.js +292 -0
  99. package/packages/tools/utils/date.js +368 -0
  100. package/packages/tools/utils/dom.js +227 -0
  101. package/packages/tools/utils/menu/aria-menubar.js +14 -0
  102. package/packages/tools/utils/menu/aria-menuitem.js +49 -0
  103. package/packages/tools/utils/menu/aria-submenu.js +59 -0
  104. package/packages/tools/utils/merge.js +15 -0
  105. package/packages/tools/utils/popper.js +1276 -0
  106. package/packages/tools/utils/popup/index.js +218 -0
  107. package/packages/tools/utils/popup/popup-manager.js +194 -0
  108. package/packages/tools/utils/resize-event.js +35 -0
  109. package/packages/tools/utils/scroll-into-view.js +27 -0
  110. package/packages/tools/utils/scrollbar-width.js +29 -0
  111. package/packages/tools/utils/shared.js +7 -0
  112. package/packages/tools/utils/svg.js +1 -0
  113. package/packages/tools/utils/types.js +28 -0
  114. package/packages/tools/utils/util.js +241 -0
  115. package/packages/tools/utils/vdom.js +5 -0
  116. package/packages/tools/utils/vue-popper.js +198 -0
  117. package/packages/tooltip/index.js +8 -0
  118. package/packages/tooltip/src/main.js +241 -0
  119. package/packages/u-table/index.js +4 -0
  120. package/packages/u-table/revise-el-table-mixins/index.js +10 -0
  121. package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
  122. package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
  123. package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
  124. package/packages/u-table/src/u-table.vue +248 -0
  125. package/packages/u-table/u-table-mixins/index.js +483 -0
  126. package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
  127. package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
  128. package/packages/u-table-column/index.js +8 -0
  129. package/packages/utils/common.js +27 -0
  130. package/packages/ux-grid/index.js +6 -0
  131. package/packages/ux-grid/mixins/index.js +707 -0
  132. package/packages/ux-grid/src/interceptor.js +6 -0
  133. package/packages/ux-grid/src/ux-grid.vue +301 -0
  134. package/packages/ux-table-column/index.js +10 -0
  135. package/tools/locale/format.js +46 -0
  136. package/tools/locale/index.js +54 -0
  137. package/tools/locale/lang/en.js +120 -0
  138. package/tools/locale/lang/zh-CN.js +116 -0
  139. package/tools/mixins/locale.js +9 -0
  140. package/tools/utils/svg.js +1 -0
  141. package/tools/utils/types.js +28 -0
  142. package/tools/utils/util.js +241 -0
@@ -0,0 +1,8 @@
1
+ import ElTable from './src/table';
2
+
3
+ /* istanbul ignore next */
4
+ ElTable.install = function(Vue) {
5
+ Vue.component(ElTable.name, ElTable);
6
+ };
7
+
8
+ export default ElTable;
@@ -0,0 +1,123 @@
1
+ import { getPropByPath } from '../../tools/utils/util';
2
+
3
+ export const cellStarts = {
4
+ default: {
5
+ order: ''
6
+ },
7
+ selection: {
8
+ width: 48,
9
+ minWidth: 48,
10
+ realWidth: 48,
11
+ order: '',
12
+ className: 'el-table-column--selection'
13
+ },
14
+ expand: {
15
+ width: 48,
16
+ minWidth: 48,
17
+ realWidth: 48,
18
+ order: ''
19
+ },
20
+ index: {
21
+ width: 48,
22
+ minWidth: 48,
23
+ realWidth: 48,
24
+ order: ''
25
+ }
26
+ };
27
+
28
+ // 这些选项不应该被覆盖
29
+ export const cellForced = {
30
+ selection: {
31
+ renderHeader: function(h, { store }) {
32
+ return <el-checkbox
33
+ disabled={ store.states.data && store.states.data.length === 0 }
34
+ indeterminate={ store.states.selection.length > 0 && !this.isAllSelected }
35
+ nativeOn-click={ this.toggleAllSelection }
36
+ value={ this.isAllSelected } />;
37
+ },
38
+ renderCell: function(h, { row, column, store, $index }) {
39
+ return <el-checkbox
40
+ nativeOn-click={ (event) => event.stopPropagation() }
41
+ value={ store.isSelected(row) }
42
+ disabled={ column.selectable ? !column.selectable.call(null, row, $index) : false }
43
+ on-input={ () => { store.commit('rowSelectedChanged', row); } } />;
44
+ },
45
+ sortable: false,
46
+ resizable: false
47
+ },
48
+ index: {
49
+ renderHeader: function(h, { column }) {
50
+ return column.label || '#';
51
+ },
52
+ renderCell: function(h, { $index, column }) {
53
+ let i = $index + 1;
54
+ const index = column.index;
55
+
56
+ if (typeof index === 'number') {
57
+ i = $index + index;
58
+ } else if (typeof index === 'function') {
59
+ i = index($index);
60
+ }
61
+
62
+ return <div>{ i }</div>;
63
+ },
64
+ sortable: false
65
+ },
66
+ expand: {
67
+ renderHeader: function(h, { column }) {
68
+ return column.label || '';
69
+ },
70
+ renderCell: function(h, { row, store }) {
71
+ const classes = ['el-table__expand-icon'];
72
+ if (store.states.expandRows.indexOf(row) > -1) {
73
+ classes.push('el-table__expand-icon--expanded');
74
+ }
75
+ const callback = function(e) {
76
+ e.stopPropagation();
77
+ store.toggleRowExpansion(row);
78
+ };
79
+ return (<div class={ classes }
80
+ on-click={callback}>
81
+ <i class='el-icon el-icon-arrow-right'></i>
82
+ </div>);
83
+ },
84
+ sortable: false,
85
+ resizable: false,
86
+ className: 'el-table__expand-column'
87
+ }
88
+ };
89
+
90
+ export function defaultRenderCell(h, { row, column, $index }) {
91
+ const property = column.property;
92
+ const value = property && getPropByPath(row, property).v;
93
+ if (column && column.formatter) {
94
+ return column.formatter(row, column, value, $index);
95
+ }
96
+ return value;
97
+ }
98
+
99
+ export function treeCellPrefix(h, { row, treeNode, store }) {
100
+ if (!treeNode) return null;
101
+ const ele = [];
102
+ const callback = function(e) {
103
+ e.stopPropagation();
104
+ store.loadOrToggle(row);
105
+ };
106
+ if (treeNode.indent) {
107
+ ele.push(<span class="el-table__indent" style={{'padding-left': treeNode.indent + 'px'}}></span>);
108
+ }
109
+ if (typeof treeNode.expanded === 'boolean' && !treeNode.noLazyChildren) {
110
+ const expandClasses = ['el-table__expand-icon', treeNode.expanded ? 'el-table__expand-icon--expanded' : ''];
111
+ let iconClasses = ['el-icon-arrow-right'];
112
+ if (treeNode.loading) {
113
+ iconClasses = ['el-icon-loading'];
114
+ }
115
+ ele.push(<div class={ expandClasses }
116
+ on-click={ callback }>
117
+ <i class={ iconClasses }></i>
118
+ </div>);
119
+ } else {
120
+ ele.push(<span class="el-table__placeholder"></span>);
121
+ }
122
+ return ele;
123
+ }
@@ -0,0 +1,28 @@
1
+ import Vue from 'vue';
2
+ var dropdowns = [];
3
+
4
+ !Vue.prototype.$isServer && document.addEventListener('click', function(event) {
5
+ dropdowns.forEach(function(dropdown) {
6
+ var target = event.target;
7
+ if (!dropdown || !dropdown.$el) return;
8
+ if (target === dropdown.$el || dropdown.$el.contains(target)) {
9
+ return;
10
+ }
11
+ dropdown.handleOutsideClick && dropdown.handleOutsideClick(event);
12
+ });
13
+ });
14
+
15
+ export default {
16
+ open(instance) {
17
+ if (instance) {
18
+ dropdowns.push(instance);
19
+ }
20
+ },
21
+
22
+ close(instance) {
23
+ var index = dropdowns.indexOf(instance);
24
+ if (index !== -1) {
25
+ dropdowns.splice(instance, 1);
26
+ }
27
+ }
28
+ };
@@ -0,0 +1,194 @@
1
+ <template>
2
+ <transition name="el-zoom-in-top">
3
+ <div
4
+ class="el-table-filter"
5
+ v-if="multiple"
6
+ v-clickoutside="handleOutsideClick"
7
+ v-show="showPopper">
8
+ <div class="el-table-filter__content">
9
+ <el-scrollbar wrap-class="el-table-filter__wrap">
10
+ <el-checkbox-group class="el-table-filter__checkbox-group" v-model="filteredValue">
11
+ <el-checkbox
12
+ v-for="filter in filters"
13
+ :key="filter.value"
14
+ :label="filter.value">{{ filter.text }}</el-checkbox>
15
+ </el-checkbox-group>
16
+ </el-scrollbar>
17
+ </div>
18
+ <div class="el-table-filter__bottom">
19
+ <button @click="handleConfirm"
20
+ :class="{ 'is-disabled': filteredValue.length === 0 }"
21
+ :disabled="filteredValue.length === 0">{{ t('el.table.confirmFilter') }}</button>
22
+ <button @click="handleReset">{{ t('el.table.resetFilter') }}</button>
23
+ </div>
24
+ </div>
25
+ <div
26
+ class="el-table-filter"
27
+ v-else
28
+ v-clickoutside="handleOutsideClick"
29
+ v-show="showPopper">
30
+ <ul class="el-table-filter__list">
31
+ <li class="el-table-filter__list-item"
32
+ :class="{ 'is-active': filterValue === undefined || filterValue === null }"
33
+ @click="handleSelect(null)">{{ t('el.table.clearFilter') }}</li>
34
+ <li class="el-table-filter__list-item"
35
+ v-for="filter in filters"
36
+ :label="filter.value"
37
+ :key="filter.value"
38
+ :class="{ 'is-active': isActive(filter) }"
39
+ @click="handleSelect(filter.value)" >{{ filter.text }}</li>
40
+ </ul>
41
+ </div>
42
+ </transition>
43
+ </template>
44
+
45
+ <script type="text/babel">
46
+ import Popper from '../../tools/utils/vue-popper';
47
+ import { PopupManager } from '../../tools/utils/popup';
48
+ import Locale from '../../tools/mixins/locale';
49
+ import Clickoutside from '../../tools/utils/clickoutside';
50
+ import Dropdown from './dropdown';
51
+ import ElCheckbox from '../../checkbox';
52
+ import ElCheckboxGroup from '../../checkbox-group';
53
+ import ElScrollbar from '../../scrollbar';
54
+
55
+ export default {
56
+ name: 'ElTableFilterPanel',
57
+
58
+ mixins: [Popper, Locale],
59
+
60
+ directives: {
61
+ Clickoutside
62
+ },
63
+
64
+ components: {
65
+ ElCheckbox,
66
+ ElCheckboxGroup,
67
+ ElScrollbar
68
+ },
69
+
70
+ props: {
71
+ placement: {
72
+ type: String,
73
+ default: 'bottom-end'
74
+ }
75
+ },
76
+
77
+ methods: {
78
+ isActive(filter) {
79
+ return filter.value === this.filterValue;
80
+ },
81
+
82
+ handleOutsideClick() {
83
+ setTimeout(() => {
84
+ this.showPopper = false;
85
+ }, 16);
86
+ },
87
+
88
+ handleConfirm() {
89
+ this.confirmFilter(this.filteredValue);
90
+ this.handleOutsideClick();
91
+ },
92
+
93
+ handleReset() {
94
+ this.filteredValue = [];
95
+ this.confirmFilter(this.filteredValue);
96
+ this.handleOutsideClick();
97
+ },
98
+
99
+ handleSelect(filterValue) {
100
+ this.filterValue = filterValue;
101
+
102
+ if ((typeof filterValue !== 'undefined') && (filterValue !== null)) {
103
+ this.confirmFilter(this.filteredValue);
104
+ } else {
105
+ this.confirmFilter([]);
106
+ }
107
+
108
+ this.handleOutsideClick();
109
+ },
110
+
111
+ confirmFilter(filteredValue) {
112
+ this.table.store.commit('filterChange', {
113
+ column: this.column,
114
+ values: filteredValue
115
+ });
116
+ this.table.store.updateAllSelected();
117
+ }
118
+ },
119
+
120
+ data() {
121
+ return {
122
+ table: null,
123
+ cell: null,
124
+ column: null
125
+ };
126
+ },
127
+
128
+ computed: {
129
+ filters() {
130
+ return this.column && this.column.filters;
131
+ },
132
+
133
+ filterValue: {
134
+ get() {
135
+ return (this.column.filteredValue || [])[0];
136
+ },
137
+ set(value) {
138
+ if (this.filteredValue) {
139
+ if ((typeof value !== 'undefined') && (value !== null)) {
140
+ this.filteredValue.splice(0, 1, value);
141
+ } else {
142
+ this.filteredValue.splice(0, 1);
143
+ }
144
+ }
145
+ }
146
+ },
147
+
148
+ filteredValue: {
149
+ get() {
150
+ if (this.column) {
151
+ return this.column.filteredValue || [];
152
+ }
153
+ return [];
154
+ },
155
+ set(value) {
156
+ if (this.column) {
157
+ this.column.filteredValue = value;
158
+ }
159
+ }
160
+ },
161
+
162
+ multiple() {
163
+ if (this.column) {
164
+ return this.column.filterMultiple;
165
+ }
166
+ return true;
167
+ }
168
+ },
169
+
170
+ mounted() {
171
+ this.popperElm = this.$el;
172
+ this.referenceElm = this.cell;
173
+ this.table.bodyWrapper.addEventListener('scroll', () => {
174
+ this.updatePopper();
175
+ });
176
+
177
+ this.$watch('showPopper', (value) => {
178
+ if (this.column) this.column.filterOpened = value;
179
+ if (value) {
180
+ Dropdown.open(this);
181
+ } else {
182
+ Dropdown.close(this);
183
+ }
184
+ });
185
+ },
186
+ watch: {
187
+ showPopper(val) {
188
+ if (val === true && parseInt(this.popperJS._popper.style.zIndex, 10) < PopupManager.zIndex) {
189
+ this.popperJS._popper.style.zIndex = PopupManager.nextZIndex();
190
+ }
191
+ }
192
+ }
193
+ };
194
+ </script>
@@ -0,0 +1,68 @@
1
+ export default {
2
+ created() {
3
+ this.tableLayout.addObserver(this);
4
+ },
5
+
6
+ destroyed() {
7
+ this.tableLayout.removeObserver(this);
8
+ },
9
+
10
+ computed: {
11
+ tableLayout() {
12
+ let layout = this.layout;
13
+ if (!layout && this.table) {
14
+ layout = this.table.layout;
15
+ }
16
+ if (!layout) {
17
+ throw new Error('Can not find table layout.');
18
+ }
19
+ return layout;
20
+ }
21
+ },
22
+
23
+ mounted() {
24
+ this.onColumnsChange(this.tableLayout);
25
+ this.onScrollableChange(this.tableLayout);
26
+ },
27
+
28
+ updated() {
29
+ if (this.__updated__) return;
30
+ this.onColumnsChange(this.tableLayout);
31
+ this.onScrollableChange(this.tableLayout);
32
+ this.__updated__ = true;
33
+ },
34
+
35
+ methods: {
36
+ onColumnsChange() {
37
+ const cols = this.$el.querySelectorAll('colgroup > col');
38
+ if (!cols.length) return;
39
+ const flattenColumns = this.tableLayout.getFlattenColumns();
40
+ const columnsMap = {};
41
+ flattenColumns.forEach((column) => {
42
+ columnsMap[column.id] = column;
43
+ });
44
+ for (let i = 0, j = cols.length; i < j; i++) {
45
+ const col = cols[i];
46
+ const name = col.getAttribute('name');
47
+ const column = columnsMap[name];
48
+ if (column) {
49
+ col.setAttribute('width', column.realWidth || column.width);
50
+ }
51
+ }
52
+ },
53
+
54
+ onScrollableChange(layout) {
55
+ const cols = this.$el.querySelectorAll('colgroup > col[name=gutter]');
56
+ for (let i = 0, j = cols.length; i < j; i++) {
57
+ const col = cols[i];
58
+ col.setAttribute('width', layout.scrollY ? layout.gutterWidth : '0');
59
+ }
60
+ const ths = this.$el.querySelectorAll('th.gutter');
61
+ for (let i = 0, j = ths.length; i < j; i++) {
62
+ const th = ths[i];
63
+ th.style.width = layout.scrollY ? layout.gutterWidth + 'px' : '0';
64
+ th.style.display = layout.scrollY ? '' : 'none';
65
+ }
66
+ }
67
+ }
68
+ };
@@ -0,0 +1,71 @@
1
+ import { arrayFind } from '../../../tools/utils/util';
2
+ import { getRowIdentity } from '../util';
3
+
4
+ export default {
5
+ data() {
6
+ return {
7
+ states: {
8
+ // 不可响应的,设置 currentRowKey 时,data 不一定存在,也许无法算出正确的 currentRow
9
+ // 把该值缓存一下,当用户点击修改 currentRow 时,把该值重置为 null
10
+ _currentRowKey: null,
11
+ currentRow: null
12
+ }
13
+ };
14
+ },
15
+
16
+ methods: {
17
+ setCurrentRowKey(key) {
18
+ this.assertRowKey();
19
+ this.states._currentRowKey = key;
20
+ this.setCurrentRowByKey(key);
21
+ },
22
+
23
+ restoreCurrentRowKey() {
24
+ this.states._currentRowKey = null;
25
+ },
26
+
27
+ setCurrentRowByKey(key) {
28
+ const { states } = this;
29
+ const { data = [], rowKey } = states;
30
+ let currentRow = null;
31
+ if (rowKey) {
32
+ currentRow = arrayFind(data, item => getRowIdentity(item, rowKey) === key);
33
+ }
34
+ states.currentRow = currentRow;
35
+ },
36
+
37
+ updateCurrentRow(currentRow) {
38
+ const { states, table } = this;
39
+ const { rowKey, _currentRowKey } = states;
40
+ // data 为 null 时,结构时的默认值会被忽略
41
+ const data = states.data || [];
42
+ const oldCurrentRow = states.currentRow;
43
+ if (currentRow) {
44
+ this.restoreCurrentRowKey();
45
+ states.currentRow = currentRow;
46
+ if (oldCurrentRow !== currentRow) {
47
+ this.table.$emit('current-change', currentRow, oldCurrentRow);
48
+ }
49
+ } else {
50
+ // 当 currentRow 不在 data 中时尝试更新数据
51
+ if (data.indexOf(oldCurrentRow) === -1 && oldCurrentRow) {
52
+ this.restoreCurrentRowKey();
53
+ if (rowKey) {
54
+ const currentRowKey = getRowIdentity(oldCurrentRow, rowKey);
55
+ this.setCurrentRowByKey(currentRowKey);
56
+ } else {
57
+ states.currentRow = null;
58
+ }
59
+ if (states.currentRow !== oldCurrentRow) {
60
+ table.$emit('current-change', null, oldCurrentRow);
61
+ }
62
+ } else if (_currentRowKey) {
63
+ this.setCurrentRowByKey(_currentRowKey);
64
+ } else {
65
+ // 修改源码
66
+ states.currentRow = null;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ };
@@ -0,0 +1,65 @@
1
+ import { toggleRowStatus, getKeysMap, getRowIdentity } from '../util';
2
+
3
+ export default {
4
+ data() {
5
+ return {
6
+ states: {
7
+ defaultExpandAll: false,
8
+ expandRows: []
9
+ }
10
+ };
11
+ },
12
+
13
+ methods: {
14
+ updateExpandRows() {
15
+ const { data = [], rowKey, defaultExpandAll, expandRows } = this.states;
16
+ if (defaultExpandAll) {
17
+ this.states.expandRows = data.slice();
18
+ } else if (rowKey) {
19
+ // TODO:这里的代码可以优化
20
+ const expandRowsMap = getKeysMap(expandRows, rowKey);
21
+ this.states.expandRows = data.reduce((prev, row) => {
22
+ const rowId = getRowIdentity(row, rowKey);
23
+ const rowInfo = expandRowsMap[rowId];
24
+ if (rowInfo) {
25
+ prev.push(row);
26
+ }
27
+ return prev;
28
+ }, []);
29
+ } else {
30
+ this.states.expandRows = [];
31
+ }
32
+ },
33
+
34
+ toggleRowExpansion(row, expanded) {
35
+ const changed = toggleRowStatus(this.states.expandRows, row, expanded);
36
+ if (changed) {
37
+ this.table.$emit('expand-change', row, this.states.expandRows.slice());
38
+ this.scheduleLayout();
39
+ }
40
+ },
41
+
42
+ setExpandRowKeys(rowKeys) {
43
+ this.assertRowKey();
44
+ // TODO:这里的代码可以优化
45
+ const { data, rowKey } = this.states;
46
+ const keysMap = getKeysMap(data, rowKey);
47
+ this.states.expandRows = rowKeys.reduce((prev, cur) => {
48
+ const info = keysMap[cur];
49
+ if (info) {
50
+ prev.push(info.row);
51
+ }
52
+ return prev;
53
+ }, []);
54
+ },
55
+
56
+ isRowExpanded(row) {
57
+ const { expandRows = [], rowKey } = this.states;
58
+ if (rowKey) {
59
+ const expandMap = getKeysMap(expandRows, rowKey);
60
+ return !!expandMap[getRowIdentity(row, rowKey)];
61
+ }
62
+ return expandRows.indexOf(row) !== -1;
63
+ }
64
+ }
65
+ };
@@ -0,0 +1,37 @@
1
+ import Store from './index';
2
+
3
+ export function createStore(table, initialState = {}) {
4
+ if (!table) {
5
+ throw new Error('Table is required.');
6
+ }
7
+
8
+ const store = new Store();
9
+ store.table = table;
10
+ Object.keys(initialState).forEach(key => {
11
+ store.states[key] = initialState[key];
12
+ });
13
+ return store;
14
+ }
15
+
16
+ export function mapStates(mapper) {
17
+ const res = {};
18
+ Object.keys(mapper).forEach(key => {
19
+ const value = mapper[key];
20
+ let fn;
21
+ if (typeof value === 'string') {
22
+ fn = function() {
23
+ return this.store.states[value];
24
+ };
25
+ } else if (typeof value === 'function') {
26
+ fn = function() {
27
+ return value.call(this, this.store.states);
28
+ };
29
+ } else {
30
+ console.error('invalid value type');
31
+ }
32
+ if (fn) {
33
+ res[key] = fn;
34
+ }
35
+ });
36
+ return res;
37
+ };