public ServiceResult HandleNavAction(string navId, string buttonId, Dictionary <string, string> data) { var nav = GetNav(navId); if (nav.CreateRowButtons().FirstOrDefault(t => t.Id == buttonId) == null) { throw new ZzbException("当前buttonId没有按钮,出现不可能错误"); } var method = nav.GetType().GetMethod(buttonId); if (method == null) { throw new ZzbException("没有找到反射方法"); } foreach (PropertyInfo propertyInfo in nav.GetType().GetProperties()) { if (data.ContainsKey(propertyInfo.Name)) { propertyInfo.SetValue(nav, BaseStringHandle.GetValue(propertyInfo.PropertyType, data[propertyInfo.Name])); } } var s = method.Invoke(nav, null); if (s is ServiceResult) { return(s as ServiceResult); } else { return(new ServiceResult(ServiceResultCode.Success)); } }
public object GetButtonModalInfo(string modalId, Dictionary <string, string> data) { var button = GetModal(modalId); if (data != null) { foreach (PropertyInfo propertyInfo in button.GetType().GetProperties()) { if (data.ContainsKey(propertyInfo.Name)) { propertyInfo.SetValue(button, BaseStringHandle.GetValue(propertyInfo.PropertyType, data[propertyInfo.Name])); } } } button.Init(); List <BaseFieldAttribute> list = new List <BaseFieldAttribute>(); foreach (PropertyInfo propertyInfo in button.GetType().GetProperties()) { var field = propertyInfo.GetCustomAttribute <BaseFieldAttribute>(); if (field != null) { field.PropertyType = propertyInfo.PropertyType; field.HttpContextAccessor = HttpContextAccessor; field.Id = Guid.NewGuid().ToString("N") + propertyInfo.Name; field.Value = BaseStringHandle.Handle(propertyInfo.PropertyType, propertyInfo.GetValue(button)); list.Add(field); } } return(new { Fields = CreateFields(list.ToArray()), Buttons = from b in button.Buttons() select new { b.Id, b.Type, b.Icon, Name = b.ButtonName }, Title = button.ModalName }); }
public ServiceResult HandleModalAction(string modalId, string buttonId, Dictionary <string, string> data) { var button = GetModal(modalId); if (button.Buttons().FirstOrDefault(t => t.Id == buttonId) == null) { throw new ZzbException("当前buttonId没有按钮,出现不可能错误"); } var method = button.GetType().GetMethod(buttonId); if (method == null) { throw new ZzbException("没有找到反射方法"); } var ins = HttpContextAccessor.HttpContext.RequestServices.GetService(button.GetType());//button.GetType().Assembly.CreateInstance(button.GetType().FullName); foreach (PropertyInfo propertyInfo in button.GetType().GetProperties()) { if (data.ContainsKey(propertyInfo.Name)) { propertyInfo.SetValue(ins, BaseStringHandle.GetValue(propertyInfo.PropertyType, data[propertyInfo.Name])); } } var s = method.Invoke(ins, null); if (s is ServiceResult) { return(s as ServiceResult); } else { return(new ServiceResult(ServiceResultCode.Success)); } }
/// <summary> /// 获取表格数据 /// </summary> /// <param name="navId">主键</param> /// <param name="limit">获取多少条数据</param> /// <param name="offset">跳过多少条数据</param> public NavRowDatasModel GetRowsData(string navId, int limit, int offset, Dictionary <string, string> query) { var nav = BaseData.GetNavModel(navId); if (nav == null) { throw new ZzbException("navId不正确,无法找到对应菜单"); } if (!(HttpContextAccessor.HttpContext.RequestServices.GetService(nav.Type) is BaseNav baseNav)) { throw new ZzbException("BaseData反射失败"); } NavRowDatasModel model = new NavRowDatasModel(); var datas = baseNav.GetNavDatas(limit, offset, query, out var total); model.Total = total; //获取数据 if (datas != null && datas.Any()) { model.Rows = new Dictionary <string, object> [datas.Length]; for (int i = 0; i < datas.Length; i++) { model.Rows[i] = new Dictionary <string, object>(); //添加字段数据 foreach (PropertyInfo propertyInfo in nav.Type.GetProperties()) { var field = propertyInfo.GetCustomAttribute <NavFieldAttribute>(); if (field != null) { var value = BaseStringHandle.Handle(propertyInfo.PropertyType, propertyInfo.GetValue(datas[i])); if (field.IsKey) { model.Rows[i].Add("key", value); } model.Rows[i].Add(propertyInfo.Name, value); if (propertyInfo.PropertyType == typeof(bool)) { model.Rows[i].Add(propertyInfo.Name + "_Value", value == "1" ? "是" : "否"); } if (propertyInfo.PropertyType.BaseType == typeof(Enum)) { model.Rows[i].Add(propertyInfo.Name + "_Value", ((Enum)Enum.Parse(propertyInfo.PropertyType, value.ToString())).ToDescriptionString()); } } } if (datas[i] is BaseNav navOne) { var buttons = navOne.CreateRowButtons(); if (buttons != null && buttons.Length > 0) { List <Object> lis = new List <object>(); foreach (var b in buttons) { BaseModal tempModal = b as BaseModal; ConfirmActionButton cb = b as ConfirmActionButton; lis.Add(new { ConfirmMessage = cb?.ConfirmMessage, ButtonName = b.ButtonName, ButtonType = b.ButtonType, Icon = b.Icon, Id = b.Id, Type = b.Type, ModalId = tempModal?.ModalId }); } model.Rows[i].Add("Zzb_Buttons", lis); } } else { throw new ZzbException(nav.Type + "类型的GetNavDatas返回的不是本类型数组!"); } } } return(model); }