Skip to content

PageContainer 页容器 ​

Pro 页面的标准外壳:上方页头(面包屑、返回、标题、标签、操作区、标签页),中间内容区,底部可带 FooterToolbar 底部操作栏。对标 Ant Design Pro Components v3 的 PageContainer 和 FooterToolbar。

何时使用 ​

  • ProLayout 内容区里的每一个业务页面:详情页、编辑页、高级表单页,需要统一的页头和间距。
  • 长表单或编辑页需要一条始终可见的「提交 / 取消」操作栏时,用 FooterToolbar(或 PageContainer 的 Footer)。
  • 只需要一个带标题的内容块时用 Card 卡片 或 ProCard 高级卡片;整体导航框架用 ProLayout。

在线体验 ​

PageContainer 场景展示完整页头与底部操作栏。

PageContainer 页容器 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

FooterToolbar 场景:滚动内容区,可以看到吸底操作栏下方的色块和文字被模糊、透出半透明底色。

FooterToolbar 底部操作栏 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

基本用法 ​

下面代码放在应用的页面文件中;完整的 main 和窗口初始化见 打开自绘窗口。

go
import "github.com/tangoui/tango/ui"

var activeTab = "base"

func page(c *ui.Context) {
    ui.PageContainer(c, "高级表单").
        Breadcrumb("首页", "表单页", "高级表单").
        SubTitle("这是一个副标题").
        Extra(func() {
            ui.Button(c, "次要按钮")
            ui.Button(c, "主操作").Primary()
        }).
        Tabs(&activeTab, []ui.TabItem{{Key: "base", Label: "基本信息"}, {Key: "log", Label: "操作日志"}}).
        Footer(func() {
            ui.Button(c, "重置")
            ui.Button(c, "提交").Primary()
        }).
        Body(func() {
            ui.ProCard(c, "页面内容").Body(func() { ui.Text(c, "当前标签:" + activeTab) })
        })
}

链式设置页头后调用 Body 构建内容。页头本身是一个 PageHeader;Footer 会在页面底部生成一条 FooterToolbar,FooterExtra 设置它左侧的内容。

常见用法 ​

以下片段省略了 import。

返回、标签与页头内容 ​

Back() 显示返回按钮,BackClicked() 报告本帧是否被点击;Tags 放在标题右侧,Content 和 ExtraContent 分别是页头下方左侧与右侧的区域。

go
func detailPage(c *ui.Context, goBack func()) {
    pc := ui.PageContainer(c, "订单 #1024").Back().
        Tags(func() { ui.Tag(c, "进行中").Color("processing") }).
        Content(func() { ui.Text(c, "创建人:曲丽丽") }).
        ExtraContent(func() { ui.Statistic(c, "订单金额", 568.08, 2).Prefix("¥") }).
        Body(func() { ui.Text(c, "详情内容") })
    if pc.BackClicked() {
        goBack()
    }
}

填满窗口与 Ghost ​

Fill() 让页容器填满父容器高度,内容区单独滚动、底部操作栏固定在最下方;Ghost() 去掉页头背景和外边距,适合嵌在 ProLayout 内容区里;NoHeader() 完全不显示页头;Loading(true) 显示加载态。

go
func fillPage(c *ui.Context) {
    ui.PageContainer(c, "编辑规则").Ghost().Fill().
        Footer(func() { ui.Button(c, "保存").Primary() }).
        FooterExtra(func() { ui.Text(c, "已修改 2 项").Secondary() }).
        Body(func() { ui.Skeleton(c).Rows(8).Show() })
}

FooterToolbar:独立使用 ​

FooterToolbar 也可以单独放在任何页面底部。Body 里是右侧的按钮,Extra 是左侧的提示。不吸底时,它就是普通流式布局里一条宽度跟随父容器的操作栏。

go
func footer(c *ui.Context) {
    ui.FooterToolbar(c).
        Extra(func() { ui.Text(c, "表单有 2 处修改尚未保存") }).
        Body(func() {
            ui.Button(c, "取消")
            ui.Button(c, "提交").Primary()
        })
}

FooterToolbar:吸底与毛玻璃 ​

Sticky() 通过 Affix 把操作栏固定在窗口底部;Target(id) 改为固定在某个滚动容器底部(同时隐含 Sticky)。固定期间,操作栏下面滚过的内容会被背景模糊(paint.BackdropBlur),再叠上一层半透明底色,形成毛玻璃效果;回到正常流式位置后恢复普通背景。

滚动容器的 ID 要在它构建之后才知道,即时模式下的惯用做法是把本帧的 ID 存起来,下一帧传给 Target:

go
var scrollID ui.ID

func stickyFooter(c *ui.Context) {
    sb := ui.Scroll(c, func() {
        for i := 0; i < 30; i++ {
            ui.Paragraph(c, "长表单内容……")
        }
        ui.FooterToolbar(c).Target(scrollID).Body(func() {
            ui.Button(c, "提交").Primary()
        })
    })
    scrollID = sb.ID()
}

第一帧 scrollID 为 0,操作栏退化为固定在窗口底部;从第二帧起固定在滚动容器底部。

主题与样式 ​

风格差异
Ant Design操作栏高 56、左右内边距 24,上方分隔线和向上的阴影;吸底时 FrostedBg 为容器色 60% 不透明、模糊半径 8(对应 Pro 的 rgba(255,255,255,0.6) + blur(8px))。
Element Plus操作栏高 60、内边距 20;Element Plus 没有对应组件,取值偏离基线:吸底时底色 72% 不透明、模糊半径 10。
shadcn上边框、无阴影;流式底色为容器色 95%,吸底时 60% + 模糊 8(对应 bg-background/60 backdrop-blur)。

FooterToolbar 组件令牌在 theme.Components.FooterToolbar(theme.FooterToolbarToken)。流式布局使用 Bg,吸底时用 BlurRadius 设置背景模糊半径,再叠加半透明的 FrostedBg。半径为 0 时使用 Bg。高对比度主题或渲染器不支持背景模糊时,吸底的操作栏使用不透明的 BgContainer。

ConfigProvider.Defaults 键:"PageContainer" 支持 "ghost"、"fill"、"tabsCard"(bool);"FooterToolbar" 支持 "sticky"(bool)。

注意事项 ​

  • 状态:标签页的当前键绑定在应用变量上(Tabs(&activeTab, ...)),TabChanged() 报告本帧是否切换;页容器本身不保存业务状态。
  • 吸底目标:Target 使用上一帧的滚动容器 ID,见上文示例;PageContainer.Fill() 自带的底部栏不需要手动设置 Target。
  • 性能:背景模糊只覆盖操作栏自身的矩形,并按损坏区域局部重绘;内容在下方滚动时只重算这条区域。
  • 无障碍:操作栏的无障碍角色是 toolbar;按钮按重要性从左到右排列,主操作放在最右。
  • RTL:模糊区域就是操作栏的矩形,在 RTL 下同样生效;操作栏内容不做额外镜像。

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

PageContainer 页容器

gallery 演示 PageContainer 的具名 Render 函数,源码 page_pro2_page.go#L24。

加载中…

FooterToolbar 底部操作栏

gallery 演示 FooterToolbar 的具名 Render 函数,源码 page_pro2_page.go#L71。

加载中…

PageLoading 页面加载

gallery 演示 PageLoading 的 Render 函数,源码 page_b4c.go#L23。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.PageContainer ​

go
func PageContainer(c *Context, title string) *PageContainerW

PageContainer starts a page container titled title; chain options, then Body with the page content.

ConfigProvider.Defaults("PageContainer", ...) keys: "ghost", "fill", "tabsCard" (bool).

返回 *PageContainerW,可链式调用的方法见 PageContainerW 方法。

ui.FooterToolbar ​

go
func FooterToolbar(c *Context) *FooterToolbarW

FooterToolbar starts a bottom action bar; chain options, then Body with the right-hand buttons.

ConfigProvider.Defaults("FooterToolbar", ...) keys: "fixed" (bool, default true), "sticky" (legacy bool).

返回 *FooterToolbarW,可链式调用的方法见 FooterToolbarW 方法。

PageContainerW 方法 ​

ui.PageContainerW:PageContainerW builds a PageContainer.

方法说明签名
BackBack shows the back button (query BackClicked).Back() *PageContainerW
BackClickedBackClicked reports a click on the back button.BackClicked() bool
BodyBody builds the container with fn as the page content.Body(fn func()) *PageContainerW
BreadcrumbBreadcrumb shows a breadcrumb above the title.Breadcrumb(items ...string) *PageContainerW
ContentContent builds the description area under the title.Content(fn func()) *PageContainerW
CrumbClickedCrumbClicked returns the index of a clicked breadcrumb item or -1.CrumbClicked() int
ExtraExtra builds the actions at the right of the title.Extra(fn func()) *PageContainerW
ExtraContentExtraContent builds a block at the right of Content.ExtraContent(fn func()) *PageContainerW
FillFill makes the container take its parent's free height: header and body scroll inside it and the footer toolbar stays at the bottom.Fill() *PageContainerW
FooterFooter builds the right-hand buttons of a FooterToolbar.Footer(fn func()) *PageContainerW
FooterExtraFooterExtra builds the left side of the FooterToolbar.FooterExtra(fn func()) *PageContainerW
GhostGhost drops the header background and the content padding (for use inside a padded content area).Ghost() *PageContainerW
LayoutLayout applies layout options to the container.Layout(o ...layout.Option) *PageContainerW
LoadingLoading shows a centred spinner instead of the body.Loading(on bool) *PageContainerW
NoHeaderNoHeader hides the page header (body and footer only).NoHeader() *PageContainerW
ScrollIDScrollID returns the scroll box of a Fill container (0 otherwise).ScrollID() ID
SubTitleSubTitle sets the secondary title.SubTitle(s string) *PageContainerW
TabChangedTabChanged reports a tab switch this frame.TabChanged() bool
TabExtraTabExtra builds content at the right of the tab list.TabExtra(fn func()) *PageContainerW
TabsTabs shows a tab list at the bottom of the header bound to active.Tabs(active *string, items []TabItem) *PageContainerW
TabsCardTabsCard uses card-style tabs.TabsCard() *PageContainerW
TagsTags builds tags after the title.Tags(fn func()) *PageContainerW

FooterToolbarW 方法 ​

ui.FooterToolbarW:FooterToolbarW builds a FooterToolbar.

方法说明签名
BodyBody builds the bar with fn as the right-hand actions.Body(fn func()) *FooterToolbarW
ExtraExtra builds content at the left of the bar.Extra(fn func()) *FooterToolbarW
FixedFixed controls whether the bar is pinned to the bottom (default true).Fixed(on bool) *FooterToolbarW
IDID returns the bar's widget ID (after Body).ID() ID
LayoutLayout applies layout options to the bar.Layout(o ...layout.Option) *FooterToolbarW
StickySticky pins the bar to the bottom of the viewport while the content above scrolls (Affix with offset bottom 0).Sticky() *FooterToolbarW
TargetTarget makes Sticky pin to the bottom of a scroll box (ScrollBox.ID()) instead of the window.Target(id ID) *FooterToolbarW

相关链接 ​

以 MIT 许可发布