table-column.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(316);
  37. /***/ },
  38. /***/ 164:
  39. /***/ function(module, exports) {
  40. module.exports = require("element-ui/lib/utils/merge");
  41. /***/ },
  42. /***/ 266:
  43. /***/ function(module, exports) {
  44. module.exports = require("element-ui/lib/tag");
  45. /***/ },
  46. /***/ 304:
  47. /***/ function(module, exports) {
  48. module.exports = require("element-ui/lib/checkbox");
  49. /***/ },
  50. /***/ 306:
  51. /***/ function(module, exports) {
  52. 'use strict';
  53. exports.__esModule = true;
  54. 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; };
  55. var getCell = exports.getCell = function getCell(event) {
  56. var cell = event.target;
  57. while (cell && cell.tagName.toUpperCase() !== 'HTML') {
  58. if (cell.tagName.toUpperCase() === 'TD') {
  59. return cell;
  60. }
  61. cell = cell.parentNode;
  62. }
  63. return null;
  64. };
  65. var getValueByPath = exports.getValueByPath = function getValueByPath(object, prop) {
  66. prop = prop || '';
  67. var paths = prop.split('.');
  68. var current = object;
  69. var result = null;
  70. for (var i = 0, j = paths.length; i < j; i++) {
  71. var path = paths[i];
  72. if (!current) break;
  73. if (i === j - 1) {
  74. result = current[path];
  75. break;
  76. }
  77. current = current[path];
  78. }
  79. return result;
  80. };
  81. var isObject = function isObject(obj) {
  82. return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
  83. };
  84. var orderBy = exports.orderBy = function orderBy(array, sortKey, reverse, sortMethod) {
  85. if (typeof reverse === 'string') {
  86. reverse = reverse === 'descending' ? -1 : 1;
  87. }
  88. if (!sortKey) {
  89. return array;
  90. }
  91. var order = reverse && reverse < 0 ? -1 : 1;
  92. // sort on a copy to avoid mutating original array
  93. return array.slice().sort(sortMethod ? function (a, b) {
  94. return sortMethod(a, b) ? order : -order;
  95. } : function (a, b) {
  96. if (sortKey !== '$key') {
  97. if (isObject(a) && '$value' in a) a = a.$value;
  98. if (isObject(b) && '$value' in b) b = b.$value;
  99. }
  100. a = isObject(a) ? getValueByPath(a, sortKey) : a;
  101. b = isObject(b) ? getValueByPath(b, sortKey) : b;
  102. return a === b ? 0 : a > b ? order : -order;
  103. });
  104. };
  105. var getColumnById = exports.getColumnById = function getColumnById(table, columnId) {
  106. var column = null;
  107. table.columns.forEach(function (item) {
  108. if (item.id === columnId) {
  109. column = item;
  110. }
  111. });
  112. return column;
  113. };
  114. var getColumnByCell = exports.getColumnByCell = function getColumnByCell(table, cell) {
  115. var matches = (cell.className || '').match(/el-table_[^\s]+/gm);
  116. if (matches) {
  117. return getColumnById(table, matches[0]);
  118. }
  119. return null;
  120. };
  121. var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  122. var mousewheel = exports.mousewheel = function mousewheel(element, callback) {
  123. if (element && element.addEventListener) {
  124. element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
  125. }
  126. };
  127. var getRowIdentity = exports.getRowIdentity = function getRowIdentity(row, rowKey) {
  128. if (!row) throw new Error('row is required when get row identity');
  129. if (typeof rowKey === 'string') {
  130. return row[rowKey];
  131. } else if (typeof rowKey === 'function') {
  132. return rowKey.call(null, row);
  133. }
  134. };
  135. /***/ },
  136. /***/ 316:
  137. /***/ function(module, exports, __webpack_require__) {
  138. 'use strict';
  139. exports.__esModule = true;
  140. var _tableColumn = __webpack_require__(317);
  141. var _tableColumn2 = _interopRequireDefault(_tableColumn);
  142. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  143. /* istanbul ignore next */
  144. _tableColumn2.default.install = function (Vue) {
  145. Vue.component(_tableColumn2.default.name, _tableColumn2.default);
  146. };
  147. exports.default = _tableColumn2.default;
  148. /***/ },
  149. /***/ 317:
  150. /***/ function(module, exports, __webpack_require__) {
  151. 'use strict';
  152. exports.__esModule = true;
  153. var _checkbox = __webpack_require__(304);
  154. var _checkbox2 = _interopRequireDefault(_checkbox);
  155. var _tag = __webpack_require__(266);
  156. var _tag2 = _interopRequireDefault(_tag);
  157. var _merge = __webpack_require__(164);
  158. var _merge2 = _interopRequireDefault(_merge);
  159. var _util = __webpack_require__(306);
  160. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  161. function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure undefined"); }
  162. var columnIdSeed = 1;
  163. var defaults = {
  164. default: {
  165. order: ''
  166. },
  167. selection: {
  168. width: 48,
  169. minWidth: 48,
  170. realWidth: 48,
  171. order: '',
  172. className: 'el-table-column--selection'
  173. },
  174. expand: {
  175. width: 48,
  176. minWidth: 48,
  177. realWidth: 48,
  178. order: ''
  179. },
  180. index: {
  181. width: 48,
  182. minWidth: 48,
  183. realWidth: 48,
  184. order: ''
  185. }
  186. };
  187. var forced = {
  188. selection: {
  189. renderHeader: function renderHeader(h) {
  190. return h(
  191. 'el-checkbox',
  192. {
  193. nativeOn: {
  194. 'click': this.toggleAllSelection
  195. },
  196. domProps: {
  197. 'value': this.isAllSelected
  198. }
  199. },
  200. []
  201. );
  202. },
  203. renderCell: function renderCell(h, _ref) {
  204. var row = _ref.row,
  205. column = _ref.column,
  206. store = _ref.store,
  207. $index = _ref.$index;
  208. return h(
  209. 'el-checkbox',
  210. {
  211. domProps: {
  212. 'value': store.isSelected(row)
  213. },
  214. attrs: {
  215. disabled: column.selectable ? !column.selectable.call(null, row, $index) : false
  216. },
  217. on: {
  218. 'input': function input() {
  219. store.commit('rowSelectedChanged', row);
  220. }
  221. }
  222. },
  223. []
  224. );
  225. },
  226. sortable: false,
  227. resizable: false
  228. },
  229. index: {
  230. renderHeader: function renderHeader(h, _ref2) {
  231. var column = _ref2.column;
  232. return column.label || '#';
  233. },
  234. renderCell: function renderCell(h, _ref3) {
  235. var $index = _ref3.$index;
  236. return h(
  237. 'div',
  238. null,
  239. [$index + 1]
  240. );
  241. },
  242. sortable: false
  243. },
  244. expand: {
  245. renderHeader: function renderHeader(h, _ref4) {
  246. _objectDestructuringEmpty(_ref4);
  247. return '';
  248. },
  249. renderCell: function renderCell(h, _ref5, proxy) {
  250. var row = _ref5.row,
  251. store = _ref5.store;
  252. var expanded = store.states.expandRows.indexOf(row) > -1;
  253. return h(
  254. 'div',
  255. { 'class': 'el-table__expand-icon ' + (expanded ? 'el-table__expand-icon--expanded' : ''),
  256. on: {
  257. 'click': function click() {
  258. return proxy.handleExpandClick(row);
  259. }
  260. }
  261. },
  262. [h(
  263. 'i',
  264. { 'class': 'el-icon el-icon-arrow-right' },
  265. []
  266. )]
  267. );
  268. },
  269. sortable: false,
  270. resizable: false,
  271. className: 'el-table__expand-column'
  272. }
  273. };
  274. var getDefaultColumn = function getDefaultColumn(type, options) {
  275. var column = {};
  276. (0, _merge2.default)(column, defaults[type || 'default']);
  277. for (var name in options) {
  278. if (options.hasOwnProperty(name)) {
  279. var value = options[name];
  280. if (typeof value !== 'undefined') {
  281. column[name] = value;
  282. }
  283. }
  284. }
  285. if (!column.minWidth) {
  286. column.minWidth = 80;
  287. }
  288. column.realWidth = column.width || column.minWidth;
  289. return column;
  290. };
  291. var DEFAULT_RENDER_CELL = function DEFAULT_RENDER_CELL(h, _ref6) {
  292. var row = _ref6.row,
  293. column = _ref6.column;
  294. var property = column.property;
  295. if (column && column.formatter) {
  296. return column.formatter(row, column);
  297. }
  298. if (property && property.indexOf('.') === -1) {
  299. return row[property];
  300. }
  301. return (0, _util.getValueByPath)(row, property);
  302. };
  303. exports.default = {
  304. name: 'ElTableColumn',
  305. props: {
  306. type: {
  307. type: String,
  308. default: 'default'
  309. },
  310. label: String,
  311. className: String,
  312. labelClassName: String,
  313. property: String,
  314. prop: String,
  315. width: {},
  316. minWidth: {},
  317. renderHeader: Function,
  318. sortable: {
  319. type: [String, Boolean],
  320. default: false
  321. },
  322. sortMethod: Function,
  323. resizable: {
  324. type: Boolean,
  325. default: true
  326. },
  327. context: {},
  328. columnKey: String,
  329. align: String,
  330. headerAlign: String,
  331. showTooltipWhenOverflow: Boolean,
  332. showOverflowTooltip: Boolean,
  333. fixed: [Boolean, String],
  334. formatter: Function,
  335. selectable: Function,
  336. reserveSelection: Boolean,
  337. filterMethod: Function,
  338. filteredValue: Array,
  339. filters: Array,
  340. filterMultiple: {
  341. type: Boolean,
  342. default: true
  343. }
  344. },
  345. data: function data() {
  346. return {
  347. isSubColumn: false,
  348. columns: []
  349. };
  350. },
  351. beforeCreate: function beforeCreate() {
  352. this.row = {};
  353. this.column = {};
  354. this.$index = 0;
  355. },
  356. components: {
  357. ElCheckbox: _checkbox2.default,
  358. ElTag: _tag2.default
  359. },
  360. computed: {
  361. owner: function owner() {
  362. var parent = this.$parent;
  363. while (parent && !parent.tableId) {
  364. parent = parent.$parent;
  365. }
  366. return parent;
  367. }
  368. },
  369. created: function created() {
  370. var _this = this;
  371. this.customRender = this.$options.render;
  372. this.$options.render = function (h) {
  373. return h('div', _this.$slots.default);
  374. };
  375. this.columnId = (this.$parent.tableId || this.$parent.columnId + '_') + 'column_' + columnIdSeed++;
  376. var parent = this.$parent;
  377. var owner = this.owner;
  378. this.isSubColumn = owner !== parent;
  379. var type = this.type;
  380. var width = this.width;
  381. if (width !== undefined) {
  382. width = parseInt(width, 10);
  383. if (isNaN(width)) {
  384. width = null;
  385. }
  386. }
  387. var minWidth = this.minWidth;
  388. if (minWidth !== undefined) {
  389. minWidth = parseInt(minWidth, 10);
  390. if (isNaN(minWidth)) {
  391. minWidth = 80;
  392. }
  393. }
  394. var isColumnGroup = false;
  395. var column = getDefaultColumn(type, {
  396. id: this.columnId,
  397. columnKey: this.columnKey,
  398. label: this.label,
  399. className: this.className,
  400. labelClassName: this.labelClassName,
  401. property: this.prop || this.property,
  402. type: type,
  403. renderCell: null,
  404. renderHeader: this.renderHeader,
  405. minWidth: minWidth,
  406. width: width,
  407. isColumnGroup: isColumnGroup,
  408. context: this.context,
  409. align: this.align ? 'is-' + this.align : null,
  410. headerAlign: this.headerAlign ? 'is-' + this.headerAlign : this.align ? 'is-' + this.align : null,
  411. sortable: this.sortable === '' ? true : this.sortable,
  412. sortMethod: this.sortMethod,
  413. resizable: this.resizable,
  414. showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
  415. formatter: this.formatter,
  416. selectable: this.selectable,
  417. reserveSelection: this.reserveSelection,
  418. fixed: this.fixed === '' ? true : this.fixed,
  419. filterMethod: this.filterMethod,
  420. filters: this.filters,
  421. filterable: this.filters || this.filterMethod,
  422. filterMultiple: this.filterMultiple,
  423. filterOpened: false,
  424. filteredValue: this.filteredValue || []
  425. });
  426. (0, _merge2.default)(column, forced[type] || {});
  427. this.columnConfig = column;
  428. var renderCell = column.renderCell;
  429. var _self = this;
  430. if (type === 'expand') {
  431. owner.renderExpanded = function (h, data) {
  432. return _self.$scopedSlots.default ? _self.$scopedSlots.default(data) : _self.$slots.default;
  433. };
  434. column.renderCell = function (h, data) {
  435. return h(
  436. 'div',
  437. { 'class': 'cell' },
  438. [renderCell(h, data, this._renderProxy)]
  439. );
  440. };
  441. return;
  442. }
  443. column.renderCell = function (h, data) {
  444. // 未来版本移除
  445. if (_self.$vnode.data.inlineTemplate) {
  446. renderCell = function renderCell() {
  447. data._self = _self.context || data._self;
  448. if (Object.prototype.toString.call(data._self) === '[object Object]') {
  449. for (var prop in data._self) {
  450. if (!data.hasOwnProperty(prop)) {
  451. data[prop] = data._self[prop];
  452. }
  453. }
  454. }
  455. // 静态内容会缓存到 _staticTrees 内,不改的话获取的静态数据就不是内部 context
  456. data._staticTrees = _self._staticTrees;
  457. data.$options.staticRenderFns = _self.$options.staticRenderFns;
  458. return _self.customRender.call(data);
  459. };
  460. } else if (_self.$scopedSlots.default) {
  461. renderCell = function renderCell() {
  462. return _self.$scopedSlots.default(data);
  463. };
  464. }
  465. if (!renderCell) {
  466. renderCell = DEFAULT_RENDER_CELL;
  467. }
  468. return _self.showOverflowTooltip || _self.showTooltipWhenOverflow ? h(
  469. 'div',
  470. { 'class': 'cell el-tooltip' },
  471. [renderCell(h, data)]
  472. ) : h(
  473. 'div',
  474. { 'class': 'cell' },
  475. [renderCell(h, data)]
  476. );
  477. };
  478. },
  479. destroyed: function destroyed() {
  480. if (!this.$parent) return;
  481. this.owner.store.commit('removeColumn', this.columnConfig);
  482. },
  483. watch: {
  484. label: function label(newVal) {
  485. if (this.columnConfig) {
  486. this.columnConfig.label = newVal;
  487. }
  488. },
  489. prop: function prop(newVal) {
  490. if (this.columnConfig) {
  491. this.columnConfig.property = newVal;
  492. }
  493. },
  494. property: function property(newVal) {
  495. if (this.columnConfig) {
  496. this.columnConfig.property = newVal;
  497. }
  498. },
  499. filters: function filters(newVal) {
  500. if (this.columnConfig) {
  501. this.columnConfig.filters = newVal;
  502. }
  503. },
  504. filterMultiple: function filterMultiple(newVal) {
  505. if (this.columnConfig) {
  506. this.columnConfig.filterMultiple = newVal;
  507. }
  508. },
  509. align: function align(newVal) {
  510. if (this.columnConfig) {
  511. this.columnConfig.align = newVal ? 'is-' + newVal : null;
  512. if (!this.headerAlign) {
  513. this.columnConfig.headerAlign = newVal ? 'is-' + newVal : null;
  514. }
  515. }
  516. },
  517. headerAlign: function headerAlign(newVal) {
  518. if (this.columnConfig) {
  519. this.columnConfig.headerAlign = 'is-' + (newVal ? newVal : this.align);
  520. }
  521. },
  522. width: function width(newVal) {
  523. if (this.columnConfig) {
  524. this.columnConfig.width = newVal;
  525. this.owner.store.scheduleLayout();
  526. }
  527. },
  528. minWidth: function minWidth(newVal) {
  529. if (this.columnConfig) {
  530. this.columnConfig.minWidth = newVal;
  531. this.owner.store.scheduleLayout();
  532. }
  533. },
  534. fixed: function fixed(newVal) {
  535. if (this.columnConfig) {
  536. this.columnConfig.fixed = newVal;
  537. this.owner.store.scheduleLayout();
  538. }
  539. }
  540. },
  541. mounted: function mounted() {
  542. var owner = this.owner;
  543. var parent = this.$parent;
  544. var columnIndex = void 0;
  545. if (!this.isSubColumn) {
  546. columnIndex = [].indexOf.call(parent.$refs.hiddenColumns.children, this.$el);
  547. } else {
  548. columnIndex = [].indexOf.call(parent.$el.children, this.$el);
  549. }
  550. owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
  551. }
  552. };
  553. /***/ }
  554. /******/ });