예제 #1
0
        /// <summary>
        /// 生成按钮
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IHtmlContent AuthButton(this IHtmlHelper htmlHelper, AuthButtonOptions options)
        {
            if (options == null || (options.UseNowVerifyResult && !options.AllowAccess))
            {
                return(HtmlString.Empty);
            }
            if (!options.UseNowVerifyResult)
            {
                var allowAccess = AuthorizeManager.AuthorizeVerifyAsync(new AuthorizeVerifyRequest()
                {
                    ActionCode     = options.AuthorizeFunc?.ActionCode,
                    ControllerCode = options.AuthorizeFunc?.ControllerCode,
                    Application    = ApplicationManager.Current,
                    Claims         = HttpContextHelper.Current.User.Claims.ToDictionary(c => c.Type, c => c.Value)
                }).Result?.AllowAccess ?? false;
                if (!allowAccess)
                {
                    return(HtmlString.Empty);
                }
            }
            var btnTagBuilder     = new TagBuilder("button");
            var btnHtmlAttributes = options.HtmlAttributes ?? new Dictionary <string, object>();

            if (!btnHtmlAttributes.ContainsKey("type"))
            {
                btnHtmlAttributes.Add("type", "button");
            }
            btnTagBuilder.MergeAttributes(btnHtmlAttributes);
            if (options.UseIco)
            {
                var icoTagBuilder = new TagBuilder("i");
                icoTagBuilder.MergeAttributes(options.IcoHtmlAttributes);
                btnTagBuilder.InnerHtml.AppendHtml(icoTagBuilder);
                btnTagBuilder.InnerHtml.Append(" ");
            }
            btnTagBuilder.InnerHtml.Append(options.Text);
            return(btnTagBuilder);
        }