Commit bf475a3c authored by 郭志伟's avatar 郭志伟

feat(pay): 路由调整完成

parent 9373addb
......@@ -12,7 +12,7 @@ import Raven from 'raven-js';
import RavenVue from 'raven-js/plugins/vue';
import { release } from '../.sentryclirc';
if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') {
Raven.config('//21779c2dcb594299bdc803c5560cfecd@sentry.q-gp.com/60', {
Raven.config('//7b09a4aeffca4a49b37328da6a5468a9@sentry.q-gp.com/83', {
release,
environment: process.env.NODE_ENV
})
......
......@@ -11,6 +11,34 @@ export default [
},
component: () => import('../views/pay')
},
{
path: '/payFail',
name: 'payFail',
alias: ['/payFail'],
meta: {
title: '支付失败'
},
component: () => import('../views/pay/payResult')
},
{
path: '/paySuccess',
name: 'paySuccess',
alias: ['/paySuccess'],
meta: {
title: '支付成功',
success: true
},
component: () => import('../views/pay/payResult')
},
{
path: '/payWaiting',
name: 'payWaiting',
meta: {
title: '支付中',
success: true
},
component: () => import('../views/pay/payWaiting')
},
{
path: '/error',
name: 'error',
......
import HttpRequest from '@qg/ui-request';
import { Toast } from '@qg/cherry-ui';
import store from '@/store';
import router from '@/router';
import { appVersion, isWxMp } from '@/service/validation.service';
import { getVccChannel } from './userInfo.service';
import { parseSearch } from './utils.service';
import localStorage from '@/service/localStorage.service';
import sessionStorage from '@/service/sessionStorage.service';
......@@ -42,7 +44,12 @@ const http = new HttpRequest(
sessionStorage.remove('vccToken');
const toast = Toast('未登录!');
toast.onClose = () => {
window.location.href = document.referrer;
const { returnUrl } = parseSearch(window.location.href);
if (returnUrl) {
window.location.href = returnUrl;
} else {
router.replace({ name: 'error' });
}
};
}
......
......@@ -92,6 +92,25 @@ export function onKeyboardStateChange(callback = () => {}, off = false) {
}
}
export function json2Query(json) {
function cleanArray(actual) {
const newArray = [];
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i]);
}
}
return newArray;
}
if (!json) return '';
return cleanArray(
Object.keys(json).map(key => {
if (json[key] === undefined) return '';
return encodeURIComponent(key) + '=' + encodeURIComponent(json[key]);
})
).join('&');
}
export function throttle(fn, wait) {
let flag = true;
return function() {
......
import cookies from '@/service/cookieStorage.service';
import localStorage from '@/service/localStorage.service';
export const goUrlExtends = {
methods: {
goHome() {
// 商城地址
setTimeout(() => {
window.location.href = document.referrer;
localStorage.remove('redirectUrl');
window.location.href = localStorage.get('redirectUrl');
}, 500);
},
goOrderList() {
setTimeout(() => {
this.$router.replace({ name: 'orderList', params: { status: 0 } });
}, 500);
},
goOrderDetail() {
const orderNo = cookies.get('orderNo')?.orderNo;
this.$router.push({
name: 'orderDetail',
query: { orderNo }
});
}
}
};
......@@ -54,9 +54,6 @@
</cr-button>
</p>
<p v-if="overtime" class="btn">
<!-- <cr-button v-if="isOrder" type="default" class="btn-default" @click="goOrderList"
>我的订单</cr-button
> -->
<cr-button type="primary" class="btn-primary" @click="navigateBack">返回</cr-button>
</p>
<p class="placeholder" />
......@@ -104,7 +101,7 @@ import crSmsCodeModal from './components/SmsModal.vue';
import { isWechat } from '@/service/validation.service';
import { encryptByDESModeEBC } from '@/service/encrypt';
import localStorage from '@/service/localStorage.service';
import { throttle } from '@/service/utils.service';
import { throttle, json2Query } from '@/service/utils.service';
// import { goUrlExtends } from './extends';
import cookies from '@/service/cookieStorage.service';
// import { saTrackEvent } from '@/service/sa.service';
......@@ -192,7 +189,8 @@ export default {
isCheckAgreement: false,
mergePayPretreatmentInfo: {},
tradeType: isWechat ? 'JSAPI' : 'MWEB',
amountInfo: {}
amountInfo: {},
redirectUrl: ''
};
},
computed: {
......@@ -227,6 +225,12 @@ export default {
mounted() {
this.getQuery();
this.setIsOrder();
if (this.$route.query.redirectUrl) {
localStorage.set('redirectUrl', this.redirectUrl);
this.redirectUrl = this.$route.query.redirectUrl;
} else {
this.redirectUrl = localStorage.get('redirectUrl');
}
this.orderNo = this.$route.query.orderNo;
cookies.set('orderNo', this.orderNo);
if (this.$route?.query?.ocrflag) {
......@@ -237,7 +241,8 @@ export default {
this.pay(this.payInfo?.paramsData, 'ocr', cookies.get('ocrflag'));
}
const vccToken = localStorage.get('vccToken');
Current_Url = `${window.location.origin}/payWaiting?vccToken=${vccToken}&orderNo=${this.orderNo}`;
Current_Url = `${this.redirectUrl ||
window.location.origin}/payWaiting?vccToken=${vccToken}&orderNo=${this.orderNo}`;
this.queryPayInfo();
this.getCouponList(this.orderNo);
},
......@@ -532,17 +537,22 @@ export default {
}
},
payResult(type, error) {
/* 跳转支付结果页面 */
this.$router.replace({
name: `pay${type}`,
query: {
reason: error,
orderNo: this.orderNo,
payType: this.payType,
amount: this.amountInfo.finalAmt || '',
freeAmount: this.amountInfo.freeAmount || ''
}
});
const params = {
reason: error,
orderNo: this.orderNo,
payType: this.payType,
amount: this.amountInfo.finalAmt || '',
freeAmount: this.amountInfo.freeAmount || ''
};
if (this.redirectUrl) {
localStorage.remove('redirectUrl');
window.location.replace(`${this.redirectUrl}/pay${type}?${json2Query(params)}`);
} else {
this.$router.replace({
name: `pay${type}`,
query: params
});
}
},
/* 选择支付方式 */
changePayType(type, mergePayPretreatmentInfo) {
......
......@@ -14,7 +14,7 @@
<p v-if="freeAmount > 0" class="info__text info__free">已优惠¥{{ freeAmount }}</p>
</div>
</div>
<div :class="['actions', 'no-order']">
<div v-if="hasRedirectUrl" :class="['actions', 'no-order']">
<cr-button shape="circle" type="primary" @click="goHome">返回</cr-button>
</div>
</div>
......@@ -31,21 +31,25 @@
<p class="tips">
{{ reason }}
</p>
<cr-button type="primary" shape="circle" class="info_button" @click="goPay"
>重新支付</cr-button
<cr-button
v-if="hasRedirectUrl"
type="primary"
shape="circle"
class="info_button"
@click="goPay"
>
重新支付
</cr-button>
</div>
<RecoGoods v-if="!getReturnUrl()" />
</div>
</template>
<script>
import RecoGoods from '@/components/RecoGoods.vue';
import cookies from '@/service/cookieStorage.service';
import localStorage from '@/service/localStorage.service';
import { isApp } from '@/service/validation.service';
import { goUrlExtends } from './extends';
import { payTypeMap } from './STATIC_DATA';
export default {
components: { RecoGoods },
extends: goUrlExtends,
data() {
return {
......@@ -54,6 +58,7 @@ export default {
isSuccess: false,
freeAmount: 0,
payStatus: '',
hasRedirectUrl: !!localStorage.get('redirectUrl'),
returnUrl: ''
};
},
......
......@@ -5,7 +5,7 @@
width="63px"
height="63px"
class="info__image"
src="../../assets/images/paying.png"
src="@/assets/images/pay/paying.png"
/>
<div v-if="init" class="info__desc">
<p class="info__text">
......@@ -16,7 +16,7 @@
<p class="tips">
努力返回支付结果中,请留心查看!
</p>
<div :class="['actions', 'no-order']">
<div v-if="hasRedirectUrl" :class="['actions', 'no-order']">
<cr-button shape="circle" type="primary" @click="goHome">返回</cr-button>
</div>
</div>
......@@ -34,6 +34,7 @@ export default {
timer: null,
time: 10,
init: false,
hasRedirectUrl: !!localStorage.get('redirectUrl'),
returnUrl: ''
};
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment