🎈 perf(优化支付):

This commit is contained in:
2022-12-13 14:06:14 +08:00
parent a79ffacf95
commit 662617b5ac
5 changed files with 59 additions and 30 deletions
+25 -12
View File
@@ -1,24 +1,36 @@
import { Button, View } from '@tarojs/components'
import Taro, { useDidShow, useRouter } from '@tarojs/taro'
import { useEffect, useState } from 'react'
import Taro, { useDidShow, useLoad, useRouter } from '@tarojs/taro'
import { useEffect, useRef, useState } from 'react'
import { BANk_WX_APPID } from '@/common/constant'
interface Param {
merchId: string
custMerchId: string
needCashier?: '1'|'0'
callBack?: (val: any) => void // 从招商银行返回时的回调函数
}
export default () => {
export default (props: Param) => {
const { merchId = '', custMerchId = '', needCashier = '1', callBack } = props
const [payStatus, setPayStatus] = useState(false)
Taro.onAppShow((res) => {
if (res?.referrerInfo?.appId == 'wx65934ee32a88d726') {
const tf = res?.referrerInfo?.extraData?.payStatus == 'success'
setPayStatus(() => tf)
}
})
const pullBank = ({ merchId = '', custMerchId = '', needCashier = '1' }: Param) => {
const openStatus = useRef(false)
console.log('openstatus::', openStatus)
useEffect(() => {
Taro.onAppShow((res) => {
if (res?.referrerInfo?.appId == BANk_WX_APPID && !openStatus.current) {
console.log('onAppShow::', res)
callBack?.(res)
const tf = res?.referrerInfo?.extraData?.payStatus == 'success'
setPayStatus(() => tf)
openStatus.current = true
}
})
}, [])
const pullBank = () => {
console.log('merchId::', `${merchId}&&${custMerchId}`)
Taro.navigateToMiniProgram({
appId: CURRENT_PAY_Bank_APPID, // 生产环境Id【UAT测试环境appId:wx0fb358ee24237c71】
// appId: 'wx0fb358ee24237c71', // 生产环境Id【UAT测试环境appId:wx0fb358ee24237c71】
// appId: CURRENT_PAY_Bank_APPID, // 生产环境Id【UAT测试环境appId:wx0fb358ee24237c71】
appId: 'wx65934ee32a88d726', // 生产环境Id【UAT测试环境appId:wx0fb358ee24237c71】
path: 'pages/index/index',
extraData: {
merchId, // 传商户号(必填,此处传JE开头的商户号)
@@ -27,6 +39,7 @@ export default () => {
},
success(res) { // 打开成功的回调函数
console.log('打开成功::', res)
openStatus.current = false
},
fail(res) {
console.log('打开失败::', res)