add StoreCustomerTagWordCloudChart.vue
This commit is contained in:
@@ -0,0 +1,156 @@
|
|||||||
|
<template>
|
||||||
|
<section class="chart-section">
|
||||||
|
<h2>标签词云</h2>
|
||||||
|
<center-tips v-if="isLoading" :content="'正在分析客户标签'" />
|
||||||
|
<center-tips v-else-if="!tagList.length" :content="'暂无可分析的客户标签'" />
|
||||||
|
<div v-else ref="chartElement" class="chart" />
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { ECharts, EChartsOption } from "echarts";
|
||||||
|
import { init, use } from "echarts/core";
|
||||||
|
import { TooltipComponent } from "echarts/components";
|
||||||
|
import "echarts-wordcloud";
|
||||||
|
import { CanvasRenderer } from "echarts/renderers";
|
||||||
|
import TagAPI from "@/api/TagAPI";
|
||||||
|
import type { Tag } from "@/types/Tag";
|
||||||
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { Message } from "@/utils/message";
|
||||||
|
|
||||||
|
use([TooltipComponent, CanvasRenderer]);
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: "StoreCustomerTagWordCloudChart"
|
||||||
|
});
|
||||||
|
|
||||||
|
const chartColorList = ["#2563eb", "#0f766e", "#d97706", "#db2777", "#7c3aed", "#0891b2"];
|
||||||
|
|
||||||
|
// ---------- 图表数据 ----------
|
||||||
|
|
||||||
|
const tagList = ref<Tag[]>([]);
|
||||||
|
const isLoading = ref(false);
|
||||||
|
const chartElement = ref<HTMLElement>();
|
||||||
|
let chart: ECharts | undefined;
|
||||||
|
let requestId = 0;
|
||||||
|
|
||||||
|
const chartOption = computed<EChartsOption>(() => ({
|
||||||
|
tooltip: {
|
||||||
|
trigger: "item",
|
||||||
|
formatter: "{b}:{c} 位客户"
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: "客户标签",
|
||||||
|
type: "wordCloud",
|
||||||
|
shape: "circle",
|
||||||
|
left: "center",
|
||||||
|
top: "center",
|
||||||
|
width: "94%",
|
||||||
|
height: "92%",
|
||||||
|
gridSize: 8,
|
||||||
|
sizeRange: [14, 48],
|
||||||
|
rotationRange: [0, 0],
|
||||||
|
rotationStep: 0,
|
||||||
|
drawOutOfBound: false,
|
||||||
|
layoutAnimation: false,
|
||||||
|
textStyle: {
|
||||||
|
fontFamily: "sans-serif",
|
||||||
|
fontWeight: "bold"
|
||||||
|
},
|
||||||
|
data: tagList.value.map((item, index) => ({
|
||||||
|
name: item.name || item.zhCN || "未命名标签",
|
||||||
|
value: item.useCount || 0,
|
||||||
|
textStyle: {
|
||||||
|
color: chartColorList[index % chartColorList.length]
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
] as unknown as EChartsOption["series"]
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ---------- 图表生命周期 ----------
|
||||||
|
|
||||||
|
watch(tagList, async () => {
|
||||||
|
await nextTick();
|
||||||
|
renderChart();
|
||||||
|
}, { deep: true });
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadTagList();
|
||||||
|
window.addEventListener("resize", resizeChart);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener("resize", resizeChart);
|
||||||
|
chart?.dispose();
|
||||||
|
chart = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadTagList(): Promise<void> {
|
||||||
|
const currentRequestId = ++requestId;
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await TagAPI.list({
|
||||||
|
index: 0,
|
||||||
|
size: 60
|
||||||
|
});
|
||||||
|
if (currentRequestId === requestId) {
|
||||||
|
tagList.value = result.list || [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (currentRequestId === requestId) {
|
||||||
|
Message.error(getErrorMessage(error, "客户标签词云加载失败"));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (currentRequestId === requestId) {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderChart(): void {
|
||||||
|
if (!chartElement.value || !tagList.value.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chart = chart || init(chartElement.value);
|
||||||
|
chart.setOption(chartOption.value, true);
|
||||||
|
chart.resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resizeChart(): void {
|
||||||
|
chart?.resize();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.chart-section {
|
||||||
|
padding: 1rem;
|
||||||
|
background: rgba(255, 255, 255, .92);
|
||||||
|
box-shadow: var(--td-shadow-1);
|
||||||
|
border-radius: 1.25rem;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin: 0;
|
||||||
|
color: #0f172a;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart {
|
||||||
|
width: 100%;
|
||||||
|
height: 18rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(html.theme-dark) {
|
||||||
|
.chart-section {
|
||||||
|
background: rgba(15, 23, 42, .88);
|
||||||
|
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
<template v-if="chartMode === 'customer'">
|
<template v-if="chartMode === 'customer'">
|
||||||
<store-customer-growth-chart v-entrance-transition :date-text-list="dateTextList" />
|
<store-customer-growth-chart v-entrance-transition :date-text-list="dateTextList" />
|
||||||
<store-customer-age-chart v-entrance-transition />
|
<store-customer-age-chart v-entrance-transition />
|
||||||
|
<store-customer-tag-word-cloud-chart v-entrance-transition />
|
||||||
<store-customer-disease-word-cloud-chart v-entrance-transition />
|
<store-customer-disease-word-cloud-chart v-entrance-transition />
|
||||||
<store-customer-gender-chart v-entrance-transition />
|
<store-customer-gender-chart v-entrance-transition />
|
||||||
</template>
|
</template>
|
||||||
@@ -36,6 +37,7 @@ import StoreCustomerAgeChart from "@/pages/store/component/StoreCustomerAgeChart
|
|||||||
import StoreCustomerGenderChart from "@/pages/store/component/StoreCustomerGenderChart.vue";
|
import StoreCustomerGenderChart from "@/pages/store/component/StoreCustomerGenderChart.vue";
|
||||||
import StoreCustomerGrowthChart from "@/pages/store/component/StoreCustomerGrowthChart.vue";
|
import StoreCustomerGrowthChart from "@/pages/store/component/StoreCustomerGrowthChart.vue";
|
||||||
import StoreCustomerDiseaseWordCloudChart from "@/pages/store/component/StoreCustomerDiseaseWordCloudChart.vue";
|
import StoreCustomerDiseaseWordCloudChart from "@/pages/store/component/StoreCustomerDiseaseWordCloudChart.vue";
|
||||||
|
import StoreCustomerTagWordCloudChart from "@/pages/store/component/StoreCustomerTagWordCloudChart.vue";
|
||||||
import StoreEventRecordCalendarSection from "@/pages/store/component/StoreEventRecordCalendarSection.vue";
|
import StoreEventRecordCalendarSection from "@/pages/store/component/StoreEventRecordCalendarSection.vue";
|
||||||
import StoreEventRecordTrendChart from "@/pages/store/component/StoreEventRecordTrendChart.vue";
|
import StoreEventRecordTrendChart from "@/pages/store/component/StoreEventRecordTrendChart.vue";
|
||||||
import StoreEventRecordNumberValueChart from "@/pages/store/component/StoreEventRecordNumberValueChart.vue";
|
import StoreEventRecordNumberValueChart from "@/pages/store/component/StoreEventRecordNumberValueChart.vue";
|
||||||
|
|||||||
Reference in New Issue
Block a user