UNPKG

element-ui

Version:

A Component Library for Vue.js.

1,984 lines (1,649 loc) 110 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] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = 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; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/dist/"; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 183); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports) { /* globals __VUE_SSR_CONTEXT__ */ // IMPORTANT: Do NOT use ES2015 features in this file. // 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, functionalTemplate, 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 options._compiled = true } // functional template if (functionalTemplate) { options.functional = true } // scopedId if (scopeId) { options._scopeId = scopeId } var hook if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || // cached call (this.$vnode && this.$vnode.ssrContext) || // stateful (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional // 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) { var functional = options.functional var existing = functional ? options.render : options.beforeCreate if (!functional) { // inject component registration as beforeCreate hook options.beforeCreate = existing ? [].concat(existing, hook) : [hook] } else { // for template-only hot-reload because in that case the render fn doesn't // go through the normalizer options._injectStyles = hook // register for functioal component in vue file options.render = function renderWithStyleInjection (h, context) { hook.call(context) return existing(h, context) } } } 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/popup"); /***/ }), /***/ 14: /***/ (function(module, exports) { module.exports = require("throttle-debounce/debounce"); /***/ }), /***/ 16: /***/ (function(module, exports) { module.exports = require("element-ui/lib/checkbox"); /***/ }), /***/ 18: /***/ (function(module, exports) { module.exports = require("element-ui/lib/utils/resize-event"); /***/ }), /***/ 183: /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(184); /***/ }), /***/ 184: /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _table = __webpack_require__(185); 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; /***/ }), /***/ 185: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__ = __webpack_require__(186); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_271dac46_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_table_vue__ = __webpack_require__(198); var normalizeComponent = __webpack_require__(0) /* script */ /* template */ /* template functional */ var __vue_template_functional__ = false /* styles */ var __vue_styles__ = null /* scopeId */ var __vue_scopeId__ = null /* moduleIdentifier (server only) */ var __vue_module_identifier__ = null var Component = normalizeComponent( __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_table_vue___default.a, __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_271dac46_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_table_vue__["a" /* default */], __vue_template_functional__, __vue_styles__, __vue_scopeId__, __vue_module_identifier__ ) /* harmony default export */ __webpack_exports__["default"] = (Component.exports); /***/ }), /***/ 186: /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _checkbox = __webpack_require__(16); var _checkbox2 = _interopRequireDefault(_checkbox); var _debounce = __webpack_require__(14); var _debounce2 = _interopRequireDefault(_debounce); var _resizeEvent = __webpack_require__(18); var _mousewheel = __webpack_require__(187); var _mousewheel2 = _interopRequireDefault(_mousewheel); var _locale = __webpack_require__(5); var _locale2 = _interopRequireDefault(_locale); var _migrating = __webpack_require__(8); var _migrating2 = _interopRequireDefault(_migrating); var _tableStore = __webpack_require__(189); var _tableStore2 = _interopRequireDefault(_tableStore); var _tableLayout = __webpack_require__(190); var _tableLayout2 = _interopRequireDefault(_tableLayout); var _tableBody = __webpack_require__(191); var _tableBody2 = _interopRequireDefault(_tableBody); var _tableHeader = __webpack_require__(192); var _tableHeader2 = _interopRequireDefault(_tableHeader); var _tableFooter = __webpack_require__(197); var _tableFooter2 = _interopRequireDefault(_tableFooter); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var tableIdSeed = 1; // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // exports.default = { name: 'ElTable', mixins: [_locale2.default, _migrating2.default], directives: { Mousewheel: _mousewheel2.default }, props: { data: { type: Array, default: function _default() { return []; } }, size: String, 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], cellClassName: [String, Function], cellStyle: [Object, Function], headerRowClassName: [String, Function], headerRowStyle: [Object, Function], headerCellClassName: [String, Function], headerCellStyle: [Object, Function], highlightCurrentRow: Boolean, currentRowKey: [String, Number], emptyText: String, expandRowKeys: Array, defaultExpandAll: Boolean, defaultSort: Object, tooltipEffect: String, spanMethod: Function, selectOnIndeterminate: { type: Boolean, default: true } }, components: { TableHeader: _tableHeader2.default, TableFooter: _tableFooter2.default, TableBody: _tableBody2.default, ElCheckbox: _checkbox2.default }, methods: { getMigratingConfig: function getMigratingConfig() { return { events: { expand: 'expand is renamed to expand-change' } }; }, setCurrentRow: function setCurrentRow(row) { this.store.commit('setCurrentRow', row); }, toggleRowSelection: function toggleRowSelection(row, selected) { this.store.toggleRowSelection(row, selected); this.store.updateAllSelected(); }, toggleRowExpansion: function toggleRowExpansion(row, expanded) { this.store.toggleRowExpansion(row, expanded); }, clearSelection: function clearSelection() { this.store.clearSelection(); }, clearFilter: function clearFilter() { this.store.clearFilter(); }, clearSort: function clearSort() { this.store.clearSort(); }, handleMouseLeave: function handleMouseLeave() { this.store.commit('setHoverRow', null); if (this.hoverState) this.hoverState = null; }, updateScrollY: function updateScrollY() { this.layout.updateScrollY(); }, handleFixedMousewheel: function handleFixedMousewheel(event, data) { var bodyWrapper = this.bodyWrapper; if (Math.abs(data.spinY) > 0) { var currentScrollTop = bodyWrapper.scrollTop; if (data.pixelY < 0 && currentScrollTop !== 0) { event.preventDefault(); } if (data.pixelY > 0 && bodyWrapper.scrollHeight - bodyWrapper.clientHeight > currentScrollTop) { event.preventDefault(); } bodyWrapper.scrollTop += Math.ceil(data.pixelY / 5); } else { bodyWrapper.scrollLeft += Math.ceil(data.pixelX / 5); } }, handleHeaderFooterMousewheel: function handleHeaderFooterMousewheel(event, data) { var pixelX = data.pixelX, pixelY = data.pixelY; if (Math.abs(pixelX) >= Math.abs(pixelY)) { event.preventDefault(); this.bodyWrapper.scrollLeft += data.pixelX / 5; } }, bindEvents: function bindEvents() { var _$refs = this.$refs, headerWrapper = _$refs.headerWrapper, footerWrapper = _$refs.footerWrapper; var refs = this.$refs; var self = this; 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 maxScrollLeftPosition = this.scrollWidth - this.offsetWidth - 1; var scrollLeft = this.scrollLeft; if (scrollLeft >= maxScrollLeftPosition) { self.scrollPosition = 'right'; } else if (scrollLeft === 0) { self.scrollPosition = 'left'; } else { self.scrollPosition = 'middle'; } }); if (this.fit) { (0, _resizeEvent.addResizeListener)(this.$el, this.resizeListener); } }, resizeListener: function resizeListener() { if (!this.$ready) return; var shouldUpdateLayout = false; var el = this.$el; var _resizeState = this.resizeState, oldWidth = _resizeState.width, oldHeight = _resizeState.height; var width = el.offsetWidth; if (oldWidth !== width) { shouldUpdateLayout = true; } var height = el.offsetHeight; if ((this.height || this.shouldUpdateHeight) && oldHeight !== height) { shouldUpdateLayout = true; } if (shouldUpdateLayout) { this.resizeState.width = width; this.resizeState.height = height; this.doLayout(); } }, doLayout: function doLayout() { this.layout.updateColumnsWidth(); if (this.shouldUpdateHeight) { this.layout.updateElsHeight(); } } }, created: function created() { var _this = this; this.tableId = 'el-table_' + tableIdSeed++; this.debouncedUpdateLayout = (0, _debounce2.default)(50, function () { return _this.doLayout(); }); }, computed: { tableSize: function tableSize() { return this.size || (this.$ELEMENT || {}).size; }, bodyWrapper: function bodyWrapper() { return this.$refs.bodyWrapper; }, shouldUpdateHeight: function shouldUpdateHeight() { return this.height || this.maxHeight || 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; }, bodyWidth: function bodyWidth() { var _layout = this.layout, bodyWidth = _layout.bodyWidth, scrollY = _layout.scrollY, gutterWidth = _layout.gutterWidth; return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : ''; }, bodyHeight: function bodyHeight() { if (this.height) { return { height: this.layout.bodyHeight ? this.layout.bodyHeight + 'px' : '' }; } else if (this.maxHeight) { return { 'max-height': (this.showHeader ? this.maxHeight - this.layout.headerHeight - this.layout.footerHeight : this.maxHeight - this.layout.footerHeight) + 'px' }; } return {}; }, fixedBodyHeight: function fixedBodyHeight() { if (this.height) { return { 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; } maxHeight -= this.layout.footerHeight; return { 'max-height': maxHeight + 'px' }; } return {}; }, fixedHeight: function fixedHeight() { if (this.maxHeight) { if (this.showSummary) { return { bottom: 0 }; } return { bottom: this.layout.scrollX && this.data.length ? this.layout.gutterWidth + 'px' : '' }; } else { if (this.showSummary) { return { height: this.layout.tableHeight ? this.layout.tableHeight + 'px' : '' }; } return { height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : '' }; } } }, watch: { height: { immediate: true, handler: function handler(value) { this.layout.setHeight(value); } }, maxHeight: { immediate: true, handler: function handler(value) { this.layout.setMaxHeight(value); } }, currentRowKey: function currentRowKey(newVal) { this.store.setCurrentRowKey(newVal); }, data: { immediate: true, handler: function handler(value) { var _this2 = this; this.store.commit('setData', value); if (this.$ready) { this.$nextTick(function () { _this2.doLayout(); }); } } }, expandRowKeys: { immediate: true, handler: function handler(newVal) { if (newVal) { this.store.setExpandRowKeys(newVal); } } } }, destroyed: function destroyed() { if (this.resizeListener) (0, _resizeEvent.removeResizeListener)(this.$el, this.resizeListener); }, mounted: function mounted() { var _this3 = this; this.bindEvents(); this.store.updateColumns(); this.doLayout(); this.resizeState = { width: this.$el.offsetWidth, height: this.$el.offsetHeight }; // init filters this.store.states.columns.forEach(function (column) { if (column.filteredValue && column.filteredValue.length) { _this3.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, selectOnIndeterminate: this.selectOnIndeterminate }); var layout = new _tableLayout2.default({ store: store, table: this, fit: this.fit, showHeader: this.showHeader }); return { layout: layout, store: store, isHidden: false, renderExpanded: null, resizeProxyVisible: false, resizeState: { width: null, height: null }, // 是否拥有多级表头 isGroup: false, scrollPosition: 'left' }; } }; /***/ }), /***/ 187: /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _normalizeWheel = __webpack_require__(188); var _normalizeWheel2 = _interopRequireDefault(_normalizeWheel); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1; var mousewheel = function mousewheel(element, callback) { if (element && element.addEventListener) { element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', function (event) { var normalized = (0, _normalizeWheel2.default)(event); callback && callback.apply(this, [event, normalized]); }); } }; exports.default = { bind: function bind(el, binding) { mousewheel(el, binding.value); } }; /***/ }), /***/ 188: /***/ (function(module, exports) { module.exports = require("normalize-wheel"); /***/ }), /***/ 189: /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _vue = __webpack_require__(4); var _vue2 = _interopRequireDefault(_vue); var _debounce = __webpack_require__(14); var _debounce2 = _interopRequireDefault(_debounce); var _merge = __webpack_require__(9); var _merge2 = _interopRequireDefault(_merge); var _util = __webpack_require__(47); 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, sortingColumn.sortBy); }; 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 toggleRowExpansion = function toggleRowExpansion(states, row, expanded) { var changed = false; var expandRows = states.expandRows; if (typeof expanded !== 'undefined') { var index = expandRows.indexOf(row); if (expanded) { if (index === -1) { expandRows.push(row); changed = true; } } else { if (index !== -1) { expandRows.splice(index, 1); changed = true; } } } else { var _index = expandRows.indexOf(row); if (_index === -1) { expandRows.push(row); changed = true; } else { expandRows.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: [], leafColumns: [], fixedLeafColumns: [], rightFixedLeafColumns: [], leafColumnsLength: 0, fixedLeafColumnsLength: 0, rightFixedLeafColumnsLength: 0, isComplex: false, 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, selectOnIndeterminate: 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; Object.keys(states.filters).forEach(function (columnId) { var values = states.filters[columnId]; if (!values || values.length === 0) return; var column = (0, _util.getColumnById)(_this.states, columnId); if (column && column.filterMethod) { data = data.filter(function (row) { return values.some(function (value) { return column.filterMethod.call(null, value, row, column); }); }); } }); states.filteredData = 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.'); } })(); } 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, options) { var _this2 = this; states.data = sortData(states.filteredData || states._data || [], states); if (!options || !options.silent) { 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, column); }); }); } }); 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; } if (this.table.$ready) { this.updateColumns(); // hack for dynamics insert column this.scheduleLayout(); } }, removeColumn: function removeColumn(states, column, parent) { var array = states._columns; if (parent) { array = parent.children; if (!array) array = parent.children = []; } if (array) { array.splice(array.indexOf(column), 1); } if (this.table.$ready) { 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 ? selection.slice() : []); table.$emit('select', selection, row); } this.updateAllSelected(); }, toggleAllSelection: (0, _debounce2.default)(10, function (states) { var data = states.data || []; if (data.length === 0) return; var selection = this.states.selection; // when only some rows are selected (but not all), select or deselect all of them // depending on the value of selectOnIndeterminate var value = states.selectOnIndeterminate ? !states.isAllSelected : !(states.isAllSelected || selection.length); 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 ? selection.slice() : []); } 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]); } var notFixedColumns = _columns.filter(function (column) { return !column.fixed; }); states.originColumns = [].concat(states.fixedColumns).concat(notFixedColumns).concat(states.rightFixedColumns); var leafColumns = doFlattenColumns(notFixedColumns); var fixedLeafColumns = doFlattenColumns(states.fixedColumns); var rightFixedLeafColumns = doFlattenColumns(states.rightFixedColumns); states.leafColumnsLength = leafColumns.length; states.fixedLeafColumnsLength = fixedLeafColumns.length; states.rightFixedLeafColumnsLength = rightFixedLeafColumns.length; states.columns = [].concat(fixedLeafColumns).concat(leafColumns).concat(rightFixedLeafColumns); 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; if (states.selection.length) { states.selection = []; } if (oldSelection.length > 0) { this.table.$emit('selection-change', states.selection ? states.selection.slice() : []); } }; 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 ? this.states.selection.slice() : []); } }; TableStore.prototype.toggleRowExpansion = function (row, expanded) { var changed = toggleRowExpansion(this.states, row, expanded); if (changed) { this.table.$emit('expand-change', row, this.states.expandRows); this.scheduleLayout(); } }; TableStore.prototype.isRowExpanded = function (row) { var _states = this.states, _states$expandRows = _states.expandRows, expandRows = _states$expandRows === undefined ? [] : _states$expandRows, rowKey = _states.rowKey; if (rowKey) { var expandMap = getKeysMap(expandRows, rowKey); return !!expandMap[(0, _util.getRowIdentity)(row, rowKey)]; } return expandRows.indexOf(row) !== -1; }; 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 ? selection.slice() : []); } }; TableStore.prototype.clearFilter = function () { var states = this.states; var _table$$refs = this.table.$refs, tableHeader = _table$$refs.tableHeader, fixedTableHeader = _table$$refs.fixedTableHeader, rightFixedTableHeader = _table$$refs.rightFixedTableHeader; var panels = {}; if (tableHeader) panels = (0, _merge2.default)(panels, tableHeader.filterPanels); if (fixedTableHeader) panels = (0, _merge2.default)(panels, fixedTableHeader.filterPanels); if (rightFixedTableHeader) panels = (0, _merge2.default)(panels, rightFixedTableHeader.filterPanels); var keys = Object.keys(panels); if (!keys.length) return; keys.forEach(function (key) { panels[key].filteredValue = []; }); states.filters = {}; this.commit('filterChange', { column: {}, values: [], silent: true }); }; TableStore.prototype.clearSort = function () { var states = this.states; if (!states.sortingColumn) return; states.sortingColumn.order = null; states.sortProp = null; states.sortOrder = null; this.commit('changeSortCondition', { silent: true }); }; 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]; var isRowSelectable = selectable && selectable.call(null, item, i); if (!isSelected(item)) { if (!selectable || isRowSelectable) { isAllSelected = false; break; } } else { selectedCount++; } } if (selectedCount === 0) isAllSelected = false; states.isAllSelected = isAllSelected; }; TableStore.prototype.scheduleLayout = function (updateColumns) { if (updateColumns) { this.updateColumns(); } this.table.debouncedUpdateLayout(); }; 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; /***/ }), /***/ 190: /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _scrollbarWidth = __webpack_require__(37); var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth); var _vue = __webpack_require__(4); var _vue2 = _interopRequireDefault(_vue); 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.observers = []; 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.appendHeight = 0; // Append Slot 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 > this.bodyHeight; } }; TableLayout.prototype.setHeight = function setHeight(value) { var _this = this; var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'height'; if (_vue2.default.prototype.$isServer) return; var el = this.table.$el; if (typeof value === 'string' && /^\d+$/.test(value)) { value = Number(value); } this.height = value; if (!el && (value || value === 0)) return _vue2.default.nextTick(function () { return _this.setHeight(value, prop); }); if (typeof value === 'number') { el.style[prop] = value + 'px'; this.updateElsHeight(); } else if (typeof value === 'string') { el.style[prop] = value; this.updateElsHeight(); } }; TableLayout.prototype.setMaxHeight = function setMaxHeight(value) { return this.setHeight(value, 'max-height'); }; TableLayout.prototype.updateElsHeight = function updateElsHeight() { var _this2 = this; if (!this.table.$ready) return _vue2.default.nextTick(function () { return _this2.updateElsHeight(); }); var _table$$refs = this.table.$refs, headerWrapper = _table$$refs.headerWrapper, appendWrapper = _table$$refs.appendWrapper, footerWrapper = _table$$refs.footerWrapper; this.appendHeight = appendWrapper ? appendWrapper.offsetHeight : 0; if (this.showHeader && !headerWrapper) return; var headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight; if (this.showHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) { return _vue2.default.nextTick(function () { return _this2.updateElsHeight(); }); } var tableHeight = this.tableHeight = this.table.$el.clientHeight; if (this.height !== null && (!isNaN(this.height) || typeof this.height === 'string')) { var footerHeight = this.footerHeight = footerWrapper ? footerWrapper.offsetHeight : 0; this.bodyHeight = tableHeight - headerHeight - footerHeight + (footerWrapper ? 1 : 0); } this.fixedBodyHeight = this.scrollX ? this.bodyHeight - this.gutterWidth : this.bodyHeight; var noData = !this.table.data || this.table.data.length === 0; this.viewportHeight = this.scrollX ? tableHeight - (noData ? 0 : this.gutterWidth) : tableHeight; this.updateScrollY(); this.notifyObservers('scrollable'); }; TableLayout.prototype.getFlattenColumns = function getFlattenColumns() { var flattenColumns = []; var columns = this.table.columns; columns.forEach(function (column) { if (column.isColumnGroup) { flattenColumns.push.apply(flattenColumns, column.columns); } else { flattenColumns.push(column); } }); return flattenColumns; }; TableLayout.prototype.updateColumnsWidth = function updateColumnsWidth() { var fit = this.fit; var bodyWidth = this.table.$el.clientWidth; var bodyMinWidth = 0; var flattenColumns = this.getFlattenColumns(); var flexColumns = flattenColumns.filter(function (column) { return typeof column.width !== 'number'; }); flattenColumns.forEach(function (column) { // Clean those columns whose width changed from flex to unflex if (typeof column.width === 'number' && column.realWidth) column.realWidth = null; }); if (flexColumns.length > 0 && fit) { flattenColumns.forEach(function (column) { bodyMinWidth += column.width || column.minWidth || 80; }); var scrollYWidth = this.scrollY ? this.gutterWidth : 0; if (bodyMinWidth <= bodyWidth - scrollYWidth) { // DON'T HAVE SCROLL BAR this.scrollX = false; var totalFlexWidth = bodyWidth - scrollYWidth - 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 || column.width; }); this.fixedWidth = fixedWidth; } var rightFixedColumns = this.store.states.rightFixedColumns; if (rightFixedColumns.length > 0) { var rightFixedWidth = 0; rightFixedColumns.forEach(function (column) { rightFixedWidth += column.realWidth || column.width; }); this.rightFixedWidth = rightFixedWidth; } this.notifyObservers('columns'); }; TableLayout.prototype.addObserver = function addObserver(observer) { this.observers.push(observer); }; TableLayout.prototype.removeObserver = function removeObserver(observer) { var index = this.observers.indexOf(observer); if (index !== -1) { this.observers.splice(index, 1); } }; TableLayout.prototype.notifyObservers = function notifyObservers(event) { var _this3 = this; var observers = this.observers; observers.forEach(function (observer) { switch (event) { case 'columns': observer.onColumnsChange(_this3); break; case 'scrollable': observer.onScrollableChange(_this3); break; default: throw new Error('Table Layout don\'t have event ' + event + '.'); } }); }; return TableLayout; }(); exports.default = TableLayout; /***/ }), /***/ 191: /***/ (function(module, exports, __webpack_require__) { "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 _util = __webpack_require__(47); var _dom = __webpack_require__(2); var _checkbox = __webpack_require__(16); var _checkbox2 = _interopRequireDefault(_checkbox); var _tooltip = __webpack_require__(22); var _tooltip2 = _interopRequireDefault(_tooltip); var _debounce = __webpack_require__(14); var _debounce2 = _interopRequireDefault(_debounce); var _layoutObserver = __webpack_require__(38); var _layoutObserver2 = _interopRequireDefault(_layoutObserver); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = { name: 'ElTableBody', mixins: [_layoutObserver2.default], components: { ElCheckbox: _checkbox2.default, ElTooltip: _tooltip2.default }, props: { store: { required: true }, stripe: Boolean, context: {}, 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