private BaseModal GetModal(string modalId) { var nav = BaseData.GetNavModel(modalId); if (nav == null) { throw new ZzbException("modalId不正确,无法找到对应菜单"); } if (!(HttpContextAccessor.HttpContext.RequestServices.GetService(nav.Type) is BaseModal ins)) { throw new ZzbException("modalId不正确或类没有无参构造函数,反射BaseModal失败"); } return(ins); }
public TableInfomationModel GetTableInfomation(string navId) { var nav = BaseData.GetNavModel(navId); if (nav == null) { throw new ZzbException("navId不正确,无法找到对应菜单"); } TableInfomationModel model = new TableInfomationModel(); model.NavColumns = CreateNavFields(nav.Type); var ins = GetNav(navId); if (ins == null) { throw new ZzbException("反射失败,该类不是BaseNav"); } model.TableName = ins.NavName; #region 获取查询字段 var fields = ins.GetQueryConditionses(); if (fields != null) { model.QueryFields = CreateFields(fields); } #endregion #region 获取页面按钮 var buttons = ins.CreateViewButtons(); if (buttons != null) { model.ViewButtons = from b in buttons select new { b.Id, Name = b.ButtonName, b.Type, b.Icon, (b as BaseModal)?.ModalId, (b as JsActionButton)?.ActionType }; } model.ShowOperaColumn = ins.ShowOperaColumn; model.OperaColumnWidth = ins.OperaColumnWidth; #endregion return(model); }
/// <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); }