康巴易测肤/伤疤uniapp小程序类
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 1.8KB

1ヶ月前
1ヶ月前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // router.js
  2. import {
  3. RouterMount,
  4. createRouter,
  5. runtimeQuit
  6. } from 'uni-simple-router'
  7. import {
  8. getToken,
  9. removeToken
  10. } from '@/utils/auth'
  11. import store from '@/store'
  12. const router = createRouter({
  13. platform: process.env.VUE_APP_PLATFORM,
  14. routerErrorEach: ({
  15. type,
  16. level,
  17. ...args
  18. }) => {
  19. // #ifdef APP-PLUS
  20. // 请勿删除此代码块
  21. if (type === 3) {
  22. router.$lockStatus = false;
  23. uni.showModal({
  24. title: '提示',
  25. content: '您确定要退出应用吗?',
  26. success: function(res) {
  27. if (res.confirm) {
  28. let main = plus.android.runtimeMainActivity();
  29. plus.runtime.quit = function() {
  30. main.moveTaskToBack(false);
  31. };
  32. plus.runtime.quit();
  33. }
  34. }
  35. });
  36. }
  37. // 请勿删除此代码块
  38. // #endif
  39. },
  40. applet: {
  41. animationDuration: 300 //默认 300ms v2.0.6+
  42. },
  43. routes: [...ROUTES]
  44. });
  45. // 免登录白名单
  46. const whiteList = ['/pages/login/index', '/pages/details/index', '/pages/skin-assessment/croppedImage', '/pages/user/mine', '/pages/user/info', '/pages/skin-assessment/photograph']
  47. //全局路由前置守卫
  48. router.beforeEach((to, from, next) => {
  49. if (getToken()) {
  50. /* 存在token */
  51. if (to.path === '/pages/login/index') {
  52. next({
  53. path: '/pages/index/index',
  54. NAVTYPE: 'replace'
  55. })
  56. } else {
  57. if (!store.getters.userId) {
  58. // 判断当前用户是否已拉取完userInfo信息
  59. store.dispatch('UserInfo').then((res) => {
  60. next();
  61. }).catch(() => {
  62. next();
  63. })
  64. } else {
  65. next();
  66. }
  67. }
  68. } else {
  69. /* 不存在token */
  70. if (whiteList.indexOf(to.path) !== -1) {
  71. // 在免登录白名单,直接进入
  72. next();
  73. } else {
  74. next();
  75. // removeToken();
  76. // next({
  77. // path: '/pages/login/index',
  78. // NAVTYPE: 'replaceAll'
  79. // })
  80. }
  81. }
  82. });
  83. // 全局路由后置守卫
  84. router.afterEach((to, from) => {})
  85. export {
  86. router,
  87. RouterMount
  88. }