From 25040692b0caf33b895e70c0279283c8a52f0281 Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Thu, 8 Aug 2019 23:45:49 +0800 Subject: [PATCH] update --- README.md | 16 +++++- dist/index.common.js | 117 ++++++++++++++++++++++--------------------- dist/index.js | 117 ++++++++++++++++++++++--------------------- dist/index.min.js | 2 +- index.js | 77 +++++++++++++++------------- package.json | 2 +- 6 files changed, 179 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index b0a7be4..2a2db93 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,19 @@ VXETable.use(VXETablePluginIView) ## API -### edit-render 单元格渲染配置项说明 +### cell-render 默认的渲染器配置项说明 + +| 属性 | 描述 | 类型 | 可选值 | 默认值 | +|------|------|-----|-----|-----| +| name | 支持的渲染组件 | String | Input, AutoComplete, InputNumber, Rate, iSwitch | — | +| props | 渲染组件附加属性,参数请查看被渲染的 Component props | Object | — | {} | +| options | 只对 name=Select 有效,下拉组件选项列表 | Array | — | [] | +| optionProps | 只对 name=Select 有效,下拉组件选项属性参数配置 | Object | — | { value: 'value', label: 'label' } | +| optionGroups | 只对 name=ElSelect 有效,下拉组件分组选项列表 | Array | — | [] | +| optionGroupProps | 只对 name=ElSelect 有效,下拉组件分组选项属性参数配置 | Object | — | { options: 'options', label: 'label' } | +| events | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object | — | — | + +### edit-render 可编辑渲染器配置项说明 | 属性 | 描述 | 类型 | 可选值 | 默认值 | |------|------|-----|-----|-----| @@ -38,7 +50,7 @@ VXETable.use(VXETablePluginIView) | optionGroupProps | 只对 name=ElSelect 有效,下拉组件分组选项属性参数配置 | Object | — | { options: 'options', label: 'label' } | | events | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object | — | — | -### filter-render 筛选渲染配置项说明 +### filter-render 筛选渲染器配置项说明 | 属性 | 描述 | 类型 | 可选值 | 默认值 | |------|------|-----|-----|-----| diff --git a/dist/index.common.js b/dist/index.common.js index 622e74c..35adcaf 100644 --- a/dist/index.common.js +++ b/dist/index.common.js @@ -47,8 +47,8 @@ function getProps(_ref, _ref2) { } : {}, props); } -function getCellEvents(editRender, params) { - var events = editRender.events; +function getCellEvents(renderOpts, params) { + var events = renderOpts.events; var $table = params.$table; var type = 'on-change'; @@ -67,12 +67,12 @@ function getCellEvents(editRender, params) { return on; } -function defaultCellRender(h, editRender, params) { +function defaultCellRender(h, renderOpts, params) { var row = params.row, column = params.column; - var attrs = editRender.attrs; - var props = getProps(params, editRender); - return [h(editRender.name, { + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); + return [h(renderOpts.name, { props: props, attrs: attrs, model: { @@ -81,12 +81,12 @@ function defaultCellRender(h, editRender, params) { _xeUtils["default"].set(row, column.property, value); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) })]; } -function getFilterEvents(on, filterRender, params) { - var events = filterRender.events; +function getFilterEvents(on, renderOpts, params) { + var events = renderOpts.events; if (events) { _xeUtils["default"].assign(on, _xeUtils["default"].objectMap(events, function (cb) { @@ -99,12 +99,12 @@ function getFilterEvents(on, filterRender, params) { return on; } -function defaultFilterRender(h, filterRender, params, context) { +function defaultFilterRender(h, renderOpts, params, context) { var column = params.column; - var name = filterRender.name, - attrs = filterRender.attrs; + var name = renderOpts.name, + attrs = renderOpts.attrs; var type = 'on-change'; - var props = getProps(params, filterRender); + var props = getProps(params, renderOpts); return column.filters.map(function (item) { return h(name, { props: props, @@ -117,7 +117,7 @@ function defaultFilterRender(h, filterRender, params, context) { }, on: getFilterEvents(_defineProperty({}, type, function () { handleConfirmFilter(context, column, !!item.data, item); - }), filterRender, params) + }), renderOpts, params) }); }); } @@ -162,34 +162,37 @@ function cellText(h, cellValue) { var renderMap = { Input: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, AutoComplete: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, InputNumber: { autofocus: 'input.ivu-input-number-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, Select: { - renderEdit: function renderEdit(h, editRender, params) { - var options = editRender.options, - optionGroups = editRender.optionGroups, - _editRender$optionPro = editRender.optionProps, - optionProps = _editRender$optionPro === void 0 ? {} : _editRender$optionPro, - _editRender$optionGro = editRender.optionGroupProps, - optionGroupProps = _editRender$optionGro === void 0 ? {} : _editRender$optionGro; + renderEdit: function renderEdit(h, renderOpts, params) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$optionPro = renderOpts.optionProps, + optionProps = _renderOpts$optionPro === void 0 ? {} : _renderOpts$optionPro, + _renderOpts$optionGro = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro === void 0 ? {} : _renderOpts$optionGro; var row = params.row, column = params.column; - var attrs = editRender.attrs; - var props = getProps(params, editRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); if (optionGroups) { var groupOptions = optionGroupProps.options || 'options'; @@ -203,7 +206,7 @@ var renderMap = { _xeUtils["default"].set(row, column.property, cellValue); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, _xeUtils["default"].map(optionGroups, function (group, gIndex) { return h('OptionGroup', { props: { @@ -223,18 +226,18 @@ var renderMap = { _xeUtils["default"].set(row, column.property, cellValue); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, renderOptions(h, options, optionProps))]; }, - renderCell: function renderCell(h, editRender, params) { - var options = editRender.options, - optionGroups = editRender.optionGroups, - _editRender$props = editRender.props, - props = _editRender$props === void 0 ? {} : _editRender$props, - _editRender$optionPro2 = editRender.optionProps, - optionProps = _editRender$optionPro2 === void 0 ? {} : _editRender$optionPro2, - _editRender$optionGro2 = editRender.optionGroupProps, - optionGroupProps = _editRender$optionGro2 === void 0 ? {} : _editRender$optionGro2; + renderCell: function renderCell(h, renderOpts, params) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$props = renderOpts.props, + props = _renderOpts$props === void 0 ? {} : _renderOpts$props, + _renderOpts$optionPro2 = renderOpts.optionProps, + optionProps = _renderOpts$optionPro2 === void 0 ? {} : _renderOpts$optionPro2, + _renderOpts$optionGro2 = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro2 === void 0 ? {} : _renderOpts$optionGro2; var row = params.row, column = params.column; var labelProp = optionProps.label || 'label'; @@ -269,16 +272,16 @@ var renderMap = { return cellText(h, ''); }, - renderFilter: function renderFilter(h, filterRender, params, context) { - var options = filterRender.options, - optionGroups = filterRender.optionGroups, - _filterRender$optionP = filterRender.optionProps, - optionProps = _filterRender$optionP === void 0 ? {} : _filterRender$optionP, - _filterRender$optionG = filterRender.optionGroupProps, - optionGroupProps = _filterRender$optionG === void 0 ? {} : _filterRender$optionG; + renderFilter: function renderFilter(h, renderOpts, params, context) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$optionPro3 = renderOpts.optionProps, + optionProps = _renderOpts$optionPro3 === void 0 ? {} : _renderOpts$optionPro3, + _renderOpts$optionGro3 = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro3 === void 0 ? {} : _renderOpts$optionGro3; var column = params.column; - var attrs = filterRender.attrs; - var props = getProps(params, filterRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); if (optionGroups) { var groupOptions = optionGroupProps.options || 'options'; @@ -297,7 +300,7 @@ var renderMap = { 'on-change': function onChange(value) { handleConfirmFilter(context, column, value && value.length > 0, item); } - }, filterRender, params) + }, renderOpts, params) }, _xeUtils["default"].map(optionGroups, function (group, gIndex) { return h('OptionGroup', { props: { @@ -323,7 +326,7 @@ var renderMap = { 'on-change': function onChange(value) { handleConfirmFilter(context, column, value && value.length > 0, item); } - }, filterRender, params) + }, renderOpts, params) }, renderOptions(h, options, optionProps)); }); }, @@ -333,9 +336,9 @@ var renderMap = { column = _ref4.column; var data = option.data; var property = column.property, - filterRender = column.filterRender; - var _filterRender$props = filterRender.props, - props = _filterRender$props === void 0 ? {} : _filterRender$props; + renderOpts = column.renderOpts; + var _renderOpts$props2 = renderOpts.props, + props = _renderOpts$props2 === void 0 ? {} : _renderOpts$props2; var cellValue = _xeUtils["default"].get(row, property); @@ -409,12 +412,12 @@ var renderMap = { return cellText(h, cellValue); }, - renderFilter: function renderFilter(h, filterRender, params, context) { + renderFilter: function renderFilter(h, renderOpts, params, context) { var column = params.column; - var attrs = filterRender.attrs; - var props = getProps(params, filterRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); return column.filters.map(function (item) { - return h(filterRender.name, { + return h(renderOpts.name, { props: props, attrs: attrs, model: { @@ -427,7 +430,7 @@ var renderMap = { 'on-change': function onChange(value) { handleConfirmFilter(context, column, !!value, item); } - }, filterRender, params) + }, renderOpts, params) }); }); }, @@ -436,9 +439,9 @@ var renderMap = { row = _ref7.row, column = _ref7.column; var data = option.data; - var filterRender = column.filterRender; - var _filterRender$props2 = filterRender.props, - props = _filterRender$props2 === void 0 ? {} : _filterRender$props2; + var renderOpts = column.renderOpts; + var _renderOpts$props3 = renderOpts.props, + props = _renderOpts$props3 === void 0 ? {} : _renderOpts$props3; var cellValue = _xeUtils["default"].get(row, column.property); @@ -462,11 +465,13 @@ var renderMap = { renderEdit: defaultCellRender }, Rate: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, iSwitch: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod diff --git a/dist/index.js b/dist/index.js index edd602b..a2484b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -59,8 +59,8 @@ } : {}, props); } - function getCellEvents(editRender, params) { - var events = editRender.events; + function getCellEvents(renderOpts, params) { + var events = renderOpts.events; var $table = params.$table; var type = 'on-change'; @@ -79,12 +79,12 @@ return on; } - function defaultCellRender(h, editRender, params) { + function defaultCellRender(h, renderOpts, params) { var row = params.row, column = params.column; - var attrs = editRender.attrs; - var props = getProps(params, editRender); - return [h(editRender.name, { + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); + return [h(renderOpts.name, { props: props, attrs: attrs, model: { @@ -93,12 +93,12 @@ _xeUtils["default"].set(row, column.property, value); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) })]; } - function getFilterEvents(on, filterRender, params) { - var events = filterRender.events; + function getFilterEvents(on, renderOpts, params) { + var events = renderOpts.events; if (events) { _xeUtils["default"].assign(on, _xeUtils["default"].objectMap(events, function (cb) { @@ -111,12 +111,12 @@ return on; } - function defaultFilterRender(h, filterRender, params, context) { + function defaultFilterRender(h, renderOpts, params, context) { var column = params.column; - var name = filterRender.name, - attrs = filterRender.attrs; + var name = renderOpts.name, + attrs = renderOpts.attrs; var type = 'on-change'; - var props = getProps(params, filterRender); + var props = getProps(params, renderOpts); return column.filters.map(function (item) { return h(name, { props: props, @@ -129,7 +129,7 @@ }, on: getFilterEvents(_defineProperty({}, type, function () { handleConfirmFilter(context, column, !!item.data, item); - }), filterRender, params) + }), renderOpts, params) }); }); } @@ -174,34 +174,37 @@ var renderMap = { Input: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, AutoComplete: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, InputNumber: { autofocus: 'input.ivu-input-number-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, Select: { - renderEdit: function renderEdit(h, editRender, params) { - var options = editRender.options, - optionGroups = editRender.optionGroups, - _editRender$optionPro = editRender.optionProps, - optionProps = _editRender$optionPro === void 0 ? {} : _editRender$optionPro, - _editRender$optionGro = editRender.optionGroupProps, - optionGroupProps = _editRender$optionGro === void 0 ? {} : _editRender$optionGro; + renderEdit: function renderEdit(h, renderOpts, params) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$optionPro = renderOpts.optionProps, + optionProps = _renderOpts$optionPro === void 0 ? {} : _renderOpts$optionPro, + _renderOpts$optionGro = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro === void 0 ? {} : _renderOpts$optionGro; var row = params.row, column = params.column; - var attrs = editRender.attrs; - var props = getProps(params, editRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); if (optionGroups) { var groupOptions = optionGroupProps.options || 'options'; @@ -215,7 +218,7 @@ _xeUtils["default"].set(row, column.property, cellValue); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, _xeUtils["default"].map(optionGroups, function (group, gIndex) { return h('OptionGroup', { props: { @@ -235,18 +238,18 @@ _xeUtils["default"].set(row, column.property, cellValue); } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, renderOptions(h, options, optionProps))]; }, - renderCell: function renderCell(h, editRender, params) { - var options = editRender.options, - optionGroups = editRender.optionGroups, - _editRender$props = editRender.props, - props = _editRender$props === void 0 ? {} : _editRender$props, - _editRender$optionPro2 = editRender.optionProps, - optionProps = _editRender$optionPro2 === void 0 ? {} : _editRender$optionPro2, - _editRender$optionGro2 = editRender.optionGroupProps, - optionGroupProps = _editRender$optionGro2 === void 0 ? {} : _editRender$optionGro2; + renderCell: function renderCell(h, renderOpts, params) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$props = renderOpts.props, + props = _renderOpts$props === void 0 ? {} : _renderOpts$props, + _renderOpts$optionPro2 = renderOpts.optionProps, + optionProps = _renderOpts$optionPro2 === void 0 ? {} : _renderOpts$optionPro2, + _renderOpts$optionGro2 = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro2 === void 0 ? {} : _renderOpts$optionGro2; var row = params.row, column = params.column; var labelProp = optionProps.label || 'label'; @@ -281,16 +284,16 @@ return cellText(h, ''); }, - renderFilter: function renderFilter(h, filterRender, params, context) { - var options = filterRender.options, - optionGroups = filterRender.optionGroups, - _filterRender$optionP = filterRender.optionProps, - optionProps = _filterRender$optionP === void 0 ? {} : _filterRender$optionP, - _filterRender$optionG = filterRender.optionGroupProps, - optionGroupProps = _filterRender$optionG === void 0 ? {} : _filterRender$optionG; + renderFilter: function renderFilter(h, renderOpts, params, context) { + var options = renderOpts.options, + optionGroups = renderOpts.optionGroups, + _renderOpts$optionPro3 = renderOpts.optionProps, + optionProps = _renderOpts$optionPro3 === void 0 ? {} : _renderOpts$optionPro3, + _renderOpts$optionGro3 = renderOpts.optionGroupProps, + optionGroupProps = _renderOpts$optionGro3 === void 0 ? {} : _renderOpts$optionGro3; var column = params.column; - var attrs = filterRender.attrs; - var props = getProps(params, filterRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); if (optionGroups) { var groupOptions = optionGroupProps.options || 'options'; @@ -309,7 +312,7 @@ 'on-change': function onChange(value) { handleConfirmFilter(context, column, value && value.length > 0, item); } - }, filterRender, params) + }, renderOpts, params) }, _xeUtils["default"].map(optionGroups, function (group, gIndex) { return h('OptionGroup', { props: { @@ -335,7 +338,7 @@ 'on-change': function onChange(value) { handleConfirmFilter(context, column, value && value.length > 0, item); } - }, filterRender, params) + }, renderOpts, params) }, renderOptions(h, options, optionProps)); }); }, @@ -345,9 +348,9 @@ column = _ref4.column; var data = option.data; var property = column.property, - filterRender = column.filterRender; - var _filterRender$props = filterRender.props, - props = _filterRender$props === void 0 ? {} : _filterRender$props; + renderOpts = column.renderOpts; + var _renderOpts$props2 = renderOpts.props, + props = _renderOpts$props2 === void 0 ? {} : _renderOpts$props2; var cellValue = _xeUtils["default"].get(row, property); @@ -421,12 +424,12 @@ return cellText(h, cellValue); }, - renderFilter: function renderFilter(h, filterRender, params, context) { + renderFilter: function renderFilter(h, renderOpts, params, context) { var column = params.column; - var attrs = filterRender.attrs; - var props = getProps(params, filterRender); + var attrs = renderOpts.attrs; + var props = getProps(params, renderOpts); return column.filters.map(function (item) { - return h(filterRender.name, { + return h(renderOpts.name, { props: props, attrs: attrs, model: { @@ -439,7 +442,7 @@ 'on-change': function onChange(value) { handleConfirmFilter(context, column, !!value, item); } - }, filterRender, params) + }, renderOpts, params) }); }); }, @@ -448,9 +451,9 @@ row = _ref7.row, column = _ref7.column; var data = option.data; - var filterRender = column.filterRender; - var _filterRender$props2 = filterRender.props, - props = _filterRender$props2 === void 0 ? {} : _filterRender$props2; + var renderOpts = column.renderOpts; + var _renderOpts$props3 = renderOpts.props, + props = _renderOpts$props3 === void 0 ? {} : _renderOpts$props3; var cellValue = _xeUtils["default"].get(row, column.property); @@ -474,11 +477,13 @@ renderEdit: defaultCellRender }, Rate: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, iSwitch: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod diff --git a/dist/index.min.js b/dist/index.min.js index f0347dd..67e75b1 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-iview",["exports","xe-utils"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"));else{var n={exports:{}};t(n.exports,e.XEUtils),e.VXETablePluginIView=n.exports.default}}(this,function(e,b){"use strict";var t;function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e,t,n){return b.default.toDateString(e,t.format||n)}function c(e,t,n,r){return b.default.map(e,function(e){return p(e,t,r)}).join(n)}function l(e,t,n,r){return(e=p(e,n,r))>=p(t[0],n,r)&&e<=p(t[1],n,r)}function y(e,t){var n=e.$table,r=t.props;return b.default.assign(n.vSize?{size:n.vSize}:{},r)}function m(e,t){var n=e.events,r=t.$table,o=d({},"on-change",function(){return r.updateStatus(t)});return n&&b.default.assign(o,b.default.objectMap(n,function(e){return function(){e.apply(null,[t].concat.apply(t,arguments))}})),o}function n(e,t,n){var r=n.row,o=n.column,a=t.attrs,u=y(n,t);return[e(t.name,{props:u,attrs:a,model:{value:b.default.get(r,o.property),callback:function(e){b.default.set(r,o.property,e)}},on:m(t,n)})]}function g(e,t,n){var r=t.events;return r&&b.default.assign(e,b.default.objectMap(r,function(e){return function(){e.apply(null,[n].concat.apply(n,arguments))}})),e}function r(e,n,r,o){var a=r.column,u=n.name,i=n.attrs,l=y(r,n);return a.filters.map(function(t){return e(u,{props:l,attrs:i,model:{value:t.data,callback:function(e){t.data=e}},on:g(d({},"on-change",function(){M(o,a,!!t.data,t)}),n,r)})})}function M(e,t,n,r){e[t.filterMultiple?"changeMultipleOption":"changeRadioOption"]({},n,r)}function o(e){var t=e.option,n=e.row,r=e.column,o=t.data;return b.default.get(n,r.property)===o}function h(n,e,t){var r=t.label||"label",o=t.value||"value";return b.default.map(e,function(e,t){return n("Option",{props:{value:e[o],label:e[r]},key:t})})}function w(e,t){return[""+(null==t?"":t)]}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,b=(t=b)&&t.__esModule?t:{default:t};var a={Input:{autofocus:"input.ivu-input",renderEdit:n,renderFilter:r,filterMethod:o},AutoComplete:{autofocus:"input.ivu-input",renderEdit:n,renderFilter:r,filterMethod:o},InputNumber:{autofocus:"input.ivu-input-number-input",renderEdit:n,renderFilter:r,filterMethod:o},Select:{renderEdit:function(n,e,t){var r=e.options,o=e.optionGroups,a=e.optionProps,u=void 0===a?{}:a,i=e.optionGroupProps,l=void 0===i?{}:i,d=t.row,p=t.column,c=e.attrs,f=y(t,e);if(o){var s=l.options||"options",v=l.label||"label";return[n("Select",{props:f,attrs:c,model:{value:b.default.get(d,p.property),callback:function(e){b.default.set(d,p.property,e)}},on:m(e,t)},b.default.map(o,function(e,t){return n("OptionGroup",{props:{label:e[v]},key:t},h(n,e[s],u))}))]}return[n("Select",{props:f,attrs:c,model:{value:b.default.get(d,p.property),callback:function(e){b.default.set(d,p.property,e)}},on:m(e,t)},h(n,r,u))]},renderCell:function(e,t,n){var r=t.options,o=t.optionGroups,a=t.props,u=void 0===a?{}:a,i=t.optionProps,l=void 0===i?{}:i,d=t.optionGroupProps,p=void 0===d?{}:d,c=n.row,f=n.column,s=l.label||"label",v=l.value||"value",y=p.options||"options",m=b.default.get(c,f.property);return w(0,null!=m&&""!==m?b.default.map(u.multiple?m:[m],o?function(t){for(var e,n=0;nn&&b.default.each(e,function(e){e.value===a&&(o.push(e.label),t(++n,e.children,r,o))})}(0,o.data,i,l),w(0,l.join(" ".concat(o.separator||"/"," ")))}},DatePicker:{renderEdit:n,renderCell:function(e,t,n){var r=t.props,o=void 0===r?{}:r,a=n.row,u=n.column,i=o.separator,l=b.default.get(a,u.property);switch(o.type){case"week":l=p(l,o,"yyyywWW");break;case"month":l=p(l,o,"yyyy-MM");break;case"year":l=p(l,o,"yyyy");break;case"dates":l=c(l,o,", ","yyyy-MM-dd");break;case"daterange":l=c(l,o," ".concat(i||"-"," "),"yyyy-MM-dd");break;case"datetimerange":l=c(l,o," ".concat(i||"-"," "),"yyyy-MM-dd HH:ss:mm");break;default:l=p(l,o,"yyyy-MM-dd")}return w(0,l)},renderFilter:function(e,n,r,o){var a=r.column,u=n.attrs,i=y(r,n);return a.filters.map(function(t){return e(n.name,{props:i,attrs:u,model:{value:t.data,callback:function(e){t.data=e}},on:g({"on-change":function(e){M(o,a,!!e,t)}},n,r)})})},filterMethod:function(e){var t=e.option,n=e.row,r=e.column,o=t.data,a=r.filterRender.props,u=void 0===a?{}:a,i=b.default.get(n,r.property);if(o)switch(u.type){case"daterange":return l(i,o,u,"yyyy-MM-dd");case"datetimerange":return l(i,o,u,"yyyy-MM-dd HH:ss:mm");default:return i===o}return!1}},TimePicker:{renderEdit:n},Rate:{renderEdit:n,renderFilter:r,filterMethod:o},iSwitch:{renderEdit:n,renderFilter:r,filterMethod:o}};function u(e,t,n){if((0,n.getEventTargetNode)(t,document.body,"ivu-select-dropdown").flag)return!1}var i={install:function(e){var t=e.interceptor;e.renderer.mixin(a),t.add("event.clear_filter",u),t.add("event.clear_actived",u)}};"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(i);var f=i;e.default=f}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-iview",["exports","xe-utils"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"));else{var n={exports:{}};t(n.exports,e.XEUtils),e.VXETablePluginIView=n.exports.default}}(this,function(e,b){"use strict";var t;function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e,t,n){return b.default.toDateString(e,t.format||n)}function c(e,t,n,r){return b.default.map(e,function(e){return p(e,t,r)}).join(n)}function l(e,t,n,r){return(e=p(e,n,r))>=p(t[0],n,r)&&e<=p(t[1],n,r)}function y(e,t){var n=e.$table,r=t.props;return b.default.assign(n.vSize?{size:n.vSize}:{},r)}function m(e,t){var n=e.events,r=t.$table,o=d({},"on-change",function(){return r.updateStatus(t)});return n&&b.default.assign(o,b.default.objectMap(n,function(e){return function(){e.apply(null,[t].concat.apply(t,arguments))}})),o}function n(e,t,n){var r=n.row,o=n.column,a=t.attrs,u=y(n,t);return[e(t.name,{props:u,attrs:a,model:{value:b.default.get(r,o.property),callback:function(e){b.default.set(r,o.property,e)}},on:m(t,n)})]}function g(e,t,n){var r=t.events;return r&&b.default.assign(e,b.default.objectMap(r,function(e){return function(){e.apply(null,[n].concat.apply(n,arguments))}})),e}function r(e,n,r,o){var a=r.column,u=n.name,i=n.attrs,l=y(r,n);return a.filters.map(function(t){return e(u,{props:l,attrs:i,model:{value:t.data,callback:function(e){t.data=e}},on:g(d({},"on-change",function(){M(o,a,!!t.data,t)}),n,r)})})}function M(e,t,n,r){e[t.filterMultiple?"changeMultipleOption":"changeRadioOption"]({},n,r)}function o(e){var t=e.option,n=e.row,r=e.column,o=t.data;return b.default.get(n,r.property)===o}function h(n,e,t){var r=t.label||"label",o=t.value||"value";return b.default.map(e,function(e,t){return n("Option",{props:{value:e[o],label:e[r]},key:t})})}function w(e,t){return[""+(null==t?"":t)]}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,b=(t=b)&&t.__esModule?t:{default:t};var a={Input:{autofocus:"input.ivu-input",renderDefault:n,renderEdit:n,renderFilter:r,filterMethod:o},AutoComplete:{autofocus:"input.ivu-input",renderDefault:n,renderEdit:n,renderFilter:r,filterMethod:o},InputNumber:{autofocus:"input.ivu-input-number-input",renderDefault:n,renderEdit:n,renderFilter:r,filterMethod:o},Select:{renderEdit:function(n,e,t){var r=e.options,o=e.optionGroups,a=e.optionProps,u=void 0===a?{}:a,i=e.optionGroupProps,l=void 0===i?{}:i,d=t.row,p=t.column,c=e.attrs,f=y(t,e);if(o){var s=l.options||"options",v=l.label||"label";return[n("Select",{props:f,attrs:c,model:{value:b.default.get(d,p.property),callback:function(e){b.default.set(d,p.property,e)}},on:m(e,t)},b.default.map(o,function(e,t){return n("OptionGroup",{props:{label:e[v]},key:t},h(n,e[s],u))}))]}return[n("Select",{props:f,attrs:c,model:{value:b.default.get(d,p.property),callback:function(e){b.default.set(d,p.property,e)}},on:m(e,t)},h(n,r,u))]},renderCell:function(e,t,n){var r=t.options,o=t.optionGroups,a=t.props,u=void 0===a?{}:a,i=t.optionProps,l=void 0===i?{}:i,d=t.optionGroupProps,p=void 0===d?{}:d,c=n.row,f=n.column,s=l.label||"label",v=l.value||"value",y=p.options||"options",m=b.default.get(c,f.property);return w(0,null!=m&&""!==m?b.default.map(u.multiple?m:[m],o?function(t){for(var e,n=0;nn&&b.default.each(e,function(e){e.value===a&&(o.push(e.label),t(++n,e.children,r,o))})}(0,o.data,i,l),w(0,l.join(" ".concat(o.separator||"/"," ")))}},DatePicker:{renderEdit:n,renderCell:function(e,t,n){var r=t.props,o=void 0===r?{}:r,a=n.row,u=n.column,i=o.separator,l=b.default.get(a,u.property);switch(o.type){case"week":l=p(l,o,"yyyywWW");break;case"month":l=p(l,o,"yyyy-MM");break;case"year":l=p(l,o,"yyyy");break;case"dates":l=c(l,o,", ","yyyy-MM-dd");break;case"daterange":l=c(l,o," ".concat(i||"-"," "),"yyyy-MM-dd");break;case"datetimerange":l=c(l,o," ".concat(i||"-"," "),"yyyy-MM-dd HH:ss:mm");break;default:l=p(l,o,"yyyy-MM-dd")}return w(0,l)},renderFilter:function(e,n,r,o){var a=r.column,u=n.attrs,i=y(r,n);return a.filters.map(function(t){return e(n.name,{props:i,attrs:u,model:{value:t.data,callback:function(e){t.data=e}},on:g({"on-change":function(e){M(o,a,!!e,t)}},n,r)})})},filterMethod:function(e){var t=e.option,n=e.row,r=e.column,o=t.data,a=r.renderOpts.props,u=void 0===a?{}:a,i=b.default.get(n,r.property);if(o)switch(u.type){case"daterange":return l(i,o,u,"yyyy-MM-dd");case"datetimerange":return l(i,o,u,"yyyy-MM-dd HH:ss:mm");default:return i===o}return!1}},TimePicker:{renderEdit:n},Rate:{renderDefault:n,renderEdit:n,renderFilter:r,filterMethod:o},iSwitch:{renderDefault:n,renderEdit:n,renderFilter:r,filterMethod:o}};function u(e,t,n){if((0,n.getEventTargetNode)(t,document.body,"ivu-select-dropdown").flag)return!1}var i={install:function(e){var t=e.interceptor;e.renderer.mixin(a),t.add("event.clear_filter",u),t.add("event.clear_actived",u)}};"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(i);var f=i;e.default=f}); \ No newline at end of file diff --git a/index.js b/index.js index 89fbe2a..3c84e7b 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,8 @@ function getProps ({ $table }, { props }) { return XEUtils.assign($table.vSize ? { size: $table.vSize } : {}, props) } -function getCellEvents (editRender, params) { - let { events } = editRender +function getCellEvents (renderOpts, params) { + let { events } = renderOpts let { $table } = params let type = 'on-change' let on = { @@ -44,12 +44,12 @@ function getCellEvents (editRender, params) { return on } -function defaultCellRender (h, editRender, params) { +function defaultCellRender (h, renderOpts, params) { let { row, column } = params - let { attrs } = editRender - let props = getProps(params, editRender) + let { attrs } = renderOpts + let props = getProps(params, renderOpts) return [ - h(editRender.name, { + h(renderOpts.name, { props, attrs, model: { @@ -58,13 +58,13 @@ function defaultCellRender (h, editRender, params) { XEUtils.set(row, column.property, value) } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }) ] } -function getFilterEvents (on, filterRender, params) { - let { events } = filterRender +function getFilterEvents (on, renderOpts, params) { + let { events } = renderOpts if (events) { XEUtils.assign(on, XEUtils.objectMap(events, cb => function () { cb.apply(null, [params].concat.apply(params, arguments)) @@ -73,11 +73,11 @@ function getFilterEvents (on, filterRender, params) { return on } -function defaultFilterRender (h, filterRender, params, context) { +function defaultFilterRender (h, renderOpts, params, context) { let { column } = params - let { name, attrs } = filterRender + let { name, attrs } = renderOpts let type = 'on-change' - let props = getProps(params, filterRender) + let props = getProps(params, renderOpts) return column.filters.map(item => { return h(name, { props, @@ -92,7 +92,7 @@ function defaultFilterRender (h, filterRender, params, context) { [type] () { handleConfirmFilter(context, column, !!item.data, item) } - }, filterRender, params) + }, renderOpts, params) }) }) } @@ -131,28 +131,31 @@ function cellText (h, cellValue) { const renderMap = { Input: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, AutoComplete: { autofocus: 'input.ivu-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, InputNumber: { autofocus: 'input.ivu-input-number-input', + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, Select: { - renderEdit (h, editRender, params) { - let { options, optionGroups, optionProps = {}, optionGroupProps = {} } = editRender + renderEdit (h, renderOpts, params) { + let { options, optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts let { row, column } = params - let { attrs } = editRender - let props = getProps(params, editRender) + let { attrs } = renderOpts + let props = getProps(params, renderOpts) if (optionGroups) { let groupOptions = optionGroupProps.options || 'options' let groupLabel = optionGroupProps.label || 'label' @@ -166,7 +169,7 @@ const renderMap = { XEUtils.set(row, column.property, cellValue) } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, XEUtils.map(optionGroups, (group, gIndex) => { return h('OptionGroup', { props: { @@ -187,12 +190,12 @@ const renderMap = { XEUtils.set(row, column.property, cellValue) } }, - on: getCellEvents(editRender, params) + on: getCellEvents(renderOpts, params) }, renderOptions(h, options, optionProps)) ] }, - renderCell (h, editRender, params) { - let { options, optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = editRender + renderCell (h, renderOpts, params) { + let { options, optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts let { row, column } = params let labelProp = optionProps.label || 'label' let valueProp = optionProps.value || 'value' @@ -215,11 +218,11 @@ const renderMap = { } return cellText(h, '') }, - renderFilter (h, filterRender, params, context) { - let { options, optionGroups, optionProps = {}, optionGroupProps = {} } = filterRender + renderFilter (h, renderOpts, params, context) { + let { options, optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts let { column } = params - let { attrs } = filterRender - let props = getProps(params, filterRender) + let { attrs } = renderOpts + let props = getProps(params, renderOpts) if (optionGroups) { let groupOptions = optionGroupProps.options || 'options' let groupLabel = optionGroupProps.label || 'label' @@ -237,7 +240,7 @@ const renderMap = { 'on-change' (value) { handleConfirmFilter(context, column, value && value.length > 0, item) } - }, filterRender, params) + }, renderOpts, params) }, XEUtils.map(optionGroups, (group, gIndex) => { return h('OptionGroup', { props: { @@ -262,14 +265,14 @@ const renderMap = { 'on-change' (value) { handleConfirmFilter(context, column, value && value.length > 0, item) } - }, filterRender, params) + }, renderOpts, params) }, renderOptions(h, options, optionProps)) }) }, filterMethod ({ option, row, column }) { let { data } = option - let { property, filterRender } = column - let { props = {} } = filterRender + let { property, renderOpts } = column + let { props = {} } = renderOpts let cellValue = XEUtils.get(row, property) if (props.multiple) { if (XEUtils.isArray(cellValue)) { @@ -322,12 +325,12 @@ const renderMap = { } return cellText(h, cellValue) }, - renderFilter (h, filterRender, params, context) { + renderFilter (h, renderOpts, params, context) { let { column } = params - let { attrs } = filterRender - let props = getProps(params, filterRender) + let { attrs } = renderOpts + let props = getProps(params, renderOpts) return column.filters.map(item => { - return h(filterRender.name, { + return h(renderOpts.name, { props, attrs, model: { @@ -340,14 +343,14 @@ const renderMap = { 'on-change' (value) { handleConfirmFilter(context, column, !!value, item) } - }, filterRender, params) + }, renderOpts, params) }) }) }, filterMethod ({ option, row, column }) { let { data } = option - let { filterRender } = column - let { props = {} } = filterRender + let { renderOpts } = column + let { props = {} } = renderOpts let cellValue = XEUtils.get(row, column.property) if (data) { switch (props.type) { @@ -366,11 +369,13 @@ const renderMap = { renderEdit: defaultCellRender }, Rate: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod }, iSwitch: { + renderDefault: defaultCellRender, renderEdit: defaultCellRender, renderFilter: defaultFilterRender, filterMethod: defaultFilterMethod diff --git a/package.json b/package.json index bfa20b0..0d027eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table-plugin-iview", - "version": "1.3.1", + "version": "1.3.2", "description": "vxe-table renderer plugins for iview.", "scripts": { "lib": "gulp build"