feat: 登录管理设备列表显示会话类型和剩余有效期
- 临时会话显示橙色'临时会话'徽章 - 非当前设备显示剩余有效时间(临时/长期均显示) - 当前设备不显示剩余时间(持续续期,显示无意义) - 新增 formatTTL 模板函数,分钟数转人类可读格式 - sessionConfig 接口增加 GetRememberTimeout 方法
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -17,8 +18,9 @@ type TemplateRoot struct {
|
||||
// 模板名 = prefix + 相对于 root.Dir 的相对路径
|
||||
func LoadTemplates(roots ...TemplateRoot) (*template.Template, error) {
|
||||
funcMap := template.FuncMap{
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"subtract": func(a, b int) int { return a - b },
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"subtract": func(a, b int) int { return a - b },
|
||||
"formatTTL": formatTTL,
|
||||
}
|
||||
t := template.New("").Funcs(funcMap)
|
||||
for _, root := range roots {
|
||||
@ -55,3 +57,23 @@ func LoadContent(path string) (template.HTML, error) {
|
||||
}
|
||||
return template.HTML(content), nil
|
||||
}
|
||||
|
||||
// formatTTL 将剩余分钟数格式化为人类可读的时间(如 "23 小时"、"3 天"、"15 分钟")
|
||||
func formatTTL(minutes int) string {
|
||||
if minutes <= 0 {
|
||||
return "即将过期"
|
||||
}
|
||||
if minutes < 60 {
|
||||
return fmt.Sprintf("%d 分钟", minutes)
|
||||
}
|
||||
hours := minutes / 60
|
||||
if hours < 24 {
|
||||
return fmt.Sprintf("%d 小时", hours)
|
||||
}
|
||||
days := hours / 24
|
||||
remainHours := hours % 24
|
||||
if remainHours == 0 {
|
||||
return fmt.Sprintf("%d 天", days)
|
||||
}
|
||||
return fmt.Sprintf("%d 天 %d 小时", days, remainHours)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user