01
返回
<cu-custom :isBack="true" title="点左侧回显 leftClick" :statusBarHeight="0" @leftClick="onLeft" />
自定义导航容器用于替代页面原生导航栏,承载标题、返回入口与右侧操作。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 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),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-custom :isBack="true" title="点左侧回显 leftClick" :statusBarHeight="0" @leftClick="onLeft" />
<cu-custom :isBack="true" backText="返回" title="带返回文字" :safeAreaInsetTop="false"> <template v-slot:right> <text> 右侧 </text> </template> </cu-custom>
<cu-custom bgColor="bg-blue" title="bg-blue 类名档" :statusBarHeight="0" /> <cu-custom bgColor="bg-gradual-red" title="bg-gradual-red 渐变档" :statusBarHeight="0" />
<cu-custom bgImage="static/logo.png" title="bgImage 档:标题不再反白" :statusBarHeight="0" />
<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" />
<cu-custom :statusBarHeight="0"> <template v-slot:content> <text> slot=content:整块自定义 </text> </template> </cu-custom> <cu-custom :statusBarHeight="0" />
<cu-custom :isCustom="true" title="isCustom=true:应与默认档一致" :statusBarHeight="0" />
<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>
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 外观 | |||
| bgColor | 顶栏色彩层类名,拼在条节点类名末尾;空串不追加 | String | '' |
| bgImage | 背景图地址;App 端背景图不渲染,请改用 bgColor 或自行叠一层图片 | String | '' |
| 文案 | |||
| title | 中间标题文字;空串不渲染标题节点 | String | '' |
| backText | 返回区文字,仅返回区打开时渲染 | String | '' |
| 布局 | |||
| statusBarHeight | 状态栏占位高度,px 数值 | Number | 0 |
| height | 条内容区高度,带单位字符串(默认 44px) | String | '44px' |
| safeAreaInsetTop | 是否渲染状态栏占位节点 | Boolean | true |
| fixed | 是否固定在顶部;false 改为随流排布 | Boolean | true |
| 交互与样式 | |||
| autoBack | 点左侧返回区后是否自动返回上一页 | Boolean | false |
| isBack | 左侧返回区开关,为真时渲染返回图标与 backText | Boolean | false |
| url | 不参与跳转;本件只有返回行为,需要跳转请在 @leftClick 里自行处理 | String | '' |
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| isCustom | 左下角胶囊形态开关;本仓未实现该形态,传了不生效 | Boolean | false |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @leftClick | 点左侧返回区时触发,无载荷;返回动作由 autoBack 决定 | Handler | - | 各端一致 |
| @rightClick | 点右侧操作区时触发,无载荷 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| backText | 自定义返回区内容;不填时按 backText 文字兜底,仍为空则只留返回图标 |
| content | 自定义中间区内容;不填时渲染 title |
| right | 放右侧操作区内容;不填时右侧留空占位 |
无占位开关 :顶栏默认吸顶,但本件没有任何占位开关,页面内容会被整条盖住;须在页面顶部自留状态栏与条高的空间,或关掉吸顶改随流排布。
底色只认类名 :顶栏底色只认色彩层类名,直接传十六进制色值不会上色;请改传现成的色彩层类名。