Merge remote-tracking branch 'origin/master'

master
lwj 2024-08-24 22:31:48 +08:00
commit b179bf511a
2 changed files with 32 additions and 17 deletions

View File

@ -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',
})
}

View File

@ -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)// userIdlocalStorage
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>