fix:修复setNavigationBarTitle调用后导致背景颜色被重置问题
parent
a97d9223b6
commit
e632a6dd8f
@ -1,48 +0,0 @@
|
|||||||
const DEFAULT_NAV_BACKGROUND = '#22486e'
|
|
||||||
const DEFAULT_NAV_FRONT = '#ffffff'
|
|
||||||
const LOGIN_NAV_BACKGROUND = '#ffffff'
|
|
||||||
const LOGIN_NAV_FRONT = '#000000'
|
|
||||||
|
|
||||||
function getCurrentRoute() {
|
|
||||||
try {
|
|
||||||
const pages = getCurrentPages()
|
|
||||||
if (!pages || pages.length === 0) return ''
|
|
||||||
return pages[pages.length - 1]?.route || ''
|
|
||||||
} catch (error) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNavigationTheme(route = '') {
|
|
||||||
const currentRoute = route || getCurrentRoute()
|
|
||||||
if (currentRoute === 'pages/login') {
|
|
||||||
return {
|
|
||||||
frontColor: LOGIN_NAV_FRONT,
|
|
||||||
backgroundColor: LOGIN_NAV_BACKGROUND
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
frontColor: DEFAULT_NAV_FRONT,
|
|
||||||
backgroundColor: DEFAULT_NAV_BACKGROUND
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function applyNavigationBarTheme(route = '') {
|
|
||||||
const theme = getNavigationTheme(route)
|
|
||||||
try {
|
|
||||||
uni.setNavigationBarColor({
|
|
||||||
frontColor: theme.frontColor,
|
|
||||||
backgroundColor: theme.backgroundColor,
|
|
||||||
animation: {
|
|
||||||
duration: 0,
|
|
||||||
timingFunc: 'linear'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDefaultNavigationBackground() {
|
|
||||||
return DEFAULT_NAV_BACKGROUND
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue