App.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <script>
  2. export default {
  3. globalData: {
  4. theme: '',
  5. timer: {}, //倒计时模式
  6. watch: {}, //默认模式
  7. },
  8. methods: {
  9. watch(method, name) {
  10. Object.defineProperty(this.globalData, name, {
  11. configurable: true,
  12. enumerable: true,
  13. set: function(value) {
  14. this._customValue = value
  15. method(value)
  16. },
  17. get: function(value) {
  18. return this._customValue
  19. }
  20. })
  21. },
  22. getTheme() {
  23. const appBaseInfo = wx.getAppBaseInfo();
  24. var followSystem = !wx.getStorageSync('selfTheme');
  25. var theme = wx.getStorageSync('theme') || 'light';
  26. if (followSystem) { //跟随系统
  27. theme = appBaseInfo.theme || 'light';
  28. }
  29. this.globalData.theme = theme;
  30. if (theme == 'light') {
  31. uni.setNavigationBarColor({
  32. frontColor: '#000000',
  33. backgroundColor: '#f6f6f6'
  34. });
  35. uni.setBackgroundTextStyle({
  36. textStyle: 'light'
  37. })
  38. uni.setBackgroundColor({
  39. backgroundColor: '#f4f4f4',
  40. backgroundColorTop: '#eeeeee',
  41. backgroundColorBottom: '#efefef'
  42. });
  43. uni.setTabBarStyle({
  44. color: '#999999',
  45. selectedColor: '#000000',
  46. backgroundColor: '#ffffff',
  47. borderStyle: 'black'
  48. });
  49. uni.setTabBarItem({
  50. index: 0,
  51. iconPath: 'static/images/tabbar/todo.png',
  52. selectedIconPath: 'static/images/tabbar/todo_selected.png'
  53. });
  54. uni.setTabBarItem({
  55. index: 1,
  56. iconPath: 'static/images/tabbar/statistics.png',
  57. selectedIconPath: 'static/images/tabbar/statistics_selected.png'
  58. });
  59. uni.setTabBarItem({
  60. index: 2,
  61. iconPath: 'static/images/tabbar/record.png',
  62. selectedIconPath: 'static/images/tabbar/record_selected.png'
  63. });
  64. uni.setTabBarItem({
  65. index: 3,
  66. iconPath: 'static/images/tabbar/my.png',
  67. selectedIconPath: 'static/images/tabbar/my_selected.png'
  68. });
  69. } else {
  70. uni.setNavigationBarColor({
  71. frontColor: '#ffffff',
  72. backgroundColor: '#000000'
  73. });
  74. uni.setBackgroundTextStyle({
  75. textStyle: 'dark'
  76. })
  77. uni.setBackgroundColor({
  78. backgroundColor: '#1f1f1f',
  79. backgroundColorTop: '#000000',
  80. backgroundColorBottom: '#1f1f1f'
  81. });
  82. uni.setTabBarStyle({
  83. color: '#f0f0f0',
  84. selectedColor: '#ffffff',
  85. backgroundColor: '#000000',
  86. borderStyle: 'white'
  87. });
  88. uni.setTabBarItem({
  89. index: 0,
  90. iconPath: 'static/images/tabbar/todo_dark.png',
  91. selectedIconPath: 'static/images/tabbar/todo_selected_dark.png'
  92. });
  93. uni.setTabBarItem({
  94. index: 1,
  95. iconPath: 'static/images/tabbar/statistics_dark.png',
  96. selectedIconPath: 'static/images/tabbar/statistics_selected_dark.png'
  97. });
  98. uni.setTabBarItem({
  99. index: 2,
  100. iconPath: 'static/images/tabbar/record_dark.png',
  101. selectedIconPath: 'static/images/tabbar/record_selected_dark.png'
  102. });
  103. uni.setTabBarItem({
  104. index: 3,
  105. iconPath: 'static/images/tabbar/my_dark.png',
  106. selectedIconPath: 'static/images/tabbar/my_selected_dark.png'
  107. });
  108. }
  109. return theme;
  110. },
  111. checkForUpdate() { //检查是否有新版本,有则更新
  112. const updateManager = uni.getUpdateManager() // 小程序版本更新管理器
  113. updateManager.onCheckForUpdate(res => { // 检测新版本后的回调
  114. if (res.hasUpdate) { // 如果有新版本提醒并进行强制升级
  115. console.log('有新版本,强制升级')
  116. }
  117. })
  118. updateManager.onUpdateReady(() => { // 新版本下载完成的回调
  119. this.$u.func.logout(true) //登出但是不跳转页面,为了保证新版本用新登录逻辑
  120. updateManager.applyUpdate() // 强制更新版本并重启
  121. })
  122. updateManager.onUpdateFailed(() => { // 新版本下载失败的回调
  123. // 新版本下载失败,提示用户删除后通过冷启动重新打开
  124. uni.showModal({
  125. content: '下载失败,请删除当前小程序后重新搜索打开',
  126. showCancel: false,
  127. confirmText: '我知道了',
  128. success: () => {
  129. this.$u.func.logout() //登出
  130. }
  131. })
  132. })
  133. },
  134. },
  135. onLaunch: function() {
  136. console.log('App Launch')
  137. this.checkForUpdate() //检查是否有新版本,有则更新
  138. },
  139. onShow: function() {
  140. // uni.hideTabBar()//需要手动隐藏原生的tabbar
  141. console.log('App Show')
  142. if (this.$u.func.checkLogin()) { //已登录
  143. //原来是会员,但是现在过期了
  144. if (this.userInfo.isVIP && !this.$u.func.checkVIP(this.userInfo.equityEffective)) {
  145. console.log('会员过期,强制登出并且跳转到登录页')
  146. this.$u.func.logout() //强制登出并且跳转到登录页
  147. }
  148. }
  149. },
  150. onThemeChange: function() {
  151. this.getTheme();
  152. },
  153. onHide: function() {
  154. console.log('App Hide')
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. /*uview全局样式*/
  160. @import "uview-ui/index.scss";
  161. /*app全局样式*/
  162. @import 'static/style/app.scss';
  163. @import 'static/style/person_colors.scss';
  164. /*主题样式*/
  165. @import 'static/style/theme.scss';
  166. </style>