Compare commits
50 Commits
maf
...
298ce03aa6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
298ce03aa6 | ||
|
|
5d6797b16a | ||
|
|
2ffad479ba | ||
|
|
9b25c62662 | ||
|
|
1b3d01c78c | ||
|
|
0ef4b52fcc | ||
|
|
2043976998 | ||
|
|
3cbc868e9b | ||
|
|
c74ce24727 | ||
|
|
14bbd62262 | ||
|
|
0c95b6aa6e | ||
|
|
f77cc57cab | ||
|
|
59b81148ac | ||
|
|
04e4946f3d | ||
|
|
319f8f7d7b | ||
|
|
9069e3dbcf | ||
|
|
71a8707241 | ||
|
|
0e140548b7 | ||
|
|
12b8e4bd0e | ||
|
|
f4f1600782 | ||
|
|
caf6f3fe60 | ||
|
|
df3a06051b | ||
|
|
c80e5daf7d | ||
|
|
ea11d72c00 | ||
|
|
9e03187a95 | ||
|
|
667358fa0b | ||
|
|
69298c2ffa | ||
|
|
82e5c79868 | ||
|
|
65f7316c82 | ||
|
|
12cf1b6323 | ||
|
|
4444f2b808 | ||
|
|
0ccfa57d7b | ||
| f2f741411b | |||
|
|
6e7a237df9 | ||
|
|
6a45f3d67d | ||
|
|
c5c3b56200 | ||
| 556fc5af20 | |||
|
|
03115a04ec | ||
|
|
de4e692bce | ||
|
|
d324d204d5 | ||
|
|
b4cb0a200e | ||
| 02fcf07235 | |||
| e11c1e4fc4 | |||
|
|
83dfa66d85 | ||
|
|
c07c9dd07d | ||
|
|
a41c2b79af | ||
|
|
5cac4d6dde | ||
|
|
a8da1c6a70 | ||
|
|
8c7dbd24ad | ||
|
|
694925e326 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -404,3 +404,4 @@ FodyWeavers.xsd
|
|||||||
Web/dist
|
Web/dist
|
||||||
# ESLint
|
# ESLint
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
.aider*
|
||||||
|
|||||||
@@ -50,9 +50,20 @@ public static class ServiceExtension
|
|||||||
|
|
||||||
foreach (var @interface in interfaces)
|
foreach (var @interface in interfaces)
|
||||||
{
|
{
|
||||||
// 其他 Services 用 Singleton
|
// EmailBackgroundService 必须是 Singleton(后台服务),其他服务可用 Transient
|
||||||
|
if (type.Name == "EmailBackgroundService")
|
||||||
|
{
|
||||||
services.AddSingleton(@interface, type);
|
services.AddSingleton(@interface, type);
|
||||||
Console.WriteLine($"✓ 注册 Service: {@interface.Name} -> {type.Name}");
|
}
|
||||||
|
else if (type.Name == "EmailFetchService")
|
||||||
|
{
|
||||||
|
// EmailFetchService 用 Transient,避免连接冲突
|
||||||
|
services.AddTransient(@interface, type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
services.AddSingleton(@interface, type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +83,7 @@ public static class ServiceExtension
|
|||||||
foreach (var @interface in interfaces)
|
foreach (var @interface in interfaces)
|
||||||
{
|
{
|
||||||
services.AddSingleton(@interface, type);
|
services.AddSingleton(@interface, type);
|
||||||
Console.WriteLine($"✓ 注册 Repository: {@interface.Name} -> {type.Name}");
|
Console.WriteLine($"注册 Repository: {@interface.Name} -> {type.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Email & MIME Libraries -->
|
<!-- Email & MIME Libraries -->
|
||||||
<PackageVersion Include="FreeSql" Version="3.5.304" />
|
<PackageVersion Include="FreeSql" Version="3.5.305" />
|
||||||
|
<PackageVersion Include="FreeSql.Extensions.JsonMap" Version="3.5.305" />
|
||||||
<PackageVersion Include="MailKit" Version="4.14.1" />
|
<PackageVersion Include="MailKit" Version="4.14.1" />
|
||||||
<PackageVersion Include="Microsoft.Agents.AI" Version="1.0.0-preview.260108.1" />
|
|
||||||
<PackageVersion Include="Microsoft.Agents.AI.DevUI" Version="1.0.0-preview.260108.1" />
|
|
||||||
<PackageVersion Include="Microsoft.Agents.AI.Hosting" Version="1.0.0-preview.260108.1" />
|
|
||||||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.1" />
|
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.1" />
|
||||||
<PackageVersion Include="MimeKit" Version="4.14.0" />
|
<PackageVersion Include="MimeKit" Version="4.14.0" />
|
||||||
<!-- Dependency Injection & Configuration -->
|
<!-- Dependency Injection & Configuration -->
|
||||||
@@ -23,7 +21,7 @@
|
|||||||
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
||||||
<PackageVersion Include="Scalar.AspNetCore" Version="2.11.9" />
|
<PackageVersion Include="Scalar.AspNetCore" Version="2.11.9" />
|
||||||
<!-- Database -->
|
<!-- Database -->
|
||||||
<PackageVersion Include="FreeSql.Provider.Sqlite" Version="3.5.304" />
|
<PackageVersion Include="FreeSql.Provider.Sqlite" Version="3.5.305" />
|
||||||
<PackageVersion Include="WebPush" Version="1.0.12" />
|
<PackageVersion Include="WebPush" Version="1.0.12" />
|
||||||
<PackageVersion Include="Yitter.IdGenerator" Version="1.0.14" />
|
<PackageVersion Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||||
<!-- File Processing -->
|
<!-- File Processing -->
|
||||||
@@ -36,6 +34,5 @@
|
|||||||
<!-- Text Processing -->
|
<!-- Text Processing -->
|
||||||
<PackageVersion Include="JiebaNet.Analyser" Version="1.0.6" />
|
<PackageVersion Include="JiebaNet.Analyser" Version="1.0.6" />
|
||||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.AI" Version="10.1.1" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -2,31 +2,6 @@
|
|||||||
|
|
||||||
public class BudgetArchive : BaseEntity
|
public class BudgetArchive : BaseEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 预算Id
|
|
||||||
/// </summary>
|
|
||||||
public long BudgetId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 预算周期类型
|
|
||||||
/// </summary>
|
|
||||||
public BudgetPeriodType BudgetType { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 预算金额
|
|
||||||
/// </summary>
|
|
||||||
public decimal BudgetedAmount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 周期内实际发生金额
|
|
||||||
/// </summary>
|
|
||||||
public decimal RealizedAmount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 详细描述
|
|
||||||
/// </summary>
|
|
||||||
public string? Description { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 归档目标年份
|
/// 归档目标年份
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -37,8 +12,79 @@ public class BudgetArchive : BaseEntity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Month { get; set; }
|
public int Month { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 归档内容
|
||||||
|
/// </summary>
|
||||||
|
[JsonMap]
|
||||||
|
public BudgetArchiveContent[] Content { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 归档日期
|
/// 归档日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime ArchiveDate { get; set; } = DateTime.Now;
|
public DateTime ArchiveDate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 支出结余(预算 - 实际,正数表示省钱,负数表示超支)
|
||||||
|
/// </summary>
|
||||||
|
public decimal ExpenseSurplus { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收入结余(实际 - 预算,正数表示超额收入,负数表示未达预期)
|
||||||
|
/// </summary>
|
||||||
|
public decimal IncomeSurplus { get; set; }
|
||||||
|
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public record BudgetArchiveContent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 预算ID
|
||||||
|
/// </summary>
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 预算名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 统计周期
|
||||||
|
/// </summary>
|
||||||
|
public BudgetPeriodType Type { get; set; } = BudgetPeriodType.Month;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 预算金额
|
||||||
|
/// </summary>
|
||||||
|
public decimal Limit { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实际金额
|
||||||
|
/// </summary>
|
||||||
|
public decimal Actual { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 预算类别
|
||||||
|
/// </summary>
|
||||||
|
public BudgetCategory Category { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 相关分类 (逗号分隔的分类名称)
|
||||||
|
/// </summary>
|
||||||
|
public string[] SelectedCategories { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 不记额预算
|
||||||
|
/// </summary>
|
||||||
|
public bool NoLimit { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 硬性消费
|
||||||
|
/// </summary>
|
||||||
|
public bool IsMandatoryExpense { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述说明
|
||||||
|
/// </summary>
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,16 @@ public class BudgetRecord : BaseEntity
|
|||||||
/// 开始日期
|
/// 开始日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime StartDate { get; set; } = DateTime.Now;
|
public DateTime StartDate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 不记额预算(选中后该预算没有预算金额,发生的收入或支出直接在存款中加减)
|
||||||
|
/// </summary>
|
||||||
|
public bool NoLimit { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 硬性消费(固定消费,如房租、水电等。当是当前年月且为硬性消费时,会根据经过的天数累加Current)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsMandatoryExpense { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BudgetPeriodType
|
public enum BudgetPeriodType
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FreeSql" />
|
<PackageReference Include="FreeSql" />
|
||||||
|
<PackageReference Include="FreeSql.Extensions.JsonMap" />
|
||||||
<PackageReference Include="Yitter.IdGenerator" />
|
<PackageReference Include="Yitter.IdGenerator" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,19 +2,21 @@
|
|||||||
|
|
||||||
public interface IBudgetArchiveRepository : IBaseRepository<BudgetArchive>
|
public interface IBudgetArchiveRepository : IBaseRepository<BudgetArchive>
|
||||||
{
|
{
|
||||||
Task<BudgetArchive?> GetArchiveAsync(long budgetId, int year, int month);
|
Task<BudgetArchive?> GetArchiveAsync(int year, int month);
|
||||||
|
|
||||||
Task<List<BudgetArchive>> GetListAsync(int year, int month);
|
Task<List<BudgetArchive>> GetListAsync(int year, int month);
|
||||||
|
|
||||||
|
Task<List<BudgetArchive>> GetArchivesByYearAsync(int year);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BudgetArchiveRepository(
|
public class BudgetArchiveRepository(
|
||||||
IFreeSql freeSql
|
IFreeSql freeSql
|
||||||
) : BaseRepository<BudgetArchive>(freeSql), IBudgetArchiveRepository
|
) : BaseRepository<BudgetArchive>(freeSql), IBudgetArchiveRepository
|
||||||
{
|
{
|
||||||
public async Task<BudgetArchive?> GetArchiveAsync(long budgetId, int year, int month)
|
public async Task<BudgetArchive?> GetArchiveAsync(int year, int month)
|
||||||
{
|
{
|
||||||
return await FreeSql.Select<BudgetArchive>()
|
return await FreeSql.Select<BudgetArchive>()
|
||||||
.Where(a => a.BudgetId == budgetId &&
|
.Where(a => a.Year == year &&
|
||||||
a.Year == year &&
|
|
||||||
a.Month == month)
|
a.Month == month)
|
||||||
.ToOneAsync();
|
.ToOneAsync();
|
||||||
}
|
}
|
||||||
@@ -22,13 +24,15 @@ public class BudgetArchiveRepository(
|
|||||||
public async Task<List<BudgetArchive>> GetListAsync(int year, int month)
|
public async Task<List<BudgetArchive>> GetListAsync(int year, int month)
|
||||||
{
|
{
|
||||||
return await FreeSql.Select<BudgetArchive>()
|
return await FreeSql.Select<BudgetArchive>()
|
||||||
.Where(
|
.Where(a => a.Year == year && a.Month == month)
|
||||||
a => a.BudgetType == BudgetPeriodType.Month &&
|
.ToListAsync();
|
||||||
a.Year == year &&
|
}
|
||||||
a.Month == month ||
|
|
||||||
a.BudgetType == BudgetPeriodType.Year &&
|
public async Task<List<BudgetArchive>> GetArchivesByYearAsync(int year)
|
||||||
a.Year == year
|
{
|
||||||
)
|
return await FreeSql.Select<BudgetArchive>()
|
||||||
|
.Where(a => a.Year == year)
|
||||||
|
.OrderBy(a => a.Month)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,8 +57,16 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="year">年份</param>
|
/// <param name="year">年份</param>
|
||||||
/// <param name="month">月份</param>
|
/// <param name="month">月份</param>
|
||||||
/// <returns>每天的消费笔数和金额</returns>
|
/// <returns>每天的消费笔数和金额详情</returns>
|
||||||
Task<Dictionary<string, (int count, decimal amount)>> GetDailyStatisticsAsync(int year, int month);
|
Task<Dictionary<string, (int count, decimal expense, decimal income, decimal saving)>> GetDailyStatisticsAsync(int year, int month, string? savingClassify = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定日期范围内的每日统计
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startDate">开始日期</param>
|
||||||
|
/// <param name="endDate">结束日期</param>
|
||||||
|
/// <returns>每天的消费笔数和金额详情</returns>
|
||||||
|
Task<Dictionary<string, (int count, decimal expense, decimal income, decimal saving)>> GetDailyStatisticsByRangeAsync(DateTime startDate, DateTime endDate, string? savingClassify = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取指定日期范围内的交易记录
|
/// 获取指定日期范围内的交易记录
|
||||||
@@ -190,6 +198,16 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
|||||||
/// <returns>影响行数</returns>
|
/// <returns>影响行数</returns>
|
||||||
Task<int> ConfirmAllUnconfirmedAsync(long[] ids);
|
Task<int> ConfirmAllUnconfirmedAsync(long[] ids);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定分类在指定时间范围内的每日/每月统计趋势
|
||||||
|
/// </summary>
|
||||||
|
Task<Dictionary<DateTime, decimal>> GetFilteredTrendStatisticsAsync(
|
||||||
|
DateTime startDate,
|
||||||
|
DateTime endDate,
|
||||||
|
TransactionType type,
|
||||||
|
IEnumerable<string> classifies,
|
||||||
|
bool groupByMonth = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新分类名称
|
/// 更新分类名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -337,11 +355,16 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
|||||||
.ToListAsync(t => t.Classify);
|
.ToListAsync(t => t.Classify);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, (int count, decimal amount)>> GetDailyStatisticsAsync(int year, int month)
|
public async Task<Dictionary<string, (int count, decimal expense, decimal income, decimal saving)>> GetDailyStatisticsAsync(int year, int month, string? savingClassify = null)
|
||||||
{
|
{
|
||||||
var startDate = new DateTime(year, month, 1);
|
var startDate = new DateTime(year, month, 1);
|
||||||
var endDate = startDate.AddMonths(1);
|
var endDate = startDate.AddMonths(1);
|
||||||
|
|
||||||
|
return await GetDailyStatisticsByRangeAsync(startDate, endDate, savingClassify);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<string, (int count, decimal expense, decimal income, decimal saving)>> GetDailyStatisticsByRangeAsync(DateTime startDate, DateTime endDate, string? savingClassify = null)
|
||||||
|
{
|
||||||
var records = await FreeSql.Select<TransactionRecord>()
|
var records = await FreeSql.Select<TransactionRecord>()
|
||||||
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
@@ -353,11 +376,16 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
|||||||
g =>
|
g =>
|
||||||
{
|
{
|
||||||
// 分别统计收入和支出
|
// 分别统计收入和支出
|
||||||
var income = g.Where(t => t.Type == TransactionType.Income).Sum(t => t.Amount);
|
var income = g.Where(t => t.Type == TransactionType.Income).Sum(t => Math.Abs(t.Amount));
|
||||||
var expense = g.Where(t => t.Type == TransactionType.Expense).Sum(t => t.Amount);
|
var expense = g.Where(t => t.Type == TransactionType.Expense).Sum(t => Math.Abs(t.Amount));
|
||||||
// 净额 = 收入 - 支出(消费大于收入时为负数)
|
|
||||||
var netAmount = income - expense;
|
var saving = 0m;
|
||||||
return (count: g.Count(), amount: netAmount);
|
if(!string.IsNullOrEmpty(savingClassify))
|
||||||
|
{
|
||||||
|
saving = g.Where(t => savingClassify.Split(',').Contains(t.Classify)).Sum(t => Math.Abs(t.Amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (count: g.Count(), expense, income, saving);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -499,19 +527,11 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
|||||||
{
|
{
|
||||||
statistics.TotalExpense += amount;
|
statistics.TotalExpense += amount;
|
||||||
statistics.ExpenseCount++;
|
statistics.ExpenseCount++;
|
||||||
if (amount > statistics.MaxExpense)
|
|
||||||
{
|
|
||||||
statistics.MaxExpense = amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (record.Type == TransactionType.Income)
|
else if (record.Type == TransactionType.Income)
|
||||||
{
|
{
|
||||||
statistics.TotalIncome += amount;
|
statistics.TotalIncome += amount;
|
||||||
statistics.IncomeCount++;
|
statistics.IncomeCount++;
|
||||||
if (amount > statistics.MaxIncome)
|
|
||||||
{
|
|
||||||
statistics.MaxIncome = amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,6 +729,37 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
|||||||
.Where(t => ids.Contains(t.Id))
|
.Where(t => ids.Contains(t.Id))
|
||||||
.ExecuteAffrowsAsync();
|
.ExecuteAffrowsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<DateTime, decimal>> GetFilteredTrendStatisticsAsync(
|
||||||
|
DateTime startDate,
|
||||||
|
DateTime endDate,
|
||||||
|
TransactionType type,
|
||||||
|
IEnumerable<string> classifies,
|
||||||
|
bool groupByMonth = false)
|
||||||
|
{
|
||||||
|
var query = FreeSql.Select<TransactionRecord>()
|
||||||
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt <= endDate && t.Type == type);
|
||||||
|
|
||||||
|
if (classifies != null && classifies.Any())
|
||||||
|
{
|
||||||
|
query = query.Where(t => classifies.Contains(t.Classify));
|
||||||
|
}
|
||||||
|
|
||||||
|
var list = await query.ToListAsync(t => new { t.OccurredAt, t.Amount });
|
||||||
|
|
||||||
|
if (groupByMonth)
|
||||||
|
{
|
||||||
|
return list
|
||||||
|
.GroupBy(t => new DateTime(t.OccurredAt.Year, t.OccurredAt.Month, 1))
|
||||||
|
.ToDictionary(g => g.Key, g => g.Sum(x => Math.Abs(x.Amount)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return list
|
||||||
|
.GroupBy(t => t.OccurredAt.Date)
|
||||||
|
.ToDictionary(g => g.Key, g => g.Sum(x => Math.Abs(x.Amount)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -760,8 +811,6 @@ public class MonthlyStatistics
|
|||||||
public int ExpenseCount { get; set; }
|
public int ExpenseCount { get; set; }
|
||||||
public int IncomeCount { get; set; }
|
public int IncomeCount { get; set; }
|
||||||
public int TotalCount { get; set; }
|
public int TotalCount { get; set; }
|
||||||
public decimal MaxExpense { get; set; }
|
|
||||||
public decimal MaxIncome { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AI 工具集
|
|
||||||
/// </summary>
|
|
||||||
public interface IAITools
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// AI 分类决策
|
|
||||||
/// </summary>
|
|
||||||
Task<ClassificationResult[]> ClassifyTransactionsAsync(
|
|
||||||
string systemPrompt,
|
|
||||||
string userPrompt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AI 工具实现
|
|
||||||
/// </summary>
|
|
||||||
public class AITools(
|
|
||||||
IOpenAiService openAiService,
|
|
||||||
ILogger<AITools> logger
|
|
||||||
) : IAITools
|
|
||||||
{
|
|
||||||
public async Task<ClassificationResult[]> ClassifyTransactionsAsync(
|
|
||||||
string systemPrompt,
|
|
||||||
string userPrompt)
|
|
||||||
{
|
|
||||||
logger.LogInformation("调用 AI 进行账单分类");
|
|
||||||
|
|
||||||
var response = await openAiService.ChatAsync(systemPrompt, userPrompt);
|
|
||||||
if (string.IsNullOrWhiteSpace(response))
|
|
||||||
{
|
|
||||||
logger.LogWarning("AI 返回空响应");
|
|
||||||
return Array.Empty<ClassificationResult>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 NDJSON 格式的 AI 响应
|
|
||||||
var results = new List<ClassificationResult>();
|
|
||||||
var lines = response.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(line))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var doc = JsonDocument.Parse(line);
|
|
||||||
var root = doc.RootElement;
|
|
||||||
|
|
||||||
var result = new ClassificationResult
|
|
||||||
{
|
|
||||||
Reason = root.GetProperty("reason").GetString() ?? string.Empty,
|
|
||||||
Classify = root.GetProperty("classify").GetString() ?? string.Empty,
|
|
||||||
Type = (TransactionType)root.GetProperty("type").GetInt32(),
|
|
||||||
Confidence = 0.9 // 可从 AI 响应中解析
|
|
||||||
};
|
|
||||||
|
|
||||||
results.Add(result);
|
|
||||||
}
|
|
||||||
catch (JsonException ex)
|
|
||||||
{
|
|
||||||
logger.LogWarning(ex, "解析 AI 响应行失败: {Line}", line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.LogInformation("AI 分类完成,得到 {Count} 条结果", results.Count);
|
|
||||||
return results.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Agents.AI;
|
|
||||||
|
|
||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Agent Framework 依赖注入扩展
|
|
||||||
/// </summary>
|
|
||||||
public static class AgentFrameworkExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 注册 Agent Framework 相关服务
|
|
||||||
/// </summary>
|
|
||||||
public static IServiceCollection AddAgentFramework(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
// 注册 Tool Registry (Singleton - 无状态,全局共享)
|
|
||||||
services.AddSingleton<IToolRegistry, ToolRegistry>();
|
|
||||||
|
|
||||||
// 注册 Tools (Scoped - 因为依赖 Scoped Repository)
|
|
||||||
services.AddSingleton<ITransactionQueryTools, TransactionQueryTools>();
|
|
||||||
services.AddSingleton<ITextProcessingTools, TextProcessingTools>();
|
|
||||||
services.AddSingleton<IAITools, AITools>();
|
|
||||||
|
|
||||||
// 注册 Agents (Scoped - 因为依赖 Scoped Tools)
|
|
||||||
services.AddSingleton<ClassificationAgent>();
|
|
||||||
services.AddSingleton<ParsingAgent>();
|
|
||||||
services.AddSingleton<ImportAgent>();
|
|
||||||
|
|
||||||
// 注册 Service Facade (Scoped - 避免生命周期冲突)
|
|
||||||
services.AddSingleton<ISmartHandleServiceV2, SmartHandleServiceV2>();
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 初始化 Agent 框架的 Tools
|
|
||||||
/// 在应用启动时调用此方法
|
|
||||||
/// </summary>
|
|
||||||
public static void InitializeAgentTools(
|
|
||||||
this IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
var toolRegistry = serviceProvider.GetRequiredService<IToolRegistry>();
|
|
||||||
var logger = serviceProvider.GetRequiredService<ILogger<IToolRegistry>>();
|
|
||||||
|
|
||||||
logger.LogInformation("开始初始化 Agent Tools...");
|
|
||||||
|
|
||||||
// 这里可以注册更多的 Tool
|
|
||||||
// 目前大部分 Tool 被整合到了工具类中,后续可根据需要扩展
|
|
||||||
|
|
||||||
logger.LogInformation("Agent Tools 初始化完成");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Agent 执行结果的标准化输出模型
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">数据类型</typeparam>
|
|
||||||
public record AgentResult<T>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Agent 执行的主要数据结果
|
|
||||||
/// </summary>
|
|
||||||
public T Data { get; init; } = default!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 多轮提炼后的总结信息(3-5 句,包含关键指标)
|
|
||||||
/// </summary>
|
|
||||||
public string Summary { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Agent 执行的步骤链(用于可视化和调试)
|
|
||||||
/// </summary>
|
|
||||||
public List<ExecutionStep> Steps { get; init; } = new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 元数据(统计信息、性能指标等)
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<string, object?> Metadata { get; init; } = new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行是否成功
|
|
||||||
/// </summary>
|
|
||||||
public bool Success { get; init; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误信息(如果有的话)
|
|
||||||
/// </summary>
|
|
||||||
public string? Error { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Agent 执行步骤
|
|
||||||
/// </summary>
|
|
||||||
public record ExecutionStep
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 步骤名称
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 步骤描述
|
|
||||||
/// </summary>
|
|
||||||
public string Description { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 步骤状态:Pending, Running, Completed, Failed
|
|
||||||
/// </summary>
|
|
||||||
public string Status { get; init; } = "Pending";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行耗时(毫秒)
|
|
||||||
/// </summary>
|
|
||||||
public long DurationMs { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 步骤输出数据(可选)
|
|
||||||
/// </summary>
|
|
||||||
public object? Output { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误信息(如果步骤失败)
|
|
||||||
/// </summary>
|
|
||||||
public string? Error { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分类结果模型
|
|
||||||
/// </summary>
|
|
||||||
public record ClassificationResult
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 原始摘要
|
|
||||||
/// </summary>
|
|
||||||
public string Reason { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分类名称
|
|
||||||
/// </summary>
|
|
||||||
public string Classify { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 交易类型
|
|
||||||
/// </summary>
|
|
||||||
public TransactionType Type { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AI 置信度评分 (0-1)
|
|
||||||
/// </summary>
|
|
||||||
public double Confidence { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 影响的交易记录 ID
|
|
||||||
/// </summary>
|
|
||||||
public List<long> TransactionIds { get; init; } = new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 参考的相似记录
|
|
||||||
/// </summary>
|
|
||||||
public List<string> References { get; init; } = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 账单解析结果模型
|
|
||||||
/// </summary>
|
|
||||||
public record TransactionParseResult
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 金额
|
|
||||||
/// </summary>
|
|
||||||
public decimal Amount { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 摘要
|
|
||||||
/// </summary>
|
|
||||||
public string Reason { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 日期
|
|
||||||
/// </summary>
|
|
||||||
public DateTime Date { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 交易类型
|
|
||||||
/// </summary>
|
|
||||||
public TransactionType Type { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分类
|
|
||||||
/// </summary>
|
|
||||||
public string? Classify { get; init; }
|
|
||||||
}
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Agent 基类 - 提供通用的工作流编排能力
|
|
||||||
/// </summary>
|
|
||||||
public abstract class BaseAgent
|
|
||||||
{
|
|
||||||
protected readonly IToolRegistry _toolRegistry;
|
|
||||||
protected readonly ILogger<BaseAgent> _logger;
|
|
||||||
protected readonly List<ExecutionStep> _steps = new();
|
|
||||||
protected readonly Dictionary<string, object?> _metadata = new();
|
|
||||||
|
|
||||||
// 定义 ActivitySource 供 DevUI 捕获
|
|
||||||
private static readonly ActivitySource _activitySource = new("Microsoft.Agents.Workflows");
|
|
||||||
|
|
||||||
protected BaseAgent(
|
|
||||||
IToolRegistry toolRegistry,
|
|
||||||
ILogger<BaseAgent> logger)
|
|
||||||
{
|
|
||||||
_toolRegistry = toolRegistry;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 记录执行步骤
|
|
||||||
/// </summary>
|
|
||||||
protected void RecordStep(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
object? output = null,
|
|
||||||
long durationMs = 0)
|
|
||||||
{
|
|
||||||
var step = new ExecutionStep
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Status = "Completed",
|
|
||||||
Output = output,
|
|
||||||
DurationMs = durationMs
|
|
||||||
};
|
|
||||||
|
|
||||||
_steps.Add(step);
|
|
||||||
|
|
||||||
// 使用 Activity 进行埋点,将被 DevUI 自动捕获
|
|
||||||
using var activity = _activitySource.StartActivity(name);
|
|
||||||
activity?.SetTag("agent.step.description", description);
|
|
||||||
if (output != null) activity?.SetTag("agent.step.output", output.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 记录失败的步骤
|
|
||||||
/// </summary>
|
|
||||||
protected void RecordFailedStep(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
string error,
|
|
||||||
long durationMs = 0)
|
|
||||||
{
|
|
||||||
var step = new ExecutionStep
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Status = "Failed",
|
|
||||||
Error = error,
|
|
||||||
DurationMs = durationMs
|
|
||||||
};
|
|
||||||
|
|
||||||
_steps.Add(step);
|
|
||||||
|
|
||||||
using var activity = _activitySource.StartActivity($"{name} (Failed)");
|
|
||||||
activity?.SetTag("agent.step.error", error);
|
|
||||||
_logger.LogError("[Agent步骤失败] {StepName}: {Error}", name, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置元数据
|
|
||||||
/// </summary>
|
|
||||||
protected void SetMetadata(string key, object? value)
|
|
||||||
{
|
|
||||||
_metadata[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取执行日志
|
|
||||||
/// </summary>
|
|
||||||
protected List<ExecutionStep> GetExecutionLog()
|
|
||||||
{
|
|
||||||
return _steps.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 生成多轮总结
|
|
||||||
/// </summary>
|
|
||||||
protected virtual async Task<string> GenerateSummaryAsync(
|
|
||||||
string[] phases,
|
|
||||||
Dictionary<string, object?> phaseResults)
|
|
||||||
{
|
|
||||||
var summaryParts = new List<string>();
|
|
||||||
|
|
||||||
// 简单的总结生成逻辑
|
|
||||||
// 实际项目中可以集成 AI 生成更复杂的总结
|
|
||||||
foreach (var phase in phases)
|
|
||||||
{
|
|
||||||
if (phaseResults.TryGetValue(phase, out var result))
|
|
||||||
{
|
|
||||||
summaryParts.Add($"{phase}:已完成");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return await Task.FromResult(string.Join(";", summaryParts) + "。");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用 Tool(简化接口)
|
|
||||||
/// </summary>
|
|
||||||
protected async Task<TResult> CallToolAsync<TResult>(
|
|
||||||
string toolName,
|
|
||||||
string stepName,
|
|
||||||
string stepDescription)
|
|
||||||
{
|
|
||||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogInformation("开始执行 Tool: {ToolName}", toolName);
|
|
||||||
var result = await _toolRegistry.InvokeToolAsync<TResult>(toolName);
|
|
||||||
sw.Stop();
|
|
||||||
|
|
||||||
RecordStep(stepName, stepDescription, result, sw.ElapsedMilliseconds);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
RecordFailedStep(stepName, stepDescription, ex.Message, sw.ElapsedMilliseconds);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用带参数的 Tool
|
|
||||||
/// </summary>
|
|
||||||
protected async Task<TResult> CallToolAsync<TParam, TResult>(
|
|
||||||
string toolName,
|
|
||||||
TParam param,
|
|
||||||
string stepName,
|
|
||||||
string stepDescription)
|
|
||||||
{
|
|
||||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogInformation("开始执行 Tool: {ToolName},参数: {Param}", toolName, param);
|
|
||||||
var result = await _toolRegistry.InvokeToolAsync<TParam, TResult>(toolName, param);
|
|
||||||
sw.Stop();
|
|
||||||
|
|
||||||
RecordStep(stepName, stepDescription, result, sw.ElapsedMilliseconds);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
RecordFailedStep(stepName, stepDescription, ex.Message, sw.ElapsedMilliseconds);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用带多参数的 Tool
|
|
||||||
/// </summary>
|
|
||||||
protected async Task<TResult> CallToolAsync<TParam1, TParam2, TResult>(
|
|
||||||
string toolName,
|
|
||||||
TParam1 param1,
|
|
||||||
TParam2 param2,
|
|
||||||
string stepName,
|
|
||||||
string stepDescription)
|
|
||||||
{
|
|
||||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogInformation("开始执行 Tool: {ToolName},参数: {Param1}, {Param2}", toolName, param1, param2);
|
|
||||||
var result = await _toolRegistry.InvokeToolAsync<TParam1, TParam2, TResult>(
|
|
||||||
toolName, param1, param2);
|
|
||||||
sw.Stop();
|
|
||||||
|
|
||||||
RecordStep(stepName, stepDescription, result, sw.ElapsedMilliseconds);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
RecordFailedStep(stepName, stepDescription, ex.Message, sw.ElapsedMilliseconds);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取 Agent 执行结果
|
|
||||||
/// </summary>
|
|
||||||
protected AgentResult<T> CreateResult<T>(
|
|
||||||
T data,
|
|
||||||
string summary,
|
|
||||||
bool success = true,
|
|
||||||
string? error = null)
|
|
||||||
{
|
|
||||||
return new AgentResult<T>
|
|
||||||
{
|
|
||||||
Data = data,
|
|
||||||
Summary = summary,
|
|
||||||
Steps = _steps,
|
|
||||||
Metadata = _metadata,
|
|
||||||
Success = success,
|
|
||||||
Error = error
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,301 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 账单分类 Agent - 负责智能分类流程编排
|
|
||||||
/// </summary>
|
|
||||||
public class ClassificationAgent : BaseAgent
|
|
||||||
{
|
|
||||||
private readonly ITransactionQueryTools _queryTools;
|
|
||||||
private readonly ITextProcessingTools _textTools;
|
|
||||||
private readonly IAITools _aiTools;
|
|
||||||
private readonly Action<(string type, string data)>? _progressCallback;
|
|
||||||
|
|
||||||
public ClassificationAgent(
|
|
||||||
IToolRegistry toolRegistry,
|
|
||||||
ITransactionQueryTools queryTools,
|
|
||||||
ITextProcessingTools textTools,
|
|
||||||
IAITools aiTools,
|
|
||||||
ILogger<ClassificationAgent> logger,
|
|
||||||
Action<(string type, string data)>? progressCallback = null
|
|
||||||
) : base(toolRegistry, logger)
|
|
||||||
{
|
|
||||||
_queryTools = queryTools;
|
|
||||||
_textTools = textTools;
|
|
||||||
_aiTools = aiTools;
|
|
||||||
_progressCallback = progressCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行智能分类工作流
|
|
||||||
/// </summary>
|
|
||||||
public async Task<AgentResult<ClassificationResult[]>> ExecuteAsync(
|
|
||||||
long[] transactionIds,
|
|
||||||
ITransactionCategoryRepository categoryRepository)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// ========== Phase 1: 数据采集阶段 ==========
|
|
||||||
ReportProgress("start", "开始分类,正在查询待分类账单");
|
|
||||||
|
|
||||||
var sampleRecords = await _queryTools.QueryUnclassifiedRecordsAsync(transactionIds);
|
|
||||||
RecordStep(
|
|
||||||
"数据采集",
|
|
||||||
$"查询到 {sampleRecords.Length} 条待分类账单",
|
|
||||||
sampleRecords.Length);
|
|
||||||
|
|
||||||
if (sampleRecords.Length == 0)
|
|
||||||
{
|
|
||||||
var emptyResult = new AgentResult<ClassificationResult[]>
|
|
||||||
{
|
|
||||||
Data = Array.Empty<ClassificationResult>(),
|
|
||||||
Summary = "未找到待分类的账单。",
|
|
||||||
Steps = _steps,
|
|
||||||
Metadata = _metadata,
|
|
||||||
Success = false,
|
|
||||||
Error = "没有待分类记录"
|
|
||||||
};
|
|
||||||
return emptyResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReportProgress("progress", $"找到 {sampleRecords.Length} 条待分类账单");
|
|
||||||
SetMetadata("sample_count", sampleRecords.Length);
|
|
||||||
|
|
||||||
// ========== Phase 2: 分析阶段 ==========
|
|
||||||
ReportProgress("progress", "正在进行分析...");
|
|
||||||
|
|
||||||
// 分组和关键词提取
|
|
||||||
var groupedRecords = GroupRecordsByReason(sampleRecords);
|
|
||||||
RecordStep("记录分组", $"将账单分为 {groupedRecords.Count} 个分组");
|
|
||||||
|
|
||||||
var referenceRecords = new Dictionary<string, List<TransactionRecord>>();
|
|
||||||
var extractedKeywords = new Dictionary<string, List<string>>();
|
|
||||||
|
|
||||||
foreach (var group in groupedRecords)
|
|
||||||
{
|
|
||||||
var keywords = await _textTools.ExtractKeywordsAsync(group.Reason);
|
|
||||||
extractedKeywords[group.Reason] = keywords;
|
|
||||||
|
|
||||||
if (keywords.Count > 0)
|
|
||||||
{
|
|
||||||
var similar = await _queryTools.QueryClassifiedByKeywordsAsync(keywords, minMatchRate: 0.4, limit: 10);
|
|
||||||
if (similar.Count > 0)
|
|
||||||
{
|
|
||||||
var topSimilar = similar.Take(5).Select(x => x.record).ToList();
|
|
||||||
referenceRecords[group.Reason] = topSimilar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordStep(
|
|
||||||
"关键词提取与相似度匹配",
|
|
||||||
$"为 {extractedKeywords.Count} 个摘要提取了关键词,找到 {referenceRecords.Count} 个参考记录",
|
|
||||||
referenceRecords.Count);
|
|
||||||
|
|
||||||
SetMetadata("groups_count", groupedRecords.Count);
|
|
||||||
SetMetadata("reference_records_count", referenceRecords.Count);
|
|
||||||
ReportProgress("progress", $"分析完成,共分组 {groupedRecords.Count} 个");
|
|
||||||
|
|
||||||
// ========== Phase 3: 决策阶段 ==========
|
|
||||||
_logger.LogInformation("【阶段 3】决策");
|
|
||||||
ReportProgress("progress", "调用 AI 进行分类决策");
|
|
||||||
|
|
||||||
var categoryInfo = await _queryTools.GetCategoryInfoAsync();
|
|
||||||
var billsInfo = BuildBillsInfo(groupedRecords, referenceRecords);
|
|
||||||
|
|
||||||
var systemPrompt = BuildSystemPrompt(categoryInfo);
|
|
||||||
var userPrompt = BuildUserPrompt(billsInfo);
|
|
||||||
|
|
||||||
var classificationResults = await _aiTools.ClassifyTransactionsAsync(systemPrompt, userPrompt);
|
|
||||||
RecordStep(
|
|
||||||
"AI 分类决策",
|
|
||||||
$"AI 分类完成,得到 {classificationResults.Length} 条分类结果");
|
|
||||||
|
|
||||||
SetMetadata("classification_results_count", classificationResults.Length);
|
|
||||||
|
|
||||||
// ========== Phase 4: 结果保存阶段 ==========
|
|
||||||
_logger.LogInformation("【阶段 4】保存结果");
|
|
||||||
ReportProgress("progress", "正在保存分类结果...");
|
|
||||||
|
|
||||||
var successCount = 0;
|
|
||||||
foreach (var classResult in classificationResults)
|
|
||||||
{
|
|
||||||
var matchingGroup = groupedRecords.FirstOrDefault(g => g.Reason == classResult.Reason);
|
|
||||||
if (matchingGroup.Reason == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach (var id in matchingGroup.Ids)
|
|
||||||
{
|
|
||||||
var success = await _queryTools.UpdateTransactionClassifyAsync(
|
|
||||||
id,
|
|
||||||
classResult.Classify,
|
|
||||||
classResult.Type);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
successCount++;
|
|
||||||
var resultJson = JsonSerializer.Serialize(new
|
|
||||||
{
|
|
||||||
id,
|
|
||||||
classResult.Classify,
|
|
||||||
classResult.Type
|
|
||||||
});
|
|
||||||
ReportProgress("data", resultJson);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordStep("保存结果", $"成功保存 {successCount} 条分类结果");
|
|
||||||
SetMetadata("saved_count", successCount);
|
|
||||||
|
|
||||||
// ========== 生成多轮总结 ==========
|
|
||||||
var summary = GenerateMultiPhaseSummary(
|
|
||||||
sampleRecords.Length,
|
|
||||||
groupedRecords.Count,
|
|
||||||
classificationResults.Length,
|
|
||||||
successCount);
|
|
||||||
|
|
||||||
var finalResult = new AgentResult<ClassificationResult[]>
|
|
||||||
{
|
|
||||||
Data = classificationResults,
|
|
||||||
Summary = summary,
|
|
||||||
Steps = _steps,
|
|
||||||
Metadata = _metadata,
|
|
||||||
Success = true
|
|
||||||
};
|
|
||||||
|
|
||||||
ReportProgress("success", $"分类完成!{summary}");
|
|
||||||
_logger.LogInformation("=== 分类 Agent 执行完成 ===");
|
|
||||||
|
|
||||||
return finalResult;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "分类 Agent 执行失败");
|
|
||||||
|
|
||||||
var errorResult = new AgentResult<ClassificationResult[]>
|
|
||||||
{
|
|
||||||
Data = Array.Empty<ClassificationResult>(),
|
|
||||||
Summary = $"分类失败: {ex.Message}",
|
|
||||||
Steps = _steps,
|
|
||||||
Metadata = _metadata,
|
|
||||||
Success = false,
|
|
||||||
Error = ex.Message
|
|
||||||
};
|
|
||||||
|
|
||||||
ReportProgress("error", ex.Message);
|
|
||||||
return errorResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 辅助方法 ==========
|
|
||||||
|
|
||||||
private List<(string Reason, List<long> Ids, int Count, decimal TotalAmount, TransactionType SampleType)> GroupRecordsByReason(
|
|
||||||
TransactionRecord[] records)
|
|
||||||
{
|
|
||||||
var grouped = records
|
|
||||||
.GroupBy(r => r.Reason)
|
|
||||||
.Select(g => (
|
|
||||||
Reason: g.Key,
|
|
||||||
Ids: g.Select(r => r.Id).ToList(),
|
|
||||||
Count: g.Count(),
|
|
||||||
TotalAmount: g.Sum(r => r.Amount),
|
|
||||||
SampleType: g.First().Type
|
|
||||||
))
|
|
||||||
.OrderByDescending(g => Math.Abs(g.TotalAmount))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return grouped;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string BuildBillsInfo(
|
|
||||||
List<(string Reason, List<long> Ids, int Count, decimal TotalAmount, TransactionType SampleType)> groupedRecords,
|
|
||||||
Dictionary<string, List<TransactionRecord>> referenceRecords)
|
|
||||||
{
|
|
||||||
var billsInfo = new StringBuilder();
|
|
||||||
foreach (var (group, index) in groupedRecords.Select((g, i) => (g, i)))
|
|
||||||
{
|
|
||||||
billsInfo.AppendLine($"{index + 1}. 摘要={group.Reason}, 当前类型={GetTypeName(group.SampleType)}, 涉及金额={group.TotalAmount}");
|
|
||||||
|
|
||||||
if (referenceRecords.TryGetValue(group.Reason, out var references))
|
|
||||||
{
|
|
||||||
billsInfo.AppendLine(" 【参考】相似且已分类的账单:");
|
|
||||||
foreach (var refer in references.Take(3))
|
|
||||||
{
|
|
||||||
billsInfo.AppendLine($" - 摘要={refer.Reason}, 分类={refer.Classify}, 类型={GetTypeName(refer.Type)}, 金额={refer.Amount}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return billsInfo.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string BuildSystemPrompt(string categoryInfo)
|
|
||||||
{
|
|
||||||
return $$"""
|
|
||||||
你是一个专业的账单分类助手。请根据提供的账单分组信息和分类列表,为每个分组选择最合适的分类。
|
|
||||||
|
|
||||||
可用的分类列表:
|
|
||||||
{{categoryInfo}}
|
|
||||||
|
|
||||||
分类规则:
|
|
||||||
1. 根据账单的摘要和涉及金额,选择最匹配的分类
|
|
||||||
2. 如果提供了【参考】信息,优先参考相似账单的分类,这些是历史上已分类的相似账单
|
|
||||||
3. 如果无法确定分类,可以选择"其他"
|
|
||||||
4. 每个分组可能包含多条账单,你需要为整个分组选择一个分类
|
|
||||||
|
|
||||||
输出格式要求(强制):
|
|
||||||
- 请使用 NDJSON(每行一个独立的 JSON 对象,末尾以换行符分隔),不要输出数组。
|
|
||||||
- 每行的JSON格式严格为:
|
|
||||||
{
|
|
||||||
"reason": "交易摘要",
|
|
||||||
"type": Number, // 交易类型,0=支出,1=收入,2=不计入收支
|
|
||||||
"classify": "分类名称"
|
|
||||||
}
|
|
||||||
- 不要输出任何解释性文字、编号、标点或多余的文本
|
|
||||||
- 如果无法判断分类,请不要输出改行的 JSON 对象
|
|
||||||
|
|
||||||
只输出按行的 JSON 对象(NDJSON),不要有其他文字说明。
|
|
||||||
""";
|
|
||||||
}
|
|
||||||
|
|
||||||
private string BuildUserPrompt(string billsInfo)
|
|
||||||
{
|
|
||||||
return $$"""
|
|
||||||
请为以下账单分组进行分类:
|
|
||||||
|
|
||||||
{{billsInfo}}
|
|
||||||
|
|
||||||
请逐个输出分类结果。
|
|
||||||
""";
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateMultiPhaseSummary(
|
|
||||||
int sampleCount,
|
|
||||||
int groupCount,
|
|
||||||
int classificationCount,
|
|
||||||
int savedCount)
|
|
||||||
{
|
|
||||||
var highConfidenceCount = savedCount; // 简化,实际可从 Confidence 字段计算
|
|
||||||
var confidenceRate = sampleCount > 0 ? (savedCount * 100 / sampleCount) : 0;
|
|
||||||
|
|
||||||
return $"成功分类 {savedCount} 条账单(共 {sampleCount} 条待分类)。" +
|
|
||||||
$"分为 {groupCount} 个分组,AI 给出 {classificationCount} 条分类建议。" +
|
|
||||||
$"分类完成度 {confidenceRate}%,所有结果已保存。";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReportProgress(string type, string data)
|
|
||||||
{
|
|
||||||
_progressCallback?.Invoke((type, data));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetTypeName(TransactionType type)
|
|
||||||
{
|
|
||||||
return type switch
|
|
||||||
{
|
|
||||||
TransactionType.Expense => "支出",
|
|
||||||
TransactionType.Income => "收入",
|
|
||||||
TransactionType.None => "不计入",
|
|
||||||
_ => "未知"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 的定义和元数据
|
|
||||||
/// </summary>
|
|
||||||
public record ToolDefinition
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 唯一标识
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 描述
|
|
||||||
/// </summary>
|
|
||||||
public string Description { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 对应的委托
|
|
||||||
/// </summary>
|
|
||||||
public Delegate Handler { get; init; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 所属类别
|
|
||||||
/// </summary>
|
|
||||||
public string Category { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 是否可缓存
|
|
||||||
/// </summary>
|
|
||||||
public bool Cacheable { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool Registry 接口 - 管理所有可用的 Tools
|
|
||||||
/// </summary>
|
|
||||||
public interface IToolRegistry
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 注册一个 Tool
|
|
||||||
/// </summary>
|
|
||||||
void RegisterTool<TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 注册一个带参数的 Tool
|
|
||||||
/// </summary>
|
|
||||||
void RegisterTool<TParam, TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<TParam, Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 注册一个带多参数的 Tool
|
|
||||||
/// </summary>
|
|
||||||
void RegisterTool<TParam1, TParam2, TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<TParam1, TParam2, Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取 Tool 定义
|
|
||||||
/// </summary>
|
|
||||||
ToolDefinition? GetToolDefinition(string name);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有 Tools
|
|
||||||
/// </summary>
|
|
||||||
IEnumerable<ToolDefinition> GetAllTools();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 按类别获取 Tools
|
|
||||||
/// </summary>
|
|
||||||
IEnumerable<ToolDefinition> GetToolsByCategory(string category);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用无参 Tool
|
|
||||||
/// </summary>
|
|
||||||
Task<TResult> InvokeToolAsync<TResult>(string toolName);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用带参 Tool
|
|
||||||
/// </summary>
|
|
||||||
Task<TResult> InvokeToolAsync<TParam, TResult>(string toolName, TParam param);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 调用带多参 Tool
|
|
||||||
/// </summary>
|
|
||||||
Task<TResult> InvokeToolAsync<TParam1, TParam2, TResult>(
|
|
||||||
string toolName,
|
|
||||||
TParam1 param1,
|
|
||||||
TParam2 param2);
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件导入 Agent - 处理支付宝、微信等账单导入
|
|
||||||
/// </summary>
|
|
||||||
public class ImportAgent : BaseAgent
|
|
||||||
{
|
|
||||||
private readonly ITransactionQueryTools _queryTools;
|
|
||||||
private readonly ILogger<ImportAgent> _importLogger;
|
|
||||||
|
|
||||||
public ImportAgent(
|
|
||||||
IToolRegistry toolRegistry,
|
|
||||||
ITransactionQueryTools queryTools,
|
|
||||||
ILogger<ImportAgent> logger,
|
|
||||||
ILogger<ImportAgent> importLogger
|
|
||||||
) : base(toolRegistry, logger)
|
|
||||||
{
|
|
||||||
_queryTools = queryTools;
|
|
||||||
_importLogger = importLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行批量导入流程
|
|
||||||
/// </summary>
|
|
||||||
public async Task<AgentResult<ImportResult>> ExecuteAsync(
|
|
||||||
Dictionary<string, string>[] rows,
|
|
||||||
string source,
|
|
||||||
Func<Dictionary<string, string>, Task<TransactionRecord?>> transformAsync)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Phase 1: 数据验证
|
|
||||||
RecordStep("数据验证", $"验证 {rows.Length} 条记录");
|
|
||||||
SetMetadata("total_rows", rows.Length);
|
|
||||||
|
|
||||||
var importNos = rows
|
|
||||||
.Select(r => r.ContainsKey("交易号") ? r["交易号"] : null)
|
|
||||||
.Where(no => !string.IsNullOrWhiteSpace(no))
|
|
||||||
.Cast<string>()
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
if (importNos.Length == 0)
|
|
||||||
{
|
|
||||||
var emptyResult = new ImportResult
|
|
||||||
{
|
|
||||||
TotalCount = rows.Length,
|
|
||||||
AddedCount = 0,
|
|
||||||
UpdatedCount = 0,
|
|
||||||
SkippedCount = rows.Length
|
|
||||||
};
|
|
||||||
|
|
||||||
return CreateResult(
|
|
||||||
emptyResult,
|
|
||||||
"导入失败:找不到有效的交易号。",
|
|
||||||
false,
|
|
||||||
"No valid transaction numbers found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Phase 2: 批量检查存在性
|
|
||||||
_logger.LogInformation("【阶段 2】批量检查存在性");
|
|
||||||
var existenceMap = await _queryTools.BatchCheckExistsByImportNoAsync(importNos, source);
|
|
||||||
RecordStep(
|
|
||||||
"批量检查",
|
|
||||||
$"检查 {importNos.Length} 条记录,其中 {existenceMap.Values.Count(v => v)} 条已存在");
|
|
||||||
|
|
||||||
SetMetadata("existing_count", existenceMap.Values.Count(v => v));
|
|
||||||
SetMetadata("new_count", existenceMap.Values.Count(v => !v));
|
|
||||||
|
|
||||||
// Phase 3: 数据转换和冲突解决
|
|
||||||
_logger.LogInformation("【阶段 3】数据转换和冲突解决");
|
|
||||||
var addRecords = new List<TransactionRecord>();
|
|
||||||
var updateRecords = new List<TransactionRecord>();
|
|
||||||
var skippedCount = 0;
|
|
||||||
|
|
||||||
foreach (var row in rows)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var importNo = row.ContainsKey("交易号") ? row["交易号"] : null;
|
|
||||||
if (string.IsNullOrWhiteSpace(importNo))
|
|
||||||
{
|
|
||||||
skippedCount++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var transformed = await transformAsync(row);
|
|
||||||
if (transformed == null)
|
|
||||||
{
|
|
||||||
skippedCount++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
transformed.ImportNo = importNo;
|
|
||||||
transformed.ImportFrom = source;
|
|
||||||
|
|
||||||
var exists = existenceMap.GetValueOrDefault(importNo, false);
|
|
||||||
if (exists)
|
|
||||||
{
|
|
||||||
updateRecords.Add(transformed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addRecords.Add(transformed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_importLogger.LogWarning(ex, "转换记录失败: {Row}", row);
|
|
||||||
skippedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordStep(
|
|
||||||
"数据转换",
|
|
||||||
$"转换完成:新增 {addRecords.Count},更新 {updateRecords.Count},跳过 {skippedCount}");
|
|
||||||
|
|
||||||
SetMetadata("add_count", addRecords.Count);
|
|
||||||
SetMetadata("update_count", updateRecords.Count);
|
|
||||||
SetMetadata("skip_count", skippedCount);
|
|
||||||
|
|
||||||
// Phase 4: 批量保存
|
|
||||||
_logger.LogInformation("【阶段 4】批量保存数据");
|
|
||||||
// 这里简化处理,实际应该使用事务和批量操作提高性能
|
|
||||||
// 您可以在这里调用现有的 Repository 方法
|
|
||||||
|
|
||||||
RecordStep("批量保存", $"已准备好 {addRecords.Count + updateRecords.Count} 条待保存记录");
|
|
||||||
|
|
||||||
var importResult = new ImportResult
|
|
||||||
{
|
|
||||||
TotalCount = rows.Length,
|
|
||||||
AddedCount = addRecords.Count,
|
|
||||||
UpdatedCount = updateRecords.Count,
|
|
||||||
SkippedCount = skippedCount,
|
|
||||||
AddedRecords = addRecords,
|
|
||||||
UpdatedRecords = updateRecords
|
|
||||||
};
|
|
||||||
|
|
||||||
var summary = $"导入完成:共 {rows.Length} 条记录,新增 {addRecords.Count},更新 {updateRecords.Count},跳过 {skippedCount}。";
|
|
||||||
|
|
||||||
_logger.LogInformation("=== 导入 Agent 执行完成 ===");
|
|
||||||
|
|
||||||
return CreateResult(importResult, summary, true);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "导入 Agent 执行失败");
|
|
||||||
return CreateResult(
|
|
||||||
new ImportResult { TotalCount = rows.Length },
|
|
||||||
$"导入失败: {ex.Message}",
|
|
||||||
false,
|
|
||||||
ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 导入结果
|
|
||||||
/// </summary>
|
|
||||||
public record ImportResult
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 总记录数
|
|
||||||
/// </summary>
|
|
||||||
public int TotalCount { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增数
|
|
||||||
/// </summary>
|
|
||||||
public int AddedCount { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新数
|
|
||||||
/// </summary>
|
|
||||||
public int UpdatedCount { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 跳过数
|
|
||||||
/// </summary>
|
|
||||||
public int SkippedCount { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增的记录(可选)
|
|
||||||
/// </summary>
|
|
||||||
public List<TransactionRecord> AddedRecords { get; init; } = new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新的记录(可选)
|
|
||||||
/// </summary>
|
|
||||||
public List<TransactionRecord> UpdatedRecords { get; init; } = new();
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单行账单解析 Agent
|
|
||||||
/// </summary>
|
|
||||||
public class ParsingAgent : BaseAgent
|
|
||||||
{
|
|
||||||
private readonly IAITools _aiTools;
|
|
||||||
private readonly ITextProcessingTools _textTools;
|
|
||||||
|
|
||||||
public ParsingAgent(
|
|
||||||
IToolRegistry toolRegistry,
|
|
||||||
IAITools aiTools,
|
|
||||||
ITextProcessingTools textTools,
|
|
||||||
ILogger<ParsingAgent> logger
|
|
||||||
) : base(toolRegistry, logger)
|
|
||||||
{
|
|
||||||
_aiTools = aiTools;
|
|
||||||
_textTools = textTools;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析单行账单文本
|
|
||||||
/// </summary>
|
|
||||||
public async Task<AgentResult<TransactionParseResult?>> ExecuteAsync(string billText)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Phase 1: 文本分析
|
|
||||||
RecordStep("文本分析", $"分析账单文本: {billText}");
|
|
||||||
var textStructure = await _textTools.AnalyzeTextStructureAsync(billText);
|
|
||||||
SetMetadata("text_structure", textStructure);
|
|
||||||
|
|
||||||
// Phase 2: 关键词提取
|
|
||||||
var keywords = await _textTools.ExtractKeywordsAsync(billText);
|
|
||||||
RecordStep("关键词提取", $"提取到 {keywords.Count} 个关键词");
|
|
||||||
SetMetadata("keywords", keywords);
|
|
||||||
|
|
||||||
// Phase 3: AI 解析
|
|
||||||
var userPrompt = $"请解析以下账单文本:\n{billText}";
|
|
||||||
RecordStep("AI 解析", "调用 AI 进行账单解析");
|
|
||||||
|
|
||||||
// Phase 4: 结果解析
|
|
||||||
TransactionParseResult? parseResult = null;
|
|
||||||
|
|
||||||
var summary = parseResult != null
|
|
||||||
? $"成功解析账单:{parseResult.Reason},金额 {parseResult.Amount},日期 {parseResult.Date:yyyy-MM-dd}。"
|
|
||||||
: "账单解析失败,无法提取结构化数据。";
|
|
||||||
|
|
||||||
return CreateResult<TransactionParseResult?>(parseResult, summary, parseResult != null);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "解析 Agent 执行失败");
|
|
||||||
return CreateResult<TransactionParseResult?>(
|
|
||||||
null,
|
|
||||||
$"解析失败: {ex.Message}",
|
|
||||||
false,
|
|
||||||
ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文本处理工具集
|
|
||||||
/// </summary>
|
|
||||||
public interface ITextProcessingTools
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 提取关键词
|
|
||||||
/// </summary>
|
|
||||||
Task<List<string>> ExtractKeywordsAsync(string text);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分析文本结构
|
|
||||||
/// </summary>
|
|
||||||
Task<Dictionary<string, object?>> AnalyzeTextStructureAsync(string text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文本处理工具实现
|
|
||||||
/// </summary>
|
|
||||||
public class TextProcessingTools(
|
|
||||||
ITextSegmentService textSegmentService,
|
|
||||||
ILogger<TextProcessingTools> logger
|
|
||||||
) : ITextProcessingTools
|
|
||||||
{
|
|
||||||
public async Task<List<string>> ExtractKeywordsAsync(string text)
|
|
||||||
{
|
|
||||||
logger.LogDebug("提取关键词: {Text}", text);
|
|
||||||
|
|
||||||
var keywords = await Task.FromResult(textSegmentService.ExtractKeywords(text));
|
|
||||||
|
|
||||||
logger.LogDebug("提取到 {Count} 个关键词: {Keywords}",
|
|
||||||
keywords.Count,
|
|
||||||
string.Join(", ", keywords));
|
|
||||||
|
|
||||||
return keywords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Dictionary<string, object?>> AnalyzeTextStructureAsync(string text)
|
|
||||||
{
|
|
||||||
logger.LogDebug("分析文本结构");
|
|
||||||
|
|
||||||
return await Task.FromResult(new Dictionary<string, object?>
|
|
||||||
{
|
|
||||||
["length"] = text.Length,
|
|
||||||
["wordCount"] = text.Split(' ').Length,
|
|
||||||
["timestamp"] = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tool 注册表实现
|
|
||||||
/// </summary>
|
|
||||||
public class ToolRegistry : IToolRegistry
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string, ToolDefinition> _tools = new();
|
|
||||||
private readonly ILogger<ToolRegistry> _logger;
|
|
||||||
|
|
||||||
public ToolRegistry(ILogger<ToolRegistry> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterTool<TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
|
||||||
throw new ArgumentException("Tool 名称不能为空", nameof(name));
|
|
||||||
|
|
||||||
var toolDef = new ToolDefinition
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Handler = handler,
|
|
||||||
Category = category,
|
|
||||||
Cacheable = cacheable
|
|
||||||
};
|
|
||||||
|
|
||||||
_tools[name] = toolDef;
|
|
||||||
_logger.LogInformation("已注册 Tool: {ToolName} (类别: {Category})", name, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterTool<TParam, TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<TParam, Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
|
||||||
throw new ArgumentException("Tool 名称不能为空", nameof(name));
|
|
||||||
|
|
||||||
var toolDef = new ToolDefinition
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Handler = handler,
|
|
||||||
Category = category,
|
|
||||||
Cacheable = cacheable
|
|
||||||
};
|
|
||||||
|
|
||||||
_tools[name] = toolDef;
|
|
||||||
_logger.LogInformation("已注册 Tool: {ToolName} (类别: {Category})", name, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterTool<TParam1, TParam2, TResult>(
|
|
||||||
string name,
|
|
||||||
string description,
|
|
||||||
Func<TParam1, TParam2, Task<TResult>> handler,
|
|
||||||
string category = "General",
|
|
||||||
bool cacheable = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
|
||||||
throw new ArgumentException("Tool 名称不能为空", nameof(name));
|
|
||||||
|
|
||||||
var toolDef = new ToolDefinition
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Handler = handler,
|
|
||||||
Category = category,
|
|
||||||
Cacheable = cacheable
|
|
||||||
};
|
|
||||||
|
|
||||||
_tools[name] = toolDef;
|
|
||||||
_logger.LogInformation("已注册 Tool: {ToolName} (类别: {Category})", name, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ToolDefinition? GetToolDefinition(string name)
|
|
||||||
{
|
|
||||||
return _tools.TryGetValue(name, out var tool) ? tool : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<ToolDefinition> GetAllTools()
|
|
||||||
{
|
|
||||||
return _tools.Values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<ToolDefinition> GetToolsByCategory(string category)
|
|
||||||
{
|
|
||||||
return _tools.Values.Where(t => t.Category == category);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<TResult> InvokeToolAsync<TResult>(string toolName)
|
|
||||||
{
|
|
||||||
if (!_tools.TryGetValue(toolName, out var toolDef))
|
|
||||||
throw new InvalidOperationException($"未找到 Tool: {toolName}");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogDebug("调用 Tool: {ToolName}", toolName);
|
|
||||||
|
|
||||||
if (toolDef.Handler is Func<Task<TResult>> handler)
|
|
||||||
{
|
|
||||||
var result = await handler();
|
|
||||||
_logger.LogDebug("Tool {ToolName} 执行成功", toolName);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException($"Tool {toolName} 签名不匹配");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Tool {ToolName} 执行失败", toolName);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<TResult> InvokeToolAsync<TParam, TResult>(string toolName, TParam param)
|
|
||||||
{
|
|
||||||
if (!_tools.TryGetValue(toolName, out var toolDef))
|
|
||||||
throw new InvalidOperationException($"未找到 Tool: {toolName}");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogDebug("调用 Tool: {ToolName}, 参数: {Param}", toolName, param);
|
|
||||||
|
|
||||||
if (toolDef.Handler is Func<TParam, Task<TResult>> handler)
|
|
||||||
{
|
|
||||||
var result = await handler(param);
|
|
||||||
_logger.LogDebug("Tool {ToolName} 执行成功", toolName);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException($"Tool {toolName} 签名不匹配");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Tool {ToolName} 执行失败", toolName);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<TResult> InvokeToolAsync<TParam1, TParam2, TResult>(
|
|
||||||
string toolName,
|
|
||||||
TParam1 param1,
|
|
||||||
TParam2 param2)
|
|
||||||
{
|
|
||||||
if (!_tools.TryGetValue(toolName, out var toolDef))
|
|
||||||
throw new InvalidOperationException($"未找到 Tool: {toolName}");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogDebug("调用 Tool: {ToolName}, 参数: {Param1}, {Param2}", toolName, param1, param2);
|
|
||||||
|
|
||||||
if (toolDef.Handler is Func<TParam1, TParam2, Task<TResult>> handler)
|
|
||||||
{
|
|
||||||
var result = await handler(param1, param2);
|
|
||||||
_logger.LogDebug("Tool {ToolName} 执行成功", toolName);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException($"Tool {toolName} 签名不匹配");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Tool {ToolName} 执行失败", toolName);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
namespace Service.AgentFramework;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 账单分类查询工具集
|
|
||||||
/// </summary>
|
|
||||||
public interface ITransactionQueryTools
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 查询待分类的账单记录
|
|
||||||
/// </summary>
|
|
||||||
Task<TransactionRecord[]> QueryUnclassifiedRecordsAsync(long[] transactionIds);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 按关键词查询已分类的相似记录(带评分)
|
|
||||||
/// </summary>
|
|
||||||
Task<List<(TransactionRecord record, double relevanceScore)>> QueryClassifiedByKeywordsAsync(
|
|
||||||
List<string> keywords,
|
|
||||||
double minMatchRate = 0.4,
|
|
||||||
int limit = 10);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 批量查询账单是否已存在(按导入编号)
|
|
||||||
/// </summary>
|
|
||||||
Task<Dictionary<string, bool>> BatchCheckExistsByImportNoAsync(
|
|
||||||
string[] importNos,
|
|
||||||
string source);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有分类信息
|
|
||||||
/// </summary>
|
|
||||||
Task<string> GetCategoryInfoAsync();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新账单分类信息
|
|
||||||
/// </summary>
|
|
||||||
Task<bool> UpdateTransactionClassifyAsync(
|
|
||||||
long transactionId,
|
|
||||||
string classify,
|
|
||||||
TransactionType type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 账单分类查询工具实现
|
|
||||||
/// </summary>
|
|
||||||
public class TransactionQueryTools(
|
|
||||||
ITransactionRecordRepository transactionRepository,
|
|
||||||
ITransactionCategoryRepository categoryRepository,
|
|
||||||
ILogger<TransactionQueryTools> logger
|
|
||||||
) : ITransactionQueryTools
|
|
||||||
{
|
|
||||||
public async Task<TransactionRecord[]> QueryUnclassifiedRecordsAsync(long[] transactionIds)
|
|
||||||
{
|
|
||||||
logger.LogInformation("查询待分类记录,ID 数量: {Count}", transactionIds.Length);
|
|
||||||
|
|
||||||
var records = await transactionRepository.GetByIdsAsync(transactionIds);
|
|
||||||
var unclassified = records
|
|
||||||
.Where(x => string.IsNullOrEmpty(x.Classify))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
logger.LogInformation("找到 {Count} 条待分类记录", unclassified.Length);
|
|
||||||
return unclassified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<(TransactionRecord record, double relevanceScore)>> QueryClassifiedByKeywordsAsync(
|
|
||||||
List<string> keywords,
|
|
||||||
double minMatchRate = 0.4,
|
|
||||||
int limit = 10)
|
|
||||||
{
|
|
||||||
logger.LogInformation("按关键词查询相似记录,关键词: {Keywords}", string.Join(", ", keywords));
|
|
||||||
|
|
||||||
var result = await transactionRepository.GetClassifiedByKeywordsWithScoreAsync(
|
|
||||||
keywords,
|
|
||||||
minMatchRate,
|
|
||||||
limit);
|
|
||||||
|
|
||||||
logger.LogInformation("找到 {Count} 条相似记录,相关度分数: {Scores}",
|
|
||||||
result.Count,
|
|
||||||
string.Join(", ", result.Select(x => $"{x.record.Reason}({x.relevanceScore:F2})")));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Dictionary<string, bool>> BatchCheckExistsByImportNoAsync(
|
|
||||||
string[] importNos,
|
|
||||||
string source)
|
|
||||||
{
|
|
||||||
logger.LogInformation("批量检查导入编号是否存在,数量: {Count},来源: {Source}",
|
|
||||||
importNos.Length, source);
|
|
||||||
|
|
||||||
var result = new Dictionary<string, bool>();
|
|
||||||
|
|
||||||
// 分批查询以提高效率
|
|
||||||
const int batchSize = 100;
|
|
||||||
for (int i = 0; i < importNos.Length; i += batchSize)
|
|
||||||
{
|
|
||||||
var batch = importNos.Skip(i).Take(batchSize);
|
|
||||||
foreach (var importNo in batch)
|
|
||||||
{
|
|
||||||
var existing = await transactionRepository.ExistsByImportNoAsync(importNo, source);
|
|
||||||
result[importNo] = existing != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var existCount = result.Values.Count(v => v);
|
|
||||||
logger.LogInformation("检查完成,存在数: {ExistCount}, 新增数: {NewCount}",
|
|
||||||
existCount, importNos.Length - existCount);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> GetCategoryInfoAsync()
|
|
||||||
{
|
|
||||||
logger.LogInformation("获取分类信息");
|
|
||||||
|
|
||||||
var categories = await categoryRepository.GetAllAsync();
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.AppendLine("可用分类列表:");
|
|
||||||
foreach (var cat in categories)
|
|
||||||
{
|
|
||||||
sb.AppendLine($"- {cat.Name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> UpdateTransactionClassifyAsync(
|
|
||||||
long transactionId,
|
|
||||||
string classify,
|
|
||||||
TransactionType type)
|
|
||||||
{
|
|
||||||
logger.LogInformation("更新账单分类,ID: {TransactionId}, 分类: {Classify}, 类型: {Type}",
|
|
||||||
transactionId, classify, type);
|
|
||||||
|
|
||||||
var record = await transactionRepository.GetByIdAsync(transactionId);
|
|
||||||
if (record == null)
|
|
||||||
{
|
|
||||||
logger.LogWarning("未找到交易记录,ID: {TransactionId}", transactionId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
record.Classify = classify;
|
|
||||||
record.Type = type;
|
|
||||||
|
|
||||||
var result = await transactionRepository.UpdateAsync(record);
|
|
||||||
logger.LogInformation("账单分类更新结果: {Success}", result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -14,4 +14,3 @@ global using System.Text.Json.Serialization;
|
|||||||
global using System.Text.Json.Nodes;
|
global using System.Text.Json.Nodes;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Common;
|
global using Common;
|
||||||
global using Service.AgentFramework;
|
|
||||||
@@ -23,6 +23,8 @@ public class BudgetArchiveJob(
|
|||||||
|
|
||||||
using var scope = serviceProvider.CreateScope();
|
using var scope = serviceProvider.CreateScope();
|
||||||
var budgetService = scope.ServiceProvider.GetRequiredService<IBudgetService>();
|
var budgetService = scope.ServiceProvider.GetRequiredService<IBudgetService>();
|
||||||
|
|
||||||
|
// 归档月度数据
|
||||||
var result = await budgetService.ArchiveBudgetsAsync(year, month);
|
var result = await budgetService.ArchiveBudgetsAsync(year, month);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(result))
|
if (string.IsNullOrEmpty(result))
|
||||||
|
|||||||
@@ -6,15 +6,14 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MailKit" />
|
<PackageReference Include="MailKit" />
|
||||||
<PackageReference Include="Microsoft.Agents.AI" />
|
|
||||||
<PackageReference Include="MimeKit" />
|
<PackageReference Include="MimeKit" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" />
|
|
||||||
<PackageReference Include="Serilog" />
|
<PackageReference Include="Serilog" />
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" />
|
<PackageReference Include="Serilog.Extensions.Logging" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" />
|
||||||
<PackageReference Include="CsvHelper" />
|
<PackageReference Include="CsvHelper" />
|
||||||
<PackageReference Include="EPPlus" />
|
<PackageReference Include="EPPlus" />
|
||||||
<PackageReference Include="HtmlAgilityPack" />
|
<PackageReference Include="HtmlAgilityPack" />
|
||||||
@@ -23,7 +22,6 @@
|
|||||||
<PackageReference Include="JiebaNet.Analyser" />
|
<PackageReference Include="JiebaNet.Analyser" />
|
||||||
<PackageReference Include="Newtonsoft.Json" />
|
<PackageReference Include="Newtonsoft.Json" />
|
||||||
<PackageReference Include="WebPush" />
|
<PackageReference Include="WebPush" />
|
||||||
<PackageReference Include="Microsoft.Extensions.AI" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
namespace Service;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 智能处理服务 - 使用 Agent Framework 重构
|
|
||||||
/// </summary>
|
|
||||||
public interface ISmartHandleServiceV2
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 使用 Agent Framework 进行智能分类
|
|
||||||
/// </summary>
|
|
||||||
Task<AgentResult<ClassificationResult[]>> SmartClassifyAgentAsync(
|
|
||||||
long[] transactionIds,
|
|
||||||
Action<(string type, string data)> chunkAction);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用 Agent Framework 解析单行账单
|
|
||||||
/// </summary>
|
|
||||||
Task<AgentResult<AgentFramework.TransactionParseResult?>> ParseOneLineBillAgentAsync(string text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 智能处理服务实现 - Agent Framework 版本
|
|
||||||
/// </summary>
|
|
||||||
public class SmartHandleServiceV2(
|
|
||||||
ClassificationAgent classificationAgent,
|
|
||||||
ParsingAgent parsingAgent,
|
|
||||||
ITransactionCategoryRepository categoryRepository,
|
|
||||||
ILogger<SmartHandleServiceV2> logger
|
|
||||||
) : ISmartHandleServiceV2
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 使用 Agent Framework 进行智能分类
|
|
||||||
/// </summary>
|
|
||||||
public async Task<AgentResult<ClassificationResult[]>> SmartClassifyAgentAsync(
|
|
||||||
long[] transactionIds,
|
|
||||||
Action<(string type, string data)> chunkAction)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
logger.LogInformation("开始执行智能分类 Agent,ID 数量: {Count}", transactionIds.Length);
|
|
||||||
|
|
||||||
var result = await classificationAgent.ExecuteAsync(transactionIds, categoryRepository);
|
|
||||||
|
|
||||||
logger.LogInformation("分类完成:{Summary}", result.Summary);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "智能分类 Agent 执行失败");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用 Agent Framework 解析单行账单
|
|
||||||
/// </summary>
|
|
||||||
public async Task<AgentResult<AgentFramework.TransactionParseResult?>> ParseOneLineBillAgentAsync(string text)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
logger.LogInformation("开始解析账单: {Text}", text);
|
|
||||||
|
|
||||||
var result = await parsingAgent.ExecuteAsync(text);
|
|
||||||
|
|
||||||
if (result.Success)
|
|
||||||
{
|
|
||||||
logger.LogInformation("解析成功: {Summary}", result.Summary);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.LogWarning("解析失败: {Error}", result.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "解析 Agent 执行失败");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -2,5 +2,6 @@
|
|||||||
"$schema": "https://json.schemastore.org/prettierrc",
|
"$schema": "https://json.schemastore.org/prettierrc",
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"printWidth": 100
|
"printWidth": 100,
|
||||||
|
"trailingComma": "none"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,82 @@
|
|||||||
import js from '@eslint/js'
|
import js from '@eslint/js'
|
||||||
import globals from 'globals'
|
import globals from 'globals'
|
||||||
import pluginVue from 'eslint-plugin-vue'
|
import pluginVue from 'eslint-plugin-vue'
|
||||||
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**', '**/node_modules/**', '.nuxt/**'],
|
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**', '**/node_modules/**', '.nuxt/**']
|
||||||
},
|
},
|
||||||
|
// Load Vue recommended rules first (sets up parser etc.)
|
||||||
|
...pluginVue.configs['flat/recommended'],
|
||||||
|
|
||||||
|
// General Configuration for all JS/Vue files
|
||||||
{
|
{
|
||||||
files: ['**/*.{js,mjs,jsx}'],
|
files: ['**/*.{js,mjs,jsx,vue}'],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
globals: {
|
||||||
...globals.browser,
|
...globals.browser
|
||||||
},
|
},
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 'latest',
|
ecmaVersion: 'latest',
|
||||||
sourceType: 'module',
|
sourceType: 'module'
|
||||||
},
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
|
// Import standard JS recommended rules
|
||||||
...js.configs.recommended.rules,
|
...js.configs.recommended.rules,
|
||||||
'indent': ['error', 2],
|
|
||||||
|
// --- Logic & Best Practices ---
|
||||||
|
'no-unused-vars': ['warn', {
|
||||||
|
argsIgnorePattern: '^_',
|
||||||
|
varsIgnorePattern: '^_',
|
||||||
|
caughtErrorsIgnorePattern: '^_'
|
||||||
|
}],
|
||||||
|
'no-undef': 'error',
|
||||||
|
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
|
||||||
|
'no-debugger': 'warn',
|
||||||
|
'eqeqeq': ['error', 'always', { null: 'ignore' }],
|
||||||
|
'curly': ['error', 'all'],
|
||||||
|
'prefer-const': 'warn',
|
||||||
|
'no-var': 'error',
|
||||||
|
|
||||||
|
// --- Formatting & Style (User requested warnings) ---
|
||||||
|
'indent': ['error', 2, { SwitchCase: 1 }],
|
||||||
'quotes': ['error', 'single', { avoidEscape: true }],
|
'quotes': ['error', 'single', { avoidEscape: true }],
|
||||||
'semi': ['error', 'never'],
|
'semi': ['error', 'never'],
|
||||||
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
||||||
'comma-dangle': ['error', 'never'],
|
'comma-dangle': ['error', 'never'],
|
||||||
'no-trailing-spaces': 'error',
|
'no-trailing-spaces': 'error',
|
||||||
'no-multiple-empty-lines': ['error', { max: 1 }],
|
'no-multiple-empty-lines': ['error', { max: 1 }],
|
||||||
'space-before-function-paren': ['error', 'always'],
|
'space-before-function-paren': ['error', 'always'],
|
||||||
|
'object-curly-spacing': ['error', 'always'],
|
||||||
|
'array-bracket-spacing': ['error', 'never']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
...pluginVue.configs['flat/recommended'],
|
// Vue Specific Overrides
|
||||||
{
|
{
|
||||||
files: ['**/*.vue'],
|
files: ['**/*.vue'],
|
||||||
rules: {
|
rules: {
|
||||||
'vue/multi-word-component-names': 'off',
|
'vue/multi-word-component-names': 'off',
|
||||||
'vue/no-v-html': 'warn',
|
'vue/no-v-html': 'warn',
|
||||||
|
|
||||||
|
// Turn off standard indent for Vue files to avoid conflicts with vue/html-indent
|
||||||
|
// or script indentation issues. Vue plugin handles this better.
|
||||||
'indent': 'off',
|
'indent': 'off',
|
||||||
|
// Ensure Vue's own indentation rules are active (they are in 'recommended' but let's be explicit if needed)
|
||||||
|
'vue/html-indent': ['error', 2],
|
||||||
|
'vue/script-indent': ['error', 2, {
|
||||||
|
baseIndent: 0,
|
||||||
|
switchCase: 1,
|
||||||
|
ignores: []
|
||||||
|
}]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
skipFormatting,
|
// Service Worker specific globals
|
||||||
{
|
{
|
||||||
files: ['**/service-worker.js', '**/src/registerServiceWorker.js'],
|
files: ['**/service-worker.js', '**/src/registerServiceWorker.js'],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
globals: {
|
||||||
...globals.serviceworker,
|
...globals.serviceworker
|
||||||
...globals.browser,
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint . --fix --cache",
|
"lint": "eslint . --fix --cache",
|
||||||
"format": "prettier --write --experimental-cli src/"
|
"format": "prettier --write src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
|
"echarts": "^6.0.0",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
"vant": "^4.9.22",
|
"vant": "^4.9.22",
|
||||||
"vue": "^3.5.25",
|
"vue": "^3.5.25",
|
||||||
|
|||||||
23
Web/pnpm-lock.yaml
generated
23
Web/pnpm-lock.yaml
generated
@@ -14,6 +14,9 @@ importers:
|
|||||||
dayjs:
|
dayjs:
|
||||||
specifier: ^1.11.19
|
specifier: ^1.11.19
|
||||||
version: 1.11.19
|
version: 1.11.19
|
||||||
|
echarts:
|
||||||
|
specifier: ^6.0.0
|
||||||
|
version: 6.0.0
|
||||||
pinia:
|
pinia:
|
||||||
specifier: ^3.0.4
|
specifier: ^3.0.4
|
||||||
version: 3.0.4(vue@3.5.26)
|
version: 3.0.4(vue@3.5.26)
|
||||||
@@ -787,6 +790,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
|
resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|
||||||
|
echarts@6.0.0:
|
||||||
|
resolution: {integrity: sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==}
|
||||||
|
|
||||||
electron-to-chromium@1.5.267:
|
electron-to-chromium@1.5.267:
|
||||||
resolution: {integrity: sha512-0Drusm6MVRXSOJpGbaSVgcQsuB4hEkMpHXaVstcPmhu5LIedxs1xNK/nIxmQIU/RPC0+1/o0AVZfBTkTNJOdUw==}
|
resolution: {integrity: sha512-0Drusm6MVRXSOJpGbaSVgcQsuB4hEkMpHXaVstcPmhu5LIedxs1xNK/nIxmQIU/RPC0+1/o0AVZfBTkTNJOdUw==}
|
||||||
|
|
||||||
@@ -1296,6 +1302,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==}
|
resolution: {integrity: sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
|
tslib@2.3.0:
|
||||||
|
resolution: {integrity: sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==}
|
||||||
|
|
||||||
type-check@0.4.0:
|
type-check@0.4.0:
|
||||||
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@@ -1435,6 +1444,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
|
zrender@6.0.0:
|
||||||
|
resolution: {integrity: sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==}
|
||||||
|
|
||||||
snapshots:
|
snapshots:
|
||||||
|
|
||||||
'@babel/code-frame@7.27.1':
|
'@babel/code-frame@7.27.1':
|
||||||
@@ -2131,6 +2143,11 @@ snapshots:
|
|||||||
es-errors: 1.3.0
|
es-errors: 1.3.0
|
||||||
gopd: 1.2.0
|
gopd: 1.2.0
|
||||||
|
|
||||||
|
echarts@6.0.0:
|
||||||
|
dependencies:
|
||||||
|
tslib: 2.3.0
|
||||||
|
zrender: 6.0.0
|
||||||
|
|
||||||
electron-to-chromium@1.5.267: {}
|
electron-to-chromium@1.5.267: {}
|
||||||
|
|
||||||
entities@7.0.0: {}
|
entities@7.0.0: {}
|
||||||
@@ -2611,6 +2628,8 @@ snapshots:
|
|||||||
|
|
||||||
totalist@3.0.1: {}
|
totalist@3.0.1: {}
|
||||||
|
|
||||||
|
tslib@2.3.0: {}
|
||||||
|
|
||||||
type-check@0.4.0:
|
type-check@0.4.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
prelude-ls: 1.2.1
|
prelude-ls: 1.2.1
|
||||||
@@ -2744,3 +2763,7 @@ snapshots:
|
|||||||
yallist@3.1.1: {}
|
yallist@3.1.1: {}
|
||||||
|
|
||||||
yocto-queue@0.1.0: {}
|
yocto-queue@0.1.0: {}
|
||||||
|
|
||||||
|
zrender@6.0.0:
|
||||||
|
dependencies:
|
||||||
|
tslib: 2.3.0
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
const VERSION = '1.0.0'; // Build Time: 2026-01-07 15:59:36
|
const VERSION = '1.0.0' // Build Time: 2026-01-07 15:59:36
|
||||||
const CACHE_NAME = `emailbill-${VERSION}`;
|
const CACHE_NAME = `emailbill-${VERSION}`
|
||||||
const urlsToCache = [
|
const urlsToCache = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/favicon.ico',
|
'/favicon.ico',
|
||||||
'/manifest.json'
|
'/manifest.json'
|
||||||
];
|
]
|
||||||
|
|
||||||
// 安装 Service Worker
|
// 安装 Service Worker
|
||||||
self.addEventListener('install', (event) => {
|
self.addEventListener('install', (event) => {
|
||||||
console.log('[Service Worker] 安装中...');
|
console.log('[Service Worker] 安装中...')
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CACHE_NAME)
|
caches.open(CACHE_NAME)
|
||||||
.then((cache) => {
|
.then((cache) => {
|
||||||
console.log('[Service Worker] 缓存文件');
|
console.log('[Service Worker] 缓存文件')
|
||||||
return cache.addAll(urlsToCache);
|
return cache.addAll(urlsToCache)
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听跳过等待消息
|
// 监听跳过等待消息
|
||||||
self.addEventListener('message', (event) => {
|
self.addEventListener('message', (event) => {
|
||||||
if (event.data && event.data.type === 'SKIP_WAITING') {
|
if (event.data && event.data.type === 'SKIP_WAITING') {
|
||||||
self.skipWaiting();
|
self.skipWaiting()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// 激活 Service Worker
|
// 激活 Service Worker
|
||||||
self.addEventListener('activate', (event) => {
|
self.addEventListener('activate', (event) => {
|
||||||
console.log('[Service Worker] 激活中...');
|
console.log('[Service Worker] 激活中...')
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.keys().then((cacheNames) => {
|
caches.keys().then((cacheNames) => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
cacheNames.map((cacheName) => {
|
cacheNames.map((cacheName) => {
|
||||||
if (cacheName !== CACHE_NAME) {
|
if (cacheName !== CACHE_NAME) {
|
||||||
console.log('[Service Worker] 删除旧缓存:', cacheName);
|
console.log('[Service Worker] 删除旧缓存:', cacheName)
|
||||||
return caches.delete(cacheName);
|
return caches.delete(cacheName)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}).then(() => self.clients.claim())
|
}).then(() => self.clients.claim())
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 拦截请求
|
// 拦截请求
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
const { request } = event;
|
const { request } = event
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url)
|
||||||
|
|
||||||
// 跳过跨域请求
|
// 跳过跨域请求
|
||||||
if (url.origin !== location.origin) {
|
if (url.origin !== location.origin) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// API请求使用网络优先策略
|
// API请求使用网络优先策略
|
||||||
@@ -60,19 +60,19 @@ self.addEventListener('fetch', (event) => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
// 只针对成功的GET请求进行缓存
|
// 只针对成功的GET请求进行缓存
|
||||||
if (request.method === 'GET' && response.status === 200) {
|
if (request.method === 'GET' && response.status === 200) {
|
||||||
const responseClone = response.clone();
|
const responseClone = response.clone()
|
||||||
caches.open(CACHE_NAME).then((cache) => {
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
cache.put(request, responseClone);
|
cache.put(request, responseClone)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
return response;
|
return response
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// 网络失败时尝试从缓存获取
|
// 网络失败时尝试从缓存获取
|
||||||
return caches.match(request);
|
return caches.match(request)
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面请求使用网络优先策略,确保能获取到最新的 index.html
|
// 页面请求使用网络优先策略,确保能获取到最新的 index.html
|
||||||
@@ -80,17 +80,17 @@ self.addEventListener('fetch', (event) => {
|
|||||||
event.respondWith(
|
event.respondWith(
|
||||||
fetch(request)
|
fetch(request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const responseClone = response.clone();
|
const responseClone = response.clone()
|
||||||
caches.open(CACHE_NAME).then((cache) => {
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
cache.put(request, responseClone);
|
cache.put(request, responseClone)
|
||||||
});
|
})
|
||||||
return response;
|
return response
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return caches.match('/index.html') || caches.match(request);
|
return caches.match('/index.html') || caches.match(request)
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其他静态资源使用缓存优先策略
|
// 其他静态资源使用缓存优先策略
|
||||||
@@ -98,50 +98,50 @@ self.addEventListener('fetch', (event) => {
|
|||||||
caches.match(request)
|
caches.match(request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
return response;
|
return response
|
||||||
}
|
}
|
||||||
return fetch(request).then((response) => {
|
return fetch(request).then((response) => {
|
||||||
// 检查是否是有效响应
|
// 检查是否是有效响应
|
||||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||||
return response;
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseClone = response.clone();
|
const responseClone = response.clone()
|
||||||
caches.open(CACHE_NAME).then((cache) => {
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
cache.put(request, responseClone);
|
cache.put(request, responseClone)
|
||||||
});
|
})
|
||||||
|
|
||||||
return response;
|
return response
|
||||||
});
|
})
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// 返回离线页面或默认内容
|
// 返回离线页面或默认内容
|
||||||
if (request.destination === 'document') {
|
if (request.destination === 'document') {
|
||||||
return caches.match('/index.html');
|
return caches.match('/index.html')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 后台同步
|
// 后台同步
|
||||||
self.addEventListener('sync', (event) => {
|
self.addEventListener('sync', (event) => {
|
||||||
console.log('[Service Worker] 后台同步:', event.tag);
|
console.log('[Service Worker] 后台同步:', event.tag)
|
||||||
if (event.tag === 'sync-data') {
|
if (event.tag === 'sync-data') {
|
||||||
event.waitUntil(syncData());
|
event.waitUntil(syncData())
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// 推送通知
|
// 推送通知
|
||||||
self.addEventListener('push', (event) => {
|
self.addEventListener('push', (event) => {
|
||||||
console.log('[Service Worker] 收到推送消息');
|
console.log('[Service Worker] 收到推送消息')
|
||||||
let data = { title: '账单管理', body: '您有新的消息', url: '/', icon: '/icons/icon-192x192.png' };
|
let data = { title: '账单管理', body: '您有新的消息', url: '/', icon: '/icons/icon-192x192.png' }
|
||||||
|
|
||||||
if (event.data) {
|
if (event.data) {
|
||||||
try {
|
try {
|
||||||
const json = event.data.json();
|
const json = event.data.json()
|
||||||
data = { ...data, ...json };
|
data = { ...data, ...json }
|
||||||
} catch {
|
} catch {
|
||||||
data.body = event.data.text();
|
data.body = event.data.text()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,41 +153,41 @@ self.addEventListener('push', (event) => {
|
|||||||
tag: 'emailbill-notification',
|
tag: 'emailbill-notification',
|
||||||
requireInteraction: false,
|
requireInteraction: false,
|
||||||
data: { url: data.url }
|
data: { url: data.url }
|
||||||
};
|
}
|
||||||
|
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
self.registration.showNotification(data.title, options)
|
self.registration.showNotification(data.title, options)
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 通知点击
|
// 通知点击
|
||||||
self.addEventListener('notificationclick', (event) => {
|
self.addEventListener('notificationclick', (event) => {
|
||||||
console.log('[Service Worker] 通知被点击');
|
console.log('[Service Worker] 通知被点击')
|
||||||
event.notification.close();
|
event.notification.close()
|
||||||
const urlToOpen = event.notification.data?.url || '/';
|
const urlToOpen = event.notification.data?.url || '/'
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windowClients) => {
|
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windowClients) => {
|
||||||
// 如果已经打开了该 URL,则聚焦
|
// 如果已经打开了该 URL,则聚焦
|
||||||
for (let i = 0; i < windowClients.length; i++) {
|
for (let i = 0; i < windowClients.length; i++) {
|
||||||
const client = windowClients[i];
|
const client = windowClients[i]
|
||||||
if (client.url === urlToOpen && 'focus' in client) {
|
if (client.url === urlToOpen && 'focus' in client) {
|
||||||
return client.focus();
|
return client.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 否则打开新窗口
|
// 否则打开新窗口
|
||||||
if (clients.openWindow) {
|
if (clients.openWindow) {
|
||||||
return clients.openWindow(urlToOpen);
|
return clients.openWindow(urlToOpen)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 数据同步函数
|
// 数据同步函数
|
||||||
async function syncData () {
|
async function syncData () {
|
||||||
try {
|
try {
|
||||||
// 这里添加需要同步的逻辑
|
// 这里添加需要同步的逻辑
|
||||||
console.log('[Service Worker] 执行数据同步');
|
console.log('[Service Worker] 执行数据同步')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Service Worker] 同步失败:', error);
|
console.error('[Service Worker] 同步失败:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
<div class="app-root">
|
<div class="app-root">
|
||||||
<RouterView />
|
<RouterView />
|
||||||
<van-tabbar v-show="showTabbar" v-model="active">
|
<van-tabbar v-show="showTabbar" v-model="active">
|
||||||
<van-tabbar-item name="ccalendar" icon="notes" to="/calendar">
|
<van-tabbar-item name="ccalendar" icon="notes" to="/calendar"> 日历 </van-tabbar-item>
|
||||||
日历
|
<van-tabbar-item
|
||||||
</van-tabbar-item>
|
name="statistics"
|
||||||
<van-tabbar-item name="statistics" icon="chart-trending-o" to="/" @click="handleTabClick('/statistics')">
|
icon="chart-trending-o"
|
||||||
|
to="/"
|
||||||
|
@click="handleTabClick('/statistics')"
|
||||||
|
>
|
||||||
统计
|
统计
|
||||||
</van-tabbar-item>
|
</van-tabbar-item>
|
||||||
<van-tabbar-item
|
<van-tabbar-item
|
||||||
@@ -18,12 +21,15 @@
|
|||||||
>
|
>
|
||||||
账单
|
账单
|
||||||
</van-tabbar-item>
|
</van-tabbar-item>
|
||||||
<van-tabbar-item name="budget" icon="bill-o" to="/budget" @click="handleTabClick('/budget')">
|
<van-tabbar-item
|
||||||
|
name="budget"
|
||||||
|
icon="bill-o"
|
||||||
|
to="/budget"
|
||||||
|
@click="handleTabClick('/budget')"
|
||||||
|
>
|
||||||
预算
|
预算
|
||||||
</van-tabbar-item>
|
</van-tabbar-item>
|
||||||
<van-tabbar-item name="setting" icon="setting" to="/setting">
|
<van-tabbar-item name="setting" icon="setting" to="/setting"> 设置 </van-tabbar-item>
|
||||||
设置
|
|
||||||
</van-tabbar-item>
|
|
||||||
</van-tabbar>
|
</van-tabbar>
|
||||||
<GlobalAddBill v-if="isShowAddBill" @success="handleAddTransactionSuccess" />
|
<GlobalAddBill v-if="isShowAddBill" @success="handleAddTransactionSuccess" />
|
||||||
|
|
||||||
@@ -85,12 +91,14 @@ onUnmounted(() => {
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
// 根据路由判断是否显示Tabbar
|
// 根据路由判断是否显示Tabbar
|
||||||
const showTabbar = computed(() => {
|
const showTabbar = computed(() => {
|
||||||
return route.path === '/' ||
|
return (
|
||||||
|
route.path === '/' ||
|
||||||
route.path === '/calendar' ||
|
route.path === '/calendar' ||
|
||||||
route.path === '/message' ||
|
route.path === '/message' ||
|
||||||
route.path === '/setting' ||
|
route.path === '/setting' ||
|
||||||
route.path === '/balance' ||
|
route.path === '/balance' ||
|
||||||
route.path === '/budget'
|
route.path === '/budget'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const active = ref('')
|
const active = ref('')
|
||||||
@@ -116,11 +124,14 @@ setInterval(() => {
|
|||||||
}, 60 * 1000) // 每60秒更新一次未读消息数
|
}, 60 * 1000) // 每60秒更新一次未读消息数
|
||||||
|
|
||||||
// 监听路由变化调整
|
// 监听路由变化调整
|
||||||
watch(() => route.path, (newPath) => {
|
watch(
|
||||||
|
() => route.path,
|
||||||
|
(newPath) => {
|
||||||
setActive(newPath)
|
setActive(newPath)
|
||||||
|
|
||||||
messageStore.updateUnreadCount()
|
messageStore.updateUnreadCount()
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const setActive = (path) => {
|
const setActive = (path) => {
|
||||||
active.value = (() => {
|
active.value = (() => {
|
||||||
@@ -142,10 +153,7 @@ const setActive = (path) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isShowAddBill = computed(() => {
|
const isShowAddBill = computed(() => {
|
||||||
return route.path === '/'
|
return route.path === '/' || route.path === '/balance' || route.path === '/message'
|
||||||
|| route.path === '/calendar'
|
|
||||||
|| route.path === '/balance'
|
|
||||||
|| route.path === '/message'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
@@ -166,7 +174,6 @@ const handleAddTransactionSuccess = () => {
|
|||||||
const event = new Event('transactions-changed')
|
const event = new Event('transactions-changed')
|
||||||
window.dispatchEvent(event)
|
window.dispatchEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export const uploadBillFile = (file, type) => {
|
|||||||
Authorization: `Bearer ${useAuthStore().token || ''}`
|
Authorization: `Bearer ${useAuthStore().token || ''}`
|
||||||
},
|
},
|
||||||
timeout: 60000 // 文件上传增加超时时间
|
timeout: 60000 // 文件上传增加超时时间
|
||||||
}).then(response => {
|
})
|
||||||
|
.then((response) => {
|
||||||
const { data } = response
|
const { data } = response
|
||||||
|
|
||||||
if (data.success === false) {
|
if (data.success === false) {
|
||||||
@@ -35,7 +36,8 @@ export const uploadBillFile = (file, type) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}).catch(error => {
|
})
|
||||||
|
.catch((error) => {
|
||||||
console.error('上传错误:', error)
|
console.error('上传错误:', error)
|
||||||
|
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
|
|||||||
@@ -12,19 +12,6 @@ export function getBudgetList(referenceDate) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取单个预算统计
|
|
||||||
* @param {number} id 预算ID
|
|
||||||
* @param {string} referenceDate 参考日期
|
|
||||||
*/
|
|
||||||
export function getBudgetStatistics(id, referenceDate) {
|
|
||||||
return request({
|
|
||||||
url: '/Budget/GetStatistics',
|
|
||||||
method: 'get',
|
|
||||||
params: { id, referenceDate }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建预算
|
* 创建预算
|
||||||
* @param {object} data 预算数据
|
* @param {object} data 预算数据
|
||||||
@@ -84,15 +71,41 @@ export function getUncoveredCategories(category, referenceDate) {
|
|||||||
params: { category, referenceDate }
|
params: { category, referenceDate }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 归档预算
|
* 获取归档总结
|
||||||
* @param {number} year 年份
|
* @param {string} referenceDate 参考日期
|
||||||
* @param {number} month 月份
|
|
||||||
*/
|
*/
|
||||||
export function archiveBudgets(year, month) {
|
export function getArchiveSummary(referenceDate) {
|
||||||
return request({
|
return request({
|
||||||
url: `/Budget/ArchiveBudgetsAsync/${year}/${month}`,
|
url: '/Budget/GetArchiveSummary',
|
||||||
method: 'post'
|
method: 'get',
|
||||||
|
params: { referenceDate }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新归档总结
|
||||||
|
* @param {object} data 数据 { referenceDate, summary }
|
||||||
|
*/
|
||||||
|
export function updateArchiveSummary(data) {
|
||||||
|
return request({
|
||||||
|
url: '/Budget/UpdateArchiveSummary',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定周期的存款预算信息
|
||||||
|
* @param {number} year 年份
|
||||||
|
* @param {number} month 月份
|
||||||
|
* @param {number} type 周期类型 (1:Month, 2:Year)
|
||||||
|
*/
|
||||||
|
export function getSavingsBudget(year, month, type) {
|
||||||
|
return request({
|
||||||
|
url: '/Budget/GetSavingsBudget',
|
||||||
|
method: 'get',
|
||||||
|
params: { year, month, type }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const getEmailDetail = (id) => {
|
|||||||
*/
|
*/
|
||||||
export const deleteEmail = (id) => {
|
export const deleteEmail = (id) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/EmailMessage/DeleteById`,
|
url: '/EmailMessage/DeleteById',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { id }
|
params: { id }
|
||||||
})
|
})
|
||||||
@@ -50,7 +50,7 @@ export const deleteEmail = (id) => {
|
|||||||
*/
|
*/
|
||||||
export const refreshTransactionRecords = (id) => {
|
export const refreshTransactionRecords = (id) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/EmailMessage/RefreshTransactionRecords`,
|
url: '/EmailMessage/RefreshTransactionRecords',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { id }
|
params: { id }
|
||||||
})
|
})
|
||||||
@@ -62,7 +62,7 @@ export const refreshTransactionRecords = (id) => {
|
|||||||
*/
|
*/
|
||||||
export const syncEmails = () => {
|
export const syncEmails = () => {
|
||||||
return request({
|
return request({
|
||||||
url: `/EmailMessage/SyncEmails`,
|
url: '/EmailMessage/SyncEmails',
|
||||||
method: 'post'
|
method: 'post'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const request = axios.create({
|
|||||||
|
|
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
request.interceptors.request.use(
|
request.interceptors.request.use(
|
||||||
config => {
|
(config) => {
|
||||||
// 添加 token 认证信息
|
// 添加 token 认证信息
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
if (authStore.token) {
|
if (authStore.token) {
|
||||||
@@ -22,7 +22,7 @@ request.interceptors.request.use(
|
|||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
error => {
|
(error) => {
|
||||||
console.error('请求错误:', error)
|
console.error('请求错误:', error)
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ request.interceptors.request.use(
|
|||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
request.interceptors.response.use(
|
request.interceptors.response.use(
|
||||||
response => {
|
(response) => {
|
||||||
const { data } = response
|
const { data } = response
|
||||||
|
|
||||||
// 统一处理业务错误
|
// 统一处理业务错误
|
||||||
@@ -41,7 +41,7 @@ request.interceptors.response.use(
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
error => {
|
(error) => {
|
||||||
console.error('响应错误:', error)
|
console.error('响应错误:', error)
|
||||||
|
|
||||||
// 统一处理 HTTP 错误
|
// 统一处理 HTTP 错误
|
||||||
@@ -58,7 +58,10 @@ request.interceptors.response.use(
|
|||||||
// 清除登录状态并跳转到登录页
|
// 清除登录状态并跳转到登录页
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
authStore.logout()
|
authStore.logout()
|
||||||
router.push({ name: 'login', query: { redirect: router.currentRoute.value.fullPath } })
|
router.push({
|
||||||
|
name: 'login',
|
||||||
|
query: { redirect: router.currentRoute.value.fullPath }
|
||||||
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 403:
|
case 403:
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
* @returns {Object} data.expenseCount - 支出笔数
|
* @returns {Object} data.expenseCount - 支出笔数
|
||||||
* @returns {Object} data.incomeCount - 收入笔数
|
* @returns {Object} data.incomeCount - 收入笔数
|
||||||
* @returns {Object} data.totalCount - 总笔数
|
* @returns {Object} data.totalCount - 总笔数
|
||||||
* @returns {Object} data.maxExpense - 最大单笔支出
|
|
||||||
* @returns {Object} data.maxIncome - 最大单笔收入
|
|
||||||
*/
|
*/
|
||||||
export const getMonthlyStatistics = (params) => {
|
export const getMonthlyStatistics = (params) => {
|
||||||
return request({
|
return request({
|
||||||
@@ -88,3 +86,18 @@ export const getDailyStatistics = (params) => {
|
|||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定日期范围内的每日统计
|
||||||
|
* @param {Object} params - 查询参数
|
||||||
|
* @param {string} params.startDate - 开始日期
|
||||||
|
* @param {string} params.endDate - 结束日期
|
||||||
|
* @returns {Promise<{success: boolean, data: Array}>}
|
||||||
|
*/
|
||||||
|
export const getDailyStatisticsRange = (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/TransactionRecord/GetDailyStatisticsRange',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export const updatePeriodic = (data) => {
|
|||||||
*/
|
*/
|
||||||
export const deletePeriodic = (id) => {
|
export const deletePeriodic = (id) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/TransactionPeriodic/DeleteById`,
|
url: '/TransactionPeriodic/DeleteById',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { id }
|
params: { id }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export const updateTransaction = (data) => {
|
|||||||
*/
|
*/
|
||||||
export const deleteTransaction = (id) => {
|
export const deleteTransaction = (id) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/TransactionRecord/DeleteById`,
|
url: '/TransactionRecord/DeleteById',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { id }
|
params: { id }
|
||||||
})
|
})
|
||||||
@@ -118,7 +118,6 @@ export const getTransactionsByDate = (date) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 注意:分类相关的API已迁移到 transactionCategory.js
|
// 注意:分类相关的API已迁移到 transactionCategory.js
|
||||||
// 请使用 getCategoryList 等新接口
|
// 请使用 getCategoryList 等新接口
|
||||||
|
|
||||||
@@ -160,7 +159,7 @@ export const smartClassify = (transactionIds = []) => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ transactionIds })
|
body: JSON.stringify({ transactionIds })
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,55 +1,75 @@
|
|||||||
/* color palette from <https://github.com/vuejs/theme> */
|
/* color palette from <https://github.com/vuejs/theme> */
|
||||||
|
/*
|
||||||
|
Most variables are replaced by Vant CSS variables.
|
||||||
|
Keeping only what's necessary or mapping to Vant.
|
||||||
|
*/
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--vt-c-white: #ffffff;
|
--van-danger-color: rgb(255, 107, 107) !important; /* 覆盖默认的深红色 #ee0a24 */
|
||||||
--vt-c-white-soft: #f8f8f8;
|
--color-background: var(--van-background);
|
||||||
--vt-c-white-mute: #f2f2f2;
|
--color-background-soft: var(--van-background-2);
|
||||||
|
--color-background-mute: var(--van-gray-1);
|
||||||
|
|
||||||
--vt-c-black: #181818;
|
--color-border: var(--van-border-color);
|
||||||
--vt-c-black-soft: #222222;
|
--color-border-hover: var(--van-gray-5);
|
||||||
--vt-c-black-mute: #282828;
|
|
||||||
|
|
||||||
--vt-c-indigo: #2c3e50;
|
--color-heading: var(--van-text-color);
|
||||||
|
--color-text: var(--van-text-color);
|
||||||
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
|
|
||||||
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
|
|
||||||
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
|
|
||||||
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
|
|
||||||
|
|
||||||
--vt-c-text-light-1: var(--vt-c-indigo);
|
|
||||||
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
|
|
||||||
--vt-c-text-dark-1: var(--vt-c-white);
|
|
||||||
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* semantic color variables for this project */
|
|
||||||
:root {
|
|
||||||
--color-background: var(--vt-c-white);
|
|
||||||
--color-background-soft: var(--vt-c-white-soft);
|
|
||||||
--color-background-mute: var(--vt-c-white-mute);
|
|
||||||
|
|
||||||
--color-border: var(--vt-c-divider-light-2);
|
|
||||||
--color-border-hover: var(--vt-c-divider-light-1);
|
|
||||||
|
|
||||||
--color-heading: var(--vt-c-text-light-1);
|
|
||||||
--color-text: var(--vt-c-text-light-1);
|
|
||||||
|
|
||||||
--section-gap: 160px;
|
--section-gap: 160px;
|
||||||
|
|
||||||
|
/* Chart Colors */
|
||||||
|
--chart-color-1: #ff6b6b;
|
||||||
|
--chart-color-2: #4ecdc4;
|
||||||
|
--chart-color-3: #45b7d1;
|
||||||
|
--chart-color-4: #ffa07a;
|
||||||
|
--chart-color-5: #98d8c8;
|
||||||
|
--chart-color-6: #f7dc6f;
|
||||||
|
--chart-color-7: #bb8fce;
|
||||||
|
--chart-color-8: #85c1e2;
|
||||||
|
--chart-color-9: #f8b88b;
|
||||||
|
--chart-color-10: #aab7b8;
|
||||||
|
--chart-color-11: #ff8ed4;
|
||||||
|
--chart-color-12: #67e6dc;
|
||||||
|
--chart-color-13: #ffab73;
|
||||||
|
--chart-color-14: #c9b1ff;
|
||||||
|
--chart-color-15: #7bdff2;
|
||||||
|
|
||||||
|
/* Status Colors for Charts */
|
||||||
|
--chart-success: #52c41a;
|
||||||
|
--chart-warning: #faad14;
|
||||||
|
--chart-danger: #f5222d;
|
||||||
|
--chart-primary: #1890ff;
|
||||||
|
--chart-shadow: rgba(0, 138, 255, 0.45);
|
||||||
|
--chart-axis: #e6ebf8;
|
||||||
|
--chart-split: #eee;
|
||||||
|
--chart-text-muted: #999;
|
||||||
|
|
||||||
|
/* Heatmap Colors - Light Mode */
|
||||||
|
--heatmap-level-0: var(--van-gray-2);
|
||||||
|
--heatmap-level-1: #9be9a8;
|
||||||
|
--heatmap-level-2: #40c463;
|
||||||
|
--heatmap-level-3: #30a14e;
|
||||||
|
--heatmap-level-4: #216e39;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
:root {
|
:root {
|
||||||
--color-background: var(--vt-c-black);
|
--chart-axis: #333;
|
||||||
--color-background-soft: var(--vt-c-black-soft);
|
--chart-split: #333;
|
||||||
--color-background-mute: var(--vt-c-black-mute);
|
--chart-text-muted: #666;
|
||||||
|
|
||||||
--color-border: var(--vt-c-divider-dark-2);
|
/* Heatmap Colors - Dark Mode (GitHub Style) */
|
||||||
--color-border-hover: var(--vt-c-divider-dark-1);
|
--heatmap-level-0: var(--van-gray-2);
|
||||||
|
--heatmap-level-1: #9be9a8;
|
||||||
--color-heading: var(--vt-c-text-dark-1);
|
--heatmap-level-2: #40c463;
|
||||||
--color-text: var(--vt-c-text-dark-2);
|
--heatmap-level-3: #30a14e;
|
||||||
|
--heatmap-level-4: #216e39;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Removed manual dark mode media query as Vant handles it */
|
||||||
|
|
||||||
*,
|
*,
|
||||||
*::before,
|
*::before,
|
||||||
*::after {
|
*::after {
|
||||||
@@ -60,8 +80,8 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
color: var(--color-text);
|
color: var(--van-text-color);
|
||||||
background: var(--color-background);
|
background: var(--van-background);
|
||||||
transition:
|
transition:
|
||||||
color 0.5s,
|
color 0.5s,
|
||||||
background-color 0.5s;
|
background-color 0.5s;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
@import './base.css';
|
@import './base.css';
|
||||||
|
|
||||||
/* 禁用页面弹性缩放和橡皮筋效果 */
|
/* 禁用页面弹性缩放和橡皮筋效果 */
|
||||||
html, body {
|
html,
|
||||||
|
body {
|
||||||
overscroll-behavior: none;
|
overscroll-behavior: none;
|
||||||
overscroll-behavior-y: none;
|
overscroll-behavior-y: none;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
@@ -57,7 +58,9 @@ a,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
html, body, #app {
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
show-cancel-button
|
show-cancel-button
|
||||||
@confirm="handleConfirm"
|
@confirm="handleConfirm"
|
||||||
>
|
>
|
||||||
<van-field v-model="classifyName" placeholder="请输入新的交易分类" />
|
<van-field
|
||||||
|
v-model="classifyName"
|
||||||
|
placeholder="请输入新的交易分类"
|
||||||
|
/>
|
||||||
</van-dialog>
|
</van-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,12 @@
|
|||||||
<van-field label="时间">
|
<van-field label="时间">
|
||||||
<template #input>
|
<template #input>
|
||||||
<div style="display: flex; gap: 16px">
|
<div style="display: flex; gap: 16px">
|
||||||
<div @click="showDatePicker = true">{{ form.date }}</div>
|
<div @click="showDatePicker = true">
|
||||||
<div @click="showTimePicker = true">{{ form.time }}</div>
|
{{ form.date }}
|
||||||
|
</div>
|
||||||
|
<div @click="showTimePicker = true">
|
||||||
|
{{ form.time }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
@@ -47,23 +51,20 @@
|
|||||||
<!-- 分类 -->
|
<!-- 分类 -->
|
||||||
<van-field name="category" label="分类">
|
<van-field name="category" label="分类">
|
||||||
<template #input>
|
<template #input>
|
||||||
<span v-if="!categoryName" style="color: #c8c9cc;">请选择分类</span>
|
<span v-if="!categoryName" style="color: var(--van-text-color-3)">请选择分类</span>
|
||||||
<span v-else>{{ categoryName }}</span>
|
<span v-else>{{ categoryName }}</span>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
|
|
||||||
<!-- 分类选择组件 -->
|
<!-- 分类选择组件 -->
|
||||||
<ClassifySelector
|
<ClassifySelector v-model="categoryName" :type="form.type" />
|
||||||
v-model="categoryName"
|
|
||||||
:type="form.type"
|
|
||||||
/>
|
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<van-button round block type="primary" native-type="submit" :loading="loading">
|
<van-button round block type="primary" native-type="submit" :loading="loading">
|
||||||
{{ submitText }}
|
{{ submitText }}
|
||||||
</van-button>
|
</van-button>
|
||||||
<slot name="actions"></slot>
|
<slot name="actions" />
|
||||||
</div>
|
</div>
|
||||||
</van-form>
|
</van-form>
|
||||||
|
|
||||||
@@ -146,9 +147,15 @@ const initForm = async () => {
|
|||||||
currentTime.value = form.value.time.split(':')
|
currentTime.value = form.value.time.split(':')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amount !== undefined) form.value.amount = amount
|
if (amount !== undefined) {
|
||||||
if (reason !== undefined) form.value.note = reason
|
form.value.amount = amount
|
||||||
if (type !== undefined) form.value.type = type
|
}
|
||||||
|
if (reason !== undefined) {
|
||||||
|
form.value.note = reason
|
||||||
|
}
|
||||||
|
if (type !== undefined) {
|
||||||
|
form.value.type = type
|
||||||
|
}
|
||||||
|
|
||||||
// 如果有传入分类名称,尝试设置
|
// 如果有传入分类名称,尝试设置
|
||||||
if (classify) {
|
if (classify) {
|
||||||
@@ -166,9 +173,13 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 监听 initialData 变化 (例如重新解析后)
|
// 监听 initialData 变化 (例如重新解析后)
|
||||||
watch(() => props.initialData, () => {
|
watch(
|
||||||
|
() => props.initialData,
|
||||||
|
() => {
|
||||||
initForm()
|
initForm()
|
||||||
}, { deep: true })
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
const handleTypeChange = (newType) => {
|
const handleTypeChange = (newType) => {
|
||||||
if (!isSyncing.value) {
|
if (!isSyncing.value) {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="manual-bill-add">
|
<div class="manual-bill-add">
|
||||||
<BillForm
|
<BillForm ref="billFormRef" :loading="saving" @submit="handleSave" />
|
||||||
ref="billFormRef"
|
|
||||||
:loading="saving"
|
|
||||||
@submit="handleSave"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div v-if="!parseResult" class="input-section" style="margin: 12px 12px 0 16px;">
|
<div v-if="!parseResult" class="input-section" style="margin: 12px 12px 0 16px">
|
||||||
<van-field
|
<van-field
|
||||||
v-model="text"
|
v-model="text"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
@@ -31,13 +31,7 @@
|
|||||||
@submit="handleSave"
|
@submit="handleSave"
|
||||||
>
|
>
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<van-button
|
<van-button plain round block class="mt-2" @click="parseResult = null">
|
||||||
plain
|
|
||||||
round
|
|
||||||
block
|
|
||||||
class="mt-2"
|
|
||||||
@click="parseResult = null"
|
|
||||||
>
|
|
||||||
重新输入
|
重新输入
|
||||||
</van-button>
|
</van-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -60,7 +54,9 @@ const saving = ref(false)
|
|||||||
const parseResult = ref(null)
|
const parseResult = ref(null)
|
||||||
|
|
||||||
const handleParse = async () => {
|
const handleParse = async () => {
|
||||||
if (!text.value.trim()) return
|
if (!text.value.trim()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
parsing.value = true
|
parsing.value = true
|
||||||
parseResult.value = null
|
parseResult.value = null
|
||||||
@@ -121,6 +117,6 @@ const handleSave = async (payload) => {
|
|||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 1px solid #ebedf0;
|
border: 1px solid var(--van-border-color);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<template>
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
<div class="common-card budget-card" @click="toggleExpand">
|
<template>
|
||||||
|
<!-- 普通预算卡片 -->
|
||||||
|
<div v-if="!budget.noLimit" class="common-card budget-card" @click="toggleExpand">
|
||||||
<div class="budget-content-wrapper">
|
<div class="budget-content-wrapper">
|
||||||
<!-- 折叠状态 -->
|
<!-- 折叠状态 -->
|
||||||
<div v-if="!isExpanded" class="budget-collapsed">
|
<div v-if="!isExpanded" class="budget-collapsed">
|
||||||
@@ -12,9 +14,12 @@
|
|||||||
class="status-tag"
|
class="status-tag"
|
||||||
>
|
>
|
||||||
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
||||||
|
<span v-if="budget.isMandatoryExpense" class="mandatory-mark">📌</span>
|
||||||
</van-tag>
|
</van-tag>
|
||||||
</slot>
|
</slot>
|
||||||
<h3 class="card-title">{{ budget.name }}</h3>
|
<h3 class="card-title">
|
||||||
|
{{ budget.name }}
|
||||||
|
</h3>
|
||||||
<span v-if="budget.selectedCategories?.length" class="card-subtitle">
|
<span v-if="budget.selectedCategories?.length" class="card-subtitle">
|
||||||
({{ budget.selectedCategories.join('、') }})
|
({{ budget.selectedCategories.join('、') }})
|
||||||
</span>
|
</span>
|
||||||
@@ -27,9 +32,11 @@
|
|||||||
<span class="compact-label">实际/目标</span>
|
<span class="compact-label">实际/目标</span>
|
||||||
<span class="compact-value">
|
<span class="compact-value">
|
||||||
<slot name="collapsed-amount">
|
<slot name="collapsed-amount">
|
||||||
{{ budget.current !== undefined && budget.limit !== undefined
|
{{
|
||||||
|
budget.current !== undefined && budget.limit !== undefined
|
||||||
? `¥${budget.current?.toFixed(0) || 0} / ¥${budget.limit?.toFixed(0) || 0}`
|
? `¥${budget.current?.toFixed(0) || 0} / ¥${budget.limit?.toFixed(0) || 0}`
|
||||||
: '--' }}
|
: '--'
|
||||||
|
}}
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -42,9 +49,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 展开状态 -->
|
<!-- 展开状态 -->
|
||||||
<Transition v-else :name="transitionName">
|
<div v-else class="budget-inner-card">
|
||||||
<div :key="budget.period" class="budget-inner-card">
|
<div class="card-header" style="margin-bottom: 0">
|
||||||
<div class="card-header" style="margin-bottom: 0;">
|
|
||||||
<div class="budget-info">
|
<div class="budget-info">
|
||||||
<slot name="tag">
|
<slot name="tag">
|
||||||
<van-tag
|
<van-tag
|
||||||
@@ -53,9 +59,12 @@
|
|||||||
class="status-tag"
|
class="status-tag"
|
||||||
>
|
>
|
||||||
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
||||||
|
<span v-if="budget.isMandatoryExpense" class="mandatory-mark">📌</span>
|
||||||
</van-tag>
|
</van-tag>
|
||||||
</slot>
|
</slot>
|
||||||
<h3 class="card-title" style="max-width: 120px;">{{ budget.name }}</h3>
|
<h3 class="card-title" style="max-width: 120px">
|
||||||
|
{{ budget.name }}
|
||||||
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
<slot name="actions">
|
<slot name="actions">
|
||||||
@@ -75,14 +84,8 @@
|
|||||||
@click.stop="handleQueryBills"
|
@click.stop="handleQueryBills"
|
||||||
/>
|
/>
|
||||||
<template v-if="budget.category !== 2">
|
<template v-if="budget.category !== 2">
|
||||||
<van-button
|
<van-button icon="edit" size="small" plain @click.stop="$emit('click', budget)" />
|
||||||
icon="edit"
|
|
||||||
size="small"
|
|
||||||
plain
|
|
||||||
@click.stop="$emit('click', budget)"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -101,12 +104,14 @@
|
|||||||
</van-tag>
|
</van-tag>
|
||||||
</div>
|
</div>
|
||||||
<div class="amount-info">
|
<div class="amount-info">
|
||||||
<slot name="amount-info"></slot>
|
<slot name="amount-info" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="progress-section">
|
<div class="progress-section">
|
||||||
<slot name="progress-info">
|
<slot name="progress-info">
|
||||||
<span class="period-type">{{ periodLabel }}{{ budget.category === 0 ? '使用' : '达成' }}</span>
|
<span class="period-type"
|
||||||
|
>{{ periodLabel }}{{ budget.category === 0 ? '使用' : '达成' }}</span
|
||||||
|
>
|
||||||
<van-progress
|
<van-progress
|
||||||
:percentage="Math.min(percentage, 100)"
|
:percentage="Math.min(percentage, 100)"
|
||||||
stroke-width="8"
|
stroke-width="8"
|
||||||
@@ -121,7 +126,7 @@
|
|||||||
<van-progress
|
<van-progress
|
||||||
:percentage="timePercentage"
|
:percentage="timePercentage"
|
||||||
stroke-width="4"
|
stroke-width="4"
|
||||||
color="#969799"
|
color="var(--van-gray-6)"
|
||||||
:show-pivot="false"
|
:show-pivot="false"
|
||||||
/>
|
/>
|
||||||
<span class="percent">{{ timePercentage }}%</span>
|
<span class="percent">{{ timePercentage }}%</span>
|
||||||
@@ -129,43 +134,145 @@
|
|||||||
|
|
||||||
<van-collapse-transition>
|
<van-collapse-transition>
|
||||||
<div v-if="budget.description && showDescription" class="budget-description">
|
<div v-if="budget.description && showDescription" class="budget-description">
|
||||||
<div class="description-content rich-html-content" v-html="budget.description"></div>
|
<div class="description-content rich-html-content" v-html="budget.description" />
|
||||||
</div>
|
</div>
|
||||||
</van-collapse-transition>
|
</van-collapse-transition>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<div class="period-navigation" @click.stop>
|
<slot name="footer" />
|
||||||
<van-button
|
|
||||||
icon="arrow-left"
|
|
||||||
class="nav-icon"
|
|
||||||
plain
|
|
||||||
size="small"
|
|
||||||
style="width: 50px;"
|
|
||||||
@click="handleSwitch(-1)"
|
|
||||||
/>
|
|
||||||
<span class="period-text">{{ budget.period }}</span>
|
|
||||||
<van-button
|
|
||||||
icon="arrow"
|
|
||||||
class="nav-icon"
|
|
||||||
plain
|
|
||||||
size="small"
|
|
||||||
style="width: 50px;"
|
|
||||||
:disabled="isNextDisabled"
|
|
||||||
@click="handleSwitch(1)"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 关联账单列表弹窗 -->
|
<!-- 关联账单列表弹窗 -->
|
||||||
<PopupContainer
|
<PopupContainer v-model="showBillListModal" title="关联账单列表" height="75%">
|
||||||
v-model="showBillListModal"
|
<TransactionList
|
||||||
title="关联账单列表"
|
:transactions="billList"
|
||||||
height="75%"
|
:loading="billLoading"
|
||||||
|
:finished="true"
|
||||||
|
:show-delete="false"
|
||||||
|
:show-checkbox="false"
|
||||||
|
@click="handleBillClick"
|
||||||
|
@delete="handleBillDelete"
|
||||||
|
/>
|
||||||
|
</PopupContainer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 不记额预算卡片 -->
|
||||||
|
<div v-else class="common-card budget-card no-limit-card" @click="toggleExpand">
|
||||||
|
<div class="budget-content-wrapper">
|
||||||
|
<!-- 折叠状态 -->
|
||||||
|
<div v-if="!isExpanded" class="budget-collapsed">
|
||||||
|
<div class="collapsed-header">
|
||||||
|
<div class="budget-info">
|
||||||
|
<slot name="tag">
|
||||||
|
<van-tag type="success" plain class="status-tag">
|
||||||
|
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
||||||
|
</van-tag>
|
||||||
|
</slot>
|
||||||
|
<h3 class="card-title">
|
||||||
|
{{ budget.name }}
|
||||||
|
</h3>
|
||||||
|
<span v-if="budget.selectedCategories?.length" class="card-subtitle">
|
||||||
|
({{ budget.selectedCategories.join('、') }})
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<van-icon name="arrow-down" class="expand-icon" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="collapsed-footer no-limit-footer">
|
||||||
|
<div class="collapsed-item">
|
||||||
|
<span class="compact-label">实际</span>
|
||||||
|
<span class="compact-value">
|
||||||
|
<slot name="collapsed-amount">
|
||||||
|
{{ budget.current !== undefined ? `¥${budget.current?.toFixed(0) || 0}` : '--' }}
|
||||||
|
</slot>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 展开状态 -->
|
||||||
|
<div v-else class="budget-inner-card">
|
||||||
|
<div class="card-header" style="margin-bottom: 0">
|
||||||
|
<div class="budget-info">
|
||||||
|
<slot name="tag">
|
||||||
|
<van-tag type="success" plain class="status-tag">
|
||||||
|
{{ budget.type === BudgetPeriodType.Year ? '年度' : '月度' }}
|
||||||
|
</van-tag>
|
||||||
|
</slot>
|
||||||
|
<h3 class="card-title" style="max-width: 120px">
|
||||||
|
{{ budget.name }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<slot name="actions">
|
||||||
|
<van-button
|
||||||
|
v-if="budget.description"
|
||||||
|
:icon="showDescription ? 'info' : 'info-o'"
|
||||||
|
size="small"
|
||||||
|
:type="showDescription ? 'primary' : 'default'"
|
||||||
|
plain
|
||||||
|
@click.stop="showDescription = !showDescription"
|
||||||
|
/>
|
||||||
|
<van-button
|
||||||
|
icon="orders-o"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
title="查询关联账单"
|
||||||
|
@click.stop="handleQueryBills"
|
||||||
|
/>
|
||||||
|
<template v-if="budget.category !== 2">
|
||||||
|
<van-button icon="edit" size="small" plain @click.stop="$emit('click', budget)" />
|
||||||
|
</template>
|
||||||
|
</slot>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="budget-body">
|
||||||
|
<div v-if="budget.selectedCategories?.length" class="category-tags">
|
||||||
|
<van-tag
|
||||||
|
v-for="cat in budget.selectedCategories"
|
||||||
|
:key="cat"
|
||||||
|
size="mini"
|
||||||
|
class="category-tag"
|
||||||
|
plain
|
||||||
|
round
|
||||||
>
|
>
|
||||||
|
{{ cat }}
|
||||||
|
</van-tag>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="no-limit-amount-info">
|
||||||
|
<div class="amount-item">
|
||||||
|
<span>
|
||||||
|
<span class="label">实际</span>
|
||||||
|
<span class="value" style="margin-left: 12px"
|
||||||
|
>¥{{ budget.current?.toFixed(0) || 0 }}</span
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="no-limit-notice">
|
||||||
|
<span>
|
||||||
|
<van-icon name="info-o" style="margin-right: 4px" />
|
||||||
|
不记额预算 - 直接计入存款明细
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<van-collapse-transition>
|
||||||
|
<div v-if="budget.description && showDescription" class="budget-description">
|
||||||
|
<div class="description-content rich-html-content" v-html="budget.description" />
|
||||||
|
</div>
|
||||||
|
</van-collapse-transition>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 关联账单列表弹窗 -->
|
||||||
|
<PopupContainer v-model="showBillListModal" title="关联账单列表" height="75%">
|
||||||
<TransactionList
|
<TransactionList
|
||||||
:transactions="billList"
|
:transactions="billList"
|
||||||
:loading="billLoading"
|
:loading="billLoading"
|
||||||
@@ -193,7 +300,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
progressColor: {
|
progressColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#1989fa'
|
default: 'var(--van-primary-color)'
|
||||||
},
|
},
|
||||||
percentClass: {
|
percentClass: {
|
||||||
type: [String, Object],
|
type: [String, Object],
|
||||||
@@ -205,10 +312,9 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['switch-period', 'click'])
|
const emit = defineEmits(['click'])
|
||||||
|
|
||||||
const isExpanded = ref(props.budget.category === 2)
|
const isExpanded = ref(props.budget.category === 2)
|
||||||
const transitionName = ref('slide-left')
|
|
||||||
const showDescription = ref(false)
|
const showDescription = ref(false)
|
||||||
const showBillListModal = ref(false)
|
const showBillListModal = ref(false)
|
||||||
const billList = ref([])
|
const billList = ref([])
|
||||||
@@ -218,16 +324,6 @@ const toggleExpand = () => {
|
|||||||
isExpanded.value = !isExpanded.value
|
isExpanded.value = !isExpanded.value
|
||||||
}
|
}
|
||||||
|
|
||||||
const isNextDisabled = computed(() => {
|
|
||||||
if (!props.budget.periodEnd) return false
|
|
||||||
return new Date(props.budget.periodEnd) > new Date()
|
|
||||||
})
|
|
||||||
|
|
||||||
const handleSwitch = (direction) => {
|
|
||||||
transitionName.value = direction > 0 ? 'slide-left' : 'slide-right'
|
|
||||||
emit('switch-period', direction)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleQueryBills = async () => {
|
const handleQueryBills = async () => {
|
||||||
showBillListModal.value = true
|
showBillListModal.value = true
|
||||||
billLoading.value = true
|
billLoading.value = true
|
||||||
@@ -259,7 +355,6 @@ const handleQueryBills = async () => {
|
|||||||
} else {
|
} else {
|
||||||
billList.value = []
|
billList.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('查询账单列表失败:', error)
|
console.error('查询账单列表失败:', error)
|
||||||
billList.value = []
|
billList.value = []
|
||||||
@@ -269,18 +364,26 @@ const handleQueryBills = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const percentage = computed(() => {
|
const percentage = computed(() => {
|
||||||
if (!props.budget.limit) return 0
|
if (!props.budget.limit) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return Math.round((props.budget.current / props.budget.limit) * 100)
|
return Math.round((props.budget.current / props.budget.limit) * 100)
|
||||||
})
|
})
|
||||||
|
|
||||||
const timePercentage = computed(() => {
|
const timePercentage = computed(() => {
|
||||||
if (!props.budget.periodStart || !props.budget.periodEnd) return 0
|
if (!props.budget.periodStart || !props.budget.periodEnd) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
const start = new Date(props.budget.periodStart).getTime()
|
const start = new Date(props.budget.periodStart).getTime()
|
||||||
const end = new Date(props.budget.periodEnd).getTime()
|
const end = new Date(props.budget.periodEnd).getTime()
|
||||||
const now = new Date().getTime()
|
const now = new Date().getTime()
|
||||||
|
|
||||||
if (now <= start) return 0
|
if (now <= start) {
|
||||||
if (now >= end) return 100
|
return 0
|
||||||
|
}
|
||||||
|
if (now >= end) {
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
|
||||||
return Math.round(((now - start) / (end - start)) * 100)
|
return Math.round(((now - start) / (end - start)) * 100)
|
||||||
})
|
})
|
||||||
@@ -297,6 +400,14 @@ const timePercentage = computed(() => {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-limit-card {
|
||||||
|
border-left: 3px solid var(--van-success-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.collapsed-footer.no-limit-footer {
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
.budget-content-wrapper {
|
.budget-content-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -368,7 +479,7 @@ const timePercentage = computed(() => {
|
|||||||
|
|
||||||
.compact-label {
|
.compact-label {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,60 +493,26 @@ const timePercentage = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.compact-value.warning {
|
.compact-value.warning {
|
||||||
color: #ff976a;
|
color: var(--van-warning-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.compact-value.income {
|
.compact-value.income {
|
||||||
color: #07c160;
|
color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.expand-icon {
|
.expand-icon {
|
||||||
color: #1989fa;
|
color: var(--van-primary-color);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
transition: transform 0.3s ease;
|
transition: transform 0.3s ease;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.collapse-icon {
|
.collapse-icon {
|
||||||
color: #1989fa;
|
color: var(--van-primary-color);
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 切换动画 */
|
|
||||||
.slide-left-enter-active,
|
|
||||||
.slide-left-leave-active,
|
|
||||||
.slide-right-enter-active,
|
|
||||||
.slide-right-leave-active {
|
|
||||||
transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slide-left-enter-from {
|
|
||||||
transform: translateX(100%);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
.slide-left-leave-to {
|
|
||||||
transform: translateX(-100%);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slide-right-enter-from {
|
|
||||||
transform: translateX(-100%);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
.slide-right-leave-to {
|
|
||||||
transform: translateX(100%);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slide-left-leave-active,
|
|
||||||
.slide-right-leave-active {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.budget-info {
|
.budget-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -456,7 +533,7 @@ const timePercentage = computed(() => {
|
|||||||
|
|
||||||
.card-subtitle {
|
.card-subtitle {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -490,7 +567,7 @@ const timePercentage = computed(() => {
|
|||||||
|
|
||||||
:deep(.info-item) .label {
|
:deep(.info-item) .label {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,11 +577,11 @@ const timePercentage = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
:deep(.value.expense) {
|
:deep(.value.expense) {
|
||||||
color: #ee0a24;
|
color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.value.income) {
|
:deep(.value.income) {
|
||||||
color: #07c160;
|
color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-section {
|
.progress-section {
|
||||||
@@ -513,7 +590,7 @@ const timePercentage = computed(() => {
|
|||||||
gap: 12px;
|
gap: 12px;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #646566;
|
color: var(--van-gray-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-section :deep(.van-progress) {
|
.progress-section :deep(.van-progress) {
|
||||||
@@ -532,12 +609,12 @@ const timePercentage = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.percent.warning {
|
.percent.warning {
|
||||||
color: #ff976a;
|
color: var(--van-warning-color);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.percent.income {
|
.percent.income {
|
||||||
color: #07c160;
|
color: var(--van-success-color);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,63 +628,67 @@ const timePercentage = computed(() => {
|
|||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-limit-notice {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--van-text-color-2);
|
||||||
|
background-color: var(--van-light-gray);
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-limit-amount-info {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 0px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-item .label {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--van-text-color-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-item .value {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--van-success-color);
|
||||||
|
}
|
||||||
|
|
||||||
.budget-description {
|
.budget-description {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
background-color: #f7f8fa;
|
background-color: var(--van-background);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.description-content {
|
.description-content {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
color: #646566;
|
color: var(--van-gray-6);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-footer {
|
.mandatory-mark {
|
||||||
display: flex;
|
margin-left: 4px;
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
color: #969799;
|
|
||||||
padding: 12px 12px 0;
|
|
||||||
padding-top: 8px;
|
|
||||||
border-top: 1px solid #ebedf0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.period-navigation {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.period-text {
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
display: inline-block;
|
||||||
color: #323233;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-icon {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
padding: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: #1989fa;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.card-footer {
|
|
||||||
border-top-color: #2c2c2c;
|
|
||||||
}
|
|
||||||
.period-text {
|
|
||||||
color: #f5f5f5;
|
|
||||||
}
|
|
||||||
.budget-description {
|
.budget-description {
|
||||||
background-color: #2c2c2c;
|
background-color: var(--van-background-2);
|
||||||
}
|
}
|
||||||
.description-content {
|
.description-content {
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
}
|
}
|
||||||
.collapsed-row .value {
|
.collapsed-row .value {
|
||||||
color: #f5f5f5;
|
color: var(--van-text-color);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} */
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
1066
Web/src/components/Budget/BudgetChartAnalysis.vue
Normal file
1066
Web/src/components/Budget/BudgetChartAnalysis.vue
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<PopupContainer
|
<PopupContainer
|
||||||
v-model="visible"
|
v-model="visible"
|
||||||
:title="isEdit ? `编辑${getCategoryName(form.category)}预算` : `新增${getCategoryName(form.category)}预算`"
|
:title="
|
||||||
|
isEdit
|
||||||
|
? `编辑${getCategoryName(form.category)}预算`
|
||||||
|
: `新增${getCategoryName(form.category)}预算`
|
||||||
|
"
|
||||||
height="75%"
|
height="75%"
|
||||||
>
|
>
|
||||||
<div class="add-budget-form">
|
<div class="add-budget-form">
|
||||||
@@ -14,19 +18,55 @@
|
|||||||
placeholder="例如:每月餐饮、年度奖金"
|
placeholder="例如:每月餐饮、年度奖金"
|
||||||
:rules="[{ required: true, message: '请填写预算名称' }]"
|
:rules="[{ required: true, message: '请填写预算名称' }]"
|
||||||
/>
|
/>
|
||||||
<van-field name="type" label="统计周期">
|
<!-- 新增:不记额预算复选框 -->
|
||||||
|
<van-field label="不记额预算">
|
||||||
|
<template #input>
|
||||||
|
<van-checkbox
|
||||||
|
v-model="form.noLimit"
|
||||||
|
@update:model-value="onNoLimitChange"
|
||||||
|
>
|
||||||
|
不记额预算
|
||||||
|
</van-checkbox>
|
||||||
|
</template>
|
||||||
|
</van-field>
|
||||||
|
<!-- 新增:硬性消费复选框 -->
|
||||||
|
<van-field :label="form.category === BudgetCategory.Expense ? '硬性消费' : '硬性收入'">
|
||||||
|
<template #input>
|
||||||
|
<div class="mandatory-wrapper">
|
||||||
|
<van-checkbox
|
||||||
|
v-model="form.isMandatoryExpense"
|
||||||
|
:disabled="form.noLimit"
|
||||||
|
>
|
||||||
|
{{ form.category === BudgetCategory.Expense ? '硬性消费' : '硬性收入' }}
|
||||||
|
<span class="mandatory-tip">
|
||||||
|
当前周期 月/年 按天数自动累加(无记录时)
|
||||||
|
</span>
|
||||||
|
</van-checkbox>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</van-field>
|
||||||
|
<van-field
|
||||||
|
name="type"
|
||||||
|
label="统计周期"
|
||||||
|
>
|
||||||
<template #input>
|
<template #input>
|
||||||
<van-radio-group
|
<van-radio-group
|
||||||
v-model="form.type"
|
v-model="form.type"
|
||||||
direction="horizontal"
|
direction="horizontal"
|
||||||
:disabled="isEdit"
|
:disabled="isEdit || form.noLimit"
|
||||||
>
|
>
|
||||||
<van-radio :name="BudgetPeriodType.Month">月</van-radio>
|
<van-radio :name="BudgetPeriodType.Month">
|
||||||
<van-radio :name="BudgetPeriodType.Year">年</van-radio>
|
月
|
||||||
|
</van-radio>
|
||||||
|
<van-radio :name="BudgetPeriodType.Year">
|
||||||
|
年
|
||||||
|
</van-radio>
|
||||||
</van-radio-group>
|
</van-radio-group>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
|
<!-- 仅当未选中"不记额预算"时显示预算金额 -->
|
||||||
<van-field
|
<van-field
|
||||||
|
v-if="!form.noLimit"
|
||||||
v-model="form.limit"
|
v-model="form.limit"
|
||||||
type="number"
|
type="number"
|
||||||
name="limit"
|
name="limit"
|
||||||
@@ -40,8 +80,16 @@
|
|||||||
</van-field>
|
</van-field>
|
||||||
<van-field label="相关分类">
|
<van-field label="相关分类">
|
||||||
<template #input>
|
<template #input>
|
||||||
<div v-if="form.selectedCategories.length === 0" style="color: #c8c9cc;">可多选分类</div>
|
<div
|
||||||
<div v-else class="selected-categories">
|
v-if="form.selectedCategories.length === 0"
|
||||||
|
style="color: var(--van-text-color-3)"
|
||||||
|
>
|
||||||
|
可多选分类
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="selected-categories"
|
||||||
|
>
|
||||||
<span class="ellipsis-text">
|
<span class="ellipsis-text">
|
||||||
{{ form.selectedCategories.join('、') }}
|
{{ form.selectedCategories.join('、') }}
|
||||||
</span>
|
</span>
|
||||||
@@ -59,7 +107,14 @@
|
|||||||
</van-form>
|
</van-form>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<van-button block round type="primary" @click="onSubmit">保存预算</van-button>
|
<van-button
|
||||||
|
block
|
||||||
|
round
|
||||||
|
type="primary"
|
||||||
|
@click="onSubmit"
|
||||||
|
>
|
||||||
|
保存预算
|
||||||
|
</van-button>
|
||||||
</template>
|
</template>
|
||||||
</PopupContainer>
|
</PopupContainer>
|
||||||
</template>
|
</template>
|
||||||
@@ -83,14 +138,12 @@ const form = reactive({
|
|||||||
type: BudgetPeriodType.Month,
|
type: BudgetPeriodType.Month,
|
||||||
category: BudgetCategory.Expense,
|
category: BudgetCategory.Expense,
|
||||||
limit: '',
|
limit: '',
|
||||||
selectedCategories: []
|
selectedCategories: [],
|
||||||
|
noLimit: false, // 新增字段
|
||||||
|
isMandatoryExpense: false // 新增:硬性消费
|
||||||
})
|
})
|
||||||
|
|
||||||
const open = ({
|
const open = ({ data, isEditFlag, category }) => {
|
||||||
data,
|
|
||||||
isEditFlag,
|
|
||||||
category
|
|
||||||
}) => {
|
|
||||||
if (category === undefined) {
|
if (category === undefined) {
|
||||||
showToast('缺少必要参数:category')
|
showToast('缺少必要参数:category')
|
||||||
return
|
return
|
||||||
@@ -104,7 +157,9 @@ const open = ({
|
|||||||
type: data.type,
|
type: data.type,
|
||||||
category: category,
|
category: category,
|
||||||
limit: data.limit,
|
limit: data.limit,
|
||||||
selectedCategories: data.selectedCategories ? [...data.selectedCategories] : []
|
selectedCategories: data.selectedCategories ? [...data.selectedCategories] : [],
|
||||||
|
noLimit: data.noLimit || false, // 新增
|
||||||
|
isMandatoryExpense: data.isMandatoryExpense || false // 新增:硬性消费
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Object.assign(form, {
|
Object.assign(form, {
|
||||||
@@ -113,7 +168,9 @@ const open = ({
|
|||||||
type: BudgetPeriodType.Month,
|
type: BudgetPeriodType.Month,
|
||||||
category: category,
|
category: category,
|
||||||
limit: '',
|
limit: '',
|
||||||
selectedCategories: []
|
selectedCategories: [],
|
||||||
|
noLimit: false, // 新增
|
||||||
|
isMandatoryExpense: false // 新增:硬性消费
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
visible.value = true
|
visible.value = true
|
||||||
@@ -124,15 +181,21 @@ defineExpose({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const budgetType = computed(() => {
|
const budgetType = computed(() => {
|
||||||
return form.category === BudgetCategory.Expense ? 0 : (form.category === BudgetCategory.Income ? 1 : 2)
|
return form.category === BudgetCategory.Expense
|
||||||
|
? 0
|
||||||
|
: form.category === BudgetCategory.Income
|
||||||
|
? 1
|
||||||
|
: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
const data = {
|
const data = {
|
||||||
...form,
|
...form,
|
||||||
limit: parseFloat(form.limit),
|
limit: form.noLimit ? 0 : parseFloat(form.limit), // 不记额时金额为0
|
||||||
selectedCategories: form.selectedCategories
|
selectedCategories: form.selectedCategories,
|
||||||
|
noLimit: form.noLimit, // 新增
|
||||||
|
isMandatoryExpense: form.isMandatoryExpense // 新增:硬性消费
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = form.id ? await updateBudget(data) : await createBudget(data)
|
const res = form.id ? await updateBudget(data) : await createBudget(data)
|
||||||
@@ -159,6 +222,15 @@ const getCategoryName = (category) => {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onNoLimitChange = (value) => {
|
||||||
|
if (value) {
|
||||||
|
// 选中不记额时,自动设为年度预算
|
||||||
|
form.type = BudgetPeriodType.Year
|
||||||
|
// 选中不记额时,清除硬性消费选择
|
||||||
|
form.isMandatoryExpense = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -176,7 +248,7 @@ const getCategoryName = (category) => {
|
|||||||
|
|
||||||
.ellipsis-text {
|
.ellipsis-text {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #323233;
|
color: var(--van-text-color);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -185,7 +257,19 @@ const getCategoryName = (category) => {
|
|||||||
|
|
||||||
.no-data {
|
.no-data {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mandatory-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mandatory-tip {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--van-text-color-3);
|
||||||
|
margin-left: 6px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="summary-container">
|
<div class="summary-container">
|
||||||
<transition :name="transitionName" mode="out-in">
|
<transition :name="transitionName" mode="out-in">
|
||||||
<div v-if="stats && (stats.month || stats.year)" :key="dateKey" class="summary-card common-card">
|
<div
|
||||||
|
v-if="stats && (stats.month || stats.year)"
|
||||||
|
:key="dateKey"
|
||||||
|
class="summary-card common-card"
|
||||||
|
>
|
||||||
<!-- 左切换按钮 -->
|
<!-- 左切换按钮 -->
|
||||||
<div class="nav-arrow left" @click.stop="changeMonth(-1)">
|
<div class="nav-arrow left" @click.stop="changeMonth(-1)">
|
||||||
<van-icon name="arrow-left" />
|
<van-icon name="arrow-left" />
|
||||||
@@ -20,7 +24,7 @@
|
|||||||
<span class="amount">¥{{ formatMoney(stats[key]?.limit || 0) }}</span>
|
<span class="amount">¥{{ formatMoney(stats[key]?.limit || 0) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="config.showDivider" class="divider"></div>
|
<div v-if="config.showDivider" class="divider" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -71,8 +75,7 @@ const dateKey = computed(() => props.date.getFullYear() + '-' + props.date.getMo
|
|||||||
|
|
||||||
const isCurrentMonth = computed(() => {
|
const isCurrentMonth = computed(() => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
return props.date.getFullYear() === now.getFullYear() &&
|
return props.date.getFullYear() === now.getFullYear() && props.date.getMonth() === now.getMonth()
|
||||||
props.date.getMonth() === now.getMonth()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const periodConfigs = computed(() => ({
|
const periodConfigs = computed(() => ({
|
||||||
@@ -94,7 +97,10 @@ const changeMonth = (delta) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatMoney = (val) => {
|
const formatMoney = (val) => {
|
||||||
return parseFloat(val || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 })
|
return parseFloat(val || 0).toLocaleString(undefined, {
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 0
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -130,7 +136,7 @@ const formatMoney = (val) => {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
color: #c8c9cc;
|
color: var(--van-gray-5);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
@@ -141,6 +147,17 @@ const formatMoney = (val) => {
|
|||||||
background-color: rgba(0, 0, 0, 0.02);
|
background-color: rgba(0, 0, 0, 0.02);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-arrow.disabled {
|
||||||
|
color: #c8c9cc;
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.35;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-arrow.disabled:active {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-arrow.left {
|
.nav-arrow.left {
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
@@ -150,7 +167,7 @@ const formatMoney = (val) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-arrow.disabled {
|
.nav-arrow.disabled {
|
||||||
color: #f2f3f5;
|
color: var(--van-gray-3);
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,26 +217,26 @@ const formatMoney = (val) => {
|
|||||||
|
|
||||||
.summary-item .label {
|
.summary-item .label {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item .value {
|
.summary-item .value {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #323233;
|
color: var(--van-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item :deep(.value.expense) {
|
.summary-item :deep(.value.expense) {
|
||||||
color: #ee0a24;
|
color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item :deep(.value.income) {
|
.summary-item :deep(.value.income) {
|
||||||
color: #07c160;
|
color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item :deep(.value.warning) {
|
.summary-item :deep(.value.warning) {
|
||||||
color: #ff976a;
|
color: var(--van-warning-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item .unit {
|
.summary-item .unit {
|
||||||
@@ -230,7 +247,7 @@ const formatMoney = (val) => {
|
|||||||
|
|
||||||
.summary-item .sub-info {
|
.summary-item .sub-info {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #c8c9cc;
|
color: var(--van-text-color-3);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -238,35 +255,35 @@ const formatMoney = (val) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.summary-item .amount {
|
.summary-item .amount {
|
||||||
color: #646566;
|
color: var(--van-text-color-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-item .separator {
|
.summary-item .separator {
|
||||||
color: #c8c9cc;
|
color: var(--van-text-color-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
width: 1px;
|
width: 1px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
background-color: #ebedf0;
|
background-color: var(--van-border-color);
|
||||||
margin: 0 4px;
|
margin: 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.nav-arrow:active {
|
.nav-arrow:active {
|
||||||
background-color: rgba(255, 255, 255, 0.05);
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
}
|
}
|
||||||
.nav-arrow.disabled {
|
.nav-arrow.disabled {
|
||||||
color: #323233;
|
color: var(--van-text-color);
|
||||||
}
|
}
|
||||||
.summary-item .value {
|
.summary-item .value {
|
||||||
color: #f5f5f5;
|
color: var(--van-text-color);
|
||||||
}
|
}
|
||||||
.summary-item .amount {
|
.summary-item .amount {
|
||||||
color: #c8c9cc;
|
color: var(--van-text-color-3);
|
||||||
}
|
}
|
||||||
.divider {
|
.divider {
|
||||||
background-color: #2c2c2c;
|
background-color: var(--van-border-color);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} */
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<PopupContainer
|
<PopupContainer v-model="visible" title="设置存款分类" height="60%">
|
||||||
v-model="visible"
|
|
||||||
title="设置存款分类"
|
|
||||||
height="60%"
|
|
||||||
>
|
|
||||||
<div class="savings-config-content">
|
<div class="savings-config-content">
|
||||||
<div class="config-header">
|
<div class="config-header">
|
||||||
<p class="subtitle">这些分类的统计值将计入“存款”中</p>
|
<p class="subtitle">这些分类的统计值将计入“存款”中</p>
|
||||||
@@ -52,7 +48,7 @@ const fetchConfig = async () => {
|
|||||||
try {
|
try {
|
||||||
const res = await getConfig('SavingsCategories')
|
const res = await getConfig('SavingsCategories')
|
||||||
if (res.success && res.data) {
|
if (res.success && res.data) {
|
||||||
selectedCategories.value = res.data.split(',').filter(x => x)
|
selectedCategories.value = res.data.split(',').filter((x) => x)
|
||||||
} else {
|
} else {
|
||||||
selectedCategories.value = []
|
selectedCategories.value = []
|
||||||
}
|
}
|
||||||
@@ -91,7 +87,7 @@ const onSubmit = async () => {
|
|||||||
|
|
||||||
.subtitle {
|
.subtitle {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +99,7 @@ const onSubmit = async () => {
|
|||||||
|
|
||||||
.no-data {
|
.no-data {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 20px 0;
|
padding: 20px 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,17 +98,21 @@ const innerOptions = ref([])
|
|||||||
const addClassifyDialogRef = ref()
|
const addClassifyDialogRef = ref()
|
||||||
|
|
||||||
const displayOptions = computed(() => {
|
const displayOptions = computed(() => {
|
||||||
if (props.options) return props.options
|
if (props.options) {
|
||||||
|
return props.options
|
||||||
|
}
|
||||||
return innerOptions.value
|
return innerOptions.value
|
||||||
})
|
})
|
||||||
|
|
||||||
const fetchOptions = async () => {
|
const fetchOptions = async () => {
|
||||||
if (props.options) return
|
if (props.options) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getCategoryList(props.type)
|
const response = await getCategoryList(props.type)
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
innerOptions.value = (response.data || []).map(item => ({
|
innerOptions.value = (response.data || []).map((item) => ({
|
||||||
text: item.name,
|
text: item.name,
|
||||||
value: item.name,
|
value: item.name,
|
||||||
id: item.id
|
id: item.id
|
||||||
@@ -152,9 +156,12 @@ const handleAddConfirm = async (categoryName) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => props.type, () => {
|
watch(
|
||||||
|
() => props.type,
|
||||||
|
() => {
|
||||||
fetchOptions()
|
fetchOptions()
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchOptions()
|
fetchOptions()
|
||||||
@@ -175,8 +182,10 @@ const isSelected = (item) => {
|
|||||||
|
|
||||||
// 是否全部选中
|
// 是否全部选中
|
||||||
const isAllSelected = computed(() => {
|
const isAllSelected = computed(() => {
|
||||||
if (!props.multiple || displayOptions.value.length === 0) return false
|
if (!props.multiple || displayOptions.value.length === 0) {
|
||||||
return displayOptions.value.every(item => props.modelValue.includes(item.text))
|
return false
|
||||||
|
}
|
||||||
|
return displayOptions.value.every((item) => props.modelValue.includes(item.text))
|
||||||
})
|
})
|
||||||
|
|
||||||
// 是否有任何选中
|
// 是否有任何选中
|
||||||
@@ -208,13 +217,15 @@ const toggleItem = (item) => {
|
|||||||
|
|
||||||
// 切换全选
|
// 切换全选
|
||||||
const toggleAll = () => {
|
const toggleAll = () => {
|
||||||
if (!props.multiple) return
|
if (!props.multiple) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (isAllSelected.value) {
|
if (isAllSelected.value) {
|
||||||
emit('update:modelValue', [])
|
emit('update:modelValue', [])
|
||||||
emit('change', [])
|
emit('change', [])
|
||||||
} else {
|
} else {
|
||||||
const allValues = displayOptions.value.map(item => item.text)
|
const allValues = displayOptions.value.map((item) => item.text)
|
||||||
emit('update:modelValue', allValues)
|
emit('update:modelValue', allValues)
|
||||||
emit('change', allValues)
|
emit('change', allValues)
|
||||||
}
|
}
|
||||||
|
|||||||
446
Web/src/components/ContributionHeatmap.vue
Normal file
446
Web/src/components/ContributionHeatmap.vue
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
<template>
|
||||||
|
<div class="heatmap-card">
|
||||||
|
<div class="grid-row">
|
||||||
|
<!-- Weekday Labels (Fixed Left) -->
|
||||||
|
<div class="weekday-col-fixed">
|
||||||
|
<div class="weekday-label">
|
||||||
|
二
|
||||||
|
</div>
|
||||||
|
<div class="weekday-label">
|
||||||
|
四
|
||||||
|
</div>
|
||||||
|
<div class="weekday-label">
|
||||||
|
六
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Scrollable Heatmap Area -->
|
||||||
|
<div
|
||||||
|
ref="scrollContainer"
|
||||||
|
class="heatmap-scroll-container"
|
||||||
|
>
|
||||||
|
<div class="heatmap-content">
|
||||||
|
<!-- Month Labels -->
|
||||||
|
<div class="month-row">
|
||||||
|
<div
|
||||||
|
v-for="(month, index) in monthLabels"
|
||||||
|
:key="index"
|
||||||
|
class="month-label"
|
||||||
|
:style="{ left: month.left + 'px' }"
|
||||||
|
>
|
||||||
|
{{ month.text }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Heatmap Grid -->
|
||||||
|
<div class="heatmap-grid">
|
||||||
|
<div
|
||||||
|
v-for="(week, wIndex) in weeks"
|
||||||
|
:key="wIndex"
|
||||||
|
class="heatmap-week"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="(day, dIndex) in week"
|
||||||
|
:key="dIndex"
|
||||||
|
class="heatmap-cell"
|
||||||
|
:class="getLevelClass(day)"
|
||||||
|
@click="onCellClick(day)"
|
||||||
|
>
|
||||||
|
<!-- Tooltip could be implemented here or using title -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="heatmap-footer">
|
||||||
|
<div
|
||||||
|
v-if="totalCount > 0"
|
||||||
|
class="summary-text"
|
||||||
|
>
|
||||||
|
过去一年共 {{ totalCount }} 笔交易
|
||||||
|
</div>
|
||||||
|
<div class="legend">
|
||||||
|
<span>少</span>
|
||||||
|
<div class="legend-item level-0" />
|
||||||
|
<div class="legend-item level-1" />
|
||||||
|
<div class="legend-item level-2" />
|
||||||
|
<div class="legend-item level-3" />
|
||||||
|
<div class="legend-item level-4" />
|
||||||
|
<span>多</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, nextTick } from 'vue'
|
||||||
|
import { getDailyStatisticsRange } from '@/api/statistics'
|
||||||
|
|
||||||
|
const stats = ref({})
|
||||||
|
const weeks = ref([])
|
||||||
|
const monthLabels = ref([])
|
||||||
|
const totalCount = ref(0)
|
||||||
|
const scrollContainer = ref(null)
|
||||||
|
const thresholds = ref([2, 4, 7]) // Default thresholds
|
||||||
|
|
||||||
|
const CELL_SIZE = 15
|
||||||
|
const CELL_GAP = 3
|
||||||
|
const WEEK_WIDTH = CELL_SIZE + CELL_GAP
|
||||||
|
|
||||||
|
const formatDate = (d) => {
|
||||||
|
const year = d.getFullYear()
|
||||||
|
const month = String(d.getMonth() + 1).padStart(2, '0')
|
||||||
|
const day = String(d.getDate()).padStart(2, '0')
|
||||||
|
return `${year}-${month}-${day}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
const endDate = new Date()
|
||||||
|
const startDate = new Date()
|
||||||
|
startDate.setFullYear(endDate.getFullYear() - 1)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getDailyStatisticsRange({
|
||||||
|
startDate: formatDate(startDate),
|
||||||
|
endDate: formatDate(endDate)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.success) {
|
||||||
|
const map = {}
|
||||||
|
let count = 0
|
||||||
|
res.data.forEach((item) => {
|
||||||
|
map[item.date] = item
|
||||||
|
count += item.count
|
||||||
|
})
|
||||||
|
stats.value = map
|
||||||
|
totalCount.value = count
|
||||||
|
|
||||||
|
// Calculate thresholds based on last 15 days average
|
||||||
|
const today = new Date()
|
||||||
|
let last15DaysSum = 0
|
||||||
|
for (let i = 0; i < 15; i++) {
|
||||||
|
const d = new Date(today)
|
||||||
|
d.setDate(d.getDate() - i)
|
||||||
|
const dateStr = formatDate(d)
|
||||||
|
last15DaysSum += map[dateStr]?.count || 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const avg = last15DaysSum / 15
|
||||||
|
// Step size calculation: ensure at least 1, roughly avg/2 to create spread
|
||||||
|
// Level 1: 1 ~ step
|
||||||
|
// Level 2: step+1 ~ step*2
|
||||||
|
// Level 3: step*2+1 ~ step*3
|
||||||
|
// Level 4: > step*3
|
||||||
|
const step = Math.max(Math.ceil(avg / 2), 1)
|
||||||
|
thresholds.value = [step, step * 2, step * 3]
|
||||||
|
|
||||||
|
generateHeatmapData(startDate, endDate)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to fetch heatmap data', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateHeatmapData = (startDate, endDate) => {
|
||||||
|
const current = new Date(startDate)
|
||||||
|
|
||||||
|
const allDays = []
|
||||||
|
|
||||||
|
// Adjust start date to be Monday to align weeks
|
||||||
|
// 0 = Sunday, 1 = Monday
|
||||||
|
const startDay = current.getDay()
|
||||||
|
// If startDay is 0 (Sunday), we need to go back 6 days to Monday
|
||||||
|
// If startDay is 1 (Monday), we are good
|
||||||
|
// If startDay is 2 (Tuesday), we need to go back 1 day
|
||||||
|
// Formula: (day + 6) % 7 days back?
|
||||||
|
// Monday (1) -> 0 days back
|
||||||
|
// Sunday (0) -> 6 days back
|
||||||
|
// Tuesday (2) -> 1 day back
|
||||||
|
|
||||||
|
// We don't necessarily need to subtract from startDate for data fetching,
|
||||||
|
// but for grid alignment we want the first column to start on Monday.
|
||||||
|
|
||||||
|
const alignStart = new Date(startDate)
|
||||||
|
// alignStart.setDate(alignStart.getDate() - daysToSubtract);
|
||||||
|
|
||||||
|
const tempDate = new Date(alignStart)
|
||||||
|
while (tempDate <= endDate) {
|
||||||
|
const dateStr = formatDate(tempDate)
|
||||||
|
allDays.push({
|
||||||
|
date: dateStr,
|
||||||
|
count: stats.value[dateStr]?.count || 0,
|
||||||
|
obj: new Date(tempDate)
|
||||||
|
})
|
||||||
|
tempDate.setDate(tempDate.getDate() + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now group into weeks
|
||||||
|
const resultWeeks = []
|
||||||
|
let currentWeek = []
|
||||||
|
|
||||||
|
// Pad first week if start date is not Monday
|
||||||
|
// allDays[0] is startDate
|
||||||
|
const firstDayObj = new Date(allDays[0].date)
|
||||||
|
const firstDay = firstDayObj.getDay() // 0-6 (Sun-Sat)
|
||||||
|
|
||||||
|
// We want Monday (1) to be index 0
|
||||||
|
// Mon(1)->0, Tue(2)->1, ..., Sun(0)->6
|
||||||
|
const padCount = (firstDay + 6) % 7
|
||||||
|
|
||||||
|
for (let i = 0; i < padCount; i++) {
|
||||||
|
currentWeek.push(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
allDays.forEach((day) => {
|
||||||
|
currentWeek.push(day)
|
||||||
|
if (currentWeek.length === 7) {
|
||||||
|
resultWeeks.push(currentWeek)
|
||||||
|
currentWeek = []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Push last partial week
|
||||||
|
if (currentWeek.length > 0) {
|
||||||
|
while (currentWeek.length < 7) {
|
||||||
|
currentWeek.push(null)
|
||||||
|
}
|
||||||
|
resultWeeks.push(currentWeek)
|
||||||
|
}
|
||||||
|
|
||||||
|
weeks.value = resultWeeks
|
||||||
|
|
||||||
|
// Generate Month Labels
|
||||||
|
const labels = []
|
||||||
|
let lastMonth = -1
|
||||||
|
|
||||||
|
resultWeeks.forEach((week, index) => {
|
||||||
|
// Check the first valid day in the week
|
||||||
|
const day = week.find((d) => d !== null)
|
||||||
|
if (day) {
|
||||||
|
const d = new Date(day.date)
|
||||||
|
const month = d.getMonth()
|
||||||
|
if (month !== lastMonth) {
|
||||||
|
labels.push({
|
||||||
|
text: d.toLocaleString('zh-CN', { month: 'short' }),
|
||||||
|
left: index * WEEK_WIDTH
|
||||||
|
})
|
||||||
|
lastMonth = month
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
monthLabels.value = labels
|
||||||
|
|
||||||
|
// Scroll to end
|
||||||
|
nextTick(() => {
|
||||||
|
if (scrollContainer.value) {
|
||||||
|
scrollContainer.value.scrollLeft = scrollContainer.value.scrollWidth
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLevelClass = (day) => {
|
||||||
|
if (!day) {
|
||||||
|
return 'invisible'
|
||||||
|
}
|
||||||
|
const count = day.count
|
||||||
|
if (count === 0) {
|
||||||
|
return 'level-0'
|
||||||
|
}
|
||||||
|
if (count <= thresholds.value[0]) {
|
||||||
|
return 'level-1'
|
||||||
|
}
|
||||||
|
if (count <= thresholds.value[1]) {
|
||||||
|
return 'level-2'
|
||||||
|
}
|
||||||
|
if (count <= thresholds.value[2]) {
|
||||||
|
return 'level-3'
|
||||||
|
}
|
||||||
|
return 'level-4'
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCellClick = (day) => {
|
||||||
|
if (day) {
|
||||||
|
// Emit event or show toast
|
||||||
|
// console.log(day);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
refresh: fetchData
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchData()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.heatmap-card {
|
||||||
|
background: var(--van-background-2);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
color: var(--van-text-color);
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
||||||
|
margin: 0 10px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
border: 1px solid var(--van-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-scroll-container {
|
||||||
|
overflow-x: auto;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
scrollbar-width: none;
|
||||||
|
flex: 1; /* Take remaining space */
|
||||||
|
}
|
||||||
|
.heatmap-scroll-container::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-content {
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-row {
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
height: 15px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.months-container {
|
||||||
|
position: relative;
|
||||||
|
flex-grow: 1;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-label {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 10px;
|
||||||
|
top: 0;
|
||||||
|
color: var(--van-text-color-2);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-row {
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.weekday-col-fixed {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding-top: 19px; /* Align with cells (month row height 15px + margin 4px) */
|
||||||
|
margin-right: 6px;
|
||||||
|
font-size: 9px;
|
||||||
|
height: 142px; /* Total height: 15 (month) + 4 (margin) + 123 (grid) */
|
||||||
|
color: var(--van-text-color-2);
|
||||||
|
flex-shrink: 0;
|
||||||
|
z-index: 10;
|
||||||
|
background-color: var(--van-background-2); /* Match card background */
|
||||||
|
}
|
||||||
|
|
||||||
|
.weekday-label {
|
||||||
|
height: 15px;
|
||||||
|
line-height: 15px;
|
||||||
|
margin-top: 15px; /* (15 cell + 3 gap)*2 - 15 height - previous margin? No. */
|
||||||
|
/*
|
||||||
|
Row 0: 0px top
|
||||||
|
Row 1: 18px top (15+3) - Label "二" aligns here? No, "二" is usually row 1 (index 1, 2nd row)
|
||||||
|
If we want to align with 2nd, 4th, 6th rows (indices 1, 3, 5):
|
||||||
|
|
||||||
|
Row 0: y=0
|
||||||
|
Row 1: y=18
|
||||||
|
Row 2: y=36
|
||||||
|
Row 3: y=54
|
||||||
|
Row 4: y=72
|
||||||
|
Row 5: y=90
|
||||||
|
Row 6: y=108
|
||||||
|
|
||||||
|
Label 1 ("二") at Row 1 (y=18)
|
||||||
|
Label 2 ("四") at Row 3 (y=54)
|
||||||
|
Label 3 ("六") at Row 5 (y=90)
|
||||||
|
|
||||||
|
Padding-top of container is 19px.
|
||||||
|
First label margin-top: 18px
|
||||||
|
Second label margin-top: (54 - (18+15)) = 21px
|
||||||
|
Third label margin-top: (90 - (54+15)) = 21px
|
||||||
|
|
||||||
|
Let's try standard spacing.
|
||||||
|
Gap between tops is 36px (2 rows).
|
||||||
|
Height of label is 15px.
|
||||||
|
Margin needed is 36 - 15 = 21px.
|
||||||
|
|
||||||
|
First label top needs to be at 18px relative to grid start.
|
||||||
|
Container padding-top aligns with grid start (row 0 top).
|
||||||
|
So first label margin-top should be 18px.
|
||||||
|
*/
|
||||||
|
margin-top: 21px;
|
||||||
|
}
|
||||||
|
.weekday-label:first-child {
|
||||||
|
margin-top: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-grid {
|
||||||
|
display: flex;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-week {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-cell {
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background-color: var(--van-gray-2);
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-cell.invisible {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.level-0 {
|
||||||
|
background-color: var(--heatmap-level-0);
|
||||||
|
}
|
||||||
|
.level-1 {
|
||||||
|
background-color: var(--heatmap-level-1);
|
||||||
|
}
|
||||||
|
.level-2 {
|
||||||
|
background-color: var(--heatmap-level-2);
|
||||||
|
}
|
||||||
|
.level-3 {
|
||||||
|
background-color: var(--heatmap-level-3);
|
||||||
|
}
|
||||||
|
.level-4 {
|
||||||
|
background-color: var(--heatmap-level-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--van-text-color-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-item {
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -6,11 +6,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Bill Modal -->
|
<!-- Add Bill Modal -->
|
||||||
<PopupContainer
|
<PopupContainer v-model="showAddBill" title="记一笔" height="75%">
|
||||||
v-model="showAddBill"
|
|
||||||
title="记一笔"
|
|
||||||
height="75%"
|
|
||||||
>
|
|
||||||
<van-tabs v-model:active="activeTab" shrink>
|
<van-tabs v-model:active="activeTab" shrink>
|
||||||
<van-tab title="一句话录账" name="one">
|
<van-tab title="一句话录账" name="one">
|
||||||
<OneLineBillAdd :key="componentKey" @success="handleSuccess" />
|
<OneLineBillAdd :key="componentKey" @success="handleSuccess" />
|
||||||
@@ -79,6 +75,6 @@ const handleSuccess = () => {
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background-color: #fff;
|
background-color: var(--van-background-2);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -13,10 +13,12 @@
|
|||||||
<div class="popup-header-fixed">
|
<div class="popup-header-fixed">
|
||||||
<!-- 标题行 (无子标题且有操作时使用 Grid 布局) -->
|
<!-- 标题行 (无子标题且有操作时使用 Grid 布局) -->
|
||||||
<div class="header-title-row" :class="{ 'has-actions': !subtitle && hasActions }">
|
<div class="header-title-row" :class="{ 'has-actions': !subtitle && hasActions }">
|
||||||
<h3 class="popup-title">{{ title }}</h3>
|
<h3 class="popup-title">
|
||||||
|
{{ title }}
|
||||||
|
</h3>
|
||||||
<!-- 无子标题时,操作按钮与标题同行 -->
|
<!-- 无子标题时,操作按钮与标题同行 -->
|
||||||
<div v-if="!subtitle && hasActions" class="header-actions-inline">
|
<div v-if="!subtitle && hasActions" class="header-actions-inline">
|
||||||
<slot name="header-actions"></slot>
|
<slot name="header-actions" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -24,18 +26,18 @@
|
|||||||
<div v-if="subtitle" class="header-stats">
|
<div v-if="subtitle" class="header-stats">
|
||||||
<span class="stats-text" v-html="subtitle" />
|
<span class="stats-text" v-html="subtitle" />
|
||||||
<!-- 额外操作插槽 -->
|
<!-- 额外操作插槽 -->
|
||||||
<slot v-if="hasActions" name="header-actions"></slot>
|
<slot v-if="hasActions" name="header-actions" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 内容区域(可滚动) -->
|
<!-- 内容区域(可滚动) -->
|
||||||
<div class="popup-scroll-content">
|
<div class="popup-scroll-content">
|
||||||
<slot></slot>
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 底部页脚,固定不可滚动 -->
|
<!-- 底部页脚,固定不可滚动 -->
|
||||||
<div v-if="slots.footer" class="popup-footer-fixed">
|
<div v-if="slots.footer" class="popup-footer-fixed">
|
||||||
<slot name="footer"></slot>
|
<slot name="footer" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</van-popup>
|
</van-popup>
|
||||||
@@ -47,24 +49,24 @@ import { computed, useSlots } from 'vue'
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true,
|
required: true
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: ''
|
||||||
},
|
},
|
||||||
subtitle: {
|
subtitle: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: ''
|
||||||
},
|
},
|
||||||
height: {
|
height: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '80%',
|
default: '80%'
|
||||||
},
|
},
|
||||||
closeable: {
|
closeable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
@@ -74,7 +76,7 @@ const slots = useSlots()
|
|||||||
// 双向绑定
|
// 双向绑定
|
||||||
const visible = computed({
|
const visible = computed({
|
||||||
get: () => props.modelValue,
|
get: () => props.modelValue,
|
||||||
set: (value) => emit('update:modelValue', value),
|
set: (value) => emit('update:modelValue', value)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 判断是否有操作按钮
|
// 判断是否有操作按钮
|
||||||
@@ -91,8 +93,8 @@ const hasActions = computed(() => !!slots['header-actions'])
|
|||||||
.popup-header-fixed {
|
.popup-header-fixed {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
background-color: var(--van-background-2, #f7f8fa);
|
background-color: var(--van-background-2);
|
||||||
border-bottom: 1px solid var(--van-border-color, #ebedf0);
|
border-bottom: 1px solid var(--van-border-color);
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
@@ -121,7 +123,7 @@ const hasActions = computed(() => !!slots['header-actions'])
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--van-text-color, #323233);
|
color: var(--van-text-color);
|
||||||
/*超出长度*/
|
/*超出长度*/
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -139,7 +141,7 @@ const hasActions = computed(() => !!slots['header-actions'])
|
|||||||
.stats-text {
|
.stats-text {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: var(--van-text-color-2, #646566);
|
color: var(--van-text-color-2);
|
||||||
grid-column: 2;
|
grid-column: 2;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@@ -159,8 +161,8 @@ const hasActions = computed(() => !!slots['header-actions'])
|
|||||||
|
|
||||||
.popup-footer-fixed {
|
.popup-footer-fixed {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
border-top: 1px solid var(--van-border-color, #ebedf0);
|
border-top: 1px solid var(--van-border-color);
|
||||||
background-color: var(--van-background-2, #f7f8fa);
|
background-color: var(--van-background-2);
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="reason-group-list-v2">
|
<div class="reason-group-list-v2">
|
||||||
<van-empty v-if="groups.length === 0 && !loading" description="暂无数据" />
|
<van-empty
|
||||||
|
v-if="groups.length === 0 && !loading"
|
||||||
|
description="暂无数据"
|
||||||
|
/>
|
||||||
|
|
||||||
<van-cell-group v-else inset>
|
<van-cell-group
|
||||||
|
v-else
|
||||||
|
inset
|
||||||
|
>
|
||||||
<van-cell
|
<van-cell
|
||||||
v-for="group in groups"
|
v-for="group in groups"
|
||||||
:key="group.reason"
|
:key="group.reason"
|
||||||
@@ -27,7 +33,7 @@
|
|||||||
<van-tag
|
<van-tag
|
||||||
:type="getTypeColor(group.sampleType)"
|
:type="getTypeColor(group.sampleType)"
|
||||||
size="medium"
|
size="medium"
|
||||||
style="margin-right: 8px;"
|
style="margin-right: 8px"
|
||||||
>
|
>
|
||||||
{{ getTypeName(group.sampleType) }}
|
{{ getTypeName(group.sampleType) }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
@@ -35,12 +41,15 @@
|
|||||||
v-if="group.sampleClassify"
|
v-if="group.sampleClassify"
|
||||||
type="primary"
|
type="primary"
|
||||||
size="medium"
|
size="medium"
|
||||||
style="margin-right: 8px;"
|
style="margin-right: 8px"
|
||||||
>
|
>
|
||||||
{{ group.sampleClassify }}
|
{{ group.sampleClassify }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
<span class="count-text">{{ group.count }} 条</span>
|
<span class="count-text">{{ group.count }} 条</span>
|
||||||
<span v-if="group.totalAmount" class="amount-text">
|
<span
|
||||||
|
v-if="group.totalAmount"
|
||||||
|
class="amount-text"
|
||||||
|
>
|
||||||
¥{{ Math.abs(group.totalAmount).toFixed(2) }}
|
¥{{ Math.abs(group.totalAmount).toFixed(2) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -92,7 +101,10 @@
|
|||||||
title="批量设置分类"
|
title="批量设置分类"
|
||||||
height="60%"
|
height="60%"
|
||||||
>
|
>
|
||||||
<van-form ref="batchFormRef" class="setting-form">
|
<van-form
|
||||||
|
ref="batchFormRef"
|
||||||
|
class="setting-form"
|
||||||
|
>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<!-- 显示选中的摘要 -->
|
<!-- 显示选中的摘要 -->
|
||||||
<van-field
|
<van-field
|
||||||
@@ -111,20 +123,38 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 交易类型 -->
|
<!-- 交易类型 -->
|
||||||
<van-field name="type" label="交易类型">
|
<van-field
|
||||||
|
name="type"
|
||||||
|
label="交易类型"
|
||||||
|
>
|
||||||
<template #input>
|
<template #input>
|
||||||
<van-radio-group v-model="batchForm.type" direction="horizontal">
|
<van-radio-group
|
||||||
<van-radio :name="0">支出</van-radio>
|
v-model="batchForm.type"
|
||||||
<van-radio :name="1">收入</van-radio>
|
direction="horizontal"
|
||||||
<van-radio :name="2">不计</van-radio>
|
>
|
||||||
|
<van-radio :name="0">
|
||||||
|
支出
|
||||||
|
</van-radio>
|
||||||
|
<van-radio :name="1">
|
||||||
|
收入
|
||||||
|
</van-radio>
|
||||||
|
<van-radio :name="2">
|
||||||
|
不计
|
||||||
|
</van-radio>
|
||||||
</van-radio-group>
|
</van-radio-group>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
|
|
||||||
<!-- 分类选择 -->
|
<!-- 分类选择 -->
|
||||||
<van-field name="classify" label="分类">
|
<van-field
|
||||||
|
name="classify"
|
||||||
|
label="分类"
|
||||||
|
>
|
||||||
<template #input>
|
<template #input>
|
||||||
<span v-if="!batchForm.classify" style="opacity: 0.4;">请选择分类</span>
|
<span
|
||||||
|
v-if="!batchForm.classify"
|
||||||
|
style="opacity: 0.4"
|
||||||
|
>请选择分类</span>
|
||||||
<span v-else>{{ batchForm.classify }}</span>
|
<span v-else>{{ batchForm.classify }}</span>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
@@ -152,13 +182,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
||||||
import {
|
import { showToast, showSuccessToast, showLoadingToast, closeToast, showConfirmDialog } from 'vant'
|
||||||
showToast,
|
|
||||||
showSuccessToast,
|
|
||||||
showLoadingToast,
|
|
||||||
closeToast,
|
|
||||||
showConfirmDialog
|
|
||||||
} from 'vant'
|
|
||||||
import { getReasonGroups, batchUpdateByReason, getTransactionList } from '@/api/transactionRecord'
|
import { getReasonGroups, batchUpdateByReason, getTransactionList } from '@/api/transactionRecord'
|
||||||
import ClassifySelector from './ClassifySelector.vue'
|
import ClassifySelector from './ClassifySelector.vue'
|
||||||
import TransactionList from './TransactionList.vue'
|
import TransactionList from './TransactionList.vue'
|
||||||
@@ -212,9 +236,12 @@ const batchForm = ref({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 监听交易类型变化,重新加载分类
|
// 监听交易类型变化,重新加载分类
|
||||||
watch(() => batchForm.value.type, (newVal) => {
|
watch(
|
||||||
|
() => batchForm.value.type,
|
||||||
|
(newVal) => {
|
||||||
batchForm.value.classify = ''
|
batchForm.value.classify = ''
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// 获取类型名称
|
// 获取类型名称
|
||||||
const getTypeName = (type) => {
|
const getTypeName = (type) => {
|
||||||
@@ -256,7 +283,9 @@ const handleGroupClick = async (group) => {
|
|||||||
|
|
||||||
// 加载分组的交易记录
|
// 加载分组的交易记录
|
||||||
const loadGroupTransactions = async () => {
|
const loadGroupTransactions = async () => {
|
||||||
if (transactionFinished.value || !selectedGroup.value) return
|
if (transactionFinished.value || !selectedGroup.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
transactionLoading.value = true
|
transactionLoading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -354,9 +383,7 @@ const handleConfirmBatchUpdate = async () => {
|
|||||||
emit('data-changed')
|
emit('data-changed')
|
||||||
try {
|
try {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent(
|
new CustomEvent('transactions-changed', {
|
||||||
'transactions-changed',
|
|
||||||
{
|
|
||||||
detail: {
|
detail: {
|
||||||
reason: batchGroup.value.reason
|
reason: batchGroup.value.reason
|
||||||
}
|
}
|
||||||
@@ -398,7 +425,7 @@ const handleTransactionClick = (transaction) => {
|
|||||||
|
|
||||||
// 处理分组中的删除事件
|
// 处理分组中的删除事件
|
||||||
const handleGroupTransactionDelete = async (transactionId) => {
|
const handleGroupTransactionDelete = async (transactionId) => {
|
||||||
groupTransactions.value = groupTransactions.value.filter(t => t.id !== transactionId)
|
groupTransactions.value = groupTransactions.value.filter((t) => t.id !== transactionId)
|
||||||
groupTransactionsTotal.value = Math.max(0, (groupTransactionsTotal.value || 0) - 1)
|
groupTransactionsTotal.value = Math.max(0, (groupTransactionsTotal.value || 0) - 1)
|
||||||
|
|
||||||
if (groupTransactions.value.length === 0 && !transactionFinished.value) {
|
if (groupTransactions.value.length === 0 && !transactionFinished.value) {
|
||||||
@@ -409,7 +436,7 @@ const handleGroupTransactionDelete = async (transactionId) => {
|
|||||||
if (groupTransactions.value.length === 0) {
|
if (groupTransactions.value.length === 0) {
|
||||||
// 如果删除后当前分组没有交易了,关闭弹窗
|
// 如果删除后当前分组没有交易了,关闭弹窗
|
||||||
showTransactionList.value = false
|
showTransactionList.value = false
|
||||||
groups.value = groups.value.filter(g => g.reason !== selectedGroup.value.reason)
|
groups.value = groups.value.filter((g) => g.reason !== selectedGroup.value.reason)
|
||||||
selectedGroup.value = null
|
selectedGroup.value = null
|
||||||
total.value--
|
total.value--
|
||||||
}
|
}
|
||||||
@@ -433,10 +460,12 @@ const onGlobalTransactionDeleted = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当有交易新增/修改/批量更新时的刷新监听
|
// 当有交易新增/修改/批量更新时的刷新监听
|
||||||
@@ -451,10 +480,12 @@ const onGlobalTransactionsChanged = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理账单保存后的回调
|
// 处理账单保存后的回调
|
||||||
@@ -471,7 +502,9 @@ const handleTransactionSaved = async () => {
|
|||||||
* 加载数据(支持分页)
|
* 加载数据(支持分页)
|
||||||
*/
|
*/
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
if (finished.value) return
|
if (finished.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -522,7 +555,7 @@ const refresh = async () => {
|
|||||||
*/
|
*/
|
||||||
const getList = (onlySelected = false) => {
|
const getList = (onlySelected = false) => {
|
||||||
if (onlySelected && props.selectable) {
|
if (onlySelected && props.selectable) {
|
||||||
return groups.value.filter(g => selectedReasons.value.has(g.reason))
|
return groups.value.filter((g) => selectedReasons.value.has(g.reason))
|
||||||
}
|
}
|
||||||
return [...groups.value]
|
return [...groups.value]
|
||||||
}
|
}
|
||||||
@@ -564,7 +597,7 @@ const clearSelection = () => {
|
|||||||
* 全选
|
* 全选
|
||||||
*/
|
*/
|
||||||
const selectAll = () => {
|
const selectAll = () => {
|
||||||
selectedReasons.value = new Set(groups.value.map(g => g.reason))
|
selectedReasons.value = new Set(groups.value.map((g) => g.reason))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暴露方法给父组件
|
// 暴露方法给父组件
|
||||||
@@ -627,13 +660,13 @@ defineExpose({
|
|||||||
|
|
||||||
.count-text {
|
.count-text {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.amount-text {
|
.amount-text {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: #ff976a;
|
color: var(--van-orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.van-cell-group--inset) {
|
:deep(.van-cell-group--inset) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
>
|
>
|
||||||
<template v-if="!loading && !saving">
|
<template v-if="!loading && !saving">
|
||||||
<van-icon :name="buttonIcon" />
|
<van-icon :name="buttonIcon" />
|
||||||
<span style="margin-left: 4px;">{{ buttonText }}</span>
|
<span style="margin-left: 4px">{{ buttonText }}</span>
|
||||||
</template>
|
</template>
|
||||||
</van-button>
|
</van-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -52,28 +52,42 @@ const hasClassifiedResults = computed(() => {
|
|||||||
|
|
||||||
// 按钮类型
|
// 按钮类型
|
||||||
const buttonType = computed(() => {
|
const buttonType = computed(() => {
|
||||||
if (saving.value) return 'warning'
|
if (saving.value) {
|
||||||
if (loading.value) return 'primary'
|
return 'warning'
|
||||||
if (hasClassifiedResults.value) return 'success'
|
}
|
||||||
|
if (loading.value) {
|
||||||
|
return 'primary'
|
||||||
|
}
|
||||||
|
if (hasClassifiedResults.value) {
|
||||||
|
return 'success'
|
||||||
|
}
|
||||||
return 'primary'
|
return 'primary'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 按钮图标
|
// 按钮图标
|
||||||
const buttonIcon = computed(() => {
|
const buttonIcon = computed(() => {
|
||||||
if (hasClassifiedResults.value) return 'success'
|
if (hasClassifiedResults.value) {
|
||||||
|
return 'success'
|
||||||
|
}
|
||||||
return 'fire'
|
return 'fire'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 按钮文字(非加载状态)
|
// 按钮文字(非加载状态)
|
||||||
const buttonText = computed(() => {
|
const buttonText = computed(() => {
|
||||||
if (hasClassifiedResults.value) return '保存分类'
|
if (hasClassifiedResults.value) {
|
||||||
|
return '保存分类'
|
||||||
|
}
|
||||||
return '智能分类'
|
return '智能分类'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 加载中文字
|
// 加载中文字
|
||||||
const loadingText = computed(() => {
|
const loadingText = computed(() => {
|
||||||
if (saving.value) return '保存中...'
|
if (saving.value) {
|
||||||
if (loading.value) return '分类中...'
|
return '保存中...'
|
||||||
|
}
|
||||||
|
if (loading.value) {
|
||||||
|
return '分类中...'
|
||||||
|
}
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -92,7 +106,9 @@ const handleClick = () => {
|
|||||||
* 保存分类结果
|
* 保存分类结果
|
||||||
*/
|
*/
|
||||||
const handleSaveClassify = async () => {
|
const handleSaveClassify = async () => {
|
||||||
if (saving.value || loading.value) return
|
if (saving.value || loading.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
saving.value = true
|
saving.value = true
|
||||||
@@ -104,7 +120,7 @@ const handleSaveClassify = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 准备批量更新数据
|
// 准备批量更新数据
|
||||||
const items = classifiedResults.value.map(item => ({
|
const items = classifiedResults.value.map((item) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
classify: item.classify,
|
classify: item.classify,
|
||||||
type: item.type
|
type: item.type
|
||||||
@@ -200,7 +216,7 @@ const handleSmartClassify = async () => {
|
|||||||
// 分批处理
|
// 分批处理
|
||||||
for (let i = 0; i < allTransactions.length; i += batchSize) {
|
for (let i = 0; i < allTransactions.length; i += batchSize) {
|
||||||
const batch = allTransactions.slice(i, i + batchSize)
|
const batch = allTransactions.slice(i, i + batchSize)
|
||||||
const transactionIds = batch.map(t => t.id)
|
const transactionIds = batch.map((t) => t.id)
|
||||||
const currentBatch = Math.floor(i / batchSize) + 1
|
const currentBatch = Math.floor(i / batchSize) + 1
|
||||||
const totalBatches = Math.ceil(allTransactions.length / batchSize)
|
const totalBatches = Math.ceil(allTransactions.length / batchSize)
|
||||||
|
|
||||||
@@ -229,7 +245,9 @@ const handleSmartClassify = async () => {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read()
|
const { done, value } = await reader.read()
|
||||||
|
|
||||||
if (done) break
|
if (done) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
buffer += decoder.decode(value, { stream: true })
|
buffer += decoder.decode(value, { stream: true })
|
||||||
|
|
||||||
@@ -238,7 +256,9 @@ const handleSmartClassify = async () => {
|
|||||||
buffer = events.pop() || '' // 保留最后一个不完整的部分
|
buffer = events.pop() || '' // 保留最后一个不完整的部分
|
||||||
|
|
||||||
for (const eventBlock of events) {
|
for (const eventBlock of events) {
|
||||||
if (!eventBlock.trim()) continue
|
if (!eventBlock.trim()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const lines = eventBlock.split('\n')
|
const lines = eventBlock.split('\n')
|
||||||
@@ -276,7 +296,7 @@ const handleSmartClassify = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 实时更新交易记录的分类信息
|
// 实时更新交易记录的分类信息
|
||||||
const index = props.transactions.findIndex(t => t.id === data.id)
|
const index = props.transactions.findIndex((t) => t.id === data.id)
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
const transaction = props.transactions[index]
|
const transaction = props.transactions[index]
|
||||||
transaction.upsetedClassify = data.Classify
|
transaction.upsetedClassify = data.Classify
|
||||||
@@ -344,7 +364,7 @@ const handleSmartClassify = async () => {
|
|||||||
|
|
||||||
const removeClassifiedTransaction = (transactionId) => {
|
const removeClassifiedTransaction = (transactionId) => {
|
||||||
// 从已分类结果中移除指定ID的项
|
// 从已分类结果中移除指定ID的项
|
||||||
classifiedResults.value = classifiedResults.value.filter(item => item.id !== transactionId)
|
classifiedResults.value = classifiedResults.value.filter((item) => item.id !== transactionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,8 +385,7 @@ const reset = () => {
|
|||||||
defineExpose({
|
defineExpose({
|
||||||
reset,
|
reset,
|
||||||
removeClassifiedTransaction
|
removeClassifiedTransaction
|
||||||
});
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<PopupContainer
|
<PopupContainer v-model="visible" title="交易详情" height="75%" :closeable="false">
|
||||||
v-model="visible"
|
|
||||||
title="交易详情"
|
|
||||||
height="75%"
|
|
||||||
:closeable="false"
|
|
||||||
>
|
|
||||||
<template #header-actions>
|
<template #header-actions>
|
||||||
<van-button size="small" type="primary" plain @click="handleOffsetClick"> 抵账 </van-button>
|
<van-button size="small" type="primary" plain @click="handleOffsetClick"> 抵账 </van-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<van-form style="margin-top: 12px;">
|
<van-form style="margin-top: 12px">
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="记录时间" :value="formatDate(transaction.createTime)" />
|
<van-cell title="记录时间" :value="formatDate(transaction.createTime)" />
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
@@ -55,7 +50,11 @@
|
|||||||
|
|
||||||
<van-field name="type" label="交易类型">
|
<van-field name="type" label="交易类型">
|
||||||
<template #input>
|
<template #input>
|
||||||
<van-radio-group v-model="editForm.type" direction="horizontal" @change="handleTypeChange">
|
<van-radio-group
|
||||||
|
v-model="editForm.type"
|
||||||
|
direction="horizontal"
|
||||||
|
@change="handleTypeChange"
|
||||||
|
>
|
||||||
<van-radio :name="0"> 支出 </van-radio>
|
<van-radio :name="0"> 支出 </van-radio>
|
||||||
<van-radio :name="1"> 收入 </van-radio>
|
<van-radio :name="1"> 收入 </van-radio>
|
||||||
<van-radio :name="2"> 不计 </van-radio>
|
<van-radio :name="2"> 不计 </van-radio>
|
||||||
@@ -65,22 +64,34 @@
|
|||||||
|
|
||||||
<van-field name="classify" label="交易分类">
|
<van-field name="classify" label="交易分类">
|
||||||
<template #input>
|
<template #input>
|
||||||
<div style="flex: 1;">
|
<div style="flex: 1">
|
||||||
<div
|
<div
|
||||||
v-if="transaction && transaction.unconfirmedClassify && transaction.unconfirmedClassify !== editForm.classify"
|
v-if="
|
||||||
|
transaction &&
|
||||||
|
transaction.unconfirmedClassify &&
|
||||||
|
transaction.unconfirmedClassify !== editForm.classify
|
||||||
|
"
|
||||||
class="suggestion-tip"
|
class="suggestion-tip"
|
||||||
@click="applySuggestion"
|
@click="applySuggestion"
|
||||||
>
|
>
|
||||||
<van-icon name="bulb-o" class="suggestion-icon" />
|
<van-icon name="bulb-o" class="suggestion-icon" />
|
||||||
<span class="suggestion-text">
|
<span class="suggestion-text">
|
||||||
建议: {{ transaction.unconfirmedClassify }}
|
建议: {{ transaction.unconfirmedClassify }}
|
||||||
<span v-if="transaction.unconfirmedType !== null && transaction.unconfirmedType !== undefined && transaction.unconfirmedType !== editForm.type">
|
<span
|
||||||
|
v-if="
|
||||||
|
transaction.unconfirmedType !== null &&
|
||||||
|
transaction.unconfirmedType !== undefined &&
|
||||||
|
transaction.unconfirmedType !== editForm.type
|
||||||
|
"
|
||||||
|
>
|
||||||
({{ getTypeName(transaction.unconfirmedType) }})
|
({{ getTypeName(transaction.unconfirmedType) }})
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<div class="suggestion-apply">应用</div>
|
<div class="suggestion-apply">应用</div>
|
||||||
</div>
|
</div>
|
||||||
<span v-else-if="!editForm.classify" style="color: #c8c9cc;">请选择交易分类</span>
|
<span v-else-if="!editForm.classify" style="color: var(--van-gray-5)"
|
||||||
|
>请选择交易分类</span
|
||||||
|
>
|
||||||
<span v-else>{{ editForm.classify }}</span>
|
<span v-else>{{ editForm.classify }}</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -95,24 +106,14 @@
|
|||||||
</van-form>
|
</van-form>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<van-button
|
<van-button round block type="primary" :loading="submitting" @click="onSubmit">
|
||||||
round
|
|
||||||
block
|
|
||||||
type="primary"
|
|
||||||
:loading="submitting"
|
|
||||||
@click="onSubmit"
|
|
||||||
>
|
|
||||||
保存修改
|
保存修改
|
||||||
</van-button>
|
</van-button>
|
||||||
</template>
|
</template>
|
||||||
</PopupContainer>
|
</PopupContainer>
|
||||||
|
|
||||||
<!-- 抵账候选列表弹窗 -->
|
<!-- 抵账候选列表弹窗 -->
|
||||||
<PopupContainer
|
<PopupContainer v-model="showOffsetPopup" title="选择抵账交易" height="75%">
|
||||||
v-model="showOffsetPopup"
|
|
||||||
title="选择抵账交易"
|
|
||||||
height="75%"
|
|
||||||
>
|
|
||||||
<van-list>
|
<van-list>
|
||||||
<van-cell
|
<van-cell
|
||||||
v-for="item in offsetCandidates"
|
v-for="item in offsetCandidates"
|
||||||
@@ -154,7 +155,11 @@ import { showToast, showConfirmDialog } from 'vant'
|
|||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import PopupContainer from '@/components/PopupContainer.vue'
|
import PopupContainer from '@/components/PopupContainer.vue'
|
||||||
import ClassifySelector from '@/components/ClassifySelector.vue'
|
import ClassifySelector from '@/components/ClassifySelector.vue'
|
||||||
import { updateTransaction, getCandidatesForOffset, offsetTransactions } from '@/api/transactionRecord'
|
import {
|
||||||
|
updateTransaction,
|
||||||
|
getCandidatesForOffset,
|
||||||
|
offsetTransactions
|
||||||
|
} from '@/api/transactionRecord'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
show: {
|
show: {
|
||||||
@@ -196,11 +201,16 @@ const occurredAtLabel = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 监听props变化
|
// 监听props变化
|
||||||
watch(() => props.show, (newVal) => {
|
watch(
|
||||||
|
() => props.show,
|
||||||
|
(newVal) => {
|
||||||
visible.value = newVal
|
visible.value = newVal
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
watch(() => props.transaction, (newVal) => {
|
watch(
|
||||||
|
() => props.transaction,
|
||||||
|
(newVal) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
isSyncing.value = true
|
isSyncing.value = true
|
||||||
// 填充编辑表单
|
// 填充编辑表单
|
||||||
@@ -224,7 +234,8 @@ watch(() => props.transaction, (newVal) => {
|
|||||||
isSyncing.value = false
|
isSyncing.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
watch(visible, (newVal) => {
|
watch(visible, (newVal) => {
|
||||||
emit('update:show', newVal)
|
emit('update:show', newVal)
|
||||||
@@ -258,7 +269,10 @@ const onConfirmTime = ({ selectedValues }) => {
|
|||||||
const applySuggestion = () => {
|
const applySuggestion = () => {
|
||||||
if (props.transaction.unconfirmedClassify) {
|
if (props.transaction.unconfirmedClassify) {
|
||||||
editForm.classify = props.transaction.unconfirmedClassify
|
editForm.classify = props.transaction.unconfirmedClassify
|
||||||
if (props.transaction.unconfirmedType !== null && props.transaction.unconfirmedType !== undefined) {
|
if (
|
||||||
|
props.transaction.unconfirmedType !== null &&
|
||||||
|
props.transaction.unconfirmedType !== undefined
|
||||||
|
) {
|
||||||
editForm.type = props.transaction.unconfirmedType
|
editForm.type = props.transaction.unconfirmedType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +328,9 @@ const handleClassifyChange = () => {
|
|||||||
|
|
||||||
// 清空分类
|
// 清空分类
|
||||||
const formatDate = (dateString) => {
|
const formatDate = (dateString) => {
|
||||||
if (!dateString) return ''
|
if (!dateString) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
return date.toLocaleString('zh-CN', {
|
return date.toLocaleString('zh-CN', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@@ -347,7 +363,7 @@ const handleOffsetClick = async () => {
|
|||||||
const handleCandidateSelect = (candidate) => {
|
const handleCandidateSelect = (candidate) => {
|
||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
title: '确认抵账',
|
title: '确认抵账',
|
||||||
message: `确认将当前交易与 "${candidate.reason}" (${candidate.amount}) 互相抵消吗?\n抵消后两笔交易将被删除。`,
|
message: `确认将当前交易与 "${candidate.reason}" (${candidate.amount}) 互相抵消吗?\n抵消后两笔交易将被删除。`
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -367,7 +383,7 @@ const handleCandidateSelect = (candidate) => {
|
|||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// on cancel
|
// on cancel
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -377,17 +393,18 @@ const handleCandidateSelect = (candidate) => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
background: #ecf9ff;
|
background: var(--van-active-color);
|
||||||
color: #1989fa;
|
color: var(--van-primary-color);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: opacity 0.2s;
|
transition: opacity 0.2s;
|
||||||
border: 1px solid rgba(25, 137, 250, 0.1);
|
border: 1px solid var(--van-primary-color);
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
|
opacity: 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.suggestion-tip:active {
|
.suggestion-tip:active {
|
||||||
opacity: 0.7;
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.suggestion-icon {
|
.suggestion-icon {
|
||||||
@@ -402,23 +419,12 @@ const handleCandidateSelect = (candidate) => {
|
|||||||
.suggestion-apply {
|
.suggestion-apply {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
padding: 0 6px;
|
padding: 0 6px;
|
||||||
background: #1989fa;
|
background: var(--van-primary-color);
|
||||||
color: #fff;
|
color: var(--van-white);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.suggestion-tip {
|
|
||||||
background: rgba(25, 137, 250, 0.15);
|
|
||||||
border-color: rgba(25, 137, 250, 0.2);
|
|
||||||
color: #58a6ff;
|
|
||||||
}
|
|
||||||
.suggestion-apply {
|
|
||||||
background: #58a6ff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="transaction-list-container transaction-list">
|
<div class="transaction-list-container transaction-list">
|
||||||
<van-list
|
<van-list :loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
|
||||||
:loading="loading"
|
|
||||||
:finished="finished"
|
|
||||||
finished-text="没有更多了"
|
|
||||||
@load="onLoad"
|
|
||||||
>
|
|
||||||
<van-cell-group v-if="transactions && transactions.length" inset style="margin-top: 10px">
|
<van-cell-group v-if="transactions && transactions.length" inset style="margin-top: 10px">
|
||||||
<van-swipe-cell
|
<van-swipe-cell
|
||||||
v-for="transaction in transactions"
|
v-for="transaction in transactions"
|
||||||
@@ -19,10 +14,7 @@
|
|||||||
class="checkbox-col"
|
class="checkbox-col"
|
||||||
@update:model-value="toggleSelection(transaction)"
|
@update:model-value="toggleSelection(transaction)"
|
||||||
/>
|
/>
|
||||||
<div
|
<div class="transaction-card" @click="handleClick(transaction)">
|
||||||
class="transaction-card"
|
|
||||||
@click="handleClick(transaction)"
|
|
||||||
>
|
|
||||||
<div class="card-left">
|
<div class="card-left">
|
||||||
<div class="transaction-title">
|
<div class="transaction-title">
|
||||||
<span class="reason">{{ transaction.reason || '(无摘要)' }}</span>
|
<span class="reason">{{ transaction.reason || '(无摘要)' }}</span>
|
||||||
@@ -30,34 +22,32 @@
|
|||||||
<div class="transaction-info">
|
<div class="transaction-info">
|
||||||
<div>交易时间: {{ formatDate(transaction.occurredAt) }}</div>
|
<div>交易时间: {{ formatDate(transaction.occurredAt) }}</div>
|
||||||
<div>
|
<div>
|
||||||
<span v-if="transaction.classify">
|
<span v-if="transaction.classify"> 分类: {{ transaction.classify }} </span>
|
||||||
分类: {{ transaction.classify }}
|
<span
|
||||||
</span>
|
v-if="
|
||||||
<span v-if="transaction.upsetedClassify && transaction.upsetedClassify !== transaction.classify" style="color: #ff976a">
|
transaction.upsetedClassify &&
|
||||||
|
transaction.upsetedClassify !== transaction.classify
|
||||||
|
"
|
||||||
|
style="color: var(--van-warning-color)"
|
||||||
|
>
|
||||||
→ {{ transaction.upsetedClassify }}
|
→ {{ transaction.upsetedClassify }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</div>
|
|
||||||
<div v-if="transaction.importFrom">
|
|
||||||
来源: {{ transaction.importFrom }}
|
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="transaction.importFrom">来源: {{ transaction.importFrom }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-middle">
|
<div class="card-middle">
|
||||||
<van-tag
|
<van-tag :type="getTypeTagType(transaction.type)" size="medium">
|
||||||
:type="getTypeTagType(transaction.type)"
|
|
||||||
size="medium"
|
|
||||||
>
|
|
||||||
{{ getTypeName(transaction.type) }}
|
{{ getTypeName(transaction.type) }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
<template
|
<template
|
||||||
v-if="Number.isFinite(transaction.upsetedType) && transaction.upsetedType !== transaction.type"
|
v-if="
|
||||||
|
Number.isFinite(transaction.upsetedType) &&
|
||||||
|
transaction.upsetedType !== transaction.type
|
||||||
|
"
|
||||||
>
|
>
|
||||||
→
|
→
|
||||||
<van-tag
|
<van-tag :type="getTypeTagType(transaction.upsetedType)" size="medium">
|
||||||
:type="getTypeTagType(transaction.upsetedType)"
|
|
||||||
size="medium"
|
|
||||||
>
|
|
||||||
{{ getTypeName(transaction.upsetedType) }}
|
{{ getTypeName(transaction.upsetedType) }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
</template>
|
</template>
|
||||||
@@ -70,11 +60,14 @@
|
|||||||
<div v-if="transaction.balance && transaction.balance > 0" class="balance">
|
<div v-if="transaction.balance && transaction.balance > 0" class="balance">
|
||||||
余额: {{ formatMoney(transaction.balance) }}
|
余额: {{ formatMoney(transaction.balance) }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="transaction.refundAmount && transaction.refundAmount > 0" class="balance">
|
<div
|
||||||
|
v-if="transaction.refundAmount && transaction.refundAmount > 0"
|
||||||
|
class="balance"
|
||||||
|
>
|
||||||
退款: {{ formatMoney(transaction.refundAmount) }}
|
退款: {{ formatMoney(transaction.refundAmount) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<van-icon name="arrow" size="16" color="#c8c9cc" />
|
<van-icon name="arrow" size="16" color="var(--van-gray-5)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -212,16 +205,24 @@ const getTypeTagType = (type) => {
|
|||||||
|
|
||||||
// 获取金额样式类
|
// 获取金额样式类
|
||||||
const getAmountClass = (type) => {
|
const getAmountClass = (type) => {
|
||||||
if (type === 0) return 'expense'
|
if (type === 0) {
|
||||||
if (type === 1) return 'income'
|
return 'expense'
|
||||||
|
}
|
||||||
|
if (type === 1) {
|
||||||
|
return 'income'
|
||||||
|
}
|
||||||
return 'neutral'
|
return 'neutral'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化金额(带符号)
|
// 格式化金额(带符号)
|
||||||
const formatAmount = (amount, type) => {
|
const formatAmount = (amount, type) => {
|
||||||
const formatted = formatMoney(amount)
|
const formatted = formatMoney(amount)
|
||||||
if (type === 0) return `- ${formatted}`
|
if (type === 0) {
|
||||||
if (type === 1) return `+ ${formatted}`
|
return `- ${formatted}`
|
||||||
|
}
|
||||||
|
if (type === 1) {
|
||||||
|
return `+ ${formatted}`
|
||||||
|
}
|
||||||
return formatted
|
return formatted
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +233,9 @@ const formatMoney = (amount) => {
|
|||||||
|
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
const formatDate = (dateString) => {
|
const formatDate = (dateString) => {
|
||||||
if (!dateString) return ''
|
if (!dateString) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
return date.toLocaleString('zh-CN', {
|
return date.toLocaleString('zh-CN', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@@ -315,12 +318,12 @@ const formatDate = (dateString) => {
|
|||||||
|
|
||||||
.transaction-info {
|
.transaction-info {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.original-info {
|
.original-info {
|
||||||
color: #ff976a;
|
color: var(--van-orange);
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -343,16 +346,16 @@ const formatDate = (dateString) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.amount.expense {
|
.amount.expense {
|
||||||
color: #ee0a24;
|
color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.amount.income {
|
.amount.income {
|
||||||
color: #07c160;
|
color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.balance {
|
.balance {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { createPinia } from 'pinia'
|
|||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import vant from 'vant'
|
import vant from 'vant'
|
||||||
import { ConfigProvider } from 'vant';
|
import { ConfigProvider } from 'vant'
|
||||||
import 'vant/lib/index.css'
|
import 'vant/lib/index.css'
|
||||||
|
|
||||||
// 注册 Service Worker
|
// 注册 Service Worker
|
||||||
@@ -19,7 +19,7 @@ const app = createApp(App)
|
|||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(router)
|
app.use(router)
|
||||||
app.use(vant)
|
app.use(vant)
|
||||||
app.use(ConfigProvider);
|
app.use(ConfigProvider)
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|
||||||
|
|||||||
@@ -1,65 +1,68 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export const needRefresh = ref(false);
|
export const needRefresh = ref(false)
|
||||||
let swRegistration = null;
|
let swRegistration = null
|
||||||
|
|
||||||
export async function updateServiceWorker() {
|
export async function updateServiceWorker() {
|
||||||
if (swRegistration && swRegistration.waiting) {
|
if (swRegistration && swRegistration.waiting) {
|
||||||
await swRegistration.waiting.postMessage({ type: 'SKIP_WAITING' });
|
await swRegistration.waiting.postMessage({ type: 'SKIP_WAITING' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function register() {
|
export function register() {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const swUrl = `/service-worker.js`;
|
const swUrl = '/service-worker.js'
|
||||||
|
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register(swUrl)
|
.register(swUrl)
|
||||||
.then((registration) => {
|
.then((registration) => {
|
||||||
swRegistration = registration;
|
swRegistration = registration
|
||||||
console.log('[SW] Service Worker 注册成功:', registration.scope);
|
console.log('[SW] Service Worker 注册成功:', registration.scope)
|
||||||
|
|
||||||
// 如果已经有等待中的更新
|
// 如果已经有等待中的更新
|
||||||
if (registration.waiting) {
|
if (registration.waiting) {
|
||||||
console.log('[SW] 发现未处理的新版本');
|
console.log('[SW] 发现未处理的新版本')
|
||||||
needRefresh.value = true;
|
needRefresh.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查更新
|
// 检查更新
|
||||||
registration.addEventListener('updatefound', () => {
|
registration.addEventListener('updatefound', () => {
|
||||||
const newWorker = registration.installing;
|
const newWorker = registration.installing
|
||||||
console.log('[SW] 发现新版本');
|
console.log('[SW] 发现新版本')
|
||||||
|
|
||||||
newWorker.addEventListener('statechange', () => {
|
newWorker.addEventListener('statechange', () => {
|
||||||
if (newWorker.state === 'installed') {
|
if (newWorker.state === 'installed') {
|
||||||
if (navigator.serviceWorker.controller) {
|
if (navigator.serviceWorker.controller) {
|
||||||
// 新的 Service Worker 已安装,提示用户刷新
|
// 新的 Service Worker 已安装,提示用户刷新
|
||||||
console.log('[SW] 新版本可用,请刷新页面');
|
console.log('[SW] 新版本可用,请刷新页面')
|
||||||
needRefresh.value = true;
|
needRefresh.value = true
|
||||||
} else {
|
} else {
|
||||||
// 首次安装
|
// 首次安装
|
||||||
console.log('[SW] 内容已缓存,可离线使用');
|
console.log('[SW] 内容已缓存,可离线使用')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
// 定期检查更新
|
// 定期检查更新
|
||||||
setInterval(() => {
|
setInterval(
|
||||||
registration.update();
|
() => {
|
||||||
}, 60 * 60 * 1000); // 每小时检查一次
|
registration.update()
|
||||||
|
},
|
||||||
|
60 * 60 * 1000
|
||||||
|
) // 每小时检查一次
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('[SW] Service Worker 注册失败:', error);
|
console.error('[SW] Service Worker 注册失败:', error)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 监听 Service Worker 控制器变化
|
// 监听 Service Worker 控制器变化
|
||||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||||
console.log('[SW] 控制器已更改,页面将刷新');
|
console.log('[SW] 控制器已更改,页面将刷新')
|
||||||
window.location.reload();
|
window.location.reload()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,35 +70,37 @@ export function unregister() {
|
|||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.ready
|
navigator.serviceWorker.ready
|
||||||
.then((registration) => {
|
.then((registration) => {
|
||||||
registration.unregister();
|
registration.unregister()
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error.message);
|
console.error(error.message)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 请求通知权限
|
// 请求通知权限
|
||||||
export function requestNotificationPermission() {
|
export function requestNotificationPermission() {
|
||||||
if ('Notification' in window && 'serviceWorker' in navigator) {
|
if ('Notification' in window && 'serviceWorker' in navigator) {
|
||||||
Notification.requestPermission().then((permission) => {
|
Notification.requestPermission().then((permission) => {
|
||||||
if (permission === 'granted') {
|
if (permission === 'granted') {
|
||||||
console.log('[SW] 通知权限已授予');
|
console.log('[SW] 通知权限已授予')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 后台同步
|
// 后台同步
|
||||||
export function registerBackgroundSync(tag = 'sync-data') {
|
export function registerBackgroundSync(tag = 'sync-data') {
|
||||||
if ('serviceWorker' in navigator && 'SyncManager' in window) {
|
if ('serviceWorker' in navigator && 'SyncManager' in window) {
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
navigator.serviceWorker.ready
|
||||||
return registration.sync.register(tag);
|
.then((registration) => {
|
||||||
}).then(() => {
|
return registration.sync.register(tag)
|
||||||
console.log('[SW] 后台同步已注册:', tag);
|
})
|
||||||
}).catch((err) => {
|
.then(() => {
|
||||||
console.error('[SW] 后台同步注册失败:', err);
|
console.log('[SW] 后台同步已注册:', tag)
|
||||||
});
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('[SW] 后台同步注册失败:', err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,106 +8,106 @@ const router = createRouter({
|
|||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'login',
|
name: 'login',
|
||||||
component: () => import('../views/LoginView.vue'),
|
component: () => import('../views/LoginView.vue'),
|
||||||
meta: { requiresAuth: false },
|
meta: { requiresAuth: false }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/balance',
|
path: '/balance',
|
||||||
name: 'balance',
|
name: 'balance',
|
||||||
component: () => import('../views/BalanceView.vue'),
|
component: () => import('../views/BalanceView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/email',
|
path: '/email',
|
||||||
name: 'email',
|
name: 'email',
|
||||||
component: () => import('../views/EmailRecord.vue'),
|
component: () => import('../views/EmailRecord.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/setting',
|
path: '/setting',
|
||||||
name: 'setting',
|
name: 'setting',
|
||||||
component: () => import('../views/SettingView.vue'),
|
component: () => import('../views/SettingView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/calendar',
|
path: '/calendar',
|
||||||
name: 'calendar',
|
name: 'calendar',
|
||||||
component: () => import('../views/CalendarView.vue'),
|
component: () => import('../views/CalendarView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/smart-classification',
|
path: '/smart-classification',
|
||||||
name: 'smart-classification',
|
name: 'smart-classification',
|
||||||
component: () => import('../views/ClassificationSmart.vue'),
|
component: () => import('../views/ClassificationSmart.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/classification-edit',
|
path: '/classification-edit',
|
||||||
name: 'classification-edit',
|
name: 'classification-edit',
|
||||||
component: () => import('../views/ClassificationEdit.vue'),
|
component: () => import('../views/ClassificationEdit.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/classification-batch',
|
path: '/classification-batch',
|
||||||
name: 'classification-batch',
|
name: 'classification-batch',
|
||||||
component: () => import('../views/ClassificationBatch.vue'),
|
component: () => import('../views/ClassificationBatch.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/classification-nlp',
|
path: '/classification-nlp',
|
||||||
name: 'classification-nlp',
|
name: 'classification-nlp',
|
||||||
component: () => import('../views/ClassificationNLP.vue'),
|
component: () => import('../views/ClassificationNLP.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'statistics',
|
name: 'statistics',
|
||||||
component: () => import('../views/StatisticsView.vue'),
|
component: () => import('../views/StatisticsView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/bill-analysis',
|
path: '/bill-analysis',
|
||||||
name: 'bill-analysis',
|
name: 'bill-analysis',
|
||||||
component: () => import('../views/BillAnalysisView.vue'),
|
component: () => import('../views/BillAnalysisView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/message',
|
path: '/message',
|
||||||
name: 'message',
|
name: 'message',
|
||||||
redirect: { path: '/balance', query: { tab: 'message' } },
|
redirect: { path: '/balance', query: { tab: 'message' } },
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/periodic-record',
|
path: '/periodic-record',
|
||||||
name: 'periodic-record',
|
name: 'periodic-record',
|
||||||
component: () => import('../views/PeriodicRecord.vue'),
|
component: () => import('../views/PeriodicRecord.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/log',
|
path: '/log',
|
||||||
name: 'log',
|
name: 'log',
|
||||||
component: () => import('../views/LogView.vue'),
|
component: () => import('../views/LogView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/budget',
|
path: '/budget',
|
||||||
name: 'budget',
|
name: 'budget',
|
||||||
component: () => import('../views/BudgetView.vue'),
|
component: () => import('../views/BudgetView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/scheduled-tasks',
|
path: '/scheduled-tasks',
|
||||||
name: 'scheduled-tasks',
|
name: 'scheduled-tasks',
|
||||||
component: () => import('../views/ScheduledTasksView.vue'),
|
component: () => import('../views/ScheduledTasksView.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 待确认的分类项
|
// 待确认的分类项
|
||||||
path: '/unconfirmed-classification',
|
path: '/unconfirmed-classification',
|
||||||
name: 'unconfirmed-classification',
|
name: 'unconfirmed-classification',
|
||||||
component: () => import('../views/UnconfirmedClassification.vue'),
|
component: () => import('../views/UnconfirmedClassification.vue'),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true }
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// 路由守卫
|
// 路由守卫
|
||||||
@@ -127,4 +127,3 @@ router.beforeEach((to, from, next) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
const expiresAt = ref(localStorage.getItem('expiresAt') || '')
|
const expiresAt = ref(localStorage.getItem('expiresAt') || '')
|
||||||
|
|
||||||
const isAuthenticated = computed(() => {
|
const isAuthenticated = computed(() => {
|
||||||
if (!token.value || !expiresAt.value) return false
|
if (!token.value || !expiresAt.value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
// 检查token是否过期
|
// 检查token是否过期
|
||||||
return new Date(expiresAt.value) > new Date()
|
return new Date(expiresAt.value) > new Date()
|
||||||
})
|
})
|
||||||
@@ -44,6 +46,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
expiresAt,
|
expiresAt,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
login,
|
login,
|
||||||
logout,
|
logout
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,16 +4,10 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
overscroll-behavior: contain; /* 防止滚动链传播到 body */
|
overscroll-behavior: contain; /* 防止滚动链传播到 body */
|
||||||
background: #f7f8fa;
|
background: var(--van-background);
|
||||||
padding-bottom: env(safe-area-inset-bottom, 0px);
|
padding-bottom: env(safe-area-inset-bottom, 0px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.page-container {
|
|
||||||
background: #141414;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 页面内容区域 */
|
/* 页面内容区域 */
|
||||||
.page-content {
|
.page-content {
|
||||||
padding: 16px 0 0 0;
|
padding: 16px 0 0 0;
|
||||||
@@ -26,20 +20,12 @@
|
|||||||
|
|
||||||
/* 统一卡片样式 */
|
/* 统一卡片样式 */
|
||||||
.common-card {
|
.common-card {
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
margin: 0 12px 16px;
|
margin: 0 12px 16px;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
||||||
border: 1px solid #ebedf0;
|
border: 1px solid var(--van-border-color);
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.common-card {
|
|
||||||
background: #1f1f1f;
|
|
||||||
border-color: #2c2c2c;
|
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 卡片头部 */
|
/* 卡片头部 */
|
||||||
@@ -60,31 +46,16 @@
|
|||||||
/* 增加卡片组的对比度 */
|
/* 增加卡片组的对比度 */
|
||||||
:deep(.van-cell-group--inset) {
|
:deep(.van-cell-group--inset) {
|
||||||
margin: 10px 16px;
|
margin: 10px 16px;
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
||||||
border: 1px solid #ebedf0;
|
border: 1px solid var(--van-border-color);
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:deep(.van-cell-group--inset) {
|
|
||||||
background: #1f1f1f;
|
|
||||||
border-color: #2c2c2c;
|
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 单元格样式 */
|
/* 单元格样式 */
|
||||||
:deep(.van-cell) {
|
:deep(.van-cell) {
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
border-bottom: 1px solid #ebedf0;
|
border-bottom: 1px solid var(--van-border-color);
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:deep(.van-cell) {
|
|
||||||
background: #1f1f1f;
|
|
||||||
border-bottom: 1px solid #2c2c2c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.van-cell:last-child) {
|
:deep(.van-cell:last-child) {
|
||||||
@@ -96,31 +67,17 @@
|
|||||||
padding: 16px;
|
padding: 16px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
background: #f7f8fa;
|
background: var(--van-background);
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.detail-popup {
|
|
||||||
background: #141414;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 弹出层内的卡片组样式 */
|
/* 弹出层内的卡片组样式 */
|
||||||
.detail-popup :deep(.van-cell-group--inset) {
|
.detail-popup :deep(.van-cell-group--inset) {
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
||||||
border: 1px solid #ebedf0;
|
border: 1px solid var(--van-border-color);
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.detail-popup :deep(.van-cell-group--inset) {
|
|
||||||
background: #1f1f1f;
|
|
||||||
border-color: #2c2c2c;
|
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 详情头部样式 */
|
/* 详情头部样式 */
|
||||||
.detail-header {
|
.detail-header {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
@@ -136,7 +93,7 @@
|
|||||||
.detail-header p {
|
.detail-header p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,17 +173,11 @@
|
|||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
margin: 0 12px;
|
margin: 0 12px;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.sticky-header {
|
|
||||||
background: #1f1f1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sticky-header-text {
|
.sticky-header-text {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -240,11 +191,11 @@
|
|||||||
|
|
||||||
/* ===== 颜色工具类 ===== */
|
/* ===== 颜色工具类 ===== */
|
||||||
.text-expense {
|
.text-expense {
|
||||||
color: #ff6b6b;
|
color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-income {
|
.text-income {
|
||||||
color: #51cf66;
|
color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 底部操作栏 */
|
/* 底部操作栏 */
|
||||||
@@ -256,18 +207,11 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
background-color: var(--van-background-2, #fff);
|
background-color: var(--van-background-2);
|
||||||
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.bottom-button {
|
|
||||||
background-color: var(--van-background-2, #2c2c2c);
|
|
||||||
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ===== 统一弹窗样式 ===== */
|
/* ===== 统一弹窗样式 ===== */
|
||||||
/* 弹窗容器 - 使用 flex 布局,确保标题固定,内容可滚动 */
|
/* 弹窗容器 - 使用 flex 布局,确保标题固定,内容可滚动 */
|
||||||
.popup-container {
|
.popup-container {
|
||||||
@@ -304,15 +248,5 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
}
|
background: var(--van-background);
|
||||||
|
|
||||||
/* 深色模式适配 */
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.popup-header-fixed {
|
|
||||||
background: #1f1f1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
.popup-scroll-content {
|
|
||||||
background: #141414;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -71,9 +71,9 @@
|
|||||||
.rich-html-content thead,
|
.rich-html-content thead,
|
||||||
.rich-html-content tbody {
|
.rich-html-content tbody {
|
||||||
display: table;
|
display: table;
|
||||||
width: 130%;
|
width: 100%;
|
||||||
min-width: 400px; /* 确保窄屏下有足够宽度触发滚动 */
|
|
||||||
table-layout: fixed; /* 核心:强制列宽分配逻辑一致 */
|
table-layout: fixed; /* 核心:强制列宽分配逻辑一致 */
|
||||||
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rich-html-content tr {
|
.rich-html-content tr {
|
||||||
@@ -87,52 +87,48 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 1px solid var(--van-border-color-light);
|
border-bottom: 1px solid var(--van-border-color-light);
|
||||||
font-size: 12px;
|
font-size: 11px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 针对第一列“名称”分配更多空间,其余平分 */
|
.rich-html-content th {
|
||||||
|
background: var(--van-border-color);
|
||||||
|
color: var(--van-text-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 通用列宽规则:第一列占 30%,其他列自动平分剩余 70% */
|
||||||
.rich-html-content th:first-child,
|
.rich-html-content th:first-child,
|
||||||
.rich-html-content td:first-child {
|
.rich-html-content td:first-child {
|
||||||
width: 30%;
|
width: 30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rich-html-content th:not(:first-child),
|
|
||||||
.rich-html-content td:not(:first-child) {
|
|
||||||
width: 20%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rich-html-content th {
|
|
||||||
background: var(--van-gray-1);
|
|
||||||
color: var(--van-text-color);
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 业务特定样式:收入、支出、高亮 */
|
/* 业务特定样式:收入、支出、高亮 */
|
||||||
.rich-html-content .income-value {
|
.rich-html-content .income-value {
|
||||||
color: #07c160 !important;
|
color: var(--van-success-color) !important;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rich-html-content .expense-value {
|
.rich-html-content .expense-value {
|
||||||
color: #ee0a24 !important;
|
color: var(--van-danger-color) !important;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rich-html-content .highlight {
|
.rich-html-content .highlight {
|
||||||
background-color: #fffbe6;
|
background-color: var(--van-orange-light);
|
||||||
color: #ed6a0c;
|
color: var(--van-orange-dark);
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
border: 1px solid #ffe58f;
|
border: 1px solid var(--van-orange);
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 暗色模式适配 */
|
/* 暗色模式适配 */
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.rich-html-content .highlight {
|
.rich-html-content .highlight {
|
||||||
background-color: rgba(255, 243, 205, 0.2);
|
background-color: rgba(255, 243, 205, 0.2);
|
||||||
color: #ffc107;
|
color: #ffc107;
|
||||||
@@ -160,4 +156,4 @@
|
|||||||
.rich-html-content td {
|
.rich-html-content td {
|
||||||
border-bottom: 1px solid #2c2c2c;
|
border-bottom: 1px solid #2c2c2c;
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|||||||
4
Web/src/utils/theme.js
Normal file
4
Web/src/utils/theme.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const getCssVar = (name) => {
|
||||||
|
const val = getComputedStyle(document.documentElement).getPropertyValue(name).trim()
|
||||||
|
return val || '#999' // Default fallback
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</van-nav-bar>
|
</van-nav-bar>
|
||||||
<van-tabs v-model:active="tabActive" animated>
|
<van-tabs v-model:active="tabActive" type="card" style="margin: 12px 0 2px 0">
|
||||||
<van-tab title="账单" name="balance" />
|
<van-tab title="账单" name="balance" />
|
||||||
<van-tab title="邮件" name="email" />
|
<van-tab title="邮件" name="email" />
|
||||||
<van-tab title="消息" name="message" />
|
<van-tab title="消息" name="message" />
|
||||||
@@ -33,25 +33,28 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue';
|
import { ref, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router'
|
||||||
import TransactionsRecord from './TransactionsRecord.vue';
|
import TransactionsRecord from './TransactionsRecord.vue'
|
||||||
import EmailRecord from './EmailRecord.vue';
|
import EmailRecord from './EmailRecord.vue'
|
||||||
import MessageView from './MessageView.vue';
|
import MessageView from './MessageView.vue'
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute()
|
||||||
const tabActive = ref(route.query.tab || 'balance');
|
const tabActive = ref(route.query.tab || 'balance')
|
||||||
|
|
||||||
// 监听路由参数变化,用于从 tabbar 点击时切换 tab
|
// 监听路由参数变化,用于从 tabbar 点击时切换 tab
|
||||||
watch(() => route.query.tab, (newTab) => {
|
watch(
|
||||||
|
() => route.query.tab,
|
||||||
|
(newTab) => {
|
||||||
if (newTab) {
|
if (newTab) {
|
||||||
tabActive.value = newTab;
|
tabActive.value = newTab
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const transactionsRecordRef = ref(null);
|
const transactionsRecordRef = ref(null)
|
||||||
const emailRecordRef = ref(null);
|
const emailRecordRef = ref(null)
|
||||||
const messageViewRef = ref(null);
|
const messageViewRef = ref(null)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<van-icon
|
<van-icon
|
||||||
name="setting-o"
|
name="setting-o"
|
||||||
size="20"
|
size="20"
|
||||||
style="cursor: pointer; padding-right: 12px;"
|
style="cursor: pointer; padding-right: 12px"
|
||||||
@click="onClickPrompt"
|
@click="onClickPrompt"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@@ -33,7 +33,9 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="quick-questions">
|
<div class="quick-questions">
|
||||||
<div class="quick-title">快捷问题</div>
|
<div class="quick-title">
|
||||||
|
快捷问题
|
||||||
|
</div>
|
||||||
<van-tag
|
<van-tag
|
||||||
v-for="(q, index) in quickQuestions"
|
v-for="(q, index) in quickQuestions"
|
||||||
:key="index"
|
:key="index"
|
||||||
@@ -61,7 +63,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 结果区域 -->
|
<!-- 结果区域 -->
|
||||||
<div v-if="showResult" class="result-section">
|
<div
|
||||||
|
v-if="showResult"
|
||||||
|
class="result-section"
|
||||||
|
>
|
||||||
<div class="result-header">
|
<div class="result-header">
|
||||||
<h3>分析结果</h3>
|
<h3>分析结果</h3>
|
||||||
<van-icon
|
<van-icon
|
||||||
@@ -72,12 +77,18 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ref="resultContainer" class="result-content rich-html-content">
|
<div
|
||||||
<div v-html="resultHtml"></div>
|
ref="resultContainer"
|
||||||
<van-loading v-if="analyzing" class="result-loading">
|
class="result-content rich-html-content"
|
||||||
|
>
|
||||||
|
<div v-html="resultHtml" />
|
||||||
|
<van-loading
|
||||||
|
v-if="analyzing"
|
||||||
|
class="result-loading"
|
||||||
|
>
|
||||||
AI正在分析中...
|
AI正在分析中...
|
||||||
</van-loading>
|
</van-loading>
|
||||||
<div ref="scrollAnchor"></div>
|
<div ref="scrollAnchor" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -204,10 +215,13 @@ const startAnalysis = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
const baseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
||||||
|
const token = localStorage.getItem('token')
|
||||||
|
|
||||||
const response = await fetch(`${baseUrl}/TransactionRecord/AnalyzeBill`, {
|
const response = await fetch(`${baseUrl}/TransactionRecord/AnalyzeBill`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
userInput: userInput.value
|
userInput: userInput.value
|
||||||
@@ -224,7 +238,9 @@ const startAnalysis = async () => {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read()
|
const { done, value } = await reader.read()
|
||||||
|
|
||||||
if (done) break
|
if (done) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
const chunk = decoder.decode(value, { stream: true })
|
const chunk = decoder.decode(value, { stream: true })
|
||||||
const lines = chunk.split('\n')
|
const lines = chunk.split('\n')
|
||||||
@@ -251,7 +267,6 @@ const startAnalysis = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('分析失败:', error)
|
console.error('分析失败:', error)
|
||||||
showToast('分析失败,请重试')
|
showToast('分析失败,请重试')
|
||||||
@@ -271,21 +286,14 @@ const startAnalysis = async () => {
|
|||||||
|
|
||||||
/* 输入区域 */
|
/* 输入区域 */
|
||||||
.input-section {
|
.input-section {
|
||||||
background: #ffffff;
|
background: var(--van-background-2);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
||||||
border: 1px solid #ebedf0;
|
border: 1px solid var(--van-border-color);
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.input-section {
|
|
||||||
background: #1f1f1f;
|
|
||||||
border-color: #2c2c2c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-header h3 {
|
.input-header h3 {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -352,7 +360,7 @@ const startAnalysis = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.error-message {
|
.error-message {
|
||||||
color: #ff6b6b;
|
color: var(--van-danger-color);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container calendar-container">
|
<div class="page-container calendar-container">
|
||||||
<van-calendar
|
<van-calendar
|
||||||
title="日历"
|
title="日历"
|
||||||
@@ -11,6 +11,11 @@
|
|||||||
@select="onDateSelect"
|
@select="onDateSelect"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ContributionHeatmap ref="heatmapRef" />
|
||||||
|
|
||||||
|
<!-- 底部安全距离 -->
|
||||||
|
<div style="height: calc(60px + env(safe-area-inset-bottom, 0px))" />
|
||||||
|
|
||||||
<!-- 日期交易列表弹出层 -->
|
<!-- 日期交易列表弹出层 -->
|
||||||
<PopupContainer
|
<PopupContainer
|
||||||
v-model="listVisible"
|
v-model="listVisible"
|
||||||
@@ -45,158 +50,165 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, nextTick, onBeforeUnmount } from "vue";
|
import { ref, onMounted, nextTick, onBeforeUnmount } from 'vue'
|
||||||
import { showToast } from "vant";
|
import { showToast } from 'vant'
|
||||||
import request from "@/api/request";
|
import request from '@/api/request'
|
||||||
import { getTransactionDetail, getTransactionsByDate } from "@/api/transactionRecord";
|
import { getTransactionDetail, getTransactionsByDate } from '@/api/transactionRecord'
|
||||||
import TransactionList from "@/components/TransactionList.vue";
|
import TransactionList from '@/components/TransactionList.vue'
|
||||||
import TransactionDetail from "@/components/TransactionDetail.vue";
|
import TransactionDetail from '@/components/TransactionDetail.vue'
|
||||||
import SmartClassifyButton from "@/components/SmartClassifyButton.vue";
|
import SmartClassifyButton from '@/components/SmartClassifyButton.vue'
|
||||||
import PopupContainer from "@/components/PopupContainer.vue";
|
import PopupContainer from '@/components/PopupContainer.vue'
|
||||||
|
import ContributionHeatmap from '@/components/ContributionHeatmap.vue'
|
||||||
|
|
||||||
const dailyStatistics = ref({});
|
const dailyStatistics = ref({})
|
||||||
const listVisible = ref(false);
|
const listVisible = ref(false)
|
||||||
const detailVisible = ref(false);
|
const detailVisible = ref(false)
|
||||||
const dateTransactions = ref([]);
|
const dateTransactions = ref([])
|
||||||
const currentTransaction = ref(null);
|
const currentTransaction = ref(null)
|
||||||
const listLoading = ref(false);
|
const listLoading = ref(false)
|
||||||
const selectedDate = ref(null);
|
const selectedDate = ref(null)
|
||||||
const selectedDateText = ref("");
|
const selectedDateText = ref('')
|
||||||
|
const heatmapRef = ref(null)
|
||||||
|
|
||||||
// 设置日历可选范围(例如:过去2年到未来1年)
|
// 设置日历可选范围(例如:过去2年到未来1年)
|
||||||
const minDate = new Date(new Date().getFullYear() - 2, 0, 1); // 2年前的1月1日
|
const minDate = new Date(new Date().getFullYear() - 2, 0, 1) // 2年前的1月1日
|
||||||
const maxDate = new Date(new Date().getFullYear() + 1, 11, 31); // 明年12月31日
|
const maxDate = new Date(new Date().getFullYear() + 1, 11, 31) // 明年12月31日
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await nextTick();
|
await nextTick()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 计算页面高度,滚动3/4高度以显示更多日期
|
// 计算页面高度,滚动3/4高度以显示更多日期
|
||||||
const height = document.querySelector(".calendar-container").clientHeight * 0.45;
|
const height = document.querySelector('.calendar-container').clientHeight * 0.43
|
||||||
document.querySelector(".van-calendar__body").scrollBy({
|
document.querySelector('.van-calendar__body').scrollBy({
|
||||||
top: -height,
|
top: -height,
|
||||||
behavior: "smooth",
|
behavior: 'smooth'
|
||||||
});
|
})
|
||||||
}, 300);
|
}, 300)
|
||||||
});
|
})
|
||||||
|
|
||||||
// 获取日历统计数据
|
// 获取日历统计数据
|
||||||
const fetchDailyStatistics = async (year, month) => {
|
const fetchDailyStatistics = async (year, month) => {
|
||||||
try {
|
try {
|
||||||
const response = await request.get("/TransactionRecord/GetDailyStatistics", {
|
const response = await request.get('/TransactionRecord/GetDailyStatistics', {
|
||||||
params: { year, month },
|
params: { year, month }
|
||||||
});
|
})
|
||||||
if (response.success && response.data) {
|
if (response.success && response.data) {
|
||||||
// 将数组转换为对象,key为日期
|
// 将数组转换为对象,key为日期
|
||||||
const statsMap = {};
|
const statsMap = {}
|
||||||
response.data.forEach((item) => {
|
response.data.forEach((item) => {
|
||||||
|
console.warn(item)
|
||||||
statsMap[item.date] = {
|
statsMap[item.date] = {
|
||||||
count: item.count,
|
count: item.count,
|
||||||
amount: item.amount,
|
amount: (item.income - item.expense).toFixed(1)
|
||||||
};
|
}
|
||||||
});
|
})
|
||||||
dailyStatistics.value = {
|
dailyStatistics.value = {
|
||||||
...dailyStatistics.value,
|
...dailyStatistics.value,
|
||||||
...statsMap,
|
...statsMap
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取日历统计数据失败:", error);
|
console.error('获取日历统计数据失败:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const smartClassifyButtonRef = ref(null);
|
const smartClassifyButtonRef = ref(null)
|
||||||
// 获取指定日期的交易列表
|
// 获取指定日期的交易列表
|
||||||
const fetchDateTransactions = async (date) => {
|
const fetchDateTransactions = async (date) => {
|
||||||
try {
|
try {
|
||||||
listLoading.value = true;
|
listLoading.value = true
|
||||||
const dateStr = date
|
const dateStr = date
|
||||||
.toLocaleString("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit" })
|
.toLocaleString('zh-CN', {
|
||||||
.replace(/\//g, "-");
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit'
|
||||||
|
})
|
||||||
|
.replace(/\//g, '-')
|
||||||
|
|
||||||
const response = await getTransactionsByDate(dateStr);
|
const response = await getTransactionsByDate(dateStr)
|
||||||
|
|
||||||
if (response.success && response.data) {
|
if (response.success && response.data) {
|
||||||
// 根据金额从大到小排序
|
// 根据金额从大到小排序
|
||||||
dateTransactions.value = response
|
dateTransactions.value = response.data.sort((a, b) => b.amount - a.amount)
|
||||||
.data
|
|
||||||
.sort((a, b) => b.amount - a.amount);
|
|
||||||
// 重置智能分类按钮
|
// 重置智能分类按钮
|
||||||
smartClassifyButtonRef.value?.reset()
|
smartClassifyButtonRef.value?.reset()
|
||||||
} else {
|
} else {
|
||||||
dateTransactions.value = [];
|
dateTransactions.value = []
|
||||||
showToast(response.message || "获取交易列表失败");
|
showToast(response.message || '获取交易列表失败')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取日期交易列表失败:", error);
|
console.error('获取日期交易列表失败:', error)
|
||||||
dateTransactions.value = [];
|
dateTransactions.value = []
|
||||||
showToast("获取交易列表失败");
|
showToast('获取交易列表失败')
|
||||||
} finally {
|
} finally {
|
||||||
listLoading.value = false;
|
listLoading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const getBalance = (transactions) => {
|
const getBalance = (transactions) => {
|
||||||
let balance = 0;
|
let balance = 0
|
||||||
transactions.forEach(tx => {
|
transactions.forEach((tx) => {
|
||||||
if (tx.type === 1) {
|
if (tx.type === 1) {
|
||||||
balance += tx.amount;
|
balance += tx.amount
|
||||||
} else if (tx.type === 0) {
|
} else if (tx.type === 0) {
|
||||||
balance -= tx.amount;
|
balance -= tx.amount
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if (balance >= 0) {
|
if (balance >= 0) {
|
||||||
return `结余收入 ${balance.toFixed(1)} 元`;
|
return `结余收入 ${balance.toFixed(1)} 元`
|
||||||
} else {
|
} else {
|
||||||
return `结余支出 ${(-balance).toFixed(1)} 元`;
|
return `结余支出 ${(-balance).toFixed(1)} 元`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// 当月份显示时触发
|
// 当月份显示时触发
|
||||||
const onMonthShow = ({ date }) => {
|
const onMonthShow = ({ date }) => {
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear()
|
||||||
const month = date.getMonth() + 1;
|
const month = date.getMonth() + 1
|
||||||
fetchDailyStatistics(year, month);
|
fetchDailyStatistics(year, month)
|
||||||
};
|
}
|
||||||
|
|
||||||
// 日期选择事件
|
// 日期选择事件
|
||||||
const onDateSelect = (date) => {
|
const onDateSelect = (date) => {
|
||||||
selectedDate.value = date;
|
selectedDate.value = date
|
||||||
selectedDateText.value = formatSelectedDate(date);
|
selectedDateText.value = formatSelectedDate(date)
|
||||||
fetchDateTransactions(date);
|
fetchDateTransactions(date)
|
||||||
listVisible.value = true;
|
listVisible.value = true
|
||||||
};
|
}
|
||||||
|
|
||||||
// 格式化选中的日期
|
// 格式化选中的日期
|
||||||
const formatSelectedDate = (date) => {
|
const formatSelectedDate = (date) => {
|
||||||
return date.toLocaleDateString("zh-CN", {
|
return date.toLocaleDateString('zh-CN', {
|
||||||
year: "numeric",
|
year: 'numeric',
|
||||||
month: "long",
|
month: 'long',
|
||||||
day: "numeric",
|
day: 'numeric',
|
||||||
weekday: "long",
|
weekday: 'long'
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
// 查看详情
|
// 查看详情
|
||||||
const viewDetail = async (transaction) => {
|
const viewDetail = async (transaction) => {
|
||||||
try {
|
try {
|
||||||
const response = await getTransactionDetail(transaction.id);
|
const response = await getTransactionDetail(transaction.id)
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
currentTransaction.value = response.data;
|
currentTransaction.value = response.data
|
||||||
detailVisible.value = true;
|
detailVisible.value = true
|
||||||
} else {
|
} else {
|
||||||
showToast(response.message || "获取详情失败");
|
showToast(response.message || '获取详情失败')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取详情出错:", error);
|
console.error('获取详情出错:', error)
|
||||||
showToast("获取详情失败");
|
showToast('获取详情失败')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// 详情保存后的回调
|
// 详情保存后的回调
|
||||||
const onDetailSave = async (saveData) => {
|
const onDetailSave = async (saveData) => {
|
||||||
var item = dateTransactions.value.find(tx => tx.id === saveData.id);
|
const item = dateTransactions.value.find((tx) => tx.id === saveData.id)
|
||||||
if(!item) return
|
if (!item) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 如果分类发生了变化 移除智能分类的内容,防止被智能分类覆盖
|
// 如果分类发生了变化 移除智能分类的内容,防止被智能分类覆盖
|
||||||
if (item.classify !== saveData.classify) {
|
if (item.classify !== saveData.classify) {
|
||||||
@@ -206,58 +218,60 @@ const onDetailSave = async (saveData) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新当前日期交易列表中的数据
|
// 更新当前日期交易列表中的数据
|
||||||
Object.assign(item, saveData);
|
Object.assign(item, saveData)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 重新加载当前月份的统计数据
|
// 重新加载当前月份的统计数据
|
||||||
const now = selectedDate.value || new Date();
|
const now = selectedDate.value || new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
};
|
}
|
||||||
|
|
||||||
// 处理删除事件:从当前日期交易列表中移除,并刷新当日和当月统计
|
// 处理删除事件:从当前日期交易列表中移除,并刷新当日和当月统计
|
||||||
const handleDateTransactionDelete = async (transactionId) => {
|
const handleDateTransactionDelete = async (transactionId) => {
|
||||||
dateTransactions.value = dateTransactions.value.filter(t => t.id !== transactionId)
|
dateTransactions.value = dateTransactions.value.filter((t) => t.id !== transactionId)
|
||||||
|
|
||||||
// 刷新当前日期以及当月的统计数据
|
// 刷新当前日期以及当月的统计数据
|
||||||
const now = selectedDate.value || new Date();
|
const now = selectedDate.value || new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
};
|
}
|
||||||
|
|
||||||
// 智能分类保存回调
|
// 智能分类保存回调
|
||||||
const onSmartClassifySave = async () => {
|
const onSmartClassifySave = async () => {
|
||||||
// 保存完成后重新加载数据
|
// 保存完成后重新加载数据
|
||||||
if (selectedDate.value) {
|
if (selectedDate.value) {
|
||||||
await fetchDateTransactions(selectedDate.value);
|
await fetchDateTransactions(selectedDate.value)
|
||||||
}
|
}
|
||||||
// 重新加载统计数据
|
// 重新加载统计数据
|
||||||
const now = selectedDate.value || new Date();
|
const now = selectedDate.value || new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
};
|
}
|
||||||
|
|
||||||
const formatterCalendar = (day) => {
|
const formatterCalendar = (day) => {
|
||||||
const dayCopy = { ...day };
|
const dayCopy = { ...day }
|
||||||
if (dayCopy.date.toDateString() === new Date().toDateString()) {
|
if (dayCopy.date.toDateString() === new Date().toDateString()) {
|
||||||
dayCopy.text = "今天";
|
dayCopy.text = '今天'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期为 yyyy-MM-dd
|
// 格式化日期为 yyyy-MM-dd
|
||||||
const dateKey = dayCopy.date
|
const dateKey = dayCopy.date
|
||||||
.toLocaleString("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit" })
|
.toLocaleString('zh-CN', {
|
||||||
.replace(/\//g, "-");
|
year: 'numeric',
|
||||||
const stats = dailyStatistics.value[dateKey];
|
month: '2-digit',
|
||||||
|
day: '2-digit'
|
||||||
|
})
|
||||||
|
.replace(/\//g, '-')
|
||||||
|
const stats = dailyStatistics.value[dateKey]
|
||||||
|
|
||||||
if (stats) {
|
if (stats) {
|
||||||
dayCopy.topInfo = `${stats.count}笔`; // 展示消费笔数
|
dayCopy.topInfo = `${stats.count}笔` // 展示消费笔数
|
||||||
dayCopy.bottomInfo = `${stats.amount.toFixed(1)}元`; // 展示消费金额
|
dayCopy.bottomInfo = `${stats.amount}元` // 展示消费金额
|
||||||
}
|
}
|
||||||
|
|
||||||
return dayCopy;
|
return dayCopy
|
||||||
};
|
}
|
||||||
|
|
||||||
// 初始加载当前月份数据
|
// 初始加载当前月份数据
|
||||||
const now = new Date();
|
const now = new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
|
|
||||||
// 全局删除事件监听,确保日历页面数据一致
|
// 全局删除事件监听,确保日历页面数据一致
|
||||||
const onGlobalTransactionDeleted = () => {
|
const onGlobalTransactionDeleted = () => {
|
||||||
@@ -266,12 +280,15 @@ const onGlobalTransactionDeleted = () => {
|
|||||||
}
|
}
|
||||||
const now = selectedDate.value || new Date()
|
const now = selectedDate.value || new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
|
heatmapRef.value?.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当有交易被新增/修改/批量更新时刷新
|
// 当有交易被新增/修改/批量更新时刷新
|
||||||
@@ -281,33 +298,39 @@ const onGlobalTransactionsChanged = () => {
|
|||||||
}
|
}
|
||||||
const now = selectedDate.value || new Date()
|
const now = selectedDate.value || new Date()
|
||||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||||
|
heatmapRef.value?.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
:deep(.van-calendar__header-title){
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.van-calendar {
|
.van-calendar {
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.calendar-container {
|
.calendar-container {
|
||||||
/* 使用准确的视口高度减去 TabBar 高度(50px)和安全区域 */
|
/* 使用准确的视口高度减去 TabBar 高度(50px)和安全区域 */
|
||||||
height: calc(var(--vh, 100vh) - 50px - env(safe-area-inset-bottom, 0px));
|
|
||||||
max-height: calc(var(--vh, 100vh) - 50px - env(safe-area-inset-bottom, 0px));
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
background-color: var(--van-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
.calendar-container :deep(.van-calendar) {
|
.calendar-container :deep(.van-calendar) {
|
||||||
height: 100% !important;
|
height: calc(auto + 40px) !important;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@@ -328,4 +351,8 @@ onBeforeUnmount(() => {
|
|||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add margin to bottom of heatmap to separate from tabbar */
|
||||||
|
:deep(.heatmap-card) {
|
||||||
|
flex-shrink: 0; /* Prevent heatmap from shrinking */
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -26,12 +26,7 @@
|
|||||||
<div v-else class="level-container">
|
<div v-else class="level-container">
|
||||||
<!-- 面包屑导航 -->
|
<!-- 面包屑导航 -->
|
||||||
<div class="breadcrumb">
|
<div class="breadcrumb">
|
||||||
<van-tag
|
<van-tag type="primary" closeable style="margin-left: 16px" @close="handleBackToRoot">
|
||||||
type="primary"
|
|
||||||
closeable
|
|
||||||
style="margin-left: 16px;"
|
|
||||||
@close="handleBackToRoot"
|
|
||||||
>
|
|
||||||
{{ currentTypeName }}
|
{{ currentTypeName }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
</div>
|
</div>
|
||||||
@@ -41,34 +36,20 @@
|
|||||||
|
|
||||||
<van-cell-group v-else inset>
|
<van-cell-group v-else inset>
|
||||||
<van-swipe-cell v-for="category in categories" :key="category.id">
|
<van-swipe-cell v-for="category in categories" :key="category.id">
|
||||||
<van-cell
|
<van-cell :title="category.name" is-link @click="handleEdit(category)" />
|
||||||
:title="category.name"
|
|
||||||
is-link
|
|
||||||
@click="handleEdit(category)"
|
|
||||||
/>
|
|
||||||
<template #right>
|
<template #right>
|
||||||
<van-button
|
<van-button square type="danger" text="删除" @click="handleDelete(category)" />
|
||||||
square
|
|
||||||
type="danger"
|
|
||||||
text="删除"
|
|
||||||
@click="handleDelete(category)"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</van-swipe-cell>
|
</van-swipe-cell>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(80px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(55px + env(safe-area-inset-bottom, 0px))" />
|
||||||
|
|
||||||
<div class="bottom-button">
|
<div class="bottom-button">
|
||||||
<!-- 新增分类按钮 -->
|
<!-- 新增分类按钮 -->
|
||||||
<van-button
|
<van-button type="primary" size="large" icon="plus" @click="handleAddCategory">
|
||||||
type="primary"
|
|
||||||
size="large"
|
|
||||||
icon="plus"
|
|
||||||
@click="handleAddCategory"
|
|
||||||
>
|
|
||||||
新增分类
|
新增分类
|
||||||
</van-button>
|
</van-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -123,12 +104,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import { showSuccessToast, showToast, showLoadingToast, closeToast } from 'vant'
|
||||||
showSuccessToast,
|
|
||||||
showToast,
|
|
||||||
showLoadingToast,
|
|
||||||
closeToast
|
|
||||||
} from 'vant'
|
|
||||||
import {
|
import {
|
||||||
getCategoryList,
|
getCategoryList,
|
||||||
createCategory,
|
createCategory,
|
||||||
@@ -149,7 +125,7 @@ const typeOptions = [
|
|||||||
const currentLevel = ref(0) // 0=类型选择, 1=分类管理
|
const currentLevel = ref(0) // 0=类型选择, 1=分类管理
|
||||||
const currentType = ref(null) // 当前选中的交易类型
|
const currentType = ref(null) // 当前选中的交易类型
|
||||||
const currentTypeName = computed(() => {
|
const currentTypeName = computed(() => {
|
||||||
const type = typeOptions.find(t => t.value === currentType.value)
|
const type = typeOptions.find((t) => t.value === currentType.value)
|
||||||
return type ? type.label : ''
|
return type ? type.label : ''
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -340,7 +316,9 @@ const handleDelete = async (category) => {
|
|||||||
* 确认删除
|
* 确认删除
|
||||||
*/
|
*/
|
||||||
const handleConfirmDelete = async () => {
|
const handleConfirmDelete = async () => {
|
||||||
if (!deleteTarget.value) return
|
if (!deleteTarget.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
showLoadingToast({
|
showLoadingToast({
|
||||||
@@ -382,7 +360,6 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.level-container {
|
.level-container {
|
||||||
min-height: calc(100vh - 50px);
|
min-height: calc(100vh - 50px);
|
||||||
@@ -398,11 +375,11 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 深色模式 */
|
/* 深色模式 */
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.level-container {
|
.level-container {
|
||||||
background: #1a1a1a;
|
background: var(--van-background);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
/* 设置页面容器背景色 */
|
/* 设置页面容器背景色 */
|
||||||
:deep(.van-nav-bar) {
|
:deep(.van-nav-bar) {
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex classification-nlp">
|
<div class="page-container-flex classification-nlp">
|
||||||
<van-nav-bar
|
<van-nav-bar title="自然语言分类" left-text="返回" left-arrow @click-left="onClickLeft" />
|
||||||
title="自然语言分类"
|
|
||||||
left-text="返回"
|
|
||||||
left-arrow
|
|
||||||
@click-left="onClickLeft"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="scroll-content">
|
<div class="scroll-content">
|
||||||
<!-- 输入区域 -->
|
<!-- 输入区域 -->
|
||||||
@@ -23,13 +18,7 @@
|
|||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<van-button
|
<van-button type="primary" block round :loading="analyzing" @click="handleAnalyze">
|
||||||
type="primary"
|
|
||||||
block
|
|
||||||
round
|
|
||||||
:loading="analyzing"
|
|
||||||
@click="handleAnalyze"
|
|
||||||
>
|
|
||||||
分析查询
|
分析查询
|
||||||
</van-button>
|
</van-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -59,30 +48,12 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 记录列表弹窗 -->
|
<!-- 记录列表弹窗 -->
|
||||||
<PopupContainer
|
<PopupContainer v-model="showRecordsList" title="交易记录列表" height="75%">
|
||||||
v-model="showRecordsList"
|
<div style="background: var(--van-background)">
|
||||||
title="交易记录列表"
|
|
||||||
height="75%"
|
|
||||||
>
|
|
||||||
<div style="background: var(--van-background, #f7f8fa);">
|
|
||||||
<!-- 批量操作按钮 -->
|
<!-- 批量操作按钮 -->
|
||||||
<div class="batch-actions">
|
<div class="batch-actions">
|
||||||
<van-button
|
<van-button plain type="primary" size="small" @click="selectAll"> 全选 </van-button>
|
||||||
plain
|
<van-button plain type="default" size="small" @click="selectNone"> 全不选 </van-button>
|
||||||
type="primary"
|
|
||||||
size="small"
|
|
||||||
@click="selectAll"
|
|
||||||
>
|
|
||||||
全选
|
|
||||||
</van-button>
|
|
||||||
<van-button
|
|
||||||
plain
|
|
||||||
type="default"
|
|
||||||
size="small"
|
|
||||||
@click="selectNone"
|
|
||||||
>
|
|
||||||
全不选
|
|
||||||
</van-button>
|
|
||||||
<van-button
|
<van-button
|
||||||
type="success"
|
type="success"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -138,9 +109,11 @@ const onClickLeft = () => {
|
|||||||
|
|
||||||
// 将带目标分类的记录转换为普通交易记录格式供列表显示
|
// 将带目标分类的记录转换为普通交易记录格式供列表显示
|
||||||
const displayRecords = computed(() => {
|
const displayRecords = computed(() => {
|
||||||
if (!analysisResult.value) return []
|
if (!analysisResult.value) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
return analysisResult.value.records.map(r => ({
|
return analysisResult.value.records.map((r) => ({
|
||||||
id: r.id,
|
id: r.id,
|
||||||
reason: r.reason,
|
reason: r.reason,
|
||||||
amount: r.amount,
|
amount: r.amount,
|
||||||
@@ -183,7 +156,7 @@ const handleAnalyze = async () => {
|
|||||||
analysisResult.value = response.data
|
analysisResult.value = response.data
|
||||||
|
|
||||||
// 默认全选
|
// 默认全选
|
||||||
const allIds = new Set(response.data.records.map(r => r.id))
|
const allIds = new Set(response.data.records.map((r) => r.id))
|
||||||
selectedIds.value = allIds
|
selectedIds.value = allIds
|
||||||
|
|
||||||
showToast(`找到 ${response.data.records.length} 条记录`)
|
showToast(`找到 ${response.data.records.length} 条记录`)
|
||||||
@@ -200,8 +173,10 @@ const handleAnalyze = async () => {
|
|||||||
|
|
||||||
// 全选
|
// 全选
|
||||||
const selectAll = () => {
|
const selectAll = () => {
|
||||||
if (!analysisResult.value) return
|
if (!analysisResult.value) {
|
||||||
const allIds = new Set(analysisResult.value.records.map(r => r.id))
|
return
|
||||||
|
}
|
||||||
|
const allIds = new Set(analysisResult.value.records.map((r) => r.id))
|
||||||
selectedIds.value = allIds
|
selectedIds.value = allIds
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +193,7 @@ const updateSelectedIds = (newSelectedIds) => {
|
|||||||
// 点击记录查看详情
|
// 点击记录查看详情
|
||||||
const handleRecordClick = (transaction) => {
|
const handleRecordClick = (transaction) => {
|
||||||
// 从原始记录中获取完整信息
|
// 从原始记录中获取完整信息
|
||||||
const record = analysisResult.value?.records.find(r => r.id === transaction.id)
|
const record = analysisResult.value?.records.find((r) => r.id === transaction.id)
|
||||||
if (record) {
|
if (record) {
|
||||||
currentTransaction.value = {
|
currentTransaction.value = {
|
||||||
id: record.id,
|
id: record.id,
|
||||||
@@ -266,8 +241,8 @@ const handleSubmit = async () => {
|
|||||||
|
|
||||||
// 构建批量更新数据(使用AI修改后的结果)
|
// 构建批量更新数据(使用AI修改后的结果)
|
||||||
const items = analysisResult.value.records
|
const items = analysisResult.value.records
|
||||||
.filter(r => selectedIds.value.has(r.id))
|
.filter((r) => selectedIds.value.has(r.id))
|
||||||
.map(r => ({
|
.map((r) => ({
|
||||||
id: r.id,
|
id: r.id,
|
||||||
classify: r.upsetedClassify,
|
classify: r.upsetedClassify,
|
||||||
type: r.upsetedType
|
type: r.upsetedType
|
||||||
@@ -320,7 +295,7 @@ const handleSubmit = async () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
background-color: var(--van-background-2, #fff);
|
background-color: var(--van-background-2);
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex smart-classification">
|
<div class="page-container-flex smart-classification">
|
||||||
<van-nav-bar
|
<van-nav-bar title="智能分类" left-text="返回" left-arrow @click-left="onClickLeft" />
|
||||||
title="智能分类"
|
|
||||||
left-text="返回"
|
|
||||||
left-arrow
|
|
||||||
@click-left="onClickLeft"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="scroll-content" style="padding-top: 5px;">
|
<div class="scroll-content" style="padding-top: 5px">
|
||||||
<!-- 统计信息 -->
|
<!-- 统计信息 -->
|
||||||
<div class="stats-info">
|
<div class="stats-info">
|
||||||
<span class="stats-label">未分类账单 </span>
|
<span class="stats-label">未分类账单 </span>
|
||||||
@@ -23,7 +18,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 底部操作按钮 -->
|
<!-- 底部操作按钮 -->
|
||||||
@@ -56,11 +51,7 @@
|
|||||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { showToast, showLoadingToast, closeToast, showConfirmDialog } from 'vant'
|
import { showToast, showLoadingToast, closeToast, showConfirmDialog } from 'vant'
|
||||||
import {
|
import { getUnclassifiedCount, smartClassify, batchUpdateClassify } from '@/api/transactionRecord'
|
||||||
getUnclassifiedCount,
|
|
||||||
smartClassify,
|
|
||||||
batchUpdateClassify
|
|
||||||
} from '@/api/transactionRecord'
|
|
||||||
import ReasonGroupList from '@/components/ReasonGroupList.vue'
|
import ReasonGroupList from '@/components/ReasonGroupList.vue'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -74,7 +65,9 @@ const suppressDataChanged = ref(false)
|
|||||||
|
|
||||||
// 计算已选中的数量
|
// 计算已选中的数量
|
||||||
const selectedCount = computed(() => {
|
const selectedCount = computed(() => {
|
||||||
if (!groupListRef.value) return 0
|
if (!groupListRef.value) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return groupListRef.value.getSelectedReasons().size
|
return groupListRef.value.getSelectedReasons().size
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -114,10 +107,12 @@ const onClickLeft = () => {
|
|||||||
if (hasChanges.value) {
|
if (hasChanges.value) {
|
||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '有未保存的分类结果,确定要离开吗?',
|
message: '有未保存的分类结果,确定要离开吗?'
|
||||||
}).then(() => {
|
})
|
||||||
|
.then(() => {
|
||||||
router.back()
|
router.back()
|
||||||
}).catch(() => {})
|
})
|
||||||
|
.catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
@@ -125,7 +120,9 @@ const onClickLeft = () => {
|
|||||||
|
|
||||||
// 开始智能分类
|
// 开始智能分类
|
||||||
const startClassify = async () => {
|
const startClassify = async () => {
|
||||||
if (!groupListRef.value) return
|
if (!groupListRef.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 获取所有选中分组
|
// 获取所有选中分组
|
||||||
const selectedGroups = groupListRef.value.getList(true)
|
const selectedGroups = groupListRef.value.getList(true)
|
||||||
@@ -167,14 +164,18 @@ const startClassify = async () => {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read()
|
const { done, value } = await reader.read()
|
||||||
|
|
||||||
if (done) break
|
if (done) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
buffer += decoder.decode(value, { stream: true })
|
buffer += decoder.decode(value, { stream: true })
|
||||||
const lines = buffer.split('\n\n')
|
const lines = buffer.split('\n\n')
|
||||||
buffer = lines.pop() || ''
|
buffer = lines.pop() || ''
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line.trim()) continue
|
if (!line.trim()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const eventMatch = line.match(/^event: (.+)$/m)
|
const eventMatch = line.match(/^event: (.+)$/m)
|
||||||
const dataMatch = line.match(/^data: (.+)$/m)
|
const dataMatch = line.match(/^data: (.+)$/m)
|
||||||
@@ -215,8 +216,9 @@ const handleSSEEvent = (eventType, data, classifyResults) => {
|
|||||||
let braceCount = 0
|
let braceCount = 0
|
||||||
let closeBrace = -1
|
let closeBrace = -1
|
||||||
for (let i = openBrace; i < classifyBuffer.value.length; i++) {
|
for (let i = openBrace; i < classifyBuffer.value.length; i++) {
|
||||||
if (classifyBuffer.value[i] === '{') braceCount++
|
if (classifyBuffer.value[i] === '{') {
|
||||||
else if (classifyBuffer.value[i] === '}') {
|
braceCount++
|
||||||
|
} else if (classifyBuffer.value[i] === '}') {
|
||||||
braceCount--
|
braceCount--
|
||||||
if (braceCount === 0) {
|
if (braceCount === 0) {
|
||||||
closeBrace = i
|
closeBrace = i
|
||||||
@@ -283,7 +285,9 @@ const handleSSEEvent = (eventType, data, classifyResults) => {
|
|||||||
|
|
||||||
// 保存分类
|
// 保存分类
|
||||||
const saveClassifications = async () => {
|
const saveClassifications = async () => {
|
||||||
if (!groupListRef.value) return
|
if (!groupListRef.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 收集所有已分类的账单
|
// 收集所有已分类的账单
|
||||||
const groups = groupListRef.value.getList()
|
const groups = groupListRef.value.getList()
|
||||||
@@ -346,7 +350,7 @@ onMounted(async () => {
|
|||||||
.stats-info {
|
.stats-info {
|
||||||
padding: 12px 12px 0 16px;
|
padding: 12px 12px 0 16px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats-value {
|
.stats-value {
|
||||||
|
|||||||
@@ -2,9 +2,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex">
|
<div class="page-container-flex">
|
||||||
<!-- 下拉刷新区域 -->
|
<!-- 下拉刷新区域 -->
|
||||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
<van-pull-refresh
|
||||||
|
v-model="refreshing"
|
||||||
|
@refresh="onRefresh"
|
||||||
|
>
|
||||||
<!-- 加载提示 -->
|
<!-- 加载提示 -->
|
||||||
<van-loading v-if="loading && !(emailList && emailList.length)" vertical style="padding: 50px 0">
|
<van-loading
|
||||||
|
v-if="loading && !(emailList && emailList.length)"
|
||||||
|
vertical
|
||||||
|
style="padding: 50px 0"
|
||||||
|
>
|
||||||
加载中...
|
加载中...
|
||||||
</van-loading>
|
</van-loading>
|
||||||
<!-- 邮件列表 -->
|
<!-- 邮件列表 -->
|
||||||
@@ -14,7 +21,11 @@
|
|||||||
finished-text="没有更多了"
|
finished-text="没有更多了"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
>
|
>
|
||||||
<van-cell-group v-if="emailList && emailList.length" inset style="margin-top: 10px">
|
<van-cell-group
|
||||||
|
v-if="emailList && emailList.length"
|
||||||
|
inset
|
||||||
|
style="margin-top: 10px"
|
||||||
|
>
|
||||||
<van-swipe-cell
|
<van-swipe-cell
|
||||||
v-for="email in emailList"
|
v-for="email in emailList"
|
||||||
:key="email.id"
|
:key="email.id"
|
||||||
@@ -27,11 +38,15 @@
|
|||||||
>
|
>
|
||||||
<template #value>
|
<template #value>
|
||||||
<div class="email-info">
|
<div class="email-info">
|
||||||
<div class="email-date">{{ formatDate(email.receivedDate) }}</div>
|
<div class="email-date">
|
||||||
<div v-if="email.transactionCount > 0" class="bill-count">
|
{{ formatDate(email.receivedDate) }}
|
||||||
<span style="font-size: 12px;">已解析{{ email.transactionCount }}条账单</span>
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="email.transactionCount > 0"
|
||||||
|
class="bill-count"
|
||||||
|
>
|
||||||
|
<span style="font-size: 12px">已解析{{ email.transactionCount }}条账单</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
@@ -54,13 +69,13 @@
|
|||||||
</van-list>
|
</van-list>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
|
|
||||||
<!-- 详情弹出层 -->
|
<!-- 详情弹出层 -->
|
||||||
<PopupContainer
|
<PopupContainer
|
||||||
v-model="detailVisible"
|
v-model="detailVisible"
|
||||||
:title="currentEmail ? (currentEmail.Subject || currentEmail.subject || '(无主题)') : ''"
|
:title="currentEmail ? currentEmail.Subject || currentEmail.subject || '(无主题)' : ''"
|
||||||
height="75%"
|
height="75%"
|
||||||
>
|
>
|
||||||
<template #header-actions>
|
<template #header-actions>
|
||||||
@@ -75,10 +90,22 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div v-if="currentEmail">
|
<div v-if="currentEmail">
|
||||||
<van-cell-group inset style="margin-top: 12px;">
|
<van-cell-group
|
||||||
<van-cell title="发件人" :value="currentEmail.From || currentEmail.from || '未知'" />
|
inset
|
||||||
<van-cell title="接收时间" :value="formatDate(currentEmail.ReceivedDate || currentEmail.receivedDate)" />
|
style="margin-top: 12px"
|
||||||
<van-cell title="记录时间" :value="formatDate(currentEmail.CreateTime || currentEmail.createTime)" />
|
>
|
||||||
|
<van-cell
|
||||||
|
title="发件人"
|
||||||
|
:value="currentEmail.From || currentEmail.from || '未知'"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="接收时间"
|
||||||
|
:value="formatDate(currentEmail.ReceivedDate || currentEmail.receivedDate)"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="记录时间"
|
||||||
|
:value="formatDate(currentEmail.CreateTime || currentEmail.createTime)"
|
||||||
|
/>
|
||||||
<van-cell
|
<van-cell
|
||||||
v-if="(currentEmail.TransactionCount || currentEmail.transactionCount || 0) > 0"
|
v-if="(currentEmail.TransactionCount || currentEmail.transactionCount || 0) > 0"
|
||||||
title="已解析账单数"
|
title="已解析账单数"
|
||||||
@@ -88,21 +115,26 @@
|
|||||||
/>
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
<div class="email-content">
|
<div class="email-content">
|
||||||
<h4 style="margin-left: 10px;">邮件内容</h4>
|
<h4 style="margin-left: 10px">
|
||||||
|
邮件内容
|
||||||
|
</h4>
|
||||||
<div
|
<div
|
||||||
v-if="currentEmail.htmlBody"
|
v-if="currentEmail.htmlBody"
|
||||||
class="content-body html-content"
|
class="content-body html-content"
|
||||||
v-html="currentEmail.htmlBody"
|
v-html="currentEmail.htmlBody"
|
||||||
></div>
|
/>
|
||||||
<div
|
<div
|
||||||
v-else-if="currentEmail.body"
|
v-else-if="currentEmail.body"
|
||||||
class="content-body"
|
class="content-body"
|
||||||
>
|
>
|
||||||
{{ currentEmail.body }}
|
{{ currentEmail.body }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="content-body empty-content">
|
<div
|
||||||
|
v-else
|
||||||
|
class="content-body empty-content"
|
||||||
|
>
|
||||||
暂无邮件内容
|
暂无邮件内容
|
||||||
<div style="font-size: 12px; margin-top: 8px; color: #999;">
|
<div style="font-size: 12px; margin-top: 8px; color: var(--van-gray-6)">
|
||||||
Debug: {{ Object.keys(currentEmail).join(', ') }}
|
Debug: {{ Object.keys(currentEmail).join(', ') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,7 +171,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import { showToast, showConfirmDialog } from 'vant'
|
import { showToast, showConfirmDialog } from 'vant'
|
||||||
import { getEmailList, getEmailDetail, deleteEmail, refreshTransactionRecords, syncEmails, getEmailTransactions } from '@/api/emailRecord'
|
import {
|
||||||
|
getEmailList,
|
||||||
|
getEmailDetail,
|
||||||
|
deleteEmail,
|
||||||
|
refreshTransactionRecords,
|
||||||
|
syncEmails,
|
||||||
|
getEmailTransactions
|
||||||
|
} from '@/api/emailRecord'
|
||||||
import { getTransactionDetail } from '@/api/transactionRecord'
|
import { getTransactionDetail } from '@/api/transactionRecord'
|
||||||
import TransactionList from '@/components/TransactionList.vue'
|
import TransactionList from '@/components/TransactionList.vue'
|
||||||
import TransactionDetail from '@/components/TransactionDetail.vue'
|
import TransactionDetail from '@/components/TransactionDetail.vue'
|
||||||
@@ -163,7 +202,9 @@ const currentTransaction = ref(null)
|
|||||||
|
|
||||||
// 加载数据
|
// 加载数据
|
||||||
const loadData = async (isRefresh = false) => {
|
const loadData = async (isRefresh = false) => {
|
||||||
if (loading.value) return // 防止重复加载
|
if (loading.value) {
|
||||||
|
return
|
||||||
|
} // 防止重复加载
|
||||||
|
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
pageIndex.value = 1
|
pageIndex.value = 1
|
||||||
@@ -246,7 +287,7 @@ const handleDelete = async (email) => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要删除这封邮件吗?',
|
message: '确定要删除这封邮件吗?'
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await deleteEmail(email.id)
|
const response = await deleteEmail(email.id)
|
||||||
@@ -266,12 +307,14 @@ const handleDelete = async (email) => {
|
|||||||
|
|
||||||
// 重新分析
|
// 重新分析
|
||||||
const handleRefreshAnalysis = async () => {
|
const handleRefreshAnalysis = async () => {
|
||||||
if (!currentEmail.value) return
|
if (!currentEmail.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要重新分析该邮件并刷新交易记录吗?',
|
message: '确定要重新分析该邮件并刷新交易记录吗?'
|
||||||
})
|
})
|
||||||
|
|
||||||
refreshingAnalysis.value = true
|
refreshingAnalysis.value = true
|
||||||
@@ -316,7 +359,9 @@ const handleSync = async () => {
|
|||||||
|
|
||||||
// 查看关联的账单列表
|
// 查看关联的账单列表
|
||||||
const viewTransactions = async () => {
|
const viewTransactions = async () => {
|
||||||
if (!currentEmail.value) return
|
if (!currentEmail.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const emailId = currentEmail.value.id
|
const emailId = currentEmail.value.id
|
||||||
@@ -340,18 +385,22 @@ const onGlobalTransactionDeleted = (e) => {
|
|||||||
// 如果交易列表弹窗打开,尝试重新加载邮箱的交易列表
|
// 如果交易列表弹窗打开,尝试重新加载邮箱的交易列表
|
||||||
if (transactionListVisible.value && currentEmail.value) {
|
if (transactionListVisible.value && currentEmail.value) {
|
||||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||||
getEmailTransactions(emailId).then(response => {
|
getEmailTransactions(emailId)
|
||||||
|
.then((response) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
transactionList.value = response.data || []
|
transactionList.value = response.data || []
|
||||||
}
|
}
|
||||||
}).catch(() => {})
|
})
|
||||||
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听新增/修改/批量更新事件,刷新弹窗内交易或邮件列表
|
// 监听新增/修改/批量更新事件,刷新弹窗内交易或邮件列表
|
||||||
@@ -359,21 +408,25 @@ const onGlobalTransactionsChanged = (e) => {
|
|||||||
console.log('收到全局交易变更事件:', e)
|
console.log('收到全局交易变更事件:', e)
|
||||||
if (transactionListVisible.value && currentEmail.value) {
|
if (transactionListVisible.value && currentEmail.value) {
|
||||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||||
getEmailTransactions(emailId).then(response => {
|
getEmailTransactions(emailId)
|
||||||
|
.then((response) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
transactionList.value = response.data || []
|
transactionList.value = response.data || []
|
||||||
}
|
}
|
||||||
}).catch(() => {})
|
})
|
||||||
|
.catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
// 也刷新邮件列表以保持统计一致
|
// 也刷新邮件列表以保持统计一致
|
||||||
loadData(true)
|
loadData(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理点击账单
|
// 处理点击账单
|
||||||
@@ -394,7 +447,7 @@ const handleTransactionClick = async (transaction) => {
|
|||||||
|
|
||||||
const handleTransactionDelete = (transactionId) => {
|
const handleTransactionDelete = (transactionId) => {
|
||||||
// 从当前的交易列表中移除该交易
|
// 从当前的交易列表中移除该交易
|
||||||
transactionList.value = transactionList.value.filter(t => t.id !== transactionId)
|
transactionList.value = transactionList.value.filter((t) => t.id !== transactionId)
|
||||||
|
|
||||||
// 刷新邮件列表
|
// 刷新邮件列表
|
||||||
loadData(true)
|
loadData(true)
|
||||||
@@ -402,15 +455,14 @@ const handleTransactionDelete = (transactionId) => {
|
|||||||
// 刷新当前邮件详情
|
// 刷新当前邮件详情
|
||||||
if (currentEmail.value) {
|
if (currentEmail.value) {
|
||||||
const emailId = currentEmail.value.id
|
const emailId = currentEmail.value.id
|
||||||
getEmailDetail(emailId).then(response => {
|
getEmailDetail(emailId).then((response) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
currentEmail.value = response.data
|
currentEmail.value = response.data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(new CustomEvent('transaction-deleted', { detail: transactionId }))
|
||||||
new CustomEvent('transaction-deleted', { detail: transactionId }))
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
@@ -428,13 +480,12 @@ const handleTransactionSave = async () => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent(
|
new CustomEvent('transactions-changed', {
|
||||||
'transactions-changed',
|
|
||||||
{
|
|
||||||
detail: {
|
detail: {
|
||||||
emailId: currentEmail.value?.id
|
emailId: currentEmail.value?.id
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
@@ -442,7 +493,9 @@ const handleTransactionSave = async () => {
|
|||||||
|
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
const formatDate = (dateString) => {
|
const formatDate = (dateString) => {
|
||||||
if (!dateString) return ''
|
if (!dateString) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
return date.toLocaleString('zh-CN', {
|
return date.toLocaleString('zh-CN', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@@ -454,8 +507,6 @@ const formatDate = (dateString) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadData(true)
|
loadData(true)
|
||||||
})
|
})
|
||||||
@@ -467,7 +518,6 @@ defineExpose({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
:deep(.van-pull-refresh) {
|
:deep(.van-pull-refresh) {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@@ -487,7 +537,7 @@ defineExpose({
|
|||||||
|
|
||||||
.email-date {
|
.email-date {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,12 +563,12 @@ defineExpose({
|
|||||||
margin: 0 20px;
|
margin: 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.content-body {
|
.content-body {
|
||||||
background-color: #2c2c2c;
|
background-color: var(--van-background-2);
|
||||||
border: 1px solid #3a3a3a;
|
border: 1px solid var(--van-border-color);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
.delete-button {
|
.delete-button {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -20,16 +20,31 @@
|
|||||||
|
|
||||||
<div class="filter-row">
|
<div class="filter-row">
|
||||||
<van-dropdown-menu>
|
<van-dropdown-menu>
|
||||||
<van-dropdown-item v-model="selectedLevel" :options="levelOptions" @change="handleSearch" />
|
<van-dropdown-item
|
||||||
<van-dropdown-item v-model="selectedDate" :options="dateOptions" @change="handleSearch" />
|
v-model="selectedLevel"
|
||||||
|
:options="levelOptions"
|
||||||
|
@change="handleSearch"
|
||||||
|
/>
|
||||||
|
<van-dropdown-item
|
||||||
|
v-model="selectedDate"
|
||||||
|
:options="dateOptions"
|
||||||
|
@change="handleSearch"
|
||||||
|
/>
|
||||||
</van-dropdown-menu>
|
</van-dropdown-menu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 下拉刷新区域 -->
|
<!-- 下拉刷新区域 -->
|
||||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
<van-pull-refresh
|
||||||
|
v-model="refreshing"
|
||||||
|
@refresh="onRefresh"
|
||||||
|
>
|
||||||
<!-- 加载提示 -->
|
<!-- 加载提示 -->
|
||||||
<van-loading v-if="loading && !logList.length" vertical style="padding: 50px 0">
|
<van-loading
|
||||||
|
v-if="loading && !logList.length"
|
||||||
|
vertical
|
||||||
|
style="padding: 50px 0"
|
||||||
|
>
|
||||||
加载中...
|
加载中...
|
||||||
</van-loading>
|
</van-loading>
|
||||||
|
|
||||||
@@ -51,7 +66,9 @@
|
|||||||
<span class="log-level">{{ log.level }}</span>
|
<span class="log-level">{{ log.level }}</span>
|
||||||
<span class="log-time">{{ formatTime(log.timestamp) }}</span>
|
<span class="log-time">{{ formatTime(log.timestamp) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="log-message">{{ log.message }}</div>
|
<div class="log-message">
|
||||||
|
{{ log.message }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 空状态 -->
|
<!-- 空状态 -->
|
||||||
@@ -63,7 +80,7 @@
|
|||||||
</van-list>
|
</van-list>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: 20px"></div>
|
<div style="height: 20px" />
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,9 +123,7 @@ const levelOptions = ref([
|
|||||||
])
|
])
|
||||||
|
|
||||||
// 日期选项
|
// 日期选项
|
||||||
const dateOptions = ref([
|
const dateOptions = ref([{ text: '全部日期', value: '' }])
|
||||||
{ text: '全部日期', value: '' }
|
|
||||||
])
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回上一页
|
* 返回上一页
|
||||||
@@ -122,12 +137,12 @@ const handleBack = () => {
|
|||||||
*/
|
*/
|
||||||
const getLevelClass = (level) => {
|
const getLevelClass = (level) => {
|
||||||
const levelMap = {
|
const levelMap = {
|
||||||
'ERR': 'level-error',
|
ERR: 'level-error',
|
||||||
'FTL': 'level-fatal',
|
FTL: 'level-fatal',
|
||||||
'WRN': 'level-warning',
|
WRN: 'level-warning',
|
||||||
'INF': 'level-info',
|
INF: 'level-info',
|
||||||
'DBG': 'level-debug',
|
DBG: 'level-debug',
|
||||||
'VRB': 'level-verbose'
|
VRB: 'level-verbose'
|
||||||
}
|
}
|
||||||
return levelMap[level] || 'level-default'
|
return levelMap[level] || 'level-default'
|
||||||
}
|
}
|
||||||
@@ -145,7 +160,9 @@ const formatTime = (timestamp) => {
|
|||||||
* 加载日志数据
|
* 加载日志数据
|
||||||
*/
|
*/
|
||||||
const loadLogs = async (reset = false) => {
|
const loadLogs = async (reset = false) => {
|
||||||
if (fetching.value) return
|
if (fetching.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fetching.value = true
|
fetching.value = true
|
||||||
|
|
||||||
@@ -223,7 +240,9 @@ const onRefresh = async () => {
|
|||||||
* 加载更多
|
* 加载更多
|
||||||
*/
|
*/
|
||||||
const onLoad = async () => {
|
const onLoad = async () => {
|
||||||
if (finished.value || fetching.value) return
|
if (finished.value || fetching.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是第一次加载
|
// 如果是第一次加载
|
||||||
if (pageIndex.value === 1 && logList.value.length === 0) {
|
if (pageIndex.value === 1 && logList.value.length === 0) {
|
||||||
@@ -257,14 +276,11 @@ const loadAvailableDates = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await getAvailableDates()
|
const response = await getAvailableDates()
|
||||||
if (response.success && response.data) {
|
if (response.success && response.data) {
|
||||||
const dates = response.data.map(date => ({
|
const dates = response.data.map((date) => ({
|
||||||
text: formatDate(date),
|
text: formatDate(date),
|
||||||
value: date
|
value: date
|
||||||
}))
|
}))
|
||||||
dateOptions.value = [
|
dateOptions.value = [{ text: '全部日期', value: '' }, ...dates]
|
||||||
{ text: '全部日期', value: '' },
|
|
||||||
...dates
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载日期列表失败:', error)
|
console.error('加载日期列表失败:', error)
|
||||||
@@ -292,27 +308,27 @@ onMounted(() => {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
.log-view {
|
.log-view {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
background-color: #f5f5f5;
|
background-color: var(--van-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.log-view {
|
.log-view {
|
||||||
background-color: #1a1a1a;
|
background-color: #1a1a1a;
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
.filter-section {
|
.filter-section {
|
||||||
background-color: #ffffff;
|
background-color: var(--van-background-2);
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.filter-section {
|
.filter-section {
|
||||||
background-color: #2c2c2c;
|
background-color: #2c2c2c;
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
.filter-row {
|
.filter-row {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -323,8 +339,8 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.log-item {
|
.log-item {
|
||||||
background-color: #ffffff;
|
background-color: var(--van-background-2);
|
||||||
border-left: 3px solid #1989fa;
|
border-left: 3px solid var(--van-primary-color);
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@@ -338,7 +354,7 @@ onMounted(() => {
|
|||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
.log-item {
|
.log-item {
|
||||||
background-color: #2c2c2c;
|
background-color: #2c2c2c;
|
||||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
|
||||||
@@ -347,7 +363,7 @@ onMounted(() => {
|
|||||||
.log-item:hover {
|
.log-item:hover {
|
||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
.log-header {
|
.log-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -398,20 +414,20 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.level-debug .log-level {
|
.level-debug .log-level {
|
||||||
background-color: #1989fa;
|
background-color: var(--van-primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-info .log-level {
|
.level-info .log-level {
|
||||||
background-color: #07c160;
|
background-color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-warning .log-level {
|
.level-warning .log-level {
|
||||||
background-color: #ff976a;
|
background-color: var(--van-orange);
|
||||||
border-left-color: #ff976a;
|
border-left-color: var(--van-orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-error .log-level {
|
.level-error .log-level {
|
||||||
background-color: #ee0a24;
|
background-color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-fatal .log-level {
|
.level-fatal .log-level {
|
||||||
@@ -419,7 +435,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.level-default .log-level {
|
.level-default .log-level {
|
||||||
background-color: #646566;
|
background-color: var(--van-gray-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-verbose {
|
.level-verbose {
|
||||||
@@ -427,19 +443,19 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.level-debug {
|
.level-debug {
|
||||||
border-left-color: #1989fa;
|
border-left-color: var(--van-primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-info {
|
.level-info {
|
||||||
border-left-color: #07c160;
|
border-left-color: var(--van-success-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-warning {
|
.level-warning {
|
||||||
border-left-color: #ff976a;
|
border-left-color: var(--van-orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-error {
|
.level-error {
|
||||||
border-left-color: #ee0a24;
|
border-left-color: var(--van-danger-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level-fatal {
|
.level-fatal {
|
||||||
@@ -447,7 +463,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.level-default {
|
.level-default {
|
||||||
border-left-color: #646566;
|
border-left-color: var(--van-gray-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 优化下拉菜单样式 */
|
/* 优化下拉菜单样式 */
|
||||||
@@ -455,9 +471,9 @@ onMounted(() => {
|
|||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
/* @media (prefers-color-scheme: dark) {
|
||||||
:deep(.van-dropdown-menu) {
|
:deep(.van-dropdown-menu) {
|
||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,18 +1,34 @@
|
|||||||
<!-- eslint-disable vue/no-v-html -->
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex">
|
<div class="page-container-flex">
|
||||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
<van-pull-refresh
|
||||||
|
v-model="refreshing"
|
||||||
|
@refresh="onRefresh"
|
||||||
|
>
|
||||||
<van-list
|
<van-list
|
||||||
v-model:loading="loading"
|
v-model:loading="loading"
|
||||||
:finished="finished"
|
:finished="finished"
|
||||||
finished-text="没有更多了"
|
finished-text="没有更多了"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
>
|
>
|
||||||
<van-cell-group v-if="list.length" inset style="margin-top: 10px">
|
<van-cell-group
|
||||||
<van-swipe-cell v-for="item in list" :key="item.id">
|
v-if="list.length"
|
||||||
<div class="message-card" @click="viewDetail(item)">
|
inset
|
||||||
|
style="margin-top: 10px"
|
||||||
|
>
|
||||||
|
<van-swipe-cell
|
||||||
|
v-for="item in list"
|
||||||
|
:key="item.id"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="message-card"
|
||||||
|
@click="viewDetail(item)"
|
||||||
|
>
|
||||||
<div class="card-left">
|
<div class="card-left">
|
||||||
<div class="message-title" :class="{ 'unread': !item.isRead }">
|
<div
|
||||||
|
class="message-title"
|
||||||
|
:class="{ unread: !item.isRead }"
|
||||||
|
>
|
||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</div>
|
</div>
|
||||||
<div class="message-content">
|
<div class="message-content">
|
||||||
@@ -23,16 +39,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-right">
|
<div class="card-right">
|
||||||
<van-tag v-if="!item.isRead" type="danger">未读</van-tag>
|
<van-tag
|
||||||
<van-icon name="arrow" size="16" class="arrow-icon" />
|
v-if="!item.isRead"
|
||||||
|
type="danger"
|
||||||
|
>
|
||||||
|
未读
|
||||||
|
</van-tag>
|
||||||
|
<van-icon
|
||||||
|
name="arrow"
|
||||||
|
size="16"
|
||||||
|
class="arrow-icon"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template #right>
|
<template #right>
|
||||||
<van-button square text="删除" type="danger" class="delete-button" @click="handleDelete(item)" />
|
<van-button
|
||||||
|
square
|
||||||
|
text="删除"
|
||||||
|
type="danger"
|
||||||
|
class="delete-button"
|
||||||
|
@click="handleDelete(item)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</van-swipe-cell>
|
</van-swipe-cell>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
<van-empty v-else-if="!loading" description="暂无消息" />
|
<van-empty
|
||||||
|
v-else-if="!loading"
|
||||||
|
description="暂无消息"
|
||||||
|
/>
|
||||||
</van-list>
|
</van-list>
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
|
|
||||||
@@ -47,13 +81,23 @@
|
|||||||
v-if="currentMessage.messageType === 2"
|
v-if="currentMessage.messageType === 2"
|
||||||
class="detail-content rich-html-content"
|
class="detail-content rich-html-content"
|
||||||
v-html="currentMessage.content"
|
v-html="currentMessage.content"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="detail-content"
|
||||||
>
|
>
|
||||||
</div>
|
|
||||||
<div v-else class="detail-content">
|
|
||||||
{{ currentMessage.content }}
|
{{ currentMessage.content }}
|
||||||
</div>
|
</div>
|
||||||
<template v-if="currentMessage.url && currentMessage.messageType === 1" #footer>
|
<template
|
||||||
<van-button type="primary" block round @click="handleUrlJump(currentMessage.url)">
|
v-if="currentMessage.url && currentMessage.messageType === 1"
|
||||||
|
#footer
|
||||||
|
>
|
||||||
|
<van-button
|
||||||
|
type="primary"
|
||||||
|
block
|
||||||
|
round
|
||||||
|
@click="handleUrlJump(currentMessage.url)"
|
||||||
|
>
|
||||||
查看详情
|
查看详情
|
||||||
</van-button>
|
</van-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -62,164 +106,166 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router'
|
||||||
import { showToast, showDialog } from 'vant';
|
import { showToast, showDialog } from 'vant'
|
||||||
import { getMessageList, markAsRead, deleteMessage, markAllAsRead } from '@/api/message';
|
import { getMessageList, markAsRead, deleteMessage, markAllAsRead } from '@/api/message'
|
||||||
import { useMessageStore } from '@/stores/message';
|
import { useMessageStore } from '@/stores/message'
|
||||||
import PopupContainer from '@/components/PopupContainer.vue';
|
import PopupContainer from '@/components/PopupContainer.vue'
|
||||||
|
|
||||||
const messageStore = useMessageStore();
|
const messageStore = useMessageStore()
|
||||||
const router = useRouter();
|
const router = useRouter()
|
||||||
const list = ref([]);
|
const list = ref([])
|
||||||
const loading = ref(false);
|
const loading = ref(false)
|
||||||
const finished = ref(false);
|
const finished = ref(false)
|
||||||
const refreshing = ref(false);
|
const refreshing = ref(false)
|
||||||
const pageIndex = ref(1);
|
const pageIndex = ref(1)
|
||||||
const pageSize = ref(20);
|
const pageSize = ref(20)
|
||||||
|
|
||||||
const detailVisible = ref(false);
|
const detailVisible = ref(false)
|
||||||
const currentMessage = ref({});
|
const currentMessage = ref({})
|
||||||
|
|
||||||
const onLoad = async () => {
|
const onLoad = async () => {
|
||||||
if (refreshing.value) {
|
if (refreshing.value) {
|
||||||
list.value = [];
|
list.value = []
|
||||||
pageIndex.value = 1;
|
pageIndex.value = 1
|
||||||
refreshing.value = false;
|
refreshing.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getMessageList({
|
const res = await getMessageList({
|
||||||
pageIndex: pageIndex.value,
|
pageIndex: pageIndex.value,
|
||||||
pageSize: pageSize.value
|
pageSize: pageSize.value
|
||||||
});
|
})
|
||||||
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
// 格式化时间
|
// 格式化时间
|
||||||
const data = res.data.map(item => ({
|
const data = res.data.map((item) => ({
|
||||||
...item,
|
...item,
|
||||||
createTime: new Date(item.createTime).toLocaleString()
|
createTime: new Date(item.createTime).toLocaleString()
|
||||||
}));
|
}))
|
||||||
|
|
||||||
if (pageIndex.value === 1) {
|
if (pageIndex.value === 1) {
|
||||||
list.value = data;
|
list.value = data
|
||||||
} else {
|
} else {
|
||||||
list.value = [...list.value, ...data];
|
list.value = [...list.value, ...data]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否加载完成
|
// 判断是否加载完成
|
||||||
if (list.value.length >= res.total || data.length < pageSize.value) {
|
if (list.value.length >= res.total || data.length < pageSize.value) {
|
||||||
finished.value = true;
|
finished.value = true
|
||||||
} else {
|
} else {
|
||||||
pageIndex.value++;
|
pageIndex.value++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showToast(res.message || '加载失败');
|
showToast(res.message || '加载失败')
|
||||||
finished.value = true;
|
finished.value = true
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
showToast('加载失败');
|
showToast('加载失败')
|
||||||
finished.value = true;
|
finished.value = true
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const onRefresh = () => {
|
const onRefresh = () => {
|
||||||
finished.value = false;
|
finished.value = false
|
||||||
loading.value = true;
|
loading.value = true
|
||||||
onLoad();
|
onLoad()
|
||||||
};
|
}
|
||||||
|
|
||||||
const viewDetail = async (item) => {
|
const viewDetail = async (item) => {
|
||||||
if (!item.isRead) {
|
if (!item.isRead) {
|
||||||
try {
|
try {
|
||||||
await markAsRead(item.id);
|
await markAsRead(item.id)
|
||||||
item.isRead = true;
|
item.isRead = true
|
||||||
messageStore.updateUnreadCount();
|
messageStore.updateUnreadCount()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('标记已读失败', error);
|
console.error('标记已读失败', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentMessage.value = item;
|
currentMessage.value = item
|
||||||
detailVisible.value = true;
|
detailVisible.value = true
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleUrlJump = (targetUrl) => {
|
const handleUrlJump = (targetUrl) => {
|
||||||
if (!targetUrl) return;
|
if (!targetUrl) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (targetUrl.startsWith('http')) {
|
if (targetUrl.startsWith('http')) {
|
||||||
window.open(targetUrl, '_blank');
|
window.open(targetUrl, '_blank')
|
||||||
} else if (targetUrl.startsWith('/')) {
|
} else if (targetUrl.startsWith('/')) {
|
||||||
router.push(targetUrl);
|
router.push(targetUrl)
|
||||||
detailVisible.value = false;
|
detailVisible.value = false
|
||||||
} else {
|
} else {
|
||||||
showToast('无效的URL');
|
showToast('无效的URL')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleDelete = (item) => {
|
const handleDelete = (item) => {
|
||||||
showDialog({
|
showDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要删除这条消息吗?',
|
message: '确定要删除这条消息吗?',
|
||||||
showCancelButton: true,
|
showCancelButton: true
|
||||||
}).then(async (action) => {
|
}).then(async (action) => {
|
||||||
if (action === 'confirm') {
|
if (action === 'confirm') {
|
||||||
try {
|
try {
|
||||||
const res = await deleteMessage(item.id);
|
const res = await deleteMessage(item.id)
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
showToast('删除成功');
|
showToast('删除成功')
|
||||||
const wasUnread = !item.isRead;
|
const wasUnread = !item.isRead
|
||||||
list.value = list.value.filter(i => i.id !== item.id);
|
list.value = list.value.filter((i) => i.id !== item.id)
|
||||||
if (wasUnread) {
|
if (wasUnread) {
|
||||||
messageStore.updateUnreadCount();
|
messageStore.updateUnreadCount()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showToast(res.message || '删除失败');
|
showToast(res.message || '删除失败')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除消息失败', error);
|
console.error('删除消息失败', error)
|
||||||
showToast('删除失败');
|
showToast('删除失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleMarkAllRead = () => {
|
const handleMarkAllRead = () => {
|
||||||
showDialog({
|
showDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要将所有消息标记为已读吗?',
|
message: '确定要将所有消息标记为已读吗?',
|
||||||
showCancelButton: true,
|
showCancelButton: true
|
||||||
}).then(async (action) => {
|
}).then(async (action) => {
|
||||||
if (action === 'confirm') {
|
if (action === 'confirm') {
|
||||||
try {
|
try {
|
||||||
const res = await markAllAsRead();
|
const res = await markAllAsRead()
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
showToast('操作成功');
|
showToast('操作成功')
|
||||||
// 刷新列表
|
// 刷新列表
|
||||||
onRefresh();
|
onRefresh()
|
||||||
// 更新未读计数
|
// 更新未读计数
|
||||||
messageStore.updateUnreadCount();
|
messageStore.updateUnreadCount()
|
||||||
} else {
|
} else {
|
||||||
showToast(res.message || '操作失败');
|
showToast(res.message || '操作失败')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('标记所有已读失败', error);
|
console.error('标记所有已读失败', error)
|
||||||
showToast('操作失败');
|
showToast('操作失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// onLoad 会由 van-list 自动触发
|
// onLoad 会由 van-list 自动触发
|
||||||
});
|
})
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
handleMarkAllRead
|
handleMarkAllRead
|
||||||
});
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -36,7 +36,10 @@
|
|||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell title="分类" :value="item.classify || '未分类'" />
|
<van-cell title="分类" :value="item.classify || '未分类'" />
|
||||||
<van-cell title="下次执行时间" :value="formatDateTime(item.nextExecuteTime) || '未设置'" />
|
<van-cell
|
||||||
|
title="下次执行时间"
|
||||||
|
:value="formatDateTime(item.nextExecuteTime) || '未设置'"
|
||||||
|
/>
|
||||||
<van-cell title="状态">
|
<van-cell title="状态">
|
||||||
<template #value>
|
<template #value>
|
||||||
<van-switch
|
<van-switch
|
||||||
@@ -69,18 +72,12 @@
|
|||||||
</van-list>
|
</van-list>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
|
|
||||||
<!-- 底部新增按钮 -->
|
<!-- 底部新增按钮 -->
|
||||||
<div class="bottom-button">
|
<div class="bottom-button">
|
||||||
<van-button
|
<van-button type="primary" size="large" round icon="plus" @click="openAddDialog">
|
||||||
type="primary"
|
|
||||||
size="large"
|
|
||||||
round
|
|
||||||
icon="plus"
|
|
||||||
@click="openAddDialog"
|
|
||||||
>
|
|
||||||
新增周期账单
|
新增周期账单
|
||||||
</van-button>
|
</van-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -173,11 +170,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
:rules="[{ required: true, message: '请输入金额' }]"
|
:rules="[{ required: true, message: '请输入金额' }]"
|
||||||
/>
|
/>
|
||||||
<van-field
|
<van-field v-model="form.type" name="type" label="类型">
|
||||||
v-model="form.type"
|
|
||||||
name="type"
|
|
||||||
label="类型"
|
|
||||||
>
|
|
||||||
<template #input>
|
<template #input>
|
||||||
<van-radio-group v-model="form.type" direction="horizontal">
|
<van-radio-group v-model="form.type" direction="horizontal">
|
||||||
<van-radio :name="0"> 支出 </van-radio>
|
<van-radio :name="0"> 支出 </van-radio>
|
||||||
@@ -188,16 +181,13 @@
|
|||||||
</van-field>
|
</van-field>
|
||||||
<van-field name="classify" label="分类">
|
<van-field name="classify" label="分类">
|
||||||
<template #input>
|
<template #input>
|
||||||
<span v-if="!form.classify" style="color: #c8c9cc;">请选择交易分类</span>
|
<span v-if="!form.classify" style="color: var(--van-gray-5)">请选择交易分类</span>
|
||||||
<span v-else>{{ form.classify }}</span>
|
<span v-else>{{ form.classify }}</span>
|
||||||
</template>
|
</template>
|
||||||
</van-field>
|
</van-field>
|
||||||
|
|
||||||
<!-- 分类选择组件 -->
|
<!-- 分类选择组件 -->
|
||||||
<ClassifySelector
|
<ClassifySelector v-model="form.classify" :type="form.type" />
|
||||||
v-model="form.classify"
|
|
||||||
:type="form.type"
|
|
||||||
/>
|
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
</van-form>
|
</van-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -392,18 +382,20 @@ const getPeriodicTypeText = (item) => {
|
|||||||
|
|
||||||
if (item.periodicConfig) {
|
if (item.periodicConfig) {
|
||||||
switch (item.periodicType) {
|
switch (item.periodicType) {
|
||||||
case 1: // 每周
|
case 1: {
|
||||||
{
|
// 每周
|
||||||
const weekdays = item.periodicConfig.split(',').map(
|
const weekdays = item.periodicConfig
|
||||||
d => {
|
.split(',')
|
||||||
|
.map((d) => {
|
||||||
const dayMap = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
const dayMap = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||||
return dayMap[parseInt(d)] || ''
|
return dayMap[parseInt(d)] || ''
|
||||||
}).join('、')
|
})
|
||||||
|
.join('、')
|
||||||
text += ` (${weekdays})`
|
text += ` (${weekdays})`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 2: // 每月
|
case 2: {
|
||||||
{
|
// 每月
|
||||||
const days = item.periodicConfig.split(',').join('、')
|
const days = item.periodicConfig.split(',').join('、')
|
||||||
text += ` (${days}日)`
|
text += ` (${days}日)`
|
||||||
break
|
break
|
||||||
@@ -436,20 +428,22 @@ const editPeriodic = (item) => {
|
|||||||
form.type = item.type
|
form.type = item.type
|
||||||
form.classify = item.classify
|
form.classify = item.classify
|
||||||
form.periodicType = item.periodicType
|
form.periodicType = item.periodicType
|
||||||
form.periodicTypeText = periodicTypeColumns.find(t => t.value === item.periodicType)?.text || ''
|
form.periodicTypeText = periodicTypeColumns.find((t) => t.value === item.periodicType)?.text || ''
|
||||||
|
|
||||||
// 解析周期配置
|
// 解析周期配置
|
||||||
if (item.periodicConfig) {
|
if (item.periodicConfig) {
|
||||||
switch (item.periodicType) {
|
switch (item.periodicType) {
|
||||||
case 1: // 每周
|
case 1: // 每周
|
||||||
form.weekdays = item.periodicConfig.split(',').map(d => parseInt(d))
|
form.weekdays = item.periodicConfig.split(',').map((d) => parseInt(d))
|
||||||
form.weekdaysText = form.weekdays.map(d => {
|
form.weekdaysText = form.weekdays
|
||||||
return weekdaysColumns.find(w => w.value === d)?.text || ''
|
.map((d) => {
|
||||||
}).join('、')
|
return weekdaysColumns.find((w) => w.value === d)?.text || ''
|
||||||
|
})
|
||||||
|
.join('、')
|
||||||
break
|
break
|
||||||
case 2: // 每月
|
case 2: // 每月
|
||||||
form.monthDays = item.periodicConfig.split(',').map(d => parseInt(d))
|
form.monthDays = item.periodicConfig.split(',').map((d) => parseInt(d))
|
||||||
form.monthDaysText = form.monthDays.map(d => `${d}日`).join('、')
|
form.monthDaysText = form.monthDays.map((d) => `${d}日`).join('、')
|
||||||
break
|
break
|
||||||
case 3: // 每季度
|
case 3: // 每季度
|
||||||
form.quarterDay = item.periodicConfig
|
form.quarterDay = item.periodicConfig
|
||||||
@@ -468,7 +462,7 @@ const deletePeriodic = async (item) => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要删除这条周期性账单吗?',
|
message: '确定要删除这条周期性账单吗?'
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await deletePeriodicApi(item.id)
|
const response = await deletePeriodicApi(item.id)
|
||||||
@@ -493,7 +487,7 @@ const toggleEnabled = async (id, enabled) => {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
showToast(enabled ? '已启用' : '已禁用')
|
showToast(enabled ? '已启用' : '已禁用')
|
||||||
// 更新本地数据
|
// 更新本地数据
|
||||||
const item = periodicList.value.find(p => p.id === id)
|
const item = periodicList.value.find((p) => p.id === id)
|
||||||
if (item) {
|
if (item) {
|
||||||
item.isEnabled = enabled
|
item.isEnabled = enabled
|
||||||
}
|
}
|
||||||
@@ -510,7 +504,9 @@ const toggleEnabled = async (id, enabled) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatDateTime = (date) => {
|
const formatDateTime = (date) => {
|
||||||
if (!date) return ''
|
if (!date) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
return dayjs(date).format('YYYY-MM-DD HH:mm:ss')
|
return dayjs(date).format('YYYY-MM-DD HH:mm:ss')
|
||||||
}
|
}
|
||||||
@@ -557,7 +553,6 @@ const onMonthDaysConfirm = ({ selectedValues, selectedOptions }) => {
|
|||||||
form.monthDaysText = selectedOptions[0].text
|
form.monthDaysText = selectedOptions[0].text
|
||||||
showMonthDaysPicker.value = false
|
showMonthDaysPicker.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -596,4 +591,7 @@ const onMonthDaysConfirm = ({ selectedValues, selectedOptions }) => {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.van-nav-bar) {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,19 +1,40 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex">
|
<div class="page-container-flex">
|
||||||
<van-nav-bar title="定时任务" left-arrow placeholder @click-left="onClickLeft" />
|
<van-nav-bar
|
||||||
|
title="定时任务"
|
||||||
|
left-arrow
|
||||||
|
placeholder
|
||||||
|
@click-left="onClickLeft"
|
||||||
|
/>
|
||||||
<div class="scroll-content">
|
<div class="scroll-content">
|
||||||
<van-pull-refresh v-model="loading" @refresh="fetchTasks">
|
<van-pull-refresh
|
||||||
<div v-for="task in tasks" :key="task.name" class="task-card">
|
v-model="loading"
|
||||||
|
@refresh="fetchTasks"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="task in tasks"
|
||||||
|
:key="task.name"
|
||||||
|
class="task-card"
|
||||||
|
>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell :title="task.jobDescription" :label="task.triggerDescription || task.name">
|
<van-cell
|
||||||
|
:title="task.jobDescription"
|
||||||
|
:label="task.triggerDescription || task.name"
|
||||||
|
>
|
||||||
<template #value>
|
<template #value>
|
||||||
<van-tag :type="task.status === 'Paused' ? 'warning' : 'success'">
|
<van-tag :type="task.status === 'Paused' ? 'warning' : 'success'">
|
||||||
{{ task.status === 'Paused' ? '已暂停' : '已启动' }}
|
{{ task.status === 'Paused' ? '已暂停' : '已启动' }}
|
||||||
</van-tag>
|
</van-tag>
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell title="任务标识" :value="task.name" />
|
<van-cell
|
||||||
<van-cell title="下次执行" :value="task.nextRunTime || '无'" />
|
title="任务标识"
|
||||||
|
:value="task.name"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="下次执行"
|
||||||
|
:value="task.nextRunTime || '无'"
|
||||||
|
/>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<van-row gutter="10">
|
<van-row gutter="10">
|
||||||
<van-col span="12">
|
<van-col span="12">
|
||||||
@@ -55,10 +76,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
|
|
||||||
<van-empty v-if="tasks.length === 0 && !loading" description="无定时任务" />
|
<van-empty
|
||||||
|
v-if="tasks.length === 0 && !loading"
|
||||||
|
description="无定时任务"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(20px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(20px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -102,7 +126,7 @@ const handleExecute = async (task) => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '确认执行',
|
title: '确认执行',
|
||||||
message: `确定要立即执行"${task.jobDescription}"吗?`,
|
message: `确定要立即执行"${task.jobDescription}"吗?`
|
||||||
})
|
})
|
||||||
|
|
||||||
showLoadingToast({
|
showLoadingToast({
|
||||||
@@ -132,7 +156,7 @@ const handlePause = async (task) => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '确认暂停',
|
title: '确认暂停',
|
||||||
message: `确定要暂停"${task.jobDescription}"吗?`,
|
message: `确定要暂停"${task.jobDescription}"吗?`
|
||||||
})
|
})
|
||||||
|
|
||||||
const { success, message } = await pauseJob(task.name)
|
const { success, message } = await pauseJob(task.name)
|
||||||
@@ -179,4 +203,9 @@ const handleResume = async (task) => {
|
|||||||
.scroll-content {
|
.scroll-content {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 设置页面容器背景色 */
|
||||||
|
:deep(.van-nav-bar) {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,59 +1,137 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container-flex">
|
<div class="page-container-flex">
|
||||||
<van-nav-bar title="设置" placeholder/>
|
<van-nav-bar
|
||||||
|
title="设置"
|
||||||
|
placeholder
|
||||||
|
/>
|
||||||
<div class="scroll-content">
|
<div class="scroll-content">
|
||||||
<div class="detail-header" style="padding-bottom: 5px;">
|
<div
|
||||||
|
class="detail-header"
|
||||||
|
style="padding-bottom: 5px"
|
||||||
|
>
|
||||||
<p>账单</p>
|
<p>账单</p>
|
||||||
</div>
|
</div>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="从支付宝导入" is-link @click="handleImportClick('Alipay')" />
|
<van-cell
|
||||||
<van-cell title="从微信导入" is-link @click="handleImportClick('WeChat')" />
|
title="从支付宝导入"
|
||||||
<van-cell title="周期记录" is-link @click="handlePeriodicRecord" />
|
is-link
|
||||||
|
@click="handleImportClick('Alipay')"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="从微信导入"
|
||||||
|
is-link
|
||||||
|
@click="handleImportClick('WeChat')"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="周期记录"
|
||||||
|
is-link
|
||||||
|
@click="handlePeriodicRecord"
|
||||||
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<!-- 隐藏的文件选择器 -->
|
<!-- 隐藏的文件选择器 -->
|
||||||
<input ref="fileInputRef" type="file" accept=".csv,.xlsx,.xls" style="display: none" @change="handleFileChange" />
|
<input
|
||||||
|
ref="fileInputRef"
|
||||||
|
type="file"
|
||||||
|
accept=".csv,.xlsx,.xls"
|
||||||
|
style="display: none"
|
||||||
|
@change="handleFileChange"
|
||||||
|
>
|
||||||
|
|
||||||
<div class="detail-header" style="padding-bottom: 5px;">
|
<div
|
||||||
|
class="detail-header"
|
||||||
|
style="padding-bottom: 5px"
|
||||||
|
>
|
||||||
<p>分类</p>
|
<p>分类</p>
|
||||||
</div>
|
</div>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="待确认分类" is-link @click="handleUnconfirmedClassification" />
|
<van-cell
|
||||||
<van-cell title="编辑分类" is-link @click="handleEditClassification" />
|
title="待确认分类"
|
||||||
<van-cell title="批量分类" is-link @click="handleBatchClassification" />
|
is-link
|
||||||
<van-cell title="智能分类" is-link @click="handleSmartClassification" />
|
@click="handleUnconfirmedClassification"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="编辑分类"
|
||||||
|
is-link
|
||||||
|
@click="handleEditClassification"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="批量分类"
|
||||||
|
is-link
|
||||||
|
@click="handleBatchClassification"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="智能分类"
|
||||||
|
is-link
|
||||||
|
@click="handleSmartClassification"
|
||||||
|
/>
|
||||||
<!-- <van-cell title="自然语言分类" is-link @click="handleNaturalLanguageClassification" /> -->
|
<!-- <van-cell title="自然语言分类" is-link @click="handleNaturalLanguageClassification" /> -->
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<div class="detail-header" style="padding-bottom: 5px;">
|
<div
|
||||||
|
class="detail-header"
|
||||||
|
style="padding-bottom: 5px"
|
||||||
|
>
|
||||||
<p>通知</p>
|
<p>通知</p>
|
||||||
</div>
|
</div>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="开启消息通知">
|
<van-cell title="开启消息通知">
|
||||||
<template #right-icon>
|
<template #right-icon>
|
||||||
<van-switch v-model="notificationEnabled" size="24" :loading="notificationLoading" @change="handleNotificationToggle" />
|
<van-switch
|
||||||
|
v-model="notificationEnabled"
|
||||||
|
size="24"
|
||||||
|
:loading="notificationLoading"
|
||||||
|
@change="handleNotificationToggle"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell v-if="notificationEnabled" title="测试通知" is-link @click="handleTestNotification" />
|
<van-cell
|
||||||
|
v-if="notificationEnabled"
|
||||||
|
title="测试通知"
|
||||||
|
is-link
|
||||||
|
@click="handleTestNotification"
|
||||||
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<div class="detail-header" style="padding-bottom: 5px;">
|
<div
|
||||||
|
class="detail-header"
|
||||||
|
style="padding-bottom: 5px"
|
||||||
|
>
|
||||||
<p>开发者</p>
|
<p>开发者</p>
|
||||||
</div>
|
</div>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="查看日志" is-link @click="handleLogView" />
|
<van-cell
|
||||||
<van-cell title="清除缓存" is-link @click="handleReloadFromNetwork" />
|
title="查看日志"
|
||||||
<van-cell title="定时任务" is-link @click="handleScheduledTasks" />
|
is-link
|
||||||
|
@click="handleLogView"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="清除缓存"
|
||||||
|
is-link
|
||||||
|
@click="handleReloadFromNetwork"
|
||||||
|
/>
|
||||||
|
<van-cell
|
||||||
|
title="定时任务"
|
||||||
|
is-link
|
||||||
|
@click="handleScheduledTasks"
|
||||||
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
|
|
||||||
<div class="detail-header" style="padding-bottom: 5px;">
|
<div
|
||||||
|
class="detail-header"
|
||||||
|
style="padding-bottom: 5px"
|
||||||
|
>
|
||||||
<p>账户</p>
|
<p>账户</p>
|
||||||
</div>
|
</div>
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell title="退出登录" is-link @click="handleLogout" />
|
<van-cell
|
||||||
|
title="退出登录"
|
||||||
|
is-link
|
||||||
|
@click="handleLogout"
|
||||||
|
/>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(80px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(80px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -83,14 +161,14 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function urlBase64ToUint8Array (base64String) {
|
function urlBase64ToUint8Array (base64String) {
|
||||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
||||||
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/')
|
||||||
const rawData = window.atob(base64);
|
const rawData = window.atob(base64)
|
||||||
const outputArray = new Uint8Array(rawData.length);
|
const outputArray = new Uint8Array(rawData.length)
|
||||||
for (let i = 0; i < rawData.length; ++i) {
|
for (let i = 0; i < rawData.length; ++i) {
|
||||||
outputArray[i] = rawData.charCodeAt(i);
|
outputArray[i] = rawData.charCodeAt(i)
|
||||||
}
|
}
|
||||||
return outputArray;
|
return outputArray
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNotificationToggle = async (checked) => {
|
const handleNotificationToggle = async (checked) => {
|
||||||
@@ -113,7 +191,7 @@ const handleNotificationToggle = async (checked) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let { success, data, message } = await getVapidPublicKey()
|
const { success, data, message } = await getVapidPublicKey()
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new Error(message || '获取 VAPID 公钥失败')
|
throw new Error(message || '获取 VAPID 公钥失败')
|
||||||
@@ -184,7 +262,11 @@ const handleFileChange = async (event) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 验证文件类型
|
// 验证文件类型
|
||||||
const validTypes = ['text/csv', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
|
const validTypes = [
|
||||||
|
'text/csv',
|
||||||
|
'application/vnd.ms-excel',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
]
|
||||||
if (!validTypes.includes(file.type)) {
|
if (!validTypes.includes(file.type)) {
|
||||||
showToast('请选择 CSV 或 Excel 文件')
|
showToast('请选择 CSV 或 Excel 文件')
|
||||||
return
|
return
|
||||||
@@ -218,8 +300,7 @@ const handleFileChange = async (event) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('上传失败:', error)
|
console.error('上传失败:', error)
|
||||||
showToast('上传失败: ' + (error.message || '未知错误'))
|
showToast('上传失败: ' + (error.message || '未知错误'))
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
closeToast()
|
closeToast()
|
||||||
// 清空文件输入,允许重复选择同一文件
|
// 清空文件输入,允许重复选择同一文件
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
@@ -249,7 +330,7 @@ const handleLogout = async () => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要退出登录吗?',
|
message: '确定要退出登录吗?'
|
||||||
})
|
})
|
||||||
|
|
||||||
authStore.logout()
|
authStore.logout()
|
||||||
@@ -276,7 +357,7 @@ const handleReloadFromNetwork = async () => {
|
|||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '确定要刷新网络吗?此操作不可撤销。',
|
message: '确定要刷新网络吗?此操作不可撤销。'
|
||||||
})
|
})
|
||||||
|
|
||||||
// PWA程序强制页面更新到最新版本
|
// PWA程序强制页面更新到最新版本
|
||||||
@@ -300,34 +381,20 @@ const handleReloadFromNetwork = async () => {
|
|||||||
const handleScheduledTasks = () => {
|
const handleScheduledTasks = () => {
|
||||||
router.push({ name: 'scheduled-tasks' })
|
router.push({ name: 'scheduled-tasks' })
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* 页面背景色 */
|
/* 页面背景色 */
|
||||||
:deep(body) {
|
:deep(body) {
|
||||||
background-color: #f5f5f5;
|
background-color: var(--van-background);
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:deep(body) {
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 增加卡片对比度 */
|
/* 增加卡片对比度 */
|
||||||
:deep(.van-cell-group--inset) {
|
:deep(.van-cell-group--inset) {
|
||||||
background-color: #ffffff;
|
background-color: var(--van-background-2);
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:deep(.van-cell-group--inset) {
|
|
||||||
background-color: #2c2c2c;
|
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-header {
|
.detail-header {
|
||||||
padding: 16px 16px 5px 16px;
|
padding: 16px 16px 5px 16px;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
@@ -336,7 +403,7 @@ const handleScheduledTasks = () => {
|
|||||||
.detail-header p {
|
.detail-header p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #969799;
|
color: var(--van-text-color-2);
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,11 @@
|
|||||||
<!-- 下拉刷新区域 -->
|
<!-- 下拉刷新区域 -->
|
||||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
||||||
<!-- 加载提示 -->
|
<!-- 加载提示 -->
|
||||||
<van-loading v-if="loading && !(transactionList && transactionList.length)" vertical style="padding: 50px 0">
|
<van-loading
|
||||||
|
v-if="loading && !(transactionList && transactionList.length)"
|
||||||
|
vertical
|
||||||
|
style="padding: 50px 0"
|
||||||
|
>
|
||||||
加载中...
|
加载中...
|
||||||
</van-loading>
|
</van-loading>
|
||||||
|
|
||||||
@@ -26,14 +30,16 @@
|
|||||||
:show-delete="true"
|
:show-delete="true"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
@click="viewDetail"
|
@click="viewDetail"
|
||||||
@delete="(id) => {
|
@delete="
|
||||||
|
(id) => {
|
||||||
// 从当前的交易列表中移除该交易
|
// 从当前的交易列表中移除该交易
|
||||||
transactionList.value = transactionList.value.filter(t => t.id !== id)
|
transactionList.value = transactionList.value.filter((t) => t.id !== id)
|
||||||
}"
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 底部安全距离 -->
|
<!-- 底部安全距离 -->
|
||||||
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))"></div>
|
<div style="height: calc(50px + env(safe-area-inset-bottom, 0px))" />
|
||||||
</van-pull-refresh>
|
</van-pull-refresh>
|
||||||
|
|
||||||
<!-- 详情/编辑弹出层 -->
|
<!-- 详情/编辑弹出层 -->
|
||||||
@@ -48,10 +54,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import { showToast } from 'vant'
|
import { showToast } from 'vant'
|
||||||
import {
|
import { getTransactionList, getTransactionDetail } from '@/api/transactionRecord'
|
||||||
getTransactionList,
|
|
||||||
getTransactionDetail
|
|
||||||
} from '@/api/transactionRecord'
|
|
||||||
import TransactionList from '@/components/TransactionList.vue'
|
import TransactionList from '@/components/TransactionList.vue'
|
||||||
import TransactionDetail from '@/components/TransactionDetail.vue'
|
import TransactionDetail from '@/components/TransactionDetail.vue'
|
||||||
|
|
||||||
@@ -69,8 +72,6 @@ const currentTransaction = ref(null)
|
|||||||
const searchKeyword = ref('')
|
const searchKeyword = ref('')
|
||||||
let searchTimer = null
|
let searchTimer = null
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 加载数据
|
// 加载数据
|
||||||
const loadData = async (isRefresh = false) => {
|
const loadData = async (isRefresh = false) => {
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
@@ -194,10 +195,12 @@ const onGlobalTransactionDeleted = () => {
|
|||||||
loadData(true)
|
loadData(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 外部新增/修改/批量更新时的刷新监听
|
// 外部新增/修改/批量更新时的刷新监听
|
||||||
@@ -208,18 +211,16 @@ const onGlobalTransactionsChanged = () => {
|
|||||||
loadData(true)
|
loadData(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.addEventListener &&
|
||||||
|
window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
window.removeEventListener &&
|
||||||
|
window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
:deep(.van-pull-refresh) {
|
:deep(.van-pull-refresh) {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@@ -230,7 +231,7 @@ onBeforeUnmount(() => {
|
|||||||
background: var(--van-background-2);
|
background: var(--van-background-2);
|
||||||
padding: 4px 12px;
|
padding: 4px 12px;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
border-bottom: 1px solid var(--van-border-color);
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-search-bar :deep(.van-search) {
|
.top-search-bar :deep(.van-search) {
|
||||||
@@ -238,8 +239,6 @@ onBeforeUnmount(() => {
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 设置页面容器背景色 */
|
/* 设置页面容器背景色 */
|
||||||
:deep(.van-nav-bar) {
|
:deep(.van-nav-bar) {
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
|
|||||||
@@ -20,8 +20,13 @@
|
|||||||
</van-nav-bar>
|
</van-nav-bar>
|
||||||
|
|
||||||
<div class="scroll-content">
|
<div class="scroll-content">
|
||||||
<div v-if="loading && transactions.length === 0" class="loading-container">
|
<div
|
||||||
<van-loading vertical>加载中...</van-loading>
|
v-if="loading && transactions.length === 0"
|
||||||
|
class="loading-container"
|
||||||
|
>
|
||||||
|
<van-loading vertical>
|
||||||
|
加载中...
|
||||||
|
</van-loading>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TransactionList
|
<TransactionList
|
||||||
@@ -92,7 +97,7 @@ const handleConfirmSelected = async () => {
|
|||||||
|
|
||||||
// 转换数据格式以适配 TransactionList 组件
|
// 转换数据格式以适配 TransactionList 组件
|
||||||
const displayTransactions = computed(() => {
|
const displayTransactions = computed(() => {
|
||||||
return transactions.value.map(t => ({
|
return transactions.value.map((t) => ({
|
||||||
...t,
|
...t,
|
||||||
upsetedClassify: t.unconfirmedClassify,
|
upsetedClassify: t.unconfirmedClassify,
|
||||||
upsetedType: t.unconfirmedType
|
upsetedType: t.unconfirmedType
|
||||||
@@ -104,13 +109,12 @@ const loadData = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await getUnconfirmedTransactionList()
|
const response = await getUnconfirmedTransactionList()
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
transactions.value = (response.data || [])
|
transactions.value = (response.data || []).map((t) => ({
|
||||||
.map(t => ({
|
|
||||||
...t,
|
...t,
|
||||||
upsetedClassify: t.unconfirmedClassify,
|
upsetedClassify: t.unconfirmedClassify,
|
||||||
upsetedType: t.unconfirmedType
|
upsetedType: t.unconfirmedType
|
||||||
}))
|
}))
|
||||||
selectedIds.value = new Set(response.data.map(t => t.id))
|
selectedIds.value = new Set(response.data.map((t) => t.id))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取待确认列表失败:', error)
|
console.error('获取待确认列表失败:', error)
|
||||||
@@ -125,7 +129,7 @@ const handleTransactionClick = (transaction) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleTransactionDeleted = (id) => {
|
const handleTransactionDeleted = (id) => {
|
||||||
transactions.value = transactions.value.filter(t => t.id !== id)
|
transactions.value = transactions.value.filter((t) => t.id !== id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateSelectedIds = (ids) => {
|
const updateSelectedIds = (ids) => {
|
||||||
@@ -159,4 +163,9 @@ onMounted(() => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 设置页面容器背景色 */
|
||||||
|
:deep(.van-nav-bar) {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export default defineConfig({
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
// 确保 Service Worker 和 manifest 被正确复制
|
// 确保 Service Worker 和 manifest 被正确复制
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ public class BudgetController(
|
|||||||
/// 获取预算列表
|
/// 获取预算列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<BaseResponse<List<BudgetResult>>> GetListAsync([FromQuery] DateTime? referenceDate = null)
|
public async Task<BaseResponse<List<BudgetResult>>> GetListAsync([FromQuery] DateTime referenceDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (await budgetService.GetListAsync(referenceDate))
|
return (await budgetService.GetListAsync(referenceDate))
|
||||||
.OrderBy(b => b.Category)
|
.OrderByDescending(b => b.IsMandatoryExpense)
|
||||||
|
.ThenBy(b => b.Category)
|
||||||
.ThenBy(b => b.Type)
|
.ThenBy(b => b.Type)
|
||||||
.ThenByDescending(b => b.Limit > 0 ? b.Current / b.Limit : 0)
|
.ThenByDescending(b => b.Limit > 0 ? b.Current / b.Limit : 0)
|
||||||
.ThenBy(b => b.Name)
|
.ThenBy(b => b.Name)
|
||||||
@@ -30,41 +31,11 @@ public class BudgetController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取单个预算统计信息
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet]
|
|
||||||
public async Task<BaseResponse<BudgetResult>> GetStatisticsAsync([FromQuery] long id, [FromQuery] DateTime referenceDate)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 参数验证
|
|
||||||
if (id == 0)
|
|
||||||
{
|
|
||||||
return "预算 Id 无效".Fail<BudgetResult>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = await budgetService.GetStatisticsAsync(id, referenceDate);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
return "预算不存在".Fail<BudgetResult>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "获取预算统计失败, Id: {Id}", id);
|
|
||||||
return $"获取预算统计失败: {ex.Message}".Fail<BudgetResult>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取分类统计信息(月度和年度)
|
/// 获取分类统计信息(月度和年度)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<BaseResponse<BudgetCategoryStats>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime? referenceDate = null)
|
public async Task<BaseResponse<BudgetCategoryStats>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime referenceDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -96,6 +67,42 @@ public class BudgetController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取归档总结
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<BaseResponse<string?>> GetArchiveSummaryAsync([FromQuery] DateTime referenceDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await budgetService.GetArchiveSummaryAsync(referenceDate.Year, referenceDate.Month);
|
||||||
|
return result.Ok<string?>();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "获取归档总结失败");
|
||||||
|
return $"获取归档总结失败: {ex.Message}".Fail<string?>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定周期的存款预算信息
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<BaseResponse<BudgetResult?>> GetSavingsBudgetAsync(int year, int month, BudgetPeriodType type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await budgetService.GetSavingsBudgetAsync(year, month, type);
|
||||||
|
return result.Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "获取存款预算信息失败");
|
||||||
|
return $"获取存款预算信息失败: {ex.Message}".Fail<BudgetResult?>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除预算
|
/// 删除预算
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -122,14 +129,19 @@ public class BudgetController(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 不记额预算的金额强制设为0
|
||||||
|
var limit = dto.NoLimit ? 0 : dto.Limit;
|
||||||
|
|
||||||
var budget = new BudgetRecord
|
var budget = new BudgetRecord
|
||||||
{
|
{
|
||||||
Name = dto.Name,
|
Name = dto.Name,
|
||||||
Type = dto.Type,
|
Type = dto.Type,
|
||||||
Limit = dto.Limit,
|
Limit = limit,
|
||||||
Category = dto.Category,
|
Category = dto.Category,
|
||||||
SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty,
|
SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty,
|
||||||
StartDate = dto.StartDate ?? DateTime.Now
|
StartDate = dto.StartDate ?? DateTime.Now,
|
||||||
|
NoLimit = dto.NoLimit,
|
||||||
|
IsMandatoryExpense = dto.IsMandatoryExpense
|
||||||
};
|
};
|
||||||
|
|
||||||
var varidationError = await ValidateBudgetSelectedCategoriesAsync(budget);
|
var varidationError = await ValidateBudgetSelectedCategoriesAsync(budget);
|
||||||
@@ -163,11 +175,16 @@ public class BudgetController(
|
|||||||
var budget = await budgetRepository.GetByIdAsync(dto.Id);
|
var budget = await budgetRepository.GetByIdAsync(dto.Id);
|
||||||
if (budget == null) return "预算不存在".Fail();
|
if (budget == null) return "预算不存在".Fail();
|
||||||
|
|
||||||
|
// 不记额预算的金额强制设为0
|
||||||
|
var limit = dto.NoLimit ? 0 : dto.Limit;
|
||||||
|
|
||||||
budget.Name = dto.Name;
|
budget.Name = dto.Name;
|
||||||
budget.Type = dto.Type;
|
budget.Type = dto.Type;
|
||||||
budget.Limit = dto.Limit;
|
budget.Limit = limit;
|
||||||
budget.Category = dto.Category;
|
budget.Category = dto.Category;
|
||||||
budget.SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty;
|
budget.SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty;
|
||||||
|
budget.NoLimit = dto.NoLimit;
|
||||||
|
budget.IsMandatoryExpense = dto.IsMandatoryExpense;
|
||||||
if (dto.StartDate.HasValue)
|
if (dto.StartDate.HasValue)
|
||||||
{
|
{
|
||||||
budget.StartDate = dto.StartDate.Value;
|
budget.StartDate = dto.StartDate.Value;
|
||||||
@@ -189,32 +206,14 @@ public class BudgetController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 归档预算
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("{year}/{month}")]
|
|
||||||
public async Task<BaseResponse> ArchiveBudgetsAsync(int year, int month)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var msg = await budgetService.ArchiveBudgetsAsync(year, month);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(msg))
|
|
||||||
{
|
|
||||||
return msg.Fail();
|
|
||||||
}
|
|
||||||
|
|
||||||
return BaseResponse.Done();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "归档预算失败, 归档日期: {Year}-{Month}", year, month);
|
|
||||||
return $"归档预算失败: {ex.Message}".Fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> ValidateBudgetSelectedCategoriesAsync(BudgetRecord record)
|
private async Task<string> ValidateBudgetSelectedCategoriesAsync(BudgetRecord record)
|
||||||
{
|
{
|
||||||
|
// 验证不记额预算必须是年度预算
|
||||||
|
if (record.NoLimit && record.Type != BudgetPeriodType.Year)
|
||||||
|
{
|
||||||
|
return "不记额预算只能设置为年度预算。";
|
||||||
|
}
|
||||||
|
|
||||||
var allBudgets = await budgetRepository.GetAllAsync();
|
var allBudgets = await budgetRepository.GetAllAsync();
|
||||||
|
|
||||||
var recordSelectedCategories = record.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
var recordSelectedCategories = record.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ public class CreateBudgetDto
|
|||||||
public BudgetCategory Category { get; set; }
|
public BudgetCategory Category { get; set; }
|
||||||
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
||||||
public DateTime? StartDate { get; set; }
|
public DateTime? StartDate { get; set; }
|
||||||
|
public bool NoLimit { get; set; } = false;
|
||||||
|
public bool IsMandatoryExpense { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpdateBudgetDto : CreateBudgetDto
|
public class UpdateBudgetDto : CreateBudgetDto
|
||||||
@@ -15,3 +17,9 @@ public class UpdateBudgetDto : CreateBudgetDto
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UpdateArchiveSummaryDto
|
||||||
|
{
|
||||||
|
public DateTime ReferenceDate { get; set; }
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace WebApi.Controllers;
|
namespace WebApi.Controllers;
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
@@ -9,8 +9,8 @@ using Repository;
|
|||||||
public class TransactionRecordController(
|
public class TransactionRecordController(
|
||||||
ITransactionRecordRepository transactionRepository,
|
ITransactionRecordRepository transactionRepository,
|
||||||
ISmartHandleService smartHandleService,
|
ISmartHandleService smartHandleService,
|
||||||
ISmartHandleServiceV2 smartHandleServiceV2,
|
ILogger<TransactionRecordController> logger,
|
||||||
ILogger<TransactionRecordController> logger
|
IConfigService configService
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -273,8 +273,17 @@ public class TransactionRecordController(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var statistics = await transactionRepository.GetDailyStatisticsAsync(year, month);
|
// 获取存款分类
|
||||||
var result = statistics.Select(s => new DailyStatisticsDto(s.Key, s.Value.count, s.Value.amount)).ToList();
|
var savingClassify = await configService.GetConfigByKeyAsync<string>("SavingsCategories");
|
||||||
|
|
||||||
|
var statistics = await transactionRepository.GetDailyStatisticsAsync(year, month, savingClassify);
|
||||||
|
var result = statistics.Select(s => new DailyStatisticsDto(
|
||||||
|
s.Key,
|
||||||
|
s.Value.count,
|
||||||
|
s.Value.expense,
|
||||||
|
s.Value.income,
|
||||||
|
s.Value.saving
|
||||||
|
)).ToList();
|
||||||
|
|
||||||
return result.Ok();
|
return result.Ok();
|
||||||
}
|
}
|
||||||
@@ -285,6 +294,45 @@ public class TransactionRecordController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定日期范围内的每日统计
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<BaseResponse<List<DailyStatisticsDto>>> GetDailyStatisticsRangeAsync(
|
||||||
|
[FromQuery] DateTime startDate,
|
||||||
|
[FromQuery] DateTime endDate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 确保包含结束日期当天
|
||||||
|
var effectiveEndDate = endDate.Date.AddDays(1);
|
||||||
|
var effectiveStartDate = startDate.Date;
|
||||||
|
|
||||||
|
// 获取存款分类
|
||||||
|
var savingClassify = await configService.GetConfigByKeyAsync<string>("SavingsCategories");
|
||||||
|
|
||||||
|
var statistics = await transactionRepository.GetDailyStatisticsByRangeAsync(
|
||||||
|
effectiveStartDate,
|
||||||
|
effectiveEndDate,
|
||||||
|
savingClassify);
|
||||||
|
var result = statistics.Select(s => new DailyStatisticsDto(
|
||||||
|
s.Key,
|
||||||
|
s.Value.count,
|
||||||
|
s.Value.expense,
|
||||||
|
s.Value.income,
|
||||||
|
s.Value.income - s.Value.expense
|
||||||
|
)).ToList();
|
||||||
|
|
||||||
|
return result.Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "获取日历统计数据失败,开始: {StartDate}, 结束: {EndDate}", startDate, endDate);
|
||||||
|
return $"获取日历统计数据失败: {ex.Message}".Fail<List<DailyStatisticsDto>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取月度统计数据
|
/// 获取月度统计数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -604,28 +652,28 @@ public class TransactionRecordController(
|
|||||||
/// 一句话录账解析
|
/// 一句话录账解析
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<BaseResponse<Service.AgentFramework.TransactionParseResult>> ParseOneLine([FromBody] ParseOneLineRequestDto request)
|
public async Task<BaseResponse<TransactionParseResult>> ParseOneLine([FromBody] ParseOneLineRequestDto request)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(request.Text))
|
if (string.IsNullOrEmpty(request.Text))
|
||||||
{
|
{
|
||||||
return "请求参数缺失:text".Fail<Service.AgentFramework.TransactionParseResult>();
|
return "请求参数缺失:text".Fail<TransactionParseResult>();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var agentResult = await smartHandleServiceV2.ParseOneLineBillAgentAsync(request.Text);
|
var result = await smartHandleService.ParseOneLineBillAsync(request.Text);
|
||||||
|
|
||||||
if (agentResult?.Data == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
return "AI解析失败".Fail<Service.AgentFramework.TransactionParseResult>();
|
return "AI解析失败".Fail<TransactionParseResult>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return agentResult.Data.Ok();
|
return result.Ok();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "一句话录账解析失败,文本: {Text}", request.Text);
|
logger.LogError(ex, "一句话录账解析失败,文本: {Text}", request.Text);
|
||||||
return ("AI解析失败: " + ex.Message).Fail<Service.AgentFramework.TransactionParseResult>();
|
return ("AI解析失败: " + ex.Message).Fail<TransactionParseResult>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,17 +735,6 @@ public class TransactionRecordController(
|
|||||||
await Response.WriteAsync(message);
|
await Response.WriteAsync(message);
|
||||||
await Response.Body.FlushAsync();
|
await Response.Body.FlushAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetTypeName(TransactionType type)
|
|
||||||
{
|
|
||||||
return type switch
|
|
||||||
{
|
|
||||||
TransactionType.Expense => "支出",
|
|
||||||
TransactionType.Income => "收入",
|
|
||||||
TransactionType.None => "不计入收支",
|
|
||||||
_ => "未知"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -729,7 +766,9 @@ public record UpdateTransactionDto(
|
|||||||
public record DailyStatisticsDto(
|
public record DailyStatisticsDto(
|
||||||
string Date,
|
string Date,
|
||||||
int Count,
|
int Count,
|
||||||
decimal Amount
|
decimal Expense,
|
||||||
|
decimal Income,
|
||||||
|
decimal Balance
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
global using Service;
|
global using Service;
|
||||||
global using Service.AgentFramework;
|
|
||||||
global using Common;
|
global using Common;
|
||||||
global using Microsoft.AspNetCore.Mvc;
|
global using Microsoft.AspNetCore.Mvc;
|
||||||
global using WebApi.Controllers.Dto;
|
global using WebApi.Controllers.Dto;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using System.Text;
|
|
||||||
using Microsoft.Agents.AI;
|
|
||||||
using FreeSql;
|
using FreeSql;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -35,10 +33,6 @@ builder.Services.AddControllers(options =>
|
|||||||
builder.Services.AddOpenApi();
|
builder.Services.AddOpenApi();
|
||||||
builder.Services.AddHttpClient();
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
// 注册 Agent Framework
|
|
||||||
builder.Services.AddAgentFramework();
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
// 配置 CORS
|
// 配置 CORS
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
@@ -49,7 +43,6 @@ builder.Services.AddCors(options =>
|
|||||||
.AllowAnyMethod();
|
.AllowAnyMethod();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
|
|
||||||
// 绑定配置
|
// 绑定配置
|
||||||
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));
|
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));
|
||||||
@@ -123,14 +116,13 @@ var fsql = new FreeSqlBuilder()
|
|||||||
)
|
)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
fsql.UseJsonMap();
|
||||||
|
|
||||||
builder.Services.AddSingleton(fsql);
|
builder.Services.AddSingleton(fsql);
|
||||||
|
|
||||||
// 自动扫描注册服务和仓储
|
// 自动扫描注册服务和仓储
|
||||||
builder.Services.AddServices();
|
builder.Services.AddServices();
|
||||||
|
|
||||||
// 注册 Agent Framework
|
|
||||||
builder.Services.AddAgentFramework();
|
|
||||||
|
|
||||||
// 注册日志清理后台服务
|
// 注册日志清理后台服务
|
||||||
builder.Services.AddHostedService<LogCleanupService>();
|
builder.Services.AddHostedService<LogCleanupService>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Agents.AI.DevUI" />
|
<PackageReference Include="FreeSql.Extensions.JsonMap" />
|
||||||
<PackageReference Include="Microsoft.Agents.AI.Hosting" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
||||||
<PackageReference Include="Scalar.AspNetCore" />
|
<PackageReference Include="Scalar.AspNetCore" />
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
# SmartHandleServiceV2 & Agent Framework 架构文档
|
|
||||||
|
|
||||||
## 1. 概述
|
|
||||||
|
|
||||||
`SmartHandleServiceV2` 是本项目中负责智能处理的核心服务,它基于 **Agent Framework** 重构,旨在通过 AI 代理(Agents)实现复杂的业务逻辑自动化。目前主要包含以下功能:
|
|
||||||
- **智能分类**:自动识别交易记录并归类。
|
|
||||||
- **单行账单解析**:从非结构化文本中提取账单信息。
|
|
||||||
|
|
||||||
## 2. 架构设计
|
|
||||||
|
|
||||||
本项目采用 **Agent 模式**,将复杂的业务流程封装为独立的 Agent,每个 Agent 继承自基类 `BaseAgent`,具备统一的执行流、日志记录、步骤追踪和错误处理能力。
|
|
||||||
|
|
||||||
### 2.1 核心组件
|
|
||||||
|
|
||||||
* **`ISmartHandleServiceV2` / `SmartHandleServiceV2`**: 服务入口,负责协调各个 Agent 的执行。它不包含具体的业务逻辑,而是作为 Facade 层调用具体的 Agent。
|
|
||||||
* **`BaseAgent` (`Service.AgentFramework`)**: Agent 的基类,提供了以下核心能力:
|
|
||||||
* **步骤记录 (`RecordStep`)**: 记录执行过程中的关键步骤,用于调试和可视化。
|
|
||||||
* **工具调用 (`CallToolAsync`)**: 统一封装工具调用,包含性能监控和异常处理。
|
|
||||||
* **结果封装 (`CreateResult`)**: 返回标准化的 `AgentResult<T>`。
|
|
||||||
* **可观测性**: 集成了 `ActivitySource` ("Microsoft.Agents.Workflows"),支持分布式追踪。
|
|
||||||
* **`AgentResult<T>`**: 标准化的返回结果,包含数据 (`Data`)、摘要 (`Summary`)、执行步骤 (`Steps`)、元数据 (`Metadata`) 和 错误信息 (`Error`)。
|
|
||||||
|
|
||||||
## 3. 详细工作流
|
|
||||||
|
|
||||||
### 3.1 智能分类 Agent (`ClassificationAgent`)
|
|
||||||
|
|
||||||
该 Agent 负责对未分类的交易记录进行批量智能分类。其执行流程 (`ExecuteAsync`) 分为四个阶段:
|
|
||||||
|
|
||||||
1. **数据采集 (Data Collection)**
|
|
||||||
* 调用 `QueryUnclassifiedRecordsAsync` 获取待分类的交易记录。
|
|
||||||
* 如果没有待分类记录,直接返回。
|
|
||||||
|
|
||||||
2. **分析阶段 (Analysis)**
|
|
||||||
* **分组**: 将交易记录按摘要 (`Reason`) 分组,计算每个组的总金额和样本类型。
|
|
||||||
* **关键词提取**: 对每个分组的摘要提取关键词。
|
|
||||||
* **相似度匹配**: 根据关键词查询历史已分类的相似记录,作为 AI 的参考依据。
|
|
||||||
|
|
||||||
3. **决策阶段 (Decision)**
|
|
||||||
* 构建 Prompt:包含分类列表 (`categoryInfo`) 和待分类的分组信息 (`billsInfo`)。
|
|
||||||
* 调用 AI (`_aiTools.ClassifyTransactionsAsync`) 进行批量分类决策。
|
|
||||||
* AI 返回 NDJSON 格式的分类结果。
|
|
||||||
|
|
||||||
4. **结果保存 (Result Saving)**
|
|
||||||
* 遍历 AI 的分类结果,更新数据库中的交易记录 (`UpdateTransactionClassifyAsync`)。
|
|
||||||
* 生成多轮执行总结。
|
|
||||||
|
|
||||||
### 3.2 单行账单解析 Agent (`ParsingAgent`)
|
|
||||||
|
|
||||||
该 Agent 负责将一段文本解析为结构化的交易记录。其执行流程 (`ExecuteAsync`) 如下:
|
|
||||||
|
|
||||||
1. **文本分析**: 分析文本结构(如分隔符、行数等)。
|
|
||||||
2. **关键词提取**: 提取文本中的关键信息(如金额、商家、日期)。
|
|
||||||
3. **AI 解析**: 调用 AI 模型将非结构化文本转换为结构化数据。
|
|
||||||
4. **结果封装**: 返回解析后的 `TransactionParseResult` 对象。
|
|
||||||
|
|
||||||
## 4. 关键类与模型
|
|
||||||
|
|
||||||
### 4.1 数据模型
|
|
||||||
|
|
||||||
* **`ClassificationResult`**: 分类结果,包含摘要、分类名称、交易类型、置信度和参考记录。
|
|
||||||
* **`TransactionParseResult`**: 解析结果,包含金额、摘要、日期、类型和分类。
|
|
||||||
* **`ExecutionStep`**: 执行步骤记录,包含步骤名、描述、状态、耗时和输出。
|
|
||||||
|
|
||||||
### 4.2 依赖服务
|
|
||||||
|
|
||||||
* `IToolRegistry`: 工具注册表,用于管理和调用各种工具。
|
|
||||||
* `ITransactionQueryTools`: 交易查询工具,用于数据库交互。
|
|
||||||
* `ITextProcessingTools`: 文本处理工具,用于关键词提取和结构分析。
|
|
||||||
* `IAITools`: AI 工具,用于与 LLM 交互。
|
|
||||||
|
|
||||||
## 5. 维护与扩展指南
|
|
||||||
|
|
||||||
### 5.1 添加新的 Agent
|
|
||||||
|
|
||||||
1. 在 `Service.AgentFramework` 目录下创建新的 Agent 类,继承自 `BaseAgent`。
|
|
||||||
2. 在构造函数中注入所需的工具和服务。
|
|
||||||
3. 实现 `ExecuteAsync` 方法,定义 Agent 的工作流。
|
|
||||||
4. 使用 `RecordStep` 记录关键步骤。
|
|
||||||
5. 在 `SmartHandleServiceV2` 中注入并调用新的 Agent。
|
|
||||||
|
|
||||||
### 5.2 调试与排错
|
|
||||||
|
|
||||||
* **查看日志**: Agent 会记录详细的执行日志,包括每个步骤的输入输出。
|
|
||||||
* **检查 `AgentResult.Steps`**: 返回结果中包含了完整的执行步骤链,可以查看每一步的状态和耗时。
|
|
||||||
* **Activity 追踪**: 利用 `ActivitySource` 可以结合 APM 工具(如 OpenTelemetry)进行链路追踪。
|
|
||||||
|
|
||||||
### 5.3 修改 AI 逻辑
|
|
||||||
|
|
||||||
* **Prompt 调整**: `ClassificationAgent` 中的 `BuildSystemPrompt` and `BuildUserPrompt` 方法定义了与 AI 的交互逻辑。修改这些 Prompt 可以调整 AI 的行为。
|
|
||||||
* **模型参数**: AI 调用的具体参数(如温度、模型版本)通常在 `IAITools` 的实现中配置。
|
|
||||||
|
|
||||||
## 6. 代码引用
|
|
||||||
|
|
||||||
* [SmartHandleServiceV2.cs](../Service/SmartHandleServiceV2.cs)
|
|
||||||
* [BaseAgent.cs](../Service/AgentFramework/BaseAgent.cs)
|
|
||||||
* [ClassificationAgent.cs](../Service/AgentFramework/ClassificationAgent.cs)
|
|
||||||
* [ParsingAgent.cs](../Service/AgentFramework/ParsingAgent.cs)
|
|
||||||
Reference in New Issue
Block a user