App.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. //获取主题颜色
  5. this.fetchBaseTheme()
  6. //用户上线
  7. this.$api.census.online()
  8. //更新版本
  9. this.updateApp()
  10. },
  11. onHide() {
  12. //用户下线
  13. this.$api.census.offline()
  14. uni.removeStorageSync('isWorksSkip');
  15. },
  16. methods: {
  17. //设置主题色
  18. async fetchBaseTheme() {
  19. //活动id为空
  20. if ( this.$isEmpty(this.vuex_active_setting) || this.$isEmpty(this.vuex_active_setting.defaultActiveId)) {
  21. return
  22. }
  23. let params = {
  24. activeId: this.vuex_active_setting.defaultActiveId,
  25. platformSettingEnum: 'ACTIVE_SETTING'
  26. }
  27. //主题配置为空
  28. let activeSetting = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data);
  29. if (this.$isEmpty(activeSetting) || this.$isEmpty(activeSetting.theme)) {
  30. return
  31. }
  32. const baseTheme = activeSetting.theme
  33. this.$config.setTheme(baseTheme,this)
  34. },
  35. updateApp() {
  36. const updateManager = uni.getUpdateManager();
  37. updateManager.onCheckForUpdate(function(res) {
  38. // 请求完新版本信息的回调
  39. console.log("是否有新版本:", res.hasUpdate);
  40. });
  41. updateManager.onUpdateReady(function(res) {
  42. uni.showModal({
  43. title: '更新提示',
  44. content: '新版本已经准备好,是否重启应用?',
  45. success(res) {
  46. if (res.confirm) {
  47. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  48. updateManager.applyUpdate();
  49. }
  50. }
  51. });
  52. });
  53. updateManager.onUpdateFailed(function(res) {
  54. // 新的版本下载失败
  55. });
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. @import "uview-ui/index.scss";
  62. @import "assets/colorui/main.css";
  63. @import "assets/colorui/icon.css";
  64. @import "assets/colorui/app.scss";
  65. </style>