Browse Source

Merge branch 'master' of ssh://10.10.101.21/source/mall-web-ssr into HEAD

# Conflicts:
#	nuxt.config.js
yangc 7 years ago
parent
commit
fb6f873bf8

+ 15 - 6
components/default/Header.vue

@@ -29,8 +29,10 @@
               </ul>
             </div>
             <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
-            <nuxt-link class="item" to="/user">买家中心</nuxt-link>
-            <nuxt-link class="item" to="/vendor">卖家中心</nuxt-link>
+            <!--<nuxt-link class="item" to="/user">买家中心</nuxt-link>
+            <nuxt-link class="item" to="/vendor">卖家中心</nuxt-link>-->
+            <a class="item" :href="url + '/user'">买家中心</a>
+            <a class="item" :href="url + '/vendor'">卖家中心</a>
           </template>
           <template v-else>
             <a class="item" @click="onLoginClick()">登录</a>
@@ -61,16 +63,20 @@
           return ens.find(item => item.current) || ens[0]
         }
         return {}
+      },
+      url () {
+        return this.$store.state.option.url
       }
     },
     methods: {
       logout () {
-        this.$store.dispatch('logout')
+        this.$router.push('/auth/logout')
       },
       onLoginClick () {
         this.$http.get('/login/page').then(response => {
-          // 跳转登录
-          window.location.href = response.data.content
+          if (response.data) {
+            this.$router.push('/auth/login')
+          }
         })
         // TODO 待Account Center改版
       },
@@ -80,10 +86,13 @@
       // 切换当前企业
       switchEnterprise (en) {
         this.toggleEnterprises()
-        this.$http.get(`authentication/${en.enUU}`).then(() => {
+        this.$http.get(`/user/authentication/${en.uu}`).then(() => {
           this.$store.dispatch('loadUserInfo')
         })
       }
+    },
+    beforeMount () {
+      // this.$store.dispatch('loadUserInfo')
     }
   }
 </script>

+ 3 - 3
components/main/count/Box.vue

@@ -58,8 +58,8 @@
     height: 60px;
     overflow: hidden;
 
-    .swiper-container {
-      height: 100%;
-    }
+  .swiper-container {
+    height: 100%;
+  }
   }
 </style>

+ 4 - 0
components/product/brand/BrandComponent.vue

@@ -103,6 +103,10 @@
     margin-left: 20px;
     width: 970px;
   }
+  .bgf7 th{
+    color: #333;
+    vertical-align: middle;
+  }
   .component-list .type-list{
     height: 34px;
     width: 150px;

+ 172 - 167
components/store/RecommendProduct.vue

@@ -42,171 +42,176 @@ export default {
 </script>
 <style scoped>
   #recommend-fragment{
-		width: 1190px;
-		margin: 0 auto;
-	}
-	.recommend-list{
-		width: 100%;
-		margin: 0 auto;
-		display: inline-block;
-	}
-	#recommend-fragment ul{
-		width: 100%;
-		margin: 0 auto;
-		display: inline-block;
-		-webkit-padding-start: 0;
-	}
-	#recommend-fragment ul li{
-		float: left;
-		width: 218px;
-		height: 260px;
-		border: #d2d2d2 1px solid;
-		position: relative;
-		overflow: hidden;
-		margin-right: 25px;
-		margin-bottom: 20px;
-	}
-	#recommend-fragment ul li:nth-child(5n){
-		margin-right: 0;
-	}
-	#recommend-fragment ul li .img{
-		height: 175px;
-		text-align: center;
-		line-height: 170px;
-	}
-	#recommend-fragment ul li .img img{
-		max-width: 120px;
-		max-height: 120px;
-	}
-	#recommend-fragment ul li .content{
-		width: 100%;
-		margin: 0 auto;
-	}
-	#recommend-fragment ul li .content p{
-		width: 90%;
-		display: inline-block;
-		line-height: 22px;
-		font-size: 14px;
-		overflow: hidden;
-		text-overflow: ellipsis;
-		white-space: nowrap;
-		margin-bottom: 0;
-		padding-left: 10px;
-	}
-	#recommend-fragment ul li .content p.price{
-		color: #ff9000;
-		font-size: 16px;
-		font-weight: bold;
-	}
-	.color666{
-		color: #666;
-	}
-	#recommend-fragment ul li .hover-show{
-		width: 100%;
-		height: 100%;
-		position: absolute;
-		top: 100%;
-		left: 0;
-		background: rgba(80,120,203,.85);
-		padding: 30px 10px;
-	}
-	#recommend-fragment ul li:hover .hover-show{
-		top: 0;
-		transition: top .5s ease-in;
-	}
-	#recommend-fragment ul li .hover-show div{
-		width: 100%;
-		margin: 0 auto;
-		text-align: left;
-		color: #fff;
-		line-height: 25px;
-	}
-	#recommend-fragment ul li .hover-show .title{
-		font-size: 18px;
-		margin-top: 8px;
-		text-overflow: ellipsis;
-		white-space: nowrap;
-		overflow: hidden;
-		margin-bottom: 0;
-	}
-	#recommend-fragment ul li .hover-show .type{
-		font-size: 14px;
-	}
-	#recommend-fragment ul li .hover-show .hr{
-		text-align: center;
-		margin-top: 5px;
-	}
-	#recommend-fragment ul li .hover-show .hr span{
-		font-size: 16px;
-		position: relative;
-	}
-	#recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
-		content: '';
-		position: absolute;
-		display: inline-block;
-		width: 65px;
-		height: 1px;
-		background: #fff;
-		top: 10px;
-	}
-	#recommend-fragment ul li .hover-show .hr span:before{
-		left: 53px;
-	}
-	#recommend-fragment ul li .hover-show .hr span:after{
-		right: 53px;
-	}
-	#recommend-fragment ul li .hover-show .price{
-		font-size: 20px;
-		text-align: center;
-		line-height: 48px;
-	}
-	#recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
-		text-align: center;
-		position: absolute;
-	}
-	#recommend-fragment ul li .hover-show .by-cart{
-		bottom: 50px;
-	}
-	#recommend-fragment ul li .hover-show .buy-now{
-		bottom: 15px;
-	}
-	#recommend-fragment ul li .hover-show .by-cart button{
-		display: inline-block;
-		width: 38px;
-		height: 38px;
-		border-radius: 100%;
-		background: #fff;
-		line-height: 38px;
-		margin-bottom: 5px;
-		cursor: pointer;
-		border: none;
-		z-index: 100;
-		position: relative;
-	}
-	#recommend-fragment ul li .hover-show .buy-now button{
-		display: inline-block;
-		width: 90px;
-		height: 34px;
-		text-align: center;
-		font-size: 14px;
-		border-radius: 4px;
-		background: #df1b0f;
-		line-height: 34px;
-		color: #fff;
-		cursor: pointer;
-		border: none;
-		z-index: 100;
-		position: relative;
-	}
-	#recommend-fragment ul li .hover-show .buy-now button:hover{
-		background: #f00;
-	}
-	#recommend-fragment ul li a.href{
-		display: inline-block;
-		position: relative;
-		z-index: 10;
-		width: 100%;
-		text-align: center;
-		height: 260px;
-	}
+    width: 1190px;
+    margin: 0 auto;
+  }
+  .recommend-list{
+    width: 100%;
+    margin: 0 auto;
+    display: inline-block;
+  }
+  #recommend-fragment ul{
+    width: 100%;
+    margin: 0 auto;
+    display: inline-block;
+    -webkit-padding-start: 0;
+  }
+  #recommend-fragment ul li{
+    float: left;
+    width: 218px;
+    height: 260px;
+    border: #d2d2d2 1px solid;
+    position: relative;
+    overflow: hidden;
+    margin-right: 25px;
+    margin-bottom: 20px;
+  }
+  #recommend-fragment ul li:nth-child(5n){
+    margin-right: 0;
+  }
+  #recommend-fragment ul li .img{
+    height: 175px;
+    text-align: center;
+    line-height: 170px;
+  }
+  #recommend-fragment ul li .img img{
+    max-width: 120px;
+    max-height: 120px;
+  }
+  #recommend-fragment ul li .content{
+    width: 100%;
+    margin: 0 auto;
+  }
+  #recommend-fragment ul li .content p{
+    width: 90%;
+    display: inline-block;
+    line-height: 22px;
+    font-size: 14px;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+    margin-bottom: 0;
+    padding-left: 10px;
+  }
+  #recommend-fragment ul li .content p.price{
+    color: #ff9000;
+    font-size: 16px;
+    font-weight: bold;
+  }
+  .color666{
+    color: #666;
+  }
+  #recommend-fragment ul li .hover-show{
+    width: 100%;
+    height: 100%;
+    position: absolute;
+    top: 100%;
+    left: 0;
+    background: rgba(80,120,203,.85);
+    padding: 30px 10px;
+  }
+  #recommend-fragment ul li:hover .hover-show{
+    top: 0;
+    transition: top .5s ease-in;
+  }
+  #recommend-fragment ul li .hover-show div{
+    width: 100%;
+    margin: 0 auto;
+    text-align: left;
+    color: #fff;
+    line-height: 25px;
+    display: block;
+    text-overflow: ellipsis;
+    overflow: hidden;
+    white-space: nowrap;
+  }
+  #recommend-fragment ul li .hover-show .title{
+    font-size: 18px;
+    margin-top: 8px;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+    overflow: hidden;
+    margin-bottom: 0;
+  }
+  #recommend-fragment ul li .hover-show .type{
+    font-size: 14px;
+  }
+  #recommend-fragment ul li .hover-show .hr{
+    text-align: center;
+    margin-top: 5px;
+  }
+  #recommend-fragment ul li .hover-show .hr span{
+    font-size: 16px;
+    position: relative;
+  }
+  #recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
+    content: '';
+    position: absolute;
+    display: inline-block;
+    width: 65px;
+    height: 1px;
+    background: #fff;
+    top: 10px;
+  }
+  #recommend-fragment ul li .hover-show .hr span:before{
+    left: 53px;
+  }
+  #recommend-fragment ul li .hover-show .hr span:after{
+    right: 53px;
+  }
+  #recommend-fragment ul li .hover-show .price{
+    font-size: 20px;
+    text-align: center;
+    line-height: 48px;
+  }
+  #recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
+    text-align: center;
+    position: absolute;
+    left: 0;
+  }
+  #recommend-fragment ul li .hover-show .by-cart{
+    bottom: 50px;
+  }
+  #recommend-fragment ul li .hover-show .buy-now{
+    bottom: 15px;
+  }
+  #recommend-fragment ul li .hover-show .by-cart button{
+    display: inline-block;
+    width: 38px;
+    height: 38px;
+    border-radius: 100%;
+    background: #fff;
+    line-height: 38px;
+    margin-bottom: 5px;
+    cursor: pointer;
+    border: none;
+    z-index: 100;
+    position: relative;
+  }
+  #recommend-fragment ul li .hover-show .buy-now button{
+    display: inline-block;
+    width: 90px;
+    height: 34px;
+    text-align: center;
+    font-size: 14px;
+    border-radius: 4px;
+    background: #df1b0f;
+    line-height: 34px;
+    color: #fff;
+    cursor: pointer;
+    border: none;
+    z-index: 100;
+    position: relative;
+  }
+  #recommend-fragment ul li .hover-show .buy-now button:hover{
+    background: #f00;
+  }
+  #recommend-fragment ul li a.href{
+    display: inline-block;
+    position: relative;
+    z-index: 10;
+    width: 100%;
+    text-align: center;
+    height: 260px;
+  }
 </style>

+ 14 - 0
layouts/login.vue

@@ -0,0 +1,14 @@
+<template>
+  <div id="app">
+    <nuxt/>
+  </div>
+</template>
+<script>
+
+  export default {
+    name: 'login'
+  }
+</script>
+<style>
+
+</style>

+ 9 - 0
middleware/authenticated.js

@@ -0,0 +1,9 @@
+
+export default function ({ isServer, store, req, redirect }) {
+  // If nuxt generate, pass this middleware
+  if (isServer && !req) return
+
+  if (!store.state.option.user.logged) {
+    redirect('/auth/login')
+  }
+}

+ 3 - 2
middleware/check-auth.js

@@ -6,7 +6,8 @@ export default function ({ isServer, store, req }) {
   if (isServer) {
     store.dispatch('loadUserInfo')
   } else {
-    const loggedUser = getAuthInfo()
-    store.commit('option/REQUEST_USER_INFO_SUCCESS', loggedUser)
+    getAuthInfo()
+    // const loggedUser = getAuthInfo()
+    // store.commit('option/REQUEST_USER_INFO_SUCCESS', loggedUser)
   }
 }

+ 3 - 0
nuxt.config.js

@@ -102,6 +102,9 @@ module.exports = {
   }, {
     src: '~plugins/filters.js',
     ssr: false
+  }, {
+    src: '~plugins/jsonp.js',
+    ssr: false
   }, {
     src: '~plugins/babel-polyfill.js',
     ssr: false

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
     "font-awesome": "^4.7.0",
     "http-proxy-middleware": "^0.17.4",
     "iview": "^2.0.0-rc.19",
+    "jsonp": "^0.2.1",
     "nuxt": "0.10.6",
     "vue-awesome-swiper": "^2.5.4",
     "vue2-filters": "^0.1.9"

+ 56 - 0
pages/auth/login.vue

@@ -0,0 +1,56 @@
+<template>
+  <!-- Login 代理页面 -->
+  <div>
+  </div>
+</template>
+<script>
+
+export default {
+  layout: 'login',
+  mounted () {
+    this.crossBefore()
+  },
+  methods: {
+    async crossBefore () {
+      try {
+        let { data } = await this.$http.get('/login/crossBefore')
+        const params = data || {}
+        this.proxyLogin(params.askUrl, params.askData, params.loginUrl)
+      } catch (err) {
+        this.$router.replace('/')
+        console.log(err)
+      }
+    },
+    proxyLogin (askUrl, askData, loginUrl) {
+      const crossAfter = this.crossAfter
+      this.$jsonp(`${askUrl}?askData=${askData}`, function (err, data) {
+        if (err) throw err
+
+        // 判断是否已经登录
+        if (data.error) {
+          // 如果未登录,跳转登录界面
+          window.location.href = loginUrl
+        } else {
+          crossAfter(data.content)
+        }
+      })
+    },
+    async crossAfter (content) {
+      if (!content && content === '') {
+        this.$router.replace('/')
+      }
+
+      try {
+        let { data } = await this.$http.post('/login/crossAfter', {}, { params: { replyTxt: content } })
+
+        this.$store.dispatch('loadUserInfo', data)
+
+        window.location.href = data.returnUrl || '/'
+      } catch (err) {
+        this.$router.replace('/')
+        console.log(err)
+      }
+    }
+  }
+}
+</script>

+ 34 - 0
pages/auth/logout.vue

@@ -0,0 +1,34 @@
+<template>
+  <!-- Login 代理页面 -->
+  <div>
+  </div>
+</template>
+<script>
+
+export default {
+  layout: 'login',
+  mounted () {
+    this.crossBefore()
+  },
+  methods: {
+    async crossBefore () {
+      try {
+        let { data } = await this.$http.get('/logout/crossBefore')
+        const params = data || {}
+        this.proxyLogout(params.askUrl, params.returnUrl)
+      } catch (err) {
+        this.$router.replace('/')
+        console.log(err)
+      }
+    },
+    proxyLogout (askUrl, returnUrl) {
+      this.$jsonp(`${askUrl}`, function (err, data) {
+        if (err) throw err
+        console.log(data)
+
+        window.location.href = returnUrl && returnUrl !== 'null' ? returnUrl : '/'
+      })
+    }
+  }
+}
+</script>

+ 15 - 0
pages/user/index.vue

@@ -0,0 +1,15 @@
+<template>
+  <div class="container" style="height: 300px;line-height: 300px;text-align: center;font-size: 24px;">
+    暂未开放买家中心SSR版
+  </div>
+</template>
+<script>
+
+export default {
+  layout: 'main',
+  middleware: 'authenticated'
+}
+</script>
+<style>
+
+</style>

+ 15 - 0
pages/vendor/index.vue

@@ -0,0 +1,15 @@
+<template>
+  <div class="container" style="height: 300px;line-height: 300px;text-align: center;font-size: 24px;">
+    暂未开放卖家中心SSR版
+  </div>
+</template>
+<script>
+
+export default {
+  layout: 'main',
+  middleware: 'authenticated'
+}
+</script>
+<style>
+
+</style>

+ 16 - 0
plugins/axios.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
 import axios from 'axios'
+import store from '~store'
 
 const service = axios.create({
   baseURL: process.env.proxyUrl || process.env.baseUrl
@@ -9,6 +10,8 @@ service.interceptors.request.use(config => {
   // is server render, use ${baseUrl} directly rather than ${proxyUrl}
   if (process.env.proxyUrl && typeof window === 'undefined') {
     config.url = process.env.baseUrl + config.url
+    config.headers.cookie = store.state.option.cookies + '; ' + store.state.option.sessionId
+    config.headers['User-Agent'] = store.state.option.userAgent
   }
   return config
 }, error => {
@@ -16,6 +19,19 @@ service.interceptors.request.use(config => {
 })
 
 service.interceptors.response.use(response => {
+  const cookies = response.headers['set-cookie']
+  if (cookies && cookies.length && cookies.length > 0) {
+    for (let i = 0; i < cookies.length; i++) {
+      if (cookies[i].indexOf('JSESSIONID') > -1) {
+        const sessionId = cookies[i]
+        const first = sessionId.indexOf(';')
+        const second = sessionId.lastIndexOf(';')
+        const newSessionId = sessionId.replace(sessionId.substring(first, second), '')
+        store.commit('option/SET_SESSION_ID', newSessionId)
+        break
+      }
+    }
+  }
   return response
 }, error => {
   return Promise.reject(error)

+ 4 - 0
plugins/jsonp.js

@@ -0,0 +1,4 @@
+import jsonp from 'jsonp'
+import Vue from 'vue'
+
+Vue.prototype.$jsonp = jsonp

+ 10 - 2
store/index.js

@@ -25,15 +25,23 @@ function loadBrandComponent ({commit}, params = {}) {
 
 export const actions = {
   // 全局服务初始化
-  nuxtServerInit (store, { params, route, isServer, req }) {
+  nuxtServerInit (store, { params, route, isDev, isServer, req }) {
     // 检查设备类型
     const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
     const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
+
+    const cookie = isServer ? req.headers['cookie'] : null
     store.commit('option/SET_MOBILE_LAYOUT', isMobile)
     store.commit('option/SET_USER_AGENT', userAgent)
+    store.commit('option/SET_COOKIES', cookie)
+
+    // 设置跳转的URL
+    if (!isDev) {
+      store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
+    }
     return Promise.all([
       // 全局数据
-      // store.dispatch('loadUserInfo')
+      store.dispatch('loadUserInfo')
     ])
   },
   // 获取用户信息

+ 15 - 0
store/option.js

@@ -5,6 +5,12 @@ export const state = {
   userAgent: '',
   // 是否移动端
   isMobile: false,
+  // 身份token
+  cookies: '',
+  // 用户身份SessionId
+  sessionId: '',
+  // 正式系统地址
+  url: 'http://218.17.158.219:9090/platform-b2c',
   // 用户信息
   user: {
     // 是否登录
@@ -26,6 +32,15 @@ export const mutations = {
   SET_MOBILE_LAYOUT (state, result) {
     state.isMobile = result
   },
+  SET_COOKIES (state, result) {
+    state.cookies = result || ''
+  },
+  SET_SESSION_ID (state, result) {
+    state.sessionId = result || ''
+  },
+  UPDATE_URL (state, result) {
+    state.url = result
+  },
   REQUEST_USER_INFO (state) {
     state.user.fetching = true
   },

+ 7 - 1
yarn.lock

@@ -1549,7 +1549,7 @@ debug@2.6.7:
   dependencies:
     ms "2.0.0"
 
-debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.6.3, debug@^2.6.8:
+debug@2.6.8, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.6.3, debug@^2.6.8:
   version "2.6.8"
   resolved "http://registry.npm.taobao.org/debug/download/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
   dependencies:
@@ -2881,6 +2881,12 @@ jsonify@~0.0.0:
   version "0.0.0"
   resolved "http://registry.npm.taobao.org/jsonify/download/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
 
+jsonp@^0.2.1:
+  version "0.2.1"
+  resolved "http://registry.npm.taobao.org/jsonp/download/jsonp-0.2.1.tgz#a65b4fa0f10bda719a05441ea7b94c55f3e15bae"
+  dependencies:
+    debug "^2.1.3"
+
 jsonpointer@^4.0.0:
   version "4.0.1"
   resolved "http://registry.npm.taobao.org/jsonpointer/download/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9"