feat: 增加贡献图直观展示数据读取情况

This commit is contained in:
2026-08-16 17:37:27 +08:00
parent c35c985eb0
commit 3c0dfc2f77
6 changed files with 444 additions and 22 deletions
@@ -0,0 +1,100 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { AdvertisingCostItem } from '@/types/advertisingCost';
import {
buildHeatmapWeeks,
cellTitle,
monthLabelsForWeeks,
summarizeByDate,
type HeatDayCell,
} from '@/shared/dateHeatmap';
const props = defineProps<{
items: AdvertisingCostItem[];
pageDate?: string;
selectedDate?: string;
}>();
const emit = defineEmits<{
select: [date: string | undefined];
}>();
const WEEKDAY_LABELS = ['', '一', '', '三', '', '五', ''];
const stats = computed(() => summarizeByDate(props.items));
const weeks = computed(() =>
buildHeatmapWeeks({
weeks: 13,
stats: stats.value,
pageDate: props.pageDate,
}),
);
const monthLabelMap = computed(() => {
const map = new Map<number, string>();
for (const item of monthLabelsForWeeks(weeks.value)) {
map.set(item.index, item.label);
}
return map;
});
function onCellClick(cell: HeatDayCell) {
if (!cell.inRange || !cell.stat) return;
emit('select', props.selectedDate === cell.date ? undefined : cell.date);
}
function cellClass(cell: HeatDayCell): string[] {
const classes = [`ecbi-heat-l${cell.level}`];
if (!cell.inRange) classes.push('ecbi-heat-out');
if (cell.isToday) classes.push('ecbi-heat-today');
if (cell.isPageDate) classes.push('ecbi-heat-page');
if (props.selectedDate === cell.date) classes.push('ecbi-heat-selected');
if (cell.stat) classes.push('ecbi-heat-lit');
return classes;
}
</script>
<template>
<div class="ecbi-heat">
<div class="ecbi-heat-head">
<span class="ecbi-heat-title">读取日历</span>
<span class="ecbi-muted">点亮=已读 · 点击筛选当日</span>
</div>
<div class="ecbi-heat-body">
<div class="ecbi-heat-dows">
<span class="ecbi-heat-month-spacer" />
<span v-for="(label, i) in WEEKDAY_LABELS" :key="i" class="ecbi-heat-dow">{{ label }}</span>
</div>
<div class="ecbi-heat-weeks">
<div v-for="(week, wi) in weeks" :key="wi" class="ecbi-heat-week">
<span class="ecbi-heat-month">{{ monthLabelMap.get(wi) || '' }}</span>
<button
v-for="cell in week"
:key="cell.date"
type="button"
class="ecbi-heat-cell"
:class="cellClass(cell)"
:title="cellTitle(cell)"
:disabled="!cell.inRange || !cell.stat"
@click="onCellClick(cell)"
/>
</div>
</div>
</div>
<div class="ecbi-heat-legend">
<span class="ecbi-muted">少</span>
<span class="ecbi-heat-cell ecbi-heat-l0" />
<span class="ecbi-heat-cell ecbi-heat-l1" />
<span class="ecbi-heat-cell ecbi-heat-l2" />
<span class="ecbi-heat-cell ecbi-heat-l3" />
<span class="ecbi-heat-cell ecbi-heat-l4" />
<span class="ecbi-muted">多</span>
<span class="ecbi-heat-gap" />
<span class="ecbi-heat-cell ecbi-heat-l0 ecbi-heat-page" />
<span class="ecbi-muted">当前页日期</span>
</div>
</div>
</template>
@@ -3,6 +3,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue';
import { batchImportPddGoodsAdFee } from '@/api/open/pddGoodsAdFee';
import { listPddChannelShops, type PddChannelShop } from '@/api/open/pddShop';
import DateHeatmap from './DateHeatmap.vue';
import { resolveAdapter } from '@/platform/core/PlatformDetector';
import { matchChannelShopByMallName } from '@/platform/pdd/matchShop';
import { EXTENSION_NAME } from '@/shared/constants';
@@ -24,6 +25,7 @@ const shopsLoading = ref(false);
const pageContext = ref<PageContext | null>(null);
const batch = ref<AdvertisingCostBatch | null>(null);
const filterDate = ref<string | undefined>(undefined);
const statusText = ref('等待读取');
const errorText = ref('');
const syncResultText = ref('');
@@ -41,8 +43,15 @@ const totalFee = computed(() =>
(batch.value?.items ?? []).reduce((sum, item) => sum + Number(item.feeAmount || 0), 0),
);
const itemCount = computed(() => batch.value?.items.length ?? 0);
const accumulatedDates = computed(() => listFeeDates(batch.value?.items ?? []));
const dateCount = computed(() => accumulatedDates.value.length);
const dateCount = computed(() => listFeeDates(batch.value?.items ?? []).length);
const previewItems = computed(() => {
const items = batch.value?.items ?? [];
if (!filterDate.value) return items;
return items.filter((item) => item.feeDate === filterDate.value);
});
const previewFee = computed(() =>
previewItems.value.reduce((sum, item) => sum + Number(item.feeAmount || 0), 0),
);
const selectedShopLabel = computed(() => {
if (channelShopId.value == null) return '未选择渠道店';
return channelShopName.value
@@ -59,6 +68,14 @@ const accumulatedLabel = computed(() => {
if (!dateCount.value) return '尚未累计';
return `${dateCount.value} 天 · ${itemCount.value} 条`;
});
const previewLabel = computed(() => {
if (!filterDate.value) return '全部已读';
return filterDate.value;
});
function onHeatSelect(date: string | undefined) {
filterDate.value = date;
}
async function refreshContext() {
try {
@@ -177,6 +194,9 @@ async function handleRead(fromAuto = false) {
source: 'browser-extension',
importedAt: new Date().toISOString(),
};
if (incomingDate) {
filterDate.value = incomingDate;
}
await refreshContext();
const tag = parsed.platform === 'mock' ? 'Mock' : '页面';
statusText.value = incomingDate
@@ -193,6 +213,7 @@ async function handleRead(fromAuto = false) {
function clearAccumulated() {
batch.value = null;
filterDate.value = undefined;
syncResultText.value = '';
errorText.value = '';
statusText.value = '已清空累计数据';
@@ -350,6 +371,19 @@ onUnmounted(() => {
<span>{{ accumulatedLabel }}</span>
</div>
<section class="ecbi-card">
<DateHeatmap
:items="batch?.items ?? []"
:page-date="pageContext?.feeDate"
:selected-date="filterDate"
@select="onHeatSelect"
/>
<div v-if="filterDate" class="ecbi-heat-filter">
<span class="ecbi-muted">筛选:{{ filterDate }}</span>
<button class="ecbi-link" type="button" @click="filterDate = undefined">显示全部</button>
</div>
</section>
<div class="ecbi-field">
<div class="ecbi-row">
<span class="ecbi-label">BI 渠道店铺</span>
@@ -402,32 +436,27 @@ onUnmounted(() => {
</div>
<section class="ecbi-card">
<h2>数据预览</h2>
<h2>数据预览 · {{ previewLabel }}</h2>
<div class="ecbi-row">
<span class="ecbi-label">推广费用</span>
<span class="ecbi-fee">¥{{ totalFee.toFixed(2) }}</span>
</div>
<div class="ecbi-row">
<span class="ecbi-label">日期</span>
<span class="ecbi-muted" style="max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap">
{{ accumulatedDates.join('、') || '—' }}
</span>
<span class="ecbi-label">{{ filterDate ? '当日费用' : '累计费用' }}</span>
<span class="ecbi-fee">¥{{ (filterDate ? previewFee : totalFee).toFixed(2) }}</span>
</div>
<div class="ecbi-row">
<span class="ecbi-label">条数</span>
<span>{{ itemCount }}</span>
<span>{{ previewItems.length }}{{ filterDate ? ` / ${itemCount}` : '' }}</span>
</div>
<ul v-if="batch?.items?.length" class="ecbi-list">
<li v-for="item in batch.items" :key="`${item.feeDate}-${item.goodsId}`">
<ul v-if="previewItems.length" class="ecbi-list">
<li v-for="item in previewItems" :key="`${item.feeDate}-${item.goodsId}`">
<span>{{ item.feeDate }} · {{ item.goodsId }}</span>
<span>¥{{ Number(item.feeAmount).toFixed(2) }}</span>
</li>
</ul>
<p v-else class="ecbi-muted" style="margin: 8px 0 0">暂无数据,请在单日视图读取</p>
</section>
<p v-if="syncResultText" class="ecbi-ok">{{ syncResultText }}</p>
<p v-if="errorText" class="ecbi-error">{{ errorText }}</p>
<p class="ecbi-muted">请逐日切换「单日」视图读取并累计;范围视图不会追加。同步会提交全部已累计条目。</p>
<p class="ecbi-muted">日历点亮表示已读取;虚线框为当前页日期。同步提交全部已累计条目(不受筛选影响)。</p>
</div>
</div>
</template>
@@ -5,8 +5,8 @@
.ecbi-panel {
position: fixed;
z-index: 2147483646;
width: 360px;
max-height: min(560px, calc(100vh - 24px));
width: 380px;
max-height: min(640px, calc(100vh - 24px));
overflow: hidden;
display: flex;
flex-direction: column;
@@ -220,3 +220,154 @@
.ecbi-link:hover {
text-decoration: underline;
}
/* —— 读取日历(贡献图) —— */
.ecbi-heat {
display: flex;
flex-direction: column;
gap: 6px;
}
.ecbi-heat-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.ecbi-heat-title {
font-size: 11px;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
color: #64748b;
}
.ecbi-heat-body {
display: flex;
gap: 4px;
overflow-x: auto;
padding-bottom: 2px;
}
.ecbi-heat-dows {
display: flex;
flex-direction: column;
gap: 3px;
flex-shrink: 0;
}
.ecbi-heat-month-spacer {
height: 14px;
}
.ecbi-heat-dow {
height: 11px;
width: 14px;
font-size: 9px;
line-height: 11px;
color: #94a3b8;
text-align: right;
}
.ecbi-heat-weeks {
display: flex;
gap: 3px;
}
.ecbi-heat-week {
display: flex;
flex-direction: column;
gap: 3px;
width: 11px;
}
.ecbi-heat-month {
height: 14px;
font-size: 9px;
line-height: 14px;
color: #94a3b8;
white-space: nowrap;
width: max-content;
max-width: none;
position: relative;
z-index: 1;
pointer-events: none;
}
.ecbi-heat-cell {
width: 11px;
height: 11px;
border-radius: 2px;
border: 0;
padding: 0;
display: block;
box-sizing: border-box;
background: #ebedf0;
cursor: default;
}
button.ecbi-heat-cell:not(:disabled) {
cursor: pointer;
}
button.ecbi-heat-cell:disabled {
opacity: 1;
}
.ecbi-heat-l0 {
background: #ebedf0;
}
.ecbi-heat-l1 {
background: #bbf7d0;
}
.ecbi-heat-l2 {
background: #86efac;
}
.ecbi-heat-l3 {
background: #22c55e;
}
.ecbi-heat-l4 {
background: #15803d;
}
.ecbi-heat-out {
opacity: 0.35;
}
.ecbi-heat-page {
outline: 1px dashed #0369a1;
outline-offset: 0;
}
.ecbi-heat-today:not(.ecbi-heat-selected) {
box-shadow: inset 0 0 0 1px #64748b;
}
.ecbi-heat-selected {
outline: 2px solid #0f172a;
outline-offset: 0;
}
.ecbi-heat-legend {
display: flex;
align-items: center;
gap: 3px;
flex-wrap: wrap;
}
.ecbi-heat-gap {
width: 8px;
}
.ecbi-heat-filter {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 2px;
}