diff --git a/src/pages.json b/src/pages.json index 14297f35..210a726d 100644 --- a/src/pages.json +++ b/src/pages.json @@ -209,6 +209,13 @@ { "root": "pages/profile", "pages": [ + { + "path": "pay-result", + "style": { + "navigationBarTitleText": "支付结果", + "navigationStyle": "custom" + } + }, { "path": "userinfo", "style": { diff --git a/src/pages/profile/apply-vip.vue b/src/pages/profile/apply-vip.vue index fea008cd..22e6660b 100644 --- a/src/pages/profile/apply-vip.vue +++ b/src/pages/profile/apply-vip.vue @@ -10,8 +10,7 @@ + class="mx-4 p-4 rounded-2 bg-gradient-to-b from-#111 to-#222 b-4 b-solid b-t-#D29E52/60 b-l-#D29E52/40 b-r-#D29E52/40 b-b-#D29E52/20"> VIP @@ -25,20 +24,12 @@ - - + + {{ item.title }} ¥{{ fen2yuan(item.preferentialPrice) }} @@ -59,18 +50,14 @@ + :style="{ borderColor: payMethod === 'alipay' ? '#D29E52' : '' }" @click="payMethod = 'alipay'"> 支付宝 + :style="{ borderColor: payMethod === 'wechat' ? '#D29E52' : '' }" @click="payMethod = 'wechat'"> 微信支付 @@ -83,21 +70,15 @@ 《荷塘月色会员协议》 - + @click="handleOpenVip"> 立即开通VIP - + @@ -112,82 +93,134 @@ diff --git a/src/pages/profile/pay-result.vue b/src/pages/profile/pay-result.vue new file mode 100644 index 00000000..a484ac68 --- /dev/null +++ b/src/pages/profile/pay-result.vue @@ -0,0 +1,313 @@ + + + + + + diff --git a/src/pages/profile/recharge.vue b/src/pages/profile/recharge.vue index 2cfe3f52..a3bd0a19 100644 --- a/src/pages/profile/recharge.vue +++ b/src/pages/profile/recharge.vue @@ -7,14 +7,8 @@ diff --git a/src/sheep/platform/pay.js b/src/sheep/platform/pay.js index 52d4fb15..a0b3cbba 100644 --- a/src/sheep/platform/pay.js +++ b/src/sheep/platform/pay.js @@ -150,9 +150,8 @@ export default class SheepPay { async wechatWapPay() { const { error, data } = await this.prepay(); if (error === 0) { - const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${ - this.payment - }&orderType=${this.orderType}`; + const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment + }&orderType=${this.orderType}`; location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`; } } @@ -265,13 +264,13 @@ export default class SheepPay { // 解析支付参数 let payConfig = JSON.parse(data.displayContent); - if(typeof payConfig.appId === 'undefined'){ + if (typeof payConfig.appId === 'undefined') { payConfig.appId = payConfig.appid; } - if(typeof payConfig.nonceStr === 'undefined'){ + if (typeof payConfig.nonceStr === 'undefined') { payConfig.nonceStr = payConfig.noncestr; } - if(typeof payConfig.timeStamp === 'undefined'){ + if (typeof payConfig.timeStamp === 'undefined') { payConfig.timeStamp = payConfig.timestamp; } // 调用微信支付 @@ -378,11 +377,8 @@ export function getPayMethods(channels) { // 支付结果跳转,success:成功,fail:失败 export function goPayResult(id, orderType, resultType) { - sheep.$router.redirect('/pages/pay/result', { - id, - orderType, - payState: resultType, - }); + const url = `/pages/pay/result?id=${id}&orderType=${orderType}&payState=${resultType}`; + uni.redirectTo({ url: url }) } export function goBindWeixin() { diff --git a/src/sheep/util/wechat-tool.ts b/src/sheep/util/wechat-tool.ts new file mode 100644 index 00000000..15a19019 --- /dev/null +++ b/src/sheep/util/wechat-tool.ts @@ -0,0 +1,48 @@ +// @ts-nocheck +import { isEmpty } from 'lodash-es'; + +const targetAppId = 'wx2b4e4d3feff8267f'; + +const paramsToQuery = (params: Record) => { + if (isEmpty(params)) { + return ''; + } + let query = []; + for (let key in params) { + query.push(key + '=' + params[key]); + } + return query.join('&'); +} + +export const jumpToWechatMiniProgram = ( + action: 'recharge' | 'openVip', + params: Record, +) => { + let path = ''; + if (action === 'recharge') { + path = 'pages/profile/recharge'; + } + if (action === 'openVip') { + path = 'pages/profile/apply-vip'; + } + if (params) { + path += `?${paramsToQuery(params)}`; + } + console.info(`跳转到appId:${targetAppId},page:${path}`); + return new Promise((resolve, reject) => { + uni.navigateToMiniProgram({ + appId: targetAppId, + path: path, + envVersion: 'release', + success(res) { + console.log('跳转成功', res); + resolve(res); + }, + fail(res) { + console.log('跳转失败', res); + reject(res); + }, + }); + }); +} +