183 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			183 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Code generated by templ - DO NOT EDIT.
 | ||
| 
 | ||
| // templ: version: v0.3.898
 | ||
| package department
 | ||
| 
 | ||
| //lint:file-ignore SA4006 This context is only used if a nested component is present.
 | ||
| 
 | ||
| import "github.com/a-h/templ"
 | ||
| import templruntime "github.com/a-h/templ/runtime"
 | ||
| 
 | ||
| import (
 | ||
| 	"context"
 | ||
| 
 | ||
| 	"management/internal/erpserver/templ/base"
 | ||
| 	"management/internal/erpserver/templ/component"
 | ||
| 	"management/internal/pkg/mid"
 | ||
| )
 | ||
| 
 | ||
| func List(ctx context.Context) templ.Component {
 | ||
| 	return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
 | ||
| 		templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
 | ||
| 		if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
 | ||
| 			return templ_7745c5c3_CtxErr
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
 | ||
| 		if !templ_7745c5c3_IsBuffer {
 | ||
| 			defer func() {
 | ||
| 				templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
 | ||
| 				if templ_7745c5c3_Err == nil {
 | ||
| 					templ_7745c5c3_Err = templ_7745c5c3_BufErr
 | ||
| 				}
 | ||
| 			}()
 | ||
| 		}
 | ||
| 		ctx = templ.InitializeContext(ctx)
 | ||
| 		templ_7745c5c3_Var1 := templ.GetChildren(ctx)
 | ||
| 		if templ_7745c5c3_Var1 == nil {
 | ||
| 			templ_7745c5c3_Var1 = templ.NopComponent
 | ||
| 		}
 | ||
| 		ctx = templ.ClearChildren(ctx)
 | ||
| 		templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
 | ||
| 			templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
 | ||
| 			templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
 | ||
| 			if !templ_7745c5c3_IsBuffer {
 | ||
| 				defer func() {
 | ||
| 					templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
 | ||
| 					if templ_7745c5c3_Err == nil {
 | ||
| 						templ_7745c5c3_Err = templ_7745c5c3_BufErr
 | ||
| 					}
 | ||
| 				}()
 | ||
| 			}
 | ||
| 			ctx = templ.InitializeContext(ctx)
 | ||
| 			meuns := mid.GetCurMenus(ctx)
 | ||
| 			templ_7745c5c3_Err = component.TemplBtn(meuns, true, "add", "refresh_cache", "rebuild_parent_path").Render(ctx, templ_7745c5c3_Buffer)
 | ||
| 			if templ_7745c5c3_Err != nil {
 | ||
| 				return templ_7745c5c3_Err
 | ||
| 			}
 | ||
| 			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, " ")
 | ||
| 			if templ_7745c5c3_Err != nil {
 | ||
| 				return templ_7745c5c3_Err
 | ||
| 			}
 | ||
| 			templ_7745c5c3_Err = component.TemplLink(meuns, "add_children", "edit").Render(ctx, templ_7745c5c3_Buffer)
 | ||
| 			if templ_7745c5c3_Err != nil {
 | ||
| 				return templ_7745c5c3_Err
 | ||
| 			}
 | ||
| 			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " <div class=\"search-layer\" id=\"search-layer\" style=\"display: none;\"><input type=\"hidden\" id=\"parentId\" name=\"parentId\" value=\"0\"><div class=\"layui-form layui-row\"><div class=\"layui-col-xs12 layui-col-sm12 layui-col-md4\"><div class=\"layui-form-column\"><label for=\"status\" class=\"tips\">状态</label> <select id=\"status\"><option value=\"0\">正常</option> <option value=\"-1\">删除</option> <option value=\"9999\">全部</option></select></div></div><div class=\"layui-col-xs12 layui-col-sm12 layui-col-md4\"><div class=\"layui-form-column\"><label for=\"id\" class=\"tips\">编号</label> <input type=\"text\" id=\"id\" placeholder=\"请输入编号\" class=\"layui-input\"></div></div><div class=\"layui-col-xs12 layui-col-sm12 layui-col-md4\"><div class=\"layui-form-column\"><label for=\"name\" class=\"tips\">标题</label> <input type=\"text\" id=\"name\" placeholder=\"请输入标题\" class=\"layui-input\"></div></div></div></div><div class=\"layui-row h-all\"><div class=\"layui-col-md2 h-all\"><div class=\"own-left-pannel\"><div id=\"departmentTree\" class=\"own-tree\"></div></div></div><div class=\"layui-col-md10\"><div class=\"own-pannel\"><table id=\"tablelist\" lay-filter=\"tablelist\"></table></div></div></div>")
 | ||
| 			if templ_7745c5c3_Err != nil {
 | ||
| 				return templ_7745c5c3_Err
 | ||
| 			}
 | ||
| 			return nil
 | ||
| 		})
 | ||
| 		templ_7745c5c3_Err = base.Base(ctx, listCss(), listJs(ctx)).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		return nil
 | ||
| 	})
 | ||
| }
 | ||
| 
 | ||
| func listCss() templ.Component {
 | ||
| 	return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
 | ||
| 		templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
 | ||
| 		if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
 | ||
| 			return templ_7745c5c3_CtxErr
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
 | ||
| 		if !templ_7745c5c3_IsBuffer {
 | ||
| 			defer func() {
 | ||
| 				templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
 | ||
| 				if templ_7745c5c3_Err == nil {
 | ||
| 					templ_7745c5c3_Err = templ_7745c5c3_BufErr
 | ||
| 				}
 | ||
| 			}()
 | ||
| 		}
 | ||
| 		ctx = templ.InitializeContext(ctx)
 | ||
| 		templ_7745c5c3_Var3 := templ.GetChildren(ctx)
 | ||
| 		if templ_7745c5c3_Var3 == nil {
 | ||
| 			templ_7745c5c3_Var3 = templ.NopComponent
 | ||
| 		}
 | ||
| 		ctx = templ.ClearChildren(ctx)
 | ||
| 		return nil
 | ||
| 	})
 | ||
| }
 | ||
| 
 | ||
| func listJs(ctx context.Context) templ.Component {
 | ||
| 	return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
 | ||
| 		templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
 | ||
| 		if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
 | ||
| 			return templ_7745c5c3_CtxErr
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
 | ||
| 		if !templ_7745c5c3_IsBuffer {
 | ||
| 			defer func() {
 | ||
| 				templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
 | ||
| 				if templ_7745c5c3_Err == nil {
 | ||
| 					templ_7745c5c3_Err = templ_7745c5c3_BufErr
 | ||
| 				}
 | ||
| 			}()
 | ||
| 		}
 | ||
| 		ctx = templ.InitializeContext(ctx)
 | ||
| 		templ_7745c5c3_Var4 := templ.GetChildren(ctx)
 | ||
| 		if templ_7745c5c3_Var4 == nil {
 | ||
| 			templ_7745c5c3_Var4 = templ.NopComponent
 | ||
| 		}
 | ||
| 		ctx = templ.ClearChildren(ctx)
 | ||
| 		token := mid.GetCsrfToken(ctx)
 | ||
| 		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<script>\n        layui.use(['jquery', 'table', 'form', 'tree', 'util'], function () {\n            let $ = layui.jquery;\n            let table = layui.table;\n            let form = layui.form;\n            let tree = layui.tree;\n            let util = layui.util;\n\n            getDepartmentTree();\n\n            // 加载列表\n            table.render({\n                elem: '#tablelist',\n                url: '/system/department/list',\n                method: 'post',\n                headers: { 'X-CSRF-Token': '")
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Var5, templ_7745c5c3_Err := templruntime.ScriptContentInsideStringLiteral(token)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/erpserver/templ/system/department/list.templ`, Line: 80, Col: 52}
 | ||
| 		}
 | ||
| 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "' },\n                where: getQueryParams(),\n                height: function () {\n                    return $(window).height() - 22;\n                },\n                page: true,\n                limit: 15,\n                limits: [15, 30, 45, 60, 75, 90],\n                cols: [[\n                    { field: 'id', title: '编号', width: 60, fixed: 'left' },\n                    { field: 'name', title: '名称', width: 240, fixed: 'left' },\n                    {\n                        field: 'status', title: '状态', width: 60, align: 'center', templet: function (d) {\n                            if (d.id === 0) { return ''; }\n\n                            switch (d.status) {\n                                case 0: return '<span style=\"color: green\">正常</span>';\n                                case -1: return '<span style=\"color: red\">删除</span>';\n                                default: return '其它';\n                            }\n                        }\n                    },\n                    { field: 'created_at', title: '创建时间', width: 160, align: 'center', templet: function (d) { return (!d.created_at || d.id === 0) ? '' : util.toDateString(d.created_at) } },\n                    { field: 'updated_at', title: '更新时间', width: 160, align: 'center', templet: function (d) { return !d.updated_at ? '' : util.toDateString(d.updated_at) } },\n                    { title: '操作', toolbar: '#actionBox', align: 'center', width: 200, fixed: 'right' },\n                ]],\n                skin: 'grid',\n                toolbar: '#toolbar',\n                defaultToolbar: [{\n                    title: '刷新',\n                    layEvent: 'refresh',\n                    icon: 'layui-icon-refresh',\n                }, 'filter', 'exports'],\n                request: {\n                    pageName: 'page',\n                    limitName: 'rows'\n                }\n            });\n\n            // 工具栏\n            table.on('toolbar(tablelist)', function (obj) {\n                switch (obj.event) {\n                    case 'add': add(); break;\n                    case 'refresh': table.reload('tablelist'); break;\n                    case 'refresh_cache': refresh_cache(); break;\n                    case 'rebuild_parent_path': rebuildParentPath(); break;\n                    case 'search': search(); break;\n                }\n            });\n\n            function add() {\n                layer.open({\n                    type: 2,\n                    title: '新增部门',\n                    shade: 0.1,\n                    area: ['99%', '98%'],\n                    content: \"/system/department/add\"\n                });\n            }\n\n            function refresh_cache() {\n                layer.confirm('确定要刷新部门缓存数据吗?', { title: '提示' }, function (index, layero) {\n                    $.ajax({\n                        url: '/system/department/refresh_cache',\n                        type: 'post',\n                        headers: { 'X-CSRF-Token': '")
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Var6, templ_7745c5c3_Err := templruntime.ScriptContentInsideStringLiteral(token)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/erpserver/templ/system/department/list.templ`, Line: 145, Col: 60}
 | ||
| 		}
 | ||
| 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "' },\n                        dataType: 'json',\n                        success: function (result) {\n                            if (result.success) {\n                                layer.msg(result.msg, { icon: 1, time: 2000 });\n                                search_btn();\n                            } else {\n                                layer.msg(result.msg, { icon: 2 })\n                            }\n                        }\n                    });\n                    layer.close(index); // 关闭弹窗\n                }, function (index, layero) {\n                    layer.close(index); // 关闭弹窗\n                });\n            }\n\n            function rebuildParentPath() {\n                layer.confirm('确定要重建父路径吗?', { title: '提示' }, function (index, layero) {\n                    $.ajax({\n                        url: '/system/department/rebuild_parent_path',\n                        type: 'post',\n                        headers: { 'X-CSRF-Token': '")
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Var7, templ_7745c5c3_Err := templruntime.ScriptContentInsideStringLiteral(token)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/erpserver/templ/system/department/list.templ`, Line: 167, Col: 60}
 | ||
| 		}
 | ||
| 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "' },\n                        dataType: 'json',\n                        success: function (result) {\n                            if (result.success) {\n                                layer.msg(result.msg, { icon: 1, time: 2000 });\n                                search_btn();\n                            } else {\n                                layer.msg(result.msg, { icon: 2 })\n                            }\n                        }\n                    });\n                    layer.close(index); // 关闭弹窗\n                }, function (index, layero) {\n                    layer.close(index); // 关闭弹窗\n                });\n            }\n\n            function search() {\n                layer.open({\n                    type: 1,\n                    offset: '20px',\n                    title: '搜索',\n                    content: $('#search-layer'), // 捕获的元素\n                    shade: 0.1,\n                    shadeClose: false,\n                    scrollbar: false,\n                    resize: false,\n                    move: false,\n                    skin: 'search-layer-open',\n                    area: ['50%', '350px'],\n                    btn: ['搜索', '重置'],\n                    btn1: function (index, layero) {\n                        search_btn();\n                        layer.close(index);\n                    },\n                    btn2: function (index, layero) {\n                        $('#status').val(0);\n                        $('#id').val('');\n                        $('#name').val('');\n                        $('#parentId').val(0);\n                        form.render('select');\n                        return false;\n                    }\n                });\n            }\n\n            // 表格项操作按钮\n            table.on('tool(tablelist)', function (obj) {\n                switch (obj.event) {\n                    case 'add_children': addChildren(obj); break;\n                    case 'edit': edit(obj); break;\n                }\n            });\n\n            function addChildren(obj) {\n                layer.open({\n                    type: 2,\n                    title: '为 ' + obj.data['Name'] + ' 新增子级',\n                    shade: 0.1,\n                    area: ['99%', '98%'],\n                    content: \"/system/department/add_children?parentID=\" + obj.data['id']\n                });\n            }\n\n            function edit(obj) {\n                layer.open({\n                    type: 2,\n                    title: '修改',\n                    shade: 0.1,\n                    area: ['99%', '98%'],\n                    content: \"/system/department/edit?id=\" + obj.data['id']\n                });\n            }\n\n            // 搜索条件\n            function getQueryParams() {\n                return {\n                    status: $('#status').val(),\n                    name: $('#name').val(),\n                    id: $('#id').val(),\n                    parentId: $('#parentId').val()\n                };\n            }\n\n            // 搜索\n            function search_btn() {\n                table.reload('tablelist', {\n                    where: getQueryParams(),\n                    page: {\n                        curr: 1\n                    }\n                })\n            }\n\n            form.on('submit(btn-query)', function (data) {\n                table.reload('tablelist', {\n                    where: getQueryParams(),\n                    page: {\n                        curr: 1\n                    }\n                })\n                return false;\n            });\n\n            function getDepartmentTree() {\n                $.ajax({\n                    url: \"/system/department/data?type=tree\",\n                    type: 'post',\n                    dataType: 'json',\n                    headers: { 'X-CSRF-Token': '")
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Var8, templ_7745c5c3_Err := templruntime.ScriptContentInsideStringLiteral(token)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/erpserver/templ/system/department/list.templ`, Line: 276, Col: 56}
 | ||
| 		}
 | ||
| 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "' },\n                    success: function (res) {\n                        tree.render({\n                            elem: '#departmentTree',\n                            data: res,\n                            onlyIconControl: true,  // 是否仅允许节点左侧图标控制展开收缩\n                            showLine: true,\n                            click: function (obj) {\n                                // console.log(obj.data); // 得到当前点击的节点数据\n                                // console.log(obj.state); // 得到当前节点的展开状态:open、close、normal\n                                // console.log(obj.elem); // 得到当前节点元素\n                                // console.log(obj.data.children); // 当前节点下是否有子节点\n                                $('#parentId').val(obj.data.id);\n                                search_btn();\n                            }\n                        });\n                    },\n                    error: function (err) {\n                        // 处理请求错误\n                        console.log('请求出错:', err);\n                    }\n                });\n            }\n        });\n    </script>")
 | ||
| 		if templ_7745c5c3_Err != nil {
 | ||
| 			return templ_7745c5c3_Err
 | ||
| 		}
 | ||
| 		return nil
 | ||
| 	})
 | ||
| }
 | ||
| 
 | ||
| var _ = templruntime.GeneratedTemplate
 |