wechatInfo.js 762 B

1234567891011121314151617
  1. export default function ({ isServer, store, req, redirect, route }) {
  2. if (isServer && !req) return
  3. // nuxt拦截器 存在一个问题,如果进入到了判断的地方,一定需要做跳转路由相关操作,不然会出现404
  4. if (!store.state.option.wechatInfo.data.openid) {
  5. let ua = store.state.option.userAgent.toLowerCase()
  6. // let _info = localStorage.getItem('USOFTMALLWECHATINFO')
  7. if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') === -1) {
  8. // 判断是浏览器,且不存在code
  9. console.log('进入拦截器')
  10. if (isServer) {
  11. return redirect(`/mobile/wechat/toggle?url=${route.path}`)
  12. }
  13. } else {
  14. return true
  15. }
  16. }
  17. }