跳到内容

布局

布局用于在一条消息中排列多个 cell。cell 可以是文本,也可以是组件。布局只描述排列结构,不表达业务语义,也不包含视觉渲染器。

应用不能定义自定义布局。需要布局能力时,启用 MFUI SDK 提供的内置布局;自定义业务内容仍然通过自定义组件表达。

mfui.columns

mfui.columns 用于把两个或三个相关内容并排展示。

启用

mfui.columns 不会自动启用。应用需要从 @mfui/client/layouts 导入 columnsLayout,并把它放进请求 manifest 的 layouts 中。

ts
import { createMFUIManifest } from '@mfui/client';
import { timelineDefinition } from '@mfui/client/definitions';
import { columnsLayout } from '@mfui/client/layouts';

const mfui = createMFUIManifest({
  components: [timelineDefinition],
  layouts: [columnsLayout],
});

结构

字段类型是否必填描述
layout'mfui.columns'布局名称。
columnsArray<TextCell | ComponentCell>列内容,必须是 2 或 3 个 cell。
约束说明
列数只能是 2 或 3 列。
每列内容每列正好包含一个 cell。
cell 类型每个 cell 必须是 TextCellComponentCell 之一。
嵌套布局不支持在 columns 中嵌套布局。

TextCell

字段类型是否必填描述
textstring文本内容,不能为空。可以使用 Markdown 兼容文本。

ComponentCell

字段类型是否必填描述
componentstring组件名,必须引用同一个 manifest 中包含的组件。
specunknown组件 spec,必须匹配对应组件的 schema。

每个 cell 必须只包含一种内容:要么是 text,要么是 componentspec。不能同时包含 textcomponent

模型输出

模型在 <mfui> block 中输出的 layout payload 形如:

json
{
  "layout": "mfui.columns",
  "columns": [
    {
      "text": "### Recommendation\nShip behind a feature flag."
    },
    {
      "component": "mfui.timeline",
      "spec": {
        "title": "Launch plan",
        "items": [
          {
            "time": "Today",
            "title": "Prepare rollout checklist"
          }
        ]
      }
    }
  ]
}

布局的文本投影规则见投影