feat(t241): improve freight admin views
This commit is contained in:
@@ -3,6 +3,7 @@ package webui
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"path"
|
||||
@@ -21,9 +22,11 @@ func NewRenderer() (*Renderer, error) {
|
||||
templates, err := template.New("admin").
|
||||
Option("missingkey=error").
|
||||
Funcs(template.FuncMap{
|
||||
"displayTime": displayTime,
|
||||
"machineTime": machineTime,
|
||||
"pathPart": pathPart,
|
||||
"displayTime": displayTime,
|
||||
"machineTime": machineTime,
|
||||
"pathPart": pathPart,
|
||||
"formatMoney": formatMinorCurrency,
|
||||
"imageStatusLabel": freightImageStatusLabel,
|
||||
}).
|
||||
ParseFS(embeddedFiles, "templates/*.gohtml")
|
||||
if err != nil {
|
||||
@@ -32,6 +35,34 @@ func NewRenderer() (*Renderer, error) {
|
||||
return &Renderer{templates: templates}, nil
|
||||
}
|
||||
|
||||
func formatMinorCurrency(value *int64, currency string) string {
|
||||
if value == nil {
|
||||
return "未提供"
|
||||
}
|
||||
if currency == "" {
|
||||
currency = "TWD"
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"%s %d.%02d",
|
||||
currency,
|
||||
*value/100,
|
||||
*value%100,
|
||||
)
|
||||
}
|
||||
|
||||
func freightImageStatusLabel(status string) string {
|
||||
switch status {
|
||||
case "PENDING":
|
||||
return "图片待获取"
|
||||
case "MISSING":
|
||||
return "ERP 无图片"
|
||||
case "FAILED":
|
||||
return "图片获取失败"
|
||||
default:
|
||||
return "未提供图片"
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Renderer) Execute(
|
||||
writer io.Writer,
|
||||
name string,
|
||||
|
||||
Reference in New Issue
Block a user