Commit d3de9184 by 前端

1

1 parent ace13144
/*
*/
import {
http3,
http
} from '@/main'
const getPortraitData = (params)=> {
params.method = 'entmicro.api.customer.portrait.view'
return http3({
url: '/rop-scrm-entmicro/router',
method: 'POST',
data: params,
sign: true
})
}
export default {
getPortraitData
}
......@@ -218,3 +218,14 @@
.headPortrait {
vertical-align: middle;
}
.line-color-title{
width: 403px;
height: 36px;
line-height: 36px;
background-image: linear-gradient(90deg, #F2F2FF 0%, #f0f6fe75 54%, #f8fbff00 100%);
border-radius: 15px;
font-weight: 600;
font-size: 16px;
padding-left: 16px;
}
......@@ -18,7 +18,7 @@ export const fetchConfig = function(isEnv = true) {
return Promise.resolve(cfg)
}
return new Http({ request: { timeout: 3000 } }).get('https://oss-config.test.glsx.com.cn/mock/616d3b131072f92988f05a01/custom/config2')
return new Http({ request: { timeout: 3000 } }).get('https://oss-config.dev.glsx.com.cn/mock/616d3b131072f92988f05a01/custom/config2')
//开发环境mock
// return new Http({ request: { timeout: 3000 } }).get('http://192.168.3.171:7300/mock/616d3b131072f92988f05a01/custom/config2')
}
......
<template>
<div class="bar-chart">
<p class="line-color-title">{{title}}</p>
<div ref="barChart" style="width: 100%; height: 30vh;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixin/resize'
export default {
name: "BarChart",
mixins:[resize],
props: {
title:{
type: String,
default: '',
},
data: {
type: Array,
required: true
},
colors: {
type: Array,
default: () => [
['#6E77FF', '#A1D9FF'], // 渐变色1
['#90D55C', '#FDDB93'], // 渐变色2
]
}
},
watch: {
data: 'drawChart',
colors: 'drawChart'
},
mounted() {
this.initChart(this.$refs.barChart);
this.drawChart();
},
methods: {
drawChart() {
const chart = echarts.init(this.$refs.barChart);
const option = {
xAxis: {
type: 'category',
data: this.data.map(item => item.name),
axisTick: { show: false },
axisLine: { show: false },
axisLabel: {
interval: 0,
rotate: 45
}
},
yAxis: {
type: 'value',
axisTick: { show: false },
axisLine: { show: false },
splitLine: { show: false },
// axisLabel: { show: false }
},
series: [{
data: this.data.map(item => item.value),
type: 'bar',
barWidth: '20%',
label: {
show: true,
position: 'top'
},
itemStyle: {
color: (params) => {
const dataIndex = params.dataIndex
const gradientIndex = Math.floor(dataIndex%2)
return {
type: 'linear',
colorStops: [
{ offset: 0, color: this.colors[gradientIndex][0] },
{ offset: 1, color: this.colors[gradientIndex][1] },
],
globalCoord: false,
x: 0, // 渐变的起始点横坐标
y: 0, // 渐变的起始点纵坐标
x2: 0, // 渐变的结束点横坐标
y2: 1, // 渐变的结束点纵坐标(设置为1表示从上到下
};
},
barBorderRadius: 5
}
// itemStyle: {
// color: (params) => {
// return this.colors[params.dataIndex % this.colors.length];
// },
// barBorderRadius: 5
// }
}]
};
chart.setOption(option);
}
}
};
</script>
<style lang="scss">
#chart {
width: 100%;
height: 400px;
}
</style>
<template>
<div class="horizontal-bar">
<p class="title">{{ title }}</p>
<div ref="horizontalBarChart" style="width: 100%; height: 20vh;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixin/resize'
export default {
name: 'HorizontalBarChart',
mixins: [resize],
props: {
title: {
type: String,
default: '',
},
data: {
type: Array,
default: () => [
{name: '<20岁', value: 4},
{name: '20–30岁', value: 10},
{name: '30–40岁', value: 25},
{name: '40–50岁', value: 30},
{name: '50–60岁', value: 20},
{name: '60–70岁', value: 10},
{name: '≥70岁', value: 1},
],
},
colors: {
type: Array,
default: () => [],
},
},
mounted() {
this.initChart(this.$refs.horizontalBarChart);
this.drawChart();
},
methods: {
drawChart() {
const chart = echarts.init(this.$refs.horizontalBarChart);
const option = {
tooltip: {
// trigger: 'axis',
// axisPointer: {
// type: 'shadow',
// },
show: false
},
grid: {
top: '5%',
left: '6%',
right: '8%',
bottom: '3%',
containLabel: true,
},
xAxis: {
type: 'value',
axisTick: {show: false},
splitLine: {show: false}, // 去掉背景的竖线
axisLabel: { show: false }
},
yAxis: {
type: 'category',
data: this.data.map(item => item.name),
axisTick: {show: false}, // 去掉y轴刻度
axisLine: {show: false},
axisLabel: {
textStyle:{
padding:[0,20,0,0]
}
}
},
series: [
{
// name: '年龄分布',
type: 'bar',
data: this.data.map(item => item.value),
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0, // 渐变方向从左到右
this.colors
),
barBorderRadius: 4
},
label: {
show: true,
position: 'right',
valueAnimation: true,
formatter: (params) => `${params.value}%` // 在柱状图右边展示x轴的数据和名称
}
},
],
};
chart.setOption(option);
},
},
};
</script>
<style lang="scss" scoped>
.horizontal-bar {
margin: 2vh 0;
.title {
color: #333333;
font-size: 16px;
font-weight: 600;
}
}
</style>
<template>
<div class="line-chart">
<p class="line-color-title">{{title}}</p>
<div ref="lineChart" style="width: 100%; height:30vh;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixin/resize'
export default {
name: 'LineChart',
mixins:[resize],
props: {
title:{
type: String,
default: '',
},
data: {
type: Array,
default: () => [],
},
gradientColors: {
type: Array,
default: () =>['#A8A4FF', '#F2F1FF']
},
},
mounted() {
this.initChart(this.$refs.lineChart);
this.drawChart();
},
methods: {
drawChart() {
const chart = echarts.init(this.$refs.lineChart);
const option = {
tooltip: {
trigger: 'axis',
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: {
type: 'category',
boundaryGap: false,
axisTick: { show: false },
data: this.data.map(item => item.name),
},
yAxis: {
type: 'value',
},
series: [
{
type: 'line',
data: this.data,
// smooth: true,
symbol: 'circle', // 设置为圆点
symbolSize: 4, // 圆点大小
itemStyle: {
color: '#5850FF',
borderColor: '#0000FF',
borderWidth: 1,
shadowBlur: 8,
shadowOffsetY: 8,
shadowColor: 'rgba(0, 0, 0, 0.2)',
},
areaStyle: {
// 渐变背景
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: this.gradientColors[0] },
{ offset: 1, color: this.gradientColors[1] }
]),
},
},
],
};
chart.setOption(option);
},
},
};
</script>
<style lang="scss" scoped>
.line-chart{
}
</style>
<template>
<div>
<p class="line-color-title">{{title}}</p>
<div ref="pieChart" style="margin-top:10px;width: 100%; height: 20vh;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixin/resize'
export default {
name: 'PieChart',
mixins:[resize],
props: {
title:{
type: String,
default: '',
},
data: {
type: Array,
default: () => [],
},
colors: {
type: Array,
default: () => ['#50CEFB', '#5850FF','#FBBE50','#90D55C','#FDDB93','#A1EDFF','#6EA3FF','#FF5A92','#BCCAFF','#9F6EFF'],
},
},
mounted() {
this.initChart(this.$refs.pieChart);
this.drawChart();
},
methods: {
drawChart() {
const chart = echarts.init(this.$refs.pieChart);
const option = {
tooltip: {
trigger: 'item',
},
legend: {
show: false,
},
series: [
{
type: 'pie',
radius: ['40%', '60%'],
avoidLabelOverlap: false,
label: {
show: true,
position: 'outside',
formatter: function(params) {
return '{a|' + params.value + '%'+ '}'
+'\n'+'\n'+
' {b|' + params.name + '}'
},
rich: {
a: {
color: '#50CEFB',
fontWeight: 'bold',
fontSize:'18px'
},
b: {
color: '#333',
fontSize:'14px',
}
}
},
labelLine: {
show: true
},
data: this.data,
itemStyle: {
color: (params) => {
return this.colors[params.dataIndex];
},
},
},
],
};
chart.setOption(option);
},
},
};
</script>
<style lang="scss">
/* 您可以根据需要添加自定义样式 */
</style>
<template>
<div class="user-stats">
<div class="user male">
<div class="avatar male"></div>
<span>男</span>
<div class="progress">
<div class="fill male" :style="{ width: malePercentage + '%' }">{{ malePercentage || 0 }}%</div>
</div>
<span class="male-count">{{ maleCount }}人</span>
</div>
<div class="user female">
<div class="avatar female"></div>
<span>女</span>
<div class="progress">
<div class="fill female" :style="{ width: femalePercentage + '%' }">{{femalePercentage || 0}}%</div>
</div>
<span class="female-count">{{ femaleCount }}人</span>
</div>
</div>
</template>
<script>
export default {
name: "UserStats",
props:{
maleCount:{
type: String,
default: '',
},
femaleCount:{
type: String,
default: '',
}
},
computed: {
malePercentage() {
return (this.maleCount / (this.maleCount + this.femaleCount)) * 100;
},
femalePercentage() {
return 100 - this.malePercentage;
}
}
};
</script>
<style lang="scss" scoped>
.user-stats {
display: flex;
justify-content: center;
background-image: linear-gradient(180deg, #F5F4FF 0%, #F8FBFF 100%);
border-radius: 2px;
padding: 12px;
.user {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.avatar {
width: 60px;
height: 60px;
border-radius: 50%;
&.male {
background: url('./../../../assets/userPortrait/male.png') center/cover no-repeat;
}
&.female {
background: url('./../../../assets/userPortrait/female.png') center/cover no-repeat;
}
}
.progress {
justify-content: center;
width: 10vw;
height: 2.5vh;
margin: 10px 0;
.fill {
height: 100%;
line-height: 2.5vh;
color: #FFFFFF;
font-size: 14px;
&.male {
margin-left: 3.5vw;
padding-left: 10px;
text-align: left;
background: #5A64FF;
border-top-left-radius: 25px; // 左上角圆角
border-bottom-left-radius: 25px; // 左下角圆角
clip-path: polygon(0 0, 100% 0%, 85% 100%, 0% 100%); // 右侧切面
}
&.female {
padding-right: 10px;
text-align: right;
background: #FF5A92;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
clip-path: polygon(10% 0, 100% 0%, 100% 100%, 0% 100%); // 左侧切面
}
}
}
.male-count{
color: #5A64FF;
font-size: 14px;
text-align: left;
}
.female-count{
color: #FF5A92;
font-size: 14px;
}
}
}
</style>
<template>
<!-- 该页面图表显示的颜色均可通过传入color参数修改-->
<div class="dashboard">
<!-- 用户信息部分 -->
<div class="user-section">
<UserStats :maleCount="findSexCount('男')" :femaleCount="findSexCount('女')"/>
<HorizontalBarChart v-if="ageDistribution" :title="'年龄分布'" :data="ageDistribution" :colors="mockAgeColors"/>
<HorizontalBarChart v-if="eraDistribution" :title="'年代分布'" :data="eraDistribution"
:colors="mockPeriodColors"/>
<HorizontalBarChart v-if="childDistribution" :title="'有无小孩'" :data="childDistribution"
:colors="mockChildColors"/>
</div>
<!-- 图表部分 -->
<div class="charts-section">
<PieChart :title="'客户来源'" v-if="sourceDistribution" :data="sourceDistribution"/>
<PieChart :title="'租住比'" v-if="lodgeDistribution" :data="lodgeDistribution"/>
<PieChart :title="'消费能力'" v-if="consumeDistribution" :data="consumeDistribution"/>
<PieChart :title="'车辆类型'" v-if="vehicleDistribution" :data="vehicleDistribution"/>
<LineChart :title="'浏览时段偏好'" v-if="browseDistribution" :data="browseDistribution"/>
<BarChart :title="'甄选商品偏好(top10)'" v-if="productDistribution" :data="productDistribution"></BarChart>
</div>
</div>
</template>
<script>
import UserStats from './components/UserStats.vue';
import HorizontalBarChart from './components/HorizontalBarChart.vue';
import PieChart from './components/PieChart.vue'
import LineChart from './components/LineChart.vue';
import BarChart from "./components/BarChart";
import {getDataOverview} from '@/api/modules/clientDataOverview'
export default {
components: {
UserStats,
HorizontalBarChart,
PieChart,
LineChart,
BarChart
},
data() {
return {
sexDistribution: null,
ageDistribution: null,
eraDistribution: null,
childDistribution: null,
sourceDistribution: null,
lodgeDistribution: null,
consumeDistribution: null,
vehicleDistribution: null,
browseDistribution: null,
productDistribution: null,
mockAgeColors: [
{offset: 0.02, color: '#BCCAFF'},
{offset: 1, color: '#9F6EFF'}],
mockPeriodColors: [
{offset: 0.02, color: '#A1EDFF'},
{offset: 1, color: '#6EA3FF'}],
mockChildColors: [
{offset: 0.02, color: '#90D55C'},
{offset: 1, color: '#FDDB93'}],
}
},
async created() {
await this.getUserPortraitData()
},
methods: {
async getUserPortraitData() {
// 44209572
// this.$globalState.session.merchantId
await this.$apis.userPortrait.getPortraitData({merchantId:this.$globalState.session.merchantId}).then(res => {
for (const key in res) {
if (this.hasOwnProperty(key)) {
this[key] = res[key]
}
}
})
},
findSexCount(sex) {
const foundItem = this.sexDistribution.find(({name}) => name === sex);
return foundItem ? foundItem.value : 0;
}
}
}
</script>
<style lang="scss" scoped>
.dashboard {
display: grid;
grid-template-columns: 1fr 2.5fr;
gap: 20px;
max-height: 90vh;
width: 100%;
.user-section {
// 样式定义
background: #FFFFFF;
padding: 10px;
width: 23vw;
max-height: 89.5vh;
}
.charts-section {
display: grid;
width: 69vw;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
background-color: #fff;
padding: 10px;
}
}
</style>
export default {
data() {
return {
chartInstance: null
};
},
mounted() {
this.$nextTick(() => {
// 在组件mounted后开始监听resize事件
window.addEventListener('resize', this.handleResize);
});
},
beforeDestroy() {
// 在组件销毁前移除resize事件监听
window.removeEventListener('resize', this.handleResize);
},
methods: {
handleResize() {
// 如果ECharts实例存在,则调用其resize方法
if (this.chartInstance) {
this.chartInstance.resize();
}
},
initChart(chartContainer) {
// 初始化ECharts实例并保存到data中
this.chartInstance = this.$echarts.init(chartContainer);
}
}
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!