优化钱包界面ui

This commit is contained in:
yml
2026-06-03 19:12:33 +08:00
parent 783999f396
commit 04193ae687
+557 -45
View File
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { CircleCheck, CreditCard, Loading, Lock, Money, Refresh, Tickets, Wallet as WalletIcon } from '@element-plus/icons-vue'
import QRCode from 'qrcode'
import {
@@ -30,6 +31,37 @@ const qrGenerating = ref(false)
const checkingRecharge = ref(false)
let rechargePollingTimer: number | undefined
const quickRechargeAmounts = [50, 100, 200, 500]
const walletMetrics = computed(() => {
if (!account.value) {
return []
}
return [
{
label: '可用余额',
value: formatMoney(account.value.available_balance),
hint: '可用于支付租号订单',
icon: WalletIcon,
tone: 'available',
},
{
label: '冻结余额',
value: formatMoney(account.value.frozen_balance),
hint: '订单押金与待结算金额',
icon: Lock,
tone: 'frozen',
},
{
label: '账户状态',
value: walletStatusLabel(account.value.status),
hint: account.value.status === 'active' ? '钱包可正常使用' : '请联系客服处理',
icon: CircleCheck,
tone: account.value.status === 'active' ? 'status' : 'warning',
},
]
})
onMounted(loadWallet)
onBeforeUnmount(stopRechargePolling)
@@ -71,6 +103,10 @@ async function handleRecharge() {
}
}
function handleWithdraw() {
ElMessage.info('提现功能待实现')
}
function showRechargePaymentDialog(payment: PaymentOrder) {
activeRechargePayment.value = payment
rechargeDialogVisible.value = true
@@ -163,53 +199,164 @@ function readError(error: unknown, fallback: string) {
}
return fallback
}
function formatMoney(value: number) {
return `¥${Number(value || 0).toFixed(2)}`
}
function pickQuickRecharge(amount: number) {
rechargeAmount.value = amount
}
function walletBizTypeLabel(type: string) {
const map: Record<string, string> = {
dev_recharge: '测试充值',
channel_recharge: '渠道充值',
order_pay: '订单支付',
order_lock: '订单冻结',
channel_order_lock: '支付冻结',
order_cancel: '取消解冻',
order_cancel_refund: '取消退款',
admin_order_close: '客服关闭解冻',
admin_order_close_refund: '客服关闭退款',
order_settle: '订单结算',
owner_income: '号主收入',
deposit_compensation: '押金赔付',
rent_refund: '租金退款',
deposit_release: '押金释放',
arbitration_release_frozen: '仲裁解冻',
arbitration_renter_refund: '仲裁退款',
arbitration_owner_income: '仲裁收入',
}
return map[type] || type || '-'
}
function directionTone(direction: string) {
const map: Record<string, string> = {
in: 'success',
out: 'danger',
freeze: 'warning',
unfreeze: 'info',
}
return map[direction] || 'info'
}
function amountPrefix(direction: string) {
if (direction === 'in' || direction === 'unfreeze') return '+'
if (direction === 'out' || direction === 'freeze') return '-'
return ''
}
</script>
<template>
<section class="page" v-loading="loading">
<div class="page-header">
<p class="eyebrow">Wallet</p>
<h1>钱包</h1>
<p>查看可用余额冻结余额和资金流水</p>
</div>
<div v-if="account" class="metric-grid">
<div class="metric-card">
<span>可用余额</span>
<strong>¥{{ account.available_balance }}</strong>
<section class="page wallet-page" v-loading="loading">
<div class="wallet-hero">
<div class="page-header">
<p class="eyebrow">我的钱包</p>
<h1>资金账户</h1>
<p>查看余额充值和每一笔资金变化订单押金与租金都会记录在这里</p>
</div>
<div class="metric-card">
<span>冻结余额</span>
<strong>¥{{ account.frozen_balance }}</strong>
</div>
<div class="metric-card">
<span>状态</span>
<strong>{{ walletStatusLabel(account.status) }}</strong>
<div class="wallet-hero-action">
<span>当前可用</span>
<strong>{{ account ? formatMoney(account.available_balance) : '¥0.00' }}</strong>
<el-button class="withdraw-button" :icon="Money" @click="handleWithdraw">申请提现</el-button>
</div>
</div>
<div class="table-panel recharge-panel">
<h2>支付充值</h2>
<el-input-number v-model="rechargeAmount" :min="0.01" :step="0.01" :precision="2" controls-position="right" />
<el-button type="primary" :loading="recharging" @click="handleRecharge">发起充值</el-button>
<div v-if="account" class="wallet-metric-grid">
<div v-for="item in walletMetrics" :key="item.label" class="wallet-metric-card" :class="`is-${item.tone}`">
<div class="metric-icon">
<el-icon><component :is="item.icon" /></el-icon>
</div>
<div>
<span>{{ item.label }}</span>
<strong>{{ item.value }}</strong>
<small>{{ item.hint }}</small>
</div>
</div>
</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" />
<el-table-column label="方向" width="80">
<template #default="{ row }">{{ ledgerDirectionLabel(row.direction) }}</template>
</el-table-column>
<el-table-column prop="amount" label="金额" width="100" />
<el-table-column label="余额类型" width="110">
<template #default="{ row }">{{ balanceTypeLabel(row.balance_type) }}</template>
</el-table-column>
<el-table-column prop="balance_after" label="变化后余额" width="130" />
<el-table-column prop="remark" label="备注" min-width="220" />
<el-table-column label="时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
</el-table>
<div class="wallet-workspace">
<section class="recharge-panel">
<div class="panel-title">
<div class="panel-title-icon">
<el-icon><CreditCard /></el-icon>
</div>
<div>
<h2>钱包充值</h2>
<p>充值成功后会自动入账到可用余额</p>
</div>
</div>
<div class="quick-amounts">
<button
v-for="amount in quickRechargeAmounts"
:key="amount"
type="button"
:class="{ active: rechargeAmount === amount }"
@click="pickQuickRecharge(amount)"
>
{{ formatMoney(amount) }}
</button>
</div>
<div class="recharge-action-row">
<el-input-number
v-model="rechargeAmount"
:min="0.01"
:step="0.01"
:precision="2"
controls-position="right"
/>
<el-button type="primary" :icon="CreditCard" :loading="recharging" @click="handleRecharge">发起充值</el-button>
</div>
</section>
<section class="ledger-summary-card">
<div class="panel-title">
<div class="panel-title-icon is-blue">
<el-icon><Tickets /></el-icon>
</div>
<div>
<h2>资金流水</h2>
<p> {{ total }} 条记录最近变动优先展示</p>
</div>
</div>
<el-button :icon="Refresh" :loading="loading" @click="loadWallet">刷新</el-button>
</section>
</div>
<section class="wallet-ledger-table" role="table" aria-label="资金流水">
<div class="ledger-grid ledger-header" role="row">
<span role="columnheader">流水号</span>
<span role="columnheader">业务</span>
<span role="columnheader">方向</span>
<span class="align-right" role="columnheader">金额</span>
<span role="columnheader">余额类型</span>
<span class="align-right" role="columnheader">变化后余额</span>
<span role="columnheader">备注</span>
<span role="columnheader">时间</span>
</div>
<div v-if="ledger.length === 0" class="ledger-empty">暂无资金流水</div>
<div v-else class="ledger-body">
<div v-for="row in ledger" :key="row.id" class="ledger-grid ledger-row" role="row">
<span class="ledger-cell ledger-no" :title="row.ledger_no">{{ row.ledger_no }}</span>
<span class="ledger-cell">
<el-tag effect="plain" class="biz-tag">{{ walletBizTypeLabel(row.biz_type) }}</el-tag>
</span>
<span class="ledger-cell">
<el-tag :type="directionTone(row.direction)" effect="light" round>
{{ ledgerDirectionLabel(row.direction) }}
</el-tag>
</span>
<span class="ledger-cell align-right amount-cell" :class="`is-${row.direction}`">
{{ amountPrefix(row.direction) }}{{ formatMoney(row.amount) }}
</span>
<span class="ledger-cell muted-cell">{{ balanceTypeLabel(row.balance_type) }}</span>
<span class="ledger-cell align-right">{{ formatMoney(row.balance_after) }}</span>
<span class="ledger-cell" :title="row.remark">{{ row.remark || '-' }}</span>
<span class="ledger-cell">{{ formatDateTime(row.created_at) }}</span>
</div>
</div>
</section>
<div class="pagination-wrap" v-if="total > 0">
<el-pagination
@@ -235,7 +382,7 @@ function readError(error: unknown, fallback: string) {
<div v-if="activeRechargePayment" class="pay-dialog-body">
<div class="pay-summary">
<span>充值金额</span>
<strong>¥{{ (activeRechargePayment.amount_cent / 100).toFixed(2) }}</strong>
<strong>{{ formatMoney(activeRechargePayment.amount_cent / 100) }}</strong>
</div>
<div v-if="rechargePayURL()" class="pay-qr-panel">
<div class="pay-qr-box">
@@ -259,17 +406,330 @@ function readError(error: unknown, fallback: string) {
</template>
<style scoped>
.recharge-panel {
.wallet-page {
display: grid;
gap: 18px;
}
.wallet-hero {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
padding: 28px;
border: 1px solid #e6eaf2;
border-radius: 8px;
background:
linear-gradient(135deg, rgba(255, 122, 0, 0.08), rgba(15, 118, 110, 0.06)),
#ffffff;
box-shadow: 0 14px 36px rgba(17, 24, 39, 0.06);
}
.wallet-hero :deep(.page-header) {
max-width: 780px;
}
.wallet-hero-action {
min-width: 220px;
padding: 16px 18px;
border: 1px solid rgba(255, 122, 0, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.78);
text-align: right;
}
.wallet-hero-action span {
display: block;
color: #6b7280;
font-size: 13px;
}
.wallet-hero-action strong {
display: block;
margin-top: 6px;
color: #111a44;
font-size: 28px;
line-height: 1.15;
}
.withdraw-button {
width: 100%;
margin-top: 14px;
}
.wallet-metric-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 16px;
}
.wallet-metric-card {
display: flex;
align-items: center;
gap: 16px;
min-height: 120px;
padding: 20px;
border: 1px solid #e6eaf2;
border-radius: 8px;
background: #ffffff;
box-shadow: 0 12px 30px rgba(17, 24, 39, 0.05);
}
.metric-icon {
display: grid;
flex: 0 0 46px;
width: 46px;
height: 46px;
place-items: center;
border-radius: 8px;
color: #ffffff;
font-size: 22px;
}
.wallet-metric-card.is-available .metric-icon {
background: #ff6b00;
}
.wallet-metric-card.is-frozen .metric-icon {
background: #3b82f6;
}
.wallet-metric-card.is-status .metric-icon {
background: #0f766e;
}
.wallet-metric-card.is-warning .metric-icon {
background: #d97706;
}
.wallet-metric-card span,
.wallet-metric-card small {
display: block;
color: #64748b;
}
.wallet-metric-card span {
font-size: 13px;
font-weight: 600;
}
.wallet-metric-card strong {
display: block;
margin-top: 8px;
color: #111a44;
font-size: 26px;
line-height: 1.1;
}
.wallet-metric-card small {
margin-top: 8px;
font-size: 12px;
}
.wallet-workspace {
display: grid;
grid-template-columns: minmax(420px, 1.1fr) minmax(320px, 0.9fr);
gap: 16px;
}
.recharge-panel,
.ledger-summary-card {
display: grid;
gap: 18px;
padding: 20px;
border: 1px solid #e6eaf2;
border-radius: 8px;
background: #ffffff;
box-shadow: 0 12px 30px rgba(17, 24, 39, 0.05);
}
.ledger-summary-card {
align-content: space-between;
}
.ledger-summary-card :deep(.el-button) {
justify-self: start;
min-width: 118px;
}
.panel-title {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 16px;
padding: 16px;
}
.recharge-panel h2 {
.panel-title-icon {
display: grid;
flex: 0 0 40px;
width: 40px;
height: 40px;
place-items: center;
border-radius: 8px;
background: #fff4ec;
color: #ff6b00;
font-size: 20px;
}
.panel-title-icon.is-blue {
background: #eff6ff;
color: #2563eb;
}
.panel-title h2 {
margin: 0;
font-size: 16px;
color: #111827;
font-size: 17px;
}
.panel-title p {
margin: 5px 0 0;
color: #64748b;
font-size: 13px;
}
.quick-amounts {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.quick-amounts button {
min-width: 92px;
height: 36px;
border: 1px solid #d8dee9;
border-radius: 8px;
background: #f8fafc;
color: #334155;
font-weight: 600;
cursor: pointer;
}
.quick-amounts button.active,
.quick-amounts button:hover {
border-color: #ff8a3d;
background: #fff4ec;
color: #ea580c;
}
.recharge-action-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.wallet-ledger-table {
overflow-x: auto;
border: 1px solid #e6eaf2;
border-radius: 8px;
background: #ffffff;
box-shadow: 0 12px 30px rgba(17, 24, 39, 0.05);
}
.ledger-grid {
display: grid;
grid-template-columns:
minmax(200px, 2fr)
minmax(100px, 0.8fr)
minmax(80px, 0.6fr)
minmax(100px, 0.8fr)
minmax(100px, 0.8fr)
minmax(120px, 0.9fr)
minmax(140px, 1.2fr)
minmax(170px, 1.1fr);
align-items: center;
column-gap: clamp(10px, 1vw, 20px);
padding: 0 clamp(16px, 1.5vw, 24px);
}
.ledger-header {
min-height: 48px;
border-bottom: 1px solid #e6eaf2;
background: #f8fafc;
color: #64748b;
font-size: 13px;
font-weight: 700;
}
.ledger-header span {
text-align: center;
}
.ledger-header span.align-right {
text-align: right;
}
.ledger-row {
min-height: 54px;
border-bottom: 1px solid #edf1f6;
color: #334155;
font-size: 14px;
transition: background 0.15s ease;
}
.ledger-row:last-child {
border-bottom: 0;
}
.ledger-row:hover {
background: #f8fafc;
}
.ledger-cell {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: center;
}
.ledger-cell.align-right {
text-align: right;
}
.ledger-no {
color: #475569;
font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
font-size: 12px;
letter-spacing: 0.02em;
text-align: center;
}
.align-right {
text-align: right;
}
.ledger-empty {
display: grid;
min-height: 80px;
place-items: center;
border-top: 1px solid #edf1f6;
color: #94a3b8;
font-size: 14px;
}
.biz-tag {
max-width: 96px;
height: 24px;
line-height: 22px;
}
.amount-cell {
font-weight: 700;
}
.amount-cell.is-in,
.amount-cell.is-unfreeze {
color: #047857;
}
.amount-cell.is-out,
.amount-cell.is-freeze {
color: #dc2626;
}
.muted-cell {
color: #64748b;
}
.pay-dialog-body {
@@ -352,10 +812,62 @@ function readError(error: unknown, fallback: string) {
}
@media (max-width: 720px) {
.wallet-hero {
display: grid;
padding: 20px;
}
.wallet-hero-action {
min-width: 0;
text-align: left;
}
.wallet-metric-grid,
.wallet-workspace {
grid-template-columns: 1fr;
}
.wallet-metric-card {
min-height: auto;
}
.recharge-action-row :deep(.el-input-number) {
width: 100%;
}
.recharge-action-row :deep(.el-button) {
width: 100%;
}
.pay-qr-panel {
grid-template-columns: 1fr;
justify-items: center;
text-align: center;
}
.ledger-grid {
grid-template-columns:
minmax(160px, 1.5fr)
minmax(80px, 0.8fr)
minmax(64px, 0.6fr)
minmax(80px, 0.8fr)
minmax(80px, 0.8fr)
minmax(100px, 0.9fr)
minmax(120px, 1fr)
minmax(140px, 1fr);
column-gap: 8px;
padding: 0 12px;
font-size: 13px;
}
.ledger-header {
min-height: 40px;
font-size: 12px;
}
.ledger-row {
min-height: 48px;
font-size: 13px;
}
}
</style>