mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
feat: show block title
This commit is contained in:
parent
0f5952a6e1
commit
687780eda3
@ -12,6 +12,9 @@
|
|||||||
- **sortIndex: number**
|
- **sortIndex: number**
|
||||||
排序索引。
|
排序索引。
|
||||||
|
|
||||||
|
- **title: string**
|
||||||
|
模型标题,用于界面展示,例如区块标题。
|
||||||
|
|
||||||
- **props: IModelComponentProps**
|
- **props: IModelComponentProps**
|
||||||
组件属性,支持响应式。
|
组件属性,支持响应式。
|
||||||
|
|
||||||
@ -59,6 +62,9 @@
|
|||||||
- **getStepParams(...)**
|
- **getStepParams(...)**
|
||||||
支持多种重载,获取流步骤参数。
|
支持多种重载,获取流步骤参数。
|
||||||
|
|
||||||
|
- **setTitle(value: string)**
|
||||||
|
设置模型标题,能够为各个模型设置不同的标题。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 流注册与执行
|
### 流注册与执行
|
||||||
|
@ -34,6 +34,16 @@ export class DataBlockModel<T = DefaultStructure> extends BlockModel<T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get title() {
|
||||||
|
return (
|
||||||
|
this._title ||
|
||||||
|
`
|
||||||
|
${this.collection.title} ->
|
||||||
|
${this.collection.dataSource.displayName} ->
|
||||||
|
${this.translate(this.constructor['meta']?.title || this.constructor.name)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
addAppends(fieldPath: string, refresh = false) {
|
addAppends(fieldPath: string, refresh = false) {
|
||||||
const field = this.ctx.globals.dataSourceManager.getCollectionField(
|
const field = this.ctx.globals.dataSourceManager.getCollectionField(
|
||||||
`${this.collection.dataSourceKey}.${this.collection.name}.${fieldPath}`,
|
`${this.collection.dataSourceKey}.${this.collection.name}.${fieldPath}`,
|
||||||
|
@ -115,6 +115,7 @@ export class GridModel extends FlowModel<GridModelStructure> {
|
|||||||
fallback={<SkeletonFallback />}
|
fallback={<SkeletonFallback />}
|
||||||
showFlowSettings={{ showBackground: false }}
|
showFlowSettings={{ showBackground: false }}
|
||||||
showErrorFallback
|
showErrorFallback
|
||||||
|
showTitle
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
@ -26,6 +26,13 @@
|
|||||||
* hideRemoveInSettings={true}
|
* hideRemoveInSettings={true}
|
||||||
* />
|
* />
|
||||||
*
|
*
|
||||||
|
* // 显示设置和title
|
||||||
|
* <FlowModelRenderer
|
||||||
|
* model={myModel}
|
||||||
|
* showFlowSettings={true}
|
||||||
|
* showTitle={true}
|
||||||
|
* />
|
||||||
|
*
|
||||||
* // 使用右键菜单模式并隐藏删除按钮
|
* // 使用右键菜单模式并隐藏删除按钮
|
||||||
* <FlowModelRenderer
|
* <FlowModelRenderer
|
||||||
* model={myModel}
|
* model={myModel}
|
||||||
@ -62,6 +69,9 @@ interface FlowModelRendererProps {
|
|||||||
/** 是否在设置中隐藏移除按钮 */
|
/** 是否在设置中隐藏移除按钮 */
|
||||||
hideRemoveInSettings?: boolean; // 默认 false
|
hideRemoveInSettings?: boolean; // 默认 false
|
||||||
|
|
||||||
|
/** 是否在边框左上角显示模型title,默认 false */
|
||||||
|
showTitle?: boolean; // 默认 false
|
||||||
|
|
||||||
/** 是否跳过自动应用流程,默认 false */
|
/** 是否跳过自动应用流程,默认 false */
|
||||||
skipApplyAutoFlows?: boolean; // 默认 false
|
skipApplyAutoFlows?: boolean; // 默认 false
|
||||||
|
|
||||||
@ -89,6 +99,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
||||||
flowSettingsVariant: string;
|
flowSettingsVariant: string;
|
||||||
hideRemoveInSettings: boolean;
|
hideRemoveInSettings: boolean;
|
||||||
|
showTitle: boolean;
|
||||||
extraContext?: Record<string, any>;
|
extraContext?: Record<string, any>;
|
||||||
sharedContext?: Record<string, any>;
|
sharedContext?: Record<string, any>;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
@ -100,6 +111,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
showFlowSettings,
|
showFlowSettings,
|
||||||
flowSettingsVariant,
|
flowSettingsVariant,
|
||||||
hideRemoveInSettings,
|
hideRemoveInSettings,
|
||||||
|
showTitle,
|
||||||
extraContext,
|
extraContext,
|
||||||
sharedContext,
|
sharedContext,
|
||||||
showErrorFallback,
|
showErrorFallback,
|
||||||
@ -115,6 +127,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
showFlowSettings={showFlowSettings}
|
showFlowSettings={showFlowSettings}
|
||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
|
showTitle={showTitle}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
settingsMenuLevel={settingsMenuLevel}
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
extraToolbarItems={extraToolbarItems}
|
extraToolbarItems={extraToolbarItems}
|
||||||
@ -132,6 +145,7 @@ const FlowModelRendererWithoutAutoFlows: React.FC<{
|
|||||||
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
||||||
flowSettingsVariant: string;
|
flowSettingsVariant: string;
|
||||||
hideRemoveInSettings: boolean;
|
hideRemoveInSettings: boolean;
|
||||||
|
showTitle: boolean;
|
||||||
sharedContext?: Record<string, any>;
|
sharedContext?: Record<string, any>;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
settingsMenuLevel?: number;
|
settingsMenuLevel?: number;
|
||||||
@ -142,6 +156,7 @@ const FlowModelRendererWithoutAutoFlows: React.FC<{
|
|||||||
showFlowSettings,
|
showFlowSettings,
|
||||||
flowSettingsVariant,
|
flowSettingsVariant,
|
||||||
hideRemoveInSettings,
|
hideRemoveInSettings,
|
||||||
|
showTitle,
|
||||||
sharedContext,
|
sharedContext,
|
||||||
showErrorFallback,
|
showErrorFallback,
|
||||||
settingsMenuLevel,
|
settingsMenuLevel,
|
||||||
@ -154,6 +169,7 @@ const FlowModelRendererWithoutAutoFlows: React.FC<{
|
|||||||
showFlowSettings={showFlowSettings}
|
showFlowSettings={showFlowSettings}
|
||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
|
showTitle={showTitle}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
settingsMenuLevel={settingsMenuLevel}
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
extraToolbarItems={extraToolbarItems}
|
extraToolbarItems={extraToolbarItems}
|
||||||
@ -171,6 +187,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
showFlowSettings: boolean | { showBackground?: boolean; showBorder?: boolean };
|
||||||
flowSettingsVariant: string;
|
flowSettingsVariant: string;
|
||||||
hideRemoveInSettings: boolean;
|
hideRemoveInSettings: boolean;
|
||||||
|
showTitle: boolean;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
settingsMenuLevel?: number;
|
settingsMenuLevel?: number;
|
||||||
extraToolbarItems?: ToolbarItemConfig[];
|
extraToolbarItems?: ToolbarItemConfig[];
|
||||||
@ -180,6 +197,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
showFlowSettings,
|
showFlowSettings,
|
||||||
flowSettingsVariant,
|
flowSettingsVariant,
|
||||||
hideRemoveInSettings,
|
hideRemoveInSettings,
|
||||||
|
showTitle,
|
||||||
showErrorFallback,
|
showErrorFallback,
|
||||||
settingsMenuLevel,
|
settingsMenuLevel,
|
||||||
extraToolbarItems,
|
extraToolbarItems,
|
||||||
@ -205,6 +223,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
case 'dropdown':
|
case 'dropdown':
|
||||||
return (
|
return (
|
||||||
<FlowsFloatContextMenu
|
<FlowsFloatContextMenu
|
||||||
|
showTitle={showTitle}
|
||||||
model={model}
|
model={model}
|
||||||
showDeleteButton={!hideRemoveInSettings}
|
showDeleteButton={!hideRemoveInSettings}
|
||||||
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
||||||
@ -239,6 +258,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<FlowsFloatContextMenu
|
<FlowsFloatContextMenu
|
||||||
|
showTitle={showTitle}
|
||||||
model={model}
|
model={model}
|
||||||
showDeleteButton={!hideRemoveInSettings}
|
showDeleteButton={!hideRemoveInSettings}
|
||||||
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
||||||
@ -263,6 +283,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
* @param {boolean} props.showFlowSettings - Whether to show flow settings entry (buttons, menus, etc.).
|
* @param {boolean} props.showFlowSettings - Whether to show flow settings entry (buttons, menus, etc.).
|
||||||
* @param {string} props.flowSettingsVariant - The interaction style for flow settings.
|
* @param {string} props.flowSettingsVariant - The interaction style for flow settings.
|
||||||
* @param {boolean} props.hideRemoveInSettings - Whether to hide remove button in settings.
|
* @param {boolean} props.hideRemoveInSettings - Whether to hide remove button in settings.
|
||||||
|
* @param {boolean} props.showTitle - Whether to show model title in the top-left corner of the border.
|
||||||
* @param {boolean} props.skipApplyAutoFlows - Whether to skip applying auto flows.
|
* @param {boolean} props.skipApplyAutoFlows - Whether to skip applying auto flows.
|
||||||
* @param {any} props.extraContext - Extra context to pass to useApplyAutoFlows when skipApplyAutoFlows is false.
|
* @param {any} props.extraContext - Extra context to pass to useApplyAutoFlows when skipApplyAutoFlows is false.
|
||||||
* @param {any} props.sharedContext - Shared context to pass to the model.
|
* @param {any} props.sharedContext - Shared context to pass to the model.
|
||||||
@ -277,6 +298,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
showFlowSettings = false,
|
showFlowSettings = false,
|
||||||
flowSettingsVariant = 'dropdown',
|
flowSettingsVariant = 'dropdown',
|
||||||
hideRemoveInSettings = false,
|
hideRemoveInSettings = false,
|
||||||
|
showTitle = false,
|
||||||
skipApplyAutoFlows = false,
|
skipApplyAutoFlows = false,
|
||||||
extraContext,
|
extraContext,
|
||||||
sharedContext,
|
sharedContext,
|
||||||
@ -303,6 +325,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
showFlowSettings={showFlowSettings}
|
showFlowSettings={showFlowSettings}
|
||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
|
showTitle={showTitle}
|
||||||
sharedContext={sharedContext}
|
sharedContext={sharedContext}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
settingsMenuLevel={settingsMenuLevel}
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
@ -318,6 +341,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
showFlowSettings={showFlowSettings}
|
showFlowSettings={showFlowSettings}
|
||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
|
showTitle={showTitle}
|
||||||
extraContext={extraContext}
|
extraContext={extraContext}
|
||||||
sharedContext={sharedContext}
|
sharedContext={sharedContext}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
|
@ -117,6 +117,27 @@ const floatContainerStyles = ({ showBackground, showBorder }) => css`
|
|||||||
background: var(--colorTemplateBgSettingsHover);
|
background: var(--colorTemplateBgSettingsHover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> .general-schema-designer-title {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 0;
|
||||||
|
line-height: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border-bottom-right-radius: 2px;
|
||||||
|
border-radius: 2px;
|
||||||
|
top: 2px;
|
||||||
|
left: 2px;
|
||||||
|
|
||||||
|
.title-tag {
|
||||||
|
padding: 0 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: var(--colorSettings);
|
||||||
|
color: #fff;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
> .general-schema-designer-icons {
|
> .general-schema-designer-icons {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 2px;
|
right: 2px;
|
||||||
@ -156,6 +177,10 @@ interface ModelProvidedProps {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
showBackground?: boolean;
|
showBackground?: boolean;
|
||||||
|
/**
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
showTitle?: boolean;
|
||||||
/**
|
/**
|
||||||
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
||||||
*/
|
*/
|
||||||
@ -183,6 +208,10 @@ interface ModelByIdProps {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
showBackground?: boolean;
|
showBackground?: boolean;
|
||||||
|
/**
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
showTitle?: boolean;
|
||||||
/**
|
/**
|
||||||
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
||||||
*/
|
*/
|
||||||
@ -221,6 +250,7 @@ const isModelByIdProps = (props: FlowsFloatContextMenuProps): props is ModelById
|
|||||||
* @param props.showCopyUidButton 是否显示复制UID按钮,默认为true
|
* @param props.showCopyUidButton 是否显示复制UID按钮,默认为true
|
||||||
* @param props.containerStyle 容器自定义样式
|
* @param props.containerStyle 容器自定义样式
|
||||||
* @param props.className 容器自定义类名
|
* @param props.className 容器自定义类名
|
||||||
|
* @param props.showTitle 是否在边框左上角显示模型title,默认为false
|
||||||
* @param props.settingsMenuLevel 设置菜单层级:1=仅当前模型(默认),2=包含子模型
|
* @param props.settingsMenuLevel 设置菜单层级:1=仅当前模型(默认),2=包含子模型
|
||||||
* @param props.extraToolbarItems 额外的工具栏项目,仅应用于此实例
|
* @param props.extraToolbarItems 额外的工具栏项目,仅应用于此实例
|
||||||
*/
|
*/
|
||||||
@ -249,6 +279,7 @@ const FlowsFloatContextMenuWithModel: React.FC<ModelProvidedProps> = observer(
|
|||||||
className,
|
className,
|
||||||
showBackground = true,
|
showBackground = true,
|
||||||
showBorder = true,
|
showBorder = true,
|
||||||
|
showTitle = false,
|
||||||
settingsMenuLevel,
|
settingsMenuLevel,
|
||||||
extraToolbarItems,
|
extraToolbarItems,
|
||||||
}: ModelProvidedProps) => {
|
}: ModelProvidedProps) => {
|
||||||
@ -325,6 +356,11 @@ const FlowsFloatContextMenuWithModel: React.FC<ModelProvidedProps> = observer(
|
|||||||
|
|
||||||
{/* 悬浮工具栏 - 使用与 NocoBase 一致的结构 */}
|
{/* 悬浮工具栏 - 使用与 NocoBase 一致的结构 */}
|
||||||
<div className="general-schema-designer">
|
<div className="general-schema-designer">
|
||||||
|
{showTitle && model.title && (
|
||||||
|
<div className="general-schema-designer-title">
|
||||||
|
<span className="title-tag">{model.title}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="general-schema-designer-icons">
|
<div className="general-schema-designer-icons">
|
||||||
<Space size={3} align="center">
|
<Space size={3} align="center">
|
||||||
{renderToolbarItems(
|
{renderToolbarItems(
|
||||||
@ -355,6 +391,7 @@ const FlowsFloatContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
|||||||
showCopyUidButton = true,
|
showCopyUidButton = true,
|
||||||
containerStyle,
|
containerStyle,
|
||||||
className,
|
className,
|
||||||
|
showTitle = false,
|
||||||
settingsMenuLevel,
|
settingsMenuLevel,
|
||||||
extraToolbarItems: extraToolbarItems,
|
extraToolbarItems: extraToolbarItems,
|
||||||
}) => {
|
}) => {
|
||||||
@ -373,6 +410,7 @@ const FlowsFloatContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
|||||||
showCopyUidButton={showCopyUidButton}
|
showCopyUidButton={showCopyUidButton}
|
||||||
containerStyle={containerStyle}
|
containerStyle={containerStyle}
|
||||||
className={className}
|
className={className}
|
||||||
|
showTitle={showTitle}
|
||||||
settingsMenuLevel={settingsMenuLevel}
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
extraToolbarItems={extraToolbarItems}
|
extraToolbarItems={extraToolbarItems}
|
||||||
>
|
>
|
||||||
|
@ -47,6 +47,7 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
|
|||||||
public parent: ParentFlowModel<Structure>;
|
public parent: ParentFlowModel<Structure>;
|
||||||
public subModels: Structure['subModels'];
|
public subModels: Structure['subModels'];
|
||||||
private _options: FlowModelOptions<Structure>;
|
private _options: FlowModelOptions<Structure>;
|
||||||
|
protected _title: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有 fork 实例的引用集合。
|
* 所有 fork 实例的引用集合。
|
||||||
@ -135,6 +136,15 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
|
|||||||
return modelMetas.get(this);
|
return modelMetas.get(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get title() {
|
||||||
|
// model 可以通过 setTitle 来自定义title, 具有更高的优先级
|
||||||
|
return this._title || this.translate(this.constructor['meta']?.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTitle(value: string) {
|
||||||
|
this._title = value;
|
||||||
|
}
|
||||||
|
|
||||||
private createSubModels(subModels: Record<string, CreateSubModelOptions | CreateSubModelOptions[]>) {
|
private createSubModels(subModels: Record<string, CreateSubModelOptions | CreateSubModelOptions[]>) {
|
||||||
Object.entries(subModels || {}).forEach(([key, value]) => {
|
Object.entries(subModels || {}).forEach(([key, value]) => {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user