Skip to content

Commit

Permalink
Merge pull request #11426 from 2betop/chore-crud-1224
Browse files Browse the repository at this point in the history
chore: 补充 CRUD 配置面板
  • Loading branch information
hsm-lv authored Dec 25, 2024
2 parents 2c9fb07 + 7da2c57 commit 237d511
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/amis-core/src/utils/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const AMISDebug = observer(({store}: {store: AMISDebugStore}) => {
panelRef.current!.addEventListener('mouseup', handlePanelMouseUp);

return () => {
panelRef.current!.removeEventListener('mouseup', handlePanelMouseUp);
panelRef.current?.removeEventListener('mouseup', handlePanelMouseUp);
};
}, []);

Expand Down
27 changes: 27 additions & 0 deletions packages/amis-editor/src/plugin/CRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,33 @@ export class CRUDPlugin extends BasePlugin {
hiddenOn: 'this.mode && this.mode !== "table" || this.pickerMode'
},

getSchemaTpl('switch', {
name: 'selectable',
label: '开启选择',
pipeIn: defaultValue(false),
labelRemark: {
className: 'm-l-xs',
trigger: 'click',
rootClose: true,
content: '开启后即便没有批量操作按钮也显示可点选',
placement: 'left'
}
}),

getSchemaTpl('switch', {
name: 'multiple',
label: '开启多选',
visibleOn: '${selectable}',
pipeIn: defaultValue(true),
labelRemark: {
className: 'm-l-xs',
trigger: 'click',
rootClose: true,
content: '控制是单选还是多选',
placement: 'left'
}
}),

getSchemaTpl('switch', {
name: 'syncLocation',
label: '同步地址栏',
Expand Down
6 changes: 6 additions & 0 deletions packages/amis-editor/src/plugin/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,12 @@ export class TablePlugin extends BasePlugin {
]
},

getSchemaTpl('switch', {
name: 'showIndex',
label: '是否显示序号',
pipeIn: defaultValue(false)
}),

getSchemaTpl('switch', {
name: 'affixHeader',
label: '是否固定表头',
Expand Down
130 changes: 65 additions & 65 deletions packages/amis/src/renderers/Table/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,71 +77,6 @@ export default function Cell({
onCheck?.(item);
}, []);

if (column.type === '__checkme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
{...testIdBuilder?.getTestId()}
>
<Checkbox
classPrefix={ns}
type={multiple ? 'checkbox' : 'radio'}
partial={multiple ? item.partial : false}
checked={item.checked || (multiple ? item.partial : false)}
disabled={item.checkdisable || !item.checkable}
onChange={onCheckboxChange}
testIdBuilder={testIdBuilder?.getChild('chekbx')}
/>
</td>
);
} else if (column.type === '__dragme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName, {
'is-dragDisabled': !item.draggable
})}
{...testIdBuilder?.getChild('drag').getTestId()}
>
{item.draggable ? <Icon icon="drag" className="icon" /> : null}
</td>
);
} else if (column.type === '__expandme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
>
{item.expandable ? (
<a
className={cx('Table-expandBtn', item.expanded ? 'is-active' : '')}
// data-tooltip="展开/收起"
// data-position="top"
onClick={item.toggleExpanded}
{...testIdBuilder
?.getChild(item.expanded ? 'fold' : 'expand')
.getTestId()}
>
<Icon icon="right-arrow-bold" className="icon" />
</a>
) : null}
</td>
);
} else if (column.type === '__index') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
>
{`${filterItemIndex ? filterItemIndex(item.path, item) : item.path}`
.split('.')
.map(a => parseInt(a, 10) + 1)
.join('.')}
</td>
);
}

let [prefix, affix, addtionalClassName] = React.useMemo(() => {
let prefix: React.ReactNode[] = [];
let affix: React.ReactNode[] = [];
Expand Down Expand Up @@ -273,6 +208,71 @@ export default function Cell({
};
delete subProps.label;

if (column.type === '__checkme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
{...testIdBuilder?.getTestId()}
>
<Checkbox
classPrefix={ns}
type={multiple ? 'checkbox' : 'radio'}
partial={multiple ? item.partial : false}
checked={item.checked || (multiple ? item.partial : false)}
disabled={item.checkdisable || !item.checkable}
onChange={onCheckboxChange}
testIdBuilder={testIdBuilder?.getChild('chekbx')}
/>
</td>
);
} else if (column.type === '__dragme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName, {
'is-dragDisabled': !item.draggable
})}
{...testIdBuilder?.getChild('drag').getTestId()}
>
{item.draggable ? <Icon icon="drag" className="icon" /> : null}
</td>
);
} else if (column.type === '__expandme') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
>
{item.expandable ? (
<a
className={cx('Table-expandBtn', item.expanded ? 'is-active' : '')}
// data-tooltip="展开/收起"
// data-position="top"
onClick={item.toggleExpanded}
{...testIdBuilder
?.getChild(item.expanded ? 'fold' : 'expand')
.getTestId()}
>
<Icon icon="right-arrow-bold" className="icon" />
</a>
) : null}
</td>
);
} else if (column.type === '__index') {
return (
<td
style={style}
className={cx(column.pristine.className, stickyClassName)}
>
{`${filterItemIndex ? filterItemIndex(item.path, item) : item.path}`
.split('.')
.map(a => parseInt(a, 10) + 1)
.join('.')}
</td>
);
}

return render(
region,
{
Expand Down
8 changes: 4 additions & 4 deletions packages/amis/src/renderers/Table/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ export class TableRow<
<tbody>
{ignoreFootableContent
? columns.map(column => (
<tr key={column.index}>
<tr key={column.id}>
{column.label !== false ? <th></th> : null}
<td></td>
</tr>
))
: columns.map(column => (
<tr key={column.index}>
<tr key={column.id}>
{column.label !== false ? (
<th>
{render(
Expand All @@ -275,14 +275,14 @@ export class TableRow<
rowIndexPath: item.path,
colIndex: column.index,
rowPath,
key: column.index,
key: column.id,
onAction: this.handleAction,
onQuickChange: this.handleQuickChange,
onChange: this.handleChange
}
)
) : (
<td key={column.index}>
<td key={column.id}>
<div className={cx('Table-emptyBlock')}>&nbsp;</div>
</td>
)}
Expand Down

0 comments on commit 237d511

Please sign in to comment.