组件 / 导航 / cu-custom 自定义导航容器

cu-custom

自定义导航容器用于替代页面原生导航栏,承载标题、返回入口与右侧操作。

01 / Install

引入组件

整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。

install
# 1  整目录放进工程(easycom 自动解析)
your-project/
└── uni_modules/
    └── colorui-x/

# 2  App.uvue 全局引入主题层(一次)
@import 'uni_modules/colorui-x/theme/base.css';
@import 'uni_modules/colorui-x/theme/layout.css';
@import 'uni_modules/colorui-x/theme/color.scss';  // 颜色工具类(.bg-* / .text-*)

# 3  页面里直接用,不写 import(只编译用到的组件)
<cu-custom />

# 4  单个组件也可以显式引入(可选,不用 easycom 时)
import CuCustom from '@/uni_modules/colorui-x/components/cu-custom/cu-custom.uvue'

组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。

02 / Platform

平台支持

AndroidiOSHarmonyOSWeb(H5)微信小程序支付宝小程序
√ — — √ — —

Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。

Web 列只表示已编出可运行的预览产物,非真机渲染。

其余三端没有任何实测证据,不作支持承诺。

03 / Demo

代码演示

01

返回

uvue
<cu-custom :isBack="true" title="点左侧回显 leftClick" :statusBarHeight="0" @leftClick="onLeft" />
02

返回文案 / 右槽

uvue
<cu-custom :isBack="true" backText="返回" title="带返回文字" :safeAreaInsetTop="false">
  <template v-slot:right>
    <text>
      右侧
    </text>
  </template>
</cu-custom>
03

底色

uvue
<cu-custom bgColor="bg-blue" title="bg-blue 类名档" :statusBarHeight="0" />
<cu-custom bgColor="bg-gradual-red" title="bg-gradual-red 渐变档" :statusBarHeight="0" />
04

背景图

uvue
<cu-custom bgImage="static/logo.png" title="bgImage 档:标题不再反白" :statusBarHeight="0" />
05

高度 / 固定

uvue
<cu-custom title="height 默认 44px" :statusBarHeight="0" />
<cu-custom title="height 60px" height="60px" :statusBarHeight="0" />
<cu-custom title="fixed=false 随流档" :fixed="false" :statusBarHeight="0" />
06

内容插槽

uvue
<cu-custom :statusBarHeight="0">
  <template v-slot:content>
    <text>
      slot=content:整块自定义
    </text>
  </template>
</cu-custom>
<cu-custom :statusBarHeight="0" />
07

未消费项

uvue
<cu-custom :isCustom="true" title="isCustom=true:应与默认档一致" :statusBarHeight="0" />
08

自动返回 / 右击

uvue
<cu-custom :isBack="true" :autoBack="true" title="左箭头点后退回上一页" :statusBarHeight="0" />
<cu-custom title="右侧点击走组件 rightClick" :statusBarHeight="0" @rightClick="onRightEvent">
  <template v-slot:right>
    <text>
      右侧
    </text>
  </template>
</cu-custom>
09

取值与事件

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
外观
bgColor顶栏色彩层类名,拼在条节点类名末尾;空串不追加String''
bgImage背景图地址;App 端背景图不渲染,请改用 bgColor 或自行叠一层图片String''
文案
title中间标题文字;空串不渲染标题节点String''
backText返回区文字,仅返回区打开时渲染String''
布局
statusBarHeight状态栏占位高度,px 数值Number0
height条内容区高度,带单位字符串(默认 44px)String'44px'
safeAreaInsetTop是否渲染状态栏占位节点Booleantrue
fixed是否固定在顶部;false 改为随流排布Booleantrue
交互与样式
autoBack点左侧返回区后是否自动返回上一页Booleanfalse
isBack左侧返回区开关,为真时渲染返回图标与 backTextBooleanfalse
url不参与跳转;本件只有返回行为,需要跳转请在 @leftClick 里自行处理String''
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
isCustom左下角胶囊形态开关;本仓未实现该形态,传了不生效Booleanfalse
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@leftClick点左侧返回区时触发,无载荷;返回动作由 autoBack 决定Handler-各端一致
@rightClick点右侧操作区时触发,无载荷Handler-各端一致

slots

slot说明
backText自定义返回区内容;不填时按 backText 文字兜底,仍为空则只留返回图标
content自定义中间区内容;不填时渲染 title
right放右侧操作区内容;不填时右侧留空占位
05 / Notes

注意事项

无占位开关 :顶栏默认吸顶,但本件没有任何占位开关,页面内容会被整条盖住;须在页面顶部自留状态栏与条高的空间,或关掉吸顶改随流排布。

底色只认类名 :顶栏底色只认色彩层类名,直接传十六进制色值不会上色;请改传现成的色彩层类名。