• uniapp 自定义导航栏


    自定义导航栏

    修改 pages.json

    pages.json 中将 navigateionStyle 设为 custom

    image-20231013124909430

    新建 systemInfo.js

    systemInfo.js 用来获取当前设备的机型系统信息,放在 common 目录下

    image-20231013130951574

    /**
     * 此 js 文件管理关于当前设备的机型系统信息
     */
    const systemInfo = function() {
    	/****************** 所有平台共有的系统信息 ********************/
    	// 设备系统信息
    	let systemInfomations = uni.getSystemInfoSync()
    	// 机型适配比例系数
    	let scaleFactor = 750 / systemInfomations.windowWidth
    	// 当前机型-屏幕高度
    	let windowHeight = systemInfomations.windowHeight * scaleFactor //rpx
    	// 当前机型-屏幕宽度
    	let windowWidth = systemInfomations.windowWidth * scaleFactor //rpx
    	// 状态栏高度
    	let statusBarHeight = (systemInfomations.statusBarHeight) * scaleFactor //rpx
     
    	// 导航栏高度  注意:此导航栏高度只针对微信小程序有效 其他平台如自定义导航栏请使用:状态栏高度+自定义文本高度
    	let navHeight = 0 //rpx
    	
    	/****************** 微信小程序头部胶囊信息 ********************/
    	// #ifdef MP-WEIXIN
    	const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
    	// 胶囊高度
    	let menuButtonHeight = menuButtonInfo.height * scaleFactor //rpx
    	// 胶囊宽度
    	let menuButtonWidth = menuButtonInfo.width * scaleFactor //rpx
    	// 胶囊上边界的坐标
    	let menuButtonTop = menuButtonInfo.top * scaleFactor //rpx
    	// 胶囊右边界的坐标
    	let menuButtonRight = menuButtonInfo.right * scaleFactor //rpx
    	// 胶囊下边界的坐标
    	let menuButtonBottom = menuButtonInfo.bottom * scaleFactor //rpx
    	// 胶囊左边界的坐标
    	let menuButtonLeft = menuButtonInfo.left * scaleFactor //rpx
     
    	// 微信小程序中导航栏高度 = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
    	navHeight = menuButtonHeight + (menuButtonTop - statusBarHeight) * 2
    	// #endif
     
     
    	// #ifdef MP-WEIXIN
    	return {
    		scaleFactor,
    		windowHeight,
    		windowWidth,
    		statusBarHeight,
    		menuButtonHeight,
    		menuButtonWidth,
    		menuButtonTop,
    		menuButtonRight,
    		menuButtonBottom,
    		menuButtonLeft,
    		navHeight
    	}
    	// #endif
     
    	// #ifndef MP-WEIXIN
    	return {
    		scaleFactor,
    		windowHeight,
    		windowWidth,
    		statusBarHeight
    	}
    	// #endif
    }
     
    export {
    	systemInfo
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69

    新建组件 HeadNav

    
    
     
    
     
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283

    使用

    引入组件,使用

    
    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    如果需要定义状态栏前景字体的颜色,可以设置 navigationBarTextStyle ,只能设置 whiteblack

    {
    	"pages": [
    		{
    			"path": "pages/index/Index",
    			"style": {
    				"navigationBarTextStyle": "black"
    			}
    		}
    	],
    	"globalStyle": {
    		"navigationStyle": "custom",
    		"backgroundColor": "#F8F8F8"
    		
    	},
    	"uniIdRouter": {}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    效果

    image-20231013134547024

    uview 导航栏使用

    引入 uview ,根据文档引入

    Navbar 自定义导航栏 | uView 2.0 (uviewui.com)

    使用 u-navvar

    
    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    效果

    image-20231013141209926

  • 相关阅读:
    一年前 LLM & AGI 碎片化思考与回顾系列④ · System2慢思考下的暴力美学
    跨平台客户端Blazor方案尝试
    Python 自动化(十八)admin后台管理
    14-vue项目搭建.md
    SQL语言
    SpringCloud Alibaba组件-Gateway
    MyBatis-Plus使用乐观锁具体实现
    【计算机视觉 | 目标检测 | 图像分割】arxiv 计算机视觉关于目标检测和图像分割的学术速递(7 月 17 日论文合集)
    Google Earth Engine(GEE)——火灾数据下载(添加图例信息)
    vue一个页面同时添加两个mars-dialog对话框时,关闭按钮失效处理
  • 原文地址:https://blog.csdn.net/weixin_62726289/article/details/134023936