Browse Source

手机端页面相关操作登录验证

yangc 8 years ago
parent
commit
c7e93cbc5f

+ 12 - 2
components/mobile/Home.vue

@@ -34,12 +34,12 @@
           </div>
           <p>店铺列表</p>
         </nuxt-link>
-        <nuxt-link to="/mobile/user" class="home-main-content">
+        <a @click="goCollect" class="home-main-content">
           <div>
             <img src="/images/mobile/@2x/home/storebrand@2x.png">
           </div>
           <p>我的收藏</p>
-        </nuxt-link>
+        </a>
         <nuxt-link to="/mobile/brand/brandCenter/ABCD" class="home-main-content">
           <div>
             <!--<i class="icon-pinpai iconfont"></i>-->
@@ -135,6 +135,13 @@
       },
       onCancelSearch: function () {
         this.showMainSearch = false
+      },
+      goCollect: function () {
+        if (this.user.logged) {
+          this.$router.push('/mobile/user')
+        } else {
+          this.$router.push('/auth/login')
+        }
       }
     },
     computed: {
@@ -143,6 +150,9 @@
       },
       counts () {
         return this.$store.state.product.common.counts.data
+      },
+      user () {
+        return this.$store.state.option.user
       }
     }
   }

+ 12 - 2
components/mobile/MobileFooter.vue

@@ -11,9 +11,9 @@
       </nuxt-link>
     </span>
     <span :class="activeType=='user'?'active':''">
-      <nuxt-link to="/mobile/user">
+      <a @click="goCollect">
         <i :class="activeType=='user'?'iconfont icon-icon':'iconfont icon-wo'"></i><p>我</p>
-      </nuxt-link>
+      </a>
     </span>
     <a @click="toTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>
   </div>
@@ -30,6 +30,9 @@
     computed: {
       activeType () {
         return this.$route.path === '/' ? 'home' : this.$route.path === '/mobile/shop' ? 'shops' : this.$route.path === '/mobile/user' ? 'user' : ''
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     mounted: function () {
@@ -48,6 +51,13 @@
       },
       toTop () {
         scrollTo('body', 300)
+      },
+      goCollect: function () {
+        if (this.user.logged) {
+          this.$router.push('/mobile/user')
+        } else {
+          this.$router.push('/auth/login')
+        }
       }
     }
   }

+ 9 - 2
components/mobile/brand/BrandDetail.vue

@@ -200,6 +200,9 @@
           }
         }
         return kindList
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     methods: {
@@ -272,8 +275,12 @@
         }
       },
       toShowPdf: function (url) {
-        if (url && url !== '1') {
-          window.location.href = url
+        if (this.user.logged) {
+          if (url && url !== '1') {
+            window.location.href = url
+          }
+        } else {
+          this.$router.push('/auth/login')
         }
       },
       setActiveType: function (type) {

+ 22 - 11
components/mobile/brand/ComponentDetail.vue

@@ -175,6 +175,9 @@
         } else {
           return false
         }
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     filters: {
@@ -241,21 +244,29 @@
         }
       },
       goAttach: function (url) {
-        if (url && url !== '1') {
-          window.location.href = url
+        if (this.user.logged) {
+          if (url && url !== '1') {
+            window.location.href = url
+          }
+        } else {
+          this.$router.push('/auth/login')
         }
       },
       collectComponent: function () {
-        if (!this.isCollect) {
-          this.$store.dispatch('product/saveEntity', {componentid: this.component.id, kind: 2})
-          this.collectResult = '收藏成功'
-          this.timeoutCount++
-        } else {
-          this.$http.post('/trade/collection/delete/cmpId', [this.component.id]).then(response => {
-            this.collectResult = '取消成功'
+        if (this.user.logged) {
+          if (!this.isCollect) {
+            this.$store.dispatch('product/saveEntity', {componentid: this.component.id, kind: 2})
+            this.collectResult = '收藏成功'
             this.timeoutCount++
-            this.$store.dispatch('product/saveStores')
-          })
+          } else {
+            this.$http.post('/trade/collection/delete/cmpId', [this.component.id]).then(response => {
+              this.collectResult = '取消成功'
+              this.timeoutCount++
+              this.$store.dispatch('product/saveStores')
+            })
+          }
+        } else {
+          this.$router.push('/auth/login')
         }
       }
     }

+ 21 - 14
components/mobile/store/StoreDetail.vue

@@ -140,6 +140,9 @@
       },
       isFocus () {
         return this.$store.state.shop.storeInfo.focusList.data
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     methods: {
@@ -172,20 +175,24 @@
         this.$router.push('/mobile/brand/componentDetail/' + uuid)
       },
       collectStore: function () {
-        if (this.isFocus === 'false') {
-          this.$store.dispatch('shop/StoreFocus', {storeName: this.store.storeName, storeid: this.store.id})
-            .then(response => {
-              this.$store.dispatch('shop/StoreFocusList', {id: this.store.id})
-              this.collectResult = '收藏成功'
-              this.timeoutCount++
-            })
-        } else if (this.isFocus === 'true') {
-          this.$http.post('/trade/storeFocus/delete/storeId', [this.store.id])
-            .then(response => {
-              this.$store.dispatch('shop/StoreFocusList', {id: this.store.id})
-              this.collectResult = '取消成功'
-              this.timeoutCount++
-            })
+        if (this.user.logged) {
+          if (this.isFocus === 'false') {
+            this.$store.dispatch('shop/StoreFocus', {storeName: this.store.storeName, storeid: this.store.id})
+              .then(response => {
+                this.$store.dispatch('shop/StoreFocusList', {id: this.store.id})
+                this.collectResult = '收藏成功'
+                this.timeoutCount++
+              })
+          } else if (this.isFocus === 'true') {
+            this.$http.post('/trade/storeFocus/delete/storeId', [this.store.id])
+              .then(response => {
+                this.$store.dispatch('shop/StoreFocusList', {id: this.store.id})
+                this.collectResult = '取消成功'
+                this.timeoutCount++
+              })
+          }
+        } else {
+          this.$router.push('/auth/login')
         }
       }
     }

+ 1 - 1
layouts/mobile.vue

@@ -13,7 +13,7 @@
       MobileHeader,
       MobileFooter
     },
-    middleware: 'authenticated',
+//    middleware: 'authenticated',
     head () {
       return {
         meta: [

+ 17 - 10
pages/mobile/search/_keycode.vue

@@ -119,6 +119,9 @@
           this.applications = list.application.split(',')
         }
         return list
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     methods: {
@@ -140,19 +143,23 @@
       },
       collect: function (item, $event) {
         this.isClickCollect = true
-        if (!item.isFocus) {
-          this.$http.post('/trade/collection/save', {componentid: item.cmpId, kind: 2})
-            .then(response => {
-              item.isFocus = true
-              this.collectResult = '收藏成功'
+        if (this.user.logged) {
+          if (!item.isFocus) {
+            this.$http.post('/trade/collection/save', {componentid: item.cmpId, kind: 2})
+              .then(response => {
+                item.isFocus = true
+                this.collectResult = '收藏成功'
+                this.timeoutCount++
+              })
+          } else {
+            this.$http.post('/trade/collection/delete/cmpId', [item.cmpId]).then(response => {
+              item.isFocus = false
+              this.collectResult = '取消成功'
               this.timeoutCount++
             })
+          }
         } else {
-          this.$http.post('/trade/collection/delete/cmpId', [item.cmpId]).then(response => {
-            item.isFocus = false
-            this.collectResult = '取消成功'
-            this.timeoutCount++
-          })
+          this.$router.push('/auth/login')
         }
       },
       goComponent: function (uuid) {

+ 20 - 13
pages/mobile/shop/index.vue

@@ -87,6 +87,9 @@
       },
       allPage () {
         return this.list.totalPages
+      },
+      user () {
+        return this.$store.state.option.user
       }
     },
     mounted: function () {
@@ -145,20 +148,24 @@
       focusStore: function (item, $event) {
 //        item.isFocus = item.isFocus === 'false' ? 'true' : 'false'
         $event.stopPropagation()
-        if (item.isFocus === 'false') {
-          this.$http.post('/trade/storeFocus/save', {storeName: item.storeName, storeid: item.id})
-            .then(response => {
-              item.isFocus = 'true'
-              this.collectResult = '收藏成功'
-              this.timeoutCount++
-            })
+        if (this.user.logged) {
+          if (item.isFocus === 'false') {
+            this.$http.post('/trade/storeFocus/save', {storeName: item.storeName, storeid: item.id})
+              .then(response => {
+                item.isFocus = 'true'
+                this.collectResult = '收藏成功'
+                this.timeoutCount++
+              })
+          } else {
+            this.$http.post('/trade/storeFocus/delete/storeId', [item.id])
+              .then(response => {
+                item.isFocus = 'false'
+                this.collectResult = '取消成功'
+                this.timeoutCount++
+              })
+          }
         } else {
-          this.$http.post('/trade/storeFocus/delete/storeId', [item.id])
-            .then(response => {
-              item.isFocus = 'false'
-              this.collectResult = '取消成功'
-              this.timeoutCount++
-            })
+          this.$router.push('/auth/login')
         }
       },
       goStoreDetail: function (uuid) {

+ 7 - 2
store/provider.js

@@ -9,7 +9,12 @@ function countStoreOrderCount (store) {
   return axios.get('/api/provider/order/storeid/' + store.uuid + '/count')
 }
 function findStoreFocusInMobil (store) {
-  return axios.get('/trade/storeFocus/ifFocus?storeid=' + store.id)
+  axios.get('/trade/storeFocus/ifFocus?storeid=' + store.id).then(response => {
+    return response.data
+  }, err => {
+    console.log(err)
+    return false
+  })
 }
 export const actions = {
   // 获取销售排行榜信息
@@ -120,7 +125,7 @@ export const actions = {
           .then(result => {
             if (result) {
               for (let i = 0; i < result.length; i++) {
-                listData.content[i].isFocus = result[i].data
+                listData.content[i].isFocus = result[i] ? result[i].data : false
               }
             }
             commit('stores/GET_STORE_LIST_SUCCESS', listData)

+ 3 - 0
store/searchData.js

@@ -12,6 +12,9 @@ function reloadListData ({ commit }, listData) {
       }
     }
     commit('searchList/GET_LIST_SUCCESS', listData)
+  }, err => {
+    console.log(err)
+    commit('searchList/GET_LIST_SUCCESS', listData)
   })
 }
 export const actions = {