feat(v1.2): 亮暗主题、按尾号快速完成、加急置顶、按套餐分日历、大屏升级
1) 全站亮色 / 暗色 - 管理端与大屏都提供切换按钮(顶栏 ☾/☀、大屏右上角),偏好写 cookie,服务端首屏直出,不闪 - 未选择时跟随系统(prefers-color-scheme);两套配色都改成 CSS 变量,色签、热力、表格、抽屉全部适配 - 大屏默认仍是深色记分板,浅色为纸感背景 2) 工作台 → 当日待完成:按手机尾号快速完成 - 输入尾号回车:唯一匹配直接完成并提示 - 同尾号多客户 / 一单多服务:跳到选择面板,默认全选,可多选后一次完成 - 新增 POST /checkins/quick 与 POST /checkins/batch;抽屉标题改为「未完成数 / 总单数」 3) 加急 - 每条任务右侧可勾选/取消加急;加急任务红 tag + 置顶(抽屉与大屏「今日待打」) - 日历格子出现红点,单据色签加红边;大屏热力格也带红点 - 新增表 task_flags(sub_id, service_date, urgent),按 订阅+日期 存,避免和打卡状态耦合 4) 套餐「在日历中独立显示」 - 套餐表单新增勾选项,列表页显示「独立日历」标记 - 勾选后工作台与大屏顶部出现套餐标签页(全部 / 每日任务 / …),可只看某类委托的排单、热量与待办 - 新增列 packages.calendar_separate;老库打开时自动 ALTER,无需手工迁移 5) 大屏 - 热力默认改为「每日待完成单量」,右上角可切回「到期热力」 - 鼠标悬停任意日期格,浮出当日待办明细(客户、套餐、剩余、加急),数据来自 GET /api/screen/day - 底部面板改为「今日到期」(左)+「今日待打」(右,加急置顶),最近追加改为最底部细条 数据库兼容性: - 只做加法:新增 task_flags 表与 packages.calendar_separate 列,原有表结构、字段、接口与已有数据均不变 - 迁移可重复执行(CREATE TABLE IF NOT EXISTS + PRAGMA 检查后 ALTER) 测试: - 新增单元测试:套餐独立日历标记、加急增删查、旧库自动加列与重复迁移 - 新增功能冒烟 33 项(主题 cookie、套餐标签、快速完成单/多匹配、加急排序、大屏接口)全部通过 - 原有 119 项验收回归全绿(3 条断言按新 UI 更新:抽屉标题、热力默认口径、今日待打数取值方式) - go vet / go test ./... 通过;版本号 1.2.0
This commit is contained in:
+175
-45
@@ -1,9 +1,9 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"daili/internal/domain"
|
||||
"daili/internal/store"
|
||||
@@ -15,10 +15,15 @@ type screenDay struct {
|
||||
InMonth bool
|
||||
IsToday bool
|
||||
IsPast bool
|
||||
Due int
|
||||
Count int
|
||||
Urgent int
|
||||
Heat int
|
||||
}
|
||||
|
||||
type screenTask struct {
|
||||
TaskRow
|
||||
}
|
||||
|
||||
type screenData struct {
|
||||
Stats *store.Stats
|
||||
MonthTitle string
|
||||
@@ -27,17 +32,51 @@ type screenData struct {
|
||||
Weekdays []string
|
||||
Top []SubView
|
||||
DueToday []SubView
|
||||
TodayList []SubView
|
||||
TodayList []screenTask
|
||||
Recent []store.Adjustment
|
||||
TodayTasks int
|
||||
TodayDone int
|
||||
TodayUrgent int
|
||||
Refresh int
|
||||
Version string
|
||||
|
||||
HeatMode string // task = 每日待完成;due = 到期
|
||||
HeatTotal int
|
||||
Tabs []PkgTab
|
||||
PkgID int64
|
||||
HasTabs bool
|
||||
Theme string
|
||||
}
|
||||
|
||||
// screenCalSubs 读取大屏日历区间内的订阅,并带上暂停/打卡/加急。
|
||||
func (s *Server) screenCalSubs(from, to string, pkgID int64) ([]calSub, map[int64]map[string]store.Checkin, map[int64]map[string]bool, error) {
|
||||
subs, pauses, checkins, urgent, err := s.loadCalendarSubs(from, to, pkgID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
today := domain.Today()
|
||||
warn := s.warnDays()
|
||||
list := make([]calSub, 0, len(subs))
|
||||
for _, sub := range subs {
|
||||
cs := calSub{sub: sub, pauses: pauses[sub.ID], eval: sub.Eval(today, warn)}
|
||||
if sub.EndDate != "" {
|
||||
cs.hasEnd = true
|
||||
cs.end = domain.ParseDateOr(sub.EndDate, today)
|
||||
}
|
||||
list = append(list, cs)
|
||||
}
|
||||
return list, checkins, urgent, nil
|
||||
}
|
||||
|
||||
func (s *Server) handleScreen(w http.ResponseWriter, r *http.Request) {
|
||||
today := domain.Today()
|
||||
warn := s.warnDays()
|
||||
pkgID := int64(s.queryInt(r, "pkg", 0))
|
||||
heatMode := r.URL.Query().Get("heat")
|
||||
if heatMode != "due" {
|
||||
heatMode = "task"
|
||||
}
|
||||
|
||||
stats, err := s.db.ScreenStats(today, warn)
|
||||
if err != nil {
|
||||
http.Error(w, "读取大屏数据失败", http.StatusInternalServerError)
|
||||
@@ -50,85 +89,176 @@ func (s *Server) handleScreen(w http.ResponseWriter, r *http.Request) {
|
||||
Month: int(today.Month()),
|
||||
Weekdays: []string{"一", "二", "三", "四", "五", "六", "日"},
|
||||
Top: subViews(stats.Top, today, warn),
|
||||
DueToday: subViews(stats.DueTodaySubs, today, warn),
|
||||
Refresh: s.screenRefresh(),
|
||||
Version: s.cfg.Version,
|
||||
}
|
||||
if len(data.DueToday) > 6 {
|
||||
data.DueToday = data.DueToday[:6]
|
||||
HeatMode: heatMode,
|
||||
PkgID: pkgID,
|
||||
}
|
||||
|
||||
// 本月热力
|
||||
// 今日到期(可按套餐过滤)
|
||||
dueToday := []store.Subscription{}
|
||||
for _, sub := range stats.DueTodaySubs {
|
||||
if pkgID > 0 && sub.PackageID != pkgID {
|
||||
continue
|
||||
}
|
||||
dueToday = append(dueToday, sub)
|
||||
}
|
||||
data.DueToday = subViews(dueToday, today, warn)
|
||||
|
||||
// 本月热力:默认统计“每日待完成的单子”,可切换到“到期”
|
||||
monthStart := domain.MonthStart(today.Year(), today.Month())
|
||||
monthEnd := domain.MonthEnd(today.Year(), today.Month())
|
||||
gridStart := domain.AddDays(monthStart, -domain.WeekdayIndex(monthStart))
|
||||
weeks := (domain.WeekdayIndex(monthStart) + monthEnd.Day() + 6) / 7
|
||||
gridEnd := domain.AddDays(gridStart, weeks*7-1)
|
||||
|
||||
list, checkins, urgent, err := s.screenCalSubs(domain.Date(gridStart), domain.Date(gridEnd), pkgID)
|
||||
if err != nil {
|
||||
http.Error(w, "读取大屏日历失败", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for wi := 0; wi < weeks; wi++ {
|
||||
week := make([]screenDay, 0, 7)
|
||||
for di := 0; di < 7; di++ {
|
||||
d := domain.AddDays(gridStart, wi*7+di)
|
||||
ds := domain.Date(d)
|
||||
due := stats.Heat[ds]
|
||||
count, urgentN := 0, 0
|
||||
for _, cs := range list {
|
||||
if heatMode == "due" {
|
||||
if cs.sub.EndDate == ds {
|
||||
count++
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !cs.covers(ds) {
|
||||
continue
|
||||
}
|
||||
ci, has := checkins[cs.sub.ID][ds]
|
||||
if has && (ci.Status == "done" || ci.Status == "skipped") {
|
||||
continue // “待完成”只统计还没处理的
|
||||
}
|
||||
count++
|
||||
if urgent[cs.sub.ID][ds] {
|
||||
urgentN++
|
||||
}
|
||||
}
|
||||
if d.Month() == today.Month() {
|
||||
data.HeatTotal += count
|
||||
}
|
||||
week = append(week, screenDay{
|
||||
Date: ds,
|
||||
Day: d.Day(),
|
||||
InMonth: d.Month() == today.Month(),
|
||||
IsToday: ds == domain.Date(today),
|
||||
IsPast: d.Before(today),
|
||||
Due: due,
|
||||
Heat: heatLevel(due),
|
||||
Count: count,
|
||||
Urgent: urgentN,
|
||||
Heat: heatLevel(count),
|
||||
})
|
||||
}
|
||||
data.Weeks = append(data.Weeks, week)
|
||||
}
|
||||
|
||||
// 今日待打(加急置顶)
|
||||
rows, err := s.pendingTasks(domain.Date(today), nil, pkgID)
|
||||
if err == nil {
|
||||
for _, row := range rows {
|
||||
if row.Done || row.Skipped {
|
||||
continue
|
||||
}
|
||||
data.TodayList = append(data.TodayList, screenTask{TaskRow: row})
|
||||
if row.Urgent {
|
||||
data.TodayUrgent++
|
||||
}
|
||||
}
|
||||
}
|
||||
data.TodayTasks = len(data.TodayList)
|
||||
for _, row := range rows {
|
||||
if row.Done {
|
||||
data.TodayDone++
|
||||
}
|
||||
}
|
||||
|
||||
// 最近追加(底部细条)
|
||||
if adj, err := s.db.RecentAdjustments(6); err == nil {
|
||||
data.Recent = adj
|
||||
}
|
||||
list, done := s.todayTaskList(today)
|
||||
data.TodayTasks = len(list)
|
||||
data.TodayDone = done
|
||||
data.TodayList = subViews(list, today, warn)
|
||||
|
||||
// 套餐标签
|
||||
pkgs, _ := s.db.ListPackages(true)
|
||||
for _, p := range pkgs {
|
||||
if p.CalendarSeparate && !p.Archived {
|
||||
if !data.HasTabs {
|
||||
data.HasTabs = true
|
||||
data.Tabs = append(data.Tabs, PkgTab{ID: 0, Name: "全部", Color: "#8A8F98"})
|
||||
}
|
||||
data.Tabs = append(data.Tabs, PkgTab{ID: p.ID, Name: p.Name, Color: p.Color})
|
||||
}
|
||||
}
|
||||
|
||||
data.Theme = themeFromRequest(r)
|
||||
p := s.newPage(r, "大屏", "screen")
|
||||
p.Theme = data.Theme
|
||||
p.D = data
|
||||
s.render(w, r, "screen", p)
|
||||
}
|
||||
|
||||
// todayTaskList 返回今天应服务的订阅与已完成数量。
|
||||
func (s *Server) todayTaskList(today time.Time) ([]store.Subscription, int) {
|
||||
ts := domain.Date(today)
|
||||
subs, err := s.db.CalendarSubs(ts, ts)
|
||||
// handleScreenDay 返回某天的待办明细,供大屏悬停浮层使用。
|
||||
func (s *Server) handleScreenDay(w http.ResponseWriter, r *http.Request) {
|
||||
date := r.URL.Query().Get("date")
|
||||
if _, err := domain.ParseDate(date); err != nil {
|
||||
http.Error(w, "日期不正确", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
pkgID := int64(s.queryInt(r, "pkg", 0))
|
||||
rows, err := s.pendingTasks(date, nil, pkgID)
|
||||
if err != nil {
|
||||
return nil, 0
|
||||
http.Error(w, "读取失败", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ids := make([]int64, 0, len(subs))
|
||||
for _, sub := range subs {
|
||||
ids = append(ids, sub.ID)
|
||||
type item struct {
|
||||
Tail string `json:"tail"`
|
||||
Name string `json:"name"`
|
||||
Pkg string `json:"pkg"`
|
||||
Color string `json:"color"`
|
||||
Remain string `json:"remain"`
|
||||
Urgent bool `json:"urgent"`
|
||||
Done bool `json:"done"`
|
||||
}
|
||||
pauses, _ := s.db.PausesForSubs(ids)
|
||||
checkins, _ := s.db.CheckinsBetween(ts, ts)
|
||||
warn := s.warnDays()
|
||||
out := []store.Subscription{}
|
||||
done := 0
|
||||
for _, sub := range subs {
|
||||
if sub.Status == domain.StatusClosed {
|
||||
out := struct {
|
||||
Date string `json:"date"`
|
||||
Total int `json:"total"`
|
||||
Done int `json:"done"`
|
||||
Urgent int `json:"urgent"`
|
||||
More int `json:"more"`
|
||||
Items []item `json:"items"`
|
||||
}{Date: date}
|
||||
|
||||
const limit = 60
|
||||
for _, row := range rows {
|
||||
out.Total++
|
||||
if row.Done || row.Skipped {
|
||||
out.Done++
|
||||
}
|
||||
if row.Urgent {
|
||||
out.Urgent++
|
||||
}
|
||||
if len(out.Items) >= limit {
|
||||
out.More++
|
||||
continue
|
||||
}
|
||||
if sub.StartDate > ts || sub.EndDate == "" || sub.EndDate < ts {
|
||||
continue
|
||||
}
|
||||
cs := calSub{sub: sub, pauses: pauses[sub.ID], hasEnd: true, eval: sub.Eval(today, warn)}
|
||||
if sub.Unit == domain.UnitCount && cs.eval.RemainingCount <= 0 {
|
||||
continue
|
||||
}
|
||||
if cs.pausedOn(ts) {
|
||||
continue
|
||||
}
|
||||
out = append(out, sub)
|
||||
if ci, ok := checkins[sub.ID][ts]; ok && ci.Status == "done" {
|
||||
done++
|
||||
}
|
||||
out.Items = append(out.Items, item{
|
||||
Tail: row.CustomerTail,
|
||||
Name: row.CustomerName,
|
||||
Pkg: row.PackageName,
|
||||
Color: row.PackageColor,
|
||||
Remain: row.RemainText,
|
||||
Urgent: row.Urgent,
|
||||
Done: row.Done || row.Skipped,
|
||||
})
|
||||
}
|
||||
return out, done
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_ = json.NewEncoder(w).Encode(out)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user