Browse Source

修改微信小程序404问题

shenjj 7 years ago
parent
commit
a9902a9481

+ 6 - 2
components/mobile/Home.vue

@@ -191,8 +191,12 @@
     },
     mounted() {
       this.$nextTick(() => {
-//        window.addEventListener('scroll', this.scroll, false)
-        if (this.$route.query.code) {
+        let ua = this.$store.state.option.userAgent.toLowerCase()
+        // 如果当前为授权则进入这里
+        if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && !this.$route.query.code) {
+          window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+          // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd29bbca61728b189&redirect_uri=http://bf2sgy.natappfree.cc&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+        } else if (this.$route.query.code) {
           let ua = window.navigator.userAgent.toLowerCase()
           if (ua.match(/micromessenger/i)[0] === 'micromessenger') {
             let info = localStorage.getItem('USOFTMALLWECHATINFO')

+ 6 - 8
middleware/wechatInfo.js

@@ -1,17 +1,15 @@
 export default function ({ isServer, store, req, redirect, route }) {
   if (isServer && !req) return
+  if (isServer) return
   // nuxt拦截器 存在一个问题,如果进入到了判断的地方,一定需要做跳转路由相关操作,不然会出现404
+  //  && window.__wxjs_environment !== 'miniprogram'
   if (!store.state.option.wechatInfo.data.openid) {
     let ua = store.state.option.userAgent.toLowerCase()
-    // let _info = localStorage.getItem('USOFTMALLWECHATINFO')
     if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') === -1) {
-      // 判断是浏览器,且不存在code
-      console.log('进入拦截器')
-      if (isServer) {
-        return redirect(`/mobile/wechat/toggle?url=${route.path}`)
-      }
-    } else {
-      return true
+      // 判断是浏览器,且不存在code且不是微信小程序打开
+      // return redirect(`/mobile/wechat/toggle?url=${route.path}`)
+      // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com${route.path}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+      // return
     }
   }
 }

+ 1 - 1
pages/index.vue

@@ -25,7 +25,7 @@
 
   export default {
     name: 'index',
-    middleware: 'wechatInfo',
+    // middleware: 'wechatInfo',
     layout (context) {
       return context.store.state.option.isMobile ? 'mobile' : 'main'
     },

+ 2 - 2
pages/mobile/wechat/index.vue

@@ -149,11 +149,11 @@
     computed: {
       userName() {
         // return ''
-        return this.$store.state.option.wechatInfo.data.nickname
+        return this.wechatInfo.nickname
       },
       headerImg() {
         // return ''
-        return this.$store.state.option.wechatInfo.data.headimgurl
+        return this.wechatInfo.headimgurl
       },
       wechatInfo() {
         return this.$store.state.option.wechatInfo.data

+ 1 - 1
pages/mobile/wechat/toggle.vue

@@ -9,7 +9,7 @@
       this.$nextTick(() => {
         // this.$route.query.url
         window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com${this.$route.query.url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
-        // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd29bbca61728b189&redirect_uri=http://6fpbmx.natappfree.cc${this.$route.query.url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+        // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd29bbca61728b189&redirect_uri=http://yq43d5.natappfree.cc${this.$route.query.url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
       })
     }
   }

+ 1 - 1
store/index.js

@@ -457,7 +457,7 @@ export const actions = {
         commit('count/GET_INQUIRYSHEET_FAILURE', err)
       })
   },
-  // 保存微信信息
+  // 微信公众号 -- 保存微信信息
   GerWechatInfo({ commit }, params = {}) {
     commit('option/REQUEST_WECHATINFO_STATUS')
     return axios.get('/wx/getWxUserInfo', { params: params })