提交修改
This commit is contained in:
+45
-2
@@ -2,7 +2,8 @@ App({
|
||||
globalData: {
|
||||
token: '',
|
||||
user: null,
|
||||
apiUrl: 'http://localhost:8080'
|
||||
apiUrl: 'http://localhost:8080',
|
||||
themeMode: 'light',
|
||||
},
|
||||
onLaunch() {
|
||||
const token = wx.getStorageSync('token')
|
||||
@@ -13,5 +14,47 @@ App({
|
||||
if (user) this.globalData.user = user
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
this.initTheme()
|
||||
},
|
||||
initTheme() {
|
||||
const stored = wx.getStorageSync('inchstep-theme')
|
||||
if (stored === 'light' || stored === 'dark') {
|
||||
this.globalData.themeMode = stored
|
||||
} else {
|
||||
try {
|
||||
const sysInfo = wx.getSystemInfoSync()
|
||||
this.globalData.themeMode = sysInfo.theme === 'dark' ? 'dark' : 'light'
|
||||
} catch(e) {}
|
||||
}
|
||||
this.applyTheme(this.globalData.themeMode)
|
||||
},
|
||||
applyTheme(mode) {
|
||||
this.globalData.themeMode = mode
|
||||
wx.setStorageSync('inchstep-theme', mode)
|
||||
try {
|
||||
wx.setNavigationBarColor({
|
||||
frontColor: mode === 'dark' ? '#ffffff' : '#000000',
|
||||
backgroundColor: mode === 'dark' ? '#1C1C1E' : '#F5F5F7',
|
||||
})
|
||||
wx.setTabBarStyle({
|
||||
backgroundColor: mode === 'dark' ? '#1C1C1E' : '#F5F5F7',
|
||||
borderStyle: mode === 'dark' ? 'black' : 'white',
|
||||
})
|
||||
} catch(e) {}
|
||||
this.notifyPages(mode)
|
||||
},
|
||||
toggleTheme() {
|
||||
const newMode = this.globalData.themeMode === 'light' ? 'dark' : 'light'
|
||||
this.applyTheme(newMode)
|
||||
},
|
||||
notifyPages(mode) {
|
||||
const pages = getCurrentPages()
|
||||
pages.forEach(page => {
|
||||
if (page.setData && typeof page.setThemeData === 'function') {
|
||||
page.setThemeData(mode)
|
||||
} else if (page.setData) {
|
||||
page.setData({ themeMode: mode })
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user