index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // 路由
  2. import {
  3. RouterMount,
  4. createRouter
  5. } from 'uni-simple-router'
  6. import store from '@/common/store'
  7. const router = createRouter({
  8. platform: process.env.VUE_APP_PLATFORM,
  9. applet: {
  10. animationDuration: 0 //默认 300ms
  11. },
  12. routerErrorEach: ({
  13. type,
  14. msg
  15. }) => {
  16. switch (type) {
  17. case 3: // APP退出应用
  18. // #ifdef APP-PLUS
  19. router.$lockStatus = false;
  20. uni.showModal({
  21. title: '提示',
  22. content: '您确定要退出应用吗?',
  23. success: function(res) {
  24. if (res.confirm) {
  25. plus.runtime.quit();
  26. }
  27. }
  28. });
  29. // #endif
  30. break;
  31. case 2:
  32. case 0:
  33. router.$lockStatus = false;
  34. break;
  35. default:
  36. break;
  37. }
  38. },
  39. // 通配符,非定义页面,跳转404
  40. routes: [...ROUTES,
  41. {
  42. path: '*',
  43. redirect: (to) => {
  44. return {
  45. name: '404'
  46. }
  47. }
  48. },
  49. ]
  50. });
  51. //全局路由前置守卫
  52. router.beforeEach((to, from, next) => {
  53. // 权限控制登录
  54. if (to.meta && to.meta.auth && !store.getters.isLogin) {
  55. uni.$u.toast('请登录后再操作')
  56. let pageParams = {
  57. url: to.path,
  58. params:to.query
  59. }
  60. uni.setStorageSync('formPage',JSON.stringify(pageParams))
  61. setTimeout(()=>{
  62. next({
  63. path: '/pages/account/login/login'
  64. })
  65. },1000)
  66. } else {
  67. next()
  68. }
  69. });
  70. export {
  71. router,
  72. RouterMount
  73. }