Commit a0a22d52 by chenwq

feat(行为路径分析): 重构路径流程图组件并添加数据过滤功能

- 将PathFlowChart改为接收props数据而非静态导入
- 添加无数据状态显示
- 在pathList中实现基于筛选条件的数据过滤
- 移除未使用的客户名称搜索字段
- 优化图表标题样式和布局
1 parent 393abdee
<template> <template>
<div class="path-flow-container"> <div class="path-flow-container">
<div ref="chart" class="chart-container"></div> <div class="chart-title">用户行为路径分析</div>
<div v-show="hasData" ref="chart" class="chart-container"></div>
<div v-show="!hasData" class="no-data-container">
<div class="no-data-text">暂无数据</div>
</div>
</div> </div>
</template> </template>
<script> <script>
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { nodes, links } from './chartData'
export default { export default {
name: 'PathFlowChart', name: 'PathFlowChart',
props: {
chartNodes: {
type: Array,
default: () => []
},
chartLinks: {
type: Array,
default: () => []
}
},
computed: {
hasData() {
return this.chartNodes && this.chartNodes.length > 0
}
},
data() { data() {
return { return {
chart: null chart: null
} }
}, },
watch: {
chartNodes: {
handler() {
this.updateChart()
},
deep: true
}
},
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
this.initChart() this.initChart()
...@@ -33,16 +59,23 @@ export default { ...@@ -33,16 +59,23 @@ export default {
this.chart.resize() this.chart.resize()
} }
}, },
updateChart() {
if (this.chart) {
this.chart.setOption({
series: [
{
data: this.chartNodes,
links: this.chartLinks
}
]
})
}
},
initChart() { initChart() {
const chartDom = this.$refs.chart const chartDom = this.$refs.chart
this.chart = echarts.init(chartDom) this.chart = echarts.init(chartDom)
const option = { const option = {
title: {
text: '用户行为路径分析',
left: 'center',
top: 10
},
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',
triggerOn: 'mousemove' triggerOn: 'mousemove'
...@@ -50,8 +83,8 @@ export default { ...@@ -50,8 +83,8 @@ export default {
series: [ series: [
{ {
type: 'sankey', type: 'sankey',
data: nodes, data: this.chartNodes,
links: links, links: this.chartLinks,
left: '3%', left: '3%',
right: '3%', right: '3%',
top: '5%', top: '5%',
...@@ -112,8 +145,28 @@ export default { ...@@ -112,8 +145,28 @@ export default {
border-radius: 4px; border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
} }
.chart-title {
text-align: center;
font-size: 18px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.chart-container { .chart-container {
width: 100%; width: 100%;
height: 800px; height: 800px;
} }
.no-data-container {
width: 100%;
height: 800px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f7fa;
border-radius: 4px;
}
.no-data-text {
font-size: 16px;
color: #909399;
}
</style> </style>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="scrm-sub-client-container"> <div class="scrm-sub-client-container">
<div class="pageContent"> <div class="pageContent">
<GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm> <GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm>
<PathFlowChart /> <PathFlowChart :chartNodes="chartNodes" :chartLinks="chartLinks" />
</div> </div>
</div> </div>
</div> </div>
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<script> <script>
import PathFlowChart from './components/PathFlowChart' import PathFlowChart from './components/PathFlowChart'
import { nodes, links } from './components/chartData'
const EVENT_OPTIONS = [ const EVENT_OPTIONS = [
// App相关 // App相关
...@@ -36,19 +37,21 @@ export default { ...@@ -36,19 +37,21 @@ export default {
}, },
data() { data() {
return { return {
chartNodes: [],
chartLinks: [],
searchForm: { searchForm: {
addWay: [], addWay: [],
customerName: '', customerName: '',
purchaseCar: '' purchaseCar: ''
}, },
clientManageFormList: [ clientManageFormList: [
{ // {
type: 'input', // type: 'input',
inputType: 'text', // inputType: 'text',
name: 'customerName', // name: 'customerName',
label: '客户名称', // label: '客户名称',
placeholder: '请输入客户名称' // placeholder: '请输入客户名称'
}, // },
{ {
type: 'select', type: 'select',
name: 'addWay', name: 'addWay',
...@@ -78,21 +81,40 @@ export default { ...@@ -78,21 +81,40 @@ export default {
] ]
} }
}, },
created() {}, created() {
this.chartNodes = nodes
this.chartLinks = links
},
methods: { methods: {
//搜索表格 //搜索表格
searchTable() { searchTable() {
this.$refs.clientManage.refreshTable() // Check if filters are effectively empty
const isAddWayEmpty = !this.searchForm.addWay || this.searchForm.addWay.length === 0
const isDateEmpty = !this.searchForm.purchaseCar
if (isAddWayEmpty && isDateEmpty) {
// Show current data source
this.chartNodes = nodes
this.chartLinks = links
} else {
// Show empty
this.chartNodes = []
this.chartLinks = []
}
// this.$refs.clientManage.refreshTable() // Removed as clientManage ref might not exist or is not shown in template provided
}, },
//重置表格 //重置表格
resetTable() { resetTable() {
this.searchForm = {} this.searchForm = {
this.$refs.clientManage.refreshTable() addWay: [],
// 点击之后强制页面刷新 customerName: '',
// this.reload() purchaseCar: ''
// this.$forceUpdate() // 没用 }
// this.$router.go(0)//没有预期效果,会出现一段空白页,用户体验不好 // Reset to original data
// location.reload() //没有预期效果,会出现一段空白页,用户体验不好 this.chartNodes = nodes
this.chartLinks = links
// this.$refs.clientManage.refreshTable()
}, },
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!