fix: indexof

This commit is contained in:
chenos 2025-06-29 22:16:20 +08:00
parent ec7a5fb534
commit 82a82e9230
3 changed files with 61 additions and 49 deletions

View File

@ -141,6 +141,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
color: #1890ff; color: #1890ff;
margin-left: 8px; margin-left: 8px;
cursor: pointer; cursor: pointer;
z-index: 100;
top: 50%; top: 50%;
right: 8px; right: 8px;
transform: translateY(-50%); transform: translateY(-50%);
@ -157,6 +158,9 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
<EditOutlined <EditOutlined
className="edit-icon" className="edit-icon"
onClick={async (e) => { onClick={async (e) => {
e.preventDefault();
e.stopPropagation();
// 阻止事件冒泡,避免触发行选中
try { try {
await QuickEditForm.open({ await QuickEditForm.open({
target: ref.current, target: ref.current,
@ -266,7 +270,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
selectedRowKeys: this.resource.getSelectedRows().map((row) => row.id), selectedRowKeys: this.resource.getSelectedRows().map((row) => row.id),
}} }}
virtual={this.props.virtual} virtual={this.props.virtual}
scroll={{ x: 'max-content', y: 'calc(100vh - 200px)' }} scroll={{ x: 'max-content', y: 600 }}
dataSource={this.resource.getData()} dataSource={this.resource.getData()}
columns={this.getColumns()} columns={this.getColumns()}
pagination={{ pagination={{
@ -276,9 +280,9 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
}} }}
onChange={(pagination) => { onChange={(pagination) => {
console.log('onChange pagination:', pagination); console.log('onChange pagination:', pagination);
this.resource.loading = true;
this.resource.setPage(pagination.current); this.resource.setPage(pagination.current);
this.resource.setPageSize(pagination.pageSize); this.resource.setPageSize(pagination.pageSize);
this.resource.loading = true;
this.resource.refresh(); this.resource.refresh();
}} }}
/> />

View File

@ -20,7 +20,7 @@ import {
MultiRecordResource, MultiRecordResource,
} from '@nocobase/flow-engine'; } from '@nocobase/flow-engine';
import { tval } from '@nocobase/utils/client'; import { tval } from '@nocobase/utils/client';
import { Button, Card, Pagination, Skeleton, Space } from 'antd'; import { Button, Card, Pagination, Skeleton, Space, Spin } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
import React from 'react'; import React from 'react';
import { ColumnDefinition, TabulatorFull as Tabulator } from 'tabulator-tables'; import { ColumnDefinition, TabulatorFull as Tabulator } from 'tabulator-tables';
@ -262,51 +262,60 @@ export class TabulatorModel extends DataBlockModel<S> {
render() { render() {
return ( return (
<Card> <Card>
<DndProvider> <Spin spinning={this.resource.loading}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}> <DndProvider>
<Space> <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
{this.mapSubModels('actions', (action) => { <Space>
// @ts-ignore {this.mapSubModels('actions', (action) => {
if (action.props.position === 'left') { // @ts-ignore
return ( if (action.props.position === 'left') {
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} /> return (
); <FlowModelRenderer
} model={action}
showFlowSettings={{ showBackground: false, showBorder: false }}
/>
);
}
return null; return null;
})} })}
{/* 占位 */} {/* 占位 */}
<span></span> <span></span>
</Space> </Space>
<Space> <Space>
{this.mapSubModels('actions', (action) => { {this.mapSubModels('actions', (action) => {
// @ts-ignore // @ts-ignore
if (action.props.position !== 'left') { if (action.props.position !== 'left') {
return ( return (
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} /> <FlowModelRenderer
); model={action}
} showFlowSettings={{ showBackground: false, showBorder: false }}
/>
);
}
return null; return null;
})} })}
<AddActionButton model={this} subModelBaseClass="GlobalActionModel" subModelKey="actions" /> <AddActionButton model={this} subModelBaseClass="GlobalActionModel" subModelKey="actions" />
</Space> </Space>
</div> </div>
</DndProvider> </DndProvider>
<div ref={this.tabulatorRef} /> <div ref={this.tabulatorRef} />
<Pagination <Pagination
style={{ marginTop: 16 }} style={{ marginTop: 16 }}
align="end" align="end"
defaultCurrent={this.resource.getMeta('page')} defaultCurrent={this.resource.getMeta('page')}
defaultPageSize={this.resource.getMeta('pageSize')} defaultPageSize={this.resource.getMeta('pageSize')}
total={this.resource.getMeta('count')} total={this.resource.getMeta('count')}
showSizeChanger showSizeChanger
onChange={async (page, pageSize) => { onChange={async (page, pageSize) => {
this.resource.setPage(page); this.resource.loading = true;
this.resource.setPageSize(pageSize); this.resource.setPage(page);
await this.resource.refresh(); this.resource.setPageSize(pageSize);
}} await this.resource.refresh();
/> }}
/>
</Spin>
</Card> </Card>
); );
} }

View File

@ -361,20 +361,19 @@ export class FlowEngine {
const subModelValue = modelInstance.parent.subModels[subKey]; const subModelValue = modelInstance.parent.subModels[subKey];
if (Array.isArray(subModelValue)) { if (Array.isArray(subModelValue)) {
const index = subModelValue.indexOf(modelInstance); const index = subModelValue.findIndex((subModel) => subModel.uid === modelInstance.uid);
if (index !== -1) { if (index !== -1) {
subModelValue.splice(index, 1); subModelValue.splice(index, 1);
modelInstance.parent.emitter.emit('onSubModelRemoved', modelInstance); modelInstance.parent.emitter.emit('onSubModelRemoved', modelInstance);
break; break;
} }
} else if (subModelValue === modelInstance) { } else if (subModelValue && subModelValue.uid === modelInstance.uid) {
delete modelInstance.parent.subModels[subKey]; delete modelInstance.parent.subModels[subKey];
modelInstance.parent.emitter.emit('onSubModelRemoved', modelInstance); modelInstance.parent.emitter.emit('onSubModelRemoved', modelInstance);
break; break;
} }
} }
} }
modelInstance['onRemove']?.();
this.modelInstances.delete(uid); this.modelInstances.delete(uid);
return false; return false;
} }