using System.Text;
using System.Text.RegularExpressions;
using JNPF.Common.Const;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.VisualDev.Engine.Model.CodeGen;
namespace JNPF.VisualDev.Engine.Security;
///
/// 代码生成表单控件设计帮助类.
///
public class CodeGenFormControlDesignHelper
{
private static int active = 1;
///
/// 表单控件设计.
///
/// 组件列表.
/// 真实控件.
/// 间隔.
/// 标签宽度.
/// 列表显示列列表.
/// 数据类型
/// 1-普通列表,2-左侧树形+普通表格,3-分组表格,4-编辑表格.
/// 4-PC,5-App.
/// 是否主循环.
///
public static List FormControlDesign(List fieldList, List realisticControls, int gutter, int labelWidth, List columnDesignModel, int dataType, int logic, bool isMain = false)
{
if (isMain) active = 1;
List list = new List();
foreach (var item in fieldList)
{
var config = item.__config__;
switch (config.jnpfKey)
{
case JnpfKeyConst.ROW:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
Gutter = gutter,
Children = FormControlDesign(config.children, realisticControls, gutter, labelWidth, columnDesignModel, dataType, logic)
});
}
break;
case JnpfKeyConst.TABLE:
{
List childrenTableList = new List();
var childrenRealisticControls = realisticControls.Find(it => it.__vModel__.Equals(item.__vModel__) && it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)).__config__.children;
foreach (var children in config.children)
{
var childrenConfig = children.__config__;
switch (childrenConfig.jnpfKey)
{
case JnpfKeyConst.RELATIONFORMATTR:
case JnpfKeyConst.POPUPATTR:
{
var relationField = Regex.Match(children.relationField, @"^(.+)_jnpfTable_").Groups[1].Value;
relationField = relationField.Replace(string.Format("jnpf_{0}_jnpf_", childrenConfig.relationTable), "");
var relationControl = config.children.Find(it => it.__vModel__ == relationField);
childrenTableList.Add(new FormControlDesignModel()
{
vModel = children.__vModel__.IsNotEmptyOrNull() ? string.Format("v-model=\"scope.row.{0}\"", children.__vModel__) : string.Empty,
Style = children.style != null && !children.style.ToString().Equals("{}") ? $":style='{children.style.ToJsonString()}' " : string.Empty,
jnpfKey = childrenConfig.jnpfKey,
OriginalName = childrenConfig.isStorage == 2 ? children.__vModel__ : relationField,
Name = childrenConfig.isStorage == 2 ? children.__vModel__ : relationField,
RelationField = relationField,
ShowField = children.showField,
NoShow = relationControl.__config__.noShow ? "v-if='false' " : string.Empty,
Tag = childrenConfig.tag,
Label = childrenConfig.label,
Span = childrenConfig.span,
IsStorage = childrenConfig.isStorage,
LabelWidth = childrenConfig?.labelWidth ?? labelWidth,
ColumnWidth = childrenConfig?.columnWidth != null ? $"width='{childrenConfig.columnWidth}' " : null,
required = childrenConfig.required,
});
}
break;
default:
{
var realisticControl = childrenRealisticControls.Find(it => it.__vModel__.Equals(children.__vModel__) && it.__config__.jnpfKey.Equals(childrenConfig.jnpfKey));
childrenTableList.Add(new FormControlDesignModel()
{
jnpfKey = childrenConfig.jnpfKey,
Name = children.__vModel__,
OriginalName = children.__vModel__,
Style = children.style != null && !children.style.ToString().Equals("{}") ? $":style='{children.style.ToJsonString()}' " : string.Empty,
Span = childrenConfig.span,
Placeholder = children.placeholder != null ? $"placeholder='{children.placeholder}' " : string.Empty,
Clearable = children.clearable ? "clearable " : string.Empty,
Readonly = children.@readonly ? "readonly " : string.Empty,
Disabled = children.disabled ? "disabled " : string.Empty,
IsDisabled = item.disabled ? "disabled " : string.Format(":disabled=\"judgeWrite('{0}') || judgeWrite('{0}-{1}')\" ", item.__vModel__, children.__vModel__),
ShowWordLimit = children.showWordlimit ? "show-word-limit " : string.Empty,
Type = children.type != null ? $"type='{children.type}' " : string.Empty,
Format = children.format != null ? $"format='{children.format}' " : string.Empty,
ValueFormat = children.valueformat != null ? $"value-format='{children.valueformat}' " : string.Empty,
AutoSize = children.autosize != null ? $":autosize='{children.autosize.ToJsonString()}' " : string.Empty,
Multiple = (childrenConfig.jnpfKey.Equals(JnpfKeyConst.CASCADER) ? children.props.props.multiple : children.multiple) ? $"multiple " : string.Empty,
Size = childrenConfig.optionType != null ? (childrenConfig.optionType == "default" ? string.Empty : $"size='{children.size}' ") : string.Empty,
PrefixIcon = !string.IsNullOrEmpty(children.prefixicon) ? $"prefix-icon='{children.prefixicon}' " : string.Empty,
SuffixIcon = !string.IsNullOrEmpty(children.suffixicon) ? $"suffix-icon='{children.suffixicon}' " : string.Empty,
MaxLength = !string.IsNullOrEmpty(children.maxlength) ? $"maxlength='{children.maxlength}' " : string.Empty,
ShowPassword = children.showPassword ? "show-password " : string.Empty,
Filterable = children.filterable ? "filterable " : string.Empty,
Label = childrenConfig.label,
Props = childrenConfig.props,
MainProps = children.props != null ? $":props='{string.Format("{0}_{1}", item.__vModel__, children.__vModel__)}Props' " : string.Empty,
Tag = childrenConfig.tag,
Options = children.options != null ? (realisticControl.IsLinkage ? $":options='{string.Format("scope.row.{0}", children.__vModel__)}Options' " : $":options='{string.Format("{0}_{1}", item.__vModel__, children.__vModel__)}Options' ") : string.Empty,
ShowAllLevels = children.showalllevels ? "show-all-levels " : string.Empty,
Separator = !string.IsNullOrEmpty(children.separator) ? $"separator='{children.separator}' " : string.Empty,
RangeSeparator = !string.IsNullOrEmpty(children.rangeseparator) ? $"range-separator='{children.rangeseparator}' " : string.Empty,
StartPlaceholder = !string.IsNullOrEmpty(children.startplaceholder) ? $"start-placeholder='{children.startplaceholder}' " : string.Empty,
EndPlaceholder = !string.IsNullOrEmpty(children.endplaceholder) ? $"end-placeholder='{children.endplaceholder}' " : string.Empty,
PickerOptions = children.pickeroptions != null && children.pickeroptions.ToJsonString() != "null" ? $":picker-options='{children.pickeroptions.ToJsonString()}' " : string.Empty,
Required = childrenConfig.required ? "required " : string.Empty,
Step = children.step != null ? $":step='{children.step}' " : string.Empty,
StepStrictly = children.stepstrictly ? "step-strictly " : string.Empty,
Max = children.max != null && children.max != 0 ? $":max='{children.max}' " : string.Empty,
Min = children.min != null ? $":min='{children.min}' " : string.Empty,
ColumnWidth = childrenConfig.columnWidth != null ? $"width='{childrenConfig.columnWidth}' " : null,
ModelId = children.modelId != null ? children.modelId : string.Empty,
RelationField = children.relationField != null ? $"relationField='{children.relationField}' " : string.Empty,
ColumnOptions = children.columnOptions != null ? $":columnOptions='{string.Format("{0}_{1}", item.__vModel__, children.__vModel__)}Options' " : string.Empty,
TemplateJson = childrenConfig.jnpfKey.Equals(JnpfKeyConst.POPUPTABLESELECT) || childrenConfig.jnpfKey.Equals(JnpfKeyConst.POPUPSELECT) ? string.Format(":templateJson='{0}_{1}TemplateJson' ", item.__vModel__, children.__vModel__) : string.Empty,
HasPage = children.hasPage ? "hasPage " : string.Empty,
PageSize = children.pageSize != null ? $":pageSize='{children.pageSize}' " : string.Empty,
PropsValue = children.propsValue != null ? $"propsValue='{children.propsValue}' " : string.Empty,
InterfaceId = children.interfaceId != null ? $"interfaceId='{children.interfaceId}' " : string.Empty,
Precision = children.precision != null ? $":precision='{children.precision}' " : string.Empty,
ActiveText = !string.IsNullOrEmpty(children.activetext) ? $"active-text='{children.activetext}' " : string.Empty,
InactiveText = !string.IsNullOrEmpty(children.inactivetext) ? $"inactive-text='{children.inactivetext}' " : string.Empty,
ActiveColor = !string.IsNullOrEmpty(children.activecolor) ? $"active-color='{children.activecolor}' " : string.Empty,
InactiveColor = !string.IsNullOrEmpty(children.inactivecolor) ? $"inactive-color='{children.inactivecolor}' " : string.Empty,
IsSwitch = childrenConfig.jnpfKey == JnpfKeyConst.SWITCH ? $":active-value='{children.activevalue}' :inactive-value='{children.inactivevalue}' " : string.Empty,
ShowStops = children.showstops ? $"show-stops " : string.Empty,
Accept = !string.IsNullOrEmpty(children.accept) ? $"accept='{children.accept}' " : string.Empty,
ShowTip = children.showTip ? $"showTip " : string.Empty,
FileSize = children.fileSize != null && !string.IsNullOrEmpty(children.fileSize.ToString()) ? $":fileSize='{children.fileSize}' " : string.Empty,
SizeUnit = !string.IsNullOrEmpty(children.sizeUnit) ? $"sizeUnit='{children.sizeUnit}' " : string.Empty,
Limit = children.limit != null ? $":limit='{children.limit}' " : string.Empty,
ButtonText = !string.IsNullOrEmpty(children.buttonText) ? $"buttonText='{children.buttonText}' " : string.Empty,
Level = childrenConfig.jnpfKey == JnpfKeyConst.ADDRESS ? $":level='{children.level}' " : string.Empty,
NoShow = childrenConfig.noShow ? "v-if='false' " : string.Empty,
Prepend = children.__slot__ != null && !string.IsNullOrEmpty(children.__slot__.prepend) ? children.__slot__.prepend : null,
Append = children.__slot__ != null && !string.IsNullOrEmpty(children.__slot__.append) ? children.__slot__.append : null,
ShowLevel = !string.IsNullOrEmpty(children.showLevel) ? string.Empty : string.Empty,
LabelWidth = childrenConfig?.labelWidth ?? labelWidth,
IsStorage = config.isStorage,
PopupType = !string.IsNullOrEmpty(children.popupType) ? $"popupType='{children.popupType}' " : string.Empty,
PopupTitle = !string.IsNullOrEmpty(children.popupTitle) ? $"popupTitle='{children.popupTitle}' " : string.Empty,
PopupWidth = !string.IsNullOrEmpty(children.popupWidth) ? $"popupWidth='{children.popupWidth}' " : string.Empty,
Field = childrenConfig.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM) || childrenConfig.jnpfKey.Equals(JnpfKeyConst.POPUPSELECT) ? $":field=\"'{children.__vModel__}'+scope.$index\" " : string.Empty,
required = childrenConfig.required,
SelectType = children.selectType != null ? children.selectType : string.Empty,
AbleDepIds = children.selectType != null && children.selectType == "custom" && (childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSELECT) || childrenConfig.jnpfKey.Equals(JnpfKeyConst.DEPSELECT)) ? string.Format(":ableDepIds='{0}_{1}_AbleDepIds' ", item.__vModel__, children.__vModel__) : string.Empty,
AblePosIds = children.selectType != null && children.selectType == "custom" && (childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSELECT) || childrenConfig.jnpfKey.Equals(JnpfKeyConst.POSSELECT)) ? string.Format(":ablePosIds='{0}_{1}_AblePosIds' ", item.__vModel__, children.__vModel__) : string.Empty,
AbleUserIds = children.selectType != null && children.selectType == "custom" && childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableUserIds='{0}_{1}_AbleUserIds' ", item.__vModel__, children.__vModel__) : string.Empty,
AbleRoleIds = children.selectType != null && children.selectType == "custom" && childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableRoleIds='{0}_{1}_AbleRoleIds' ", item.__vModel__, children.__vModel__) : string.Empty,
AbleGroupIds = children.selectType != null && children.selectType == "custom" && childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableGroupIds='{0}_{1}_AbleGroupIds' ", item.__vModel__, children.__vModel__) : string.Empty,
AbleIds = children.selectType != null && children.selectType == "custom" && childrenConfig.jnpfKey.Equals(JnpfKeyConst.USERSSELECT) ? string.Format(":ableIds='{0}_{1}_AbleIds' ", item.__vModel__, children.__vModel__) : string.Empty,
UserRelationAttr = GetUserRelationAttr(children, realisticControls, logic),
IsLinked = realisticControl.IsLinked,
IsLinkage = realisticControl.IsLinkage,
IsRelationForm = childrenConfig.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM),
PathType = !string.IsNullOrEmpty(children.pathType) ? string.Format("pathType=\"{0}\" ", children.pathType) : string.Empty,
IsAccount = children.isAccount != -1 ? string.Format(":isAccount=\"{0}\" ", children.isAccount) : string.Empty,
Folder = !string.IsNullOrEmpty(children.folder) ? string.Format("folder=\"{0}\" ", children.folder) : string.Empty,
DefaultCurrent = childrenConfig.defaultCurrent,
});
}
break;
}
}
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
OriginalName = config.tableName,
Span = config.span,
ShowText = config.showTitle,
Label = config.label,
ChildTableName = config.tableName.ParseToPascalCase(),
Children = childrenTableList,
LabelWidth = config?.labelWidth ?? labelWidth,
ShowSummary = item.showSummary,
required = childrenTableList.Any(it => it.required.Equals(true)),
AddType = item.addType,
IsRelationForm = childrenTableList.Any(it => it.IsRelationForm.Equals(true)),
DefaultCurrent = childrenTableList.Any(it => it.DefaultCurrent.Equals(true)),
});
}
break;
case JnpfKeyConst.CARD:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
OriginalName = item.__vModel__,
Shadow = item.shadow,
Children = FormControlDesign(config.children, realisticControls, gutter, labelWidth, columnDesignModel, dataType, logic),
Span = config.span,
Content = item.header,
LabelWidth = config?.labelWidth ?? labelWidth,
});
}
break;
case JnpfKeyConst.DIVIDER:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
OriginalName = item.__vModel__,
Span = config.span,
Contentposition = item.contentposition,
Default = item.__slot__.@default,
LabelWidth = config?.labelWidth ?? labelWidth,
});
}
break;
case JnpfKeyConst.COLLAPSE:
{
// 先加为了防止 children下 还有折叠面板
List childrenCollapseList = new List();
foreach (var children in config.children)
{
var child = FormControlDesign(children.__config__.children, realisticControls, gutter, labelWidth, columnDesignModel, dataType, logic);
childrenCollapseList.Add(new FormControlDesignModel()
{
Title = children.title,
Name = children.name,
Gutter = gutter,
Children = child,
IsRelationForm = child.Any(x => x.IsRelationForm),
});
}
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Accordion = item.accordion ? "true" : "false",
Name = "active" + active++,
Active = childrenCollapseList.Select(it => it.Name).ToJsonString(),
Children = childrenCollapseList,
Span = config.span,
LabelWidth = config?.labelWidth ?? labelWidth,
IsRelationForm = childrenCollapseList.Any(x => x.IsRelationForm),
});
}
break;
case JnpfKeyConst.TAB:
{
// 先加为了防止 children下 还有折叠面板
List childrenCollapseList = new List();
foreach (var children in config.children)
{
var child = FormControlDesign(children.__config__.children, realisticControls, gutter, labelWidth, columnDesignModel, dataType, logic);
childrenCollapseList.Add(new FormControlDesignModel()
{
Title = children.title,
Gutter = gutter,
Children = child,
IsRelationForm = child.Any(x => x.IsRelationForm),
});
}
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Type = item.type,
TabPosition = item.tabPosition,
Name = "active" + active++,
Active = config.active.ToString(),
Children = childrenCollapseList,
Span = config.span,
LabelWidth = config?.labelWidth ?? labelWidth,
IsRelationForm = childrenCollapseList.Any(x => x.IsRelationForm),
});
}
break;
case JnpfKeyConst.GROUPTITLE:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
Contentposition = item.contentposition,
Content = item.content,
LabelWidth = config?.labelWidth ?? labelWidth,
});
}
break;
case JnpfKeyConst.JNPFTEXT:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
DefaultValue = config.defaultValue,
TextStyle = item.textStyle != null ? item.textStyle.ToJsonString() : string.Empty,
Style = item.style.ToJsonString(),
LabelWidth = config?.labelWidth ?? labelWidth,
});
}
break;
case JnpfKeyConst.BUTTON:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
Align = item.align,
ButtonText = item.buttonText,
Type = item.type,
Disabled = item.disabled ? "disabled " : string.Empty,
LabelWidth = config?.labelWidth ?? labelWidth,
});
}
break;
case JnpfKeyConst.LINK:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
Content = item.content,
Href = item.href,
Target = item.target,
TextStyle = item.textStyle != null ? item.textStyle.ToJsonString() : string.Empty,
});
}
break;
case JnpfKeyConst.ALERT:
{
list.Add(new FormControlDesignModel()
{
jnpfKey = config.jnpfKey,
Span = config.span,
Title = item.title,
Type = item.type,
ShowIcon = item.showIcon ? "true" : "false",
});
}
break;
case JnpfKeyConst.RELATIONFORMATTR:
case JnpfKeyConst.POPUPATTR:
{
var relationField = Regex.Match(item.relationField, @"^(.+)_jnpfTable_").Groups[1].Value;
var relationControl = realisticControls.Find(it => it.__vModel__ == relationField);
var columnDesign = columnDesignModel?.Find(it => it.__vModel__ == item.__vModel__);
list.Add(new FormControlDesignModel()
{
vModel = item.__vModel__.IsNotEmptyOrNull() ? string.Format("v-model=\"dataForm.{0}\"", item.__vModel__) : string.Empty,
IsInlineEditor = columnDesignModel != null ? columnDesignModel.Any(it => it.__vModel__ == item.__vModel__) : false,
Style = item.style != null && !item.style.ToString().Equals("{}") ? $":style='{item.style.ToJsonString()}' " : string.Empty,
jnpfKey = config.jnpfKey,
OriginalName = config.isStorage == 2 ? item.__vModel__ : relationField,
Name = config.isStorage == 2 ? item.__vModel__ : relationField,
RelationField = relationField,
ShowField = item.showField,
NoShow = config.isStorage == 2 ? config.noShow ? "v-if='false' " : string.Empty : relationControl.__config__.noShow ? "v-if='false' " : string.Empty,
Tag = config.tag,
Label = config.label,
Span = config.span,
IsStorage = config.isStorage,
IndexWidth = columnDesign?.width,
LabelWidth = config?.labelWidth ?? labelWidth,
IndexAlign = columnDesign?.align,
});
}
break;
default:
{
var realisticControl = realisticControls.Find(it => it.__vModel__.Equals(item.__vModel__) && it.__config__.jnpfKey.Equals(config.jnpfKey));
var columnDesign = columnDesignModel?.Find(it => it.__vModel__ == item.__vModel__);
string vModel = string.Empty;
var Model = item.__vModel__;
vModel = dataType != 4 ? $"v-model='dataForm.{Model}' " : $"v-model='scope.row.{Model}' ";
list.Add(new FormControlDesignModel()
{
IsSort = columnDesign != null ? columnDesign.sortable : false,
IsInlineEditor = columnDesignModel != null ? columnDesignModel.Any(it => it.__vModel__ == item.__vModel__) : false,
IndexAlign = columnDesign?.align,
IndexWidth = columnDesign?.width,
Name = item.__vModel__,
OriginalName = item.__vModel__,
jnpfKey = config.jnpfKey,
Border = config.border ? "border " : string.Empty,
Style = item.style != null && !item.style.ToString().Equals("{}") ? $":style='{item.style.ToJsonString()}' " : string.Empty,
Type = !string.IsNullOrEmpty(item.type) ? $"type='{item.type}' " : string.Empty,
Span = config.span,
Clearable = item.clearable ? "clearable " : string.Empty,
Readonly = item.@readonly ? "readonly " : string.Empty,
Required = config.required ? "required " : string.Empty,
Placeholder = !string.IsNullOrEmpty(item.placeholder) ? $"placeholder='{item.placeholder}' " : string.Empty,
Disabled = item.disabled ? "disabled " : string.Empty,
IsDisabled = item.disabled ? "disabled " : $":disabled='judgeWrite(\"{item.__vModel__}\")' ",
ShowWordLimit = item.showWordlimit ? "show-word-limit " : string.Empty,
Format = !string.IsNullOrEmpty(item.format) ? $"format='{item.format}' " : string.Empty,
ValueFormat = !string.IsNullOrEmpty(item.valueformat) ? $"value-format='{item.valueformat}' " : string.Empty,
AutoSize = item.autosize != null && item.autosize.ToJsonString() != "null" ? $":autosize='{item.autosize.ToJsonString()}' " : string.Empty,
Multiple = (config.jnpfKey.Equals(JnpfKeyConst.CASCADER) ? item.props.props.multiple : item.multiple) ? $"multiple " : string.Empty,
IsRange = item.isrange ? "is-range " : string.Empty,
Props = config.props,
MainProps = item.props != null ? $":props='{Model}Props' " : string.Empty,
OptionType = config.optionType == "default" ? string.Empty : "-button",
Size = !string.IsNullOrEmpty(config.optionType) ? (config.optionType == "default" ? string.Empty : $"size='{item.size}' ") : string.Empty,
PrefixIcon = !string.IsNullOrEmpty(item.prefixicon) ? $"prefix-icon='{item.prefixicon}' " : string.Empty,
SuffixIcon = !string.IsNullOrEmpty(item.suffixicon) ? $"suffix-icon='{item.suffixicon}' " : string.Empty,
MaxLength = !string.IsNullOrEmpty(item.maxlength) ? $"maxlength='{item.maxlength}' " : string.Empty,
Step = item.step != null ? $":step='{item.step}' " : string.Empty,
StepStrictly = item.stepstrictly ? "step-strictly " : string.Empty,
ControlsPosition = !string.IsNullOrEmpty(item.controlsposition) ? $"controls-position='{item.controlsposition}' " : string.Empty,
ShowChinese = item.showChinese ? "showChinese " : string.Empty,
ShowPassword = item.showPassword ? "show-password " : string.Empty,
Filterable = item.filterable ? "filterable " : string.Empty,
ShowAllLevels = item.showalllevels ? "show-all-levels " : string.Empty,
Separator = !string.IsNullOrEmpty(item.separator) ? $"separator='{item.separator}' " : string.Empty,
RangeSeparator = !string.IsNullOrEmpty(item.rangeseparator) ? $"range-separator='{item.rangeseparator}' " : string.Empty,
StartPlaceholder = !string.IsNullOrEmpty(item.startplaceholder) ? $"start-placeholder='{item.startplaceholder}' " : string.Empty,
EndPlaceholder = !string.IsNullOrEmpty(item.endplaceholder) ? $"end-placeholder='{item.endplaceholder}' " : string.Empty,
PickerOptions = item.pickeroptions != null && item.pickeroptions.ToJsonString() != "null" ? $":picker-options='{item.pickeroptions.ToJsonString()}' " : string.Empty,
Options = item.options != null ? $":options='{item.__vModel__}Options' " : string.Empty,
Max = item.max != null && item.max != 0 ? $":max='{item.max}' " : string.Empty,
AllowHalf = item.allowhalf ? "allow-half " : string.Empty,
ShowTexts = item.showtext ? $"show-text " : string.Empty,
ShowScore = item.showScore ? $"show-score " : string.Empty,
ShowAlpha = item.showalpha ? $"show-alpha " : string.Empty,
ColorFormat = !string.IsNullOrEmpty(item.colorformat) ? $"color-format='{item.colorformat}' " : string.Empty,
ActiveText = !string.IsNullOrEmpty(item.activetext) ? $"active-text='{item.activetext}' " : string.Empty,
InactiveText = !string.IsNullOrEmpty(item.inactivetext) ? $"inactive-text='{item.inactivetext}' " : string.Empty,
ActiveColor = !string.IsNullOrEmpty(item.activecolor) ? $"active-color='{item.activecolor}' " : string.Empty,
InactiveColor = !string.IsNullOrEmpty(item.inactivecolor) ? $"inactive-color='{item.inactivecolor}' " : string.Empty,
IsSwitch = config.jnpfKey == JnpfKeyConst.SWITCH ? $":active-value='{item.activevalue}' :inactive-value='{item.inactivevalue}' " : string.Empty,
Min = item.min != null ? $":min='{item.min}' " : string.Empty,
ShowStops = item.showstops ? $"show-stops " : string.Empty,
Range = item.range ? $"range " : string.Empty,
Accept = !string.IsNullOrEmpty(item.accept) ? $"accept='{item.accept}' " : string.Empty,
ShowTip = item.showTip ? $"showTip " : string.Empty,
FileSize = item.fileSize != null && !string.IsNullOrEmpty(item.fileSize.ToString()) ? $":fileSize='{item.fileSize}' " : string.Empty,
SizeUnit = !string.IsNullOrEmpty(item.sizeUnit) ? $"sizeUnit='{item.sizeUnit}' " : string.Empty,
Limit = item.limit != null ? $":limit='{item.limit}' " : string.Empty,
Contentposition = !string.IsNullOrEmpty(item.contentposition) ? $"content-position='{item.contentposition}' " : string.Empty,
ButtonText = !string.IsNullOrEmpty(item.buttonText) ? $"buttonText='{item.buttonText}' " : string.Empty,
Level = config.jnpfKey == JnpfKeyConst.ADDRESS ? $":level='{item.level}' " : string.Empty,
ActionText = !string.IsNullOrEmpty(item.actionText) ? $"actionText='{item.actionText}' " : string.Empty,
Shadow = !string.IsNullOrEmpty(item.shadow) ? $"shadow='{item.shadow}' " : string.Empty,
Content = !string.IsNullOrEmpty(item.content) ? $"content='{item.content}' " : string.Empty,
NoShow = config.noShow ? "v-if='false' " : string.Empty,
Label = config.label,
vModel = vModel,
Prepend = item.__slot__ != null && !string.IsNullOrEmpty(item.__slot__.prepend) ? item.__slot__.prepend : null,
Append = item.__slot__ != null && !string.IsNullOrEmpty(item.__slot__.append) ? item.__slot__.append : null,
Tag = config.tag,
Count = item.max.ParseToInt(),
ModelId = item.modelId != null ? item.modelId : string.Empty,
RelationField = item.relationField != null ? $"relationField='{item.relationField}' " : string.Empty,
ColumnOptions = item.columnOptions != null ? $":columnOptions='{item.__vModel__}Options' " : string.Empty,
TemplateJson = config.jnpfKey.Equals(JnpfKeyConst.POPUPTABLESELECT) || config.jnpfKey.Equals(JnpfKeyConst.POPUPSELECT) ? string.Format(":templateJson='{0}TemplateJson' ", item.__vModel__) : string.Empty,
HasPage = item.hasPage ? "hasPage " : string.Empty,
PageSize = item.pageSize != null ? $":pageSize='{item.pageSize}' " : string.Empty,
PropsValue = item.propsValue != null ? $"propsValue='{item.propsValue}' " : string.Empty,
InterfaceId = item.interfaceId != null ? $"interfaceId='{item.interfaceId}' " : string.Empty,
Precision = item.precision != null ? $":precision='{item.precision}' " : string.Empty,
ShowLevel = !string.IsNullOrEmpty(item.showLevel) ? string.Empty : string.Empty,
LabelWidth = config?.labelWidth ?? labelWidth,
IsStorage = config.isStorage,
PopupType = !string.IsNullOrEmpty(item.popupType) ? $"popupType='{item.popupType}' " : string.Empty,
PopupTitle = !string.IsNullOrEmpty(item.popupTitle) ? $"popupTitle='{item.popupTitle}' " : string.Empty,
PopupWidth = !string.IsNullOrEmpty(item.popupWidth) ? $"popupWidth='{item.popupWidth}' " : string.Empty,
Field = config.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM) || config.jnpfKey.Equals(JnpfKeyConst.POPUPSELECT) ? $"field='{item.__vModel__}' " : string.Empty,
SelectType = item.selectType != null ? item.selectType : string.Empty,
AbleDepIds = item.selectType != null && item.selectType == "custom" && (config.jnpfKey.Equals(JnpfKeyConst.USERSELECT) || config.jnpfKey.Equals(JnpfKeyConst.DEPSELECT)) ? string.Format(":ableDepIds='{0}_AbleDepIds' ", item.__vModel__) : string.Empty,
AblePosIds = item.selectType != null && item.selectType == "custom" && (config.jnpfKey.Equals(JnpfKeyConst.USERSELECT) || config.jnpfKey.Equals(JnpfKeyConst.POSSELECT)) ? string.Format(":ablePosIds='{0}_AblePosIds' ", item.__vModel__) : string.Empty,
AbleUserIds = item.selectType != null && item.selectType == "custom" && config.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableUserIds='{0}_AbleUserIds' ", item.__vModel__) : string.Empty,
AbleRoleIds = item.selectType != null && item.selectType == "custom" && config.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableRoleIds='{0}_AbleRoleIds' ", item.__vModel__) : string.Empty,
AbleGroupIds = item.selectType != null && item.selectType == "custom" && config.jnpfKey.Equals(JnpfKeyConst.USERSELECT) ? string.Format(":ableGroupIds='{0}_AbleGroupIds' ", item.__vModel__) : string.Empty,
AbleIds = item.selectType != null && item.selectType == "custom" && config.jnpfKey.Equals(JnpfKeyConst.USERSSELECT) ? string.Format(":ableIds='{0}_AbleIds' ", item.__vModel__) : string.Empty,
UserRelationAttr = GetUserRelationAttr(item, realisticControls, logic),
IsLinked = realisticControl.IsLinked,
IsLinkage = realisticControl.IsLinkage,
IsRelationForm = config.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM),
PathType = !string.IsNullOrEmpty(item.pathType) ? string.Format("pathType=\"{0}\" ", item.pathType) : string.Empty,
IsAccount = item.isAccount != -1 ? string.Format(":isAccount=\"{0}\" ", item.isAccount) : string.Empty,
Folder = !string.IsNullOrEmpty(item.folder) ? string.Format("folder=\"{0}\" ", item.folder) : string.Empty,
DefaultCurrent = config.defaultCurrent,
});
}
break;
}
}
return list;
}
///
/// 表单默认值控件列表.
///
/// 组件列表.
/// 查询字段.
/// 是否主表.
///
public static DefaultFormControlModel DefaultFormControlList(List fieldList, List searchField, string subTableName = null, bool isMain = true)
{
DefaultFormControlModel model = new DefaultFormControlModel();
model.DateField = new List();
model.ComSelectList = new List();
model.DepSelectList = new List();
model.UserSelectList = new List();
model.SubTabelDefault = new List();
// 获取表单内存在默认值控件
foreach (var item in fieldList)
{
var config = item.__config__;
var search = new IndexSearchFieldModel();
switch (isMain && !config.jnpfKey.Equals(JnpfKeyConst.TABLE))
{
case false:
search = searchField?.Find(it => it.__vModel__.Equals(string.Format("{0}-{1}", subTableName, item.__vModel__)));
break;
default:
search = searchField?.Find(it => it.__vModel__.Equals(string.Format("{0}", item.__vModel__)));
break;
}
// 未作为查询条件
if (search == null)
{
search = new IndexSearchFieldModel();
search.searchMultiple = false;
}
switch (config.defaultCurrent)
{
case true:
switch (config.jnpfKey)
{
case JnpfKeyConst.TABLE:
model.SubTabelDefault.Add(DefaultFormControlList(item.__config__.children, searchField, item.__vModel__, false));
break;
case JnpfKeyConst.DATE:
model.DateField.Add(item.__vModel__);
break;
case JnpfKeyConst.COMSELECT:
model.ComSelectList.Add(new DefaultComSelectControl()
{
IsMultiple = item.multiple,
IsSearchMultiple = search.searchMultiple,
Field = item.__vModel__
});
break;
case JnpfKeyConst.DEPSELECT:
model.DepSelectList.Add(new DefaultDepSelectControl()
{
IsMultiple = item.multiple,
selectType = item.selectType,
IsSearchMultiple = search.searchMultiple,
Field = item.__vModel__,
ableDepIds = item.ableDepIds.ToJsonString(),
});
break;
case JnpfKeyConst.USERSELECT:
model.UserSelectList.Add(new DefaultUserSelectControl()
{
IsMultiple = item.multiple,
selectType = item.selectType,
IsSearchMultiple = search.searchMultiple,
Field = item.__vModel__,
ableDepIds = item.ableDepIds.ToJsonString(),
ableGroupIds = item.ableGroupIds.ToJsonString(),
ablePosIds = item.ablePosIds.ToJsonString(),
ableRoleIds = item.ableRoleIds.ToJsonString(),
ableUserIds = item.ableUserIds.ToJsonString(),
});
break;
}
break;
}
}
switch (isMain)
{
case false:
model.SubTableName = subTableName;
model.IsExistDate = model.DateField.Any();
model.IsExistComSelect = model.ComSelectList.Any();
model.IsExistDepSelect = model.DepSelectList.Any();
model.IsExistUserSelect = model.UserSelectList.Any();
break;
default:
model.IsExistDate = model.DateField.Any() || model.SubTabelDefault.Any(it => it.DateField.Any());
model.IsExistComSelect = model.ComSelectList.Any() || model.SubTabelDefault.Any(it => it.ComSelectList.Any());
model.IsExistDepSelect = model.DepSelectList.Any() || model.SubTabelDefault.Any(it => it.DepSelectList.Any());
model.IsExistUserSelect = model.UserSelectList.Any() || model.SubTabelDefault.Any(it => it.UserSelectList.Any());
model.IsExistSubTable = model.SubTabelDefault.Count > 0 ? true : false;
break;
}
return model;
}
///
/// 表单控件选项配置.
///
/// 组件列表.
/// 真实控件.
/// 列表设计.
/// 1-Web设计,2-App设计,3-流程表单,4-Web表单,5-App表单.
/// 是否主循环.
///
public static List FormControlProps(List fieldList, List realisticControls, ColumnDesignModel columnDesignModel, int type, bool isMain = false)
{
if (isMain) active = 1;
List list = new List();
foreach (var item in fieldList)
{
var config = item.__config__;
switch (config.jnpfKey)
{
case JnpfKeyConst.CARD:
case JnpfKeyConst.ROW:
{
list.AddRange(FormControlProps(config.children, realisticControls, columnDesignModel, type));
}
break;
case JnpfKeyConst.TABLE:
{
var childrenRealisticControls = realisticControls.Find(it => it.__vModel__.Equals(item.__vModel__) && it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)).__config__.children;
for (int i = 0; i < config.children.Count; i++)
{
var columnDesign = columnDesignModel.searchList?.Find(it => it.__vModel__.Equals(string.Format("{0}-{1}", item.__vModel__, config.children[i].__vModel__)));
var childrenConfig = config.children[i].__config__;
switch (childrenConfig.jnpfKey)
{
case JnpfKeyConst.DEPSELECT:
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleDepIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableDepIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.POSSELECT:
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AblePosIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ablePosIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.USERSELECT:
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleDepIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableDepIds.ToJsonString()),
});
}
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AblePosIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ablePosIds.ToJsonString()),
});
}
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleUserIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableUserIds.ToJsonString()),
});
}
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleRoleIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableRoleIds.ToJsonString()),
});
}
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleGroupIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableGroupIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.USERSSELECT:
if (config.children[i].selectType != null && config.children[i].selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_{1}_AbleIds:{2},", item.__vModel__, config.children[i].__vModel__, config.children[i].ableIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.SELECT:
{
var realisticControl = childrenRealisticControls.Find(it => it.__vModel__.Equals(config.children[i].__vModel__) && it.__config__.jnpfKey.Equals(childrenConfig.jnpfKey));
switch (childrenConfig.dataType)
{
// 静态数据
case "static":
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
DataType = childrenConfig.dataType,
IsStatic = true,
IsIndex = columnDesign != null ? true : false,
IsProps = type == 5 ? true : false,
Props = string.Format("{{'label':'{0}','value':'{1}'}}", childrenConfig.props.label, childrenConfig.props.value),
IsChildren = true,
Content = GetCodeGenConvIndexListControlOption(string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__), config.children[i].__slot__.options)
});
break;
default:
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
OptionsName = string.Format("dataForm.{0}[i].{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
DataType = childrenConfig.dataType,
IsStatic = false,
IsIndex = columnDesign != null ? true : false,
IsProps = type == 5 ? true : false,
Props = string.Format("{{'label':'{0}','value':'{1}'}}", childrenConfig.props.label, childrenConfig.props.value),
IsChildren = true,
Content = string.Format("{0}Options : [],", string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__)),
IsLinkage = realisticControl.IsLinkage,
TemplateJson = childrenConfig.dataType == "dynamic" ? childrenConfig.templateJson.ToJsonString() : "[]"
});
break;
}
}
break;
case JnpfKeyConst.TREESELECT:
case JnpfKeyConst.CASCADER:
{
var realisticControl = childrenRealisticControls.Find(it => it.__vModel__.Equals(config.children[i].__vModel__) && it.__config__.jnpfKey.Equals(childrenConfig.jnpfKey));
switch (childrenConfig.dataType)
{
case "static":
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
DataType = childrenConfig.dataType,
IsStatic = true,
IsIndex = columnDesign != null ? true : false,
IsProps = true,
IsChildren = true,
Props = config.children[i].props.props.ToJsonString(CommonConst.options),
QueryProps = GetQueryPropsModel(config.children[i].props.props).ToJsonString(CommonConst.options),
Content = GetCodeGenConvIndexListControlOption(string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__), config.children[i].options.ToObject>>())
});
break;
default:
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
OptionsName = string.Format("dataForm.{0}[i].{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
DataType = childrenConfig.dataType,
IsStatic = false,
IsIndex = columnDesign != null ? true : false,
IsProps = true,
IsChildren = true,
Props = config.children[i].props.props.ToJsonString(CommonConst.options),
QueryProps = GetQueryPropsModel(config.children[i].props.props).ToJsonString(CommonConst.options),
Content = string.Format("{0}Options : [],", string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__)),
IsLinkage = realisticControl.IsLinkage,
TemplateJson = childrenConfig.dataType == "dynamic" ? childrenConfig.templateJson.ToJsonString() : "[]"
});
break;
}
}
break;
case JnpfKeyConst.POPUPTABLESELECT:
case JnpfKeyConst.POPUPSELECT:
{
var realisticControl = childrenRealisticControls.Find(it => it.__vModel__.Equals(config.children[i].__vModel__) && it.__config__.jnpfKey.Equals(childrenConfig.jnpfKey));
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
OptionsName = string.Format("dataForm.{0}[i].{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = null,
DataType = null,
IsStatic = true,
IsIndex = columnDesign != null ? true : false,
IsProps = false,
Props = null,
IsChildren = true,
Content = $"{string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__)}Options : {config.children[i].columnOptions.ToJsonString(CommonConst.options)},",
IsLinkage = realisticControl.IsLinkage,
TemplateJson = config.children[i].templateJson.ToJsonString()
});
}
break;
case JnpfKeyConst.RELATIONFORM:
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = childrenConfig.jnpfKey,
Name = string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__),
DictionaryType = null,
DataType = null,
IsStatic = true,
IsIndex = columnDesign != null ? true : false,
IsProps = false,
Props = null,
IsChildren = true,
Content = $"{string.Format("{0}_{1}", item.__vModel__, config.children[i].__vModel__)}Options : {config.children[i].columnOptions.ToJsonString(CommonConst.options)},"
});
}
break;
}
}
}
break;
case JnpfKeyConst.COLLAPSE:
{
StringBuilder title = new StringBuilder("[");
StringBuilder activeList = new StringBuilder("[");
foreach (var children in config.children)
{
title.AppendFormat("{{title:'{0}'}},", children.title);
activeList.AppendFormat("'{0}',", children.name);
list.AddRange(FormControlProps(children.__config__.children, realisticControls, columnDesignModel, type));
}
title.Remove(title.Length - 1, 1);
activeList.Remove(activeList.Length - 1, 1);
title.Append("]");
activeList.Append("]");
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = "active" + active++,
IsStatic = true,
IsIndex = false,
IsProps = false,
IsChildren = false,
Content = activeList.ToString(),
Title = title.ToString()
});
}
break;
case JnpfKeyConst.TAB:
{
StringBuilder title = new StringBuilder("[");
foreach (var children in config.children)
{
title.AppendFormat("{{title:'{0}'}},", children.title);
list.AddRange(FormControlProps(children.__config__.children, realisticControls, columnDesignModel, type));
}
title.Remove(title.Length - 1, 1);
title.Append("]");
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = "active" + active++,
IsStatic = true,
IsIndex = false,
IsProps = false,
IsChildren = false,
Content = config.active.ToString(),
Title = title.ToString()
});
}
break;
case JnpfKeyConst.GROUPTITLE:
case JnpfKeyConst.DIVIDER:
case JnpfKeyConst.JNPFTEXT:
break;
case JnpfKeyConst.DEPSELECT:
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleDepIds:{1},", item.__vModel__, item.ableDepIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.POSSELECT:
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AblePosIds:{1},", item.__vModel__, item.ablePosIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.USERSELECT:
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleDepIds:{1},", item.__vModel__, item.ableDepIds.ToJsonString()),
});
}
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AblePosIds:{1},", item.__vModel__, item.ablePosIds.ToJsonString()),
});
}
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleUserIds:{1},", item.__vModel__, item.ableUserIds.ToJsonString()),
});
}
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleRoleIds:{1},", item.__vModel__, item.ableRoleIds.ToJsonString()),
});
}
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleGroupIds:{1},", item.__vModel__, item.ableGroupIds.ToJsonString()),
});
}
break;
case JnpfKeyConst.USERSSELECT:
if (item.selectType != null && item.selectType == "custom")
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
IsStatic = true,
IsIndex = false,
IsProps = false,
Content = string.Format("{0}_AbleIds:{1},", item.__vModel__, item.ableIds.ToJsonString()),
});
}
break;
default:
{
switch (config.jnpfKey)
{
case JnpfKeyConst.POPUPTABLESELECT:
case JnpfKeyConst.POPUPSELECT:
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = null,
DataType = null,
IsStatic = true,
IsIndex = false,
IsProps = false,
Props = null,
IsChildren = false,
Content = string.Format("{0}Options : {1},", item.__vModel__, item.columnOptions.ToJsonString(CommonConst.options)),
TemplateJson = item.templateJson.ToJsonString()
});
}
break;
case JnpfKeyConst.RELATIONFORM:
{
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = null,
DataType = null,
IsStatic = true,
IsIndex = false,
IsProps = false,
Props = null,
IsChildren = false,
Content = string.Format("{0}Options : {1},", item.__vModel__, item.columnOptions.ToJsonString(CommonConst.options))
});
}
break;
case JnpfKeyConst.CHECKBOX:
case JnpfKeyConst.SELECT:
case JnpfKeyConst.RADIO:
{
switch (config.dataType)
{
case "static":
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
DataType = config.dataType,
IsStatic = true,
IsIndex = true,
IsProps = type == 5 ? true : false,
Props = string.Format("{{'label':'{0}','value':'{1}'}}", config.props.label, config.props.value),
QueryProps = GetQueryPropsModel(config.props).ToJsonString(CommonConst.options),
IsChildren = false,
Content = GetCodeGenConvIndexListControlOption(item.__vModel__, item.__slot__.options)
});
break;
default:
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
DataType = config.dataType,
IsStatic = false,
IsIndex = true,
IsProps = type == 5 ? true : false,
QueryProps = GetQueryPropsModel(config.props).ToJsonString(CommonConst.options),
Props = $"{{'label':'{config.props.label}','value':'{config.props.value}'}}",
IsChildren = false,
Content = string.Format("{0}Options : [],", item.__vModel__),
TemplateJson = config.dataType == "dynamic" ? config.templateJson.ToJsonString() : "[]"
});
break;
}
}
break;
case JnpfKeyConst.TREESELECT:
case JnpfKeyConst.CASCADER:
{
switch (config.dataType)
{
case "static":
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
DataType = config.dataType,
IsStatic = true,
IsIndex = true,
IsProps = true,
IsChildren = false,
Props = item.props.props.ToJsonString(CommonConst.options),
QueryProps = GetQueryPropsModel(item.props.props).ToJsonString(CommonConst.options),
Content = GetCodeGenConvIndexListControlOption(item.__vModel__, item.options.ToObject>>())
});
break;
default:
list.Add(new CodeGenConvIndexListControlOptionDesign()
{
jnpfKey = config.jnpfKey,
Name = item.__vModel__,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
DataType = config.dataType,
IsStatic = false,
IsIndex = true,
IsProps = true,
IsChildren = false,
Props = item.props.props.ToJsonString(CommonConst.options),
QueryProps = GetQueryPropsModel(item.props.props).ToJsonString(CommonConst.options),
Content = string.Format("{0}Options : [],", item.__vModel__),
TemplateJson = config.dataType == "dynamic" ? config.templateJson.ToJsonString() : "[]"
});
break;
}
}
break;
}
}
break;
}
}
return list;
}
///
/// 表单真实控件-剔除布局控件后.
///
/// 组件列表
///
public static List FormRealControl(List fieldList)
{
var list = new List();
foreach (var item in fieldList)
{
var config = item.__config__;
switch (config.jnpfKey)
{
case JnpfKeyConst.TABLE:
list.Add(new CodeGenFormRealControlModel
{
jnpfKey = config.jnpfKey,
vModel = item.__vModel__,
children = FormRealControl(config.children)
});
break;
default:
list.Add(new CodeGenFormRealControlModel
{
jnpfKey = config.jnpfKey,
vModel = item.__vModel__,
multiple = config.jnpfKey == JnpfKeyConst.CASCADER ? item.props.props.multiple : item.multiple
});
break;
}
}
return list;
}
///
/// 表单脚本设计.
///
/// 生成模式.
/// 组件列表.
/// 表真实字段.
///
public static List FormScriptDesign(string genModel, List fieldList, List tableColumns, List columnDesignModel)
{
var formScript = new List();
foreach (FieldsModel item in fieldList)
{
var config = item.__config__;
switch (config.jnpfKey)
{
case JnpfKeyConst.TABLE:
{
var childrenFormScript = new List();
foreach (var children in config.children)
{
var childrenConfig = children.__config__;
switch (childrenConfig.jnpfKey)
{
case JnpfKeyConst.RELATIONFORMATTR:
case JnpfKeyConst.POPUPATTR:
{
if (childrenConfig.isStorage == 2)
{
childrenFormScript.Add(new FormScriptDesignModel()
{
Name = children.__vModel__,
OriginalName = children.__vModel__,
jnpfKey = childrenConfig.jnpfKey,
DataType = childrenConfig.dataType,
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
Format = children.format,
Multiple = childrenConfig.jnpfKey == JnpfKeyConst.CASCADER ? children.props.props.multiple : children.multiple,
BillRule = childrenConfig.rule,
Required = childrenConfig.required,
Placeholder = childrenConfig.label,
Range = children.range,
RegList = childrenConfig.regList,
DefaultValue = childrenConfig.defaultValue?.ToString(),
Trigger = string.IsNullOrEmpty(childrenConfig.trigger?.ToString()) ? "blur" : (childrenConfig.trigger is Array ? childrenConfig.trigger.ToJsonString() : childrenConfig.trigger.ToString()),
ChildrenList = null,
IsSummary = item.showSummary && item.summaryField.Any(it => it.Equals(children.__vModel__)) ? true : false,
IsLinked = children.IsLinked,
LinkageRelationship = children.linkageReverseRelationship,
IsLinkage = children.IsLinkage
});
}
}
break;
case JnpfKeyConst.SWITCH:
{
childrenFormScript.Add(new FormScriptDesignModel()
{
Name = children.__vModel__,
OriginalName = children.__vModel__,
jnpfKey = childrenConfig.jnpfKey,
DataType = childrenConfig.dataType,
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
Format = children.format,
Multiple = childrenConfig.jnpfKey == JnpfKeyConst.CASCADER ? children.props.props.multiple : children.multiple,
BillRule = childrenConfig.rule,
Required = childrenConfig.required,
Placeholder = childrenConfig.label,
Range = children.range,
RegList = childrenConfig.regList,
DefaultValue = childrenConfig.defaultValue.ParseToBool(),
Trigger = string.IsNullOrEmpty(childrenConfig.trigger?.ToString()) ? "blur" : (childrenConfig.trigger is Array ? childrenConfig.trigger.ToJsonString() : childrenConfig.trigger.ToString()),
ChildrenList = null,
IsSummary = item.showSummary && item.summaryField.Find(it => it.Equals(children.__vModel__)) != null ? true : false,
IsLinked = item.IsLinked,
LinkageRelationship = item.linkageReverseRelationship
});
}
break;
default:
{
childrenFormScript.Add(new FormScriptDesignModel()
{
Name = children.__vModel__,
OriginalName = children.__vModel__,
jnpfKey = childrenConfig.jnpfKey,
DataType = childrenConfig.dataType,
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
Format = children.format,
Multiple = childrenConfig.jnpfKey == JnpfKeyConst.CASCADER ? children.props.props.multiple : children.multiple,
BillRule = childrenConfig.rule,
Required = childrenConfig.required,
Placeholder = childrenConfig.label,
Range = children.range,
RegList = childrenConfig.regList,
DefaultValue = childrenConfig.defaultValue?.ToString(),
Trigger = string.IsNullOrEmpty(childrenConfig.trigger?.ToString()) ? "blur" : (childrenConfig.trigger is Array ? childrenConfig.trigger.ToJsonString() : childrenConfig.trigger.ToString()),
ChildrenList = null,
IsSummary = item.showSummary && item.summaryField.Any(it => it.Equals(children.__vModel__)) ? true : false,
IsLinked = children.IsLinked,
LinkageRelationship = children.linkageReverseRelationship,
IsLinkage = children.IsLinkage
});
}
break;
}
}
List childrenRegList = new List();
foreach (var reg in childrenFormScript.FindAll(it => it.RegList != null && it.RegList.Count > 0).Select(it => it.RegList))
{
childrenRegList.AddRange(reg);
}
formScript.Add(new FormScriptDesignModel()
{
Name = config.tableName.ParseToPascalCase(),
Placeholder = config.label,
OriginalName = item.__vModel__,
jnpfKey = config.jnpfKey,
ChildrenList = childrenFormScript,
Required = childrenFormScript.Any(it => it.Required.Equals(true)),
RegList = childrenRegList,
ShowSummary = item.showSummary,
SummaryField = item.summaryField.ToJsonString(),
IsDataTransfer = item.addType == 1 ? true : false,
AddTableConf = item.addTableConf.ToJsonString(),
AddType = item.addType,
IsLinked = childrenFormScript.Any(it => it.IsLinked.Equals(true))
});
}
break;
case JnpfKeyConst.RELATIONFORMATTR:
case JnpfKeyConst.POPUPATTR:
{
if (config.isStorage == 2)
{
var originalName = string.Empty;
if (item.__vModel__.Contains("_jnpf_"))
{
var auxiliaryTableName = item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_", "table").Last();
var column = item.__vModel__.Replace(item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_").Last(), string.Empty);
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(column) && it.IsAuxiliary.Equals(true) && (bool)it.TableName?.Equals(auxiliaryTableName));
if (columns != null)
originalName = columns.OriginalColumnName;
}
else
{
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(item.__vModel__));
if (columns != null)
originalName = columns.OriginalColumnName;
}
formScript.Add(new FormScriptDesignModel()
{
IsInlineEditor = columnDesignModel != null ? columnDesignModel.Any(it => it.__vModel__ == item.__vModel__) : false,
Name = item.__vModel__,
OriginalName = originalName,
jnpfKey = config.jnpfKey,
DataType = config.dataType,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
Format = item.format,
Multiple = config.jnpfKey == JnpfKeyConst.CASCADER ? item.props.props.multiple : item.multiple,
BillRule = config.rule,
Required = config.required,
Placeholder = config.label,
Range = item.range,
RegList = config.regList,
DefaultValue = config.defaultValue?.ToString(),
Trigger = !string.IsNullOrEmpty(config.trigger?.ToString()) ? (config?.trigger is Array ? config?.trigger?.ToJsonString() : config?.trigger?.ToString()) : "blur",
ChildrenList = null,
IsLinked = item.IsLinked,
LinkageRelationship = item.linkageReverseRelationship,
IsLinkage = item.IsLinkage,
});
}
}
break;
case JnpfKeyConst.SWITCH:
{
var originalName = string.Empty;
if (item.__vModel__.Contains("_jnpf_"))
{
var auxiliaryTableName = item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_", "table").Last();
var column = item.__vModel__.Replace(item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_").Last(), string.Empty);
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(column) && (bool)it.TableName?.Equals(auxiliaryTableName) && it.IsAuxiliary.Equals(true));
if (columns != null)
originalName = columns.OriginalColumnName;
}
else
{
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(item.__vModel__));
if (columns != null)
originalName = columns.OriginalColumnName;
}
formScript.Add(new FormScriptDesignModel()
{
IsInlineEditor = columnDesignModel != null ? columnDesignModel.Any(it => it.__vModel__ == item.__vModel__) : false,
Name = item.__vModel__,
OriginalName = originalName,
jnpfKey = config.jnpfKey,
DataType = config.dataType,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
Format = item.format,
Multiple = item.multiple,
BillRule = config.rule,
Required = config.required,
Placeholder = config.label,
Range = item.range,
RegList = config.regList,
DefaultValue = config.defaultValue.ParseToBool(),
Trigger = string.IsNullOrEmpty(config.trigger?.ToString()) ? "blur" : (config.trigger is Array ? config.trigger.ToJsonString() : config.trigger.ToString()),
ChildrenList = null,
IsLinked = item.IsLinked,
LinkageRelationship = item.linkageReverseRelationship
});
}
break;
default:
{
string originalName = string.Empty;
if (item.__vModel__.Contains("_jnpf_"))
{
var auxiliaryTableName = item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_", "table").Last();
var column = item.__vModel__.Replace(item.__vModel__.Matches(@"jnpf_(?[\s\S]*?)_jnpf_").Last(), string.Empty);
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(column) && it.IsAuxiliary.Equals(true) && (bool)it.TableName?.Equals(auxiliaryTableName));
if (columns != null)
originalName = columns.OriginalColumnName;
}
else
{
var columns = tableColumns.Find(it => it.LowerColumnName.Equals(item.__vModel__));
if (columns != null)
originalName = columns.OriginalColumnName;
}
formScript.Add(new FormScriptDesignModel()
{
IsInlineEditor = columnDesignModel != null ? columnDesignModel.Any(it => it.__vModel__ == item.__vModel__) : false,
Name = item.__vModel__,
OriginalName = originalName,
jnpfKey = config.jnpfKey,
DataType = config.dataType,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
Format = item.format,
Multiple = config.jnpfKey == JnpfKeyConst.CASCADER ? item.props.props.multiple : item.multiple,
BillRule = config.rule,
Required = config.required,
Placeholder = config.label,
Range = item.range,
RegList = config.regList,
DefaultValue = config.defaultValue?.ToString(),
Trigger = !string.IsNullOrEmpty(config.trigger?.ToString()) ? (config?.trigger is Array ? config?.trigger?.ToJsonString() : config?.trigger?.ToString()) : "blur",
ChildrenList = null,
IsLinked = item.IsLinked,
LinkageRelationship = item.linkageReverseRelationship,
IsLinkage = item.IsLinkage,
});
}
break;
}
}
return formScript;
}
///
/// 获取常规index列表控件Option.
///
///
///
///
private static string GetCodeGenConvIndexListControlOption(string name, List> options)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}Options:", name);
sb.Append("[");
foreach (var valueItem in options.ToObject>>())
{
sb.Append("{");
foreach (var items in valueItem)
{
sb.AppendFormat("'{0}':{1},", items.Key, items.Value.ToJsonString());
}
sb = new StringBuilder(sb.ToString().TrimEnd(','));
sb.Append("},");
}
sb = new StringBuilder(sb.ToString().TrimEnd(','));
sb.Append("],");
return sb.ToString();
}
///
/// 查询时将多选关闭.
///
///
///
private static PropsBeanModel GetQueryPropsModel(PropsBeanModel propsModel)
{
var model = new PropsBeanModel();
if (propsModel != null && propsModel.multiple)
{
model = propsModel;
model.multiple = false;
}
else if (propsModel != null)
{
model = propsModel;
}
return model;
}
///
/// 获取用户控件联动属性.
///
/// 联动控件.
/// 当前控件集合.
/// 4-PC,5-App.
///
private static string GetUserRelationAttr(FieldsModel field, List fieldList, int logic)
{
var res = string.Empty;
// 用户控件联动
if (field.__config__.jnpfKey.Equals(JnpfKeyConst.USERSELECT) && field.relationField.IsNotEmptyOrNull())
{
var relationField = fieldList.Find(x => x.__vModel__.Equals(field.relationField));
if (relationField == null && field.relationField.ToLower().Contains("tablefield") && fieldList.Any(x => x.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)))
{
var ctFieldList = fieldList.Find(x => x.__vModel__.Equals(field.relationField.Split("-").FirstOrDefault()));
if (ctFieldList != null && ctFieldList.__config__.children != null)
{
relationField = ctFieldList.__config__.children.Find(x => x.__vModel__.Equals(field.relationField.Split("-").LastOrDefault()));
field.relationField = logic == 4 ? field.relationField.Replace("-", "[scope.$index].") : field.relationField.Replace("-", "[i].");
}
}
if (relationField != null) res = string.Format(" :ableRelationIds=\"dataForm.{0}\" ", field.relationField);
}
return res;
}
///
/// 表单json.
///
///
///
public static string GetPropertyJson(List formScriptDesignModels)
{
List? list = new List();
foreach (var item in formScriptDesignModels)
{
switch (item.jnpfKey)
{
case JnpfKeyConst.TABLE:
list.Add(new CodeGenExportPropertyJsonModel
{
filedName = item.Placeholder,
jnpfKey = item.jnpfKey,
filedId = item.OriginalName,
required = item.Required,
multiple = item.Multiple,
});
foreach (var subtable in item.ChildrenList)
{
list.Add(new CodeGenExportPropertyJsonModel
{
filedName = string.Format("{0}-{1}", item.Placeholder, subtable.Placeholder),
jnpfKey = subtable.jnpfKey,
filedId = string.Format("{0}-{1}", item.OriginalName, subtable.LowerName),
required = subtable.Required,
multiple = subtable.Multiple,
});
}
break;
default:
list.Add(new CodeGenExportPropertyJsonModel
{
filedName = item.Placeholder,
jnpfKey = item.jnpfKey,
filedId = item.LowerName,
required = item.Required,
multiple = item.Multiple,
});
break;
}
}
return list.ToJsonString();
}
}