UNPKG

element-nice-ui

Version:

A Component Library for Vue.js.

1,481 lines (1,432 loc) 188 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, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // 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); /******/ }) /************************************************************************/ /******/ ({ /***/ 120: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/utils/scrollbar-width"); /***/ }), /***/ 169: /***/ (function(module, exports) { module.exports = require("normalize-wheel"); /***/ }), /***/ 17: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/utils/vue-popper"); /***/ }), /***/ 170: /***/ (function(module, exports) { module.exports = require("element-nice-ui/lib/action"); /***/ }), /***/ 18: /***/ (function(module, exports) { module.exports = require("vue"); /***/ }), /***/ 183: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib/loaders/templateLoader.js??ref--5!./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib??vue-loader-options!./packages/table/src/main.vue?vue&type=template&id=4e22e0d9 var render = function render() { var _vm = this, _c = _vm._self._c return _c( "div", { staticClass: "el-happy-table", class: { "el-happy-table--auto-height": _vm.autoHeight }, }, [ _vm.showSearcher && _vm.$slots.searcher ? _c( "div", { ref: "searcher", staticClass: "el-happy-table__searcher", on: { keyup: function ($event) { if ( !$event.type.indexOf("key") && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter") ) return null return _vm.fetchData.apply(null, arguments) }, }, }, _vm._l(_vm.$slots.searcher, function (node, i) { return _c("searcher-render", { key: i, attrs: { ctx: _vm.ctx, "label-width": _vm.queryLabelWidth, node: node, }, }) }), 1 ) : _vm._e(), _vm.showTools ? _c( "div", { ref: "tools", staticClass: "el-happy-table__tools" }, [ _c( "el-context", { staticClass: "el-happy-table__tools-left", attrs: { ctx: _vm.ctx, depth: 2, tag: "section" }, }, [_vm._t("tools")], 2 ), _c( "el-context", { staticClass: "el-happy-table__tools-right", attrs: { depth: 2, ctx: _vm.ctx, tag: "section" }, }, [ _vm.api ? [ _c( "el-tooltip", { attrs: { content: "查询" } }, [ _c("el-btn", { attrs: { loading: _vm.loading, icon: "search", type: "primary", circle: "", }, on: { click: _vm.fetchData }, }), ], 1 ), _c( "el-tooltip", { attrs: { content: "重置" } }, [ _c("el-btn", { attrs: { loading: _vm.loading, icon: "refresh", type: "danger", circle: "", }, on: { click: _vm.onReset }, }), ], 1 ), ] : _vm._e(), _vm.$slots.searcher && _vm.api && !_vm.data && !this.noSearcher ? _c( "el-tooltip", { attrs: { content: "显示/隐藏 搜索栏" } }, [ _c("el-btn", { attrs: { icon: "set-up", circle: "" }, on: { input: _vm.onToggleSearcher }, model: { value: _vm.searchable, callback: function ($$v) { _vm.searchable = $$v }, expression: "searchable", }, }), ], 1 ) : _vm._e(), ], 2 ), ], 1 ) : _vm._e(), _c( "main-table", _vm._g( _vm._b( { directives: [ { name: "loading", rawName: "v-loading", value: _vm.loading, expression: "loading", }, ], ref: "table", class: { "el-happy-table--with-footer": _vm.pagination, "el-happy-table--selectable": _vm.value !== undefined, }, attrs: { stripe: _vm.stripe, size: _vm.size, height: _vm.bodyHeight, "tree-props": _vm.treeProps, showHeader: _vm.headers && !!_vm.headers.length, data: _vm.computedData, placeholder: _vm.placeholder, "highlight-current-row": _vm.isSingle, }, on: { "selection-change": function ($event) { return _vm.onSelectionChange($event, "multiple") }, "current-change": function ($event) { return _vm.onSelectionChange($event, "single") }, }, }, "main-table", _vm.$attrs, false ), _vm.$listeners ), _vm._l(_vm.computedHeaders, function (header) { return _c( "table-column", _vm._b( { key: header._id, scopedSlots: _vm._u( [ header.slotName ? { key: "default", fn: function ({ row, column, $index, indexPath }) { return [ header.type === "action" ? _c( "el-action", { attrs: { ctx: _vm.ctx } }, [ _vm._t( "column." + header.slotName, function () { return [ _vm._v( "\n " + _vm._s(_vm.placeholder) + "\n " ), ] }, null, { row, column, value: _vm.getValueByPath( row, header.prop ), index: $index, indexPath, } ), ], 2 ) : _vm._t( "column." + header.slotName, function () { return [ _vm._v( "\n " + _vm._s(_vm.placeholder) + "\n " ), ] }, null, { row, column, value: _vm.getValueByPath( row, header.prop ), index: $index, indexPath, ctx: _vm.ctx, } ), ] }, } : null, ], null, true ), }, "table-column", header, false ) ) }), 1 ), _vm.pagination ? _c( "el-pagination", _vm._b( { ref: "pagination", attrs: { "page-size": _vm.pager.size, "current-page": _vm.pager.page, layout: "total, sizes, prev, pager, next, jumper", "page-sizes": _vm.pageSizes, total: _vm.total, disabled: _vm.loading, }, on: { "size-change": _vm.onPaginationSizeChange, "current-change": _vm.onPaginationPageChange, }, }, "el-pagination", _vm.pageConfig, false ) ) : _vm._e(), _vm._t("outer"), ], 2 ) } var staticRenderFns = [] render._withStripped = true // CONCATENATED MODULE: ./packages/table/src/main.vue?vue&type=template&id=4e22e0d9 // CONCATENATED MODULE: ./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib/loaders/templateLoader.js??ref--5!./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.18_css-loader@5.2.7_webpack@4.47.0__lodash@4.1_bb9a19950a80e648dc95ba33c71fa343/node_modules/vue-loader/lib??vue-loader-options!./packages/table/src/table.vue?vue&type=template&id=be6925c8 var tablevue_type_template_id_be6925c8_render = function render() { var _vm = this, _c = _vm._self._c return _c( "div", { staticClass: "el-table", class: [ { "el-table--fit": _vm.fit, "el-table--striped": _vm.stripe, "el-table--border": _vm.border || _vm.isGroup, "el-table--hidden": _vm.isHidden, "el-table--group": _vm.isGroup, "el-table--fluid-height": _vm.maxHeight, "el-table--scrollable-x": _vm.layout.scrollX, "el-table--scrollable-y": _vm.layout.scrollY, "el-table--enable-row-hover": !_vm.store.states.isComplex, "el-table--enable-row-transition": (_vm.store.states.data || []).length !== 0 && (_vm.store.states.data || []).length < 100, }, _vm.tableSize ? `el-table--${_vm.tableSize}` : "", ], on: { mouseleave: function ($event) { return _vm.handleMouseLeave($event) }, }, }, [ _vm.showHeader ? [ _c( "div", { ref: "hiddenColumns", staticClass: "hidden-columns" }, [_vm._t("default")], 2 ), _c( "div", { directives: [ { name: "mousewheel", rawName: "v-mousewheel", value: _vm.handleHeaderFooterMousewheel, expression: "handleHeaderFooterMousewheel", }, ], ref: "headerWrapper", staticClass: "el-table__header-wrapper", }, [ _c("table-header", { ref: "tableHeader", style: { width: _vm.layout.bodyWidth ? _vm.layout.bodyWidth + "px" : "", }, attrs: { store: _vm.store, border: _vm.border, "default-sort": _vm.defaultSort, }, }), ], 1 ), ] : _vm._e(), _c( "div", { ref: "bodyWrapper", staticClass: "el-table__body-wrapper", class: [ _vm.layout.scrollX ? `is-scrolling-${_vm.scrollPosition}` : "is-scrolling-none", ], style: [_vm.bodyHeight], }, [ _c("table-body", { style: { width: _vm.bodyWidth, }, attrs: { context: _vm.context, store: _vm.store, stripe: _vm.stripe, "row-class-name": _vm.rowClassName, "row-style": _vm.rowStyle, highlight: _vm.highlightCurrentRow, }, }), !_vm.data || _vm.data.length === 0 ? _c( "div", { ref: "emptyBlock", staticClass: "el-table__empty-block", style: _vm.emptyBlockStyle, }, [ _c( "span", { staticClass: "el-table__empty-text" }, [ _vm._t("empty", function () { return [ _vm._v( _vm._s(_vm.emptyText || _vm.t("el.table.emptyText")) ), ] }), ], 2 ), ] ) : _vm._e(), _vm.$slots.append ? _c( "div", { ref: "appendWrapper", staticClass: "el-table__append-wrapper", }, [_vm._t("append")], 2 ) : _vm._e(), ], 1 ), _vm.showSummary ? _c( "div", { directives: [ { name: "show", rawName: "v-show", value: _vm.data && _vm.data.length > 0, expression: "data && data.length > 0", }, { name: "mousewheel", rawName: "v-mousewheel", value: _vm.handleHeaderFooterMousewheel, expression: "handleHeaderFooterMousewheel", }, ], ref: "footerWrapper", staticClass: "el-table__footer-wrapper", }, [ _c("table-footer", { style: { width: _vm.layout.bodyWidth ? _vm.layout.bodyWidth + "px" : "", }, attrs: { store: _vm.store, data: _vm.tableData, border: _vm.border, "sum-text": _vm.sumText || _vm.t("el.table.sumText"), "summary-method": _vm.summaryMethod, "default-sort": _vm.defaultSort, }, }), ], 1 ) : _vm._e(), _vm.fixedColumns.length > 0 ? _c( "div", { directives: [ { name: "mousewheel", rawName: "v-mousewheel", value: _vm.handleFixedMousewheel, expression: "handleFixedMousewheel", }, ], ref: "fixedWrapper", staticClass: "el-table__fixed", style: [ { width: _vm.layout.fixedWidth ? _vm.layout.fixedWidth + "px" : "", }, _vm.fixedHeight, ], }, [ _vm.showHeader ? _c( "div", { ref: "fixedHeaderWrapper", staticClass: "el-table__fixed-header-wrapper", }, [ _c("table-header", { ref: "fixedTableHeader", style: { width: _vm.bodyWidth, }, attrs: { fixed: "left", border: _vm.border, store: _vm.store, }, }), ], 1 ) : _vm._e(), _c( "div", { ref: "fixedBodyWrapper", staticClass: "el-table__fixed-body-wrapper", style: [ { top: _vm.layout.headerHeight + "px", }, _vm.fixedBodyHeight, ], }, [ _c("table-body", { style: { width: _vm.bodyWidth, }, attrs: { fixed: "left", store: _vm.store, stripe: _vm.stripe, highlight: _vm.highlightCurrentRow, "row-class-name": _vm.rowClassName, "row-style": _vm.rowStyle, }, }), _vm.$slots.append ? _c("div", { staticClass: "el-table__append-gutter", style: { height: _vm.layout.appendHeight + "px" }, }) : _vm._e(), ], 1 ), _vm.showSummary ? _c( "div", { directives: [ { name: "show", rawName: "v-show", value: _vm.data && _vm.data.length > 0, expression: "data && data.length > 0", }, ], ref: "fixedFooterWrapper", staticClass: "el-table__fixed-footer-wrapper", }, [ _c("table-footer", { style: { width: _vm.bodyWidth, }, attrs: { fixed: "left", border: _vm.border, "sum-text": _vm.sumText || _vm.t("el.table.sumText"), "summary-method": _vm.summaryMethod, store: _vm.store, }, }), ], 1 ) : _vm._e(), ] ) : _vm._e(), _vm.rightFixedColumns.length > 0 ? _c( "div", { directives: [ { name: "mousewheel", rawName: "v-mousewheel", value: _vm.handleFixedMousewheel, expression: "handleFixedMousewheel", }, ], ref: "rightFixedWrapper", staticClass: "el-table__fixed-right", style: [ { width: _vm.layout.rightFixedWidth ? _vm.layout.rightFixedWidth + "px" : "", right: _vm.layout.scrollY ? (_vm.border ? _vm.layout.gutterWidth : _vm.layout.gutterWidth || 0) + "px" : "", }, _vm.fixedHeight, ], }, [ _vm.showHeader ? _c( "div", { ref: "rightFixedHeaderWrapper", staticClass: "el-table__fixed-header-wrapper", }, [ _c("table-header", { ref: "rightFixedTableHeader", style: { width: _vm.bodyWidth, }, attrs: { fixed: "right", border: _vm.border, store: _vm.store, }, }), ], 1 ) : _vm._e(), _c( "div", { ref: "rightFixedBodyWrapper", staticClass: "el-table__fixed-body-wrapper", style: [ { top: _vm.layout.headerHeight + "px", }, _vm.fixedBodyHeight, ], }, [ _c("table-body", { style: { width: _vm.bodyWidth, }, attrs: { fixed: "right", store: _vm.store, stripe: _vm.stripe, "row-class-name": _vm.rowClassName, "row-style": _vm.rowStyle, highlight: _vm.highlightCurrentRow, }, }), _vm.$slots.append ? _c("div", { staticClass: "el-table__append-gutter", style: { height: _vm.layout.appendHeight + "px" }, }) : _vm._e(), ], 1 ), _vm.showSummary ? _c( "div", { directives: [ { name: "show", rawName: "v-show", value: _vm.data && _vm.data.length > 0, expression: "data && data.length > 0", }, ], ref: "rightFixedFooterWrapper", staticClass: "el-table__fixed-footer-wrapper", }, [ _c("table-footer", { style: { width: _vm.bodyWidth, }, attrs: { fixed: "right", border: _vm.border, "sum-text": _vm.sumText || _vm.t("el.table.sumText"), "summary-method": _vm.summaryMethod, store: _vm.store, }, }), ], 1 ) : _vm._e(), ] ) : _vm._e(), _vm.rightFixedColumns.length > 0 ? _c("div", { ref: "rightFixedPatch", staticClass: "el-table__fixed-right-patch", style: { width: _vm.layout.scrollY ? _vm.layout.gutterWidth + "px" : "0", height: _vm.layout.headerHeight + "px", }, }) : _vm._e(), _c("div", { directives: [ { name: "show", rawName: "v-show", value: _vm.resizeProxyVisible, expression: "resizeProxyVisible", }, ], ref: "resizeProxy", staticClass: "el-table__column-resize-proxy", }), ], 2 ) } var tablevue_type_template_id_be6925c8_staticRenderFns = [] tablevue_type_template_id_be6925c8_render._withStripped = true // CONCATENATED MODULE: ./packages/table/src/table.vue?vue&type=template&id=be6925c8 // EXTERNAL MODULE: external "element-nice-ui/lib/checkbox" var checkbox_ = __webpack_require__(26); var checkbox_default = /*#__PURE__*/__webpack_require__.n(checkbox_); // EXTERNAL MODULE: external "throttle-debounce" var external_throttle_debounce_ = __webpack_require__(51); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/resize-event" var resize_event_ = __webpack_require__(35); // EXTERNAL MODULE: external "normalize-wheel" var external_normalize_wheel_ = __webpack_require__(169); var external_normalize_wheel_default = /*#__PURE__*/__webpack_require__.n(external_normalize_wheel_); // CONCATENATED MODULE: ./src/directives/mousewheel.js const isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1; const mousewheel_mousewheel = function mousewheel(element, callback) { if (element && element.addEventListener) { element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', function (event) { const normalized = external_normalize_wheel_default()(event); callback && callback.apply(this, [event, normalized]); }); } }; /* harmony default export */ var directives_mousewheel = ({ bind(el, binding) { mousewheel_mousewheel(el, binding.value); } }); // EXTERNAL MODULE: external "element-nice-ui/lib/mixins/locale" var locale_ = __webpack_require__(19); var locale_default = /*#__PURE__*/__webpack_require__.n(locale_); // EXTERNAL MODULE: external "element-nice-ui/lib/mixins/migrating" var migrating_ = __webpack_require__(25); var migrating_default = /*#__PURE__*/__webpack_require__.n(migrating_); // EXTERNAL MODULE: external "vue" var external_vue_ = __webpack_require__(18); var external_vue_default = /*#__PURE__*/__webpack_require__.n(external_vue_); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/merge" var merge_ = __webpack_require__(23); var merge_default = /*#__PURE__*/__webpack_require__.n(merge_); // EXTERNAL MODULE: ./packages/table/src/util.js var util = __webpack_require__(20); // CONCATENATED MODULE: ./packages/table/src/store/expand.js /* harmony default export */ var expand = ({ data() { return { states: { defaultExpandAll: false, expandRows: [] } }; }, methods: { updateExpandRows() { const { data = [], rowKey, defaultExpandAll, expandRows } = this.states; if (defaultExpandAll) { this.states.expandRows = data.slice(); } else if (rowKey) { // TODO:这里的代码可以优化 const expandRowsMap = Object(util["f" /* getKeysMap */])(expandRows, rowKey); this.states.expandRows = data.reduce((prev, row) => { const rowId = Object(util["g" /* getRowIdentity */])(row, rowKey); const rowInfo = expandRowsMap[rowId]; if (rowInfo) { prev.push(row); } return prev; }, []); } else { this.states.expandRows = []; } }, toggleRowExpansion(row, expanded) { const changed = Object(util["m" /* toggleRowStatus */])(this.states.expandRows, row, expanded); if (changed) { this.table.$emit('expand-change', row, this.states.expandRows.slice()); this.scheduleLayout(); } }, setExpandRowKeys(rowKeys) { this.assertRowKey(); // TODO:这里的代码可以优化 const { data, rowKey } = this.states; const keysMap = Object(util["f" /* getKeysMap */])(data, rowKey); this.states.expandRows = rowKeys.reduce((prev, cur) => { const info = keysMap[cur]; if (info) { prev.push(info.row); } return prev; }, []); }, isRowExpanded(row) { const { expandRows = [], rowKey } = this.states; if (rowKey) { const expandMap = Object(util["f" /* getKeysMap */])(expandRows, rowKey); return !!expandMap[Object(util["g" /* getRowIdentity */])(row, rowKey)]; } return expandRows.indexOf(row) !== -1; } } }); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/util" var util_ = __webpack_require__(5); // CONCATENATED MODULE: ./packages/table/src/store/current.js /* harmony default export */ var current = ({ data() { return { states: { // 不可响应的,设置 currentRowKey 时,data 不一定存在,也许无法算出正确的 currentRow // 把该值缓存一下,当用户点击修改 currentRow 时,把该值重置为 null _currentRowKey: null, currentRow: null } }; }, methods: { setCurrentRowKey(key) { this.assertRowKey(); this.states._currentRowKey = key; this.setCurrentRowByKey(key); }, restoreCurrentRowKey() { this.states._currentRowKey = null; }, setCurrentRowByKey(key) { const { states } = this; const { data = [], rowKey } = states; let currentRow = null; if (rowKey) { currentRow = Object(util_["arrayFind"])(data, item => Object(util["g" /* getRowIdentity */])(item, rowKey) === key); } states.currentRow = currentRow; return currentRow; }, updateCurrentRow(currentRow) { const { states, table } = this; const oldCurrentRow = states.currentRow; if (currentRow) { if (currentRow !== oldCurrentRow) { states.currentRow = currentRow; table.$emit('current-change', currentRow, oldCurrentRow); } else { states.currentRow = null; table.$emit('current-change', null, oldCurrentRow); } return; } if (!currentRow && oldCurrentRow) { states.currentRow = null; table.$emit('current-change', null, oldCurrentRow); } }, updateCurrentRowData() { const { states, table } = this; const { rowKey, _currentRowKey } = states; // data 为 null 时,解构时的默认值会被忽略 const data = states.data || []; const oldCurrentRow = states.currentRow; // 当 currentRow 不在 data 中时尝试更新数据 if (data.indexOf(oldCurrentRow) === -1 && oldCurrentRow) { if (rowKey) { const currentRowKey = Object(util["g" /* getRowIdentity */])(oldCurrentRow, rowKey); this.setCurrentRowByKey(currentRowKey); } else { states.currentRow = null; } if (states.currentRow === null) { table.$emit('current-change', null, oldCurrentRow); } } else if (_currentRowKey) { // 把初始时下设置的 rowKey 转化成 rowData this.setCurrentRowByKey(_currentRowKey); this.restoreCurrentRowKey(); } } } }); // EXTERNAL MODULE: external "element-nice-ui/lib/utils/shared" var shared_ = __webpack_require__(31); // CONCATENATED MODULE: ./packages/table/src/store/tree.js function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* harmony default export */ var tree = ({ data() { return { states: { // defaultExpandAll 存在于 expand.js 中,这里不重复添加 // 在展开行中,expandRowKeys 会被转化成 expandRows,expandRowKeys 这个属性只是记录了 TreeTable 行的展开 // TODO: 拆分为独立的 TreeTable,统一用法 expandRowKeys: [], treeData: {}, indent: 16, lazy: false, lazyTreeNodeMap: {}, lazyColumnIdentifier: 'hasChildren', childrenColumnName: 'children' } }; }, computed: { // 嵌入型的数据,watch 无法是检测到变化 https://github.com/ElemeFE/element/issues/14998 // TODO: 使用 computed 解决该问题,是否会造成性能问题? // @return { id: { level, children } } normalizedData() { if (!this.states.rowKey) return {}; const data = this.states.data || []; return this.normalize(data); }, // @return { id: { children } } // 针对懒加载的情形,不处理嵌套数据 normalizedLazyNode() { const { rowKey, lazyTreeNodeMap, lazyColumnIdentifier } = this.states; const keys = Object.keys(lazyTreeNodeMap); const res = {}; if (!keys.length) return res; keys.forEach(key => { if (lazyTreeNodeMap[key].length) { const item = { children: [] }; lazyTreeNodeMap[key].forEach(row => { const currentRowKey = Object(util["g" /* getRowIdentity */])(row, rowKey); item.children.push(currentRowKey); if (row[lazyColumnIdentifier] && !res[currentRowKey]) { res[currentRowKey] = { children: [] }; } }); res[key] = item; } }); return res; } }, watch: { normalizedData: 'updateTreeData', normalizedLazyNode: 'updateTreeData' }, methods: { normalize(data) { const { childrenColumnName, lazyColumnIdentifier, rowKey, lazy } = this.states; const res = {}; /** 表示需要懒加载的数据 */ if (lazy) { data.forEach(item => { if (!item[lazyColumnIdentifier]) return; const parentId = Object(util["g" /* getRowIdentity */])(item, rowKey); res[parentId] = { children: [], lazy, level: 0 }; }); } else { Object(shared_["walkTreeNode"])(data, (parent, children, level) => { if (!children) return; res[Object(util["g" /* getRowIdentity */])(parent, rowKey)] = { children: children.map(row => Object(util["g" /* getRowIdentity */])(row, rowKey)), level }; }, childrenColumnName); } return res; }, updateTreeData() { const nested = this.normalizedData; const normalizedLazyNode = this.normalizedLazyNode; const keys = Object.keys(nested); const newTreeData = {}; if (keys.length) { const { treeData: oldTreeData, defaultExpandAll, expandRowKeys, lazy } = this.states; const rootLazyRowKeys = []; const getExpanded = (oldValue, key) => { const included = defaultExpandAll || expandRowKeys && expandRowKeys.indexOf(key) !== -1; return !!(oldValue && oldValue.expanded || included); }; // 合并 expanded 与 display,确保数据刷新后,状态不变 keys.forEach(key => { const oldValue = oldTreeData[key]; const newValue = _objectSpread({}, nested[key]); newValue.expanded = getExpanded(oldValue, key); if (newValue.lazy) { const { loaded = false, loading = false } = oldValue || {}; newValue.loaded = !!loaded; newValue.loading = !!loading; rootLazyRowKeys.push(key); } newTreeData[key] = newValue; }); // 根据懒加载数据更新 treeData const lazyKeys = Object.keys(normalizedLazyNode); if (lazy && lazyKeys.length && rootLazyRowKeys.length) { lazyKeys.forEach(key => { const oldValue = oldTreeData[key]; const lazyNodeChildren = normalizedLazyNode[key].children; if (rootLazyRowKeys.indexOf(key) !== -1) { // 懒加载的 root 节点,更新一下原有的数据,原来的 children 一定是空数组 if (newTreeData[key].children.length !== 0) { throw new Error('[ElTable]children must be an empty array.'); } newTreeData[key].children = lazyNodeChildren; } else { const { loaded = false, loading = false } = oldValue || {}; newTreeData[key] = { lazy: true, loaded: !!loaded, loading: !!loading, expanded: getExpanded(oldValue, key), children: lazyNodeChildren, level: '' }; } }); } } this.states.treeData = newTreeData; this.updateTableScrollY(); }, updateTreeExpandKeys(value) { this.states.expandRowKeys = value; this.updateTreeData(); }, toggleTreeExpansion(row, expanded) { this.assertRowKey(); const { rowKey, treeData } = this.states; const id = Object(util["g" /* getRowIdentity */])(row, rowKey); const data = id && treeData[id]; if (id && data && 'expanded' in data) { const oldExpanded = data.expanded; expanded = typeof expanded === 'undefined' ? !data.expanded : expanded; treeData[id].expanded = expanded; if (oldExpanded !== expanded) { this.table.$emit('expand-change', row, expanded); } this.updateTableScrollY(); } }, loadOrToggle(row) { this.assertRowKey(); const { lazy, treeData, rowKey } = this.states; const id = Object(util["g" /* getRowIdentity */])(row, rowKey); const data = treeData[id]; if (lazy && data && 'loaded' in data && !data.loaded) { this.loadData(row, id, data); } else { this.toggleTreeExpansion(row); } }, loadData(row, key, treeNode) { const { load } = this.table; const { lazyTreeNodeMap, treeData } = this.states; if (load && !treeData[key].loaded) { treeData[key].loading = true; load(row, treeNode, data => { if (!Array.isArray(data)) { throw new Error('[ElTable] data must be an array'); } treeData[key].loading = false; treeData[key].loaded = true; treeData[key].expanded = true; if (data.length) { this.$set(lazyTreeNodeMap, key, data); } this.table.$emit('expand-change', row, true); }); } } } }); // CONCATENATED MODULE: ./packages/table/src/store/watcher.js const sortData = (data, states) => { if (!data) return []; const sortingColumn = states.sortingColumn; if (!sortingColumn || typeof sortingColumn.sortable === 'string') { return data; } return Object(util["i" /* orderBy */])(data, states.sortProp, states.sortOrder, sortingColumn.sortMethod, sortingColumn.sortBy); }; const doFlattenColumns = columns => { const result = []; columns.forEach(column => { if (column.children) { result.push.apply(result, doFlattenColumns(column.children)); } else { result.push(column); } }); return result; }; /* harmony default export */ var watcher = (external_vue_default.a.extend({ data() { return { states: { // 3.0 版本后要求必须设置该属性 rowKey: null, // 渲染的数据来源,是对 table 中的 data 过滤排序后的结果 data: [], // 值为空时的默认占位置 placeholder: null, // 是否包含固定列 isComplex: false, // 列 _columns: [], // 不可响应的 originColumns: [], columns: [], fixedColumns: [], rightFixedColumns: [], leafColumns: [], fixedLeafColumns: [], rightFixedLeafColumns: [], leafColumnsLength: 0, fixedLeafColumnsLength: 0, rightFixedLeafColumnsLength: 0, // 选择 isAllSelected: false, selection: [], reserveSelection: false, selectOnIndeterminate: false, selectable: null, // 过滤 filters: {}, // 不可响应的 filteredData: null, // 排序 sortingColumn: null, sortProp: null, sortOrder: null, hoverRow: null } }; }, mixins: [expand, current, tree], methods: { // 检查 rowKey 是否存在 assertRowKey() { const rowKey = this.states.rowKey; if (!rowKey) throw new Error('[ElTable] prop row-key is required'); }, // 更新列 updateColumns() { const states = this.states; const _columns = states._columns || []; states.fixedColumns = _columns.filter(column => column.fixed === true || column.fixed === 'left'); states.rightFixedColumns = _columns.filter(column => 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]); } const notFixedColumns = _columns.filter(column => !column.fixed); states.originColumns = [].concat(states.fixedColumns).concat(notFixedColumns).concat(states.rightFixedColumns); const leafColumns = doFlattenColumns(notFixedColumns); const fixedLeafColumns = doFlattenColumns(states.fixedColumns); const 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; }, // 更新 DOM scheduleLayout(needUpdateColumns) { if (needUpdateColumns) { this.updateColumns(); } this.table.debouncedUpdateLayout(); }, // 选择 isSelected(row) { const { selection = [] } = this.states; return selection.indexOf(row) > -1; }, clearSelection() { const states = this.states; states.isAllSelected = false; const oldSelection = states.selection; if (oldSelection.length) { states.selection = []; this.table.$emit('selection-change', []); } }, cleanSelection() { const states = this.states; const { data, rowKey, selection } = states; let deleted; if (rowKey) { deleted = []; const selectedMap = Object(util["f" /* getKeysMap */])(selection, rowKey); const dataMap = Object(util["f" /* getKeysMap */])(data, rowKey); for (let key in selectedMap) { if (selectedMap.hasOwnProperty(key) && !dataMap[key]) { deleted.push(selectedMap[key].row); } } } else { deleted = selection.filter(item => data.indexOf(item) === -1); } if (deleted.length) { const newSelection = selection.filter(item => deleted.indexOf(item) === -1); states.selection = newSelection; this.table.$emit('selection-change', newSelection.slice()); } }, toggleRowSelection(row, selected) { let emitChange = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; const changed = Object(util["m" /* toggleRowStatus */])(this.states.selection, row, selected); if (changed) { const newSelection = (this.states.selection || []).slice(); // 调用 API 修改选中值,不触发 select 事件 if (emitChange) { this.table.$emit('select', newSelection, row, selected); } this.table.$emit('selection-change', newSelection); } }, setSelection(rows) { this.states.sel