1
0

router.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // router.js
  2. import {
  3. RouterMount,
  4. createRouter
  5. } from 'uni-simple-router';
  6. const router = createRouter({
  7. platform: process.env.VUE_APP_PLATFORM,
  8. routes: [...ROUTES]
  9. });
  10. import {
  11. wxLogin,
  12. appWxLogin
  13. } from '@/api/login.js'
  14. import {
  15. checkHasWxLogin,
  16. checkHasAdminLogin
  17. } from '@/utils/auth.js'
  18. //全局路由前置守卫
  19. router.beforeEach((to, from, next) => {
  20. // 管理页面:超管
  21. if (to.meta && to.meta.auth == 'admin') {
  22. if (checkHasAdminLogin()) {
  23. next()
  24. } else {
  25. uni.$eShowModal({
  26. title: '提示',
  27. content: '未登录超管账号或登录状态已过期,是否立即登录?',
  28. showCancel: true,
  29. cancelText: '否',
  30. cancelColor: '#999999',
  31. confirmText: '是',
  32. confirmColor: '#03a9f4'
  33. }).then(res => {
  34. uni.navigateTo({
  35. url: '/pagesB/login/login'
  36. })
  37. }).catch(err => {
  38. uni.switchTab({
  39. url: '/pages/tabbar/about/about'
  40. })
  41. })
  42. next(false)
  43. }
  44. }
  45. // 普通用户需要登录
  46. else if (to.meta && to.meta.auth == 'login') {
  47. if (checkHasWxLogin()) {
  48. next()
  49. } else {
  50. uni.$eShowModal({
  51. title: '提示',
  52. content: `主人,您好像还没有登录呢?`,
  53. showCancel: true,
  54. cancelText: '取消',
  55. cancelColor: '#999999',
  56. confirmText: '登录',
  57. confirmColor: '#03a9f4'
  58. }).then(res => {
  59. // #ifdef APP-PLUS
  60. appWxLogin()
  61. // #endif
  62. // #ifdef MP-WEIXIN
  63. wxLogin()
  64. // #endif
  65. // #ifndef APP-PLUS||MP-WEIXIN
  66. // #endif
  67. }).catch(err => {})
  68. next(false)
  69. }
  70. } else {
  71. next();
  72. }
  73. });
  74. // 全局路由后置守卫
  75. router.afterEach((to, from) => {
  76. console.log('跳转结束')
  77. })
  78. export {
  79. router,
  80. RouterMount
  81. }