Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
2668ced9
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2668ced9
编写于
1月 12, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 优化自定义导航栏页面
上级
1895fb73
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
181 addition
and
225 deletion
+181
-225
components/uni-navbar-lite/uni-navbar-lite.uvue
components/uni-navbar-lite/uni-navbar-lite.uvue
+117
-106
pages/API/set-navigation-bar-color/set-custom-navigation-bar-color.uvue
...navigation-bar-color/set-custom-navigation-bar-color.uvue
+0
-111
pages/API/set-navigation-bar-color/set-navigation-bar-color.uvue
...PI/set-navigation-bar-color/set-navigation-bar-color.uvue
+1
-1
pages/template/navbar-lite/navbar-lite.test.js
pages/template/navbar-lite/navbar-lite.test.js
+1
-1
pages/template/navbar-lite/navbar-lite.uvue
pages/template/navbar-lite/navbar-lite.uvue
+62
-6
未找到文件。
components/uni-navbar-lite/uni-navbar-lite.uvue
浏览文件 @
2668ced9
...
...
@@ -2,10 +2,14 @@
<view class="uni-navbar">
<view class="uni-navbar-inner" :style="navbarStyle">
<view class="left-content" @click="back">
<text class="uni-icons">{{unicode}}</text>
<text :style="{ color: textColor }" class="uni-icons">{{
unicode
}}</text>
</view>
<view class="uni-navbar-content" :class="{'is-left':isLeft}">
<slot>{{title}}</slot>
<view class="uni-navbar-content" :class="{ 'is-left': isLeft }">
<text :style="{ color: textColor }">
<slot>{{ title }}</slot>
</text>
</view>
<view class="right-content">
<slot name="right"></slot>
...
...
@@ -15,61 +19,65 @@
</template>
<script>
import iconpath from './uniicons.ttf'
import iconpath from "./uniicons.ttf";
export default {
name: "uni-navbar",
props: {
title: {
type: String,
default: ''
default: "",
},
isLeft: {
type: Boolean,
default: false
}
default: false,
},
textColor: {
type: String,
default: "#000",
},
},
data() {
return {
statusBarHeight: 0
statusBarHeight: 0,
};
},
computed: {
navbarStyle() : string {
return `margin-top:${this.statusBarHeight}px`
return `margin-top:${this.statusBarHeight}px`;
},
unicode() : string {
return '\ue600'
}
return "\ue600";
},
},
created() {
uni.loadFontFace({
global: false,
family: 'UniIconsFontFamily',
source: "url(" + iconpath + ")",
family: "UniIconsFontFamily",
source: `url("${iconpath}")`,
success() { },
fail(err) {
console.log(err);
},
})
const sys = uni.getSystemInfoSync()
const statusBarHeight = sys.statusBarHeight
this.statusBarHeight = statusBarHeight
});
const sys = uni.getSystemInfoSync();
const statusBarHeight = sys.statusBarHeight;
this.statusBarHeight = statusBarHeight;
},
mounted() {
// TODO 暂时加定时器,否则不生效
setTimeout(() => {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ffffff'
})
}, 100)
frontColor: "#000000",
backgroundColor: "#ffffff",
});
}, 100);
},
methods: {
back() {
uni.navigateBack({})
}
uni.navigateBack({});
},
}
},
};
</script>
<style>
...
...
@@ -79,10 +87,12 @@
font-style: normal;
color: #333;
}
.uni-navbar {
border: 1px #eee solid;
background-color: #fff;
background-color: #007aff;
}
.uni-navbar-inner {
position: relative;
display: flex;
...
...
@@ -112,6 +122,7 @@
justify-content: center;
align-items: center;
}
.is-left {
justify-content: flex-start;
}
...
...
pages/API/set-navigation-bar-color/set-custom-navigation-bar-color.uvue
已删除
100644 → 0
浏览文件 @
1895fb73
<template>
<view>
<view class="custom-navigation">
<text
class="back-icon"
@click="back"
:style="`color:${navigationBarTextColor}`"
>{{ backIcon }}</text
>
<text class="title" :style="`color:${navigationBarTextColor}`"
>自定义导航栏</text
>
</view>
<page-head title="setCustomNavigationBarColor"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="setNavigationBarColor1" class="uni-btn">
设置自定义导航栏前景色白色
</button>
<button @tap="setNavigationBarColor2" class="uni-btn">
设置自定义导航栏前景色黑色
</button>
</view>
</view>
</template>
<script lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
backIcon: '\ue582',
navigationBarTextColor: '#fff'
}
},
onShow(){
uni.loadFontFace({
family: 'UniFontFamily',
source: 'url(static/font/uni.ttf)'
})
},
methods: {
back(){
uni.navigateBack()
},
setNavigationBarColor1() {
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#0000',
success: () => {
this.navigationBarTextColor = '#fff'
console.log('setNavigationBarColor success')
this.setLifeCycleNum(state.lifeCycleNum + 1)
},
fail: () => {
console.log('setNavigationBarColor fail')
this.setLifeCycleNum(state.lifeCycleNum - 1)
},
complete: () => {
console.log('setNavigationBarColor complete')
this.setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setNavigationBarColor2() {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#0000',
success: () => {
this.navigationBarTextColor = '#000'
console.log('setNavigationBarColor success')
this.setLifeCycleNum(state.lifeCycleNum + 1)
},
fail: () => {
console.log('setNavigationBarColor fail')
this.setLifeCycleNum(state.lifeCycleNum - 1)
},
complete: () => {
console.log('setNavigationBarColor complete')
this.setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
// 自动化测试
getLifeCycleNum(): number {
return state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
},
},
}
</script>
<style>
.custom-navigation {
padding-top: 40px;
padding-bottom: 10px;
background-color: #007aff;
}
.custom-navigation > .title {
margin: 0 auto;
}
.custom-navigation > .back-icon {
position: absolute;
font-family: UniFontFamily;
font-size: 20px;
left: 10px;
}
</style>
pages/API/set-navigation-bar-color/set-navigation-bar-color.uvue
浏览文件 @
2668ced9
...
...
@@ -66,7 +66,7 @@ export default {
},
goCustomNavigation(){
uni.navigateTo({
url: '/pages/
API/set-navigation-bar-color/set-custom-navigation-bar-color
'
url: '/pages/
template/navbar-lite/navbar-lite
'
})
}
},
...
...
pages/
API/set-navigation-bar-color/set-custom-navigation-bar-color
.test.js
→
pages/
template/navbar-lite/navbar-lite
.test.js
浏览文件 @
2668ced9
const
CURRENT_PAGE_PATH
=
"
/pages/
API/set-navigation-bar-color/set-custom-navigation-bar-color
"
;
"
/pages/
template/navbar-lite/navbar-lite
"
;
describe
(
"
setCustomNavigationBarColor
"
,
()
=>
{
let
page
;
...
...
pages/template/navbar-lite/navbar-lite.uvue
浏览文件 @
2668ced9
<template>
<view class="content">
<uni-navbar-lite :title="title" :is-left="isLeft"></uni-navbar-lite>
<uni-navbar-lite :title="title" :is-left="isLeft"
:text-color="navigationBarTextColor"
></uni-navbar-lite>
<scroll-view class="scroll-view" scroll-y="true">
<view class="content-item" @click="onClick">
<text>点击此处,将标题切换为{{isLeft?'居中':'左侧'}}显示</text>
...
...
@@ -9,23 +9,79 @@
<text class="text">内容:{{item}}</text>
</view>
<input/>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="setNavigationBarColor1" class="uni-btn">
设置自定义导航栏前景色白色
</button>
<button @tap="setNavigationBarColor2" class="uni-btn">
设置自定义导航栏前景色黑色
</button>
</view>
</scroll-view>
</view>
</template>
<script>
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
title: 'Hello uni-app',
isLeft: false
isLeft: false,
navigationBarTextColor: '#000'
}
},
onLoad() { },
methods: {
onClick(){
this.isLeft = !this.isLeft
},
setNavigationBarColor1() {
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#0000',
success: () => {
this.navigationBarTextColor = '#fff'
console.log('setNavigationBarColor success')
this.setLifeCycleNum(state.lifeCycleNum + 1)
},
fail: () => {
console.log('setNavigationBarColor fail')
this.setLifeCycleNum(state.lifeCycleNum - 1)
},
complete: () => {
console.log('setNavigationBarColor complete')
this.setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setNavigationBarColor2() {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#0000',
success: () => {
this.navigationBarTextColor = '#000'
console.log('setNavigationBarColor success')
this.setLifeCycleNum(state.lifeCycleNum + 1)
},
fail: () => {
console.log('setNavigationBarColor fail')
this.setLifeCycleNum(state.lifeCycleNum - 1)
},
complete: () => {
console.log('setNavigationBarColor complete')
this.setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
// 自动化测试
getLifeCycleNum(): number {
return state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
},
}
}
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录