接入订单支付与钱包充值前端入口
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import { fetchWalletBalance, fetchWalletLedger, type WalletAccount, type WalletLedger } from '@/api/wallet'
|
||||
import { fetchWalletBalance, fetchWalletLedger, rechargeWallet, type WalletAccount, type WalletLedger } from '@/api/wallet'
|
||||
import { balanceTypeLabel, ledgerDirectionLabel, walletStatusLabel } from '@/utils/statusLabels'
|
||||
import { formatDateTime } from '@/utils/time'
|
||||
|
||||
const loading = ref(false)
|
||||
const account = ref<WalletAccount | null>(null)
|
||||
const ledger = ref<WalletLedger[]>([])
|
||||
const rechargeAmount = ref(100)
|
||||
const recharging = ref(false)
|
||||
|
||||
onMounted(loadWallet)
|
||||
|
||||
@@ -21,6 +24,27 @@ async function loadWallet() {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRecharge() {
|
||||
recharging.value = true
|
||||
try {
|
||||
account.value = await rechargeWallet(rechargeAmount.value)
|
||||
ElMessage.success('充值成功')
|
||||
await loadWallet()
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, '充值失败'))
|
||||
} finally {
|
||||
recharging.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -28,7 +52,7 @@ async function loadWallet() {
|
||||
<div class="page-header">
|
||||
<p class="eyebrow">Wallet</p>
|
||||
<h1>钱包</h1>
|
||||
<p>查看可用余额、冻结余额和不可变资金流水。当前是开发态模拟账务,不代表真实支付余额。</p>
|
||||
<p>查看可用余额、冻结余额和资金流水。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="account" class="metric-grid">
|
||||
@@ -46,6 +70,12 @@ async function loadWallet() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-panel recharge-panel">
|
||||
<h2>开发充值</h2>
|
||||
<el-input-number v-model="rechargeAmount" :min="0.01" :precision="2" controls-position="right" />
|
||||
<el-button type="primary" :loading="recharging" @click="handleRecharge">充值</el-button>
|
||||
</div>
|
||||
|
||||
<el-table class="table-panel" :data="ledger">
|
||||
<el-table-column prop="ledger_no" label="流水号" min-width="220" />
|
||||
<el-table-column prop="biz_type" label="业务" width="140" />
|
||||
@@ -64,3 +94,18 @@ async function loadWallet() {
|
||||
</el-table>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.recharge-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.recharge-panel h2 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user