1 、 main.js
import mixin from '@/common/js/setTheme.js'
Vue. use ( mixin)
2 、 Ver aplicación
onThemeChange ( e) {
this . getTheme ( )
} ,
3 、 setTheme.js
import {
isEmpty
} from '@/common/js/util.js' ;
export default {
install ( Vue) {
Vue. mixin ( {
data ( ) {
return {
theme: 'light' ,
navTheme: {
} ,
themeStyle: {
} ,
}
} ,
onLoad ( ) {
this . getTheme ( ) ;
} ,
methods: {
getTheme ( ) {
let temp = this . $SysCache. get ( 'theme' ) ;
if ( ! isEmpty ( temp) ) {
this . theme = temp;
}
this . navTheme = {
background: '#2d6ec4' ,
color: '#ffffff'
}
if ( this . theme == 'dark' ) {
this . themeStyle = {
color: '#fff' ,
fontsize: '30rpx' ,
}
uni. setTabBarStyle ( {
color: '#535353' ,
backgroundColor: '#242424' ,
borderStyle: 'white' ,
selectedColor: '#ffffff'
} )
} else {
this . themeStyle = {
color: '#333' ,
fontsize: '30rpx'
}
uni. setTabBarStyle ( {
backgroundColor: '#ffffff' ,
borderStyle: 'black' ,
color: '#7A7E83' ,
selectedColor: '#2d6ec4'
} )
}
} ,
}
} )
}
}
4 、 util.js
export const isEmpty = ( v) => {
switch ( typeof v) {
case 'undefined' :
return true ;
case 'string' :
if ( v. replace ( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g , '' ) . length == 0 ) return true ;
break ;
case 'boolean' :
if ( ! v) return true ;
break ;
case 'number' :
if ( 0 === v || isNaN ( v) ) return true ;
break ;
case 'object' :
if ( null === v || v. length === 0 ) return true ;
for ( var i in v) {
return false ;
}
return true ;
}
return false ;
}
5. Uni.scss en el proyecto más externo
@import 'uview-ui/theme.scss' ;
@import '@/static/theme/theme.scss' ;
6 、 theme.scss
.dark-btn-special {
background-color : #2d6ec4 !important ;
color : #ffff !important ;
}
.dark-btn-primary {
background-color : #ffffff !important ;
color : #191919 !important ;
}
.dark-text-primary {
color : #ffffff !important ;
}
.dark-text-dark {
color : #333333 !important ;
}
.dark-text-light {
color : #ffffff !important ;
}
.dark-bg-primary {
background-color : #131619!important;
}
.dark-sepcial-reverse {
background-color : #191D23 !important ;
}
.dark-bg-special {
background-color : #191D23!important;
}
.dark-bg-general {
background-color : #191D23!important;
}
.dark-bg-reverse {
background-color : #131619!important;
}
.dark-bg-subSec {
background-color : #191D23!important;
}
.dark-bg-tips {
background-color : #191D23 !important ;
}
.dark-border {
border-color : #c8c7cc !important ;
}
.dark-box-shadow {
box-shadow : 0px 0px 3px 0px #ccc !important ;
}
.dark-bg-notice {
background-color : #191D23 !important ;
}
.dark-bg-mask {
background-color : #3f3f3f !important ;
}
.light-btn-special {
background-color : #2d6ec4 !important ;
color : #ffff !important ;
}
.light-btn-primary {
background-color : #ffffff !important ;
color : #333333 !important ;
}
.light-text-primary {
color : #333333 !important ;
}
.light-text-dark {
color : #ffffff !important ;
}
.light-text-light {
color : #666666 !important ;
}
.light-bg-primary {
background-color : #f6f6f6 !important ;
}
.light-bg-special {
background-color : #2d6ec4 !important ;
}
.light-sepcial-reverse {
background-color : #eeeeef !important ;
}
//分段器
.light-bg-subSec {
background-color : #0551B5!important;
}
.light-bg-reverse {
background-color : #ffffff !important ;
}
//分段器
.light-bg-tips {
background-color : #FFFCEE!important;
}
.light-bg-general {
background-color : #ffffff !important ;
}
.light-border {
border-color : none !important ;
}
.light-box-shadow {
box-shadow : none !important ;
}
.light-bg-notice {
background-color : #F7FAFF !important ;
}
.light-bg-mask {
background-color : rgba ( 0, 0, 0, 0.2) !important ;
}