front/src/views/h5/customer-center/components/H5RechargeSheet.vue
zzh b453f0a47c
All checks were successful
Build and Deploy Front / deploy (push) Successful in 17m20s
feat: H5充值对齐PC、品牌logo刷新与无图占位BCDship
同步支付宝支付前端能力与支付相关页面体验;登录/顶栏/官网进入时重新核对品牌资源。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-04 15:47:07 +08:00

1399 lines
36 KiB
Vue

<template>
<a-drawer
:visible="visible"
placement="bottom"
height="auto"
:footer="false"
:header="false"
unmount-on-close
:mask-closable="!submitting"
:drawer-style="drawerStyle"
popup-container="body"
class="h5-recharge-drawer"
@cancel="close"
>
<div class="h5-rc">
<div class="h5-rc__handle" aria-hidden="true" />
<header class="h5-rc__head">
<h3>{{ t('h5.recharge.title') }}</h3>
<button type="button" class="h5-rc__close" :disabled="submitting" @click="close">
<icon-close />
</button>
</header>
<div class="h5-rc__body">
<template v-if="step < 2">
<section class="h5-rc__hero">
<p class="h5-rc__hero-label">{{ t('h5.recharge.currentAmount') }}</p>
<p class="h5-rc__hero-value">
<span class="h5-rc__hero-currency">¥</span>
{{ amountDisplay }}
</p>
</section>
<section class="h5-rc__card">
<p class="h5-rc__label">{{ t('h5.recharge.amount') }}</p>
<div class="h5-rc__amount-grid">
<button
v-for="amt in presets"
:key="amt"
type="button"
class="h5-rc__chip"
:class="{ 'is-active': amount === amt && !customMode }"
@click="selectAmount(amt)"
>
¥{{ formatPreset(amt) }}
</button>
<button
type="button"
class="h5-rc__chip"
:class="{ 'is-active': customMode }"
@click="enterCustomMode"
>
{{ customChipLabel }}
</button>
</div>
<div v-if="customMode" class="h5-rc__amount-focus">
<a-input-number
v-model="customAmount"
:min="0.01"
:max="999999.99"
:precision="2"
:step="0.01"
:hide-button="true"
class="h5-rc__amount-input"
:placeholder="t('h5.recharge.customPlaceholder')"
>
<template #prefix>¥</template>
</a-input-number>
</div>
</section>
<section class="h5-rc__card">
<div class="h5-rc__pay-head">
<p class="h5-rc__label h5-rc__label--flush">{{ t('h5.recharge.payType') }}</p>
<p class="h5-rc__pay-hint">{{ t('h5.recharge.payTypeHint') }}</p>
</div>
<div class="h5-rc__pay-group">
<div class="h5-rc__pay-group-label">
<span class="h5-rc__tag is-instant">{{ t('h5.recharge.groupInstant') }}</span>
<span class="h5-rc__tag-desc">{{ t('h5.recharge.groupInstantDesc') }}</span>
</div>
<div class="h5-rc__pay-grid">
<button
type="button"
class="h5-rc__pay-card is-featured"
:class="{ 'is-active': payType === 'wx' }"
@click="payType = 'wx'"
>
<span class="h5-rc__pay-badge">{{ t('h5.recharge.recommend') }}</span>
<img :src="wxIcon" :alt="t('h5.recharge.wechatOnline')" />
<div class="h5-rc__pay-text">
<strong>{{ t('h5.recharge.wechatOnline') }}</strong>
<span>{{ t('h5.recharge.wechatOnlineDesc') }}</span>
</div>
</button>
<button
type="button"
class="h5-rc__pay-card is-featured"
:class="{ 'is-active': payType === 'zfbOnline' }"
@click="payType = 'zfbOnline'"
>
<img :src="zfbIcon" :alt="t('h5.recharge.alipayOnline')" />
<div class="h5-rc__pay-text">
<strong>{{ t('h5.recharge.alipayOnline') }}</strong>
<span>{{ t('h5.recharge.alipayOnlineDesc') }}</span>
</div>
</button>
</div>
</div>
<div class="h5-rc__pay-group">
<div class="h5-rc__pay-group-label">
<span class="h5-rc__tag is-review">{{ t('h5.recharge.groupReview') }}</span>
<span class="h5-rc__tag-desc">{{ t('h5.recharge.groupReviewDesc') }}</span>
</div>
<div class="h5-rc__pay-grid">
<button
type="button"
class="h5-rc__pay-card"
:class="{ 'is-active': payType === 'zfb' }"
@click="payType = 'zfb'"
>
<img :src="zfbIcon" :alt="t('h5.recharge.alipay')" />
<div class="h5-rc__pay-text">
<strong>{{ t('h5.recharge.alipay') }}</strong>
<span>{{ t('h5.recharge.alipayDesc') }}</span>
</div>
</button>
<button
type="button"
class="h5-rc__pay-card"
:class="{ 'is-active': payType === 'wxVoucher' }"
@click="payType = 'wxVoucher'"
>
<img :src="wxIcon" :alt="t('h5.recharge.wechatVoucher')" />
<div class="h5-rc__pay-text">
<strong>{{ t('h5.recharge.wechatVoucher') }}</strong>
<span>{{ t('h5.recharge.wechatVoucherDesc') }}</span>
</div>
</button>
<button
type="button"
class="h5-rc__pay-card"
:class="{ 'is-active': payType === 'bank' }"
@click="payType = 'bank'"
>
<img :src="bankIcon" :alt="t('h5.recharge.bank')" />
<div class="h5-rc__pay-text">
<strong>{{ t('h5.recharge.bank') }}</strong>
<span>{{ t('h5.recharge.bankDesc') }}</span>
</div>
</button>
</div>
</div>
<div class="h5-rc__guide" :class="isOnlinePay ? 'is-instant' : 'is-review'">
<strong>{{ payGuideTitle }}</strong>
<p>{{ payGuideBody }}</p>
</div>
<template v-if="payType === 'wx'">
<p v-if="inWeChat" class="h5-rc__online-tip">{{ t('h5.recharge.jsapiTip') }}</p>
<p v-else class="h5-rc__online-tip is-warn">{{ t('h5.recharge.needWechatBrowser') }}</p>
</template>
<template v-else-if="payType === 'zfbOnline'">
<p class="h5-rc__online-tip">{{ t('h5.recharge.alipayWapTip') }}</p>
</template>
<div v-else-if="payType === 'bank'" class="h5-rc__bank">
<template v-if="bankAccount.configured">
<div v-for="row in bankRows" :key="row.key" class="h5-rc__bank-row">
<span class="h5-rc__bank-label">{{ row.label }}</span>
<span class="h5-rc__bank-value" :class="{ 'is-mono': row.mono }">{{ row.value }}</span>
<button
v-if="row.copyable"
type="button"
class="h5-rc__bank-copy"
@click="copyText(row.value)"
>
{{ t('h5.recharge.copy') }}
</button>
</div>
</template>
<p v-else class="h5-rc__qr-empty">{{ t('h5.recharge.bankEmpty') }}</p>
<div class="h5-rc__bank-fields">
<label class="h5-rc__field">
<span>{{ t('h5.recharge.payerName') }}</span>
<a-input
v-model="payerName"
allow-clear
:placeholder="t('h5.recharge.payerNamePlaceholder')"
/>
</label>
<label class="h5-rc__field">
<span>{{ t('h5.recharge.transferSerial') }}</span>
<a-input
v-model="transferSerial"
allow-clear
:placeholder="t('h5.recharge.transferSerialPlaceholder')"
/>
</label>
</div>
</div>
<div v-else class="h5-rc__qr">
<img v-if="currentQrDisplay" :src="currentQrDisplay" alt="qrcode" />
<p v-else class="h5-rc__qr-empty">{{ t('h5.recharge.qrEmpty') }}</p>
<p v-if="currentQrDisplay">{{ t('h5.recharge.qrTip') }}</p>
</div>
</section>
<section
v-if="payType === 'zfb' || payType === 'wxVoucher' || payType === 'bank'"
class="h5-rc__card"
>
<p class="h5-rc__label">
{{
payType === 'bank' ? t('h5.recharge.voucherBank') : t('h5.recharge.voucher')
}}
</p>
<a-upload
:file-list="fileList"
:custom-request="handleUpload"
:limit="1"
accept="image/*"
list-type="picture-card"
class="h5-rc__uploader"
@change="handleFileChange"
>
<template #upload-button>
<div class="h5-rc__upload">
<icon-plus />
<div>{{ t('h5.recharge.upload') }}</div>
</div>
</template>
</a-upload>
</section>
</template>
<div v-else class="h5-rc__success">
<a-result
:status="paidOnline ? 'success' : payConfirming ? 'warning' : 'success'"
:title="successTitle"
:subtitle="payConfirming ? t('h5.recharge.payConfirmingHint') : undefined"
/>
</div>
</div>
<footer class="h5-rc__foot">
<button
v-if="step < 2"
type="button"
class="h5-rc__submit"
:disabled="submitting || (payType === 'wx' && !inWeChat)"
@click="submit"
>
<span v-if="submitting" class="h5-rc__loading" aria-hidden="true" />
{{
payType === 'wx' || payType === 'zfbOnline'
? t('h5.recharge.payNow')
: t('h5.recharge.submit')
}}
</button>
<button v-else type="button" class="h5-rc__submit" @click="close">
{{ t('h5.recharge.done') }}
</button>
</footer>
</div>
</a-drawer>
</template>
<script lang="ts" setup>
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import { IconClose, IconPlus } from '@arco-design/web-vue/es/icon';
import zfbIcon from '@/assets/zfb.png';
import wxIcon from '@/assets/wx.png';
import bankIcon from '@/assets/bank.svg?url';
import {
getRechargeBankAccount,
submitRechargeApplication,
type RechargeBankAccount,
} from '@/api/recharge/rechargeRecord';
import {
closeWeChatPay,
createWeChatPay,
getWeChatPayMerchantConfig,
getWeChatPayStatus,
invokeWeChatJsapiPay,
isWeChatBrowser,
} from '@/api/recharge/wechatPay';
import {
closeAlipayPay,
createAlipayPay,
getAlipayPayStatus,
redirectAlipayPay,
} from '@/api/recharge/alipayPay';
import { loadPaymentReceiveQrUrls } from '@/utils/paymentReceiveQr';
defineOptions({ name: 'H5RechargeSheet' });
const OAUTH_FLAG = 'oms_wx_pay_oauth';
const OAUTH_AMOUNT_KEY = 'oms_wx_pay_amount';
const ALIPAY_RETURN_FLAG = 'oms_zfb_pay_return';
const PRESETS = [200, 500, 1000, 3000] as const;
const props = defineProps<{
visible: boolean;
}>();
const emit = defineEmits<{
'update:visible': [value: boolean];
success: [];
}>();
const { t } = useI18n();
const zfbQrDisplay = ref('');
const wxQrDisplay = ref('');
const presets = PRESETS;
const amount = ref(500);
const customMode = ref(false);
const customAmount = ref<number | undefined>();
const payType = ref<'wx' | 'zfbOnline' | 'zfb' | 'wxVoucher' | 'bank'>('wx');
const fileList = ref<any[]>([]);
const screenshotFile = ref<File | null>(null);
const submitting = ref(false);
const step = ref(0);
const paidOnline = ref(false);
/** JSAPI 已返回 ok 但轮询未确认入账 */
const payConfirming = ref(false);
const inWeChat = ref(isWeChatBrowser());
const payerName = ref('');
const transferSerial = ref('');
const bankAccount = reactive<RechargeBankAccount>({
configured: false,
accountName: '',
bankName: '',
accountNo: '',
currency: 'CNY',
});
let statusPollTimer: ReturnType<typeof setInterval> | null = null;
let activeOutTradeNo: string | null = null;
let activePayChannel: 'wx' | 'zfb' = 'wx';
const drawerStyle = {
borderRadius: '20px 20px 0 0',
overflow: 'hidden',
maxHeight: 'min(92vh, 820px)',
};
const isOnlinePay = computed(() => payType.value === 'wx' || payType.value === 'zfbOnline');
const finalAmount = computed(() =>
customMode.value ? Number(customAmount.value || 0) : amount.value,
);
const amountDisplay = computed(() => {
const value = finalAmount.value;
if (!value || value <= 0) return '--';
return value.toLocaleString('zh-CN', {
minimumFractionDigits: value % 1 === 0 ? 0 : 2,
maximumFractionDigits: 2,
});
});
const customChipLabel = computed(() => {
if (customMode.value && Number(customAmount.value || 0) > 0) {
return `¥${Number(customAmount.value).toLocaleString('zh-CN', {
minimumFractionDigits: 0,
maximumFractionDigits: 2,
})}`;
}
return t('h5.recharge.custom');
});
const currentQrDisplay = computed(() =>
payType.value === 'wxVoucher' ? wxQrDisplay.value : zfbQrDisplay.value,
);
const successTitle = computed(() =>
paidOnline.value
? t('h5.recharge.paidSuccess')
: payConfirming.value
? t('h5.recharge.payConfirmingTitle')
: t('h5.recharge.success'),
);
const payGuideTitle = computed(() => {
if (payType.value === 'wx') return t('h5.recharge.guide.wxOnlineTitle');
if (payType.value === 'zfbOnline') return t('h5.recharge.guide.zfbOnlineTitle');
if (payType.value === 'bank') return t('h5.recharge.guide.bankTitle');
if (payType.value === 'zfb') return t('h5.recharge.guide.alipayTitle');
return t('h5.recharge.guide.wxVoucherTitle');
});
const payGuideBody = computed(() => {
if (payType.value === 'wx') return t('h5.recharge.guide.wxOnlineBody');
if (payType.value === 'zfbOnline') return t('h5.recharge.guide.zfbOnlineBody');
if (payType.value === 'bank') return t('h5.recharge.guide.bankBody');
if (payType.value === 'zfb') return t('h5.recharge.guide.alipayBody');
return t('h5.recharge.guide.wxVoucherBody');
});
const bankRows = computed(() => [
{
key: 'name',
label: t('h5.recharge.bankAccountName'),
value: bankAccount.accountName,
copyable: true,
mono: false,
},
{
key: 'bank',
label: t('h5.recharge.bankName'),
value: bankAccount.bankName,
copyable: true,
mono: false,
},
{
key: 'no',
label: t('h5.recharge.bankAccountNo'),
value: bankAccount.accountNo,
copyable: true,
mono: true,
},
{
key: 'currency',
label: t('h5.recharge.bankCurrency'),
value: bankAccount.currency || 'CNY',
copyable: false,
mono: false,
},
]);
function formatPreset(amt: number) {
return amt.toLocaleString('zh-CN');
}
function stopStatusPoll() {
if (statusPollTimer) {
clearInterval(statusPollTimer);
statusPollTimer = null;
}
}
function resetForm() {
stopStatusPoll();
amount.value = 500;
customMode.value = false;
customAmount.value = undefined;
payType.value = 'wx';
fileList.value = [];
screenshotFile.value = null;
submitting.value = false;
step.value = 0;
paidOnline.value = false;
payConfirming.value = false;
payerName.value = '';
transferSerial.value = '';
activeOutTradeNo = null;
}
async function bestEffortClosePay(outTradeNo?: string | null, channel: 'wx' | 'zfb' = activePayChannel) {
const no = String(outTradeNo || '').trim();
if (!no) return;
try {
if (channel === 'zfb') {
await closeAlipayPay(no);
} else {
await closeWeChatPay(no);
}
} catch {
/* ignore */
}
}
function close() {
if (submitting.value) return;
emit('update:visible', false);
}
function selectAmount(amt: number) {
customMode.value = false;
amount.value = amt;
}
function enterCustomMode() {
customMode.value = true;
if (!customAmount.value || customAmount.value < 0.01) {
customAmount.value = undefined;
}
}
async function copyText(text: string) {
const value = String(text || '').trim();
if (!value) return;
try {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(value);
} else {
const input = document.createElement('textarea');
input.value = value;
input.setAttribute('readonly', 'true');
input.style.position = 'fixed';
input.style.left = '-9999px';
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
}
Message.success(t('h5.recharge.copied'));
} catch {
Message.error(t('h5.recharge.copyFailed'));
}
}
function handleUpload(options: any) {
const file = options?.fileItem?.file ?? options?.file;
if (!file) {
options?.onError?.(new Error('no file'));
return;
}
screenshotFile.value = file as File;
const url = URL.createObjectURL(file as File);
fileList.value = [{ uid: String(Date.now()), name: (file as File).name, url }];
options?.onSuccess?.(file);
}
function handleFileChange(files: any) {
fileList.value = files;
if (!files?.length) screenshotFile.value = null;
}
function takeOauthCodeFromUrl(): string | undefined {
const url = new URL(window.location.href);
const code = url.searchParams.get('code') || undefined;
const state = url.searchParams.get('state') || '';
if (!code || !state.startsWith(OAUTH_FLAG)) return undefined;
url.searchParams.delete('code');
url.searchParams.delete('state');
window.history.replaceState({}, '', url.toString());
return code;
}
async function redirectWechatOauth() {
const cfg = await getWeChatPayMerchantConfig();
const appId = cfg.appId?.trim();
if (!appId) {
throw new Error(t('h5.recharge.needMpAppId'));
}
try {
sessionStorage.setItem(
OAUTH_AMOUNT_KEY,
JSON.stringify({
amount: amount.value,
customMode: customMode.value,
customAmount: customAmount.value,
}),
);
} catch {
/* ignore */
}
const redirectUri = `${window.location.origin}/h5/recharge`;
const state = `${OAUTH_FLAG}_${Date.now()}`;
window.location.href =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${encodeURIComponent(appId)}` +
`&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`;
}
async function pollUntilPaid(outTradeNo: string, channel: 'wx' | 'zfb' = 'wx') {
stopStatusPoll();
return new Promise<boolean>((resolve) => {
let tries = 0;
const tick = async () => {
tries += 1;
try {
const status =
channel === 'zfb'
? await getAlipayPayStatus(outTradeNo)
: await getWeChatPayStatus(outTradeNo);
if (status.status === 'Success' || status.statusCode === 3) {
stopStatusPoll();
resolve(true);
return;
}
if (status.status === 'Closed' || status.status === 'Failed') {
stopStatusPoll();
resolve(false);
return;
}
} catch {
/* ignore */
}
if (tries >= 30) {
stopStatusPoll();
resolve(false);
}
};
void tick();
statusPollTimer = setInterval(tick, 2000);
});
}
function takeAlipayReturnOutTradeNo(): string | undefined {
const url = new URL(window.location.href);
const outTradeNo =
url.searchParams.get('outTradeNo') || url.searchParams.get('out_trade_no') || undefined;
const flag = url.searchParams.get('omsPay') || '';
if (!outTradeNo) return undefined;
const accepted =
flag === ALIPAY_RETURN_FLAG || (!flag && outTradeNo.startsWith('ZFB'));
if (!accepted) return undefined;
url.searchParams.delete('outTradeNo');
url.searchParams.delete('out_trade_no');
url.searchParams.delete('omsPay');
for (const key of [
'trade_no',
'total_amount',
'seller_id',
'app_id',
'sign',
'sign_type',
'charset',
'method',
'auth_app_id',
'version',
'timestamp',
]) {
url.searchParams.delete(key);
}
window.history.replaceState({}, '', url.toString());
return outTradeNo;
}
async function resumeAlipayReturn(outTradeNo: string) {
payType.value = 'zfbOnline';
activePayChannel = 'zfb';
activeOutTradeNo = outTradeNo;
submitting.value = true;
try {
const paid = await pollUntilPaid(outTradeNo, 'zfb');
if (paid) {
paidOnline.value = true;
payConfirming.value = false;
activeOutTradeNo = null;
step.value = 2;
emit('success');
return;
}
payConfirming.value = true;
paidOnline.value = false;
step.value = 2;
Message.warning(t('h5.recharge.payConfirming'));
} finally {
submitting.value = false;
}
}
async function submitZfbOnline() {
submitting.value = true;
activePayChannel = 'zfb';
try {
const returnUrl = `${window.location.origin}/h5/recharge?omsPay=${ALIPAY_RETURN_FLAG}`;
const created = await createAlipayPay({
rechargeAmount: Number(finalAmount.value),
scene: 'wap',
returnUrl,
});
if (!created.payUrl && !created.payFormHtml) {
throw new Error(t('h5.recharge.alipayRedirectFailed'));
}
activeOutTradeNo = created.outTradeNo;
redirectAlipayPay({
payUrl: created.payUrl,
payFormHtml: created.payFormHtml,
});
} catch (e: any) {
await bestEffortClosePay(activeOutTradeNo, 'zfb');
activeOutTradeNo = null;
Message.error(e?.message || t('h5.recharge.failed'));
} finally {
submitting.value = false;
}
}
async function submitWxOnline(oauthCode?: string) {
if (!inWeChat.value) {
Message.warning(t('h5.recharge.needWechatBrowser'));
return;
}
submitting.value = true;
try {
let created;
try {
created = await createWeChatPay({
rechargeAmount: Number(finalAmount.value),
scene: 'jsapi',
oauthCode,
});
} catch (e: any) {
const msg = String(e?.message || '');
if (!oauthCode && (msg.includes('OpenId') || msg.includes('openid') || msg.includes('授权'))) {
await redirectWechatOauth();
return;
}
throw e;
}
if (!created.jsapi) {
throw new Error(t('h5.recharge.jsapiParamsMissing'));
}
activePayChannel = 'wx';
activeOutTradeNo = created.outTradeNo;
const result = await invokeWeChatJsapiPay(created.jsapi);
if (result === 'cancel') {
await bestEffortClosePay(created.outTradeNo, 'wx');
activeOutTradeNo = null;
Message.info(t('h5.recharge.payCancel'));
return;
}
if (result === 'fail') {
await bestEffortClosePay(created.outTradeNo, 'wx');
activeOutTradeNo = null;
Message.error(t('h5.recharge.payFail'));
return;
}
const paid = await pollUntilPaid(created.outTradeNo, 'wx');
if (paid) {
paidOnline.value = true;
payConfirming.value = false;
activeOutTradeNo = null;
step.value = 2;
emit('success');
return;
}
payConfirming.value = true;
paidOnline.value = false;
step.value = 2;
Message.warning(t('h5.recharge.payConfirming'));
} catch (e: any) {
await bestEffortClosePay(activeOutTradeNo);
activeOutTradeNo = null;
Message.error(e?.message || t('h5.recharge.failed'));
} finally {
submitting.value = false;
}
}
function buildBankRemark(): string {
return `付款户名:${payerName.value.trim()};流水号:${transferSerial.value.trim()}`;
}
function voucherPayTypeCode(): 1 | 2 | 3 {
if (payType.value === 'zfb') return 2;
if (payType.value === 'bank') return 3;
return 1;
}
async function submitVoucher() {
if (payType.value === 'bank') {
if (!payerName.value.trim() || !transferSerial.value.trim()) {
Message.warning(t('h5.recharge.needBankRemark'));
return;
}
}
submitting.value = true;
try {
const result: any = await submitRechargeApplication({
rechargeAmount: Number(finalAmount.value),
payType: voucherPayTypeCode(),
remark: payType.value === 'bank' ? buildBankRemark() : undefined,
screenshotFile: screenshotFile.value ?? undefined,
});
const decision = String(result?.decision ?? result?.Decision ?? '').trim();
const approvalNo = String(
result?.approvalInstanceNo ?? result?.ApprovalInstanceNo ?? '',
).trim();
if (decision === 'PendingApproval') {
Message.info(
approvalNo
? t('user.recharge.deposit.message.pendingApproval', { no: approvalNo })
: t('user.recharge.deposit.message.pendingApprovalFallback'),
);
} else if (decision === 'Bypass') {
Message.success(t('user.recharge.deposit.message.bypassed'));
} else {
Message.success(t('h5.recharge.success'));
}
paidOnline.value = false;
payConfirming.value = false;
step.value = 2;
emit('success');
} catch (e: any) {
Message.error(e?.message || t('h5.recharge.failed'));
} finally {
submitting.value = false;
}
}
async function submit() {
if (finalAmount.value < 0.01) {
Message.warning(t('h5.recharge.needAmount'));
if (!customMode.value) enterCustomMode();
return;
}
if (payType.value === 'wx') {
await submitWxOnline();
return;
}
if (payType.value === 'zfbOnline') {
await submitZfbOnline();
return;
}
await submitVoucher();
}
watch(
() => props.visible,
async (visible) => {
if (!visible) {
stopStatusPoll();
return;
}
resetForm();
inWeChat.value = isWeChatBrowser();
try {
const raw = sessionStorage.getItem(OAUTH_AMOUNT_KEY);
if (raw) {
const saved = JSON.parse(raw) as {
amount?: number;
customMode?: boolean;
customAmount?: number;
};
if (saved.customMode) {
customMode.value = true;
customAmount.value = Number(saved.customAmount || 0) || undefined;
} else if (saved.amount && saved.amount > 0) {
amount.value = Number(saved.amount);
}
sessionStorage.removeItem(OAUTH_AMOUNT_KEY);
}
} catch {
/* ignore */
}
const [urls, bank] = await Promise.all([
loadPaymentReceiveQrUrls(),
getRechargeBankAccount().catch(() => null),
]);
zfbQrDisplay.value = urls.alipay;
wxQrDisplay.value = urls.wechat;
if (bank) {
bankAccount.configured = bank.configured;
bankAccount.accountName = bank.accountName;
bankAccount.bankName = bank.bankName;
bankAccount.accountNo = bank.accountNo;
bankAccount.currency = bank.currency || 'CNY';
}
const alipayOutTradeNo = takeAlipayReturnOutTradeNo();
if (alipayOutTradeNo) {
await resumeAlipayReturn(alipayOutTradeNo);
return;
}
const oauthCode = takeOauthCodeFromUrl();
if (oauthCode && inWeChat.value) {
payType.value = 'wx';
await submitWxOnline(oauthCode);
}
},
{ immediate: true },
);
onBeforeUnmount(() => {
stopStatusPoll();
});
</script>
<style lang="less">
.h5-recharge-drawer {
.arco-drawer-content {
border-radius: 20px 20px 0 0;
overflow: hidden;
max-height: min(92vh, 820px);
}
.arco-drawer-body {
padding: 0;
display: flex;
flex-direction: column;
max-height: min(92vh, 820px);
}
}
</style>
<style lang="less" scoped>
.h5-rc {
--h5-rc-ink: #1d2129;
--h5-rc-muted: #4e5969;
--h5-rc-soft: #86909c;
--h5-rc-well: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
--h5-rc-well-deep: 0 2px 4px rgba(15, 23, 42, 0.06), 0 8px 18px rgba(15, 23, 42, 0.08);
display: flex;
flex-direction: column;
max-height: min(92vh, 820px);
padding-bottom: env(safe-area-inset-bottom, 0px);
background: #f0f3f4;
}
.h5-rc__handle {
width: 36px;
height: 4px;
margin: 10px auto 0;
border-radius: 999px;
background: #c9cdd4;
flex-shrink: 0;
}
.h5-rc__head {
display: flex;
align-items: center;
justify-content: center;
position: relative;
height: 48px;
flex-shrink: 0;
h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: var(--h5-rc-ink);
}
}
.h5-rc__close {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
width: 36px;
height: 36px;
border: none;
border-radius: 10px;
background: transparent;
color: var(--h5-rc-soft);
font-size: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
&:disabled {
opacity: 0.5;
}
}
.h5-rc__body {
flex: 1;
min-height: 0;
overflow: auto;
padding: 0 16px 12px;
}
.h5-rc__hero {
margin-bottom: 12px;
padding: 16px 18px;
border-radius: 16px;
background:
linear-gradient(
135deg,
color-mix(in srgb, var(--app-primary-color, #1d7281) 14%, #fff) 0%,
#fff 58%
);
box-shadow: var(--h5-rc-well);
}
.h5-rc__hero-label {
margin: 0 0 6px;
font-size: 12px;
color: var(--h5-rc-soft);
}
.h5-rc__hero-value {
margin: 0;
font-size: 32px;
font-weight: 700;
line-height: 1.1;
color: var(--h5-rc-ink);
letter-spacing: -0.02em;
}
.h5-rc__hero-currency {
margin-right: 2px;
font-size: 18px;
font-weight: 700;
color: var(--app-primary-color, #1d7281);
}
.h5-rc__card {
background: #fff;
border-radius: 16px;
padding: 16px;
margin-bottom: 12px;
box-shadow: var(--h5-rc-well);
}
.h5-rc__label {
margin: 0 0 10px;
font-size: 13px;
font-weight: 600;
color: var(--h5-rc-muted);
&--flush {
margin-bottom: 0;
}
}
.h5-rc__amount-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.h5-rc__chip {
height: 40px;
border: none;
border-radius: 12px;
background: #fff;
color: var(--h5-rc-ink);
font-size: 14px;
font-weight: 600;
box-shadow: var(--h5-rc-well);
cursor: pointer;
transition: box-shadow 0.15s ease, color 0.15s ease;
&.is-active {
color: var(--app-primary-color, #1d7281);
box-shadow:
var(--h5-rc-well),
inset 0 0 0 1.5px color-mix(in srgb, var(--app-primary-color, #1d7281) 40%, transparent);
}
}
.h5-rc__amount-focus {
margin-top: 12px;
}
.h5-rc__amount-input {
width: 100%;
:deep(.arco-input-wrapper) {
height: 44px;
border-radius: 12px;
background: #f7f9fa;
}
:deep(.arco-input) {
font-size: 18px;
font-weight: 600;
}
:deep(.arco-input-prefix) {
font-size: 16px;
font-weight: 700;
color: var(--app-primary-color, #1d7281);
}
}
.h5-rc__pay-head {
margin-bottom: 12px;
}
.h5-rc__pay-hint {
margin: 4px 0 0;
font-size: 12px;
line-height: 1.5;
color: var(--h5-rc-soft);
}
.h5-rc__pay-group {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 14px;
}
.h5-rc__pay-group-label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
.h5-rc__tag {
display: inline-flex;
align-items: center;
height: 22px;
padding: 0 8px;
border-radius: 6px;
font-size: 12px;
font-weight: 600;
&.is-instant {
color: #0f766e;
background: color-mix(in srgb, #0f766e 12%, #fff);
}
&.is-review {
color: #9a6700;
background: color-mix(in srgb, #9a6700 12%, #fff);
}
}
.h5-rc__tag-desc {
font-size: 12px;
color: var(--h5-rc-soft);
}
.h5-rc__pay-grid {
display: grid;
grid-template-columns: 1fr;
gap: 8px;
}
.h5-rc__pay-card {
position: relative;
display: flex;
align-items: center;
gap: 12px;
width: 100%;
padding: 12px 14px;
border: none;
border-radius: 14px;
background: #fff;
box-shadow: var(--h5-rc-well);
text-align: left;
cursor: pointer;
transition: box-shadow 0.15s ease;
img {
width: 36px;
height: 36px;
flex-shrink: 0;
object-fit: contain;
}
&.is-featured {
padding-top: 16px;
background:
linear-gradient(
135deg,
color-mix(in srgb, var(--app-primary-color, #1d7281) 8%, #fff) 0%,
#fff 62%
);
}
&.is-active {
box-shadow:
var(--h5-rc-well-deep),
inset 0 0 0 1.5px color-mix(in srgb, var(--app-primary-color, #1d7281) 45%, transparent);
}
}
.h5-rc__pay-badge {
position: absolute;
top: 0;
right: 12px;
transform: translateY(-40%);
height: 20px;
padding: 0 8px;
border-radius: 999px;
font-size: 11px;
font-weight: 600;
line-height: 20px;
color: #fff;
background: var(--app-primary-color, #1d7281);
}
.h5-rc__pay-text {
min-width: 0;
display: flex;
flex-direction: column;
gap: 2px;
strong {
font-size: 14px;
font-weight: 600;
color: var(--h5-rc-ink);
}
span {
font-size: 12px;
line-height: 1.4;
color: var(--h5-rc-soft);
}
}
.h5-rc__guide {
margin-bottom: 12px;
padding: 10px 12px;
border-radius: 10px;
background: #f7f9fa;
strong {
display: block;
margin-bottom: 4px;
font-size: 13px;
color: var(--h5-rc-ink);
}
p {
margin: 0;
font-size: 12px;
line-height: 1.55;
color: var(--h5-rc-muted);
}
&.is-instant {
background: color-mix(in srgb, #0f766e 8%, #fff);
border: 1px solid color-mix(in srgb, #0f766e 18%, transparent);
strong {
color: #0f766e;
}
}
&.is-review {
background: color-mix(in srgb, #9a6700 8%, #fff);
border: 1px solid color-mix(in srgb, #9a6700 16%, transparent);
strong {
color: #9a6700;
}
}
}
.h5-rc__online-tip {
margin: 0;
font-size: 13px;
line-height: 1.5;
color: var(--h5-rc-muted);
&.is-warn {
color: #d97706;
}
}
.h5-rc__qr {
text-align: center;
img {
width: 168px;
height: 168px;
object-fit: contain;
border-radius: 12px;
background: #fff;
box-shadow: var(--h5-rc-well);
}
p {
margin: 8px 0 0;
font-size: 12px;
color: var(--h5-rc-soft);
}
}
.h5-rc__qr-empty {
padding: 28px 12px;
color: #c9cdd4;
font-size: 13px;
text-align: center;
}
.h5-rc__bank {
display: flex;
flex-direction: column;
gap: 10px;
}
.h5-rc__bank-row {
display: grid;
grid-template-columns: 72px minmax(0, 1fr) auto;
gap: 8px;
align-items: center;
padding: 10px 12px;
border-radius: 10px;
background: #f7f9fa;
}
.h5-rc__bank-label {
font-size: 12px;
color: var(--h5-rc-soft);
}
.h5-rc__bank-value {
font-size: 13px;
color: var(--h5-rc-ink);
word-break: break-all;
&.is-mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.02em;
}
}
.h5-rc__bank-copy {
border: none;
background: transparent;
color: var(--app-primary-color, #1d7281);
font-size: 12px;
font-weight: 600;
cursor: pointer;
padding: 0;
}
.h5-rc__bank-fields {
display: flex;
flex-direction: column;
gap: 10px;
}
.h5-rc__field {
display: flex;
flex-direction: column;
gap: 6px;
> span {
font-size: 12px;
color: var(--h5-rc-muted);
}
}
.h5-rc__upload {
width: 88px;
height: 88px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
color: var(--h5-rc-soft);
font-size: 12px;
}
.h5-rc__success {
padding: 24px 8px 12px;
}
.h5-rc__foot {
flex-shrink: 0;
padding: 12px 16px 16px;
background: #fff;
box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.04);
}
.h5-rc__submit {
width: 100%;
height: 44px;
border: none;
border-radius: 12px;
background: var(--app-primary-color, #1d7281);
color: #fff;
font-size: 15px;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
&:disabled {
opacity: 0.55;
cursor: not-allowed;
}
}
.h5-rc__loading {
width: 16px;
height: 16px;
border: 2px solid rgba(255, 255, 255, 0.35);
border-top-color: #fff;
border-radius: 50%;
animation: h5-rc-spin 0.8s linear infinite;
}
@keyframes h5-rc-spin {
to {
transform: rotate(360deg);
}
}
</style>