mindoc/static/element-ui/lib/table-column.js
2017-04-19 18:19:27 +08:00

666 lines
17 KiB
JavaScript

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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = 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;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(316);
/***/ },
/***/ 164:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/merge");
/***/ },
/***/ 266:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/tag");
/***/ },
/***/ 304:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/checkbox");
/***/ },
/***/ 306:
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var getCell = exports.getCell = function getCell(event) {
var cell = event.target;
while (cell && cell.tagName.toUpperCase() !== 'HTML') {
if (cell.tagName.toUpperCase() === 'TD') {
return cell;
}
cell = cell.parentNode;
}
return null;
};
var getValueByPath = exports.getValueByPath = function getValueByPath(object, prop) {
prop = prop || '';
var paths = prop.split('.');
var current = object;
var result = null;
for (var i = 0, j = paths.length; i < j; i++) {
var path = paths[i];
if (!current) break;
if (i === j - 1) {
result = current[path];
break;
}
current = current[path];
}
return result;
};
var isObject = function isObject(obj) {
return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
};
var orderBy = exports.orderBy = function orderBy(array, sortKey, reverse, sortMethod) {
if (typeof reverse === 'string') {
reverse = reverse === 'descending' ? -1 : 1;
}
if (!sortKey) {
return array;
}
var order = reverse && reverse < 0 ? -1 : 1;
// sort on a copy to avoid mutating original array
return array.slice().sort(sortMethod ? function (a, b) {
return sortMethod(a, b) ? order : -order;
} : function (a, b) {
if (sortKey !== '$key') {
if (isObject(a) && '$value' in a) a = a.$value;
if (isObject(b) && '$value' in b) b = b.$value;
}
a = isObject(a) ? getValueByPath(a, sortKey) : a;
b = isObject(b) ? getValueByPath(b, sortKey) : b;
return a === b ? 0 : a > b ? order : -order;
});
};
var getColumnById = exports.getColumnById = function getColumnById(table, columnId) {
var column = null;
table.columns.forEach(function (item) {
if (item.id === columnId) {
column = item;
}
});
return column;
};
var getColumnByCell = exports.getColumnByCell = function getColumnByCell(table, cell) {
var matches = (cell.className || '').match(/el-table_[^\s]+/gm);
if (matches) {
return getColumnById(table, matches[0]);
}
return null;
};
var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var mousewheel = exports.mousewheel = function mousewheel(element, callback) {
if (element && element.addEventListener) {
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
}
};
var getRowIdentity = exports.getRowIdentity = function getRowIdentity(row, rowKey) {
if (!row) throw new Error('row is required when get row identity');
if (typeof rowKey === 'string') {
return row[rowKey];
} else if (typeof rowKey === 'function') {
return rowKey.call(null, row);
}
};
/***/ },
/***/ 316:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _tableColumn = __webpack_require__(317);
var _tableColumn2 = _interopRequireDefault(_tableColumn);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* istanbul ignore next */
_tableColumn2.default.install = function (Vue) {
Vue.component(_tableColumn2.default.name, _tableColumn2.default);
};
exports.default = _tableColumn2.default;
/***/ },
/***/ 317:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _checkbox = __webpack_require__(304);
var _checkbox2 = _interopRequireDefault(_checkbox);
var _tag = __webpack_require__(266);
var _tag2 = _interopRequireDefault(_tag);
var _merge = __webpack_require__(164);
var _merge2 = _interopRequireDefault(_merge);
var _util = __webpack_require__(306);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure undefined"); }
var columnIdSeed = 1;
var defaults = {
default: {
order: ''
},
selection: {
width: 48,
minWidth: 48,
realWidth: 48,
order: '',
className: 'el-table-column--selection'
},
expand: {
width: 48,
minWidth: 48,
realWidth: 48,
order: ''
},
index: {
width: 48,
minWidth: 48,
realWidth: 48,
order: ''
}
};
var forced = {
selection: {
renderHeader: function renderHeader(h) {
return h(
'el-checkbox',
{
nativeOn: {
'click': this.toggleAllSelection
},
domProps: {
'value': this.isAllSelected
}
},
[]
);
},
renderCell: function renderCell(h, _ref) {
var row = _ref.row,
column = _ref.column,
store = _ref.store,
$index = _ref.$index;
return h(
'el-checkbox',
{
domProps: {
'value': store.isSelected(row)
},
attrs: {
disabled: column.selectable ? !column.selectable.call(null, row, $index) : false
},
on: {
'input': function input() {
store.commit('rowSelectedChanged', row);
}
}
},
[]
);
},
sortable: false,
resizable: false
},
index: {
renderHeader: function renderHeader(h, _ref2) {
var column = _ref2.column;
return column.label || '#';
},
renderCell: function renderCell(h, _ref3) {
var $index = _ref3.$index;
return h(
'div',
null,
[$index + 1]
);
},
sortable: false
},
expand: {
renderHeader: function renderHeader(h, _ref4) {
_objectDestructuringEmpty(_ref4);
return '';
},
renderCell: function renderCell(h, _ref5, proxy) {
var row = _ref5.row,
store = _ref5.store;
var expanded = store.states.expandRows.indexOf(row) > -1;
return h(
'div',
{ 'class': 'el-table__expand-icon ' + (expanded ? 'el-table__expand-icon--expanded' : ''),
on: {
'click': function click() {
return proxy.handleExpandClick(row);
}
}
},
[h(
'i',
{ 'class': 'el-icon el-icon-arrow-right' },
[]
)]
);
},
sortable: false,
resizable: false,
className: 'el-table__expand-column'
}
};
var getDefaultColumn = function getDefaultColumn(type, options) {
var column = {};
(0, _merge2.default)(column, defaults[type || 'default']);
for (var name in options) {
if (options.hasOwnProperty(name)) {
var value = options[name];
if (typeof value !== 'undefined') {
column[name] = value;
}
}
}
if (!column.minWidth) {
column.minWidth = 80;
}
column.realWidth = column.width || column.minWidth;
return column;
};
var DEFAULT_RENDER_CELL = function DEFAULT_RENDER_CELL(h, _ref6) {
var row = _ref6.row,
column = _ref6.column;
var property = column.property;
if (column && column.formatter) {
return column.formatter(row, column);
}
if (property && property.indexOf('.') === -1) {
return row[property];
}
return (0, _util.getValueByPath)(row, property);
};
exports.default = {
name: 'ElTableColumn',
props: {
type: {
type: String,
default: 'default'
},
label: String,
className: String,
labelClassName: String,
property: String,
prop: String,
width: {},
minWidth: {},
renderHeader: Function,
sortable: {
type: [String, Boolean],
default: false
},
sortMethod: Function,
resizable: {
type: Boolean,
default: true
},
context: {},
columnKey: String,
align: String,
headerAlign: String,
showTooltipWhenOverflow: Boolean,
showOverflowTooltip: Boolean,
fixed: [Boolean, String],
formatter: Function,
selectable: Function,
reserveSelection: Boolean,
filterMethod: Function,
filteredValue: Array,
filters: Array,
filterMultiple: {
type: Boolean,
default: true
}
},
data: function data() {
return {
isSubColumn: false,
columns: []
};
},
beforeCreate: function beforeCreate() {
this.row = {};
this.column = {};
this.$index = 0;
},
components: {
ElCheckbox: _checkbox2.default,
ElTag: _tag2.default
},
computed: {
owner: function owner() {
var parent = this.$parent;
while (parent && !parent.tableId) {
parent = parent.$parent;
}
return parent;
}
},
created: function created() {
var _this = this;
this.customRender = this.$options.render;
this.$options.render = function (h) {
return h('div', _this.$slots.default);
};
this.columnId = (this.$parent.tableId || this.$parent.columnId + '_') + 'column_' + columnIdSeed++;
var parent = this.$parent;
var owner = this.owner;
this.isSubColumn = owner !== parent;
var type = this.type;
var width = this.width;
if (width !== undefined) {
width = parseInt(width, 10);
if (isNaN(width)) {
width = null;
}
}
var minWidth = this.minWidth;
if (minWidth !== undefined) {
minWidth = parseInt(minWidth, 10);
if (isNaN(minWidth)) {
minWidth = 80;
}
}
var isColumnGroup = false;
var column = getDefaultColumn(type, {
id: this.columnId,
columnKey: this.columnKey,
label: this.label,
className: this.className,
labelClassName: this.labelClassName,
property: this.prop || this.property,
type: type,
renderCell: null,
renderHeader: this.renderHeader,
minWidth: minWidth,
width: width,
isColumnGroup: isColumnGroup,
context: this.context,
align: this.align ? 'is-' + this.align : null,
headerAlign: this.headerAlign ? 'is-' + this.headerAlign : this.align ? 'is-' + this.align : null,
sortable: this.sortable === '' ? true : this.sortable,
sortMethod: this.sortMethod,
resizable: this.resizable,
showOverflowTooltip: this.showOverflowTooltip || this.showTooltipWhenOverflow,
formatter: this.formatter,
selectable: this.selectable,
reserveSelection: this.reserveSelection,
fixed: this.fixed === '' ? true : this.fixed,
filterMethod: this.filterMethod,
filters: this.filters,
filterable: this.filters || this.filterMethod,
filterMultiple: this.filterMultiple,
filterOpened: false,
filteredValue: this.filteredValue || []
});
(0, _merge2.default)(column, forced[type] || {});
this.columnConfig = column;
var renderCell = column.renderCell;
var _self = this;
if (type === 'expand') {
owner.renderExpanded = function (h, data) {
return _self.$scopedSlots.default ? _self.$scopedSlots.default(data) : _self.$slots.default;
};
column.renderCell = function (h, data) {
return h(
'div',
{ 'class': 'cell' },
[renderCell(h, data, this._renderProxy)]
);
};
return;
}
column.renderCell = function (h, data) {
// 未来版本移除
if (_self.$vnode.data.inlineTemplate) {
renderCell = function renderCell() {
data._self = _self.context || data._self;
if (Object.prototype.toString.call(data._self) === '[object Object]') {
for (var prop in data._self) {
if (!data.hasOwnProperty(prop)) {
data[prop] = data._self[prop];
}
}
}
// 静态内容会缓存到 _staticTrees 内,不改的话获取的静态数据就不是内部 context
data._staticTrees = _self._staticTrees;
data.$options.staticRenderFns = _self.$options.staticRenderFns;
return _self.customRender.call(data);
};
} else if (_self.$scopedSlots.default) {
renderCell = function renderCell() {
return _self.$scopedSlots.default(data);
};
}
if (!renderCell) {
renderCell = DEFAULT_RENDER_CELL;
}
return _self.showOverflowTooltip || _self.showTooltipWhenOverflow ? h(
'div',
{ 'class': 'cell el-tooltip' },
[renderCell(h, data)]
) : h(
'div',
{ 'class': 'cell' },
[renderCell(h, data)]
);
};
},
destroyed: function destroyed() {
if (!this.$parent) return;
this.owner.store.commit('removeColumn', this.columnConfig);
},
watch: {
label: function label(newVal) {
if (this.columnConfig) {
this.columnConfig.label = newVal;
}
},
prop: function prop(newVal) {
if (this.columnConfig) {
this.columnConfig.property = newVal;
}
},
property: function property(newVal) {
if (this.columnConfig) {
this.columnConfig.property = newVal;
}
},
filters: function filters(newVal) {
if (this.columnConfig) {
this.columnConfig.filters = newVal;
}
},
filterMultiple: function filterMultiple(newVal) {
if (this.columnConfig) {
this.columnConfig.filterMultiple = newVal;
}
},
align: function align(newVal) {
if (this.columnConfig) {
this.columnConfig.align = newVal ? 'is-' + newVal : null;
if (!this.headerAlign) {
this.columnConfig.headerAlign = newVal ? 'is-' + newVal : null;
}
}
},
headerAlign: function headerAlign(newVal) {
if (this.columnConfig) {
this.columnConfig.headerAlign = 'is-' + (newVal ? newVal : this.align);
}
},
width: function width(newVal) {
if (this.columnConfig) {
this.columnConfig.width = newVal;
this.owner.store.scheduleLayout();
}
},
minWidth: function minWidth(newVal) {
if (this.columnConfig) {
this.columnConfig.minWidth = newVal;
this.owner.store.scheduleLayout();
}
},
fixed: function fixed(newVal) {
if (this.columnConfig) {
this.columnConfig.fixed = newVal;
this.owner.store.scheduleLayout();
}
}
},
mounted: function mounted() {
var owner = this.owner;
var parent = this.$parent;
var columnIndex = void 0;
if (!this.isSubColumn) {
columnIndex = [].indexOf.call(parent.$refs.hiddenColumns.children, this.$el);
} else {
columnIndex = [].indexOf.call(parent.$el.children, this.$el);
}
owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
}
};
/***/ }
/******/ });