新增用户余额和月度消费图表展示功能

添加了一个图表,以直观展示用户余额和过去12个月的总消费金额。优化了数据获取逻辑,确保组件在`index.vue`中能够正确拉取和显示数据。同时,修复了与用户余额相关的API路径问题。
master
wxy 2024-09-04 19:59:07 +08:00
parent 0329717d76
commit 3337d79d38
2 changed files with 34 additions and 4 deletions

View File

@ -21,6 +21,14 @@ export function userloginfo(query) {
}) })
} }
//查询12个月的总消费
export function months() {
return request({
url: '/system/user/months',
method: 'get',
})
}
//充值用户记录 //充值用户记录
export function userPayinfo(query) { export function userPayinfo(query) {

View File

@ -63,18 +63,22 @@
</template> </template>
<script> <script>
import {userBalance} from "@/api/system/user"; // import {userBalance,months} from "@/api/system/user"; //
import * as echarts from 'echarts' //echarts import * as echarts from 'echarts' //echarts
import {checkRealNameAuth} from "@/api/system/user"; import {checkRealNameAuth} from "@/api/system/user";
import item from "@/layout/components/Sidebar/Item.vue";
export default { export default {
data() { data() {
return { return {
charts: "", charts: "",
dialogVisible: false, dialogVisible: false,
listDate:[],
a:[],
b:[],
dialogFormVisible: false, dialogFormVisible: false,
formLabelWidth: '120px', formLabelWidth: '120px',
opinionData: ["155", "400", "900", "800", "300", "900", "270", "684", "165", "0", "300", "150"], // opinionData: [],
userBalanceData: { userBalanceData: {
userBalance: '加载中...' userBalance: '加载中...'
}, },
@ -97,11 +101,25 @@ export default {
}, },
created() { created() {
this.fetchUserBalance(); this.fetchUserBalance();
this.getList()
}, },
mounted() { mounted() {
this.drawLine(); this.drawLine();
}, },
methods: { methods: {
getList(){
months().then(response => {
const responseDate = response;
responseDate.forEach(item => {
console.log('月',item.month, '总金额:', item.totalAmount)
});
this.listDate = responseDate;
this.drawLine();
this.$nextTick( () => {
console.log(JSON.stringify(this.listDate))
});
});
},
handleCancel() { handleCancel() {
this.dialogVisible = false; this.dialogVisible = false;
}, },
@ -172,6 +190,10 @@ export default {
// 线 // 线
this.charts = echarts.init(document.getElementById('main')); this.charts = echarts.init(document.getElementById('main'));
this.a = this.listDate.map(item => item.month)
this.b = this.listDate.map(item => item.totalAmount)
// 线 // 线
this.charts.setOption({ this.charts.setOption({
title: { title: {
@ -213,7 +235,7 @@ export default {
alignWithLabel: true, alignWithLabel: true,
}, },
// //
data: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"], data: this.a,
}, },
// y // y
@ -230,7 +252,7 @@ export default {
name: "消费金额", // name: "消费金额", //
type: "line", type: "line",
stack: "总量", // stack: "总量", //
data: this.opinionData, // data: this.b,
areaStyle: { areaStyle: {
color: { color: {
type: "linear", type: "linear",