导出多个工具方法mousewheel方法、getRowIdentity方法(文件:util.js)
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
export const mousewheel = function(element, callback) {
if (element && element.addEventListener) {
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
}
};
export const getRowIdentity = (row, rowKey) => {
if (!row) throw new Error('row is required when get row identity');
if (typeof rowKey === 'string') {
return row[rowKey];
} else if (typeof rowKey === 'function') {
return rowKey.call(null, row);
}
};
导入多个工具方法mousewheel方法、getRowIdentity方法(文件:export-demo.vue)
import { mousewheel } from './util';
import { getRowIdentity } from './util';
import { orderBy, getColumnById, getRowIdentity } from './util';
导出类TableStore(文件:table-store.js)
import Vue from 'vue';
import debounce from 'throttle-debounce/debounce';
import { orderBy, getColumnById, getRowIdentity } from './util';
const sortData = (data, states) => {
// TO DO
};
const getKeysMap = function(array, rowKey) {
const arrayMap = {};
(array || []).forEach((row, index) => {
arrayMap[getRowIdentity(row, rowKey)] = { row, index };
});
return arrayMap;
};
const TableStore = function(table, initialState = {}) {
if (!table) {
throw new Error('Table is required.');
}
this.table = table;
this.states = {
rowKey: null,
_columns: [],
columns: [],
fixedColumns: [],
rightFixedColumns: [],
_data: null,
filteredData: null,
data: null,
sortingColumn: null,
sortProp: null,
sortOrder: null,
isAllSelected: false,
selection: [],
reserveSelection: false,
selectable: null,
currentRow: null,
hoverRow: null,
filters: {}
};
for (let prop in initialState) {
if (initialState.hasOwnProperty(prop) && this.states.hasOwnProperty(prop)) {
this.states[prop] = initialState[prop];
}
}
};
TableStore.prototype.isSelected = function(row) {
// TO DO
};
TableStore.prototype.clearSelection = function() {
// TO DO
};
export default TableStore;
导入类TableStore(文件:export-demo.vue)
import TableStore from './table-store';