mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
feat: improve code
This commit is contained in:
parent
d9ad97fb17
commit
4388daea08
@ -59,12 +59,12 @@ DeleteActionModel.registerFlow({
|
||||
ctx.globals.message.error('No resource selected for deletion.');
|
||||
return;
|
||||
}
|
||||
if (!ctx.shared.currentRecord) {
|
||||
if (!ctx.extra.currentRecord) {
|
||||
ctx.globals.message.error('No resource or record selected for deletion.');
|
||||
return;
|
||||
}
|
||||
const resource = ctx.shared.currentBlockModel.resource as MultiRecordResource;
|
||||
await resource.destroy(ctx.shared.currentRecord);
|
||||
await resource.destroy(ctx.extra.currentRecord);
|
||||
ctx.globals.message.success('Record deleted successfully.');
|
||||
},
|
||||
},
|
||||
|
71
packages/core/client/src/flow/models/FilterActionModel.tsx
Normal file
71
packages/core/client/src/flow/models/FilterActionModel.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { MultiRecordResource } from '@nocobase/flow-engine';
|
||||
import { Button, Input, Popover } from 'antd';
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
import { ActionModel } from './ActionModel';
|
||||
|
||||
export class FilterActionModel extends ActionModel {
|
||||
title = 'Filter';
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Popover
|
||||
content={
|
||||
<div>
|
||||
<Input
|
||||
placeholder="Nickname, email, phone, etc."
|
||||
onChange={_.debounce((e) => {
|
||||
const resource = this.ctx.shared?.currentBlockModel?.resource as MultiRecordResource;
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
resource.addFilterGroup(this.uid, {
|
||||
$or: [
|
||||
{ ['nickname.$includes']: e.target.value },
|
||||
{ ['email.$includes']: e.target.value },
|
||||
{ ['phone.$includes']: e.target.value },
|
||||
],
|
||||
});
|
||||
resource.refresh();
|
||||
}, 500)}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
trigger="click"
|
||||
placement="bottom"
|
||||
>
|
||||
<Button type={this.type} {...this.props}>
|
||||
{this.props.children || this.title}
|
||||
</Button>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FilterActionModel.registerFlow({
|
||||
key: 'event1',
|
||||
on: {
|
||||
eventName: 'click',
|
||||
},
|
||||
steps: {
|
||||
step1: {
|
||||
async handler(ctx, params) {
|
||||
if (!ctx.shared?.currentBlockModel?.resource) {
|
||||
ctx.globals.message.error('No resource selected for refresh.');
|
||||
return;
|
||||
}
|
||||
const currentBlockModel = ctx.shared.currentBlockModel;
|
||||
await currentBlockModel.resource.refresh();
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
@ -25,7 +25,7 @@ LinkActionModel.registerFlow({
|
||||
step1: {
|
||||
handler(ctx, params) {
|
||||
ctx.globals.modal.confirm({
|
||||
title: `${ctx.shared.currentRecord?.id}`,
|
||||
title: `${ctx.extra.currentRecord?.id}`,
|
||||
content: 'Are you sure you want to perform this action?',
|
||||
});
|
||||
},
|
||||
|
33
packages/core/client/src/flow/models/RefreshActionModel.tsx
Normal file
33
packages/core/client/src/flow/models/RefreshActionModel.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { ActionModel } from './ActionModel';
|
||||
|
||||
export class RefreshActionModel extends ActionModel {
|
||||
title = 'Refresh';
|
||||
}
|
||||
|
||||
RefreshActionModel.registerFlow({
|
||||
key: 'event1',
|
||||
on: {
|
||||
eventName: 'click',
|
||||
},
|
||||
steps: {
|
||||
step1: {
|
||||
async handler(ctx, params) {
|
||||
if (!ctx.shared?.currentBlockModel?.resource) {
|
||||
ctx.globals.message.error('No resource selected for refresh.');
|
||||
return;
|
||||
}
|
||||
const currentBlockModel = ctx.shared.currentBlockModel;
|
||||
await currentBlockModel.resource.refresh();
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
@ -34,7 +34,7 @@ SubmitActionModel.registerFlow({
|
||||
await currentBlockModel.form.submit();
|
||||
const values = currentBlockModel.form.values;
|
||||
await currentBlockModel.resource.save(values);
|
||||
console.log('Form submitted successfully:', ctx.shared.parentBlockModel);
|
||||
await currentBlockModel.form.reset();
|
||||
// currentResource.refresh();
|
||||
ctx.shared.parentBlockModel?.resource?.refresh();
|
||||
if (ctx.shared.currentDrawer) {
|
||||
|
@ -100,7 +100,7 @@ const Columns = observer<any>(({ record, model, index }) => {
|
||||
{model.mapSubModels('actions', (action: ActionModel) => {
|
||||
const fork = action.createFork({}, `${index}`);
|
||||
return (
|
||||
<FlowModelRenderer showFlowSettings key={fork.uid} model={fork} sharedContext={{ currentRecord: record }} />
|
||||
<FlowModelRenderer showFlowSettings key={fork.uid} model={fork} extraContext={{ currentRecord: record }} />
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
|
@ -35,7 +35,7 @@ ViewActionModel.registerFlow({
|
||||
parentId={ctx.model.uid}
|
||||
sharedContext={{
|
||||
currentDrawer,
|
||||
parentRecord: ctx.shared.currentRecord,
|
||||
parentRecord: ctx.extra.currentRecord,
|
||||
parentBlockModel: ctx.shared.currentBlockModel,
|
||||
}}
|
||||
/>
|
||||
|
@ -14,6 +14,7 @@ export * from './BlockGridFlowModel';
|
||||
export * from './BulkDeleteActionModel';
|
||||
export * from './CalendarBlockFlowModel';
|
||||
export * from './DeleteActionModel';
|
||||
export * from './FilterActionModel';
|
||||
export * from './FormFieldModel';
|
||||
export * from './FormModel';
|
||||
export * from './HtmlBlockFlowModel';
|
||||
@ -21,6 +22,7 @@ export * from './LinkActionModel';
|
||||
export * from './PageFlowModel';
|
||||
export * from './PageTabFlowModel';
|
||||
export * from './QuickEditForm';
|
||||
export * from './RefreshActionModel';
|
||||
export * from './SubmitActionModel';
|
||||
export * from './TableColumnModel';
|
||||
export * from './TableModel';
|
||||
|
@ -738,6 +738,13 @@ export class FlowModel<Structure extends { parent?: any; subModels?: any } = Def
|
||||
});
|
||||
}
|
||||
|
||||
get ctx() {
|
||||
return {
|
||||
globals: this.flowEngine.getContext(),
|
||||
shared: this.getSharedContext(),
|
||||
};
|
||||
}
|
||||
|
||||
public setSharedContext(ctx: Record<string, any>) {
|
||||
this._sharedContext = ctx;
|
||||
}
|
||||
|
@ -134,6 +134,13 @@ export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
||||
};
|
||||
}
|
||||
|
||||
get ctx() {
|
||||
return {
|
||||
globals: this.flowEngine.getContext(),
|
||||
shared: this.getSharedContext(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象及其原型链上的属性描述符
|
||||
*/
|
||||
|
@ -31,6 +31,8 @@ export abstract class BaseRecordResource<TData = any> extends APIResource<TData>
|
||||
headers: {} as Record<string, any>,
|
||||
};
|
||||
|
||||
protected filterGroups = new Map<string, any>();
|
||||
|
||||
protected splitValue(value: string | string[]): string[] {
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map((item) => item.trim());
|
||||
@ -104,7 +106,23 @@ export abstract class BaseRecordResource<TData = any> extends APIResource<TData>
|
||||
}
|
||||
|
||||
getFilter(): Record<string, any> {
|
||||
return this.request.params.filter;
|
||||
return {
|
||||
$and: [...this.filterGroups.values()].filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
resetFilter() {
|
||||
this.setFilter(this.getFilter());
|
||||
}
|
||||
|
||||
addFilterGroup(key: string, filter) {
|
||||
this.filterGroups.set(key, filter);
|
||||
this.resetFilter();
|
||||
}
|
||||
|
||||
removeFilterGroup(key: string) {
|
||||
this.filterGroups.delete(key);
|
||||
this.resetFilter();
|
||||
}
|
||||
|
||||
setAppends(appends: string[]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user