92 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package tpl
 | |
| 
 | |
| import (
 | |
| 	"html/template"
 | |
| 	"path/filepath"
 | |
| 	"strings"
 | |
| 
 | |
| 	"management/internal/db/model/dto"
 | |
| )
 | |
| 
 | |
| func (r *render) btnFuncs() map[string]any {
 | |
| 	res := make(map[string]any, 3)
 | |
| 
 | |
| 	res["genBtn"] = func(btns []*dto.OwnerMenuDto, actionNames ...string) template.HTML {
 | |
| 		if len(btns) == 0 {
 | |
| 			return template.HTML("")
 | |
| 		}
 | |
| 
 | |
| 		var res string
 | |
| 		for _, action := range actionNames {
 | |
| 			for _, btn := range btns {
 | |
| 				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 template.HTML(res)
 | |
| 	}
 | |
| 
 | |
| 	res["genLink"] = func(btns []*dto.OwnerMenuDto, actionNames ...string) template.HTML {
 | |
| 		if len(btns) == 0 {
 | |
| 			return template.HTML("")
 | |
| 		}
 | |
| 
 | |
| 		var res string
 | |
| 		for _, action := range actionNames {
 | |
| 			for _, btn := range btns {
 | |
| 				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 template.HTML(res)
 | |
| 	}
 | |
| 
 | |
| 	res["previewPicture"] = func(name string) template.HTML {
 | |
| 		var res string
 | |
| 		res += `<a><img src="https://school-1251542740.cos.ap-shanghai.myqcloud.com{{` + name + `}}" data-type="1" height="30" width="30" class="preview-all screenshot" onclick="previewPicture('https://school-1251542740.cos.ap-shanghai.myqcloud.com/{{` + name + `}}')"/></a>`
 | |
| 
 | |
| 		return template.HTML(res)
 | |
| 	}
 | |
| 
 | |
| 	res["submitBtn"] = func(btns []*dto.OwnerMenuDto, actionNames ...string) template.HTML {
 | |
| 		if len(btns) == 0 {
 | |
| 			return template.HTML("")
 | |
| 		}
 | |
| 
 | |
| 		var res string
 | |
| 		for _, action := range actionNames {
 | |
| 			for _, btn := range btns {
 | |
| 				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 template.HTML(res)
 | |
| 	}
 | |
| 
 | |
| 	return res
 | |
| }
 |