Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增自定义校验插槽 #2302

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/views/table/edit/CellValid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
</vxe-colgroup>
<vxe-colgroup title="分组2">
<vxe-colgroup title="分组21">
<vxe-column field="sex2" title="Sex" :edit-render="{name: 'input'}"></vxe-column>
<vxe-column field="sex2" title="Sex" :edit-render="{name: 'input'}">
<template #valid="params">
<span class="red">{{ params }}</span>
</template>
</vxe-column>
<vxe-column field="age" title="Age" :edit-render="{name: '$input', props: {type: 'integer'}}"></vxe-column>
<vxe-column field="date" title="Date" :edit-render="{name: '$input', props: {type: 'date'}}"></vxe-column>
</vxe-colgroup>
Expand Down
37 changes: 22 additions & 15 deletions packages/table/src/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineComponent({
fixedColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
fixedType: { type: String as PropType<VxeColumnPropTypes.Fixed>, default: null }
},
setup (props) {
setup(props) {
const $xetable = inject('$xetable', {} as VxeTableConstructor & VxeTableMethods & VxeTablePrivateMethods)

const xesize = inject('xesize', null as ComputedRef<SizeType> | null)
Expand Down Expand Up @@ -134,7 +134,7 @@ export default defineComponent({
const rowOpts = computeRowOpts.value
const sYOpts = computeSYOpts.value
const columnOpts = computeColumnOpts.value
const { type, cellRender, editRender, align, showOverflow, className, treeNode } = column
const { type, cellRender, editRender, align, showOverflow, className, treeNode, slots } = column
const { actived } = editStore
const { rHeight: scrollYRHeight } = sYOpts
const { height: rowHeight } = rowOpts
Expand Down Expand Up @@ -273,18 +273,25 @@ export default defineComponent({
}, column.renderCell(params))
)
if (showValidTip && errorValidItem) {
tdVNs.push(
h('div', {
class: 'vxe-cell--valid-error-hint',
style: errorValidItem.rule && errorValidItem.rule.maxWidth ? {
width: `${errorValidItem.rule.maxWidth}px`
} : null
}, [
h('span', {
class: 'vxe-cell--valid-error-msg'
}, errorValidItem.content)
])
)
if (slots.valid) {
const validErrorSlot = $xetable.callSlot(slots.valid, errorValidItem)
tdVNs.push(
h('div', { class: 'vxe-cell--valid-error-slot' }, validErrorSlot)
)
} else {
tdVNs.push(
h('div', {
class: 'vxe-cell--valid-error-hint',
style: errorValidItem.rule && errorValidItem.rule.maxWidth ? {
width: `${errorValidItem.rule.maxWidth}px`
} : null
}, [
h('span', {
class: 'vxe-cell--valid-error-msg'
}, errorValidItem.content)
])
)
}
}
}

Expand Down Expand Up @@ -840,7 +847,7 @@ export default defineComponent({
}, mouseOpts.extension ? [
h('span', {
class: 'vxe-table--cell-main-area-btn',
onMousedown (evnt: any) {
onMousedown(evnt: any) {
$xetable.triggerCellExtendMousedownEvent(evnt, { $table: $xetable, fixed: fixedType, type: renderType })
}
})
Expand Down
8 changes: 6 additions & 2 deletions types/column.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export namespace VxeColumnPropTypes {
message?: string
}

export interface TitleHelp extends TitlePrefix {}
export interface TitleHelp extends TitlePrefix { }

export type CellType = 'auto' | 'number' | 'string'

Expand Down Expand Up @@ -405,7 +405,7 @@ export namespace VxeColumnSlotTypes {
data: D[][]
}

export interface HeaderSlotParams<D = VxeTableDataRow> extends VxeTableDefines.CellRenderHeaderParams<D> {}
export interface HeaderSlotParams<D = VxeTableDataRow> extends VxeTableDefines.CellRenderHeaderParams<D> { }

export interface ContentSlotParams<D = VxeTableDataRow> {
column: VxeTableDefines.ColumnInfo<D>
Expand Down Expand Up @@ -473,4 +473,8 @@ export interface VxeColumnSlots<D = VxeTableDataRow> {
* @deprecated
*/
icon: (params: VxeColumnSlotTypes.IconSlotParams<D>) => any
/**
* 只对 edit-render 启用时有效,自定义展示错误校验模板
*/
valid: (params: { row: any; column: any; rule: any; content: any; }) => any
}