feat: 手动账单输入功能及时区修复
- 新增手动账单输入功能 - 创建 ManualBillInput 组件,支持批量添加账单 - 添加服务器端 API /api/bills/manual 处理手动账单创建 - 支持时间选择器,默认当前时间 - 交易对方字段设为可选 - 实时显示待提交账单列表 - 提交成功后显示成功/失败/重复统计 - 修复时区问题 - 后端使用 time.ParseInLocation 解析本地时间,避免 UTC 时区错误 - 确保手动输入的时间按本地时区正确存储 - UI 优化 - 账单管理页面添加标签页切换(列表/手动添加) - 主页添加快捷按钮跳转至手动添加页面 - 手动账单来源正确显示为"手动输入" - 使用 shadcn-svelte 组件统一 UI 风格 - 提交成功后保持日期筛选并重新加载数据
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
import TrendingDown from '@lucide/svelte/icons/trending-down';
|
||||
import Loader2 from '@lucide/svelte/icons/loader-2';
|
||||
import AlertCircle from '@lucide/svelte/icons/alert-circle';
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
let isDragOver = $state(false);
|
||||
let selectedFile: File | null = $state(null);
|
||||
@@ -169,9 +171,15 @@
|
||||
<div class="grid gap-6 lg:grid-cols-2">
|
||||
<!-- 上传区域 -->
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
<Card.Title>上传账单</Card.Title>
|
||||
<Card.Description>支持支付宝、微信账单 CSV 文件</Card.Description>
|
||||
<Card.Header class="flex flex-row items-center justify-between space-y-0">
|
||||
<div>
|
||||
<Card.Title>上传账单</Card.Title>
|
||||
<Card.Description>支持支付宝、微信账单 CSV 文件</Card.Description>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onclick={() => goto('/bills?tab=manual')}>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
手动添加
|
||||
</Button>
|
||||
</Card.Header>
|
||||
<Card.Content class="space-y-4">
|
||||
<!-- 拖拽上传区域 -->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { fetchBills, type CleanedBill } from '$lib/api';
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
@@ -7,7 +8,10 @@
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import { Separator } from '$lib/components/ui/separator';
|
||||
import { DateRangePicker } from '$lib/components/ui/date-range-picker';
|
||||
import ManualBillInput from '$lib/components/bills/ManualBillInput.svelte';
|
||||
import { formatLocalDate } from '$lib/utils';
|
||||
import Loader2 from '@lucide/svelte/icons/loader-2';
|
||||
import AlertCircle from '@lucide/svelte/icons/alert-circle';
|
||||
@@ -20,11 +24,22 @@
|
||||
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
||||
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
||||
import RefreshCw from '@lucide/svelte/icons/refresh-cw';
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import List from '@lucide/svelte/icons/list';
|
||||
|
||||
// 状态
|
||||
let isLoading = $state(false);
|
||||
let errorMessage = $state('');
|
||||
let records: CleanedBill[] = $state([]);
|
||||
let activeTab = $state<'list' | 'manual'>('list'); // 'list' 或 'manual'
|
||||
|
||||
// 初始化标签页(从URL查询参数)
|
||||
onMount(() => {
|
||||
const tabParam = $page.url.searchParams.get('tab');
|
||||
if (tabParam === 'manual') {
|
||||
activeTab = 'manual';
|
||||
}
|
||||
});
|
||||
|
||||
// 分页
|
||||
let currentPage = $state(1);
|
||||
@@ -56,6 +71,22 @@
|
||||
let endDate = $state(defaultDates.endDate);
|
||||
let searchText = $state('');
|
||||
|
||||
// Select 变化处理
|
||||
function handleCategoryChange(value: string | undefined) {
|
||||
filterCategory = value || '';
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
function handleIncomeExpenseChange(value: string | undefined) {
|
||||
filterIncomeExpense = value || '';
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
function handleBillTypeChange(value: string | undefined) {
|
||||
filterBillType = value || '';
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
// 分类列表(硬编码常用分类)
|
||||
const categories = [
|
||||
'餐饮美食', '交通出行', '生活服务', '日用百货',
|
||||
@@ -137,6 +168,16 @@
|
||||
onMount(() => {
|
||||
loadBills();
|
||||
});
|
||||
|
||||
// 手动账单提交成功回调
|
||||
function handleManualBillSuccess() {
|
||||
// 切换回列表标签页
|
||||
activeTab = 'list';
|
||||
// 重置分页到第一页
|
||||
currentPage = 1;
|
||||
// 重新加载账单列表(保持当前日期筛选)
|
||||
loadBills();
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -144,25 +185,52 @@
|
||||
</svelte:head>
|
||||
|
||||
<div class="space-y-6">
|
||||
<!-- 页面标题 -->
|
||||
<!-- 页面标题和标签切换 -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold tracking-tight">账单列表</h1>
|
||||
<p class="text-muted-foreground">查看和筛选已处理的账单记录</p>
|
||||
<h1 class="text-2xl font-bold tracking-tight">账单管理</h1>
|
||||
<p class="text-muted-foreground">查看、筛选和手动添加账单记录</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
{#if activeTab === 'list'}
|
||||
<Button variant="outline" onclick={loadBills} disabled={isLoading}>
|
||||
<RefreshCw class="mr-2 h-4 w-4 {isLoading ? 'animate-spin' : ''}" />
|
||||
刷新
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
<Button variant="outline" onclick={loadBills} disabled={isLoading}>
|
||||
<RefreshCw class="mr-2 h-4 w-4 {isLoading ? 'animate-spin' : ''}" />
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
{#if errorMessage}
|
||||
<div class="flex items-center gap-2 rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive">
|
||||
<AlertCircle class="h-4 w-4" />
|
||||
{errorMessage}
|
||||
</div>
|
||||
{/if}
|
||||
<!-- 标签切换 -->
|
||||
<div class="flex gap-1">
|
||||
<Button
|
||||
variant={activeTab === 'list' ? 'default' : 'ghost'}
|
||||
onclick={() => activeTab = 'list'}
|
||||
>
|
||||
<List class="mr-2 h-4 w-4" />
|
||||
账单列表
|
||||
</Button>
|
||||
<Button
|
||||
variant={activeTab === 'manual' ? 'default' : 'ghost'}
|
||||
onclick={() => activeTab = 'manual'}
|
||||
>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
手动添加
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<!-- 账单列表视图 -->
|
||||
{#if activeTab === 'list'}
|
||||
<div class="space-y-6">
|
||||
<!-- 错误提示 -->
|
||||
{#if errorMessage}
|
||||
<div class="flex items-center gap-2 rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive">
|
||||
<AlertCircle class="h-4 w-4" />
|
||||
{errorMessage}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- 统计概览 -->
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
@@ -232,40 +300,50 @@
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">分类</Label>
|
||||
<select
|
||||
class="h-9 w-full rounded-md border border-input bg-background px-3 text-sm"
|
||||
bind:value={filterCategory}
|
||||
onchange={applyFilters}
|
||||
>
|
||||
<option value="">全部</option>
|
||||
{#each categories as cat}
|
||||
<option value={cat}>{cat}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<Select.Root type="single" value={filterCategory || undefined} onValueChange={handleCategoryChange}>
|
||||
<Select.Trigger class="h-9 w-full">
|
||||
<span class="text-sm">{filterCategory || '全部'}</span>
|
||||
</Select.Trigger>
|
||||
<Select.Portal>
|
||||
<Select.Content>
|
||||
<Select.Item value="">全部</Select.Item>
|
||||
{#each categories as cat}
|
||||
<Select.Item value={cat}>{cat}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Portal>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">收/支</Label>
|
||||
<select
|
||||
class="h-9 w-full rounded-md border border-input bg-background px-3 text-sm"
|
||||
bind:value={filterIncomeExpense}
|
||||
onchange={applyFilters}
|
||||
>
|
||||
<option value="">全部</option>
|
||||
<option value="支出">支出</option>
|
||||
<option value="收入">收入</option>
|
||||
</select>
|
||||
<Select.Root type="single" value={filterIncomeExpense || undefined} onValueChange={handleIncomeExpenseChange}>
|
||||
<Select.Trigger class="h-9 w-full">
|
||||
<span class="text-sm">{filterIncomeExpense || '全部'}</span>
|
||||
</Select.Trigger>
|
||||
<Select.Portal>
|
||||
<Select.Content>
|
||||
<Select.Item value="">全部</Select.Item>
|
||||
<Select.Item value="支出">支出</Select.Item>
|
||||
<Select.Item value="收入">收入</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Portal>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">来源</Label>
|
||||
<select
|
||||
class="h-9 w-full rounded-md border border-input bg-background px-3 text-sm"
|
||||
bind:value={filterBillType}
|
||||
onchange={applyFilters}
|
||||
>
|
||||
<option value="">全部</option>
|
||||
<option value="alipay">支付宝</option>
|
||||
<option value="wechat">微信</option>
|
||||
</select>
|
||||
<Select.Root type="single" value={filterBillType || undefined} onValueChange={handleBillTypeChange}>
|
||||
<Select.Trigger class="h-9 w-full">
|
||||
<span class="text-sm">{filterBillType === 'alipay' ? '支付宝' : filterBillType === 'wechat' ? '微信' : filterBillType === 'manual' ? '手动' : '全部'}</span>
|
||||
</Select.Trigger>
|
||||
<Select.Portal>
|
||||
<Select.Content>
|
||||
<Select.Item value="">全部</Select.Item>
|
||||
<Select.Item value="alipay">支付宝</Select.Item>
|
||||
<Select.Item value="wechat">微信</Select.Item>
|
||||
<Select.Item value="manual">手动</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Portal>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="space-y-1.5 col-span-2 sm:col-span-1">
|
||||
<Label class="text-xs">搜索</Label>
|
||||
@@ -310,8 +388,8 @@
|
||||
{record.time}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="hidden xl:table-cell">
|
||||
<Badge variant={record.bill_type === 'alipay' ? 'default' : 'secondary'}>
|
||||
{record.bill_type === 'alipay' ? '支付宝' : '微信'}
|
||||
<Badge variant={record.bill_type === 'manual' ? 'outline' : (record.bill_type === 'alipay' ? 'default' : 'secondary')}>
|
||||
{record.bill_type === 'manual' ? '手动输入' : (record.bill_type === 'alipay' ? '支付宝' : '微信')}
|
||||
</Badge>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -400,4 +478,11 @@
|
||||
{/if}
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- 手动添加视图 -->
|
||||
{#if activeTab === 'manual'}
|
||||
<ManualBillInput {categories} onSuccess={handleManualBillSuccess} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user