Browse Source

微信绑定页面

shenjj 7 years ago
parent
commit
d5eccf0146

+ 19 - 7
components/mobile/Home.vue

@@ -68,7 +68,7 @@
     </div>
     <main-search v-if="showMainSearch" @cancelSearchAction="onCancelSearch"></main-search>
     <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox" :url="url"></login-box>
   </div>
 </template>
 <script>
@@ -102,7 +102,8 @@
         size: 5,
         purchaseManListData: [],
         isChange: false,
-        isDataChange: false
+        isDataChange: false,
+        url: ''
       }
     },
     components: {
@@ -111,11 +112,6 @@
       RemindBox,
       LoginBox
     },
-    mounted: function () {
-      this.$nextTick(() => {
-        window.addEventListener('scroll', this.scroll, false)
-      })
-    },
     watch: {
       '$store.state.applyPurchase.purchaseManList.purchaseHomeList.data': {
         handler: function (val) {
@@ -168,6 +164,7 @@
             this.onRemind('抱歉,您暂未开通卖家中心,可前往PC端开通')
           }
         } else {
+          this.url = '/mobile/applyPurchase/list/businessOpportunity'
           this.showLoginBox = true
         }
       },
@@ -183,6 +180,21 @@
         this.isSearchSearchingMore = true
         this.reloadData()
       }
+    },
+    mounted() {
+      this.$nextTick(() => {
+        window.addEventListener('scroll', this.scroll, false)
+        if (this.$route.query.code) {
+          let ua = window.navigator.userAgent.toLowerCase()
+          if (ua.match(/micromessenger/i)[0] === 'micromessenger') {
+            let info = localStorage.getItem('USOFTMALLWECHATINFO')
+            if (info) {
+              this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', JSON.parse(info))
+            }
+            this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
+          }
+        }
+      })
     }
   }
 </script>

+ 5 - 12
components/mobile/MobileFooter.vue

@@ -34,7 +34,7 @@
       </a>
     </span>
     <a @click="toTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box :url="url" @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
     <!--<publish-seek :showSayPriceBox="showSayPriceBox" @cancelAction="showSayPriceBox = false" @reloadAction="onReload" @remindAction="onRemind"></publish-seek>-->
     <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
   </div>
@@ -52,7 +52,8 @@
         showLoginBox: false,
 //        showSayPriceBox: false,
         remindText: '',
-        timeoutCount: 0
+        timeoutCount: 0,
+        url: ''
       }
     },
     components: {
@@ -102,6 +103,7 @@
         scrollTo('body', 300)
       },
       goWithLogin: function (url, isSelf) { // 是否拦截个人
+        this.url = url
         if (this.user.logged) {
           if (isSelf && (!this.user.data.enterprise.uu || this.user.data.enterprise.isVendor !== 313)) {
             this.onRemind('请先前往pc端开通卖家中心')
@@ -109,15 +111,6 @@
             this.$router.push(url)
           }
         } else {
-          let ua = window.navigator.userAgent.toLowerCase()
-          if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger') {
-            if (this.$store.state.option.wechatInfo.data.status === 0) {
-              this.$router.push('/mobile/wechat')
-            } else {
-              // 发送请求
-              console.log('发送请求')
-            }
-          } else {
             this.showLoginBox = true
           }
         }
@@ -142,7 +135,7 @@
         this.timeoutCount ++
       }
     }
-  }
+
 </script>
 <style scoped lang="scss">
   .mobile-footer{

+ 4 - 2
components/mobile/applyPurchase/SeekList.vue

@@ -51,7 +51,7 @@
       </li>
     </ul>
     <empty-status v-if="!purchaseManListData || purchaseManListData.length == 0 && !isDataChange" :type="isSearch ? 'search' : 'collect'" :text="isSearch ? `抱歉,暂无与“${keyword}”匹配的求购信息` : '抱歉,暂无求购信息'" :showLink="true"></empty-status>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box :url="url" @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
     <say-price :showSayPriceBox="showSayPriceBox" @cancelSayPriceAction="onSayPriceCancel"></say-price>
     <say-price-info v-if="showSayPriceInfoBox" :agreed="agreed" @cancelSayPriceInfoAction="onSayPriceInfoCancel" :userType="userType"></say-price-info>
     <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
@@ -70,7 +70,8 @@ export default {
       remindText: '',
       timeoutCount: 0,
       agreed: 0,
-      purchaseManListData: []
+      purchaseManListData: [],
+      url: ''
     }
   },
   components: {
@@ -156,6 +157,7 @@ export default {
           this.onRemind('个人账户暂不可报价')
         }
       } else {
+        this.url = this.$route.fullPath
         this.showLoginBox = true
       }
       return false

+ 5 - 2
components/mobile/brand/ComponentDetail.vue

@@ -95,7 +95,7 @@
     </div>
     <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
     <loading v-show="isSearchingMore"></loading>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox" :url="url"></login-box>
   </div>
 </template>
 <script>
@@ -123,7 +123,8 @@
         isSearchingMore: false,
         searchLists: [],
         showLoginBox: false,
-        isScrollOverTab: false
+        isScrollOverTab: false,
+        url: ''
       }
     },
     components: {
@@ -263,6 +264,7 @@
             window.location.href = url
           }
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       },
@@ -280,6 +282,7 @@
             })
           }
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       }

+ 19 - 1
components/mobile/common/LoginBox.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="mobile-modal">
+  <div class="mobile-modal" v-show="showLogin">
     <div class="mobile-modal-box">
       <div class="mobile-modal-header">请登录后再操作<i @click="close" class="icon-guanbi iconfont"></i></div>
       <div class="mobile-modal-content">
@@ -12,6 +12,12 @@
 <script>
   export default {
     name: 'loginBox',
+    props: ['url'],
+    data() {
+      return {
+        showLogin: false
+      }
+    },
     methods: {
       close: function () {
         this.$emit('onLoginBoxClose')
@@ -26,6 +32,18 @@
           }
         })
       }
+    },
+    mounted() {
+      let ua = window.navigator.userAgent.toLowerCase()
+      if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger') {
+        if (this.url) {
+          this.$router.push(`/mobile/wechat?url=${this.url}`)
+        } else {
+          this.$router.push(`/mobile/wechat`)
+        }
+      } else {
+        this.showLogin = true
+      }
     }
   }
 </script>

+ 4 - 2
components/mobile/store/StoreDetail.vue

@@ -134,7 +134,7 @@
     </div>
     <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
     <loading v-show="isSearchingMore"></loading>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox" :url="url"></login-box>
   </div>
 </template>
 <script>
@@ -151,7 +151,8 @@
         searchLists: [],
         page: 1,
         showLoginBox: false,
-        isScrollOverTab: false
+        isScrollOverTab: false,
+        url: ''
       }
     },
     components: {
@@ -276,6 +277,7 @@
               })
           }
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       }

+ 4 - 2
components/mobile/supplier/SupplierDetail.vue

@@ -72,7 +72,7 @@
     </div>
     <publish-supplier-seek :product="currentProduct" :showPublishBox="showPublishBox" @cancelAction="showPublishBox = false" @remindAction="onRemind"></publish-supplier-seek>
     <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box :url="url" @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
   </div>
 </template>
 <script>
@@ -92,7 +92,8 @@
         remindText: '',
         timeoutCount: 0,
         currentProduct: {},
-        showLoginBox: false
+        showLoginBox: false,
+        url: ''
       }
     },
     components: {
@@ -161,6 +162,7 @@
           this.currentProduct = product
           this.showPublishBox = true
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       },

+ 10 - 1
middleware/authenticated.js

@@ -2,6 +2,15 @@ export default function ({ isServer, store, req, redirect, route }) {
   // If nuxt generate, pass this middleware
   if (isServer && !req) return
   if (!store.state.option.user.logged) {
-    return redirect(`/auth/login?returnUrl=${'http://' + req.headers.host + route.fullPath}`)
+    let ua = req.headers['user-agent'].toLowerCase()
+    if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') === -1) {
+      // 判断是浏览器,切不存在code
+      return redirect(`/mobile/wechat/toggle?url=${route.path}`)
+    } else if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') > -1) {
+      // 判断是浏览器,切不存在code
+      return redirect(`/mobile/wechat?url=${route.path}`)
+    } else {
+      return redirect(`/auth/login?returnUrl=${'http://' + req.headers.host + route.fullPath}`)
+    }
   }
 }

+ 10 - 0
middleware/wechatInfo.js

@@ -0,0 +1,10 @@
+export default function ({ isServer, store, req, redirect, route }) {
+  if (isServer && !req) return
+  if (!store.state.option.user.logged) {
+    let ua = store.state.option.userAgent.toLowerCase()
+    if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') === -1) {
+      // 判断是浏览器,切不存在code
+      return redirect(`/mobile/wechat/toggle?url=${route.path}`)
+    }
+  }
+}

+ 1 - 14
pages/index.vue

@@ -25,6 +25,7 @@
 
   export default {
     name: 'index',
+    middleware: 'wechatInfo',
     layout (context) {
       return context.store.state.option.isMobile ? 'mobile' : 'main'
     },
@@ -120,20 +121,6 @@
         return this.$store.state.option.isMobile
       }
     },
-    mounted() {
-      this.$nextTick(() => {
-        if (this.$route.query.code) {
-          let ua = window.navigator.userAgent.toLowerCase()
-          if (ua.match(/micromessenger/i)[0] === 'micromessenger') {
-            let info = localStorage.getItem('USOFTMALLWECHATINFO')
-            if (info) {
-              this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', JSON.parse(info))
-            }
-            this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
-          }
-        }
-      })
-    },
     methods: {
       listenOpen () {
         this.isOpen = false

+ 4 - 2
pages/mobile/search/_keycode.vue

@@ -49,7 +49,7 @@
     </div>
     <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
     <loading v-show="isSearchSearchingMore"></loading>
-    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+    <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox" :url="url"></login-box>
   </div>
 </template>
 
@@ -74,7 +74,8 @@
         searchLists: [],
         isSearchSearchingMore: false,
         showLoginBox: false,
-        isChange: false
+        isChange: false,
+        url: ''
       }
     },
     components: {
@@ -184,6 +185,7 @@
             })
           }
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       },

+ 4 - 2
pages/mobile/shop/index.vue

@@ -49,7 +49,7 @@
           </div>
         </div>
       </div>
-      <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
+      <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox" :url="url"></login-box>
     </div>
   </div>
 </template>
@@ -75,7 +75,8 @@
         showStoreInfo: false,
         enterpriseInfo: {},
         showLoginBox: false,
-        keyword: ''
+        keyword: '',
+        url: ''
       }
     },
     components: {
@@ -204,6 +205,7 @@
               })
           }
         } else {
+          this.url = this.$route.fullPath
           this.showLoginBox = true
         }
       },

+ 68 - 3
pages/mobile/wechat/index.vue

@@ -37,11 +37,32 @@
       </nuxt-link>
     </div>
     <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
+    <div class="listAlert" ref="userContent" v-show="wechatInfo.enterprises">
+      <ul>
+        <li v-for="(item, index) in wechatInfo.enterprises" @click="clickItem(item)">
+          {{item.enName}}
+        </li>
+      </ul>
+    </div>
   </div>
 </template>
 
 <script>
   import { RemindBox } from '~components/mobile/common'
+  import BScroll from 'better-scroll'
+  // 实现深拷贝
+  function deepCopy(target) {
+    if (typeof target !== 'object') return
+    // 判断目标类型,来创建返回值
+    var newObj = target instanceof Array ? [] : {}
+    for (var item in target) {
+      // 只复制元素自身的属性,不复制原型链上的
+      if (target.hasOwnProperty(item)) {
+        newObj[item] = typeof target[item] === 'object' ? deepCopy(target[item]) : target[item]
+      }
+    }
+    return newObj
+  }
   export default {
     name: 'wechatView',
     layout: 'mobileNoHeader',
@@ -56,10 +77,32 @@
        }
     },
     mounted() {
-      let info = localStorage.getItem('USOFTMALLWECHATINFO')
-      this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', JSON.parse(info))
+      this.$nextTick(() => {
+        let info = localStorage.getItem('USOFTMALLWECHATINFO')
+        this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', JSON.parse(info))
+        if (this.BScroll) {
+          this.BScroll.refresh()
+        } else {
+          this.BScroll = new BScroll(this.$refs.userContent, {
+            click: true
+          })
+        }
+      })
     },
     methods: {
+      clickItem(item) {
+        let userAccount = deepCopy(this.$store.state.option.wechatInfo.data.userAccount)
+        userAccount.spaceUU = item.uu
+        this.$http.get('/newLogin/other', {params: userAccount}).then(res => {
+          this.$store.dispatch('loadUserInfo').then(() => {
+             if (this.$route.query.url && this.$route.query.url !== '') {
+                this.$router.replace(this.$route.query.url)
+             } else {
+               this.goLastPage()
+             }
+          })
+        })
+      },
       telphoneBlur() {
         this.telerror = false
         if (!/^1[3|5|7|8]\d{9}$/.test(this.telphoneNum)) {
@@ -72,7 +115,8 @@
         }
         let openid = this.$store.state.option.wechatInfo.data.openid
         this.$http.post('/wx/bindUser', {userTel: this.telphoneNum, userPwd: this.passwordNum, openId: openid}).then(res => {
-          console.log(res)
+          this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', res.data)
+          localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(res.data))
         })
       },
       resgiter() {
@@ -88,10 +132,15 @@
     },
     computed: {
       userName() {
+        // return ''
         return this.$store.state.option.wechatInfo.data.nickname
       },
       headerImg() {
+        // return ''
         return this.$store.state.option.wechatInfo.data.headimgurl
+      },
+      wechatInfo() {
+        return this.$store.state.option.wechatInfo.data
       }
     }
   }
@@ -266,5 +315,21 @@
       }
     }
   }
+  .listAlert {
+    position: fixed;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    background: #fff;
+    padding: 0 0.2rem;
+    overflow: hidden;
+    z-index: 10000;
+    li {
+      line-height: 0.98rem;
+      height: 0.98rem;
+      border-bottom: 1px solid #dedede;
+    }
+  }
 }
 </style>

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

@@ -4,11 +4,11 @@
 
 <script>
   export default {
-    // name: 'wechattoggle',
-    // layout: 'mobileNoHeader',
+    layout: 'mobileNoHeader',
     mounted() {
       this.$nextTick(() => {
-        window.open('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd29bbca61728b189&redirect_uri=http://wwpszp.natappfree.cc&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect')
+        // this.$route.query.url
+        window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd29bbca61728b189&redirect_uri=http://wwpszp.natappfree.cc${this.$route.query.url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
       })
     }
   }