141 lines
3.1 KiB
Go
141 lines
3.1 KiB
Go
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:]
|
|
}
|