App.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script>
  2. import config from './config'
  3. import {
  4. getToken
  5. } from '@/utils/auth'
  6. export default {
  7. onLaunch: function() {
  8. this.initApp();
  9. },
  10. onShow() {},
  11. methods: {
  12. // 初始化应用
  13. initApp() {
  14. console.log('初始化应用开始~')
  15. // 是否有版本更新
  16. this.isUpdate()
  17. // 初始化应用配置
  18. this.initConfig()
  19. // 免登录
  20. this.checkLogin()
  21. },
  22. initConfig() {
  23. this.globalData.config = config
  24. },
  25. async checkLogin() {
  26. console.log('检测是否登录开始!')
  27. if (getToken() && uni.getStorageSync('sysId')) {
  28. console.log('已登录!')
  29. await this.$store.dispatch('GetPermis')
  30. //判断用户是否有任一菜单权限
  31. if (this.$store.state.permission.permissions_menu && this.$store.state.permission
  32. .permissions_menu != '[]') {
  33. // 开发模式下取消免登录,直接跳转调试页面,生产免登录跳转主页
  34. if (process.env.NODE_ENV == 'production') {
  35. this.$tab.reLaunch('/pages/globalPages/home')
  36. }
  37. } else {
  38. this.$modal.msg('该用户无权限~')
  39. }
  40. } else {
  41. console.log('未登录!')
  42. }
  43. },
  44. isUpdate() {
  45. console.log('检测更新开始~')
  46. const updateManager = wx.getUpdateManager()
  47. updateManager.onCheckForUpdate(function(res) {
  48. // 请求完新版本信息的回调
  49. console.log(res.hasUpdate)
  50. })
  51. updateManager.onUpdateReady(function() {
  52. wx.showModal({
  53. title: '更新提示',
  54. content: '新版本已经准备好,是否重启应用?',
  55. success(res) {
  56. if (res.confirm) {
  57. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  58. updateManager.applyUpdate()
  59. }
  60. }
  61. })
  62. })
  63. updateManager.onUpdateFailed(function() {
  64. // 新版本下载失败
  65. })
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. @import "@/uni_modules/uview-ui/index.scss";
  72. @import '@/static/scss/index.scss'
  73. </style>