1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-11-13 22:11:42 +08:00

fix: 修复数据看板接口字段映射与热力图布局对齐问题

- 修正 IDataStatistics.articles 字段为 articleTotal/momentTotal/total
- 数据看板图表颜色统一为主题色系,环形图中间显示文章总数
- 热力图改为按周分列的 GitHub 风格布局,月份/周标签对齐
This commit is contained in:
小莫唐尼
2026-09-13 04:59:50 +08:00
parent 7e6efd6525
commit 9a5510546b
4 changed files with 78 additions and 39 deletions
+2 -1
View File
@@ -470,7 +470,8 @@ export function getCommentWidgetCaptcha() {
export interface IDataStatistics { export interface IDataStatistics {
tags: { name: string, count: number }[] tags: { name: string, count: number }[]
categories: { name: string, total: number }[] categories: { name: string, total: number }[]
articles: { date: string, count: number }[] /** 发布趋势:articleTotal=当日文章数,momentTotal=当日瞬间数,total=二者之和 */
articles: { date: string, articleTotal: number, momentTotal: number, name: string, total: number }[]
comments: { username: string, count: number }[] comments: { username: string, count: number }[]
top10Articles: { name: string, views: number }[] top10Articles: { name: string, views: number }[]
[key: string]: unknown [key: string]: unknown
+54 -30
View File
@@ -21,7 +21,8 @@ const weeks = ['一', '二', '三', '四', '五', '六', '日']
const currentYear = ref(new Date().getFullYear()) const currentYear = ref(new Date().getFullYear())
const currentMonth = ref(new Date().getMonth() + 1) const currentMonth = ref(new Date().getMonth() + 1)
const intensityColors = ['#ebedf0', '#dbeafe', '#93c5fd', '#3b82f6', '#1e40af'] /** 颜色分级(主题色系黄绿渐变,由浅到深) */
const intensityColors = ['#ebedf0', '#f4fad8', '#e9f79f', '#d7ee52', '#b9e424']
const yearOptions = computed(() => { const yearOptions = computed(() => {
const years = new Set<number>() const years = new Set<number>()
@@ -58,9 +59,16 @@ const daysInYear = computed(() => {
: 366 : 366
}) })
/** 单元格:日粒度,isEmpty=前置空位(非本年日期) */
interface IHeatmapCell {
date: string
count: number
isEmpty: boolean
}
/** 单元格列表:前置空位 + 全年每日 */ /** 单元格列表:前置空位 + 全年每日 */
const displayCells = computed(() => { const displayCells = computed<IHeatmapCell[]>(() => {
const cells: { date: string, count: number, isEmpty: boolean }[] = [] const cells: IHeatmapCell[] = []
for (let i = 0; i < firstDayOffset.value; i++) { for (let i = 0; i < firstDayOffset.value; i++) {
cells.push({ date: '', count: 0, isEmpty: true }) cells.push({ date: '', count: 0, isEmpty: true })
} }
@@ -71,6 +79,31 @@ const displayCells = computed(() => {
return cells return cells
}) })
/** 按周分组为列(每列 7 天,周一~周日;跨年补足空位),列不换行,横向滚动 */
const weekColumns = computed<IHeatmapCell[][]>(() => {
const cells = displayCells.value
const columns: IHeatmapCell[][] = []
for (let i = 0; i < cells.length; i += 7) {
columns.push(cells.slice(i, i + 7))
}
return columns
})
/** 每列顶部月份标签:取该列第一个非空日期所属月份,与上一列同月则空占位(保证列高一致) */
const columnMonths = computed<string[]>(() => {
let lastMonth = -1
return weekColumns.value.map((column) => {
const firstReal = column.find(cell => !cell.isEmpty)
if (!firstReal)
return ''
const month = dayjs(firstReal.date).month()
if (month === lastMonth)
return ''
lastMonth = month
return `${month + 1}月`
})
})
/** 颜色分级 */ /** 颜色分级 */
function getDayColor(day: { count: number, isEmpty: boolean }): string { function getDayColor(day: { count: number, isEmpty: boolean }): string {
if (day.isEmpty) if (day.isEmpty)
@@ -98,15 +131,6 @@ const totalCount = computed(() => props.chartData.reduce((sum, item) => sum + it
/** 本年总数 */ /** 本年总数 */
const currentYearCount = computed(() => Object.values(yearDataMap.value).reduce((sum, n) => sum + n, 0)) const currentYearCount = computed(() => Object.values(yearDataMap.value).reduce((sum, n) => sum + n, 0))
/** 月份标签(按 5 周跨度取整月位置,简化:每两月一个标签) */
const monthLabels = computed(() => {
const labels: { index: number, name: string }[] = []
for (let m = 0; m < 12; m++) {
labels.push({ index: m * 5, name: `${m + 1}月` })
}
return labels
})
function changeYear(value: number) { function changeYear(value: number) {
currentYear.value = value currentYear.value = value
} }
@@ -132,27 +156,27 @@ function changeYear(value: number) {
</view> </view>
<view class="heatmap-container flex gap-2"> <view class="heatmap-container flex gap-2">
<view class="weeks flex flex-col gap-1 pt-8"> <!-- 周标签列(固定,不随横向滚动) -->
<view v-for="(week, index) in weeks" :key="index" class="week-label h-5 text-[16rpx] text-[#999] leading-5"> <view class="weeks flex shrink-0 flex-col gap-1">
<view class="h-6 shrink-0" />
<view v-for="(week, index) in weeks" :key="index" class="week-label h-6 text-[16rpx] text-[#999] leading-6">
{{ week }} {{ week }}
</view> </view>
</view> </view>
<view class="heatmap-content flex-1 overflow-x-auto"> <!-- 主体:每列顶部带月份标签,整列横向排列(不换行),整体横向滚动 -->
<view class="months mb-1 flex"> <scroll-view scroll-x :show-scrollbar="false" class="heatmap-content flex-1">
<view v-for="month in monthLabels" :key="month.index" class="month-label w-[100rpx] shrink-0 text-[16rpx] text-[#999]"> <view class="inline-flex flex-col">
{{ month.name }} <view class="flex gap-1">
<view v-for="(column, ci) in weekColumns" :key="ci" class="flex shrink-0 flex-col">
<view class="month-label h-6 w-6 whitespace-nowrap text-center text-[16rpx] text-[#999] leading-6">
{{ columnMonths[ci] }}
</view>
<view v-for="(day, di) in column" :key="di" class="day-cell mt-1 box-border h-6 w-6 rounded"
:style="{ backgroundColor: getDayColor(day) }" @click="getDayTip(day)" />
</view>
</view> </view>
</view> </view>
<view class="days-container h-[220rpx] flex flex-wrap gap-1"> </scroll-view>
<view
v-for="(day, index) in displayCells"
:key="index"
class="day-cell box-border h-6 w-6 rounded"
:style="{ backgroundColor: getDayColor(day) }"
@click="getDayTip(day)"
/>
</view>
</view>
</view> </view>
<view class="footer mt-6 flex items-center justify-between"> <view class="footer mt-6 flex items-center justify-between">
@@ -181,8 +205,8 @@ function changeYear(value: number) {
background-color: #f5f5f5; background-color: #f5f5f5;
&.active { &.active {
color: #fff; color: #303133;
background-color: #03a9f4; background-color: #b9e424;
} }
} }
} }
+1 -1
View File
@@ -83,7 +83,7 @@
:style="{ backgroundColor: `${link.tileColor}1A` }"> :style="{ backgroundColor: `${link.tileColor}1A` }">
<text class="text-sm font-bold" :style="{ color: link.tileColor }">{{ link.tileLetter }}</text> <text class="text-sm font-bold" :style="{ color: link.tileColor }">{{ link.tileLetter }}</text>
</view> </view>
<view class="min-w-0 flex flex-1 flex-col"> <view class="min-w-0 flex flex-1 flex-col justify-center">
<text class="text-2xs text-gray-900 font-bold">{{ link.title }}</text> <text class="text-2xs text-gray-900 font-bold">{{ link.title }}</text>
<view class="truncate text-xs text-gray-400"> <view class="truncate text-xs text-gray-400">
{{ link.value }} {{ link.value }}
+21 -7
View File
@@ -41,13 +41,20 @@
}) })
/* ---------------- 图表配置 ---------------- */ /* ---------------- 图表配置 ---------------- */
const chartColors = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#14B8A6', '#F97316', '#ea7ccc', '#0EA5E9'] /** 主题色(与 style/index.scss 的 --wot-color-theme 保持一致) */
const themeColor = '#b9e424'
/** 图表系列色板:以主题色为基调配色,黄→绿→青相邻色系,避免杂乱 */
const chartColors = [themeColor, '#8bc34a', '#4caf50', '#26a69a', '#ffd54f', '#d4e157', '#66bb6a', '#9ccc65', '#00bcd4', '#ffb300']
/** 标签统计(环形图) */ /** 标签统计(环形图) */
const tagChart = ref({ const tagChart = ref({
isExpand: true, isExpand: true,
type: 'ring', type: 'ring',
data: { series: [{ data: [] as { name : string, value : number }[] }] }, data: { series: [{ data: [] as { name : string, value : number }[] }] },
/** 环形图中间标题(默认会被 uCharts 填充"收益率",需显式覆盖) */
title: { name: '', fontSize: 13, color: '#909399' },
/** 环形图中间数值 */
subtitle: { name: '', fontSize: 24, color: themeColor },
}) })
/** 分类统计(柱状图) */ /** 分类统计(柱状图) */
@@ -79,8 +86,11 @@
}) })
/* ---------------- 数据处理 ---------------- */ /* ---------------- 数据处理 ---------------- */
/** 环形图最大展示标签数(标签过多时扇区过密,占比难读) */
const TAG_CHART_TOP_N = 8
function handleTagChart() { function handleTagChart() {
const data = [...statistics.value.tags].sort((a, b) => b.count - a.count) const data = [...statistics.value.tags].sort((a, b) => b.count - a.count).slice(0, TAG_CHART_TOP_N)
tagChart.value.data = { tagChart.value.data = {
series: [ series: [
{ {
@@ -88,6 +98,10 @@
}, },
], ],
} }
// 中间文案:文章总数(articles 按日 articleTotal 求和,避免多标签文章重复计数)
const total = statistics.value.articles.reduce((sum, item) => sum + item.articleTotal, 0)
tagChart.value.title = { name: '文章总数', fontSize: 13, color: '#909399' }
tagChart.value.subtitle = { name: `${total} 篇`, fontSize: 24, color: themeColor }
} }
function handleCategoriesChart() { function handleCategoriesChart() {
@@ -101,7 +115,7 @@
function handleTrendArticlesChart() { function handleTrendArticlesChart() {
trandArticleChart.value.data = statistics.value.articles.map(item => ({ trandArticleChart.value.data = statistics.value.articles.map(item => ({
date: item.date, date: item.date,
count: item.count, count: item.articleTotal,
})) }))
} }
@@ -202,7 +216,7 @@
</uh-section-title> </uh-section-title>
<view v-show="tagChart.isExpand" class="box-border w-full mt-3"> <view v-show="tagChart.isExpand" class="box-border w-full mt-3">
<qiun-data-charts type="ring" :chart-data="tagChart.data" <qiun-data-charts type="ring" :chart-data="tagChart.data"
:opts="{ color: chartColors, padding: [5, 5, 5, 5], dataLabel: false, legend: { show: false }, extra: { ring: { ringWidth: 36, offsetAngle: -90, border: true, borderWidth: 1, borderColor: '#FFFFFF' } } }" /> :opts="{ color: chartColors, padding: [5, 5, 5, 5], dataLabel: false, legend: { show: false }, title: tagChart.title, subtitle: tagChart.subtitle, extra: { ring: { ringWidth: 36, offsetAngle: -90, border: true, borderWidth: 1, borderColor: '#FFFFFF' } } }" />
</view> </view>
</view> </view>
@@ -220,7 +234,7 @@
</uh-section-title> </uh-section-title>
<view v-show="categoryChart.isExpand" class="box-border w-full mt-3"> <view v-show="categoryChart.isExpand" class="box-border w-full mt-3">
<qiun-data-charts type="column" :chart-data="categoryChart.data" <qiun-data-charts type="column" :chart-data="categoryChart.data"
:opts="{ color: chartColors, padding: [20, 15, 10, 15], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 6 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: ['#F59E0B'] } } }" /> :opts="{ color: chartColors, padding: [20, 15, 10, 15], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 6 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" />
</view> </view>
</view> </view>
@@ -255,7 +269,7 @@
</uh-section-title> </uh-section-title>
<view v-show="userCommentsChart.isExpand" class="box-border w-full mt-3"> <view v-show="userCommentsChart.isExpand" class="box-border w-full mt-3">
<qiun-data-charts type="column" :chart-data="userCommentsChart.data" <qiun-data-charts type="column" :chart-data="userCommentsChart.data"
:opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: ['#F59E0B'] } } }" /> :opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" />
</view> </view>
</view> </view>
@@ -273,7 +287,7 @@
</uh-section-title> </uh-section-title>
<view v-show="top10ArticlesChart.isExpand" class="box-border w-full mt-3"> <view v-show="top10ArticlesChart.isExpand" class="box-border w-full mt-3">
<qiun-data-charts type="column" :chart-data="top10ArticlesChart.data" <qiun-data-charts type="column" :chart-data="top10ArticlesChart.data"
:opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: ['#F59E0B'] } } }" /> :opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" />
</view> </view>
</view> </view>
</view> </view>