/////////////////////////////////////////////////////////////////////////////////
// 宁波拓通e智造平台 ToTong Next Builder //
// https://git.tuotong-tech.com/tnb/tnb.server //
/////////////////////////////////////////////////////////////////////////////////
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Tnb.DataAccess;
using Yitter.IdGenerator;
namespace Tnb.VmodelEngine;
///
/// 视图模型属性
///
public class VmProp
{
///
/// 属性代码
///
public string code { get; set; } = string.Empty;
///
/// 显示名称
///
public string name { get; set; } = string.Empty;
}
///
/// 字段属性
///
public class VmDbProp : VmProp
{
#region Properties
///
/// 字段名称
///
public string field { get; set; } = string.Empty;
///
/// 数据类型
///
public string dataType { get; set; } = "varchar";
///
/// 数据类型
///
public string? csType { get; set; }
///
/// 长度
///
public int length { get; set; }
///
/// 精度
///
public int digit { get; set; }
///
/// 排序
///
public int ordinal { get; set; }
///
/// 非空
///
public bool required { get; set; }
///
/// 是否主键
///
public bool pkey { get; set; }
///
/// 是否模糊搜索
///
public bool fuzzy { get; set; }
///
/// 默认值
///
public string? defValue { get; set; }
///
/// 描述
///
public string? descrip { get; set; }
#endregion
///
/// 获取默认值
///
///
public object? GetDefaultValue()
{
object? val = null;
if (string.IsNullOrEmpty(defValue))
{
val = defValue switch
{
"@@snowid" => YitIdHelper.NextId().ToString(),
"@@now" => DateTime.Now,
"@@userid" => YitIdHelper.NextId().ToString(),
"@@orgid" => YitIdHelper.NextId().ToString(),
_ => null
};
}
else
{
val = csType switch
{
"string" => string.Empty,
"short" or "int" or "long" => 0,
"float" or "double" or "decimal" => 0f,
"DateTime" => DateTime.Now,
_ => null
};
}
return val;
}
///
/// 获取默认宽度
///
///
public string GetDefaultWidth()
{
return csType switch
{
"string" => "\"width\": \"auto\"",
"int" or "short" or "long" => "\"width\": 80",
"DateTime" => "\"width\": 150",
_ => ""
};
}
///
/// 获取默认组件
///
///
public CompOption GetDefaultComp()
{
CompOption comp = new CompOption();
if (pkey)
{
comp.attr.Add("disabled", true);
return comp;
}
switch (csType)
{
case "string":
comp.attr.Add("clearable", true);
comp.attr.Add("maxlength", length);
comp.attr.Add("showWordLimit", true);
break;
case "int":
case "short":
case "long":
comp.type = "el-input-number";
break;
case "DateTime":
comp.type = "el-date-picker";
break;
};
return comp;
}
}
///
/// 导航属性
///
public class VmNavProp : VmProp
{
///
/// 导航属性模型id
///
public string vmid { get; set; } = string.Empty;
///
/// 导航关联类型
///
public eNavigateType navType { get; set; }
///
/// 源表字段
///
public string refCode { get; set; } = VmSelectProp.MAIN_ALIES;
///
/// 被引用字段
///
public string refField { get; set; } = string.Empty;
///
/// 源表字段
///
public string fkField { get; set; } = string.Empty;
/////
///// 关联表表名
/////
//[JsonIgnore]
//public string refTable { get; set; } = string.Empty;
/////
///// 被引用表(中间表)
/////
//[JsonIgnore]
//public string? midTable { get; set; }
[JsonIgnore]
public Vmodel? naviModel { get; set; }
}
public class VmCalProp : VmProp
{
public string calculate { get; set; } = string.Empty;
}
public class DictOption
{
public string dictTypeId { get; set; } = string.Empty;
public string refField { get; set; } = "id";
}
public class CompOption
{
public string type { get; set; } = "el-input";
public JObject attr { get; set; } = new JObject();
}