fix: date组件兼容time格式

date组件兼容time格式
This commit is contained in:
yaoyilin
2022-11-09 10:21:56 +08:00
parent 90d66bf575
commit 1230abfd0e

View File

@@ -9,6 +9,7 @@ package widget
import (
"gitlab.52pay.top/go/easygoadmin/utils/gconv"
"html/template"
"strconv"
"strings"
"time"
)
@@ -47,8 +48,21 @@ func Date(param string, value interface{}) template.HTML {
if dateType == "date" {
dateFormat = "2006-01-02"
}
if value != nil {
dateValue = time.Unix(gconv.Int64(value), 0).Format(dateFormat)
switch value.(type) {
case string:
if dt, err := time.Parse(dateFormat, value.(string)); err == nil {
dateValue = dt.Format(dateFormat)
break
}
if unix, err := strconv.Atoi(value.(string)); err == nil {
dateValue = time.Unix(int64(unix), 0).Format(dateFormat)
break
}
case int, int64, int32:
dateValue = time.Unix(gconv.Int64(value), 0).Format(dateFormat)
}
}
html := `<input name="` + dateName + `" id="` + dateName + `" value="` + dateValue + `" lay-verify="` + dateType + `" placeholder="请选择` + dateTips + `" autocomplete="off" class="layui-input date-icon" type="text">