table-column.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 130);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 130:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. __webpack_require__.r(__webpack_exports__);
  93. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  94. var util_ = __webpack_require__(3);
  95. // CONCATENATED MODULE: ./packages/table/src/config.js
  96. var cellStarts = {
  97. default: {
  98. order: ''
  99. },
  100. selection: {
  101. width: 48,
  102. minWidth: 48,
  103. realWidth: 48,
  104. order: '',
  105. className: 'el-table-column--selection'
  106. },
  107. expand: {
  108. width: 48,
  109. minWidth: 48,
  110. realWidth: 48,
  111. order: ''
  112. },
  113. index: {
  114. width: 48,
  115. minWidth: 48,
  116. realWidth: 48,
  117. order: ''
  118. }
  119. };
  120. // 这些选项不应该被覆盖
  121. var cellForced = {
  122. selection: {
  123. renderHeader: function renderHeader(h, _ref) {
  124. var store = _ref.store;
  125. return h('el-checkbox', {
  126. attrs: {
  127. disabled: store.states.data && store.states.data.length === 0,
  128. indeterminate: store.states.selection.length > 0 && !this.isAllSelected,
  129. value: this.isAllSelected },
  130. nativeOn: {
  131. 'click': this.toggleAllSelection
  132. }
  133. });
  134. },
  135. renderCell: function renderCell(h, _ref2) {
  136. var row = _ref2.row,
  137. column = _ref2.column,
  138. store = _ref2.store,
  139. $index = _ref2.$index;
  140. return h('el-checkbox', {
  141. nativeOn: {
  142. 'click': function click(event) {
  143. return event.stopPropagation();
  144. }
  145. },
  146. attrs: {
  147. value: store.isSelected(row),
  148. disabled: column.selectable ? !column.selectable.call(null, row, $index) : false
  149. },
  150. on: {
  151. 'input': function input() {
  152. store.commit('rowSelectedChanged', row);
  153. }
  154. }
  155. });
  156. },
  157. sortable: false,
  158. resizable: false
  159. },
  160. index: {
  161. renderHeader: function renderHeader(h, _ref3) {
  162. var column = _ref3.column;
  163. return column.label || '#';
  164. },
  165. renderCell: function renderCell(h, _ref4) {
  166. var $index = _ref4.$index,
  167. column = _ref4.column;
  168. var i = $index + 1;
  169. var index = column.index;
  170. if (typeof index === 'number') {
  171. i = $index + index;
  172. } else if (typeof index === 'function') {
  173. i = index($index);
  174. }
  175. return h('div', [i]);
  176. },
  177. sortable: false
  178. },
  179. expand: {
  180. renderHeader: function renderHeader(h, _ref5) {
  181. var column = _ref5.column;
  182. return column.label || '';
  183. },
  184. renderCell: function renderCell(h, _ref6) {
  185. var row = _ref6.row,
  186. store = _ref6.store;
  187. var classes = ['el-table__expand-icon'];
  188. if (store.states.expandRows.indexOf(row) > -1) {
  189. classes.push('el-table__expand-icon--expanded');
  190. }
  191. var callback = function callback(e) {
  192. e.stopPropagation();
  193. store.toggleRowExpansion(row);
  194. };
  195. return h(
  196. 'div',
  197. { 'class': classes,
  198. on: {
  199. 'click': callback
  200. }
  201. },
  202. [h('i', { 'class': 'el-icon el-icon-arrow-right' })]
  203. );
  204. },
  205. sortable: false,
  206. resizable: false,
  207. className: 'el-table__expand-column'
  208. }
  209. };
  210. function defaultRenderCell(h, _ref7) {
  211. var row = _ref7.row,
  212. column = _ref7.column,
  213. $index = _ref7.$index;
  214. var property = column.property;
  215. var value = property && Object(util_["getPropByPath"])(row, property).v;
  216. if (column && column.formatter) {
  217. return column.formatter(row, column, value, $index);
  218. }
  219. return value;
  220. }
  221. function treeCellPrefix(h, _ref8) {
  222. var row = _ref8.row,
  223. treeNode = _ref8.treeNode,
  224. store = _ref8.store;
  225. if (!treeNode) return null;
  226. var ele = [];
  227. var callback = function callback(e) {
  228. e.stopPropagation();
  229. store.loadOrToggle(row);
  230. };
  231. if (treeNode.indent) {
  232. ele.push(h('span', { 'class': 'el-table__indent', style: { 'padding-left': treeNode.indent + 'px' } }));
  233. }
  234. if (typeof treeNode.expanded === 'boolean' && !treeNode.noLazyChildren) {
  235. var expandClasses = ['el-table__expand-icon', treeNode.expanded ? 'el-table__expand-icon--expanded' : ''];
  236. var iconClasses = ['el-icon-arrow-right'];
  237. if (treeNode.loading) {
  238. iconClasses = ['el-icon-loading'];
  239. }
  240. ele.push(h(
  241. 'div',
  242. { 'class': expandClasses,
  243. on: {
  244. 'click': callback
  245. }
  246. },
  247. [h('i', { 'class': iconClasses })]
  248. ));
  249. } else {
  250. ele.push(h('span', { 'class': 'el-table__placeholder' }));
  251. }
  252. return ele;
  253. }
  254. // EXTERNAL MODULE: ./packages/table/src/util.js
  255. var util = __webpack_require__(8);
  256. // EXTERNAL MODULE: external "element-ui/lib/checkbox"
  257. var checkbox_ = __webpack_require__(18);
  258. var checkbox_default = /*#__PURE__*/__webpack_require__.n(checkbox_);
  259. // CONCATENATED MODULE: ./packages/table/src/table-column.js
  260. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  261. var columnIdSeed = 1;
  262. /* harmony default export */ var table_column = ({
  263. name: 'ElTableColumn',
  264. props: {
  265. type: {
  266. type: String,
  267. default: 'default'
  268. },
  269. label: String,
  270. className: String,
  271. labelClassName: String,
  272. property: String,
  273. prop: String,
  274. width: {},
  275. minWidth: {},
  276. renderHeader: Function,
  277. sortable: {
  278. type: [Boolean, String],
  279. default: false
  280. },
  281. sortMethod: Function,
  282. sortBy: [String, Function, Array],
  283. resizable: {
  284. type: Boolean,
  285. default: true
  286. },
  287. columnKey: String,
  288. align: String,
  289. headerAlign: String,
  290. showTooltipWhenOverflow: Boolean,
  291. showOverflowTooltip: Boolean,
  292. fixed: [Boolean, String],
  293. formatter: Function,
  294. selectable: Function,
  295. reserveSelection: Boolean,
  296. filterMethod: Function,
  297. filteredValue: Array,
  298. filters: Array,
  299. filterPlacement: String,
  300. filterMultiple: {
  301. type: Boolean,
  302. default: true
  303. },
  304. index: [Number, Function],
  305. sortOrders: {
  306. type: Array,
  307. default: function _default() {
  308. return ['ascending', 'descending', null];
  309. },
  310. validator: function validator(val) {
  311. return val.every(function (order) {
  312. return ['ascending', 'descending', null].indexOf(order) > -1;
  313. });
  314. }
  315. }
  316. },
  317. data: function data() {
  318. return {
  319. isSubColumn: false,
  320. columns: []
  321. };
  322. },
  323. computed: {
  324. owner: function owner() {
  325. var parent = this.$parent;
  326. while (parent && !parent.tableId) {
  327. parent = parent.$parent;
  328. }
  329. return parent;
  330. },
  331. columnOrTableParent: function columnOrTableParent() {
  332. var parent = this.$parent;
  333. while (parent && !parent.tableId && !parent.columnId) {
  334. parent = parent.$parent;
  335. }
  336. return parent;
  337. },
  338. realWidth: function realWidth() {
  339. return Object(util["l" /* parseWidth */])(this.width);
  340. },
  341. realMinWidth: function realMinWidth() {
  342. return Object(util["k" /* parseMinWidth */])(this.minWidth);
  343. },
  344. realAlign: function realAlign() {
  345. return this.align ? 'is-' + this.align : null;
  346. },
  347. realHeaderAlign: function realHeaderAlign() {
  348. return this.headerAlign ? 'is-' + this.headerAlign : this.realAlign;
  349. }
  350. },
  351. methods: {
  352. getPropsData: function getPropsData() {
  353. var _this = this;
  354. for (var _len = arguments.length, props = Array(_len), _key = 0; _key < _len; _key++) {
  355. props[_key] = arguments[_key];
  356. }
  357. return props.reduce(function (prev, cur) {
  358. if (Array.isArray(cur)) {
  359. cur.forEach(function (key) {
  360. prev[key] = _this[key];
  361. });
  362. }
  363. return prev;
  364. }, {});
  365. },
  366. getColumnElIndex: function getColumnElIndex(children, child) {
  367. return [].indexOf.call(children, child);
  368. },
  369. setColumnWidth: function setColumnWidth(column) {
  370. if (this.realWidth) {
  371. column.width = this.realWidth;
  372. }
  373. if (this.realMinWidth) {
  374. column.minWidth = this.realMinWidth;
  375. }
  376. if (!column.minWidth) {
  377. column.minWidth = 80;
  378. }
  379. column.realWidth = column.width === undefined ? column.minWidth : column.width;
  380. return column;
  381. },
  382. setColumnForcedProps: function setColumnForcedProps(column) {
  383. // 对于特定类型的 column,某些属性不允许设置
  384. var type = column.type;
  385. var source = cellForced[type] || {};
  386. Object.keys(source).forEach(function (prop) {
  387. var value = source[prop];
  388. if (value !== undefined) {
  389. column[prop] = prop === 'className' ? column[prop] + ' ' + value : value;
  390. }
  391. });
  392. return column;
  393. },
  394. setColumnRenders: function setColumnRenders(column) {
  395. var _this2 = this;
  396. var h = this.$createElement;
  397. // renderHeader 属性不推荐使用。
  398. if (this.renderHeader) {
  399. console.warn('[Element Warn][TableColumn]Comparing to render-header, scoped-slot header is easier to use. We recommend users to use scoped-slot header.');
  400. } else if (column.type !== 'selection') {
  401. column.renderHeader = function (h, scope) {
  402. var renderHeader = _this2.$scopedSlots.header;
  403. return renderHeader ? renderHeader(scope) : column.label;
  404. };
  405. }
  406. var originRenderCell = column.renderCell;
  407. // TODO: 这里的实现调整
  408. if (column.type === 'expand') {
  409. // 对于展开行,renderCell 不允许配置的。在上一步中已经设置过,这里需要简单封装一下。
  410. column.renderCell = function (h, data) {
  411. return h(
  412. 'div',
  413. { 'class': 'cell' },
  414. [originRenderCell(h, data)]
  415. );
  416. };
  417. this.owner.renderExpanded = function (h, data) {
  418. return _this2.$scopedSlots.default ? _this2.$scopedSlots.default(data) : _this2.$slots.default;
  419. };
  420. } else {
  421. originRenderCell = originRenderCell || defaultRenderCell;
  422. // 对 renderCell 进行包装
  423. column.renderCell = function (h, data) {
  424. var children = null;
  425. if (_this2.$scopedSlots.default) {
  426. children = _this2.$scopedSlots.default(data);
  427. } else {
  428. children = originRenderCell(h, data);
  429. }
  430. var prefix = treeCellPrefix(h, data);
  431. var props = {
  432. class: 'cell',
  433. style: {}
  434. };
  435. if (column.showOverflowTooltip) {
  436. props.class += ' el-tooltip';
  437. props.style = { width: (data.column.realWidth || data.column.width) - 1 + 'px' };
  438. }
  439. return h(
  440. 'div',
  441. props,
  442. [prefix, children]
  443. );
  444. };
  445. }
  446. return column;
  447. },
  448. registerNormalWatchers: function registerNormalWatchers() {
  449. var _this3 = this;
  450. var props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip'];
  451. // 一些属性具有别名
  452. var aliases = {
  453. prop: 'property',
  454. realAlign: 'align',
  455. realHeaderAlign: 'headerAlign',
  456. realWidth: 'width'
  457. };
  458. var allAliases = props.reduce(function (prev, cur) {
  459. prev[cur] = cur;
  460. return prev;
  461. }, aliases);
  462. Object.keys(allAliases).forEach(function (key) {
  463. var columnKey = aliases[key];
  464. _this3.$watch(key, function (newVal) {
  465. _this3.columnConfig[columnKey] = newVal;
  466. });
  467. });
  468. },
  469. registerComplexWatchers: function registerComplexWatchers() {
  470. var _this4 = this;
  471. var props = ['fixed'];
  472. var aliases = {
  473. realWidth: 'width',
  474. realMinWidth: 'minWidth'
  475. };
  476. var allAliases = props.reduce(function (prev, cur) {
  477. prev[cur] = cur;
  478. return prev;
  479. }, aliases);
  480. Object.keys(allAliases).forEach(function (key) {
  481. var columnKey = aliases[key];
  482. _this4.$watch(key, function (newVal) {
  483. _this4.columnConfig[columnKey] = newVal;
  484. var updateColumns = columnKey === 'fixed';
  485. _this4.owner.store.scheduleLayout(updateColumns);
  486. });
  487. });
  488. }
  489. },
  490. components: {
  491. ElCheckbox: checkbox_default.a
  492. },
  493. beforeCreate: function beforeCreate() {
  494. this.row = {};
  495. this.column = {};
  496. this.$index = 0;
  497. this.columnId = '';
  498. },
  499. created: function created() {
  500. var parent = this.columnOrTableParent;
  501. this.isSubColumn = this.owner !== parent;
  502. this.columnId = (parent.tableId || parent.columnId) + '_column_' + columnIdSeed++;
  503. var type = this.type || 'default';
  504. var sortable = this.sortable === '' ? true : this.sortable;
  505. var defaults = _extends({}, cellStarts[type], {
  506. id: this.columnId,
  507. type: type,
  508. property: this.prop || this.property,
  509. align: this.realAlign,
  510. headerAlign: this.realHeaderAlign,
  511. showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
  512. // filter 相关属性
  513. filterable: this.filters || this.filterMethod,
  514. filteredValue: [],
  515. filterPlacement: '',
  516. isColumnGroup: false,
  517. filterOpened: false,
  518. // sort 相关属性
  519. sortable: sortable,
  520. // index 列
  521. index: this.index
  522. });
  523. var basicProps = ['columnKey', 'label', 'className', 'labelClassName', 'type', 'renderHeader', 'formatter', 'fixed', 'resizable'];
  524. var sortProps = ['sortMethod', 'sortBy', 'sortOrders'];
  525. var selectProps = ['selectable', 'reserveSelection'];
  526. var filterProps = ['filterMethod', 'filters', 'filterMultiple', 'filterOpened', 'filteredValue', 'filterPlacement'];
  527. var column = this.getPropsData(basicProps, sortProps, selectProps, filterProps);
  528. column = Object(util["h" /* mergeOptions */])(defaults, column);
  529. // 注意 compose 中函数执行的顺序是从右到左
  530. var chains = Object(util["a" /* compose */])(this.setColumnRenders, this.setColumnWidth, this.setColumnForcedProps);
  531. column = chains(column);
  532. this.columnConfig = column;
  533. // 注册 watcher
  534. this.registerNormalWatchers();
  535. this.registerComplexWatchers();
  536. },
  537. mounted: function mounted() {
  538. var owner = this.owner;
  539. var parent = this.columnOrTableParent;
  540. var children = this.isSubColumn ? parent.$el.children : parent.$refs.hiddenColumns.children;
  541. var columnIndex = this.getColumnElIndex(children, this.$el);
  542. owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
  543. },
  544. destroyed: function destroyed() {
  545. if (!this.$parent) return;
  546. var parent = this.$parent;
  547. this.owner.store.commit('removeColumn', this.columnConfig, this.isSubColumn ? parent.columnConfig : null);
  548. },
  549. render: function render(h) {
  550. // slots 也要渲染,需要计算合并表头
  551. return h('div', this.$slots.default);
  552. }
  553. });
  554. // CONCATENATED MODULE: ./packages/table-column/index.js
  555. /* istanbul ignore next */
  556. table_column.install = function (Vue) {
  557. Vue.component(table_column.name, table_column);
  558. };
  559. /* harmony default export */ var packages_table_column = __webpack_exports__["default"] = (table_column);
  560. /***/ }),
  561. /***/ 18:
  562. /***/ (function(module, exports) {
  563. module.exports = require("element-ui/lib/checkbox");
  564. /***/ }),
  565. /***/ 3:
  566. /***/ (function(module, exports) {
  567. module.exports = require("element-ui/lib/utils/util");
  568. /***/ }),
  569. /***/ 8:
  570. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  571. "use strict";
  572. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return getCell; });
  573. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "i", function() { return orderBy; });
  574. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return getColumnById; });
  575. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return getColumnByKey; });
  576. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return getColumnByCell; });
  577. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return getRowIdentity; });
  578. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return getKeysMap; });
  579. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return mergeOptions; });
  580. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "l", function() { return parseWidth; });
  581. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "k", function() { return parseMinWidth; });
  582. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "j", function() { return parseHeight; });
  583. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return compose; });
  584. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "m", function() { return toggleRowStatus; });
  585. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "n", function() { return walkTreeNode; });
  586. /* harmony import */ var element_ui_src_utils_util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
  587. /* harmony import */ var element_ui_src_utils_util__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(element_ui_src_utils_util__WEBPACK_IMPORTED_MODULE_0__);
  588. 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; };
  589. var getCell = function getCell(event) {
  590. var cell = event.target;
  591. while (cell && cell.tagName.toUpperCase() !== 'HTML') {
  592. if (cell.tagName.toUpperCase() === 'TD') {
  593. return cell;
  594. }
  595. cell = cell.parentNode;
  596. }
  597. return null;
  598. };
  599. var isObject = function isObject(obj) {
  600. return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
  601. };
  602. var orderBy = function orderBy(array, sortKey, reverse, sortMethod, sortBy) {
  603. if (!sortKey && !sortMethod && (!sortBy || Array.isArray(sortBy) && !sortBy.length)) {
  604. return array;
  605. }
  606. if (typeof reverse === 'string') {
  607. reverse = reverse === 'descending' ? -1 : 1;
  608. } else {
  609. reverse = reverse && reverse < 0 ? -1 : 1;
  610. }
  611. var getKey = sortMethod ? null : function (value, index) {
  612. if (sortBy) {
  613. if (!Array.isArray(sortBy)) {
  614. sortBy = [sortBy];
  615. }
  616. return sortBy.map(function (by) {
  617. if (typeof by === 'string') {
  618. return Object(element_ui_src_utils_util__WEBPACK_IMPORTED_MODULE_0__["getValueByPath"])(value, by);
  619. } else {
  620. return by(value, index, array);
  621. }
  622. });
  623. }
  624. if (sortKey !== '$key') {
  625. if (isObject(value) && '$value' in value) value = value.$value;
  626. }
  627. return [isObject(value) ? Object(element_ui_src_utils_util__WEBPACK_IMPORTED_MODULE_0__["getValueByPath"])(value, sortKey) : value];
  628. };
  629. var compare = function compare(a, b) {
  630. if (sortMethod) {
  631. return sortMethod(a.value, b.value);
  632. }
  633. for (var i = 0, len = a.key.length; i < len; i++) {
  634. if (a.key[i] < b.key[i]) {
  635. return -1;
  636. }
  637. if (a.key[i] > b.key[i]) {
  638. return 1;
  639. }
  640. }
  641. return 0;
  642. };
  643. return array.map(function (value, index) {
  644. return {
  645. value: value,
  646. index: index,
  647. key: getKey ? getKey(value, index) : null
  648. };
  649. }).sort(function (a, b) {
  650. var order = compare(a, b);
  651. if (!order) {
  652. // make stable https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
  653. order = a.index - b.index;
  654. }
  655. return order * reverse;
  656. }).map(function (item) {
  657. return item.value;
  658. });
  659. };
  660. var getColumnById = function getColumnById(table, columnId) {
  661. var column = null;
  662. table.columns.forEach(function (item) {
  663. if (item.id === columnId) {
  664. column = item;
  665. }
  666. });
  667. return column;
  668. };
  669. var getColumnByKey = function getColumnByKey(table, columnKey) {
  670. var column = null;
  671. for (var i = 0; i < table.columns.length; i++) {
  672. var item = table.columns[i];
  673. if (item.columnKey === columnKey) {
  674. column = item;
  675. break;
  676. }
  677. }
  678. return column;
  679. };
  680. var getColumnByCell = function getColumnByCell(table, cell) {
  681. var matches = (cell.className || '').match(/el-table_[^\s]+/gm);
  682. if (matches) {
  683. return getColumnById(table, matches[0]);
  684. }
  685. return null;
  686. };
  687. var getRowIdentity = function getRowIdentity(row, rowKey) {
  688. if (!row) throw new Error('row is required when get row identity');
  689. if (typeof rowKey === 'string') {
  690. if (rowKey.indexOf('.') < 0) {
  691. return row[rowKey];
  692. }
  693. var key = rowKey.split('.');
  694. var current = row;
  695. for (var i = 0; i < key.length; i++) {
  696. current = current[key[i]];
  697. }
  698. return current;
  699. } else if (typeof rowKey === 'function') {
  700. return rowKey.call(null, row);
  701. }
  702. };
  703. var getKeysMap = function getKeysMap(array, rowKey) {
  704. var arrayMap = {};
  705. (array || []).forEach(function (row, index) {
  706. arrayMap[getRowIdentity(row, rowKey)] = { row: row, index: index };
  707. });
  708. return arrayMap;
  709. };
  710. function hasOwn(obj, key) {
  711. return Object.prototype.hasOwnProperty.call(obj, key);
  712. }
  713. function mergeOptions(defaults, config) {
  714. var options = {};
  715. var key = void 0;
  716. for (key in defaults) {
  717. options[key] = defaults[key];
  718. }
  719. for (key in config) {
  720. if (hasOwn(config, key)) {
  721. var value = config[key];
  722. if (typeof value !== 'undefined') {
  723. options[key] = value;
  724. }
  725. }
  726. }
  727. return options;
  728. }
  729. function parseWidth(width) {
  730. if (width !== undefined) {
  731. width = parseInt(width, 10);
  732. if (isNaN(width)) {
  733. width = null;
  734. }
  735. }
  736. return width;
  737. }
  738. function parseMinWidth(minWidth) {
  739. if (typeof minWidth !== 'undefined') {
  740. minWidth = parseWidth(minWidth);
  741. if (isNaN(minWidth)) {
  742. minWidth = 80;
  743. }
  744. }
  745. return minWidth;
  746. };
  747. function parseHeight(height) {
  748. if (typeof height === 'number') {
  749. return height;
  750. }
  751. if (typeof height === 'string') {
  752. if (/^\d+(?:px)?$/.test(height)) {
  753. return parseInt(height, 10);
  754. } else {
  755. return height;
  756. }
  757. }
  758. return null;
  759. }
  760. // https://github.com/reduxjs/redux/blob/master/src/compose.js
  761. function compose() {
  762. for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
  763. funcs[_key] = arguments[_key];
  764. }
  765. if (funcs.length === 0) {
  766. return function (arg) {
  767. return arg;
  768. };
  769. }
  770. if (funcs.length === 1) {
  771. return funcs[0];
  772. }
  773. return funcs.reduce(function (a, b) {
  774. return function () {
  775. return a(b.apply(undefined, arguments));
  776. };
  777. });
  778. }
  779. function toggleRowStatus(statusArr, row, newVal) {
  780. var changed = false;
  781. var index = statusArr.indexOf(row);
  782. var included = index !== -1;
  783. var addRow = function addRow() {
  784. statusArr.push(row);
  785. changed = true;
  786. };
  787. var removeRow = function removeRow() {
  788. statusArr.splice(index, 1);
  789. changed = true;
  790. };
  791. if (typeof newVal === 'boolean') {
  792. if (newVal && !included) {
  793. addRow();
  794. } else if (!newVal && included) {
  795. removeRow();
  796. }
  797. } else {
  798. if (included) {
  799. removeRow();
  800. } else {
  801. addRow();
  802. }
  803. }
  804. return changed;
  805. }
  806. function walkTreeNode(root, cb) {
  807. var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
  808. var lazyKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'hasChildren';
  809. var isNil = function isNil(array) {
  810. return !(Array.isArray(array) && array.length);
  811. };
  812. function _walker(parent, children, level) {
  813. cb(parent, children, level);
  814. children.forEach(function (item) {
  815. if (item[lazyKey]) {
  816. cb(item, null, level + 1);
  817. return;
  818. }
  819. var children = item[childrenKey];
  820. if (!isNil(children)) {
  821. _walker(item, children, level + 1);
  822. }
  823. });
  824. }
  825. root.forEach(function (item) {
  826. if (item[lazyKey]) {
  827. cb(item, null, 0);
  828. return;
  829. }
  830. var children = item[childrenKey];
  831. if (!isNil(children)) {
  832. _walker(item, children, 0);
  833. }
  834. });
  835. }
  836. /***/ })
  837. /******/ });