544 lines
20 KiB
C#
544 lines
20 KiB
C#
using JNPF.Common.Const;
|
|
using JNPF.Common.Models;
|
|
using JNPF.Common.Security;
|
|
using JNPF.VisualDev.Entitys.Enum;
|
|
|
|
namespace JNPF.VisualDev.Engine.Security;
|
|
|
|
/// <summary>
|
|
/// 代码生成控件属性帮助类.
|
|
/// </summary>
|
|
public class CodeGenControlsAttributeHelper
|
|
{
|
|
/// <summary>
|
|
/// 转换静态数据.
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static List<StaticDataModel> ConversionStaticData(string data)
|
|
{
|
|
var list = new List<StaticDataModel>();
|
|
if (!string.IsNullOrEmpty(data))
|
|
{
|
|
var conData = data.ToObject<List<StaticDataModel>>();
|
|
if (conData != null)
|
|
{
|
|
foreach (var item in conData)
|
|
{
|
|
list.Add(new StaticDataModel()
|
|
{
|
|
id = item.id,
|
|
fullName = item.fullName,
|
|
});
|
|
if (item.children != null)
|
|
list.AddRange(ConversionStaticData(item.children.ToJsonString()));
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断控件是否数据转换.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static bool JudgeControlIsDataConversion(string jnpfKey, string dataType, bool multiple)
|
|
{
|
|
bool tag = false;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.UPLOADFZ:
|
|
case JnpfKeyConst.UPLOADIMG:
|
|
tag = true;
|
|
break;
|
|
case JnpfKeyConst.SELECT:
|
|
case JnpfKeyConst.TREESELECT:
|
|
{
|
|
switch (dataType)
|
|
{
|
|
case "dictionary":
|
|
if (!multiple)
|
|
{
|
|
tag = false;
|
|
}
|
|
else
|
|
{
|
|
tag = true;
|
|
}
|
|
|
|
break;
|
|
default:
|
|
tag = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.RADIO:
|
|
{
|
|
switch (dataType)
|
|
{
|
|
case "dictionary":
|
|
tag = false;
|
|
break;
|
|
default:
|
|
tag = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.DEPSELECT:
|
|
case JnpfKeyConst.POSSELECT:
|
|
case JnpfKeyConst.USERSELECT:
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
case JnpfKeyConst.ROLESELECT:
|
|
case JnpfKeyConst.GROUPSELECT:
|
|
{
|
|
if (!multiple)
|
|
tag = false;
|
|
else
|
|
tag = true;
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.CHECKBOX:
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.COMSELECT:
|
|
case JnpfKeyConst.ADDRESS:
|
|
tag = true;
|
|
break;
|
|
}
|
|
|
|
return tag;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取各模式控件是否列表转换.
|
|
/// </summary>
|
|
/// <param name="generatePattern">生成模式.</param>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <param name="dataType">数据类型 dictionary-数据字段,dynamic-远端数据.</param>
|
|
/// <param name="multiple">是否多选.</param>
|
|
/// <param name="subTableListDisplay">子表列表显示.</param>
|
|
/// <returns>true-ThenMapper转换,false-列表转换.</returns>
|
|
public static bool GetWhetherToConvertAllModeControlsIntoLists(GeneratePatterns generatePattern, string jnpfKey, string dataType, bool multiple, bool subTableListDisplay)
|
|
{
|
|
bool tag = false;
|
|
|
|
/*
|
|
* 因ORM原因 导航查询 一对多 列表查询
|
|
* 不能使用ORM 自带函数 待作者开放.Select()
|
|
* 导致一对多列表查询转换必须全使用子查询
|
|
* 远端数据与静态数据无法列表转换所以全部ThenMapper内转换
|
|
* 数据字典又分为两种值转换ID与EnCode
|
|
*/
|
|
switch (subTableListDisplay)
|
|
{
|
|
case true:
|
|
switch (generatePattern)
|
|
{
|
|
case GeneratePatterns.MainBelt:
|
|
case GeneratePatterns.PrimarySecondary:
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.CREATEUSER:
|
|
case JnpfKeyConst.MODIFYUSER:
|
|
case JnpfKeyConst.CURRORGANIZE:
|
|
case JnpfKeyConst.CURRPOSITION:
|
|
case JnpfKeyConst.DEPSELECT:
|
|
case JnpfKeyConst.POSSELECT:
|
|
case JnpfKeyConst.USERSELECT:
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
case JnpfKeyConst.ROLESELECT:
|
|
case JnpfKeyConst.GROUPSELECT:
|
|
case JnpfKeyConst.RADIO:
|
|
case JnpfKeyConst.SELECT:
|
|
case JnpfKeyConst.TREESELECT:
|
|
case JnpfKeyConst.CHECKBOX:
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.COMSELECT:
|
|
case JnpfKeyConst.ADDRESS:
|
|
case JnpfKeyConst.SWITCH:
|
|
tag = true;
|
|
break;
|
|
}
|
|
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.SELECT:
|
|
case JnpfKeyConst.TREESELECT:
|
|
{
|
|
switch (dataType)
|
|
{
|
|
case "dictionary":
|
|
if (multiple)
|
|
tag = true;
|
|
else
|
|
tag = false;
|
|
break;
|
|
default:
|
|
tag = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.RADIO:
|
|
{
|
|
switch (dataType)
|
|
{
|
|
case "dictionary":
|
|
tag = false;
|
|
break;
|
|
default:
|
|
tag = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.DEPSELECT:
|
|
case JnpfKeyConst.POSSELECT:
|
|
case JnpfKeyConst.USERSELECT:
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
case JnpfKeyConst.ROLESELECT:
|
|
case JnpfKeyConst.GROUPSELECT:
|
|
{
|
|
if (multiple)
|
|
tag = true;
|
|
else
|
|
tag = false;
|
|
}
|
|
|
|
break;
|
|
case JnpfKeyConst.CHECKBOX:
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.COMSELECT:
|
|
case JnpfKeyConst.ADDRESS:
|
|
tag = true;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
return tag;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断含子表字段控件是否数据转换.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <returns></returns>
|
|
public static bool JudgeContainsChildTableControlIsDataConversion(string jnpfKey)
|
|
{
|
|
bool tag = false;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.UPLOADFZ:
|
|
case JnpfKeyConst.UPLOADIMG:
|
|
case JnpfKeyConst.CREATEUSER:
|
|
case JnpfKeyConst.MODIFYUSER:
|
|
case JnpfKeyConst.CURRORGANIZE:
|
|
case JnpfKeyConst.CURRPOSITION:
|
|
case JnpfKeyConst.DEPSELECT:
|
|
case JnpfKeyConst.POSSELECT:
|
|
case JnpfKeyConst.USERSELECT:
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
case JnpfKeyConst.ROLESELECT:
|
|
case JnpfKeyConst.GROUPSELECT:
|
|
case JnpfKeyConst.RADIO:
|
|
case JnpfKeyConst.SELECT:
|
|
case JnpfKeyConst.TREESELECT:
|
|
case JnpfKeyConst.CHECKBOX:
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.COMSELECT:
|
|
case JnpfKeyConst.ADDRESS:
|
|
case JnpfKeyConst.SWITCH:
|
|
tag = true;
|
|
break;
|
|
}
|
|
|
|
return tag;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 系统控件不更新.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <returns></returns>
|
|
public static bool JudgeControlIsSystemControls(string jnpfKey)
|
|
{
|
|
bool tag = true;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.CREATEUSER:
|
|
case JnpfKeyConst.CREATETIME:
|
|
case JnpfKeyConst.CURRPOSITION:
|
|
case JnpfKeyConst.CURRORGANIZE:
|
|
case JnpfKeyConst.BILLRULE:
|
|
tag = false;
|
|
break;
|
|
}
|
|
|
|
return tag;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取控件数据来源ID.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <param name="dataType">数据类型.</param>
|
|
/// <param name="control">控件全属性.</param>
|
|
/// <returns></returns>
|
|
public static string GetControlsPropsUrl(string jnpfKey, string dataType, FieldsModel control)
|
|
{
|
|
string propsUrl = string.Empty;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
propsUrl = control.interfaceId;
|
|
break;
|
|
default:
|
|
switch (dataType)
|
|
{
|
|
case "dictionary":
|
|
propsUrl = control.__config__.dictionaryType;
|
|
break;
|
|
default:
|
|
propsUrl = control.__config__.propsUrl;
|
|
break;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return propsUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取控件指定选项的值.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <param name="dataType">数据类型.</param>
|
|
/// <param name="control">控件全属性.</param>
|
|
/// <returns></returns>
|
|
public static string GetControlsLabel(string jnpfKey, string dataType, FieldsModel control)
|
|
{
|
|
string label = string.Empty;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
label = control.relationField;
|
|
break;
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.TREESELECT:
|
|
label = control.props.props.label;
|
|
break;
|
|
default:
|
|
label = control.__config__.props?.label;
|
|
break;
|
|
}
|
|
|
|
return label;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取控件指定选项标签.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <param name="dataType">数据类型.</param>
|
|
/// <param name="control">控件全属性.</param>
|
|
/// <returns></returns>
|
|
public static string GetControlsValue(string jnpfKey, string dataType, FieldsModel control)
|
|
{
|
|
string value = string.Empty;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.POPUPTABLESELECT:
|
|
value = control.propsValue;
|
|
break;
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.TREESELECT:
|
|
value = control.props.props.value;
|
|
break;
|
|
default:
|
|
value = control.__config__.props?.value;
|
|
break;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取控件指定选项的子选项.
|
|
/// </summary>
|
|
/// <param name="jnpfKey">控件Key.</param>
|
|
/// <param name="dataType">数据类型.</param>
|
|
/// <param name="control">控件全属性.</param>
|
|
/// <returns></returns>
|
|
public static string GetControlsChildren(string jnpfKey, string dataType, FieldsModel control)
|
|
{
|
|
string children = string.Empty;
|
|
switch (jnpfKey)
|
|
{
|
|
case JnpfKeyConst.CASCADER:
|
|
case JnpfKeyConst.TREESELECT:
|
|
children = control.props.props.children;
|
|
break;
|
|
default:
|
|
children = control.__config__.props?.children;
|
|
break;
|
|
}
|
|
|
|
return children;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取导出配置.
|
|
/// </summary>
|
|
/// <param name="control">控件全属性.</param>
|
|
/// <param name="model">数据库真实字段.</param>
|
|
/// <param name="tableName">表名称.</param>
|
|
/// <returns></returns>
|
|
public static CodeGenFieldsModel GetImportConfig(FieldsModel control, string model, string tableName)
|
|
{
|
|
var fieldModel = new CodeGenFieldsModel();
|
|
var configModel = new CodeGenConfigModel();
|
|
fieldModel.__vModel__ = model;
|
|
fieldModel.level = control.level;
|
|
fieldModel.min = control.min;
|
|
fieldModel.max = control.max;
|
|
fieldModel.activeTxt = control.activeTxt;
|
|
fieldModel.inactiveTxt = control.inactiveTxt;
|
|
fieldModel.format = control.format;
|
|
fieldModel.multiple = CodeGenFieldJudgeHelper.IsMultipleColumn(control, model);
|
|
fieldModel.separator = control.separator;
|
|
fieldModel.__slot__ = control.__slot__?.ToObject<CodeGenSlotModel>()?.ToJsonString().ToJsonString();
|
|
fieldModel.props = control.props?.ToObject<CodeGenPropsModel>()?.ToJsonString().ToJsonString();
|
|
fieldModel.options = control.options?.ToObject<List<object>>()?.ToJsonString().ToJsonString();
|
|
fieldModel.propsValue = control.propsValue;
|
|
fieldModel.relationField = control.relationField;
|
|
fieldModel.modelId = control.modelId;
|
|
fieldModel.interfaceId = control.interfaceId;
|
|
fieldModel.selectType = control.selectType;
|
|
fieldModel.ableDepIds = control.ableDepIds?.ToJsonString().ToJsonString();
|
|
fieldModel.ablePosIds = control.ablePosIds?.ToJsonString().ToJsonString();
|
|
fieldModel.ableUserIds = control.ableUserIds?.ToJsonString().ToJsonString();
|
|
fieldModel.ableRoleIds = control.ableRoleIds?.ToJsonString().ToJsonString();
|
|
fieldModel.ableGroupIds = control.ableGroupIds?.ToJsonString().ToJsonString();
|
|
fieldModel.ableIds = control.ableIds?.ToJsonString().ToJsonString();
|
|
configModel = control.__config__.ToObject<CodeGenConfigModel>();
|
|
configModel.tableName = tableName;
|
|
fieldModel.__config__ = configModel.ToJsonString().ToJsonString();
|
|
return fieldModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取需解析的字段集合.
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
/// <param name="isInlineEditor"></param>
|
|
/// <returns>jnpfKey @@ vmodel集合以 , 号隔开.</returns>
|
|
public static List<string[]> GetParsJnpfKeyConstList(List<FieldsModel> control, bool isInlineEditor)
|
|
{
|
|
var res = new Dictionary<string, List<string>>();
|
|
|
|
control.ForEach(item =>
|
|
{
|
|
switch (item.__config__.jnpfKey)
|
|
{
|
|
case JnpfKeyConst.USERSSELECT: // 用户选择组件(包含组织、角色、岗位、分组、用户 Id)
|
|
if (!res.ContainsKey(JnpfKeyConst.USERSSELECT)) res.Add(JnpfKeyConst.USERSSELECT, new List<string>());
|
|
res[JnpfKeyConst.USERSSELECT].Add(item.__vModel__);
|
|
break;
|
|
case JnpfKeyConst.TABLE: // 遍历 子表 控件
|
|
var ctRes = GetParsJnpfKeyConstList(item.__config__.children, isInlineEditor);
|
|
if (ctRes != null && ctRes.Any())
|
|
{
|
|
foreach (var ct in ctRes)
|
|
{
|
|
if (!res.ContainsKey(ct.FirstOrDefault())) res.Add(ct.FirstOrDefault(), new List<string>());
|
|
res[ct.FirstOrDefault()].AddRange(ct.LastOrDefault().Split(','));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
});
|
|
|
|
var ret = new List<string[]>();
|
|
foreach (var item in res)
|
|
{
|
|
// 如果是行内编辑
|
|
if (isInlineEditor)
|
|
{
|
|
var newValue = new List<string>();
|
|
foreach (var it in item.Value) newValue.Add(it + "_name");
|
|
res[item.Key] = newValue;
|
|
}
|
|
}
|
|
foreach (var item in res)
|
|
{
|
|
ret.Add(new string[] { item.Key, string.Join(",", item.Value) });
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取需解析的字段集合.
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
/// <param name="isInlineEditor"></param>
|
|
/// <returns>jnpfKey @@ vmodel集合以 , 号隔开.</returns>
|
|
public static List<string[]> GetParsJnpfKeyConstListDetails(List<FieldsModel> control)
|
|
{
|
|
var res = new Dictionary<string, List<string>>();
|
|
|
|
control.ForEach(item =>
|
|
{
|
|
switch (item.__config__.jnpfKey)
|
|
{
|
|
case JnpfKeyConst.USERSSELECT: // 用户选择组件(包含组织、角色、岗位、分组、用户 Id)
|
|
if (!res.ContainsKey(JnpfKeyConst.USERSSELECT)) res.Add(JnpfKeyConst.USERSSELECT, new List<string>());
|
|
res[JnpfKeyConst.USERSSELECT].Add(item.__vModel__);
|
|
break;
|
|
case JnpfKeyConst.POPUPTABLESELECT: // 下拉表格.
|
|
if (!res.ContainsKey(JnpfKeyConst.POPUPTABLESELECT)) res.Add(JnpfKeyConst.POPUPTABLESELECT, new List<string>());
|
|
res[JnpfKeyConst.POPUPTABLESELECT].Add(item.__vModel__);
|
|
break;
|
|
case JnpfKeyConst.POPUPSELECT: // 弹窗选择.
|
|
if (!res.ContainsKey(JnpfKeyConst.POPUPSELECT)) res.Add(JnpfKeyConst.POPUPSELECT, new List<string>());
|
|
res[JnpfKeyConst.POPUPSELECT].Add(item.__vModel__);
|
|
break;
|
|
case JnpfKeyConst.RELATIONFORM: // 关联表单.
|
|
if (!res.ContainsKey(JnpfKeyConst.RELATIONFORM)) res.Add(JnpfKeyConst.RELATIONFORM, new List<string>());
|
|
res[JnpfKeyConst.RELATIONFORM].Add(item.__vModel__);
|
|
break;
|
|
case JnpfKeyConst.TABLE: // 遍历 子表 控件
|
|
var ctRes = GetParsJnpfKeyConstListDetails(item.__config__.children);
|
|
if (ctRes != null && ctRes.Any())
|
|
{
|
|
foreach (var ct in ctRes)
|
|
{
|
|
if (!res.ContainsKey(item.__vModel__ + "-" + ct.FirstOrDefault())) res.Add(item.__vModel__ + "-" + ct.FirstOrDefault(), new List<string>());
|
|
res[item.__vModel__ + "-" + ct.FirstOrDefault()].AddRange(ct.LastOrDefault().Split(','));
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
});
|
|
|
|
var ret = new List<string[]>();
|
|
foreach (var item in res)
|
|
{
|
|
ret.Add(new string[] { item.Key, string.Join(",", item.Value) });
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
} |