UNPKG

element-ui

Version:

A Component Library for Vue.js.

1,905 lines (1,575 loc) 87.7 kB
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__(305); /***/ }, /***/ 3: /***/ function(module, exports) { /* globals __VUE_SSR_CONTEXT__ */ // this module is a runtime utility for cleaner component module output and will // be included in the final webpack user bundle module.exports = function normalizeComponent ( rawScriptExports, compiledTemplate, injectStyles, scopeId, moduleIdentifier /* server only */ ) { var esModule var scriptExports = rawScriptExports = rawScriptExports || {} // ES6 modules interop var type = typeof rawScriptExports.default if (type === 'object' || type === 'function') { esModule = rawScriptExports scriptExports = rawScriptExports.default } // Vue.extend constructor export interop var options = typeof scriptExports === 'function' ? scriptExports.options : scriptExports // render functions if (compiledTemplate) { options.render = compiledTemplate.render options.staticRenderFns = compiledTemplate.staticRenderFns } // scopedId if (scopeId) { options._scopeId = scopeId } var hook if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || (this.$vnode && this.$vnode.ssrContext) // 2.2 with runInNewContext: true if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__ } // inject component styles if (injectStyles) { injectStyles.call(this, context) } // register component module identifier for async chunk inferrence if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier) } } // used by ssr in case component is cached and beforeCreate // never gets called options._ssrRegister = hook } else if (injectStyles) { hook = injectStyles } if (hook) { // inject component registration as beforeCreate hook var existing = options.beforeCreate options.beforeCreate = existing ? [].concat(existing, hook) : [hook] } return { esModule: esModule, exports: scriptExports, options: options } } /***/ }, /***/ 10: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/clickoutside"); /***/ }, /***/ 13: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/vue-popper"); /***/ }, /***/ 45: /***/ function(module, exports) { module.exports = require("throttle-debounce/throttle"); /***/ }, /***/ 46: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/resize-event"); /***/ }, /***/ 55: /***/ function(module, exports) { module.exports = require("vue"); /***/ }, /***/ 61: /***/ function(module, exports) { module.exports = require("element-ui/lib/mixins/locale"); /***/ }, /***/ 63: /***/ function(module, exports) { module.exports = require("throttle-debounce/debounce"); /***/ }, /***/ 123: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/dom"); /***/ }, /***/ 138: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/popup"); /***/ }, /***/ 219: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/util"); /***/ }, /***/ 261: /***/ function(module, exports) { module.exports = require("element-ui/lib/utils/scrollbar-width"); /***/ }, /***/ 270: /***/ function(module, exports) { module.exports = require("element-ui/lib/tag"); /***/ }, /***/ 278: /***/ function(module, exports) { module.exports = require("element-ui/lib/tooltip"); /***/ }, /***/ 305: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _table = __webpack_require__(306); 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; /***/ }, /***/ 306: /***/ function(module, exports, __webpack_require__) { var Component = __webpack_require__(3)( /* script */ __webpack_require__(307), /* template */ __webpack_require__(320), /* styles */ null, /* scopeId */ null, /* moduleIdentifier (server only) */ null ) module.exports = Component.exports /***/ }, /***/ 307: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _checkbox = __webpack_require__(308); var _checkbox2 = _interopRequireDefault(_checkbox); var _throttle = __webpack_require__(45); var _throttle2 = _interopRequireDefault(_throttle); var _debounce = __webpack_require__(63); var _debounce2 = _interopRequireDefault(_debounce); var _resizeEvent = __webpack_require__(46); var _locale = __webpack_require__(61); var _locale2 = _interopRequireDefault(_locale); var _tableStore = __webpack_require__(309); var _tableStore2 = _interopRequireDefault(_tableStore); var _tableLayout = __webpack_require__(311); var _tableLayout2 = _interopRequireDefault(_tableLayout); var _tableBody = __webpack_require__(312); var _tableBody2 = _interopRequireDefault(_tableBody); var _tableHeader = __webpack_require__(313); var _tableHeader2 = _interopRequireDefault(_tableHeader); var _tableFooter = __webpack_require__(319); var _tableFooter2 = _interopRequireDefault(_tableFooter); var _util = __webpack_require__(310); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var tableIdSeed = 1; // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // exports.default = { name: 'ElTable', mixins: [_locale2.default], props: { data: { type: Array, default: function _default() { return []; } }, width: [String, Number], height: [String, Number], maxHeight: [String, Number], fit: { type: Boolean, default: true }, stripe: Boolean, border: Boolean, rowKey: [String, Function], context: {}, showHeader: { type: Boolean, default: true }, showSummary: Boolean, sumText: String, summaryMethod: Function, rowClassName: [String, Function], rowStyle: [Object, Function], highlightCurrentRow: Boolean, currentRowKey: [String, Number], emptyText: String, expandRowKeys: Array, defaultExpandAll: Boolean, defaultSort: Object, tooltipEffect: String }, components: { TableHeader: _tableHeader2.default, TableFooter: _tableFooter2.default, TableBody: _tableBody2.default, ElCheckbox: _checkbox2.default }, methods: { setCurrentRow: function setCurrentRow(row) { this.store.commit('setCurrentRow', row); }, toggleRowSelection: function toggleRowSelection(row, selected) { this.store.toggleRowSelection(row, selected); this.store.updateAllSelected(); }, 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, headerWrapper = _$refs.headerWrapper, footerWrapper = _$refs.footerWrapper; var refs = this.$refs; this.bodyWrapper.addEventListener('scroll', function () { if (headerWrapper) headerWrapper.scrollLeft = this.scrollLeft; if (footerWrapper) footerWrapper.scrollLeft = this.scrollLeft; if (refs.fixedBodyWrapper) refs.fixedBodyWrapper.scrollTop = this.scrollTop; if (refs.rightFixedBodyWrapper) refs.rightFixedBodyWrapper.scrollTop = this.scrollTop; }); var scrollBodyWrapper = function scrollBodyWrapper(event) { var deltaX = event.deltaX, deltaY = event.deltaY; if (Math.abs(deltaX) < Math.abs(deltaY)) return; if (deltaX > 0) { _this.bodyWrapper.scrollLeft += 10; } else if (deltaX < 0) { _this.bodyWrapper.scrollLeft -= 10; } }; if (headerWrapper) { (0, _util.mousewheel)(headerWrapper, (0, _throttle2.default)(16, scrollBodyWrapper)); } if (footerWrapper) { (0, _util.mousewheel)(footerWrapper, (0, _throttle2.default)(16, scrollBodyWrapper)); } 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.maxHeight) { _this2.layout.setMaxHeight(_this2.maxHeight); } else if (_this2.shouldUpdateHeight) { _this2.layout.updateHeight(); } if (_this2.$el) { _this2.isHidden = _this2.$el.clientWidth === 0; } }); } }, created: function created() { var _this3 = this; this.tableId = 'el-table_' + tableIdSeed + '_'; this.debouncedLayout = (0, _debounce2.default)(50, function () { return _this3.doLayout(); }); }, computed: { bodyWrapper: function bodyWrapper() { return this.$refs.bodyWrapper; }, shouldUpdateHeight: function shouldUpdateHeight() { return typeof this.height === 'number' || this.fixedColumns.length > 0 || this.rightFixedColumns.length > 0; }, selection: function selection() { return this.store.states.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; }, bodyHeight: function bodyHeight() { var style = {}; if (this.height) { style = { height: this.layout.bodyHeight ? this.layout.bodyHeight + 'px' : '' }; } else if (this.maxHeight) { style = { 'max-height': (this.showHeader ? this.maxHeight - this.layout.headerHeight - this.layout.footerHeight : this.maxHeight - this.layout.footerHeight) + 'px' }; } return style; }, bodyWidth: function bodyWidth() { var _layout = this.layout, bodyWidth = _layout.bodyWidth, scrollY = _layout.scrollY, gutterWidth = _layout.gutterWidth; return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : ''; }, fixedBodyHeight: function fixedBodyHeight() { var style = {}; if (this.height) { style = { height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : '' }; } else if (this.maxHeight) { var maxHeight = this.layout.scrollX ? this.maxHeight - this.layout.gutterWidth : this.maxHeight; if (this.showHeader) { maxHeight -= this.layout.headerHeight; } style = { 'max-height': maxHeight + 'px' }; } return style; }, fixedHeight: function fixedHeight() { var style = {}; if (this.maxHeight) { style = { bottom: this.layout.scrollX && this.data.length ? this.layout.gutterWidth + 'px' : '' }; } else { style = { height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : '' }; } return style; } }, watch: { height: function height(value) { this.layout.setHeight(value); }, currentRowKey: function currentRowKey(newVal) { this.store.setCurrentRowKey(newVal); }, data: { immediate: true, handler: function handler(val) { this.store.commit('setData', val); if (this.$ready) this.doLayout(); } }, expandRowKeys: function expandRowKeys(newVal) { this.store.setExpandRowKeys(newVal); } }, destroyed: function destroyed() { if (this.windowResizeListener) (0, _resizeEvent.removeResizeListener)(this.$el, this.windowResizeListener); }, mounted: function mounted() { var _this4 = this; this.bindEvents(); this.doLayout(); // init filters this.store.states.columns.forEach(function (column) { if (column.filteredValue && column.filteredValue.length) { _this4.store.commit('filterChange', { column: column, values: column.filteredValue, silent: true }); } }); this.$ready = true; }, data: function data() { var store = new _tableStore2.default(this, { rowKey: this.rowKey, defaultExpandAll: this.defaultExpandAll }); var layout = new _tableLayout2.default({ store: store, table: this, fit: this.fit, showHeader: this.showHeader }); return { store: store, layout: layout, isHidden: false, renderExpanded: null, resizeProxyVisible: false }; } }; /***/ }, /***/ 308: /***/ function(module, exports) { module.exports = require("element-ui/lib/checkbox"); /***/ }, /***/ 309: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _vue = __webpack_require__(55); var _vue2 = _interopRequireDefault(_vue); var _debounce = __webpack_require__(63); var _debounce2 = _interopRequireDefault(_debounce); var _util = __webpack_require__(310); 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: [], originColumns: [], columns: [], fixedColumns: [], rightFixedColumns: [], isComplex: false, _data: null, filteredData: null, data: null, sortingColumn: null, sortProp: null, sortOrder: null, isAllSelected: false, selection: [], reserveSelection: false, selectable: null, currentRow: null, hoverRow: null, filters: {}, expandRows: [], defaultExpandAll: false }; 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); // states.data.forEach((item) => { // if (!item.$extra) { // Object.defineProperty(item, '$extra', { // value: {}, // enumerable: false // }); // } // }); 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.'); } })(); } var defaultExpandAll = states.defaultExpandAll; if (defaultExpandAll) { this.states.expandRows = (states.data || []).slice(0); } _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, values = options.values, silent = options.silent; if (values && !Array.isArray(values)) { values = [values]; } var prop = column.property; var filters = {}; if (prop) { states.filters[column.id] = values; filters[column.columnKey || column.id] = values; } var data = states._data; Object.keys(states.filters).forEach(function (columnId) { var values = states.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); if (!silent) { this.table.$emit('filter-change', filters); } _vue2.default.nextTick(function () { return _this3.table.updateScrollY(); }); }, insertColumn: function insertColumn(states, column, index, parent) { var array = states._columns; if (parent) { array = parent.children; if (!array) array = parent.children = []; } if (typeof index !== 'undefined') { array.splice(index, 0, column); } else { array.push(column); } if (column.type === 'selection') { states.selectable = column.selectable; states.reserveSelection = column.reserveSelection; } this.updateColumns(); // hack for dynamics insert column this.scheduleLayout(); }, removeColumn: function removeColumn(states, column) { var _columns = states._columns; if (_columns) { _columns.splice(_columns.indexOf(column), 1); } this.updateColumns(); // hack for dynamics remove column 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(); }, toggleRowExpanded: function toggleRowExpanded(states, row, expanded) { var expandRows = states.expandRows; if (typeof expanded !== 'undefined') { var index = expandRows.indexOf(row); if (expanded) { if (index === -1) expandRows.push(row); } else { if (index !== -1) expandRows.splice(index, 1); } } else { var _index = expandRows.indexOf(row); if (_index === -1) { expandRows.push(row); } else { expandRows.splice(_index, 1); } } this.table.$emit('expand', row, expandRows.indexOf(row) !== -1); }, 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; }) }; var doFlattenColumns = function doFlattenColumns(columns) { var result = []; columns.forEach(function (column) { if (column.children) { result.push.apply(result, doFlattenColumns(column.children)); } else { result.push(column); } }); return result; }; 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.originColumns = [].concat(states.fixedColumns).concat(_columns.filter(function (column) { return !column.fixed; })).concat(states.rightFixedColumns); states.columns = doFlattenColumns(states.originColumns); states.isComplex = states.fixedColumns.length > 0 || states.rightFixedColumns.length > 0; }; TableStore.prototype.isSelected = function (row) { return (this.states.selection || []).indexOf(row) > -1; }; TableStore.prototype.clearSelection = function () { var states = this.states; states.isAllSelected = false; var oldSelection = states.selection; states.selection = []; if (oldSelection.length > 0) { this.table.$emit('selection-change', states.selection); } }; TableStore.prototype.setExpandRowKeys = function (rowKeys) { var expandRows = []; var data = this.states.data; var rowKey = this.states.rowKey; if (!rowKey) throw new Error('[Table] prop row-key should not be empty.'); var keysMap = getKeysMap(data, rowKey); rowKeys.forEach(function (key) { var info = keysMap[key]; if (info) { expandRows.push(info.row); } }); this.states.expandRows = expandRows; }; TableStore.prototype.toggleRowSelection = function (row, selected) { var changed = toggleRowSelection(this.states, row, selected); if (changed) { this.table.$emit('selection-change', this.states.selection); } }; 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, rowKey = states.rowKey, selectable = states.selectable, 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; var selectedCount = 0; for (var i = 0, j = data.length; i < j; i++) { var item = data[i]; if (selectable) { var isRowSelectable = selectable.call(null, item, i); if (isRowSelectable) { if (!isSelected(item)) { isAllSelected = false; break; } else { selectedCount++; } } } else { if (!isSelected(item)) { isAllSelected = false; break; } else { selectedCount++; } } } if (selectedCount === 0) isAllSelected = false; states.isAllSelected = isAllSelected; }; TableStore.prototype.scheduleLayout = function () { this.table.debouncedLayout(); }; TableStore.prototype.setCurrentRowKey = function (key) { var states = this.states; var rowKey = states.rowKey; if (!rowKey) throw new Error('[Table] row-key should not be empty.'); var data = states.data || []; var keysMap = getKeysMap(data, rowKey); var info = keysMap[key]; if (info) { states.currentRow = info.row; } }; 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)); } else { throw new Error('Action not found: ' + name); } }; exports.default = TableStore; /***/ }, /***/ 310: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; exports.getRowIdentity = exports.mousewheel = exports.getColumnByCell = exports.getColumnById = exports.orderBy = exports.getCell = undefined; 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 _util = __webpack_require__(219); 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 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 && !sortMethod) { 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) ? (0, _util.getValueByPath)(a, sortKey) : a; b = isObject(b) ? (0, _util.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 = typeof navigator !== 'undefined' && 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') { if (rowKey.indexOf('.') < 0) { return row[rowKey]; } var key = rowKey.split('.'); var current = row; for (var i = 0; i < key.length; i++) { current = current[key[i]]; } return current; } else if (typeof rowKey === 'function') { return rowKey.call(null, row); } }; /***/ }, /***/ 311: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _scrollbarWidth = __webpack_require__(261); var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var TableLayout = function () { function TableLayout(options) { _classCallCheck(this, TableLayout); this.table = null; this.store = null; this.columns = null; this.fit = true; this.showHeader = 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.footerHeight = 44; // Table Footer 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 this.gutterWidth = (0, _scrollbarWidth2.default)(); 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 height = this.height; if (typeof height !== 'string' && typeof height !== 'number') return; var bodyWrapper = this.table.bodyWrapper; if (this.table.$el && bodyWrapper) { var body = bodyWrapper.querySelector('.el-table__body'); this.scrollY = body.offsetHeight > bodyWrapper.offsetHeight; } }; TableLayout.prototype.setHeight = function setHeight(value) { var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'height'; var el = this.table.$el; if (typeof value === 'string' && /^\d+$/.test(value)) { value = Number(value); } this.height = value; if (!el) return; if (typeof value === 'number') { el.style[prop] = value + 'px'; this.updateHeight(); } else if (typeof value === 'string') { if (value === '') { el.style[prop] = ''; } this.updateHeight(); } }; TableLayout.prototype.setMaxHeight = function setMaxHeight(value) { return this.setHeight(value, 'max-height'); }; TableLayout.prototype.updateHeight = function updateHeight() { var height = this.tableHeight = this.table.$el.clientHeight; var noData = !this.table.data || this.table.data.length === 0; var _table$$refs = this.table.$refs, headerWrapper = _table$$refs.headerWrapper, footerWrapper = _table$$refs.footerWrapper; var footerHeight = this.footerHeight = footerWrapper ? footerWrapper.offsetHeight : 0; if (this.showHeader && !headerWrapper) return; if (!this.showHeader) { this.headerHeight = 0; if (this.height !== null && (!isNaN(this.height) || typeof this.height === 'string')) { this.bodyHeight = height - footerHeight + (footerWrapper ? 1 : 0); } this.fixedBodyHeight = this.scrollX ? height - this.gutterWidth : height; } else { var headerHeight = this.headerHeight = headerWrapper.offsetHeight; var bodyHeight = height - headerHeight - footerHeight + (footerWrapper ? 1 : 0); if (this.height !== null && (!isNaN(this.height) || typeof this.height === 'string')) { this.bodyHeight = bodyHeight; } this.fixedBodyHeight = this.scrollX ? bodyHeight - this.gutterWidth : bodyHeight; } this.viewportHeight = this.scrollX ? height - (noData ? 0 : 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; } else { column.realWidth = column.width || column.minWidth; } 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; /***/ }, /***/ 312: /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _util = __webpack_require__(310); var _dom = __webpack_require__(123); var _checkbox = __webpack_require__(308); var _checkbox2 = _interopRequireDefault(_checkbox); var _tooltip = __webpack_require__(278); var _tooltip2 = _interopRequireDefault(_tooltip); var _debounce = __webpack_require__(63); var _debounce2 = _interopRequireDefault(_debounce); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = { components: { ElCheckbox: _checkbox2.default, ElTooltip: _tooltip2.default }, props: { store: { required: true }, stripe: Boolean, context: {}, layout: { required: true }, rowClassName: [String, Function], rowStyle: [Object, Function], fixed: String, highlight: Boolean }, render: function render(h) { var _this = this; var columnsHidden = this.columns.map(function (column, index) { return _this.isColumnHidden(index); }); return h( 'table', { 'class': 'el-table__body', attrs: { cellspacing: '0', cellpadding: '0', border: '0' } }, [h( 'colgroup', null, [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', { style: _this.rowStyle ? _this.getRowStyle(row, $index) : null, key: _this.table.rowKey ? _this.getKeyOfRow(row, $index) : $index, on: { 'dblclick': function dblclick($event) { return _this.handleDoubleClick($event, row); }, 'click': function click($event) { return _this.handleClick($event, row); }, 'contextmenu': function contextmenu($event) { return _this.handleContextMenu($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 || '', columnsHidden[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.context || _this.table.$vnode.context }, columnsHidden[cellIndex])] ); }), !_this.fixed && _this.layout.scrollY && _this.layout.gutterWidth ? h( 'td', { 'class': 'gutter' }, [] ) : ''] ), _this.store.states.expandRows.indexOf(row) > -1 ? h( 'tr', null, [h( 'td', { attrs: { colspan: _this.columns.length }, 'class': 'el-table__expanded-cell' }, [_this.table.renderExpanded ? _this.table.renderExpanded(h, { row: row, $index: $index, store: _this.store }) : ''] )] ) : '']; }).concat(this._self.$parent.$slots.append).concat(h( 'el-tooltip', { attrs: { effect: this.table.tooltipEffect, placement: 'top', content: this.tooltipContent }, ref: 'tooltip' }, [] ))] )] ); }, watch: { 'store.states.hoverRow': function storeStatesHoverRow(newVal, oldVal) { if (!this.store.states.isComplex) return; var el = this.$el; if (!el) return; var rows = el.querySelectorAll('tbody > tr.el-table__row'); var oldRow = rows[oldVal]; var newRow = rows[newVal]; if (oldRow) { (0, _dom.removeClass)(oldRow, 'hover-row'); } if (newRow) { (0, _dom.addClass)(newRow, '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('tbody > tr.el-table__row'); var oldRow = rows[data.indexOf(oldVal)]; var newRow = rows[data.indexOf(newVal)]; if (oldRow) { (0, _dom.removeClass)(oldRow, 'current-row'); } else if (rows) { [].forEach.call(rows, function (row) { return (0, _dom.removeClass)(row, 'current-row'); }); } if (newRow) { (0, _dom.addClass)(newRow, 'current-row'); } } }, computed: { table: function table() { return this.$parent; }, 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 { tooltipContent: '' }; }, created: function created() { this.activateTooltip = (0, _debounce2.default)(50, function (tooltip) { return tooltip.handleShowPopper(); }); }, methods: { getKeyOfRow: function getKeyOfRow(row, index) { var rowKey = this.table.rowKey; if (rowKey) { return (0, _util.getRowIdentity)(row, rowKey); } return index; }, isColumnHidden: function isColumnHidden(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; } }, getRowStyle: function getRowStyle(row, index) { var rowStyle = this.rowStyle; if (typeof rowStyle === 'function') { return rowStyle.call(null, row, index); } return rowStyle; }, getRowClass: function getRowClass(row, index) { var classes = ['el-table__row']; if (this.stripe && index % 2 === 1) { classes.push('el-table__row--striped'); } var rowClassName = this.rowClassName; if (typeof rowClassName === 'string') { classes.push(rowClassName); } else if (typeof rowClassName === 'function') { classes.push(rowClassName.call(null, row, index) || ''); } return classes.join(' '); }, handleCellMouseEnter: function handleCellMouseEnter(event, row) { var table = this.table; 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'); if ((0, _dom.hasClass)(cellChild, 'el-tooltip') && cellChild.scrollWidth > cellChild.offsetWidth) { var tooltip = this.$refs.tooltip; this.tooltipContent = cell.innerText; tooltip.referenceElm = cell; tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none'); tooltip.doDestroy(); tooltip.setExpectedState(true); this.activateTooltip(tooltip); } }, handleCellMouseLeave: function handleCellMouseLeave(event) { var tooltip = this.$refs.tooltip; if (tooltip) { tooltip.setExpectedState(false); tooltip.handleClosePopper(); } var cell = (0, _util.getCell)(event); if (!cell) return; var oldHoverState = this.table.hoverState; this.table.$emit('cell-mouse-leave', oldHoverState.row, oldHov