element-ui
Version:
A Component Library for Vue.js.
1,855 lines (1,522 loc) • 62.8 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(245);
/***/ },
/***/ 9:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/clickoutside");
/***/ },
/***/ 50:
/***/ function(module, exports) {
module.exports = require("vue");
/***/ },
/***/ 53:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/vue-popper");
/***/ },
/***/ 57:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/mixins/locale");
/***/ },
/***/ 149:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/locale");
/***/ },
/***/ 174:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/mixins/migrating");
/***/ },
/***/ 210:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/tag");
/***/ },
/***/ 211:
/***/ function(module, exports) {
module.exports = require("throttle-debounce/debounce");
/***/ },
/***/ 212:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/resize-event");
/***/ },
/***/ 245:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _table = __webpack_require__(246);
var _table2 = _interopRequireDefault(_table);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* istanbul ignore next */
_table2.default.install = function (Vue) {
Vue.component(_table2.default.name, _table2.default);
};
exports.default = _table2.default;
/***/ },
/***/ 246:
/***/ function(module, exports, __webpack_require__) {
var __vue_exports__, __vue_options__
var __vue_styles__ = {}
/* script */
__vue_exports__ = __webpack_require__(247)
/* template */
var __vue_template__ = __webpack_require__(260)
__vue_options__ = __vue_exports__ = __vue_exports__ || {}
if (
typeof __vue_exports__.default === "object" ||
typeof __vue_exports__.default === "function"
) {
__vue_options__ = __vue_exports__ = __vue_exports__.default
}
if (typeof __vue_options__ === "function") {
__vue_options__ = __vue_options__.options
}
__vue_options__.render = __vue_template__.render
__vue_options__.staticRenderFns = __vue_template__.staticRenderFns
module.exports = __vue_exports__
/***/ },
/***/ 247:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _migrating = __webpack_require__(174);
var _migrating2 = _interopRequireDefault(_migrating);
var _throttle = __webpack_require__(248);
var _throttle2 = _interopRequireDefault(_throttle);
var _debounce = __webpack_require__(211);
var _debounce2 = _interopRequireDefault(_debounce);
var _resizeEvent = __webpack_require__(212);
var _locale = __webpack_require__(149);
var _tableStore = __webpack_require__(249);
var _tableStore2 = _interopRequireDefault(_tableStore);
var _tableLayout = __webpack_require__(251);
var _tableLayout2 = _interopRequireDefault(_tableLayout);
var _tableBody = __webpack_require__(252);
var _tableBody2 = _interopRequireDefault(_tableBody);
var _tableHeader = __webpack_require__(253);
var _tableHeader2 = _interopRequireDefault(_tableHeader);
var _util = __webpack_require__(250);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var tableIdSeed = 1;
exports.default = {
name: 'el-table',
mixins: [_migrating2.default],
props: {
data: {
type: Array,
default: function _default() {
return [];
}
},
width: [String, Number],
height: [String, Number],
fit: {
type: Boolean,
default: true
},
stripe: Boolean,
border: Boolean,
rowKey: [String, Function],
rowClassName: [String, Function],
highlightCurrentRow: Boolean,
emptyText: {
type: String,
default: (0, _locale.t)('el.table.emptyText')
}
},
components: {
TableHeader: _tableHeader2.default,
TableBody: _tableBody2.default
},
methods: {
getMigratingConfig: function getMigratingConfig() {
return {
props: {
'allow-no-selection': 'Table: allow-no-selection has been removed.',
'selection-mode': 'Table: selection-mode has been removed.',
'fixed-column-count': 'Table: fixed-column-count has been removed. Use fixed prop in TableColumn instead.',
'custom-criteria': 'Table: custom-criteria has been removed. Use row-class-name instead.',
'custom-background-colors': 'custom-background-colors has been removed. Use row-class-name instead.'
},
events: {
selectionchange: 'Table: selectionchange has been renamed to selection-change.',
cellmouseenter: 'Table: cellmouseenter has been renamed to cell-mouse-enter.',
cellmouseleave: 'Table: cellmouseleave has been renamed to cell-mouse-leave.',
cellclick: 'Table: cellclick has been renamed to cell-click.'
}
};
},
toggleRowSelection: function toggleRowSelection(row, selected) {
this.store.toggleRowSelection(row, selected);
},
clearSelection: function clearSelection() {
this.store.clearSelection();
},
handleMouseLeave: function handleMouseLeave() {
this.store.commit('setHoverRow', null);
if (this.hoverState) this.hoverState = null;
},
updateScrollY: function updateScrollY() {
this.layout.updateScrollY();
},
bindEvents: function bindEvents() {
var _this = this;
var _$refs = this.$refs;
var bodyWrapper = _$refs.bodyWrapper;
var headerWrapper = _$refs.headerWrapper;
var refs = this.$refs;
bodyWrapper.addEventListener('scroll', function () {
headerWrapper.scrollLeft = this.scrollLeft;
if (refs.fixedBodyWrapper) refs.fixedBodyWrapper.scrollTop = this.scrollTop;
if (refs.rightFixedBodyWrapper) refs.rightFixedBodyWrapper.scrollTop = this.scrollTop;
});
(0, _util.mousewheel)(headerWrapper, (0, _throttle2.default)(16, function (event) {
var deltaX = event.deltaX;
if (deltaX > 0) {
bodyWrapper.scrollLeft = bodyWrapper.scrollLeft + 10;
} else {
bodyWrapper.scrollLeft = bodyWrapper.scrollLeft - 10;
}
}));
if (this.fit) {
this.windowResizeListener = (0, _throttle2.default)(50, function () {
if (_this.$ready) _this.doLayout();
});
(0, _resizeEvent.addResizeListener)(this.$el, this.windowResizeListener);
}
},
doLayout: function doLayout() {
var _this2 = this;
this.store.updateColumns();
this.layout.update();
this.updateScrollY();
this.$nextTick(function () {
if (_this2.height) {
_this2.layout.setHeight(_this2.height);
} else if (_this2.shouldUpdateHeight) {
_this2.layout.updateHeight();
}
});
}
},
created: function created() {
var _this3 = this;
this.tableId = 'el-table_' + tableIdSeed + '_';
this.debouncedLayout = (0, _debounce2.default)(50, function () {
return _this3.doLayout();
});
},
computed: {
shouldUpdateHeight: function shouldUpdateHeight() {
return typeof this.height === 'number' || this.fixedColumns.length > 0 || this.rightFixedColumns.length > 0;
},
selection: function selection() {
return this.store.selection;
},
columns: function columns() {
return this.store.states.columns;
},
tableData: function tableData() {
return this.store.states.data;
},
fixedColumns: function fixedColumns() {
return this.store.states.fixedColumns;
},
rightFixedColumns: function rightFixedColumns() {
return this.store.states.rightFixedColumns;
}
},
watch: {
height: function height(value) {
this.layout.setHeight(value);
},
data: {
immediate: true,
handler: function handler(val) {
this.store.commit('setData', val);
}
}
},
destroyed: function destroyed() {
if (this.windowResizeListener) (0, _resizeEvent.removeResizeListener)(this.$el, this.windowResizeListener);
},
mounted: function mounted() {
this.bindEvents();
this.doLayout();
this.$ready = true;
},
data: function data() {
var store = new _tableStore2.default(this, {
rowKey: this.rowKey
});
var layout = new _tableLayout2.default({
store: store,
table: this,
fit: this.fit
});
return {
store: store,
layout: layout,
resizeProxyVisible: false
};
}
};
/***/ },
/***/ 248:
/***/ function(module, exports) {
module.exports = require("throttle-debounce/throttle");
/***/ },
/***/ 249:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _vue = __webpack_require__(50);
var _vue2 = _interopRequireDefault(_vue);
var _debounce = __webpack_require__(211);
var _debounce2 = _interopRequireDefault(_debounce);
var _util = __webpack_require__(250);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var sortData = function sortData(data, states) {
var sortingColumn = states.sortingColumn;
if (!sortingColumn || typeof sortingColumn.sortable === 'string') {
return data;
}
return (0, _util.orderBy)(data, states.sortProp, states.sortOrder, sortingColumn.sortMethod);
};
var getKeysMap = function getKeysMap(array, rowKey) {
var arrayMap = {};
(array || []).forEach(function (row, index) {
arrayMap[(0, _util.getRowIdentity)(row, rowKey)] = { row: row, index: index };
});
return arrayMap;
};
var toggleRowSelection = function toggleRowSelection(states, row, selected) {
var changed = false;
var selection = states.selection;
var index = selection.indexOf(row);
if (typeof selected === 'undefined') {
if (index === -1) {
selection.push(row);
changed = true;
} else {
selection.splice(index, 1);
changed = true;
}
} else {
if (selected && index === -1) {
selection.push(row);
changed = true;
} else if (!selected && index > -1) {
selection.splice(index, 1);
changed = true;
}
}
return changed;
};
var TableStore = function TableStore(table) {
var initialState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
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 (var prop in initialState) {
if (initialState.hasOwnProperty(prop) && this.states.hasOwnProperty(prop)) {
this.states[prop] = initialState[prop];
}
}
};
TableStore.prototype.mutations = {
setData: function setData(states, data) {
var _this = this;
var dataInstanceChanged = states._data !== data;
states._data = data;
states.data = sortData(data || [], states);
this.updateCurrentRow();
if (!states.reserveSelection) {
if (dataInstanceChanged) {
this.clearSelection();
} else {
this.cleanSelection();
}
this.updateAllSelected();
} else {
(function () {
var rowKey = states.rowKey;
if (rowKey) {
(function () {
var selection = states.selection;
var selectedMap = getKeysMap(selection, rowKey);
states.data.forEach(function (row) {
var rowId = (0, _util.getRowIdentity)(row, rowKey);
var rowInfo = selectedMap[rowId];
if (rowInfo) {
selection[rowInfo.index] = row;
}
});
_this.updateAllSelected();
})();
} else {
console.warn('WARN: rowKey is required when reserve-selection is enabled.');
}
})();
}
_vue2.default.nextTick(function () {
return _this.table.updateScrollY();
});
},
changeSortCondition: function changeSortCondition(states) {
var _this2 = this;
states.data = sortData(states.filteredData || states._data || [], states);
this.table.$emit('sort-change', {
column: this.states.sortingColumn,
prop: this.states.sortProp,
order: this.states.sortOrder
});
_vue2.default.nextTick(function () {
return _this2.table.updateScrollY();
});
},
filterChange: function filterChange(states, options) {
var _this3 = this;
var column = options.column;
var values = options.values;
if (values && !Array.isArray(values)) {
values = [values];
}
var prop = column.property;
if (prop) {
states.filters[column.id] = values;
}
var data = states._data;
var filters = states.filters;
Object.keys(filters).forEach(function (columnId) {
var values = filters[columnId];
if (!values || values.length === 0) return;
var column = (0, _util.getColumnById)(_this3.states, columnId);
if (column && column.filterMethod) {
data = data.filter(function (row) {
return values.some(function (value) {
return column.filterMethod.call(null, value, row);
});
});
}
});
states.filteredData = data;
states.data = sortData(data, states);
_vue2.default.nextTick(function () {
return _this3.table.updateScrollY();
});
},
insertColumn: function insertColumn(states, column, index) {
var _columns = states._columns;
if (typeof index !== 'undefined') {
_columns.splice(index, 0, column);
} else {
_columns.push(column);
}
if (column.type === 'selection') {
states.selectable = column.selectable;
states.reserveSelection = column.reserveSelection;
}
this.scheduleLayout();
},
removeColumn: function removeColumn(states, column) {
var _columns = states._columns;
if (_columns) {
_columns.splice(_columns.indexOf(column), 1);
}
this.scheduleLayout();
},
setHoverRow: function setHoverRow(states, row) {
states.hoverRow = row;
},
setCurrentRow: function setCurrentRow(states, row) {
var oldCurrentRow = states.currentRow;
states.currentRow = row;
if (oldCurrentRow !== row) {
this.table.$emit('current-change', row, oldCurrentRow);
}
},
rowSelectedChanged: function rowSelectedChanged(states, row) {
var changed = toggleRowSelection(states, row);
var selection = states.selection;
if (changed) {
var table = this.table;
table.$emit('selection-change', selection);
table.$emit('select', selection, row);
}
this.updateAllSelected();
},
toggleAllSelection: (0, _debounce2.default)(10, function (states) {
var data = states.data || [];
var value = !states.isAllSelected;
var selection = this.states.selection;
var selectionChanged = false;
data.forEach(function (item, index) {
if (states.selectable) {
if (states.selectable.call(null, item, index) && toggleRowSelection(states, item, value)) {
selectionChanged = true;
}
} else {
if (toggleRowSelection(states, item, value)) {
selectionChanged = true;
}
}
});
var table = this.table;
if (selectionChanged) {
table.$emit('selection-change', selection);
}
table.$emit('select-all', selection);
states.isAllSelected = value;
})
};
TableStore.prototype.updateColumns = function () {
var states = this.states;
var _columns = states._columns || [];
states.fixedColumns = _columns.filter(function (column) {
return column.fixed === true || column.fixed === 'left';
});
states.rightFixedColumns = _columns.filter(function (column) {
return column.fixed === 'right';
});
if (states.fixedColumns.length > 0 && _columns[0] && _columns[0].type === 'selection' && !_columns[0].fixed) {
_columns[0].fixed = true;
states.fixedColumns.unshift(_columns[0]);
}
states.columns = [].concat(states.fixedColumns).concat(_columns.filter(function (column) {
return !column.fixed;
})).concat(states.rightFixedColumns);
};
TableStore.prototype.isSelected = function (row) {
return (this.states.selection || []).indexOf(row) > -1;
};
TableStore.prototype.clearSelection = function () {
var states = this.states;
states.isAllSelected = false;
states.selection = [];
};
TableStore.prototype.toggleRowSelection = function (row, selected) {
toggleRowSelection(this.states, row, selected);
};
TableStore.prototype.cleanSelection = function () {
var selection = this.states.selection || [];
var data = this.states.data;
var rowKey = this.states.rowKey;
var deleted = void 0;
if (rowKey) {
deleted = [];
var selectedMap = getKeysMap(selection, rowKey);
var dataMap = getKeysMap(data, rowKey);
for (var key in selectedMap) {
if (selectedMap.hasOwnProperty(key) && !dataMap[key]) {
deleted.push(selectedMap[key].row);
}
}
} else {
deleted = selection.filter(function (item) {
return data.indexOf(item) === -1;
});
}
deleted.forEach(function (deletedItem) {
selection.splice(selection.indexOf(deletedItem), 1);
});
if (deleted.length) {
this.table.$emit('selection-change', selection);
}
};
TableStore.prototype.updateAllSelected = function () {
var states = this.states;
var selection = states.selection;
var rowKey = states.rowKey;
var selectable = states.selectable;
var data = states.data;
if (!data || data.length === 0) {
states.isAllSelected = false;
return;
}
var selectedMap = void 0;
if (rowKey) {
selectedMap = getKeysMap(states.selection, rowKey);
}
var isSelected = function isSelected(row) {
if (selectedMap) {
return !!selectedMap[(0, _util.getRowIdentity)(row, rowKey)];
} else {
return selection.indexOf(row) !== -1;
}
};
var isAllSelected = true;
for (var i = 0, j = data.length; i < j; i++) {
var item = data[i];
if (selectable) {
if (selectable.call(null, item, i) && !isSelected(item)) {
isAllSelected = false;
break;
}
} else {
if (!isSelected(item)) {
isAllSelected = false;
break;
}
}
}
states.isAllSelected = isAllSelected;
};
TableStore.prototype.scheduleLayout = function () {
this.table.debouncedLayout();
};
TableStore.prototype.updateCurrentRow = function () {
var states = this.states;
var table = this.table;
var data = states.data || [];
var oldCurrentRow = states.currentRow;
if (data.indexOf(oldCurrentRow) === -1) {
states.currentRow = null;
if (states.currentRow !== oldCurrentRow) {
table.$emit('current-change', null, oldCurrentRow);
}
}
};
TableStore.prototype.commit = function (name) {
var mutations = this.mutations;
if (mutations[name]) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
mutations[name].apply(this, [this.states].concat(args));
}
};
exports.default = TableStore;
/***/ },
/***/ 250:
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var scrollBarWidth = void 0;
var getScrollBarWidth = exports.getScrollBarWidth = function getScrollBarWidth() {
if (scrollBarWidth !== undefined) return scrollBarWidth;
var outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.position = 'absolute';
outer.style.top = '-9999px';
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
outer.style.overflow = 'scroll';
var inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);
var widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
};
var getCell = exports.getCell = function getCell(event) {
var cell = event.target;
while (cell && cell.tagName.toUpperCase() !== 'HTML') {
if (cell.tagName.toUpperCase() === 'TD') {
return cell;
}
cell = cell.parentNode;
}
return null;
};
var getValueByPath = exports.getValueByPath = function getValueByPath(object, prop) {
prop = prop || '';
var paths = prop.split('.');
var current = object;
var result = null;
for (var i = 0, j = paths.length; i < j; i++) {
var path = paths[i];
if (!current) break;
if (i === j - 1) {
result = current[path];
break;
}
current = current[path];
}
return result;
};
var isObject = function isObject(obj) {
return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
};
var orderBy = exports.orderBy = function orderBy(array, sortKey, reverse, sortMethod) {
if (typeof reverse === 'string') {
reverse = reverse === 'descending' ? -1 : 1;
}
if (!sortKey) {
return array;
}
var order = reverse && reverse < 0 ? -1 : 1;
// sort on a copy to avoid mutating original array
return array.slice().sort(sortMethod ? function (a, b) {
return sortMethod(a, b) ? order : -order;
} : function (a, b) {
if (sortKey !== '$key') {
if (isObject(a) && '$value' in a) a = a.$value;
if (isObject(b) && '$value' in b) b = b.$value;
}
a = isObject(a) ? getValueByPath(a, sortKey) : a;
b = isObject(b) ? getValueByPath(b, sortKey) : b;
return a === b ? 0 : a > b ? order : -order;
});
};
var getColumnById = exports.getColumnById = function getColumnById(table, columnId) {
var column = null;
table.columns.forEach(function (item) {
if (item.id === columnId) {
column = item;
}
});
return column;
};
var getColumnByCell = exports.getColumnByCell = function getColumnByCell(table, cell) {
var matches = (cell.className || '').match(/el-table_[^\s]+/gm);
if (matches) {
return getColumnById(table, matches[0]);
}
return null;
};
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var mousewheel = exports.mousewheel = function mousewheel(element, callback) {
if (element && element.addEventListener) {
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
}
};
var getRowIdentity = exports.getRowIdentity = function 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);
}
};
/***/ },
/***/ 251:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _util = __webpack_require__(250);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var GUTTER_WIDTH = void 0;
var TableLayout = function () {
function TableLayout(options) {
_classCallCheck(this, TableLayout);
this.table = null;
this.store = null;
this.columns = null;
this.fit = true;
this.height = null;
this.scrollX = false;
this.scrollY = false;
this.bodyWidth = null;
this.fixedWidth = null;
this.rightFixedWidth = null;
this.tableHeight = null;
this.headerHeight = 44; // Table Header Height
this.viewportHeight = null; // Table Height - Scroll Bar Height
this.bodyHeight = null; // Table Height - Table Header Height
this.fixedBodyHeight = null; // Table Height - Table Header Height - Scroll Bar Height
if (GUTTER_WIDTH === undefined) {
GUTTER_WIDTH = (0, _util.getScrollBarWidth)();
}
this.gutterWidth = GUTTER_WIDTH;
for (var name in options) {
if (options.hasOwnProperty(name)) {
this[name] = options[name];
}
}
if (!this.table) {
throw new Error('table is required for Table Layout');
}
if (!this.store) {
throw new Error('store is required for Table Layout');
}
}
TableLayout.prototype.updateScrollY = function updateScrollY() {
var bodyWrapper = this.table.$refs.bodyWrapper;
if (this.table.$el && bodyWrapper) {
var body = bodyWrapper.querySelector('.el-table__body');
this.scrollY = body.offsetHeight > bodyWrapper.offsetHeight;
}
};
TableLayout.prototype.setHeight = function setHeight(height) {
if (typeof height === 'string' && /^\d+$/.test(height)) {
height = Number(height);
}
this.height = height;
var el = this.table.$el;
if (!isNaN(height) && el) {
el.style.height = height + 'px';
this.updateHeight();
}
};
TableLayout.prototype.updateHeight = function updateHeight() {
var height = this.tableHeight = this.table.$el.clientHeight;
var headerWrapper = this.table.$refs.headerWrapper;
if (!headerWrapper) return;
var headerHeight = this.headerHeight = headerWrapper.offsetHeight;
var bodyHeight = height - headerHeight;
if (this.height !== null && !isNaN(this.height)) this.bodyHeight = bodyHeight;
this.fixedBodyHeight = this.scrollX ? bodyHeight - this.gutterWidth : bodyHeight;
this.viewportHeight = this.scrollX ? height - this.gutterWidth : height;
};
TableLayout.prototype.update = function update() {
var fit = this.fit;
var columns = this.table.columns;
var bodyWidth = this.table.$el.clientWidth;
var bodyMinWidth = 0;
var flattenColumns = [];
columns.forEach(function (column) {
if (column.isColumnGroup) {
flattenColumns.push.apply(flattenColumns, column.columns);
} else {
flattenColumns.push(column);
}
});
var flexColumns = flattenColumns.filter(function (column) {
return typeof column.width !== 'number';
});
if (flexColumns.length > 0 && fit) {
flattenColumns.forEach(function (column) {
bodyMinWidth += column.width || column.minWidth || 80;
});
if (bodyMinWidth < bodyWidth - this.gutterWidth) {
// DON'T HAVE SCROLL BAR
this.scrollX = false;
var totalFlexWidth = bodyWidth - this.gutterWidth - bodyMinWidth;
if (flexColumns.length === 1) {
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth;
} else {
(function () {
var allColumnsWidth = flexColumns.reduce(function (prev, column) {
return prev + (column.minWidth || 80);
}, 0);
var flexWidthPerPixel = totalFlexWidth / allColumnsWidth;
var noneFirstWidth = 0;
flexColumns.forEach(function (column, index) {
if (index === 0) return;
var flexWidth = Math.floor((column.minWidth || 80) * flexWidthPerPixel);
noneFirstWidth += flexWidth;
column.realWidth = (column.minWidth || 80) + flexWidth;
});
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth - noneFirstWidth;
})();
}
} else {
// HAVE HORIZONTAL SCROLL BAR
this.scrollX = true;
flexColumns.forEach(function (column) {
column.realWidth = column.minWidth;
});
}
this.bodyWidth = Math.max(bodyMinWidth, bodyWidth);
} else {
flattenColumns.forEach(function (column) {
if (!column.width && !column.minWidth) {
column.realWidth = 80;
}
bodyMinWidth += column.realWidth;
});
this.scrollX = bodyMinWidth > bodyWidth;
this.bodyWidth = bodyMinWidth;
}
var fixedColumns = this.store.states.fixedColumns;
if (fixedColumns.length > 0) {
var fixedWidth = 0;
fixedColumns.forEach(function (column) {
fixedWidth += column.realWidth;
});
this.fixedWidth = fixedWidth;
}
var rightFixedColumns = this.store.states.rightFixedColumns;
if (rightFixedColumns.length > 0) {
var rightFixedWidth = 0;
rightFixedColumns.forEach(function (column) {
rightFixedWidth += column.realWidth;
});
this.rightFixedWidth = rightFixedWidth;
}
};
return TableLayout;
}();
exports.default = TableLayout;
/***/ },
/***/ 252:
/***/ function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _util = __webpack_require__(250);
exports.default = {
props: {
store: {
required: true
},
layout: {
required: true
},
rowClassName: [String, Function],
fixed: String,
highlight: Boolean
},
render: function render(h) {
var _this = this;
return h(
"table",
{
"class": "el-table__body",
attrs: { cellspacing: "0",
cellpadding: "0",
border: "0" }
},
[this._l(this.columns, function (column) {
return h(
"col",
{
attrs: {
name: column.id,
width: column.realWidth || column.width
}
},
[]
);
}), h(
"tbody",
null,
[this._l(this.data, function (row, $index) {
return h(
"tr",
{
key: _this.$parent.rowKey ? _this.getKeyOfRow(row, $index) : $index,
on: {
click: function click($event) {
return _this.handleClick($event, row);
},
mouseenter: function mouseenter(_) {
return _this.handleMouseEnter($index);
},
mouseleave: function mouseleave(_) {
return _this.handleMouseLeave();
}
},
"class": _this.getRowClass(row, $index) },
[_this._l(_this.columns, function (column, cellIndex) {
return h(
"td",
{
"class": [column.id, column.align, column.className || '', _this.isCellHidden(cellIndex) ? 'is-hidden' : ''],
on: {
mouseenter: function mouseenter($event) {
return _this.handleCellMouseEnter($event, row);
},
mouseleave: _this.handleCellMouseLeave
}
},
[column.renderCell.call(_this._renderProxy, h, { row: row, column: column, $index: $index, store: _this.store, _self: _this.$parent.$vnode.context })]
);
}), !_this.fixed && _this.layout.scrollY && _this.layout.gutterWidth ? h(
"td",
{ "class": "gutter" },
[]
) : '']
);
})]
)]
);
},
watch: {
'store.states.hoverRow': function storeStatesHoverRow(newVal, oldVal) {
var el = this.$el;
if (!el) return;
var rows = el.querySelectorAll('tr');
var oldRow = rows[oldVal];
var newRow = rows[newVal];
if (oldRow) {
oldRow.classList.remove('hover-row');
}
if (newRow) {
newRow.classList.add('hover-row');
}
},
'store.states.currentRow': function storeStatesCurrentRow(newVal, oldVal) {
if (!this.highlight) return;
var el = this.$el;
if (!el) return;
var data = this.store.states.data;
var rows = el.querySelectorAll('tr');
var oldRow = rows[data.indexOf(oldVal)];
var newRow = rows[data.indexOf(newVal)];
if (oldRow) {
oldRow.classList.remove('current-row');
}
if (newRow) {
newRow.classList.add('current-row');
}
}
},
computed: {
data: function data() {
return this.store.states.data;
},
columnsCount: function columnsCount() {
return this.store.states.columns.length;
},
leftFixedCount: function leftFixedCount() {
return this.store.states.fixedColumns.length;
},
rightFixedCount: function rightFixedCount() {
return this.store.states.rightFixedColumns.length;
},
columns: function columns() {
return this.store.states.columns;
}
},
data: function data() {
return {
tooltipDisabled: true
};
},
methods: {
getKeyOfRow: function getKeyOfRow(row, index) {
var rowKey = this.$parent.rowKey;
if (rowKey) {
return (0, _util.getRowIdentity)(row, rowKey);
}
return index;
},
isCellHidden: function isCellHidden(index) {
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedCount;
} else if (this.fixed === 'right') {
return index < this.columnsCount - this.rightFixedCount;
} else {
return index < this.leftFixedCount || index >= this.columnsCount - this.rightFixedCount;
}
},
getRowClass: function getRowClass(row, index) {
var classes = [];
var rowClassName = this.rowClassName;
if (typeof rowClassName === 'string') {
classes.push(rowClassName);
} else if (typeof rowClassName === 'function') {
classes.push(rowClassName.apply(null, [row, index]) || '');
}
return classes.join(' ');
},
handleCellMouseEnter: function handleCellMouseEnter(event, row) {
var table = this.$parent;
var cell = (0, _util.getCell)(event);
if (cell) {
var column = (0, _util.getColumnByCell)(table, cell);
var hoverState = table.hoverState = { cell: cell, column: column, row: row };
table.$emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, event);
}
// 判断是否text-overflow, 如果是就显示tooltip
var cellChild = event.target.querySelector('.cell');
this.tooltipDisabled = cellChild.scrollWidth <= cellChild.offsetWidth;
},
handleCellMouseLeave: function handleCellMouseLeave(event) {
var cell = (0, _util.getCell)(event);
if (!cell) return;
var oldHoverState = this.$parent.hoverState;
this.$parent.$emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
},
handleMouseEnter: function handleMouseEnter(index) {
this.store.commit('setHoverRow', index);
},
handleMouseLeave: function handleMouseLeave() {
this.store.commit('setHoverRow', null);
},
handleClick: function handleClick(event, row) {
var table = this.$parent;
var cell = (0, _util.getCell)(event);
if (cell) {
var column = (0, _util.getColumnByCell)(table, cell);
if (column) {
table.$emit('cell-click', row, column, cell, event);
}
}
this.store.commit('setCurrentRow', row);
table.$emit('row-click', row, event);
},
getCellContent: function getCellContent(row, property, column) {
if (column && column.formatter) {
return column.formatter(row, column);
}
if (property && property.indexOf('.') === -1) {
return row[property];
}
return (0, _util.getValueByPath)(row, property);
}
}
};
/***/ },
/***/ 253:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _checkbox = __webpack_require__(254);
var _checkbox2 = _interopRequireDefault(_checkbox);
var _tag = __webpack_require__(210);
var _tag2 = _interopRequireDefault(_tag);
var _vue = __webpack_require__(50);
var _vue2 = _interopRequireDefault(_vue);
var _filterPanel = __webpack_require__(255);
var _filterPanel2 = _interopRequireDefault(_filterPanel);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
name: 'el-table-header',
render: function render(h) {
var _this = this;
return h(
'table',
{
'class': 'el-table__header',
attrs: { cellspacing: '0',
cellpadding: '0',
border: '0' }
},
[this._l(this.columns, function (column) {
return h(
'col',
{
attrs: {
name: column.id,
width: column.realWidth || column.width
}
},
[]
);
}), !this.fixed && this.layout.gutterWidth ? h(
'col',
{
attrs: { name: 'gutter', width: this.layout.scrollY ? this.layout.gutterWidth : '' }
},
[]
) : '', h(
'thead',
null,
[h(
'tr',
null,
[this._l(this.columns, function (column, cellIndex) {
return h(
'th',
{
on: {
mousemove: function mousemove($event) {
return _this.handleMouseMove($event, column);
},
mouseout: _this.handleMouseOut,
mousedown: function mousedown($event) {
return _this.handleMouseDown($event, column);
}
},
'class': [column.id, column.order, column.align, column.className || '', _this.isCellHidden(cellIndex) ? 'is-hidden' : ''] },
[h(
'div',
{ 'class': ['cell', column.filteredValue && column.filteredValue.length > 0 ? 'highlight' : ''] },
[column.renderHeader ? column.renderHeader.call(_this._renderProxy, h, { column: column, $index: cellIndex, store: _this.store, _self: _this.$parent.$vnode.context }) : column.label, column.sortable ? h(
'span',
{ 'class': 'caret-wrapper', on: {
click: function click($event) {
return _this.handleHeaderClick($event, column);
}
}
},
[h(
'i',
{ 'class': 'sort-caret ascending' },
[]
), h(
'i',
{ 'class': 'sort-caret descending' },
[]
)]
) : '', column.filterable ? h(
'span',
{ 'class': 'el-table__column-filter-trigger', on: {
click: function click($event) {
return _this.handleFilterClick($event, column);
}
}
},
[h(
'i',
{ 'class': ['el-icon-arrow-down', column.filterOpened ? 'el-icon-arrow-up' : ''] },
[]
)]
) : '']
)]
);
}), !this.fixed && this.layout.gutterWidth ? h(
'th',
{ 'class': 'gutter', style: { width: this.layout.scrollY ? this.layout.gutterWidth + 'px' : '0' } },
[]
) : '']
)]
)]
);
},
props: {
fixed: String,
store: {
required: true
},
layout: {
required: true
},
border: Boolean
},
components: {
ElCheckbox: _checkbox2.default,
ElTag: _tag2.default
},
computed: {
isAllSelected: function isAllSelected() {
return this.store.states.isAllSelected;
},
columnsCount: function columnsCount() {
return this.store.states.columns.length;
},
leftFixedCount: function leftFixedCount() {
return this.store.states.fixedColumns.length;
},
rightFixedCount: function rightFixedCount() {
return this.store.states.rightFixedColumns.length;
},
columns: function columns() {
return this.store.states.columns;
}
},
created: function created() {
this.filterPanels = {};
},
beforeDestroy: function beforeDestroy() {
var panels = this.filterPanels;
for (var prop in panels) {
if (panels.hasOwnProperty(prop) && panels[prop]) {
panels[prop].$destroy(true);
}
}
},
methods: {
isCellHidden: function isCellHidden(index) {
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedCount;
} else if (this.fixed === 'right') {
return index < this.columnsCount - this.rightFixedCount;
} else {
return index < this.leftFixedCount || index >= this.columnsCount - this.rightFixedCount;
}
},
toggleAllSelection: function toggleAllSelection() {
this.store.commit('toggleAllSelection');
},
handleFilterClick: function handleFilterClick(event, column) {
event.stopPropagation();
var target = event.target;
var cell = target.parentNode;
var table = this.$parent;
var filterPanel = this.filterPanels[column.id];
if (filterPanel && column.filterOpened) {
filterPanel.showPopper = false;
return;
}
if (!filterPanel) {
filterPanel = new _vue2.default(_filterPanel2.default);
this.filterPanels[column.id] = filterPanel;
filterPanel.table = table;
filterPanel.cell = cell;
filterPanel.column = column;
filterPanel.$mount(document.createElement('div'));
}
setTimeout(function () {
filterPanel.showPopper = true;
}, 16);
},
handleMouseDown: function handleMouseDown(event, column) {
var _this2 = this;
/* istanbul ignore if */
if (this.draggingColumn && this.border) {
(function () {
_this2.dragging = true;
_this2.$parent.resizeProxyVisible = true;
var tableEl = _this2.$parent.$el;
var tableLeft = tableEl.getBoundingClientRect().left;
var columnEl = _this2.$el.querySelector('th.' + column.id);
var columnRect = columnEl.getBoundingClientRect();
var minLeft = columnRect.left - tableLeft + 30;
columnEl.classList.add('noclick');
_this2.dragState = {
startMouseLeft: event.clientX,
startLeft: columnRect.right - tableLeft,
startColumnLeft: columnRect.left - tableLeft,
tableLeft: tableLeft
};
var resizeProxy = _this2.$parent.$refs.resizeProxy;
resizeProxy.style.left = _this2.dragState.startLeft + 'px';
document.onselectstart = function () {
return false;
};
document.ondragstart = function () {
return false;
};
var handleMouseMove = function handleMouseMove(event) {
var deltaLeft = event.clientX - _this2.dragState.startMouseLeft;
var proxyLeft = _this2.dragState.startLeft + deltaLeft;
resizeProxy.style.left = Math.max(minLeft, proxyLeft) + 'px';
};
var handleMouseUp = function handleMouseUp() {
if (_this2.dragging) {
var finalLeft = parseInt(resizeProxy.style.left, 10);
var columnWidth = finalLeft - _this2.dragState.startColumnLeft;
column.width = column.realWidth = columnWidth;
_this2.store.scheduleLayout();
document.body.style.cursor = '';
_this2.dragging = false;
_this2.draggingColumn = null;
_this2.dragState = {};
_this2.$parent.resizeProxyVisible = false;
}
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
document.onselectstart = null;
document.ondragstart = null;
setTimeout(function () {
columnEl.classList.remove('noclick');
}, 0);
};
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
})();
}
},
handleMouseMove: function handleMouseMove(event, column) {
var target = event.target;
while (target && target.tagName !== 'TH') {
target = target.parentNode;
}
if (!column || !column.resizable) return;
if (!this.dragging && this.border) {
var rect = target.getBoundingClientRect();
var bodyStyle = document.body.style;
if (rect.width > 12 && rect.right - event.pageX < 8) {
bodyStyle.cursor = 'col-resize';
this.draggingColumn = column;
} else if (!this.dragging) {
bodyStyle.cursor = '';
this.draggingColumn = null;
}
}
},
handleMouseOut: function handleMouseOut() {
document.body.style.cursor = '';
},
handleHeaderClick: function handleHeaderClick(event, column) {
var target = event.target;
while (target && target.tagName !== 'TH') {
target = target.parentNode;
}
if (target && target.tagName === 'TH') {
if (target.classList.contains('noclick')) {
target.classList.remove('noclick');
return;
}
}
if (!column.sortable) return;
var states = this.store.states;
var sortProp = states.sortProp;
var sortOrder = void 0;
var sortingColumn = states.sortingColumn;
if (sortingColumn !== column) {
if (sortingColumn) {
sortingColumn.order = null;
}
states.sortingColumn = column;
sortProp = column.property;
}
if (!column.order) {
sortOrder = column.order = 'ascending';
} else if (column.order === 'ascending') {
sortOrder = column.order = 'descending';
} else {
sortOrder = column.order = null;
states.sortingColumn = null;
sortProp = null;
}
states.sortProp = sortProp;
states.sortOrder = sortOrder;
this.store.commit('changeSortCondition');
}
},
data: function data() {
return {
draggingColumn: null,
dragging: false,
dragState: {}
};
}
};
/***/ },
/***/ 254:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/checkbox");
/***/ },
/***/ 255:
/***/ function(module, exports, __webpack_require__) {
var __vue_exports__, __vue_options__
var __vue_styles__ = {}
/* script */
__vue_exports__ = __webpack_require__(256)
/* template */
var __vue_template__ = __webpack_require__(259)
__vue_options__ = __vue_exports__ = __vue_exports__ || {}
if (
typeof __vue_exports__.default === "object" ||
typeof __vue_exports__.default === "function"
) {
__vue_option