首页细节调整

This commit is contained in:
2026-02-06 16:18:04 +08:00
parent d00f0b7412
commit 57846534bc
86 changed files with 2751 additions and 3074 deletions

View File

@@ -1,8 +1,8 @@
<template>
<template>
<view class="page" @click.self="closeMoreMenu">
<!-- 鍥哄畾椤堕儴瀵艰埅鏍?-->
<!-- 固定顶部导航栏 -->
<AnalyticsTopBar
:title="'浼樻儬鍒告晥鏋滃垎鏋?"
:title="'优惠券效果分析'"
:lastUpdateTime="lastUpdateTime"
:sidebarVisible="showSidebarMenu"
@menu-click="handleMenu"
@@ -16,18 +16,18 @@
/>
<view class="page-layout">
<!-- 渚ц竟鏍忚彍鍗曠粍浠?-->
<!-- 侧边栏菜单组件 -->
<AnalyticsSidebarMenu
:visible="showSidebarMenu"
:currentPath="currentPath"
@visible-change="handleSidebarUpdate"
/>
<!-- 涓诲唴瀹瑰尯鍩?-->
<!-- 主内容区域 -->
<view class="main-content">
<view class="container">
<!-- 鏃堕棿缁村害绛涢€夛紙蹇嵎 + 鑷畾涔夛級 -->
<!-- 时间维度筛选(快捷 + 自定义) -->
<view class="tabs">
<view
v-for="p in timePeriods"
@@ -43,7 +43,8 @@
:class="{ active: customRangeEnabled }"
@click="toggleCustomRange"
>
鑷畾涔? </view>
自定义
</view>
</view>
<AnalyticsDateRangePicker
@@ -54,67 +55,67 @@
@clear="onDateRangeClear"
/>
<!-- KPI 鎸囨爣鍗$墖 -->
<!-- KPI 指标卡片 -->
<view class="kpi-grid">
<view class="kpi-card">
<text class="kpi-label">鍙戞斁鎬绘暟</text>
<text class="kpi-label">发放总数</text>
<text class="kpi-value">{{ formatInt(couponData.total_issued) }}</text>
<text class="kpi-meta">杈冧笂鏈燂細{{ formatPct(couponData.issued_growth) }}</text>
<text class="kpi-meta">较上期:{{ formatPct(couponData.issued_growth) }}</text>
</view>
<view class="kpi-card">
<text class="kpi-label">浣跨敤鏁伴噺</text>
<text class="kpi-label">使用数量</text>
<text class="kpi-value">{{ formatInt(couponData.total_used) }}</text>
<text class="kpi-meta">浣跨敤鐜囷細{{ formatPct(couponData.usage_rate) }}</text>
<text class="kpi-meta">使用率:{{ formatPct(couponData.usage_rate) }}</text>
</view>
<view class="kpi-card">
<text class="kpi-label">GMV 鎻愬崌</text>
<text class="kpi-value">{{ formatMoney(couponData.gmv_increase) }}</text>
<text class="kpi-meta">杈冧笂鏈燂細{{ formatPct(couponData.gmv_growth) }}</text>
<text class="kpi-label">GMV 提升</text>
<text class="kpi-value">¥{{ formatMoney(couponData.gmv_increase) }}</text>
<text class="kpi-meta">较上期:{{ formatPct(couponData.gmv_growth) }}</text>
</view>
<view class="kpi-card">
<text class="kpi-label">ROI</text>
<text class="kpi-value">{{ formatPct(couponData.roi) }}</text>
<text class="kpi-meta">鎶曞叆浜у嚭姣?/text>
<text class="kpi-meta">投入产出比</text>
</view>
</view>
<!-- 浼樻儬鍒哥被鍨嬪垎鏋?-->
<!-- 优惠券类型分析 -->
<view class="card card-full">
<view class="card-head">
<text class="card-title">浼樻儬鍒哥被鍨嬪垎鏋?/text>
<text class="card-desc">8绉嶅埜绫诲瀷锛氭弧鍑忓埜銆佹姌鎵e埜銆佸厤杩愯垂鍒搞€佹柊浜哄埜銆佷細鍛樺埜銆佸搧绫诲埜銆佸晢瀹跺埜銆侀檺鏃跺埜</text>
<text class="card-title">优惠券类型分析</text>
<text class="card-desc">8种券类型:满减券、折扣券、免运费券、新人券、会员券、品类券、商家券、限时券</text>
</view>
<EChartsView class="chart-box" :option="typeChartOption" />
</view>
<!-- 鍙戞斁娓犻亾鏁堟灉 -->
<!-- 发放渠道效果 -->
<view class="card">
<view class="card-head">
<text class="card-title">鍙戞斁娓犻亾鏁堟灉</text>
<text class="card-desc">涓诲姩棰嗗彇銆佽嚜鍔ㄥ彂鏀俱€佹椿鍔ㄨ禒閫併€侀個璇峰鍔便€佸鏈嶈禒閫併€佺Н鍒嗗厬鎹?/text>
<text class="card-title">发放渠道效果</text>
<text class="card-desc">主动领取、自动发放、活动赠送、邀请奖励、客服赠送、积分兑换</text>
</view>
<EChartsView class="chart-box" :option="channelChartOption" />
</view>
<!-- 浼樻儬鍒镐娇鐢ㄨ秼鍔?-->
<!-- 优惠券使用趋势 -->
<view class="card">
<view class="card-head">
<text class="card-title">浼樻儬鍒镐娇鐢ㄨ秼鍔?/text>
<text class="card-desc">{{ selectedPeriodText }} 路 鍙戞斁 vs 浣跨敤</text>
<text class="card-title">优惠券使用趋势</text>
<text class="card-desc">{{ selectedPeriodText }} · 发放 vs 使用</text>
</view>
<EChartsView class="chart-box" :option="trendChartOption" />
</view>
<!-- 浼樻儬鍒歌浆鍖栨晥鏋?-->
<!-- 优惠券转化效果 -->
<view class="card card-full">
<view class="card-head">
<text class="card-title">浼樻儬鍒歌浆鍖栨晥鏋?/text>
<text class="card-desc">GMV鎻愬崌銆佽鍗曞闀?/text>
<text class="card-title">优惠券转化效果</text>
<text class="card-desc">GMV提升、订单增长</text>
</view>
<EChartsView class="chart-box" :option="conversionChartOption" />
</view>
<!-- 鐣欑櫧 -->
<!-- 留白 -->
<view style="height: 24px;"></view>
</view>
</view>
@@ -146,10 +147,10 @@ const showSidebarMenu = ref(false)
const currentPath = ref('/pages/mall/analytics/coupon-analysis')
const timePeriods = ref<Array<TimePeriod>>([
{ value: '7d', label: '7澶? },
{ value: '30d', label: '30澶? },
{ value: '90d', label: '90澶? },
{ value: '1y', label: '1骞? }
{ value: '7d', label: '7天' },
{ value: '30d', label: '30天' },
{ value: '90d', label: '90天' },
{ value: '1y', label: '1年' }
])
const couponData = ref<CouponData>({
@@ -167,7 +168,7 @@ const channelChartOption = ref({} as any)
const trendChartOption = ref({} as any)
const conversionChartOption = ref({} as any)
// 鍘熷鏁版嵁
// 原始数据
const _typeRows = ref<Array<UTSJSONObject>>([])
const _channelRows = ref<Array<UTSJSONObject>>([])
const _trendRows = ref<Array<UTSJSONObject>>([])
@@ -175,7 +176,7 @@ const _conversionRows = ref<Array<UTSJSONObject>>([])
const selectedPeriodText = computed(() => {
const p = timePeriods.value.find((t) => t.value === selectedPeriod.value)
return p ? p.label : '7澶?
return p ? p.label : '7天'
})
onLoad(() => {
@@ -245,7 +246,7 @@ async function loadCouponData() {
console.error('loadCouponData failed:', e)
updateTime()
buildChartOptions()
uni.showToast({ title: mapAnalyticsError(e, { fallbackMessage: '浼樻儬鍒稿垎鏋愭暟鎹姞杞藉け璐? }), icon: 'none' })
uni.showToast({ title: mapAnalyticsError(e, { fallbackMessage: '优惠券分析数据加载失败' }), icon: 'none' })
}
}
@@ -277,13 +278,13 @@ function onDateRangeClear() {
function refreshData() {
loadCouponData()
uni.showToast({ title: '宸插埛鏂?, icon: 'success' })
uni.showToast({ title: '已刷新', icon: 'success' })
}
function exportReport() {
uni.showActionSheet({
itemList: ['瀵煎嚭Excel', '瀵煎嚭PDF', '瀵煎嚭鍥剧墖'],
success: () => uni.showToast({ title: '瀵煎嚭鎴愬姛', icon: 'success' })
itemList: ['导出Excel', '导出PDF', '导出图片'],
success: () => uni.showToast({ title: '导出成功', icon: 'success' })
})
}
@@ -296,13 +297,13 @@ function updateTime() {
function formatInt(n: number): string {
const v = isFinite(n) ? Math.round(n) : 0
if (v >= 10000) return (v / 10000).toFixed(1) + '涓?
if (v >= 10000) return (v / 10000).toFixed(1) + '万'
return v.toString()
}
function formatMoney(n: number): string {
const v = isFinite(n) ? n : 0
if (v >= 10000) return (v / 10000).toFixed(1) + '涓?
if (v >= 10000) return (v / 10000).toFixed(1) + '万'
return v.toFixed(0)
}
@@ -318,7 +319,8 @@ function buildChartOptions() {
const trendRows = _trendRows.value
const convRows = _conversionRows.value
// 1) 鍒哥被鍨嬪垎鏋? const typeNames: string[] = []
// 1) 券类型分析
const typeNames: string[] = []
const typeIssued: number[] = []
const typeUsed: number[] = []
const typeUsageRate: number[] = []
@@ -326,15 +328,15 @@ function buildChartOptions() {
for (let i = 0; i < typeRows.length; i++) {
const r = typeRows[i]
const t = r.getNumber('coupon_type') ?? 0
let label = '鏈煡'
if (t === 1) label = '婊″噺鍒?
else if (t === 2) label = '鎶樻墸鍒?
else if (t === 3) label = '鍏嶈繍璐瑰埜'
else if (t === 4) label = '鏂颁汉鍒?
else if (t === 5) label = '浼氬憳鍒?
else if (t === 6) label = '鍝佺被鍒?
else if (t === 7) label = '鍟嗗鍒?
else if (t === 8) label = '闄愭椂鍒?
let label = '未知'
if (t === 1) label = '满减券'
else if (t === 2) label = '折扣券'
else if (t === 3) label = '免运费券'
else if (t === 4) label = '新人券'
else if (t === 5) label = '会员券'
else if (t === 6) label = '品类券'
else if (t === 7) label = '商家券'
else if (t === 8) label = '限时券'
typeNames.push(label)
typeIssued.push(r.getNumber('total_issued') ?? 0)
typeUsed.push(r.getNumber('total_used') ?? 0)
@@ -344,7 +346,7 @@ function buildChartOptions() {
typeChartOption.value = {
tooltip: { trigger: 'axis' },
legend: {
data: ['鍙戞斁鏁伴噺', '浣跨敤鏁伴噺', '浣跨敤鐜?],
data: ['发放数量', '使用数量', '使用率'],
top: 'bottom'
},
grid: { left: 40, right: 40, top: 40, bottom: 60 },
@@ -354,26 +356,26 @@ function buildChartOptions() {
axisLabel: { interval: 0, rotate: 20 }
},
yAxis: [
{ type: 'value', name: '鏁伴噺' },
{ type: 'value', name: '浣跨敤鐜?, min: 0, max: 100, position: 'right' }
{ type: 'value', name: '数量' },
{ type: 'value', name: '使用率', min: 0, max: 100, position: 'right' }
],
series: [
{
name: '鍙戞斁鏁伴噺',
name: '发放数量',
type: 'bar',
data: typeIssued,
barMaxWidth: 22,
itemStyle: { color: '#3b82f6' }
},
{
name: '浣跨敤鏁伴噺',
name: '使用数量',
type: 'bar',
data: typeUsed,
barMaxWidth: 22,
itemStyle: { color: '#22c55e' }
},
{
name: '浣跨敤鐜?,
name: '使用率',
type: 'line',
yAxisIndex: 1,
smooth: true,
@@ -387,7 +389,7 @@ function buildChartOptions() {
]
}
// 2) 鍙戞斁娓犻亾鏁堟灉
// 2) 发放渠道效果
const channelNames: string[] = []
const channelIssued: number[] = []
const channelUsed: number[] = []
@@ -396,13 +398,13 @@ function buildChartOptions() {
const r = channelRows[i]
const ch = r.getString('channel') ?? ''
let chLabel = ch
if (ch === 'manual') chLabel = '涓诲姩棰嗗彇'
else if (ch === 'auto') chLabel = '鑷姩鍙戞斁'
else if (ch === 'campaign') chLabel = '娲诲姩璧犻€?
else if (ch === 'invite') chLabel = '閭€璇峰鍔?
else if (ch === 'cs') chLabel = '瀹㈡湇璧犻€?
else if (ch === 'points') chLabel = '绉垎鍏戞崲'
else if (ch.trim() === '') chLabel = '鏈煡'
if (ch === 'manual') chLabel = '主动领取'
else if (ch === 'auto') chLabel = '自动发放'
else if (ch === 'campaign') chLabel = '活动赠送'
else if (ch === 'invite') chLabel = '邀请奖励'
else if (ch === 'cs') chLabel = '客服赠送'
else if (ch === 'points') chLabel = '积分兑换'
else if (ch.trim() === '') chLabel = '未知'
channelNames.push(chLabel)
channelIssued.push(r.getNumber('total_issued') ?? 0)
channelUsed.push(r.getNumber('total_used') ?? 0)
@@ -410,17 +412,17 @@ function buildChartOptions() {
channelChartOption.value = {
tooltip: { trigger: 'axis' },
legend: { data: ['鍙戞斁鏁伴噺', '浣跨敤鏁伴噺'], top: 'bottom' },
legend: { data: ['发放数量', '使用数量'], top: 'bottom' },
grid: { left: 80, right: 30, top: 20, bottom: 60 },
xAxis: { type: 'value' },
yAxis: { type: 'category', data: channelNames },
series: [
{ name: '鍙戞斁鏁伴噺', type: 'bar', data: channelIssued },
{ name: '浣跨敤鏁伴噺', type: 'bar', data: channelUsed }
{ name: '发放数量', type: 'bar', data: channelIssued },
{ name: '使用数量', type: 'bar', data: channelUsed }
]
}
// 3) 浣跨敤瓒嬪娍
// 3) 使用趋势
const trendDays: string[] = []
const trendIssued: number[] = []
const trendUsed: number[] = []
@@ -435,17 +437,17 @@ function buildChartOptions() {
trendChartOption.value = {
tooltip: { trigger: 'axis' },
legend: { data: ['鍙戞斁鏁伴噺', '浣跨敤鏁伴噺'], top: 'bottom' },
legend: { data: ['发放数量', '使用数量'], top: 'bottom' },
grid: { left: 40, right: 20, top: 40, bottom: 60 },
xAxis: { type: 'category', data: trendDays },
yAxis: { type: 'value', name: '鏁伴噺' },
yAxis: { type: 'value', name: '数量' },
series: [
{ name: '鍙戞斁鏁伴噺', type: 'bar', data: trendIssued },
{ name: '浣跨敤鏁伴噺', type: 'line', smooth: true, data: trendUsed }
{ name: '发放数量', type: 'bar', data: trendIssued },
{ name: '使用数量', type: 'line', smooth: true, data: trendUsed }
]
}
// 4) 杞寲鏁堟灉
// 4) 转化效果
const convNames: string[] = []
const convWith: number[] = []
const convWithout: number[] = []
@@ -454,10 +456,10 @@ function buildChartOptions() {
const r = convRows[i]
const metric = r.getString('metric') ?? ''
let metricLabel = metric
if (metric === 'GMV') metricLabel = 'GMV锛堟垚浜ら锛?
else if (metric === 'orders') metricLabel = '璁㈠崟鏁?
else if (metric === 'avg_order_amount') metricLabel = '瀹㈠崟浠?
else if (metric.trim() === '') metricLabel = '鏈煡'
if (metric === 'GMV') metricLabel = 'GMV(成交额)'
else if (metric === 'orders') metricLabel = '订单数'
else if (metric === 'avg_order_amount') metricLabel = '客单价'
else if (metric.trim() === '') metricLabel = '未知'
convNames.push(metricLabel)
convWith.push(r.getNumber('with_coupon') ?? 0)
convWithout.push(r.getNumber('without_coupon') ?? 0)
@@ -465,13 +467,13 @@ function buildChartOptions() {
conversionChartOption.value = {
tooltip: { trigger: 'axis' },
legend: { data: ['浣跨敤浼樻儬鍒?, '鏈娇鐢ㄤ紭鎯犲埜'], top: 'bottom' },
legend: { data: ['使用优惠券', '未使用优惠券'], top: 'bottom' },
grid: { left: 40, right: 20, top: 20, bottom: 60 },
xAxis: { type: 'category', data: convNames },
yAxis: { type: 'value' },
series: [
{ name: '浣跨敤浼樻儬鍒?, type: 'bar', data: convWith },
{ name: '鏈娇鐢ㄤ紭鎯犲埜', type: 'bar', data: convWithout }
{ name: '使用优惠券', type: 'bar', data: convWith },
{ name: '未使用优惠券', type: 'bar', data: convWithout }
]
}
}
@@ -492,13 +494,13 @@ function handleMenu() {
showSidebarMenu.value = true
}
// 妯℃嫙鐨?TopBar 浜嬩欢澶勭悊
function handleSearch() { uni.showToast({ title: '鎼滅储', icon: 'none' }) }
function handleNotification() { uni.showToast({ title: '閫氱煡', icon: 'none' }) }
function handleFullscreen() { uni.showToast({ title: '鍏ㄥ睆', icon: 'none' }) }
function handleMobile() { uni.showToast({ title: '绉诲姩绔?, icon: 'none' }) }
function handleDropdown() { uni.showToast({ title: '涓嬫媺鑿滃崟', icon: 'none' }) }
function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' }) }
// 模拟的 TopBar 事件处理
function handleSearch() { uni.showToast({ title: '搜索', icon: 'none' }) }
function handleNotification() { uni.showToast({ title: '通知', icon: 'none' }) }
function handleFullscreen() { uni.showToast({ title: '全屏', icon: 'none' }) }
function handleMobile() { uni.showToast({ title: '移动端', icon: 'none' }) }
function handleDropdown() { uni.showToast({ title: '下拉菜单', icon: 'none' }) }
function handleSettings() { uni.showToast({ title: '设置', icon: 'none' }) }
</script>
@@ -508,7 +510,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
background: #f6f7fb;
}
/* 椤甸潰甯冨眬锛氬灞忔椂渚ц竟鏍?鍐呭锛岀獎灞忔椂鍏ㄥ睆鍐呭 */
/* 页面布局:宽屏时侧边栏+内容,窄屏时全屏内容 */
.page-layout {
display: flex;
flex-direction: row !important;
@@ -520,18 +522,18 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
min-width: 0;
display: flex;
flex-direction: column;
padding-top: 64px; /* 涓哄浐瀹氶《閮ㄥ鑸爮鐣欏嚭绌洪棿 */
padding-top: 64px; /* 为固定顶部导航栏留出空间 */
}
.container {
width: 100%;
max-width: 1280px;
margin: 0 auto;
/* padding removed */ 16px 28px;
padding: 16px 16px 28px;
box-sizing: border-box;
}
/* 椤堕儴鏍?*/
/* 顶部栏 */
.topbar {
display: flex;
flex-direction: row !important;
@@ -664,7 +666,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
color: #111;
}
/* 鏃堕棿缁村害 tabs */
/* 时间维度 tabs */
.tabs {
margin-top: 12px;
display: flex;
@@ -694,7 +696,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
color: #fff;
}
/* KPI 缃戞牸 */
/* KPI 网格 */
.kpi-grid {
margin-top: 12px;
display: flex;
@@ -731,7 +733,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
color: rgba(0,0,0,0.55);
}
/* 鍗$墖 */
/* 卡片 */
.card {
margin-top: 12px;
background: #fff;
@@ -770,7 +772,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
height: 360px;
}
/* 鍝嶅簲寮?*/
/* 响应式 */
@media screen and (min-width: 960px) {
.kpi-card {
flex: 1 1 calc(25% - 9px);
@@ -778,7 +780,7 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
}
}
/* 鍝嶅簲寮忥細绐勫睆鏃跺叏灞忔樉绀?*/
/* 响应式:窄屏时全屏显示 */
@media screen and (max-width: 959px) {
.page-layout {
flex-direction: column !important;
@@ -804,4 +806,3 @@ function handleSettings() { uni.showToast({ title: '璁剧疆', icon: 'none' })
}
}
</style>