Skip to content

Commit

Permalink
优化渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Nov 25, 2019
1 parent c5f7b34 commit b8fabe2
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 239 deletions.
166 changes: 85 additions & 81 deletions dist/index.common.js

Large diffs are not rendered by default.

164 changes: 84 additions & 80 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
};
}

function getProps(_ref2, _ref3) {
function getProps(_ref2, _ref3, defaultProps) {
var $table = _ref2.$table;
var props = _ref3.props;
return _xeUtils["default"].assign($table.vSize ? {
size: $table.vSize
} : {}, props);
} : {}, defaultProps, props);
}

function getCellEvents(renderOpts, params) {
Expand Down Expand Up @@ -104,22 +104,24 @@
return on;
}

function defaultEditRender(h, renderOpts, params) {
var row = params.row,
column = params.column;
var attrs = renderOpts.attrs;
var props = getProps(params, renderOpts);
return [h(renderOpts.name, {
props: props,
attrs: attrs,
model: {
value: _xeUtils["default"].get(row, column.property),
callback: function callback(value) {
_xeUtils["default"].set(row, column.property, value);
}
},
on: getCellEvents(renderOpts, params)
})];
function createEditRender(defaultProps) {
return function (h, renderOpts, params) {
var row = params.row,
column = params.column;
var attrs = renderOpts.attrs;
var props = getProps(params, renderOpts, defaultProps);
return [h(renderOpts.name, {
props: props,
attrs: attrs,
model: {
value: _xeUtils["default"].get(row, column.property),
callback: function callback(value) {
_xeUtils["default"].set(row, column.property, value);
}
},
on: getCellEvents(renderOpts, params)
})];
};
}

function getFilterEvents(on, renderOpts, params, context) {
Expand All @@ -144,49 +146,51 @@
return on;
}

function defaultFilterRender(h, renderOpts, params, context) {
var column = params.column;
var name = renderOpts.name,
attrs = renderOpts.attrs,
events = renderOpts.events;
var props = getProps(params, renderOpts);
var type = 'change';

switch (name) {
case 'AAutoComplete':
type = 'select';
break;

case 'AInput':
type = 'input';
break;

case 'AInputNumber':
type = 'change';
break;
}
function createFilterRender(defaultProps) {
return function (h, renderOpts, params, context) {
var column = params.column;
var name = renderOpts.name,
attrs = renderOpts.attrs,
events = renderOpts.events;
var props = getProps(params, renderOpts);
var type = 'change';

switch (name) {
case 'AAutoComplete':
type = 'select';
break;

case 'AInput':
type = 'input';
break;

case 'AInputNumber':
type = 'change';
break;
}

return column.filters.map(function (item) {
return h(name, {
props: props,
attrs: attrs,
model: {
value: item.data,
callback: function callback(optionValue) {
item.data = optionValue;
}
},
on: getFilterEvents(_defineProperty({}, type, function (evnt) {
handleConfirmFilter(context, column, !!item.data, item);
return column.filters.map(function (item) {
return h(name, {
props: props,
attrs: attrs,
model: {
value: item.data,
callback: function callback(optionValue) {
item.data = optionValue;
}
},
on: getFilterEvents(_defineProperty({}, type, function (evnt) {
handleConfirmFilter(context, column, !!item.data, item);

if (events && events[type]) {
events[type](Object.assign({
context: context
}, params), evnt);
}
}), renderOpts, params, context)
if (events && events[type]) {
events[type](Object.assign({
context: context
}, params), evnt);
}
}), renderOpts, params, context)
});
});
});
};
}

function handleConfirmFilter(context, column, checked, item) {
Expand Down Expand Up @@ -232,23 +236,23 @@
var renderMap = {
AAutoComplete: {
autofocus: 'input.ant-input',
renderDefault: defaultEditRender,
renderEdit: defaultEditRender,
renderFilter: defaultFilterRender,
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
filterMethod: defaultFilterMethod
},
AInput: {
autofocus: 'input.ant-input',
renderDefault: defaultEditRender,
renderEdit: defaultEditRender,
renderFilter: defaultFilterRender,
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
filterMethod: defaultFilterMethod
},
AInputNumber: {
autofocus: 'input.ant-input-number-input',
renderDefault: defaultEditRender,
renderEdit: defaultEditRender,
renderFilter: defaultFilterRender,
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
filterMethod: defaultFilterMethod
},
ASelect: {
Expand Down Expand Up @@ -436,7 +440,7 @@
}
},
ACascader: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: function renderCell(h, _ref6, params) {
var _ref6$props = _ref6.props,
props = _ref6$props === void 0 ? {} : _ref6$props;
Expand All @@ -452,15 +456,15 @@
}
},
ADatePicker: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: formatDatePicker('YYYY-MM-DD')
},
AMonthPicker: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: formatDatePicker('YYYY-MM')
},
ARangePicker: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: function renderCell(h, _ref7, params) {
var _ref7$props = _ref7.props,
props = _ref7$props === void 0 ? {} : _ref7$props;
Expand All @@ -479,15 +483,15 @@
}
},
AWeekPicker: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: formatDatePicker('YYYY-WW周')
},
ATimePicker: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: formatDatePicker('HH:mm:ss')
},
ATreeSelect: {
renderEdit: defaultEditRender,
renderEdit: createEditRender(),
renderCell: function renderCell(h, _ref8, params) {
var _ref8$props = _ref8.props,
props = _ref8$props === void 0 ? {} : _ref8$props;
Expand All @@ -504,15 +508,15 @@
}
},
ARate: {
renderDefault: defaultEditRender,
renderEdit: defaultEditRender,
renderFilter: defaultFilterRender,
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
filterMethod: defaultFilterMethod
},
ASwitch: {
renderDefault: defaultEditRender,
renderEdit: defaultEditRender,
renderFilter: defaultFilterRender,
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
filterMethod: defaultFilterMethod
}
};
Expand Down
Loading

0 comments on commit b8fabe2

Please sign in to comment.