f
This commit is contained in:
@@ -62,14 +62,27 @@ setupVbenVxeTable({
|
||||
},
|
||||
});
|
||||
|
||||
// 表格配置项可以用 cellRender: { name: 'CellLink' },
|
||||
// 表格配置项可以用 cellRender: { name: 'CellLink' };未传 text 时默认展示当前列字段值
|
||||
vxeUI.renderer.add('CellLink', {
|
||||
renderTableDefault(renderOpts) {
|
||||
renderTableDefault(renderOpts, params) {
|
||||
const { props } = renderOpts;
|
||||
const { column, row } = params;
|
||||
const raw =
|
||||
props?.text !== undefined && props?.text !== null && props?.text !== ''
|
||||
? props.text
|
||||
: get(row, column.field);
|
||||
const display =
|
||||
raw === null || raw === undefined || raw === '' ? '—' : String(raw);
|
||||
return h(
|
||||
Button,
|
||||
{ size: 'small', type: 'link' },
|
||||
{ default: () => props?.text },
|
||||
{
|
||||
size: 'small',
|
||||
type: 'link',
|
||||
onClick: isFunction(props?.onClick)
|
||||
? () => (props.onClick as (r: Recordable) => void)(row)
|
||||
: undefined,
|
||||
},
|
||||
{ default: () => display },
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -160,10 +173,10 @@ setupVbenVxeTable({
|
||||
return presets[opt]
|
||||
? { code: opt, ...presets[opt], ...defaultProps }
|
||||
: {
|
||||
code: opt,
|
||||
text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt,
|
||||
...defaultProps,
|
||||
};
|
||||
code: opt,
|
||||
text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt,
|
||||
...defaultProps,
|
||||
};
|
||||
} else {
|
||||
return { ...defaultProps, ...presets[opt.code], ...opt };
|
||||
}
|
||||
@@ -177,6 +190,17 @@ setupVbenVxeTable({
|
||||
})
|
||||
.filter((opt) => opt.show !== false);
|
||||
|
||||
function isOperationDisabled(opt: Recordable<any>, r: Recordable<any>) {
|
||||
const d = opt.disabled;
|
||||
if (d === true) {
|
||||
return true;
|
||||
}
|
||||
if (isFunction(d)) {
|
||||
return !!d(r);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function renderBtn(opt: Recordable<any>, listen = true) {
|
||||
return h(
|
||||
Button,
|
||||
@@ -185,11 +209,15 @@ setupVbenVxeTable({
|
||||
...opt,
|
||||
icon: undefined,
|
||||
onClick: listen
|
||||
? () =>
|
||||
? () => {
|
||||
if (isOperationDisabled(opt, row)) {
|
||||
return;
|
||||
}
|
||||
attrs?.onClick?.({
|
||||
code: opt.code,
|
||||
row,
|
||||
})
|
||||
});
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
@@ -225,6 +253,9 @@ setupVbenVxeTable({
|
||||
...opt,
|
||||
icon: undefined,
|
||||
onConfirm: () => {
|
||||
if (isOperationDisabled(opt, row)) {
|
||||
return;
|
||||
}
|
||||
attrs?.onClick?.({
|
||||
code: opt.code,
|
||||
row,
|
||||
|
||||
Reference in New Issue
Block a user