示例#1
0
        public override async void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var administrator = ViewContext.HttpContext.GetCurrentUser();

            if (administrator == null)
            {
                return;
            }

            var childContent = await output.GetChildContentAsync();

            if (((List <int>)ViewContext.ViewData["PermCodes"]).Contains(PermCode) || administrator.IsSuper)
            {
                foreach (var item in context.AllAttributes)
                {
                    output.Attributes.Add(item.Name, item.Value);
                }

                output.TagName = "a";
                output.TagMode = TagMode.StartTagAndEndTag;
                output.Content.SetHtmlContent(childContent.GetContent());
            }
            else
            {
                output.TagName = "";
                output.TagMode = TagMode.StartTagAndEndTag;
                output.Content.SetHtmlContent("");
            }
        }
示例#2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;

            var attributes = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder },
                { TextAttributeName, Text ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" }
            };

            if (Disabled)
            {
                attributes["Disabled"] = "Disabled";
            }

            var inputTagBuilder = _generator.GenerateTextBox(ViewContext, For.ModelExplorer, For.Name, Value, Format, attributes);

            var htmlText  = !attributes[TextAttributeName].ToStr().IsNullOrWhiteSpace() ? $"<label class='layui-form-label'>{attributes[TextAttributeName]}</label>" : "";
            var outpuHtml = $@"
                    {htmlText}
                    <div class='layui-input-block'>
                        {inputTagBuilder.GetString()}
                    </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", "layui-inline");
            output.Content.SetHtmlContent(outpuHtml);
        }
示例#3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem {
                    Text = a.Key.Name.ToString(), Value = a.Value.ToString(), Selected = a.Value == ((int)((For.Model) ?? -1)).ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = (List <SelectListItem>)Data;
            }

            var idStr = TagBuilder.CreateSanitizedId(For.Name,
                                                     _generator.IdAttributeDotReplacement);

            var tagBuilder = new StringBuilder(32);

            selectListItems.ForEach(item =>
            {
                var attributes = new Dictionary <string, object>
                {
                    { "title", item.Text },
                    { "lay-skin", "primary" }
                };
                var inputTagBuilder = _generator.GenerateCheckBox(ViewContext,
                                                                  For.ModelExplorer,
                                                                  For.Name,
                                                                  item.Value == (string)For.ModelExplorer.Model,
                                                                  attributes);
                tagBuilder.Append(inputTagBuilder.GetString());
            });

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div id='{idStr}_checkGroup' class='layui-input-block'>
              {tagBuilder}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Attributes.Add("id", $"{idStr}_div");
            output.Content.SetHtmlContent(outpuHtml);
            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}_checkGroup').bindCheckBoxData('{Url}','{For.Model}','{For.Name}');
                    }});
                </script>");
            }
        }
示例#4
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;
            var attributes    = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" },
                { "type", Type.ToString() }
            };

            if (modelExplorer.Metadata != null && modelExplorer.Metadata.IsRequired)
            {
                attributes["required"] = "required";
            }
            if (Disabled)
            {
                attributes["Disabled"] = "Disabled";
            }

            var value = modelExplorer.Model ?? Value;

            var inputTagBuilder = _generator.GenerateTextBox(ViewContext, modelExplorer, For.Name, value, Format, attributes);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Content.SetHtmlContent(inputTagBuilder);
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
        }
示例#5
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var buttonHtml = string.Format(@"<button id='{0}' lay-filter='{0}' type='button' class='layui-btn layuiadmin-btn-admin' lay-submit>
                        <i class='layui-icon layui-icon-search layuiadmin-button-btn'></i>
               </button>", Id);

            var scriptHtml = $@"<script>
           var form = layui.form;
           var table = layui.table;
           form.on('submit({Id})', function(data) {{
               var field = data.field;

               //执行重载
               table.reload('{TargetFormId}', {{
                   where: field,
                   page: {{
                          curr: 1 
                     }}
               }});
           }});
           </script> ";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", "layui-inline");
            output.Content.SetHtmlContent(buttonHtml);
            output.PostElement.SetHtmlContent(scriptHtml);
        }
示例#6
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;

            var kvList = Data.GetKeyValueList();

            kvList.ForEach(dic =>
            {
                var attributes = new Dictionary <string, object>
                {
                    { "title", dic.Key }
                };
                var inputTagBuilder = _generator.GenerateRadioButton(ViewContext,
                                                                     modelExplorer,
                                                                     For.Name,
                                                                     modelExplorer.Model,
                                                                     dic.Value == (int)(modelExplorer.Model ?? -1),
                                                                     attributes);

                output.Content.AppendHtml(inputTagBuilder);
            });

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
        }
示例#7
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            output.TagName = "form";
            output.TagMode = TagMode.StartTagAndEndTag;

            var htmlAttributes = new Dictionary <string, object>
            {
                { "class", "layui-form layuiadmin-card-header-auto layui-form-pane" },
                { "id", Id },
                { "lay-filter", Id }
            };

            var tagBuilder = _generator.GenerateForm(ViewContext, Action, Controller, null, "post", htmlAttributes);

            output.MergeAttributes(tagBuilder);
            output.PostContent.SetHtmlContent(
                "<div class='layui-form-item layui-hide'><input type='button' lay-submit lay-filter='btn-submit' id='btn-submit' value='确认'> </div>");

            output.PostElement.SetHtmlContent($@"<script>
                $(function () {{
                layui.form.on('submit(btn-submit)', function () {{
                    $('#{Id}').formPost(function () {{
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }});
                }});
            }});
    </script>");
        }
示例#8
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var kvList          = Data.GetKeyValueList();
            var selectListItems = kvList.Select(a => new SelectListItem {
                Text = a.Key, Value = a.Value.ToString(), Selected = a.Value == (int)(For.Model ?? -1)
            }).ToList();

            if (!DefaultText.IsNullOrEmpty())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }
            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, null);

            output.Content.AppendHtml(tagBuilder);
            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", InputDisplay.GetDisplayName());

            var idStr = NameAndIdProvider.CreateSanitizedId(ViewContext, For.Name,
                                                            _generator.IdAttributeDotReplacement);

            if (Data == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent(string.Format(@"<script type='text/javascript'>
                 $(function () {{
                    $('#{0}').bindSelectData('{1}','{2}');
                    }});
                </script>", idStr, Url, For.Model));
            }
        }
示例#9
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            output.TagName = "table";
            output.TagMode = TagMode.StartTagAndEndTag;

            output.Attributes.Add("id", Id);
            if (!Filter.IsNullOrEmpty())
            {
                output.Attributes.Add("lay-filter", Filter);
            }

            var url      = $"url:'/{Controller}/{Action}',";
            var page     = $"page: {Page.ToString().ToLower()},";
            var limit    = $"limit: {Limit},";
            var elem     = $"elem: '#{Id}',";
            var id       = $"id: '{Id}',";
            var multiple = Multiple ? "{ checkbox: true, fixed: true }," : "";
            var toolBar  = ToolBarId.IsNullOrEmpty() ? "" : $"{{title: '操作', fixed: true, width: 160, align: 'center', toolbar: '#{ToolBarId}' }},";

            var propertiyDic = ColsModel.GetProperties().ToDictionary(k => k.Name, v => v.GetCustomAttribute <TableColsAttribute>());

            var cols = new StringBuilder(64);

            foreach (var dic in propertiyDic)
            {
                if (dic.Value == null)
                {
                    continue;
                }

                var field = dic.Value.Field ?? dic.Key.ToCamelCase();
                var title = dic.Value.Tile;
                var width = dic.Value.Width;
                var align = dic.Value.Align.GetDisplayName();
                cols.AppendLine($"{{ field: '{field}', title: '{title}', width: {width},align: '{align}' }},");
            }

            output.PostElement.SetHtmlContent(string.Format(@"<script type='text/javascript'>
                layui.use('table', function() {{
                var table = layui.table;
                table.render({{
                    {0}
                    {1}
                    {2}
                    height: 473,
                    cols: [[
                        {6}
                        {5}
                        {7}
                    ]],
                     {3}
                     {4}
                }});
            }});
            </script>", elem, id, url, page, limit, toolBar, multiple, cols));
        }
示例#10
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;
            var attributes    = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" }
            };

            if (modelExplorer.Metadata != null && modelExplorer.Metadata.IsRequired)
            {
                attributes["required"] = "required";
            }

            var value = modelExplorer.Model ?? Value;

            if (value is DateTime)
            {
                value = ((DateTime)value).ToString(DateTimeType.GetDisplayName());
            }
            var inputTagBuilder = _generator.GenerateTextBox(ViewContext,
                                                             modelExplorer,
                                                             For.Name,
                                                             value,
                                                             Format,
                                                             attributes);



            var dateTimeTypeStr = DateTimeType.ToString();
            var idStr           = TagBuilder.CreateSanitizedId(For.Name,
                                                               _generator.IdAttributeDotReplacement);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(inputTagBuilder);

            output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
             layui.use('laydate',
                    function () {{
                        var laydate = layui.laydate;
                        laydate.render({{
                            elem: '#{idStr}',
                            type: '{dateTimeTypeStr}'
                        }});
                    }});
            </script>");
        }
示例#11
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var inputTagBuilder = Generator.GenerateValidationMessage(
                ViewContext,
                For.ModelExplorer,
                For.Name,
                null,
                null,
                null);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Content.SetHtmlContent(inputTagBuilder);
            output.Attributes.Add("class", "layui-form-mid");
            output.Attributes.Add("style", "color: red");
        }
示例#12
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            output.TagName = "form";
            output.TagMode = TagMode.StartTagAndEndTag;

            var htmlAttributes = new Dictionary <string, object>
            {
                { "class", "layui-form layui-form-pane" },
                { "id", Id }
            };

            var tagBuilder = _generator.GenerateForm(ViewContext, Action, Controller, null, "post", htmlAttributes);

            output.MergeAttributes(tagBuilder);
            output.PostElement.SetHtmlContent(@"<script type='text/javascript'>
                 layui.use('form', function () {{
                    var form = layui.form;
                    form.render();
                }});
            </script>");
        }
示例#13
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;

            var attributes = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder },
                { TextAttributeName, Text ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" }
            };

            if (Disabled)
            {
                attributes["Disabled"] = "Disabled";
            }

            var value   = modelExplorer.Model ?? Value;
            var showUrl = value?.ToString();

            var htmlText  = !attributes[TextAttributeName].ToStr().IsNullOrWhiteSpace() ? $"<label class='layui-form-label'>{attributes[TextAttributeName]}</label>" : "";
            var outpuHtml = $@"
                    {htmlText}
                    <div class='layui-input-inline'>
                        <button id='btn_{For.Name}_up' type='button' class='layui-btn' >上传图片</button>
                <img class='layui-upload-img' id='{For.Name}_imgs1' src='{showUrl}' style='max-width:200px' />
                <p id='{For.Name}_retry'></p>
                <input  id='{For.Name}_imgs2' type = 'hidden' value='{value}' name='{For.Name}'>
                    </div>";

            var idStr = TagBuilder.CreateSanitizedId(For.Name,
                                                     _generator.IdAttributeDotReplacement);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", "layui-form-item");
            output.Attributes.Add("id", $"{idStr}_div");
            output.Content.SetHtmlContent(outpuHtml);

            output.PostElement.SetHtmlContent($@" <script type='text/javascript'>
$(function () {{
                var imageUrl;
            var $ = layui.jquery;
            var upload = layui.upload;

            var uploadInst = upload.render({{
                elem: '#btn_{For.Name}_up',
                url: '/Upload/Img',
                before: function (obj) {{
                    obj.preview(function (index, file, result) {{
                        if (file.size / 1024 / 1024 > 2) {{
                            layer.msg('上传的图片不能超过1M',
                            {{
                                icon: 2,
                                time: 2000
                            }});
                            return false;
                        }}
                        $('#{For.Name}_imgs1').attr('src', result);
                    }});
                }},
                done: function (res) {{
                    if (res.success) {{
                        if (res.data) {{
                            imageUrl = res.data;
                                $('#{For.Name}_imgs2').val(imageUrl);
                        }}
                    }} else {{
                        var demoText = $('#{For.Name}_retry');
                        demoText.html(""<span style='color: #FF5722;'>上传失败</span> <a class='layui-btn layui-btn-xs demo-reload'>重试</a>"");
                        demoText.find('.demo-reload').on('click', function () {{
                            uploadInst.upload();
                        }});
                    }}
                }}
            }});
            }});
            </script>");
        }
示例#14
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem
                {
                    Text  = a.Key.Name.ToString(),
                    Value = a.Value.TryInt().ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = ((IEnumerable <SelectListItem>)Data).ToList();
            }

            if (!DefaultText.IsNullOrWhiteSpace())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }

            var idStr      = TagBuilder.CreateSanitizedId(For.Name, _generator.IdAttributeDotReplacement);
            var attributes = new Dictionary <string, object>
            {
                { "lay-search", "" },
                { "lay-filter", idStr }
            };

            var cValue = For.Metadata.IsEnum ? ((int)(For.Model ?? 0)).ToStr() : For.Model.ToStr();

            selectListItems.ForEach(item =>
            {
                item.Selected = For.Model != null && item.Value == cValue;
            });

            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, attributes);

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div class='layui-input-block'>
              {tagBuilder.GetString().Replace("&amp;nbsp;", "&nbsp;")}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(outpuHtml);
            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}').bindSelectData('{Url}','{For.Model}');
                    }});
                </script>");
            }
        }
示例#15
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem
                {
                    Text  = a.Key.Name.ToString(),
                    Value = a.Value.ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = ((IEnumerable <SelectListItem>)Data).ToList();
            }

            if (!DefaultText.IsNullOrWhiteSpace())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }

            var idStr      = NameAndIdProvider.CreateSanitizedId(ViewContext, For.Name, _generator.IdAttributeDotReplacement);
            var attributes = new Dictionary <string, object>
            {
                { "xm-select", idStr },
                { "xm-select-skin", "default" }
            };

            IList l = new ArrayList();

            if (For.Model != null)
            {
                l = (IList)For.Model;
            }

            selectListItems.ForEach(item =>
            {
                item.Selected = For.Model != null && l.Contains(item.Value);
            });

            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, attributes);

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div class='layui-input-block'>
              {tagBuilder.GetString().Replace("&amp;nbsp;", "&nbsp;")}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(outpuHtml);

            var jsValue = l.Cast <object>().Aggregate("", (current, t) => current + (t + ",")).TrimEnd(',');

            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}').bindMultiSelectData('{Url}','{jsValue}','{idStr}');
                    }});
                </script>");
            }
        }