fix: 修复前后端时区问题和日期范围选择器性能
- 前端时区修复:统一使用本地时区格式化日期 - 日期范围选择器优化:使用 untrack 避免循环更新 - 后端时区修复:使用 time.ParseInLocation 指定本地时区 - 其他优化:修复分页逻辑
This commit is contained in:
@@ -24,9 +24,9 @@ type ListBillsRequest struct {
|
||||
|
||||
// ListBillsResponse 账单列表响应
|
||||
type ListBillsResponse struct {
|
||||
Result bool `json:"result"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Data *ListBillsData `json:"data,omitempty"`
|
||||
Result bool `json:"result"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Data *ListBillsData `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// ListBillsData 账单列表数据
|
||||
@@ -69,13 +69,15 @@ func ListBills(c *gin.Context) {
|
||||
if req.StartDate != "" || req.EndDate != "" {
|
||||
timeFilter := make(map[string]interface{})
|
||||
if req.StartDate != "" {
|
||||
startTime, err := time.Parse("2006-01-02", req.StartDate)
|
||||
// 使用本地时区解析日期,避免 UTC 时区问题
|
||||
startTime, err := time.ParseInLocation("2006-01-02", req.StartDate, time.Local)
|
||||
if err == nil {
|
||||
timeFilter["$gte"] = startTime
|
||||
}
|
||||
}
|
||||
if req.EndDate != "" {
|
||||
endTime, err := time.Parse("2006-01-02", req.EndDate)
|
||||
// 使用本地时区解析日期,避免 UTC 时区问题
|
||||
endTime, err := time.ParseInLocation("2006-01-02", req.EndDate, time.Local)
|
||||
if err == nil {
|
||||
// 结束日期包含当天,所以加一天
|
||||
endTime = endTime.Add(24 * time.Hour)
|
||||
|
||||
Reference in New Issue
Block a user