auth.js 884 B

1234567891011121314151617181920212223242526272829303132
  1. import modeMap from '~/configs/mode-map'
  2. import axios from 'axios'
  3. const whiteList = ['/auth']
  4. export default function ({ route, error }) {
  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(authUserId)
  11. return axios
  12. .get(baseURL, {
  13. params: { authUserId: authUserId },
  14. })
  15. .then(({ data }) => {
  16. if (data.code === -1 || route.path.indexOf(routePrefix) !== 0) {
  17. error({
  18. statusCode: 404,
  19. message: '页面不存在',
  20. })
  21. }
  22. })
  23. .catch(() => {
  24. error({
  25. statusCode: 404,
  26. message: '页面不存在',
  27. })
  28. })
  29. }