82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
// Package webui 渲染采购服务当前可用的服务端页面。
|
|
package webui
|
|
|
|
import (
|
|
"embed"
|
|
"html/template"
|
|
"io"
|
|
"time"
|
|
|
|
"cmbuyer/admin/internal/tasks"
|
|
)
|
|
|
|
//go:embed templates/*.html
|
|
var templateFiles embed.FS
|
|
|
|
//go:embed static/tasks.js
|
|
var tasksScript []byte
|
|
|
|
var shanghaiLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
|
|
|
|
var templates = template.Must(template.New("webui").Funcs(template.FuncMap{
|
|
"list": func(values ...any) []any { return values },
|
|
"statusLabel": statusLabel,
|
|
"shanghaiDateTime": func(value time.Time) string { return value.In(shanghaiLocation).Format(time.RFC3339) },
|
|
"shanghaiTime": func(value time.Time) string { return value.In(shanghaiLocation).Format("2006-01-02 15:04") },
|
|
}).ParseFS(templateFiles, "templates/*.html"))
|
|
|
|
// LoginData 是登录页面所需的非敏感展示数据。
|
|
type LoginData struct {
|
|
CSRFToken string
|
|
ReturnTo string
|
|
Username string
|
|
Error string
|
|
}
|
|
|
|
// TasksData 是受保护的建单与任务工作台页面所需数据。
|
|
type TasksData struct {
|
|
CSRFToken string
|
|
Tasks []tasks.TaskRow
|
|
Filter tasks.TaskFilter
|
|
FilterErrors tasks.Errors
|
|
HasFilter bool
|
|
StartKey string
|
|
Form tasks.Form
|
|
Errors tasks.Errors
|
|
OpenForm bool
|
|
FullPage bool
|
|
FocusField string
|
|
Success bool
|
|
}
|
|
|
|
// RenderLogin 写入登录页。
|
|
func RenderLogin(writer io.Writer, data LoginData) error {
|
|
return templates.ExecuteTemplate(writer, "login.html", data)
|
|
}
|
|
|
|
// RenderTasks 写入登录后的受保护任务页。
|
|
func RenderTasks(writer io.Writer, data TasksData) error {
|
|
return templates.ExecuteTemplate(writer, "tasks.html", data)
|
|
}
|
|
|
|
func TasksScript() []byte { return tasksScript }
|
|
|
|
func statusLabel(status string) string {
|
|
labels := map[string]string{
|
|
"DRAFT": "待开始",
|
|
"PENDING": "已授权待领取",
|
|
"CLAIMED": "已领取",
|
|
"ORDERING": "执行中",
|
|
"NEEDS_MANUAL": "待人工处理",
|
|
"WAITING_PAYMENT": "待付款",
|
|
"RECONCILIATION_REQUIRED": "围栏后待调和",
|
|
"SUCCEEDED": "已完成",
|
|
"FAILED": "失败",
|
|
"CANCELED": "已取消",
|
|
}
|
|
if label, ok := labels[status]; ok {
|
|
return label
|
|
}
|
|
return "未知状态"
|
|
}
|