Commit 35c4e046 by 前端

Merge branch 'v3.23.0' into 'master'

V3.23.0

See merge request !183
2 parents 3917b2fc d5a450f8
<template> <template>
<div class="bar-chart"> <div class="bar-chart">
<p class="line-color-title">{{title}}</p> <p class="line-color-title">{{title}}</p>
<div ref="barChart" style="width: 100%; height: 30vh;"></div> <div v-if="data" ref="barChart" style="width: 100%; height: 30vh;"></div>
</div> </div>
</template> </template>
...@@ -27,6 +27,10 @@ export default { ...@@ -27,6 +27,10 @@ export default {
['#6E77FF', '#A1D9FF'], // 渐变色1 ['#6E77FF', '#A1D9FF'], // 渐变色1
['#90D55C', '#FDDB93'], // 渐变色2 ['#90D55C', '#FDDB93'], // 渐变色2
] ]
},
rotate:{
type:Number,
default:45
} }
}, },
watch: { watch: {
...@@ -41,26 +45,38 @@ export default { ...@@ -41,26 +45,38 @@ export default {
drawChart() { drawChart() {
const chart = echarts.init(this.$refs.barChart); const chart = echarts.init(this.$refs.barChart);
let xAxisData, seriesData;
if (this.data && this.data.length > 0) {
xAxisData = this.data.map(item => item.name);
seriesData = this.data.map(item => item.value);
} else {
// 当data为空时,设置默认的X轴和Y轴,但不包含数据点
xAxisData = [''];
seriesData = [0];
}
const option = { const option = {
xAxis: { xAxis: {
type: 'category', type: 'category',
data: this.data.map(item => item.name), data: this.data.map(item => item.name),
axisTick: { show: false }, axisTick: { show: false },
axisLine: { show: false }, axisLine: { show: true },
axisLabel: { axisLabel: {
interval: 0, interval: 0,
rotate: 45 rotate: this.rotate
} }
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
axisTick: { show: false }, minInterval: 1, // 确保Y轴刻度间隔最小为1,避免数据过小时出现小数点
axisLine: { show: false }, // axisTick: { show: false },
splitLine: { show: false }, // axisLine: { show: false },
// splitLine: { show: false },
// axisLabel: { show: false } // axisLabel: { show: false }
}, },
series: [{ series: [{
data: this.data.map(item => item.value), data: seriesData,
type: 'bar', type: 'bar',
barWidth: '20%', barWidth: '20%',
label: { label: {
...@@ -69,13 +85,15 @@ export default { ...@@ -69,13 +85,15 @@ export default {
}, },
itemStyle: { itemStyle: {
color: (params) => { color: (params) => {
const dataIndex = params.dataIndex const dataIndex = params.dataIndex;
const gradientIndex = Math.floor(dataIndex%2) const gradientIndex = dataIndex % this.colors.length; // 循环使用渐变色
const colorPair = this.colors[gradientIndex];
return { return {
type: 'linear', type: 'linear',
colorStops: [ colorStops: [
{ offset: 0, color: this.colors[gradientIndex][0] }, { offset: 0, color: colorPair[0] },
{ offset: 1, color: this.colors[gradientIndex][1] }, { offset: 1, color: colorPair[1] },
], ],
globalCoord: false, globalCoord: false,
x: 0, // 渐变的起始点横坐标 x: 0, // 渐变的起始点横坐标
...@@ -84,14 +102,9 @@ export default { ...@@ -84,14 +102,9 @@ export default {
y2: 1, // 渐变的结束点纵坐标(设置为1表示从上到下 y2: 1, // 渐变的结束点纵坐标(设置为1表示从上到下
}; };
}, },
barBorderRadius: 5 barBorderRadius: 3
} }
// itemStyle: {
// color: (params) => {
// return this.colors[params.dataIndex % this.colors.length];
// },
// barBorderRadius: 5
// }
}] }]
}; };
...@@ -102,9 +115,9 @@ export default { ...@@ -102,9 +115,9 @@ export default {
</script> </script>
<style lang="scss"> <style lang="scss">
#chart { //#chart {
width: 100%; // width: 100%;
height: 400px; // height: 400px;
} //}
</style> </style>
<template> <template>
<div class="line-chart"> <div class="line-chart">
<p class="line-color-title">{{title}}</p> <p class="line-color-title">{{title}}</p>
<div ref="lineChart" style="width: 100%; height:30vh;"></div> <div v-if="data" ref="lineChart" style="width: 100%; height:30vh;"></div>
</div> </div>
</template> </template>
...@@ -46,11 +46,12 @@ export default { ...@@ -46,11 +46,12 @@ export default {
xAxis: { xAxis: {
type: 'category', type: 'category',
boundaryGap: false, boundaryGap: false,
axisTick: { show: false }, // axisTick: { show: false },
data: this.data.map(item => item.name), data: this.data.map(item => item.name),
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
minInterval: 1, // 确保Y轴刻度间隔最小为1,避免数据过小时出现小数点
}, },
series: [ series: [
{ {
......
<template> <template>
<div> <div>
<p class="line-color-title">{{title}}</p> <p class="line-color-title">{{title}}</p>
<div ref="pieChart" style="margin-top:10px;width: 100%; height: 20vh;"></div> <div v-if="data" ref="pieChart" style="margin-top:10px;width: 100%; height:24.5vh;"></div>
</div> </div>
</template> </template>
...@@ -25,12 +25,43 @@ export default { ...@@ -25,12 +25,43 @@ export default {
default: () => ['#50CEFB', '#5850FF','#FBBE50','#90D55C','#FDDB93','#A1EDFF','#6EA3FF','#FF5A92','#BCCAFF','#9F6EFF'], default: () => ['#50CEFB', '#5850FF','#FBBE50','#90D55C','#FDDB93','#A1EDFF','#6EA3FF','#FF5A92','#BCCAFF','#9F6EFF'],
}, },
}, },
data() {
return {
dynamicRichStyles: {},
};
},
mounted() { mounted() {
this.initChart(this.$refs.pieChart); this.initChart(this.$refs.pieChart);
this.drawChart(); this.drawChart();
this.dynamicResizeChart();
}, },
methods: { methods: {
generateRichStyles() {
this.colors.forEach((color, index) => {
this.dynamicRichStyles['style' + index] = {
color: color,
fontWeight: 'bold',
fontSize: '17px'
};
});
},
createFormatter(params) {
const dataIndex = params.dataIndex;
const dataItem = this.data[dataIndex]; // 获取当前索引下的数据项
const styleKey = 'style' + (dataIndex % this.colors.length);
// 确保dataItem存在,并且displayQuantity已定义
const displayQuantityText = dataItem && dataItem.displayQuantity !== undefined && dataItem.displayQuantity !== null
? '('+dataItem.displayQuantity + '人' + ')'
: '';
return `{${styleKey}|${params.value}%}\n\n{b|${params.name}${displayQuantityText}}`;
},
drawChart() { drawChart() {
this.generateRichStyles(); // 生成动态样式
const chart = echarts.init(this.$refs.pieChart); const chart = echarts.init(this.$refs.pieChart);
const option = { const option = {
...@@ -45,25 +76,12 @@ export default { ...@@ -45,25 +76,12 @@ export default {
type: 'pie', type: 'pie',
radius: ['40%', '60%'], radius: ['40%', '60%'],
avoidLabelOverlap: false, avoidLabelOverlap: false,
minAngle: 50, // 设置最小角度为50度,针对传入的数据为0
label: { label: {
show: true, show: true,
position: 'outside', position: 'outside',
formatter: function(params) { formatter: this.createFormatter, // 引用 formatter 函数
return '{a|' + params.value + '%'+ '}' rich: this.dynamicRichStyles, // 使用动态生成的样式
+'\n'+'\n'+
' {b|' + params.name + '}'
},
rich: {
a: {
color: '#50CEFB',
fontWeight: 'bold',
fontSize:'18px'
},
b: {
color: '#333',
fontSize:'14px',
}
}
}, },
labelLine: { labelLine: {
show: true show: true
...@@ -84,6 +102,12 @@ export default { ...@@ -84,6 +102,12 @@ export default {
}; };
</script> </script>
<style lang="scss"> <style lang="scss" scoped>
/* 您可以根据需要添加自定义样式 */ /* 您可以根据需要添加自定义样式 */
@media screen and (min-resolution: 2dppx) {
/* 针对高分辨率显示屏的样式调整 */
.pieChart {
height: 28vh; /* 可能需要更大的高度 */
}
}
</style> </style>
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
<div class="avatar male"></div> <div class="avatar male"></div>
<span>男</span> <span>男</span>
<div class="progress"> <div class="progress">
<div class="fill male" :style="{ width: malePercentage==0? 50: malePercentage+ '%','min-width':'40%', <div class="fill male" :style="styleObject">{{
'max-width':'50%',
'margin-left':(30 <malePercentage && malePercentage < 50 ? malePercentage:0 <malePercentage && malePercentage <30?
malePercentage*2 : malePercentage/4) + '%' }">{{
malePercentage || 0 malePercentage || 0
}}% }}%
</div> </div>
...@@ -42,6 +39,28 @@ export default { ...@@ -42,6 +39,28 @@ export default {
} }
}, },
computed: { computed: {
styleObject() {
// 基本的宽度样式
let widthStyle = this.malePercentage === 0 ? '50%' : `${this.malePercentage}%`;
// 计算marginLeft
let marginLeftStyle;
if (this.malePercentage > 30 && this.malePercentage < 50) {
marginLeftStyle = `${this.malePercentage}%`;
} else if (this.malePercentage > 0 && this.malePercentage < 30) {
marginLeftStyle = `${this.malePercentage * 2}%`;
} else {
marginLeftStyle = `${this.malePercentage / 4}%`;
}
// 返回样式对象
return {
width: widthStyle,
'min-width': '40%',
'max-width': '50%',
'margin-left': marginLeftStyle,
};
},
malePercentage() { malePercentage() {
let percentage = (this.maleCount / (this.maleCount + this.femaleCount)) * 100; let percentage = (this.maleCount / (this.maleCount + this.femaleCount)) * 100;
......
<template> <template>
<!-- 该页面图表显示的颜色均可通过传入color参数修改--> <!-- 该页面图表显示的颜色均可通过传入color参数修改-->
<div class="dashboard"> <div class="dashboard">
<!-- 用户信息部分 --> <!-- 用户信息部分 -->
<div class="user-section"> <div class="user-section">
...@@ -13,13 +13,20 @@ ...@@ -13,13 +13,20 @@
<!-- 图表部分 --> <!-- 图表部分 -->
<div class="charts-section"> <div class="charts-section">
<PieChart :title="'客户来源'" v-if="sourceDistribution" :data="sourceDistribution"/> <PieChart :title="'客户来源'" :data="sourceDistribution"/>
<PieChart :title="'租住比'" v-if="lodgeDistribution" :data="lodgeDistribution"/> <PieChart :title="'租住比'" :data="lodgeDistribution"/>
<PieChart :title="'消费能力'" v-if="consumeDistribution" :data="consumeDistribution"/> <PieChart :title="'消费能力'" :data="consumeDistribution"/>
<PieChart :title="'车辆类型'" v-if="vehicleDistribution" :data="vehicleDistribution"/> <PieChart :title="'车辆类型'" :data="vehicleDistribution"/>
<LineChart :title="'浏览时段偏好'" v-if="browseDistribution" :data="browseDistribution"/> <BarChart :title="'甄选商品偏好(top10)'" :data="productDistribution"></BarChart>
<BarChart :title="'甄选商品偏好(top10)'" v-if="productDistribution" :data="productDistribution"></BarChart> <BarChart :title="'攻略偏好(top10)'" :data="strategyDistribution"></BarChart>
<BarChart :title="'权益购买偏好(top10)'" :data="equityDistribution"></BarChart>
<LineChart :title="'浏览时段偏好'" :data="browseDistribution"/>
<PieChart :title="'客户购买转化阶段'" :data="transformDistribution"/>
<BarChart :title="'客户全生命周期价值(LTV)'" :data="ltvDistribution"
:colors="[['#6E77FF', '#A1D9FF']]" :rotate="0"></BarChart>
</div> </div>
</div> </div>
...@@ -58,6 +65,11 @@ export default { ...@@ -58,6 +65,11 @@ export default {
browseDistribution: null, browseDistribution: null,
productDistribution: null, productDistribution: null,
strategyDistribution: null,
equityDistribution: null,
transformDistribution: null,
ltvDistribution: null,
mockAgeColors: [ mockAgeColors: [
{offset: 0.02, color: '#BCCAFF'}, {offset: 0.02, color: '#BCCAFF'},
{offset: 1, color: '#9F6EFF'}], {offset: 1, color: '#9F6EFF'}],
...@@ -75,8 +87,9 @@ export default { ...@@ -75,8 +87,9 @@ export default {
methods: { methods: {
async getUserPortraitData() { async getUserPortraitData() {
// 44209572 // 44209572
const merchantId = this.$globalState.session.merchantId
// this.$globalState.session.merchantId // this.$globalState.session.merchantId
await this.$apis.userPortrait.getPortraitData({merchantId:this.$globalState.session.merchantId}).then(res => { await this.$apis.userPortrait.getPortraitData({merchantId}).then(res => {
for (const key in res) { for (const key in res) {
if (this.hasOwnProperty(key)) { if (this.hasOwnProperty(key)) {
this[key] = res[key] this[key] = res[key]
...@@ -113,9 +126,10 @@ export default { ...@@ -113,9 +126,10 @@ export default {
width: 69vw; width: 69vw;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
gap: 20px; gap: 20px;
background-color: #fff; background-color: #fff;
padding: 10px; padding: 10px;
overflow-y: auto; // 添加这一行来实现滚动
max-height: 89.5vh; // 可以设置一个最大高度,超过这个高度将显示滚动条
} }
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!