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

View File

@ -20,7 +20,7 @@ import {
MultiRecordResource,
} from '@nocobase/flow-engine';
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 React from 'react';
import { ColumnDefinition, TabulatorFull as Tabulator } from 'tabulator-tables';
@ -262,6 +262,7 @@ export class TabulatorModel extends DataBlockModel<S> {
render() {
return (
<Card>
<Spin spinning={this.resource.loading}>
<DndProvider>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<Space>
@ -269,7 +270,10 @@ export class TabulatorModel extends DataBlockModel<S> {
// @ts-ignore
if (action.props.position === 'left') {
return (
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
<FlowModelRenderer
model={action}
showFlowSettings={{ showBackground: false, showBorder: false }}
/>
);
}
@ -283,7 +287,10 @@ export class TabulatorModel extends DataBlockModel<S> {
// @ts-ignore
if (action.props.position !== 'left') {
return (
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
<FlowModelRenderer
model={action}
showFlowSettings={{ showBackground: false, showBorder: false }}
/>
);
}
@ -302,11 +309,13 @@ export class TabulatorModel extends DataBlockModel<S> {
total={this.resource.getMeta('count')}
showSizeChanger
onChange={async (page, pageSize) => {
this.resource.loading = true;
this.resource.setPage(page);
this.resource.setPageSize(pageSize);
await this.resource.refresh();
}}
/>
</Spin>
</Card>
);
}

View File

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