<template>
|
<view>
|
<header-bar title="数据统计" :isBack="true" @click="back"></header-bar>
|
<view class="content">
|
<!-- 数据概览 -->
|
<view class="overview-section">
|
<view class="overview-item">
|
<view class="number">{{totalViews}}</view>
|
<view class="label">总浏览量</view>
|
</view>
|
<view class="overview-item">
|
<view class="number">{{totalSaves}}</view>
|
<view class="label">总保存量</view>
|
</view>
|
<view class="overview-item">
|
<view class="number">{{totalShares}}</view>
|
<view class="label">总分享量</view>
|
</view>
|
</view>
|
|
<!-- 趋势图表区域 -->
|
<view class="chart-section">
|
<view class="chart-header">
|
<view class="chart-title">数据趋势</view>
|
<view class="chart-tabs">
|
<view class="tab" :class="{active: timeRange === 'week'}" @click="setTimeRange('week')">周</view>
|
<view class="tab" :class="{active: timeRange === 'month'}" @click="setTimeRange('month')">月</view>
|
<view class="tab" :class="{active: timeRange === 'year'}" @click="setTimeRange('year')">年</view>
|
</view>
|
</view>
|
<view class="chart-content">
|
<!-- 这里可以集成图表组件,如echarts等 -->
|
<view class="chart-placeholder" v-if="!chartData.length">
|
<text>暂无数据</text>
|
</view>
|
<view class="chart-list" v-else>
|
<view class="chart-item" v-for="(item, index) in chartData" :key="index">
|
<view class="chart-bar">
|
<view class="bar" :style="{height: getBarHeight(item.views)}">
|
<view class="bar-value">{{item.views}}</view>
|
</view>
|
</view>
|
<view class="chart-label">{{item.date}}</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
|
<!-- 详细统计数据 -->
|
<view class="detail-section">
|
<view class="section-title">详细统计</view>
|
|
<!-- 访问来源 -->
|
<view class="stat-card">
|
<view class="card-title">访问来源</view>
|
<view class="source-list">
|
<view class="source-item" v-for="(source, index) in visitSources" :key="index">
|
<view class="source-name">{{source.name}}</view>
|
<view class="source-value">{{source.value}}次</view>
|
<view class="source-progress">
|
<view class="progress-bar" :style="{width: source.percentage + '%'}"></view>
|
</view>
|
</view>
|
</view>
|
</view>
|
|
<!-- 地域分布 -->
|
<view class="stat-card">
|
<view class="card-title">地域分布</view>
|
<view class="region-list">
|
<view class="region-item" v-for="(region, index) in regions" :key="index">
|
<view class="region-name">{{region.name}}</view>
|
<view class="region-value">{{region.value}}人</view>
|
</view>
|
</view>
|
</view>
|
|
<!-- 名片效果对比 -->
|
<view class="stat-card" v-if="cardComparison.length > 1">
|
<view class="card-title">名片效果对比</view>
|
<view class="comparison-list">
|
<view class="comparison-item" v-for="(card, index) in cardComparison" :key="index">
|
<view class="comparison-header">
|
<view class="card-name">{{card.name}}</view>
|
<view class="card-view">
|
<text class="icon iconfont icon-eye"></text>
|
<text>{{card.views}}次</text>
|
</view>
|
</view>
|
<view class="comparison-details">
|
<view class="detail">
|
<text>保存率</text>
|
<text class="rate">{{card.saveRate}}%</text>
|
</view>
|
<view class="detail">
|
<text>分享率</text>
|
<text class="rate">{{card.shareRate}}%</text>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
timeRange: 'week', // week, month, year
|
totalViews: 0,
|
totalSaves: 0,
|
totalShares: 0,
|
chartData: [],
|
visitSources: [],
|
regions: [],
|
cardComparison: [],
|
currentCardId: ''
|
};
|
},
|
onLoad(options) {
|
if (options.current) {
|
this.currentCardId = options.current;
|
}
|
this.getData();
|
},
|
methods: {
|
back() {
|
uni.navigateBack();
|
},
|
// 获取所有统计数据
|
getData() {
|
this.getOverview();
|
this.getChartData();
|
this.getDetailedStats();
|
},
|
// 获取概览数据
|
getOverview() {
|
let _this = this;
|
const params = {};
|
if (_this.currentCardId) {
|
params.business_card_id = _this.currentCardId;
|
}
|
_this._post('plus.business.business/getOverview', params, function(res) {
|
_this.totalViews = res.data.views || 0;
|
_this.totalSaves = res.data.saves || 0;
|
_this.totalShares = res.data.shares || 0;
|
});
|
},
|
// 获取图表数据
|
getChartData() {
|
let _this = this;
|
_this._post('plus.business.business/getChartData', {
|
timeRange: _this.timeRange,
|
business_card_id: _this.currentCardId
|
}, function(res) {
|
_this.chartData = res.data || [];
|
});
|
},
|
// 获取详细统计
|
getDetailedStats() {
|
let _this = this;
|
const params = {
|
business_card_id: _this.currentCardId
|
};
|
|
// 获取访问来源
|
_this._post('plus.business.business/getVisitSources', params, function(res) {
|
_this.visitSources = res.data || [];
|
});
|
|
// 获取地域分布
|
_this._post('plus.business.business/getRegions', params, function(res) {
|
_this.regions = res.data || [];
|
});
|
|
// 获取名片对比数据
|
_this._post('plus.business.business/getCardComparison', {}, function(res) {
|
_this.cardComparison = res.data || [];
|
});
|
},
|
// 设置时间范围
|
setTimeRange(range) {
|
this.timeRange = range;
|
this.getChartData();
|
},
|
// 获取柱状图高度
|
getBarHeight(value) {
|
// 简单计算柱状图高度,实际项目中可能需要更复杂的计算
|
const maxValue = Math.max(...this.chartData.map(item => item.views));
|
if (maxValue === 0) return '0%';
|
const height = (value / maxValue) * 100;
|
return Math.max(height, 10) + '%'; // 最小高度为10%
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
.content {
|
padding: 20rpx;
|
}
|
|
.overview-section {
|
display: flex;
|
background: #fff;
|
border-radius: 20rpx;
|
padding: 30rpx 0;
|
margin-bottom: 20rpx;
|
|
.overview-item {
|
flex: 1;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
|
.number {
|
font-size: 48rpx;
|
font-weight: bold;
|
color: #37bde6;
|
margin-bottom: 10rpx;
|
}
|
|
.label {
|
font-size: 28rpx;
|
color: #666;
|
}
|
}
|
}
|
|
.chart-section {
|
background: #fff;
|
border-radius: 20rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
|
.chart-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 30rpx;
|
|
.chart-title {
|
font-size: 32rpx;
|
font-weight: bold;
|
color: #333;
|
}
|
|
.chart-tabs {
|
display: flex;
|
|
.tab {
|
padding: 8rpx 20rpx;
|
margin-left: 10rpx;
|
font-size: 26rpx;
|
color: #666;
|
border-radius: 20rpx;
|
|
&.active {
|
background: #37bde6;
|
color: #fff;
|
}
|
}
|
}
|
}
|
|
.chart-placeholder {
|
height: 300rpx;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
color: #999;
|
font-size: 28rpx;
|
}
|
|
.chart-list {
|
display: flex;
|
align-items: flex-end;
|
justify-content: space-between;
|
height: 300rpx;
|
padding: 20rpx 0;
|
|
.chart-item {
|
flex: 1;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
|
.chart-bar {
|
flex: 1;
|
display: flex;
|
align-items: flex-end;
|
width: 60rpx;
|
|
.bar {
|
background: linear-gradient(to top, #37bde6, #44bbff);
|
width: 100%;
|
border-radius: 6rpx 6rpx 0 0;
|
display: flex;
|
align-items: flex-start;
|
justify-content: center;
|
padding-top: 10rpx;
|
|
.bar-value {
|
font-size: 22rpx;
|
color: #666;
|
}
|
}
|
}
|
|
.chart-label {
|
font-size: 22rpx;
|
color: #999;
|
margin-top: 10rpx;
|
transform: rotate(-45deg);
|
white-space: nowrap;
|
}
|
}
|
}
|
}
|
|
.detail-section {
|
.section-title {
|
font-size: 32rpx;
|
font-weight: bold;
|
color: #333;
|
margin-bottom: 20rpx;
|
}
|
|
.stat-card {
|
background: #fff;
|
border-radius: 20rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
|
.card-title {
|
font-size: 28rpx;
|
font-weight: bold;
|
color: #666;
|
margin-bottom: 20rpx;
|
}
|
|
.source-list,
|
.region-list {
|
.source-item,
|
.region-item {
|
margin-bottom: 20rpx;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
|
.source-name,
|
.region-name {
|
font-size: 28rpx;
|
color: #333;
|
margin-bottom: 10rpx;
|
}
|
|
.source-value,
|
.region-value {
|
font-size: 26rpx;
|
color: #999;
|
margin-bottom: 10rpx;
|
}
|
|
.source-progress {
|
height: 12rpx;
|
background: #f0f0f0;
|
border-radius: 6rpx;
|
|
.progress-bar {
|
height: 100%;
|
background: #37bde6;
|
border-radius: 6rpx;
|
}
|
}
|
}
|
}
|
|
.comparison-list {
|
.comparison-item {
|
padding: 20rpx;
|
background: #f5f5f5;
|
border-radius: 10rpx;
|
margin-bottom: 20rpx;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
|
.comparison-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 15rpx;
|
|
.card-name {
|
font-size: 30rpx;
|
font-weight: bold;
|
color: #333;
|
}
|
|
.card-view {
|
display: flex;
|
align-items: center;
|
font-size: 26rpx;
|
color: #666;
|
|
.icon {
|
margin-right: 8rpx;
|
}
|
}
|
}
|
|
.comparison-details {
|
display: flex;
|
|
.detail {
|
margin-right: 40rpx;
|
font-size: 26rpx;
|
color: #666;
|
|
.rate {
|
margin-left: 10rpx;
|
color: #37bde6;
|
font-weight: bold;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
</style>
|