From 52c8bf672bb0d42b25f0309833bd0993bc8792ff Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Wed, 27 Jan 2021 18:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=95=B0=E5=80=BC=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/api/checkbox-group.js | 13 +++++- examples/api/checkbox.js | 2 +- examples/api/column.js | 2 +- examples/api/input.js | 40 ++++++++-------- examples/api/modal.js | 2 +- examples/api/radio-button.js | 9 ++++ examples/api/radio-group.js | 15 ++++-- examples/api/radio.js | 2 +- examples/api/select.js | 2 +- examples/api/switch.js | 2 +- examples/api/textarea.js | 20 ++++---- examples/views/table/base/Sort.vue | 6 +-- package.json | 2 +- packages/grid/src/grid.js | 73 ++++++++++++++++++------------ packages/table/src/methods.js | 23 +++++----- packages/table/src/table.js | 5 +- packages/tools/src/utils.js | 2 +- 17 files changed, 133 insertions(+), 87 deletions(-) diff --git a/examples/api/checkbox-group.js b/examples/api/checkbox-group.js index a2c9f6232..43b8524c9 100644 --- a/examples/api/checkbox-group.js +++ b/examples/api/checkbox-group.js @@ -8,14 +8,23 @@ const apis = [ defVal: '', list: [ { - name: 'label', - desc: '绑定值', + name: 'v-model / value', + descKey: 'app.api.checkbox.desc.value', version: '', type: 'any[]', enum: '', defVal: '', list: [] }, + { + name: 'size', + descKey: 'app.api.checkbox.desc.size', + version: '', + type: 'string', + enum: 'medium, small, mini', + defVal: '继承上下文', + list: [] + }, { name: 'disabled', desc: '是否禁用', diff --git a/examples/api/checkbox.js b/examples/api/checkbox.js index 8c6e617dc..f25604c78 100644 --- a/examples/api/checkbox.js +++ b/examples/api/checkbox.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.checkbox.desc.value', version: '', type: 'any', diff --git a/examples/api/column.js b/examples/api/column.js index cdf3c8736..6c482f26a 100644 --- a/examples/api/column.js +++ b/examples/api/column.js @@ -248,7 +248,7 @@ const apis = [ version: '3.1.1', type: 'string', enum: 'auto, number, string', - defVal: '', + defVal: 'auto', list: [] }, { diff --git a/examples/api/input.js b/examples/api/input.js index 3d128b886..a15b690fc 100644 --- a/examples/api/input.js +++ b/examples/api/input.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.input.desc.value', version: '', type: 'any', @@ -304,7 +304,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -313,7 +313,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -322,7 +322,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -331,7 +331,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -340,7 +340,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -349,7 +349,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -358,7 +358,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -367,7 +367,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -376,7 +376,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -385,7 +385,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -394,7 +394,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -403,7 +403,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ visible, $event }', + defVal: '{ value, visible, $event }', list: [] }, { @@ -412,7 +412,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -421,7 +421,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -430,7 +430,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -439,7 +439,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -448,7 +448,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -457,7 +457,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -466,7 +466,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] } ] diff --git a/examples/api/modal.js b/examples/api/modal.js index f11481810..d4fa36ffa 100644 --- a/examples/api/modal.js +++ b/examples/api/modal.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.modal.desc.value', version: '', type: 'any', diff --git a/examples/api/radio-button.js b/examples/api/radio-button.js index 85c4c8789..c058692e8 100644 --- a/examples/api/radio-button.js +++ b/examples/api/radio-button.js @@ -7,6 +7,15 @@ const apis = [ enum: '', defVal: '', list: [ + { + name: 'v-model / value', + descKey: 'app.api.radio.desc.value', + version: '', + type: 'any', + enum: '', + defVal: '', + list: [] + }, { name: 'label', desc: '绑定值', diff --git a/examples/api/radio-group.js b/examples/api/radio-group.js index c76d1e3bf..21510dc52 100644 --- a/examples/api/radio-group.js +++ b/examples/api/radio-group.js @@ -8,14 +8,23 @@ const apis = [ defVal: '', list: [ { - name: 'label', - desc: '绑定值', + name: 'v-model / value', + descKey: 'app.api.radio.desc.value', version: '', - type: 'string | number', + type: 'any[]', enum: '', defVal: '', list: [] }, + { + name: 'size', + descKey: 'app.api.radio.desc.size', + version: '', + type: 'string', + enum: 'medium, small, mini', + defVal: '继承上下文', + list: [] + }, { name: 'disabled', desc: '是否禁用', diff --git a/examples/api/radio.js b/examples/api/radio.js index d6921cfa3..c9c44c2b6 100644 --- a/examples/api/radio.js +++ b/examples/api/radio.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.radio.desc.value', version: '', type: 'any', diff --git a/examples/api/select.js b/examples/api/select.js index f22e9cda6..2acaa409a 100644 --- a/examples/api/select.js +++ b/examples/api/select.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.select.desc.value', version: '', type: 'any', diff --git a/examples/api/switch.js b/examples/api/switch.js index b651d5ef4..8d6379569 100644 --- a/examples/api/switch.js +++ b/examples/api/switch.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.switch.desc.value', version: '', type: 'string | number | boolean', diff --git a/examples/api/textarea.js b/examples/api/textarea.js index 90c186970..8f310d30a 100644 --- a/examples/api/textarea.js +++ b/examples/api/textarea.js @@ -8,7 +8,7 @@ const apis = [ defVal: '', list: [ { - name: 'v-model', + name: 'v-model / value', descKey: 'app.api.input.desc.value', version: '', type: 'any', @@ -168,7 +168,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -177,7 +177,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -186,7 +186,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -195,7 +195,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -204,7 +204,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -213,7 +213,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -222,7 +222,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -231,7 +231,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] }, { @@ -240,7 +240,7 @@ const apis = [ version: '', type: '', enum: '', - defVal: '{ $event }', + defVal: '{ value, $event }', list: [] } ] diff --git a/examples/views/table/base/Sort.vue b/examples/views/table/base/Sort.vue index bf71c0f76..3de01dbab 100644 --- a/examples/views/table/base/Sort.vue +++ b/examples/views/table/base/Sort.vue @@ -2,7 +2,7 @@

通过给需要排序功能的列加上 属性可以支持排序,还可以通过设置 多字段进行排序
- 如果该列的值为字符串类型,但实际是数值,可以设置 ='number' 按数值类型进行排序
+ 如果该列的值为字符串类型,但实际是数值,可以设置 =number|string 按指定类型进行排序,默认 auto 自动转换数值
如果是服务端排序,只需加上 . 事件就可以实现
还可以通过调用 方法实现手动排序

@@ -25,7 +25,7 @@ - + @@ -188,7 +188,7 @@ export default { - + diff --git a/package.json b/package.json index 626974097..326173be5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table", - "version": "3.1.0", + "version": "3.1.1", "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...", "scripts": { "serve": "vue-cli-service serve", diff --git a/packages/grid/src/grid.js b/packages/grid/src/grid.js index 22a48cdca..3b0163b78 100644 --- a/packages/grid/src/grid.js +++ b/packages/grid/src/grid.js @@ -52,53 +52,68 @@ function renderDefaultForm (h, _vm) { return [] } +function getFuncSlot (_vm, optSlots, slotKey) { + const { $scopedSlots } = _vm + const funcSlot = optSlots[slotKey] + if (funcSlot) { + if (XEUtils.isString(funcSlot)) { + if ($scopedSlots[funcSlot]) { + return $scopedSlots[funcSlot] + } else { + if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') { + UtilTools.error('vxe.error.notSlot', [funcSlot]) + } + } + } else { + return funcSlot + } + } + return null +} + function getToolbarSlots (_vm) { const { $scopedSlots, toolbarOpts } = _vm const toolbarOptSlots = toolbarOpts.slots - let $buttons - let $tools + let buttonsSlot + let toolsSlot const slots = {} + if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') { + if ($scopedSlots.buttons && (!toolbarOptSlots || toolbarOptSlots.buttons !== 'buttons')) { + UtilTools.warn('vxe.error.reqProp', ['toolbar-config.slots.buttons']) + } + if ($scopedSlots.tools && (!toolbarOptSlots || toolbarOptSlots.tools !== 'tools')) { + UtilTools.warn('vxe.error.reqProp', ['toolbar-config.slots.tools']) + } + } if (toolbarOptSlots) { - $buttons = toolbarOptSlots.buttons - $tools = toolbarOptSlots.tools - if ($buttons && $scopedSlots[$buttons]) { - $buttons = $scopedSlots[$buttons] + buttonsSlot = getFuncSlot(_vm, toolbarOptSlots, 'buttons') + toolsSlot = getFuncSlot(_vm, toolbarOptSlots, 'tools') + if (buttonsSlot) { + slots.buttons = buttonsSlot } - if ($tools && $scopedSlots[$tools]) { - $tools = $scopedSlots[$tools] + if (toolsSlot) { + slots.tools = toolsSlot } } - if ($buttons) { - slots.buttons = $buttons - } - if ($tools) { - slots.tools = $tools - } return slots } function getPagerSlots (_vm) { - const { $scopedSlots, pagerOpts } = _vm + const { pagerOpts } = _vm const pagerOptSlots = pagerOpts.slots const slots = {} - let $left - let $right + let leftSlot + let rightSlot if (pagerOptSlots) { - $left = pagerOptSlots.left - $right = pagerOptSlots.right - if ($left && $scopedSlots[$left]) { - $left = $scopedSlots[$left] + leftSlot = getFuncSlot(_vm, pagerOptSlots, 'left') + rightSlot = getFuncSlot(_vm, pagerOptSlots, 'right') + if (leftSlot) { + slots.left = leftSlot } - if ($right && $scopedSlots[$right]) { - $right = $scopedSlots[$right] + if (rightSlot) { + slots.right = rightSlot } } - if ($left) { - slots.left = $left - } - if ($right) { - slots.right = $right - } return slots } diff --git a/packages/table/src/methods.js b/packages/table/src/methods.js index 40a18ca3d..234912548 100644 --- a/packages/table/src/methods.js +++ b/packages/table/src/methods.js @@ -236,20 +236,21 @@ function clearAllSort (_vm) { } function getOrderField (_vm, column) { - const { property, sortBy, sortType, formatter } = column + const { sortBy, sortType } = column if (sortBy) { return XEUtils.isArray(sortBy) ? sortBy[0] : sortBy - } else if (sortType === 'auto') { - return (row) => { - const cellValue = _vm.getCellLabel(row, column) - return isNaN(cellValue) ? cellValue : XEUtils.toNumber(cellValue) - } - } else if (sortType === 'number') { - return (row) => XEUtils.toNumber(_vm.getCellLabel(row, column)) - } else if (formatter) { - return (row) => _vm.getCellLabel(row, column) } - return property + return (row) => { + const cellValue = _vm.getCellLabel(row, column) + if (!sortType || sortType === 'auto') { + return isNaN(cellValue) ? cellValue : XEUtils.toNumber(cellValue) + } else if (sortType === 'number') { + return XEUtils.toNumber(cellValue) + } else if (sortType === 'string') { + return XEUtils.toString(cellValue) + } + return cellValue + } } const Methods = { diff --git a/packages/table/src/table.js b/packages/table/src/table.js index b5b60441c..7be687e69 100644 --- a/packages/table/src/table.js +++ b/packages/table/src/table.js @@ -126,7 +126,7 @@ export default { // 是否显示表尾合计 showFooter: Boolean, // 表尾合计的计算方法 - footerMethod: { type: Function, default: () => GlobalConfig.table.footerMethod }, + footerMethod: { type: Function, default: GlobalConfig.table.footerMethod }, // 给行附加 className rowClassName: [String, Function], // 给单元格附加 className @@ -693,6 +693,9 @@ export default { if (treeConfig && treeOpts.line && (!this.rowKey || !showOverflow)) { UtilTools.warn('vxe.error.reqProp', ['row-key | show-overflow']) } + if (this.showFooter && !this.footerMethod) { + UtilTools.warn('vxe.error.reqProp', ['footer-method']) + } if (treeConfig && this.stripe) { UtilTools.warn('vxe.error.noTree', ['stripe']) } diff --git a/packages/tools/src/utils.js b/packages/tools/src/utils.js index facd0660c..8fbf2b075 100644 --- a/packages/tools/src/utils.js +++ b/packages/tools/src/utils.js @@ -221,7 +221,7 @@ export const UtilTools = { if (groupConfig) { if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') { if ($xecolumn.$options._componentTag === 'vxe-table-column') { - UtilTools.warn('vxe.error.groupTag', [``, ``]) + UtilTools.error('vxe.error.groupTag', [``, ``]) } } if (!groupConfig.children) {