| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <script>
- export default {
- globalData: {
- theme: '',
- timer: {}, //倒计时模式
- watch: {}, //默认模式
- },
- methods: {
- watch(method, name) {
- Object.defineProperty(this.globalData, name, {
- configurable: true,
- enumerable: true,
- set: function(value) {
- this._customValue = value
- method(value)
- },
- get: function(value) {
- return this._customValue
- }
- })
- },
- getTheme() {
- const appBaseInfo = wx.getAppBaseInfo();
- var followSystem = !wx.getStorageSync('selfTheme');
- var theme = wx.getStorageSync('theme') || 'light';
- if (followSystem) { //跟随系统
- theme = appBaseInfo.theme || 'light';
- }
- this.globalData.theme = theme;
- if (theme == 'light') {
- uni.setNavigationBarColor({
- frontColor: '#000000',
- backgroundColor: '#f6f6f6'
- });
- uni.setBackgroundTextStyle({
- textStyle: 'light'
- })
- uni.setBackgroundColor({
- backgroundColor: '#f4f4f4',
- backgroundColorTop: '#eeeeee',
- backgroundColorBottom: '#efefef'
- });
- uni.setTabBarStyle({
- color: '#999999',
- selectedColor: '#000000',
- backgroundColor: '#ffffff',
- borderStyle: 'black'
- });
- uni.setTabBarItem({
- index: 0,
- iconPath: 'static/images/tabbar/todo.png',
- selectedIconPath: 'static/images/tabbar/todo_selected.png'
- });
- uni.setTabBarItem({
- index: 1,
- iconPath: 'static/images/tabbar/statistics.png',
- selectedIconPath: 'static/images/tabbar/statistics_selected.png'
- });
- uni.setTabBarItem({
- index: 2,
- iconPath: 'static/images/tabbar/record.png',
- selectedIconPath: 'static/images/tabbar/record_selected.png'
- });
- uni.setTabBarItem({
- index: 3,
- iconPath: 'static/images/tabbar/my.png',
- selectedIconPath: 'static/images/tabbar/my_selected.png'
- });
- } else {
- uni.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: '#000000'
- });
- uni.setBackgroundTextStyle({
- textStyle: 'dark'
- })
- uni.setBackgroundColor({
- backgroundColor: '#1f1f1f',
- backgroundColorTop: '#000000',
- backgroundColorBottom: '#1f1f1f'
- });
- uni.setTabBarStyle({
- color: '#f0f0f0',
- selectedColor: '#ffffff',
- backgroundColor: '#000000',
- borderStyle: 'white'
- });
- uni.setTabBarItem({
- index: 0,
- iconPath: 'static/images/tabbar/todo_dark.png',
- selectedIconPath: 'static/images/tabbar/todo_selected_dark.png'
- });
- uni.setTabBarItem({
- index: 1,
- iconPath: 'static/images/tabbar/statistics_dark.png',
- selectedIconPath: 'static/images/tabbar/statistics_selected_dark.png'
- });
- uni.setTabBarItem({
- index: 2,
- iconPath: 'static/images/tabbar/record_dark.png',
- selectedIconPath: 'static/images/tabbar/record_selected_dark.png'
- });
- uni.setTabBarItem({
- index: 3,
- iconPath: 'static/images/tabbar/my_dark.png',
- selectedIconPath: 'static/images/tabbar/my_selected_dark.png'
- });
- }
- return theme;
- },
- checkForUpdate() { //检查是否有新版本,有则更新
- const updateManager = uni.getUpdateManager() // 小程序版本更新管理器
- updateManager.onCheckForUpdate(res => { // 检测新版本后的回调
- if (res.hasUpdate) { // 如果有新版本提醒并进行强制升级
- console.log('有新版本,强制升级')
- }
- })
- updateManager.onUpdateReady(() => { // 新版本下载完成的回调
- this.$u.func.logout(true) //登出但是不跳转页面,为了保证新版本用新登录逻辑
- updateManager.applyUpdate() // 强制更新版本并重启
- })
- updateManager.onUpdateFailed(() => { // 新版本下载失败的回调
- // 新版本下载失败,提示用户删除后通过冷启动重新打开
- uni.showModal({
- content: '下载失败,请删除当前小程序后重新搜索打开',
- showCancel: false,
- confirmText: '我知道了',
- success: () => {
- this.$u.func.logout() //登出
- }
- })
- })
- },
- },
- onLaunch: function() {
- console.log('App Launch')
- this.checkForUpdate() //检查是否有新版本,有则更新
- },
- onShow: function() {
- // uni.hideTabBar()//需要手动隐藏原生的tabbar
- console.log('App Show')
- if (this.$u.func.checkLogin()) {
- //已登录
- }
- },
- onThemeChange: function() {
- this.getTheme();
- },
- onHide: function() {
- console.log('App Hide')
- }
- }
- </script>
- <style lang="scss">
- /*uview全局样式*/
- @import "uview-ui/index.scss";
- /*app全局样式*/
- @import 'static/style/app.scss';
- @import 'static/style/person_colors.scss';
- /*主题样式*/
- @import 'static/style/theme.scss';
- </style>
|