feat:【mall 商城】会员统计【antd】20% sex-card.vue 完善
This commit is contained in:
@@ -1,21 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
import type { MallMemberStatisticsApi } from '#/api/mall/statistics/member';
|
import type { MallMemberStatisticsApi } from '#/api/mall/statistics/member';
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
|
||||||
|
|
||||||
import { Card } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
|
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
// 获取字典选项
|
import { Card, Spin } from 'ant-design-vue';
|
||||||
function getIntDictOptions(dictType: string) {
|
|
||||||
return getDictOptions(dictType, 'number');
|
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
|
||||||
}
|
|
||||||
|
|
||||||
import { getSexChartOptions } from './sex-chart-options';
|
import { getSexChartOptions } from './sex-chart-options';
|
||||||
|
|
||||||
@@ -31,19 +27,18 @@ async function getMemberSexStatisticsList() {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const list = await MemberStatisticsApi.getMemberSexStatisticsList();
|
const list = await MemberStatisticsApi.getMemberSexStatisticsList();
|
||||||
const dictDataList = getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX);
|
const dictDataList = getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number');
|
||||||
dictDataList.push({ label: '未知', value: null } as any);
|
dictDataList.push({ label: '未知', value: null } as any);
|
||||||
|
|
||||||
const chartData = dictDataList.map((dictData: any) => {
|
const chartData = dictDataList.map((dictData: any) => {
|
||||||
const userCount = list.find(
|
const userCount = list.find(
|
||||||
(item: MallMemberStatisticsApi.SexStatistics) => item.sex === dictData.value,
|
(item: MallMemberStatisticsApi.SexStatistics) =>
|
||||||
|
item.sex === dictData.value,
|
||||||
)?.userCount;
|
)?.userCount;
|
||||||
return {
|
return {
|
||||||
name: dictData.label,
|
name: dictData.label,
|
||||||
value: userCount || 0,
|
value: userCount || 0,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
await renderEcharts(getSexChartOptions(chartData));
|
await renderEcharts(getSexChartOptions(chartData));
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@@ -57,7 +52,9 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Card :bordered="false" title="会员性别比例" :loading="loading">
|
<Card :bordered="false" title="会员性别比例" class="h-full">
|
||||||
<EchartsUI ref="chartRef" class="h-[300px] w-full" />
|
<Spin :spinning="loading">
|
||||||
|
<EchartsUI ref="chartRef" />
|
||||||
|
</Spin>
|
||||||
</Card>
|
</Card>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import type { EChartsOption } from 'echarts';
|
|
||||||
|
|
||||||
interface ChartData {
|
|
||||||
name: string;
|
|
||||||
value: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 会员性别比例图表配置 */
|
/** 会员性别比例图表配置 */
|
||||||
export function getSexChartOptions(data: ChartData[]): EChartsOption {
|
export function getSexChartOptions(data: any[]): any {
|
||||||
return {
|
return {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'item',
|
trigger: 'item',
|
||||||
|
|||||||
Reference in New Issue
Block a user