table-column.js 27 KB

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