File tree 7 files changed +51
-34
lines changed 7 files changed +51
-34
lines changed Original file line number Diff line number Diff line change
1
+ import themeChangeBehavior from 'tdesign-miniprogram/mixins/theme-change' ;
1
2
import list from './data/index' ;
2
3
3
4
Page ( {
5
+ behaviors : [ themeChangeBehavior ] ,
4
6
data : {
5
7
list,
6
8
currentYear : new Date ( ) . getFullYear ( ) ,
7
- isDarkMode : false ,
8
9
} ,
9
10
onLoad ( options ) {
10
11
const { path, q } = options ;
21
22
}
22
23
23
24
this . trdPrivacy = this . selectComponent ( '#trdPrivacy' ) ;
24
- this . setData ( { isDarkMode : wx . getSystemInfoSync ( ) . theme === 'dark' } ) ;
25
25
} ,
26
26
27
27
showPrivacyWin ( ) {
Original file line number Diff line number Diff line change 4
4
<image
5
5
class="title-icon"
6
6
mode="aspectFit"
7
- src="/assets/{{isDarkMode ? 'TDesign-logo_dark' : 'TDesign-logo_light'}}.png"
7
+ src="/assets/{{theme === 'dark' ? 'TDesign-logo_dark' : 'TDesign-logo_light'}}.png"
8
8
aria-label="TDesign Logo"
9
9
/>
10
10
</view>
Original file line number Diff line number Diff line change
1
+ import themeChangeBehavior from 'tdesign-miniprogram/mixins/theme-change' ;
2
+
1
3
Component ( {
4
+ behaviors : [ themeChangeBehavior ] ,
2
5
data : {
3
- logoList : [
4
- {
5
- icon : 'https://tdesign.gtimg.com/mobile/demos/logo2.png' ,
6
- title : '品牌名称' ,
7
- } ,
8
- {
9
- url : 'https://tdesign.gtimg.com/mobile/demos/logo1.png' ,
10
- } ,
11
- ] ,
12
- } ,
13
-
14
- lifetimes : {
15
- attached ( ) {
16
- if ( wx . getSystemInfoSync ( ) . theme === 'dark' ) {
17
- const updateKeyName = 'logoList[1].url' ;
18
- this . setData ( { [ updateKeyName ] : 'https://tdesign.gtimg.com/mobile/demos/footer-logo-dark.png' } ) ;
19
- }
6
+ logo : {
7
+ icon : 'https://tdesign.gtimg.com/mobile/demos/logo2.png' ,
8
+ title : '品牌名称' ,
20
9
} ,
21
10
} ,
22
11
} ) ;
Original file line number Diff line number Diff line change 1
1
<!-- theme 为 logo -->
2
2
<view class="footer-example">
3
- <t-footer logo="{{logoList[0] }}" />
3
+ <t-footer logo="{{logo }}" />
4
4
</view>
5
5
6
6
<view class="footer-example">
7
- <t-footer logo="{{logoList[1]}}" />
7
+ <t-footer
8
+ logo="{{{url: theme === 'dark'?'https://tdesign.gtimg.com/mobile/demos/footer-logo-dark.png':'https://tdesign.gtimg.com/mobile/demos/logo1.png'} }}"
9
+ />
8
10
</view>
Original file line number Diff line number Diff line change
1
+ const themeChangeBehavior = Behavior ( {
2
+ data : {
3
+ theme : 'light' ,
4
+ } ,
5
+
6
+ attached ( ) {
7
+ this . _initTheme ( ) ;
8
+ } ,
9
+
10
+ methods : {
11
+ _initTheme ( ) {
12
+ const that = this ;
13
+ wx . getSystemInfo ( {
14
+ success ( res ) {
15
+ that . setData ( {
16
+ theme : res . theme ,
17
+ } ) ;
18
+ } ,
19
+ } ) ;
20
+
21
+ wx . onThemeChange ( ( res ) => {
22
+ that . setData ( {
23
+ theme : res . theme ,
24
+ } ) ;
25
+ } ) ;
26
+ } ,
27
+ } ,
28
+ } ) ;
29
+
30
+ export default themeChangeBehavior ;
Original file line number Diff line number Diff line change 1
- Component ( {
2
- data : {
3
- image : 'https://tdesign.gtimg.com/mobile/demos/logo-light.png' ,
4
- } ,
1
+ import themeChangeBehavior from 'tdesign-miniprogram/mixins/theme-change' ;
5
2
6
- lifetimes : {
7
- attached ( ) {
8
- if ( wx . getSystemInfoSync ( ) . theme === 'dark' ) {
9
- this . setData ( { image : 'https://tdesign.gtimg.com/mobile/demos/image-dark.png' } ) ;
10
- }
11
- } ,
12
- } ,
3
+ Component ( {
4
+ behaviors : [ themeChangeBehavior ] ,
13
5
} ) ;
Original file line number Diff line number Diff line change 1
1
<t-navbar>
2
2
<view slot="left">
3
- <t-image t-class="custom-image" src="{{image}}" aria-label="导航栏图片" />
3
+ <t-image
4
+ t-class="custom-image"
5
+ src="{{theme === 'dark' ? 'https://tdesign.gtimg.com/mobile/demos/image-dark.png' : 'https://tdesign.gtimg.com/mobile/demos/logo-light.png'}}"
6
+ aria-label="导航栏图片"
7
+ />
4
8
</view>
5
9
</t-navbar>
You can’t perform that action at this time.
0 commit comments