修改参数缓存bug
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
<button class="pay-btn" @click="handlePay">立即缴费</button>
|
||||
</view>
|
||||
<view class="btn-section" v-if="currentStep === 2">
|
||||
<button class="pay-btn" open-type="launchApp" app-parameter="payResult=success" @error="handleLaunchAppError">
|
||||
<button class="pay-btn" open-type="launchApp" app-parameter="payResult=success" @click="handleBackToApp" @error="handleLaunchAppError">
|
||||
返回
|
||||
</button>
|
||||
</view>
|
||||
<view class="btn-section" v-if="currentStep === 3">
|
||||
<!-- <button class="retry-btn" @click="handleRetry">重新缴费</button> -->
|
||||
<button class="pay-btn" open-type="launchApp" app-parameter="payResult=fail" @error="handleLaunchAppError">
|
||||
<button class="pay-btn" open-type="launchApp" app-parameter="payResult=fail" @click="handleBackToApp" @error="handleLaunchAppError">
|
||||
返回
|
||||
</button>
|
||||
</view>
|
||||
@@ -35,7 +35,7 @@
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { onShow, onLoad } from '@dcloudio/uni-app'
|
||||
import { getAppPaymentData, getAppQueryParams, clearAppPaymentData, buildPaymentItemFromApp, getPaymentReturnResult, clearPaymentReturnResult, resolvePaymentResult } from '/pageSubPack/api/appLaunch.js'
|
||||
import { getAppPaymentData, getAppQueryParams, clearAppPaymentData, buildPaymentItemFromApp, getPaymentReturnResult, clearPaymentReturnResult, resolvePaymentResult, clearPaymentItem, clearPaymentCache } from '/pageSubPack/api/appLaunch.js'
|
||||
import { getBankMiniProgramParams } from '/pageSubPack/api/apiSub.js'
|
||||
import { showApiError } from '/pageSubPack/api/request.js'
|
||||
|
||||
@@ -44,31 +44,54 @@ const currentStep = ref(1)
|
||||
const navigatedToPayment = ref(false)
|
||||
|
||||
onLoad(() => {
|
||||
const data = loadPaymentItem()
|
||||
Object.assign(paymentItem, data)
|
||||
loadPaymentItem()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
// 从日照银行支付小程序返回后,根据返回结果显示成功/失败页
|
||||
// 从日照银行支付小程序返回后,根据返回结果显示成功/失败页。
|
||||
// 必须放在最前面判断:本页发起过支付跳转(navigatedToPayment)时,缓存里可能
|
||||
// 残留兜底写入的 App 参数,若先走下面的 App 入口分支会被重置回待缴费状态,
|
||||
// 成功/失败页就永远不显示了。
|
||||
if (navigatedToPayment.value) {
|
||||
navigatedToPayment.value = false
|
||||
const result = resolvePaymentResult(getPaymentReturnResult())
|
||||
clearPaymentReturnResult()
|
||||
clearAppPaymentData()
|
||||
currentStep.value = result === 'success' ? 2 : 3
|
||||
return
|
||||
}
|
||||
// 再次从 App 跳转进入(携带新的缴费参数):小程序热启动时 onLoad 不会重复执行,
|
||||
// 页面会残留上一次的金额/状态,这里必须重置后重新加载。
|
||||
if (getAppPaymentData()) {
|
||||
resetPaymentState()
|
||||
loadPaymentItem()
|
||||
}
|
||||
})
|
||||
|
||||
/** 重置为待缴费状态,并清掉上一次缴费残留的页面状态与缓存条目 */
|
||||
const resetPaymentState = () => {
|
||||
navigatedToPayment.value = false
|
||||
currentStep.value = 1
|
||||
clearPaymentReturnResult()
|
||||
clearPaymentItem()
|
||||
Object.keys(paymentItem).forEach(key => delete paymentItem[key])
|
||||
}
|
||||
|
||||
const loadPaymentItem = () => {
|
||||
Object.keys(paymentItem).forEach(key => delete paymentItem[key])
|
||||
const appData = getAppPaymentData()
|
||||
if (appData) {
|
||||
console.log('-----检测到 App 跳转参数:', appData)
|
||||
clearAppPaymentData()
|
||||
const item = buildPaymentItemFromApp(appData)
|
||||
uni.setStorageSync('arrearsPayment', item)
|
||||
Object.assign(paymentItem, item)
|
||||
return item
|
||||
}
|
||||
const stored = uni.getStorageSync('arrearsPayment')
|
||||
return (typeof stored === 'object' && stored !== null) ? stored : {}
|
||||
const data = (typeof stored === 'object' && stored !== null) ? stored : {}
|
||||
Object.assign(paymentItem, data)
|
||||
return data
|
||||
}
|
||||
|
||||
const handlePay = async () => {
|
||||
@@ -111,6 +134,12 @@ const handlePay = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回 App 前清掉本次缴费缓存,下次从 App 进入时不会残留上一次的金额 */
|
||||
const handleBackToApp = () => {
|
||||
navigatedToPayment.value = false
|
||||
clearPaymentCache()
|
||||
}
|
||||
|
||||
const handleLaunchAppError = () => {
|
||||
uni.showToast({ title: '请点击左上角关闭返回', icon: 'none', duration: 2000 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user