feat: 优化顺运宝同步反馈与记录刷新 (#61)
This commit is contained in:
+20
-14
@@ -67,12 +67,13 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
|
||||
return
|
||||
}
|
||||
|
||||
syncStatus := service.GetSybSyncStatus()
|
||||
status := msg
|
||||
if status == "" {
|
||||
status = sybStatusLine(result)
|
||||
}
|
||||
if service.GetSybSyncStatus().Running {
|
||||
status = "同步进行中,请稍后刷新页面查看结果 · " + status
|
||||
if syncStatus.Running && (msg == "" || strings.Contains(msg, "同步已开始")) {
|
||||
status = "同步正在进行,请耐心等待;可打开同步记录刷新查看结果"
|
||||
}
|
||||
|
||||
values := url.Values{}
|
||||
@@ -152,8 +153,11 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
|
||||
"SyncDateTo": dateTo,
|
||||
"RangeError": c.Query("range_error"),
|
||||
"RangeWarning": rangeWarning,
|
||||
"SyncRunning": syncStatus.Running,
|
||||
"SyncHistory": history,
|
||||
"NeedSyncHistory": c.Query("history") == "1",
|
||||
"HistoryRefreshURL": sybHistoryURL(history.Page,
|
||||
keyword, dateFrom, dateTo),
|
||||
"HistoryPagination": sybHistoryPagination(history.Page, history.TotalPages,
|
||||
keyword, dateFrom, dateTo),
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
@@ -161,15 +165,7 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
|
||||
}
|
||||
|
||||
func sybHistoryPagination(pageNum, totalPages int, keyword, dateFrom, dateTo string) service.PaginationView {
|
||||
link := func(target int) string {
|
||||
values := url.Values{"history": {"1"}, "history_page": {strconv.Itoa(target)}}
|
||||
if keyword != "" {
|
||||
values.Set("order_no", keyword)
|
||||
}
|
||||
values.Set("date_from", dateFrom)
|
||||
values.Set("date_to", dateTo)
|
||||
return "/syb?" + values.Encode()
|
||||
}
|
||||
link := func(target int) string { return sybHistoryURL(target, keyword, dateFrom, dateTo) }
|
||||
view := service.PaginationView{
|
||||
Page: pageNum, TotalPages: totalPages, HasPrev: pageNum > 1, HasNext: pageNum < totalPages,
|
||||
FirstURL: link(1), LastURL: link(totalPages),
|
||||
@@ -183,6 +179,16 @@ func sybHistoryPagination(pageNum, totalPages int, keyword, dateFrom, dateTo str
|
||||
return view
|
||||
}
|
||||
|
||||
func sybHistoryURL(pageNum int, keyword, dateFrom, dateTo string) string {
|
||||
values := url.Values{"history": {"1"}, "history_page": {strconv.Itoa(pageNum)}}
|
||||
if keyword != "" {
|
||||
values.Set("order_no", keyword)
|
||||
}
|
||||
values.Set("date_from", dateFrom)
|
||||
values.Set("date_to", dateTo)
|
||||
return "/syb?" + values.Encode()
|
||||
}
|
||||
|
||||
// sybStatusLine 组装底部状态条的默认文案(没有 msg 覆盖时)。
|
||||
// `[必须]` 显示筛选后的**全量**总数,不是本页行数,见工单 #43 定下的规则。
|
||||
func sybStatusLine(result *service.SybListResult) string {
|
||||
@@ -238,7 +244,7 @@ func (h *Handler) SybSync(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if !started {
|
||||
h.sybRedirect(c, "验证码自动识别成功,已自动登录;但已经有一个同步任务在跑,请稍后刷新页面查看结果")
|
||||
h.sybRedirect(c, "同步正在进行,请耐心等待,请勿重复点击")
|
||||
return
|
||||
}
|
||||
h.sybRedirectAfterStart(c, "验证码自动识别成功,已自动登录,同步已开始,请稍后刷新页面查看结果")
|
||||
@@ -251,7 +257,7 @@ func (h *Handler) SybSync(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if !started {
|
||||
h.sybRedirect(c, "已经有一个同步任务在跑,请稍后刷新页面查看结果,不要重复点击")
|
||||
h.sybRedirect(c, "同步正在进行,请耐心等待,请勿重复点击")
|
||||
return
|
||||
}
|
||||
h.sybRedirectAfterStart(c, "同步已开始,请稍后刷新页面查看结果")
|
||||
@@ -363,7 +369,7 @@ func (h *Handler) SybLoginAndSync(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if !started {
|
||||
h.sybRedirect(c, "登录成功,但已经有一个同步任务在跑,请稍后刷新页面查看结果")
|
||||
h.sybRedirect(c, "同步正在进行,请耐心等待,请勿重复点击")
|
||||
return
|
||||
}
|
||||
h.sybRedirectAfterStart(c, "登录成功,同步已开始,请稍后刷新页面查看结果")
|
||||
|
||||
Reference in New Issue
Block a user