Merge branch 'pinjinjin' of git.ishopex.cn:onex/espier-taro-fenxiao into pinjinjin

This commit is contained in:
chenhui0212
2019-03-07 15:48:46 +08:00
3 changed files with 33 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import { Loading, Price, BackToTop, SpHtmlContent } from '@/components'
import api from '@/api'
import { withBackToTop } from '@/hocs'
import { styleNames, log } from '@/utils'
import S from '@/spx'
import GoodsBuyToolbar from './comps/buy-toolbar'
import './espier-detail.scss'
@@ -106,9 +107,14 @@ export default class Detail extends Component {
})
}
handleBuyClick = (type) => {
const { marketing } = this.state
let url = `/pages/cart/checkout`
handleBuyClick = async (type) => {
const { marketing, info } = this.state
let url = `/pages/cart/checkout?id=${info.item_id}`
const hasToken = !!S.getAuthToken()
if (!hasToken) {
return S.login(this, false)
}
if (type === 'cart') {
return Taro.navigateTo({

View File

@@ -112,17 +112,22 @@ class Spx {
} catch (e) {
log.debug('[auth failed] redirect to login page: ', e)
const { fullPath } = getCurrentRoute(ctx.$router)
const authUrl = process.env.TARO_ENV === 'weapp'
? `/pages/auth/login?redirect=${fullPath}`
: `/pages/auth/login?redirect=${fullPath}`
Taro.redirectTo({
url: authUrl
})
this.goLogin(ctx)
}
}
login (ctx, isRedirect = true) {
const { fullPath } = getCurrentRoute(ctx.$router)
const authUrl = process.env.TARO_ENV === 'weapp'
? `/pages/auth/login?redirect=${fullPath}`
: `/pages/auth/login?redirect=${fullPath}`
Taro[isRedirect ? 'redirectTo' : 'navigateTo']({
url: authUrl
})
}
logout () {
Taro.removeStorageSync(TOKEN_IDENTIFIER)
delete globalData[TOKEN_IDENTIFIER]

View File

@@ -1,7 +1,8 @@
import { createReducer } from 'redux-create-reducer'
const initState = {
list: []
list: [],
checkoutItem: null
}
const cart = createReducer(initState, {
@@ -12,6 +13,15 @@ const cart = createReducer(initState, {
...state,
list
}
},
['cart/checkout'](state, action) {
const checkoutItem = action.payload
return {
...state,
checkoutItem
}
}
})