auth.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import modeMap from '~/configs/mode-map'
  2. import axios from 'axios'
  3. const whiteList = ['/auth']
  4. export default function ({ route, error, redirect }) {
  5. if (whiteList.indexOf(route.path) > -1) return
  6. const authUserId = parseInt(route.params.template)
  7. const auth = modeMap.find((item) => item.authUserId === authUserId)
  8. let routePrefix = !auth ? `/${authUserId}/app` : `/${authUserId}/${auth.mode}`
  9. const baseURL = process.env.BASE_URL + '/wx/auth/shop/info'
  10. console.log(auth && auth.mode, authUserId)
  11. return axios
  12. .get(baseURL, {
  13. params: { authUserId: authUserId },
  14. })
  15. .then(({ data }) => {
  16. if (data.code === -1) {
  17. error({
  18. statusCode: 404,
  19. message: '页面不存在',
  20. })
  21. } else if (authUserId === 12 && auth.mode === 'ross' && route.path.indexOf(`${authUserId}/app`) > -1) {
  22. // console.log(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`))
  23. redirect(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`))
  24. } else if (route.path.indexOf(routePrefix) !== 0) {
  25. error({
  26. statusCode: 404,
  27. message: '页面不存在',
  28. })
  29. }
  30. })
  31. .catch(() => {
  32. error({
  33. statusCode: 404,
  34. message: '页面不存在',
  35. })
  36. })
  37. }