App.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script>
  2. import config from './config'
  3. import {
  4. getToken
  5. } from '@/utils/auth'
  6. import usePermissionStore from '@/stores/permission.js';
  7. export default {
  8. onLaunch: function() {
  9. this.initApp();
  10. },
  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 usePermissionStore().GetPermis()
  30. //判断用户是否有任一菜单权限
  31. if (usePermissionStore().permissions_menu && usePermissionStore().permissions_menu != '[]') {
  32. // 开发模式下取消免登录,直接跳转调试页面,生产免登录跳转主页
  33. if (process.env.NODE_ENV == 'production') {
  34. this.$tab.reLaunch('/pages/globalPages/home')
  35. }
  36. } else {
  37. this.$modal.msg('该用户无权限~')
  38. }
  39. } else {
  40. console.log('未登录!')
  41. }
  42. },
  43. isUpdate() {
  44. console.log('检测更新开始~')
  45. const updateManager = wx.getUpdateManager()
  46. updateManager.onCheckForUpdate(function(res) {
  47. // 请求完新版本信息的回调
  48. console.log(res.hasUpdate)
  49. })
  50. updateManager.onUpdateReady(function() {
  51. wx.showModal({
  52. title: '更新提示',
  53. content: '新版本已经准备好,是否重启应用?',
  54. success(res) {
  55. if (res.confirm) {
  56. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  57. updateManager.applyUpdate()
  58. }
  59. }
  60. })
  61. })
  62. updateManager.onUpdateFailed(function() {
  63. // 新版本下载失败
  64. })
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. /*每个页面公共css */
  71. @import "./uni_modules/vk-uview-ui/index.scss";
  72. @import "static/scss/index.scss"
  73. </style>