mirror of
https://github.com/fengshuzi/coin-memo.git
synced 2026-07-22 06:08:04 +00:00
feat: 主页面可选显示简化支出统计表格,默认隐藏;版本号+1
This commit is contained in:
parent
02da6eac36
commit
0ab5643b25
6 changed files with 117 additions and 6 deletions
66
main.ts
66
main.ts
|
|
@ -14,6 +14,7 @@ interface AccountingConfig {
|
|||
quickCopyDays?: number; // 快速记账显示最近N天的记录
|
||||
billMerchantMap?: Record<string, { category: string; description?: string }>; // 账单商户关键字 → { 分类关键词, 描述 } 映射(用于bill.md自动分类)
|
||||
silentBillImport?: boolean; // 静默记账:识别成功后不弹窗,直接写入日记
|
||||
showMainPageStats?: boolean; // 在主页面显示简化支出统计表格(默认隐藏)
|
||||
budgets?: {
|
||||
monthly: {
|
||||
total: number;
|
||||
|
|
@ -3374,6 +3375,7 @@ class AccountingView extends ItemView {
|
|||
categoryFilteredRecords: AccountingRecord[]; // 时间+分类筛选后的记录(用于展示)
|
||||
currentDateRange: { start: string; end: string; label: string };
|
||||
selectedCategory: string; // 当前选中的分类关键词,空字符串表示全部
|
||||
statsContainer: HTMLElement; // 主页面简化统计容器(可通过配置隐藏)
|
||||
recordsContainer: HTMLElement;
|
||||
timeDisplay: HTMLElement;
|
||||
timeFilterEl: FilterDropdown; // 时间筛选下拉
|
||||
|
|
@ -3419,6 +3421,7 @@ class AccountingView extends ItemView {
|
|||
container.addClass('accounting-view');
|
||||
|
||||
this.renderHeader(container);
|
||||
this.statsContainer = container.createDiv('main-page-stats');
|
||||
this.renderRecordsList(container);
|
||||
|
||||
// 初始加载数据
|
||||
|
|
@ -3747,9 +3750,58 @@ class AccountingView extends ItemView {
|
|||
return colors[category] ?? '#6c757d'; // 默认灰色
|
||||
}
|
||||
|
||||
/** 主页面简化支出统计:简单表格展示当前时间范围的总支出和分类支出(可在设置中开启,默认隐藏) */
|
||||
renderMainPageStats() {
|
||||
if (!this.statsContainer) return;
|
||||
|
||||
this.statsContainer.empty();
|
||||
|
||||
if (this.plugin.config.showMainPageStats !== true) {
|
||||
this.statsContainer.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// 基于时间筛选后的记录统计,不受分类筛选影响
|
||||
const expenseByCategory: Record<string, number> = {};
|
||||
let totalExpense = 0;
|
||||
this.filteredRecords.forEach(record => {
|
||||
if (record.isIncome) return;
|
||||
expenseByCategory[record.category] = (expenseByCategory[record.category] || 0) + record.amount;
|
||||
totalExpense += record.amount;
|
||||
});
|
||||
|
||||
if (totalExpense <= 0) {
|
||||
this.statsContainer.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
this.statsContainer.removeClass('hidden');
|
||||
|
||||
const table = this.statsContainer.createEl('table', { cls: 'main-stats-table' });
|
||||
const headRow = table.createEl('thead').createEl('tr');
|
||||
headRow.createEl('th', { text: '分类' });
|
||||
headRow.createEl('th', { text: '支出' });
|
||||
|
||||
const tbody = table.createEl('tbody');
|
||||
|
||||
const totalRow = tbody.createEl('tr', { cls: 'main-stats-total-row' });
|
||||
totalRow.createEl('td', { text: '总支出' });
|
||||
totalRow.createEl('td', { text: `¥${totalExpense.toFixed(2)}` });
|
||||
|
||||
recordEntries(expenseByCategory)
|
||||
.sort(([, a], [, b]) => b - a)
|
||||
.forEach(([category, amount]) => {
|
||||
const row = tbody.createEl('tr');
|
||||
row.createEl('td', { text: category });
|
||||
row.createEl('td', { text: `¥${amount.toFixed(2)}` });
|
||||
});
|
||||
}
|
||||
|
||||
updateRecordsDisplay(records = this.currentRecords) {
|
||||
this.renderMainPageStats();
|
||||
|
||||
if (!this.recordsContainer) return;
|
||||
|
||||
|
||||
this.recordsContainer.empty();
|
||||
|
||||
if (!records || records.length === 0) {
|
||||
|
|
@ -4701,6 +4753,18 @@ class AccountingSettingTab extends PluginSettingTab {
|
|||
await this.plugin.refreshData();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('在主页面显示支出统计')
|
||||
.setDesc('开启后,记账主页面顶部以简单表格显示当前时间范围的总支出和各分类支出(默认隐藏,完整统计请打开统计页面)')
|
||||
.addToggle(toggle => toggle
|
||||
.setValue(this.plugin.config.showMainPageStats === true)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.config.showMainPageStats = value;
|
||||
await this.plugin.saveConfig();
|
||||
// 刷新视图
|
||||
await this.plugin.refreshData();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('快速记账天数')
|
||||
.setDesc('快速记账显示最近n天的记录(默认14天)')
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "coin-memo",
|
||||
"name": "Coin Memo",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"minAppVersion": "1.7.2",
|
||||
"description": "基于日记文件的每日记账插件,支持自动识别和统计记账记录.",
|
||||
"author": "lizhifeng",
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coin-memo",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coin-memo",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.4",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coin-memo",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"description": "基于日记文件的记账管理插件",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
46
styles.css
46
styles.css
|
|
@ -494,6 +494,52 @@
|
|||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 主页面简化支出统计表格 */
|
||||
.main-page-stats {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.main-page-stats.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.main-stats-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 14px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: var(--background-primary);
|
||||
}
|
||||
|
||||
.main-stats-table th,
|
||||
.main-stats-table td {
|
||||
padding: 6px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.main-stats-table th:last-child,
|
||||
.main-stats-table td:last-child {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.main-stats-table thead th {
|
||||
color: var(--text-muted);
|
||||
font-weight: 600;
|
||||
background: var(--background-secondary);
|
||||
}
|
||||
|
||||
.main-stats-table tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.main-stats-total-row td {
|
||||
font-weight: 600;
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
/* 记录列表样式 - Notion 风格 */
|
||||
.accounting-records {
|
||||
margin-top: 24px;
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@
|
|||
"1.0.14": "1.7.2",
|
||||
"1.0.15": "1.7.2",
|
||||
"1.0.16": "1.7.2",
|
||||
"1.0.17": "1.7.2"
|
||||
"1.0.17": "1.7.2",
|
||||
"1.0.18": "1.7.2"
|
||||
}
|
||||
Loading…
Reference in a new issue