Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jun 19, 2024
1 parent 82845a5 commit 330fafa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 72 deletions.
84 changes: 14 additions & 70 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOpti
const { props = {} } = renderOpts
const { row, column } = params
let cellValue = XEUtils.get(row, column.field)
if (cellValue) {
cellValue = cellValue.format ? cellValue.format(props.format || defaultFormat) : XEUtils.toDateString(cellValue, dateFormatToVxeFormat(props.format || defaultFormat))
}
try {
if (cellValue) {
cellValue = cellValue.format ? cellValue.format(props.format || defaultFormat) : XEUtils.toDateString(cellValue, dateFormatToVxeFormat(props.format || defaultFormat))
}
} catch (e) {}
return cellValue
}

Expand Down Expand Up @@ -310,20 +312,6 @@ function cellText (cellValue: any): string[] {
return [formatText(cellValue)]
}

function renderOptions (options: any[], optionProps: VxeGlobalRendererHandles.RenderOptionProps) {
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
return XEUtils.map(options, (item, oIndex) => {
return h(resolveComponent('a-select-option') as ComponentOptions, {
key: oIndex,
value: item[valueProp],
disabled: item.disabled
}, {
default: () => cellText(item[labelProp])
})
})
}

function createFormItemRender (defaultProps?: { [key: string]: any }) {
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
const { data, field } = params
Expand Down Expand Up @@ -481,53 +469,37 @@ export const VXETablePluginAntd = {
},
ASelect: {
renderEdit (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const { options, optionGroups } = renderOpts
const { row, column } = params
const { attrs } = renderOpts
const cellValue = XEUtils.get(row, column.field)
const props = getCellEditFilterProps(renderOpts, params, cellValue)
const ons = getEditOns(renderOpts, params)
if (optionGroups) {
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
return [
h(resolveComponent('a-select') as ComponentOptions, {
...props,
...attrs,
options: optionGroups,
...ons
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('a-select-opt-group') as ComponentOptions, {
key: gIndex
}, {
label: () => {
return h('span', {}, group[groupLabel])
},
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
]
}
return [
h(resolveComponent('a-select') as ComponentOptions, {
...props,
...attrs,
options: props.options || options,
...ons
}, {
default: () => renderOptions(options, optionProps)
})
]
},
renderCell (renderOpts, params) {
return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
},
renderFilter (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const { options = [], optionGroups, optionGroupProps = {} } = renderOpts
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
const { column } = params
const { attrs } = renderOpts
return [
Expand All @@ -541,23 +513,11 @@ export const VXETablePluginAntd = {
key: oIndex,
...attrs,
...props,
options: groupOptions,
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
})
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('a-select-opt-group') as ComponentOptions, {
key: gIndex
}, {
label: () => {
return h('span', {}, group[groupLabel])
},
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
})
: column.filters.map((option, oIndex) => {
Expand All @@ -567,12 +527,11 @@ export const VXETablePluginAntd = {
key: oIndex,
...attrs,
...props,
options: props.options || options,
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
})
}, {
default: () => renderOptions(options, optionProps)
})
}))
]
Expand All @@ -593,43 +552,28 @@ export const VXETablePluginAntd = {
return cellValue == data
},
renderItemContent (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const { options = [], optionGroups } = renderOpts
const { data, field } = params
const { attrs } = renderOpts
const itemValue = XEUtils.get(data, field)
const props = getItemProps(renderOpts, params, itemValue)
const ons = getItemOns(renderOpts, params)
if (optionGroups) {
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
return [
h(resolveComponent('a-select') as ComponentOptions, {
...attrs,
...props,
options: optionGroups,
...ons
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('a-select-opt-group') as ComponentOptions, {
key: gIndex
}, {
label: () => {
return h('span', {}, group[groupLabel])
},
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
]
}
return [
h(resolveComponent('a-select') as ComponentOptions, {
...attrs,
...props,
options: props.options || options,
...ons
}, {
default: () => renderOptions(options, optionProps)
})
]
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-antd",
"version": "4.0.7",
"version": "4.0.8",
"description": "基于 vxe-table 的表格适配插件,用于兼容 ant-design-vue 组件库",
"scripts": {
"lib": "gulp build"
Expand Down Expand Up @@ -50,7 +50,7 @@
"prettier": "^2.1.2",
"sass": "^1.55.0",
"typescript": "^4.6.4",
"vue": "^3.4.23",
"vue": "^3.4.27",
"vxe-table": "^4.6.17"
},
"peerDependencies": {
Expand Down

0 comments on commit 330fafa

Please sign in to comment.