```feat(user): 查询并显示当前用户余额
在用户页面展示当前用户的余额信息,通过调用用户余额接口获取数据。优化界面布局,确保余额信息 清晰呈现给用户。同时,修复了潜在的token解析问题,保证用户数据准确无误。 修复了用户余额展示的bug,优化了用户界面体验。 ```master
parent
f6a22b33b8
commit
44c7e479fa
|
@ -14,7 +14,7 @@ export function listUser(query) {
|
|||
// 用户余额
|
||||
export function userRecharge(data) {
|
||||
return request({
|
||||
url: '/money/alipay/recharge',
|
||||
url: '/system/alipay/recharge',
|
||||
method: 'post',
|
||||
params: data
|
||||
})
|
||||
|
@ -23,7 +23,7 @@ export function userRecharge(data) {
|
|||
// 查询用户余额
|
||||
export function userBalance(userId) {
|
||||
return request({
|
||||
url: '/money/balance/' + userId,
|
||||
url: '/system/user/balance/' + userId,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,30 +1,45 @@
|
|||
<template>
|
||||
<div>
|
||||
<span style="text-align: center">账户余额: {{ balance }}</span>
|
||||
<h1>用户余额</h1>
|
||||
<p>余额:{{ userBalanceData.userBalance || '加载中...' }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {userBalance} from "@/api/system/user";
|
||||
import { userBalance } from "@/api/system/user"; // 假设你的userBalance函数在@/api/money目录下
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
balance: null, // 用于存储用户余额
|
||||
userBalanceData: {
|
||||
userBalance: '加载中...'
|
||||
}
|
||||
};
|
||||
},
|
||||
async created() {
|
||||
try {
|
||||
const userId = 1; // 根据实际情况获取用户 ID
|
||||
const response = await userBalance(userId);
|
||||
this.balance = response.data.balance; // 假设响应数据中包含余额信息
|
||||
} catch (error) {
|
||||
console.error('Error fetching user balance:', error);
|
||||
}
|
||||
created() {
|
||||
this.fetchUserBalance();
|
||||
},
|
||||
methods: {
|
||||
async fetchUserBalance() {
|
||||
try {
|
||||
const userId = localStorage.getItem('userId');
|
||||
console.log(userId)// 假设你登录后把userId存到了localStorage
|
||||
if (!userId) {
|
||||
this.userBalanceData = {userBalance: '未登录'};
|
||||
return;
|
||||
}
|
||||
const response = await userBalance(userId);
|
||||
if (response.data) {
|
||||
console.log(response.data)
|
||||
this.userBalanceData.userBalance = response.data; // 假设response.data直接返回了余额信息
|
||||
} else {
|
||||
this.userBalanceData.userBalance = {userBalance: '获取失败'};
|
||||
}
|
||||
} catch (error) {
|
||||
this.userBalanceData = {userBalance: '获取失败'};
|
||||
console.error('Error fetching user balance:', error);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 添加样式 */
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue