change use strings builder
This commit is contained in:
@@ -1,140 +1,140 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"management/internal/erpserver/model/dto"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component {
|
||||
var res string
|
||||
if len(actionNames) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
if len(buttons) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
res = `<script type="text/html" id="toolbar">`
|
||||
res += GenBtn(buttons, actionNames...)
|
||||
|
||||
if searchBtn {
|
||||
res += `
|
||||
<button type="button" lay-event="search" lay-on="search" class="layui-btn layui-btn-primary layui-btn-sm">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
</button>`
|
||||
}
|
||||
|
||||
res += `</script>`
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
var res string
|
||||
if len(actionNames) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
if len(buttons) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
res = `<script type="text/html" id="actionBox">`
|
||||
res += GenLink(buttons, actionNames...)
|
||||
|
||||
res += `</script>`
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
var res string
|
||||
if len(buttons) == 0 {
|
||||
return res
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return res
|
||||
}
|
||||
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
res += `<button type="button" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`
|
||||
if len(btn.Avatar) > 0 {
|
||||
res += `<i class="` + btn.Avatar + `"></i> `
|
||||
}
|
||||
res += btn.DisplayName + `</button>`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
if len(buttons) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var res string
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
res += `<button type="button" style="font-size:12px !important;" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`
|
||||
if len(btn.Avatar) > 0 {
|
||||
res += `<i class="` + btn.Avatar + `"></i> `
|
||||
}
|
||||
res += btn.DisplayName + `</button>`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
var res string
|
||||
if len(buttons) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
res += `<button type="submit" class="layui-btn ` + btn.Style + `" lay-submit lay-filter="` + firstLower(action) + `">`
|
||||
if len(btn.Avatar) > 0 {
|
||||
res += `<i class="` + btn.Avatar + `"></i> `
|
||||
}
|
||||
res += btn.DisplayName + `</button>`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return templ.Raw(res)
|
||||
}
|
||||
|
||||
func firstLower(s string) string {
|
||||
if len(s) == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
//import (
|
||||
// "path/filepath"
|
||||
// "strings"
|
||||
//
|
||||
// "management/internal/erpserver/model/dto"
|
||||
//
|
||||
// "github.com/a-h/templ"
|
||||
//)
|
||||
//
|
||||
//func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component {
|
||||
// var res string
|
||||
// if len(actionNames) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// if len(buttons) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// res = `<script type="text/html" id="toolbar">`
|
||||
// res += GenBtn(buttons, actionNames...)
|
||||
//
|
||||
// if searchBtn {
|
||||
// res += `
|
||||
// <button type="button" lay-event="search" lay-on="search" class="layui-btn layui-btn-primary layui-btn-sm">
|
||||
// <i class="layui-icon layui-icon-search"></i>
|
||||
// </button>`
|
||||
// }
|
||||
//
|
||||
// res += `</script>`
|
||||
// return templ.Raw(res)
|
||||
//}
|
||||
//
|
||||
//func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
// var res string
|
||||
// if len(actionNames) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// if len(buttons) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// res = `<script type="text/html" id="actionBox">`
|
||||
// res += GenLink(buttons, actionNames...)
|
||||
//
|
||||
// res += `</script>`
|
||||
// return templ.Raw(res)
|
||||
//}
|
||||
//
|
||||
//func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
// var res string
|
||||
// if len(buttons) == 0 {
|
||||
// return res
|
||||
// }
|
||||
//
|
||||
// if len(actionNames) == 0 {
|
||||
// return res
|
||||
// }
|
||||
//
|
||||
// for _, action := range actionNames {
|
||||
// for _, btn := range buttons {
|
||||
// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
// base := filepath.Base(btn.Url)
|
||||
// if base == action {
|
||||
// res += `<button type="button" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`
|
||||
// if len(btn.Avatar) > 0 {
|
||||
// res += `<i class="` + btn.Avatar + `"></i> `
|
||||
// }
|
||||
// res += btn.DisplayName + `</button>`
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return res
|
||||
//}
|
||||
//
|
||||
//func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
// if len(buttons) == 0 {
|
||||
// return ""
|
||||
// }
|
||||
//
|
||||
// if len(actionNames) == 0 {
|
||||
// return ""
|
||||
// }
|
||||
//
|
||||
// var res string
|
||||
// for _, action := range actionNames {
|
||||
// for _, btn := range buttons {
|
||||
// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
// base := filepath.Base(btn.Url)
|
||||
// if base == action {
|
||||
// res += `<button type="button" style="font-size:12px !important;" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`
|
||||
// if len(btn.Avatar) > 0 {
|
||||
// res += `<i class="` + btn.Avatar + `"></i> `
|
||||
// }
|
||||
// res += btn.DisplayName + `</button>`
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return res
|
||||
//}
|
||||
//
|
||||
//func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
// var res string
|
||||
// if len(buttons) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// if len(actionNames) == 0 {
|
||||
// return templ.Raw(res)
|
||||
// }
|
||||
//
|
||||
// for _, action := range actionNames {
|
||||
// for _, btn := range buttons {
|
||||
// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
// base := filepath.Base(btn.Url)
|
||||
// if base == action {
|
||||
// res += `<button type="submit" class="layui-btn ` + btn.Style + `" lay-submit lay-filter="` + firstLower(action) + `">`
|
||||
// if len(btn.Avatar) > 0 {
|
||||
// res += `<i class="` + btn.Avatar + `"></i> `
|
||||
// }
|
||||
// res += btn.DisplayName + `</button>`
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return templ.Raw(res)
|
||||
//}
|
||||
//
|
||||
//func firstLower(s string) string {
|
||||
// if len(s) == 0 {
|
||||
// return s
|
||||
// }
|
||||
//
|
||||
// return strings.ToLower(s[:1]) + s[1:]
|
||||
//}
|
||||
|
||||
126
internal/erpserver/templ/component/btnv1.go
Normal file
126
internal/erpserver/templ/component/btnv1.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"management/internal/erpserver/model/dto"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component {
|
||||
var b strings.Builder
|
||||
b.WriteString(`<script type="text/html" id="toolbar">`)
|
||||
b.WriteString(GenBtn(buttons, actionNames...))
|
||||
|
||||
if searchBtn {
|
||||
b.WriteString(`
|
||||
<button type="button" lay-event="search" lay-on="search" class="layui-btn layui-btn-primary layui-btn-sm">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
</button>`)
|
||||
}
|
||||
|
||||
b.WriteString(`</script>`)
|
||||
return templ.Raw(b.String())
|
||||
}
|
||||
|
||||
func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
var b strings.Builder
|
||||
b.WriteString(`<script type="text/html" id="actionBox">`)
|
||||
b.WriteString(GenLink(buttons, actionNames...))
|
||||
b.WriteString(`</script>`)
|
||||
return templ.Raw(b.String())
|
||||
}
|
||||
|
||||
func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
if len(buttons) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
b.WriteString(`<button type="button" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`)
|
||||
if len(btn.Avatar) > 0 {
|
||||
b.WriteString(`<i class="` + btn.Avatar + `"></i> `)
|
||||
}
|
||||
b.WriteString(btn.DisplayName)
|
||||
b.WriteString(`</button>`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string {
|
||||
if len(buttons) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
b.WriteString(`<button type="button" style="font-size:12px !important;" class="layui-btn ` + btn.Style + `" lay-event="` + firstLower(action) + `" lay-on="` + firstLower(action) + `">`)
|
||||
if len(btn.Avatar) > 0 {
|
||||
b.WriteString(`<i class="` + btn.Avatar + `"></i> `)
|
||||
}
|
||||
b.WriteString(btn.DisplayName)
|
||||
b.WriteString(`</button>`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component {
|
||||
if len(buttons) == 0 {
|
||||
return templ.Raw("")
|
||||
}
|
||||
|
||||
if len(actionNames) == 0 {
|
||||
return templ.Raw("")
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
for _, action := range actionNames {
|
||||
for _, btn := range buttons {
|
||||
btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui")
|
||||
base := filepath.Base(btn.Url)
|
||||
if base == action {
|
||||
b.WriteString(`<button type="submit" class="layui-btn ` + btn.Style + `" lay-submit lay-filter="` + firstLower(action) + `">`)
|
||||
if len(btn.Avatar) > 0 {
|
||||
b.WriteString(`<i class="` + btn.Avatar + `"></i> `)
|
||||
}
|
||||
b.WriteString(btn.DisplayName)
|
||||
b.WriteString(`</button>`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return templ.Raw(b.String())
|
||||
}
|
||||
|
||||
func firstLower(s string) string {
|
||||
if len(s) == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
Reference in New Issue
Block a user