4029 lines
270 KiB
C#
4029 lines
270 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using Business = SuperMap.RealEstate.FrameWork.Platform.Business;
|
||
using Newtonsoft.Json.Linq;
|
||
using Newtonsoft.Json;
|
||
using HZQR.Common;
|
||
|
||
namespace CodeBuilderApi.GeneralMethod
|
||
{
|
||
/// <summary>
|
||
/// 前端页面生成相关方法
|
||
/// </summary>
|
||
public class WebPageCodeHelper
|
||
{
|
||
#region 方法 -> 前端页面数据对象相关代码
|
||
/// <summary>
|
||
/// 前端开发对象类
|
||
/// </summary>
|
||
/// <param name="dtInterfaceParams">主接口入参字段数据源</param>
|
||
/// <param name="dtParamsModel">主接口入参对象数据源</param>
|
||
/// <param name="ParamsModelName">主接口入参对象名称</param>
|
||
/// <param name="HostTable">主接口返参字段数据源</param>
|
||
/// <param name="RelateTable">关接口返参字段数据源</param>
|
||
/// <returns></returns>
|
||
public static StringBuilder GetDataModel(DataTable dtInterfaceParams, DataTable dtParamsModel,
|
||
string ParamsModelName, DataTable HostTable, DataTable RelateTable = null)
|
||
{
|
||
StringBuilder _DataModel = new StringBuilder();
|
||
|
||
//生成接口入参相关对象代码
|
||
if (dtInterfaceParams != null && dtInterfaceParams.Rows.Count > 0)
|
||
{
|
||
string ModelName = "接口入参对象"; //接口入参对象中文注释
|
||
DataTable _DataTable = dtInterfaceParams.Copy();
|
||
Business.INTERFACE.ChangeInterfaceParamsToModel(_DataTable);
|
||
//生成主表数据对象代码
|
||
BuildDataModel(_DataModel, ModelName, ParamsModelName, _DataTable, dtParamsModel);
|
||
//接口入参对象
|
||
if (dtParamsModel.Rows.Count > 0)
|
||
{
|
||
//遍历所有的参数对象
|
||
Business.WebPageCodeHelper.BuildDataModel(_DataModel, dtParamsModel);
|
||
}
|
||
}
|
||
|
||
//生成主表数据对象代码
|
||
BuildDataModel(_DataModel, HostTable, HostTable);
|
||
|
||
//如果关联了附表,则把附表数据对象加进去
|
||
if (RelateTable != null && RelateTable.Rows.Count > 0)
|
||
{
|
||
//生成附表数据对象代码
|
||
BuildDataModel(_DataModel, RelateTable, RelateTable);
|
||
}
|
||
|
||
return _DataModel;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成前端页面多个数据对象<br/>
|
||
/// 代码样例:<br/>
|
||
/// // 应收账款相关类<br/>
|
||
/// export type AccountReceivablesModel = {<br/>
|
||
/// SERVERPART_NAME: string; // 服务区名称<br/>
|
||
/// REGISTERCOMPACT_ID: string; // 备案合同内码<br/>
|
||
/// BUSINESSPROJECT_ID?: number; // 经营项目内码<br/>
|
||
/// BUSINESSPROJECT_NAME: string; // 经营项目名称<br/>
|
||
/// BUSINESSPROJECT_ICO: string; // 经营项目图标<br/>
|
||
/// COMPACT_NAME: string; // 经营合同名称<br/>
|
||
/// SERVERPARTSHOP_NAME: string; // 门店名称<br/>
|
||
/// ACCOUNT_DATE: string; // 应收账款日期<br/>
|
||
/// PAYABLE_AMOUNT?: number; // 应缴金额<br/>
|
||
/// ProjectAccountDetailList?: ProjectAccountDetailModel[]; // 经营项目应收账款明细列表<br/>
|
||
/// };<br/>
|
||
/// // 经营项目应收账款明细相关类<br/>
|
||
/// export type ProjectAccountDetailModel = {<br/>
|
||
/// ACCOUNT_TYPE?: number; // 应收款项类型<br/>
|
||
/// ACCOUNT_NAME: string; // 应收款项名称<br/>
|
||
/// PAYABLE_AMOUNT?: number; // 应缴金额<br/>
|
||
/// };<br/>
|
||
/// </summary>
|
||
/// <param name="_DataModel">字符串</param>
|
||
/// <param name="dtInterfaceModel">接口参数字段数据源,包含入参、返参数据、参数对象</param>
|
||
/// <param name="dtDataModel">接口参数对象数据源:在解析字段类型时,如果是对象或者数据,要去匹配这个数据源去解析成对象的名称</param>
|
||
public static void BuildDataModel(StringBuilder _DataModel, DataTable dtInterfaceModel, DataTable dtDataModel = null)
|
||
{
|
||
foreach (DataRow drInterfaceModel in dtInterfaceModel.Select("INTERFACEMODEL_PID = -1", "INTERFACEMODEL_ID"))
|
||
{
|
||
//查询当前参数对象子级的字段
|
||
dtInterfaceModel.DefaultView.RowFilter = "INTERFACEMODEL_PID = " + drInterfaceModel["INTERFACEMODEL_ID"];
|
||
//按照参数对象内码排序
|
||
dtInterfaceModel.DefaultView.Sort = "INTERFACEMODEL_ID";
|
||
//获得筛选后的数据源
|
||
DataTable dtChildModel = dtInterfaceModel.DefaultView.ToTable();
|
||
//生成前端页面数据对象
|
||
BuildDataModel(_DataModel, drInterfaceModel["INTERFACEMODEL_COMMENT"].ToString(),
|
||
drInterfaceModel["INTERFACEMODEL_NAME"].ToString(), dtChildModel, dtDataModel);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成前端页面单个数据对象<br/>
|
||
/// 代码样例:<br/>
|
||
/// // 接口入参对象<br/>
|
||
/// export type ParamsModel = {<br/>
|
||
/// MerchantsId?: string; // 经营商户内码(加密)<br/>
|
||
/// MerchantsName?: string; // 经营商户名称(模糊查询)<br/>
|
||
/// ShowJustPayable?: number; // 只查询欠款数据(0【否】,1【是】)<br/>
|
||
/// PageIndex?: number; // 查询页码数<br/>
|
||
/// PageSize?: number; // 每页显示行数<br/>
|
||
/// SortStr?: string; // 排序条件<br/>
|
||
/// };<br/>
|
||
/// </summary>
|
||
/// <param name="_DataModel">字符串</param>
|
||
/// <param name="ModelNameComment">对象名称中文注释</param>
|
||
/// <param name="ModelName">对象名称</param>
|
||
/// <param name="dtInterfaceModel">接口参数字段数据源,包含入参、返参数据、参数对象</param>
|
||
/// <param name="dtDataModel"></param>
|
||
public static void BuildDataModel(StringBuilder _DataModel, string ModelNameComment, string ModelName,
|
||
DataTable dtInterfaceModel, DataTable dtDataModel = null)
|
||
{
|
||
//数据对象名称
|
||
_DataModel.AppendLine("// " + ModelNameComment);
|
||
_DataModel.AppendLine("export type " + ModelName + " = {");
|
||
//遍历数据对象的字段,开始拼接代码
|
||
foreach (DataRow drInterfaceModel in dtInterfaceModel.Rows)
|
||
{
|
||
if (drInterfaceModel["INTERFACEMODEL_NAME"].ToString() == "index")
|
||
{
|
||
continue;
|
||
}
|
||
//字段格式(0:string,1:number,2:date,3:bool,4:object,5:list)
|
||
string ColumnDataType = "string";
|
||
switch (drInterfaceModel["INTERFACEMODEL_FORMAT"].TryParseToInt())
|
||
{
|
||
case 1://数字型字段
|
||
ColumnDataType = "number";
|
||
break;
|
||
case 4://对象类型字段
|
||
ColumnDataType = "any";
|
||
//判断接口中是不是已经有这个对象的参数,如果有就改成这个对象名称
|
||
if (dtDataModel != null && dtDataModel.Rows.Count > 0 && dtDataModel.Select(
|
||
"INTERFACEMODEL_ID = " + drInterfaceModel["INTERFACEMODEL_ID"]).Length > 0)
|
||
{
|
||
ColumnDataType = dtDataModel.Select("INTERFACEMODEL_ID = " +
|
||
drInterfaceModel["INTERFACEMODEL_ID"])[0]["INTERFACEMODEL_NAME"].ToString();
|
||
}
|
||
break;
|
||
case 5://集合类型字段
|
||
ColumnDataType = "any[]";
|
||
//判断接口中是不是已经有这个对象的参数,如果有就改成这个对象名称
|
||
if (dtDataModel != null && dtDataModel.Rows.Count > 0 && dtDataModel.Select(
|
||
"INTERFACEMODEL_ID = " + drInterfaceModel["INTERFACEMODEL_ID"]).Length > 0)
|
||
{
|
||
ColumnDataType = dtDataModel.Select("INTERFACEMODEL_ID = " +
|
||
drInterfaceModel["INTERFACEMODEL_ID"])[0]["INTERFACEMODEL_NAME"].ToString() + "[]";
|
||
}
|
||
break;
|
||
}
|
||
//如果是必填项或者是字符串,字段定义不可以为null
|
||
if (drInterfaceModel["INTERFACEMODEL_REQUIRED"].ToString() == "1" ||
|
||
drInterfaceModel["INTERFACEMODEL_FORMAT"].ToString() == "0")
|
||
{
|
||
_DataModel.AppendLine(CommonHelper.GetTabChar(1) + drInterfaceModel["INTERFACEMODEL_NAME"].ToString() +
|
||
": " + ColumnDataType + "; // " + drInterfaceModel["INTERFACEMODEL_COMMENT"].ToString());
|
||
}
|
||
else
|
||
{
|
||
_DataModel.AppendLine(CommonHelper.GetTabChar(1) + drInterfaceModel["INTERFACEMODEL_NAME"].ToString() +
|
||
"?: " + ColumnDataType + "; // " + drInterfaceModel["INTERFACEMODEL_COMMENT"].ToString());
|
||
}
|
||
}
|
||
_DataModel.AppendLine("};");
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 前端页面请求接口相关代码
|
||
/// <summary>
|
||
/// 生成前端接口代码
|
||
/// import { tableList, wrapTreeNode } from '@/utils/format';<br/>
|
||
/// import request from '@/utils/request';<br/>
|
||
/// import type { CheckaccountModel } from './data'; // 引用接口数据对象<br/>
|
||
/// // 获取明细【现场稽核表】<br/>
|
||
/// export async function getDetail(checkaccountId: number) {<br/>
|
||
/// const data = await request(`/Audit/GetCHECKACCOUNTDetail?checkaccountId=${checkaccountId}`, {<br/>
|
||
/// method: 'GET',<br/>
|
||
/// });<br/>
|
||
/// if (data.Result_Code !== 100) {<br/>
|
||
/// return data.Result_Desc<br/>
|
||
/// }<br/>
|
||
/// return data.Result_Data;<br/>
|
||
/// }<br/>
|
||
/// </summary>
|
||
/// <param name="transaction">事务管理器</param>
|
||
/// <param name="ServiceTable">主接口数据源</param>
|
||
/// <param name="ParamsTable">接口入参字段数据源</param>
|
||
/// <param name="ServiceParamsName">主接口入参对象名称</param>
|
||
/// <param name="ServiceClassName">主接口相关类名称</param>
|
||
/// <param name="ServiceModelName">主接口相关对象名称</param>
|
||
/// <param name="ServiceRelateTable">关联接口数据源</param>
|
||
/// <param name="RelateClassName">关联接口相关类名称</param>
|
||
/// <param name="RelateModelName">关联接口相关对象名称</param>
|
||
/// <param name="ChartInterfaceIds">图表接口的内码集合</param>
|
||
/// <returns></returns>
|
||
public static StringBuilder GetService(Transaction transaction, DataTable ServiceTable, DataTable ParamsTable = null,
|
||
string ServiceParamsName = "", string ServiceClassName = "", string ServiceModelName = "", DataTable ServiceRelateTable = null,
|
||
string RelateClassName = "", string RelateModelName = "", List<string> ChartInterfaceIds = null)
|
||
{
|
||
StringBuilder _Service = new StringBuilder();
|
||
_Service.AppendLine("import { tableList, wrapTreeNode } from '@/utils/format';");
|
||
_Service.AppendLine("import request from '@/utils/request';");
|
||
if (!string.IsNullOrWhiteSpace(ServiceParamsName))
|
||
{
|
||
//判断需不需要申明入参数据对象
|
||
_Service.AppendLine("import type { " + ServiceParamsName + " } from './data'; // 引用入参数据对象");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(ServiceModelName))
|
||
{
|
||
//判断需不需要申明标准接口数据对象
|
||
_Service.AppendLine("import type { " + ServiceModelName + " } from './data'; // 引用标准接口数据对象");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(RelateModelName))
|
||
{
|
||
//判断需不需要申明关联表接口数据对象
|
||
_Service.AppendLine("import type { " + RelateModelName + " } from './data'; // 引用关联表接口数据对象");
|
||
}
|
||
//绑定主表接口代码
|
||
GetService(_Service, ServiceTable, null, ServiceParamsName, ServiceClassName, ServiceModelName);
|
||
|
||
if (ServiceRelateTable != null && ServiceRelateTable.Rows.Count > 0)
|
||
{
|
||
//绑定关联表接口代码
|
||
GetService(_Service, ServiceRelateTable, ParamsTable, "", RelateClassName, RelateModelName, true);
|
||
}
|
||
|
||
if (ChartInterfaceIds != null)
|
||
{
|
||
foreach (string ChartInterfaceId in ChartInterfaceIds)
|
||
{
|
||
//查询接口数据,并加载到接口代码中
|
||
DataTable dtInterface = new Business.INTERFACE(transaction).FillDataTable(
|
||
"WHERE INTERFACE_ID = " + ChartInterfaceId);
|
||
GetService(_Service, dtInterface);
|
||
}
|
||
}
|
||
|
||
return _Service;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定前端接口代码<br/>
|
||
/// 代码示例:<br/>
|
||
/// // 获取明细【现场稽核表】<br/>
|
||
/// export async function getDetail(checkaccountId: number) {<br/>
|
||
/// const data = await request(`/Audit/GetCHECKACCOUNTDetail?checkaccountId=${checkaccountId}`, {<br/>
|
||
/// method: 'GET',<br/>
|
||
/// });<br/>
|
||
/// if (data.Result_Code !== 100) {<br/>
|
||
/// return data.Result_Desc<br/>
|
||
/// }<br/>
|
||
/// return data.Result_Data;<br/>
|
||
/// }
|
||
/// </summary>
|
||
/// <param name="_Service">拼接接口代码的字符串</param>
|
||
/// <param name="ServiceTable">接口数据源</param>
|
||
/// <param name="ParamsTable">接口入参数据源</param>
|
||
/// <param name="ServiceParamsName">接口入参对象名称</param>
|
||
/// <param name="ServiceClassName">接口相关的类名称</param>
|
||
/// <param name="ServiceModelName">接口相关的对象名称</param>
|
||
/// <param name="IsRelate">判断是不是关联表的接口</param>
|
||
public static void GetService(StringBuilder _Service, DataTable ServiceTable, DataTable ParamsTable = null,
|
||
string ServiceParamsName = "", string ServiceClassName = "", string ServiceModelName = "", bool IsRelate = false)
|
||
{
|
||
foreach (DataRow _DataRow in ServiceTable.Rows)
|
||
{
|
||
//获取请求方式
|
||
string Method = _DataRow["INTERFACE_ACCEPTVERBS"].ToString() == "2" ? "POST" : "GET";
|
||
//获取请求接口路由名称
|
||
string RouteName = _DataRow["INTERFACE_ROUTE"].ToString().Split('/')[2];
|
||
//标准接口的名称格式:
|
||
//获取列表【XX】、获取明细【XX】、同步数据【XX】、删除数据【XX】、获取嵌套列表【XX】、获取嵌套树【XX】
|
||
_Service.AppendLine("// " + _DataRow["INTERFACE_NAME"]);
|
||
if (_DataRow["INTERFACE_NAME"].ToString().StartsWith("获取列表【"))
|
||
{
|
||
#region 获取列表接口
|
||
_Service.AppendLine("export async function get" + (IsRelate ? "Sub" : "") + "List(params?: any) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "const search = params ? { ...params, SortStr: params?.SortStr, " +
|
||
"keyWord: params?.keyWord, PageIndex: params?.searchParameter.current } : {};");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "const data = await request(`" + _DataRow["INTERFACE_ROUTE"] + "`, {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'POST',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "data: search,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "if (data.Result_Code !== 100) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "return {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "data: [],");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "current: 1,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "pageSize: 10,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "total: 0,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "success: false");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return tableList(data.Result_Data);");
|
||
#endregion
|
||
}
|
||
else if (_DataRow["INTERFACE_NAME"].ToString().StartsWith("获取明细【"))
|
||
{
|
||
#region 获取明细接口
|
||
//获取明细接口,可能会有多个入参,所以要遍历接口入参数据,加载所以的入参字段
|
||
string str_Params = ServiceClassName.ToLower() + "Id: number",
|
||
str_reqParams = ServiceClassName.ToLower() + "Id=${" + ServiceClassName.ToLower() + "Id}";
|
||
if (ParamsTable != null && ParamsTable.Rows.Count > 0)
|
||
{
|
||
//初始化接口入参定义,从接口入参数据源中获取值
|
||
str_Params = "";
|
||
str_reqParams = "";
|
||
foreach (DataRow drParams in ParamsTable.Select("INTERFACE_ID = " + _DataRow["INTERFACE_ID"]))
|
||
{
|
||
//解析入参字段格式(0:string,1:number,2:date,3:bool,4:object,5:list)
|
||
string ColumnDataType = "string";
|
||
switch (drParams["INTERFACEPARAMS_FORMAT"].TryParseToInt())
|
||
{
|
||
case 1://数字型
|
||
ColumnDataType = "number";
|
||
break;
|
||
case 3://布尔型
|
||
ColumnDataType = "boolean";
|
||
break;
|
||
case 4://数据对象
|
||
ColumnDataType = "any";
|
||
break;
|
||
case 5://数组
|
||
ColumnDataType = "any[]";
|
||
break;
|
||
}
|
||
//拼接字段参数【非必传参数带上?,否则不带上】,样例:
|
||
//ServerpartCodes: string, ShowWholePower?: boolean
|
||
str_Params += (str_Params == "" ? "" : ", ") + drParams["INTERFACEPARAMS_NAME"] +
|
||
(drParams["INTERFACEPARAMS_REQUIRED"].ToString() == "1" ? "" : "?") + ": " + ColumnDataType;
|
||
str_reqParams += drParams["INTERFACEPARAMS_NAME"] + "=${" + drParams["INTERFACEPARAMS_NAME"] + "}";
|
||
}
|
||
}
|
||
|
||
_Service.AppendLine("export async function get" + (IsRelate ? "Sub" : "") + "Detail(" + str_Params + ") {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "const data = await request(`" +
|
||
_DataRow["INTERFACE_ROUTE"] + "?" + str_reqParams + "`, {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'GET',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "if (data.Result_Code !== 100) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "return data.Result_Desc");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return data.Result_Data;");
|
||
#endregion
|
||
}
|
||
else if (_DataRow["INTERFACE_NAME"].ToString().StartsWith("同步数据【"))
|
||
{
|
||
#region 同步数据接口
|
||
_Service.AppendLine("export async function update" + ServiceClassName.ToLower() + "(" +
|
||
ServiceClassName.ToLower() + ": " + ServiceModelName + ") {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return request(`" + _DataRow["INTERFACE_ROUTE"] + "`, {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'POST',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "data: " + ServiceClassName.ToLower() + ",");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "requestType: 'form',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
#endregion
|
||
}
|
||
else if (_DataRow["INTERFACE_NAME"].ToString().StartsWith("删除数据【"))
|
||
{
|
||
#region 删除数据接口
|
||
_Service.AppendLine("export async function del" + ServiceClassName.ToLower() +
|
||
"(" + ServiceClassName.ToLower() + "id: number) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return request(`" + _DataRow["INTERFACE_ROUTE"] + "?" +
|
||
ServiceClassName.ToLower() + "id=${" + ServiceClassName.ToLower() + "id}`, {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'POST',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "requestType: 'form',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
//标准接口中的子父级嵌套列表、子父级嵌套树接口以及非标准接口,按照下面的规则编写
|
||
_Service.AppendLine("export async function " + RouteName + "(params?: " +
|
||
(!string.IsNullOrWhiteSpace(ServiceParamsName) ? ServiceParamsName : "any") + ") {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "const data = await request('" + _DataRow["INTERFACE_ROUTE"] + "', {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: '" + Method + "',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "params,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
_Service.AppendLine("");
|
||
//返参格式(0:字符串;1:单体对象;2:列表;3:子父级对象;4:子父级列表)
|
||
switch (_DataRow["RESPONSE_FORMAT"].TryParseToInt())
|
||
{
|
||
case 0:
|
||
#region 获取执行结果
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return await request(`" + _DataRow["INTERFACE_ROUTE"] + "`, {");
|
||
if (_DataRow["INTERFACE_ACCEPTVERBS"].ToString() == "1")
|
||
{
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'GET',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "params");
|
||
}
|
||
else
|
||
{
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "method: 'POST',");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "data: " + ServiceModelName + ",");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "requestType: 'form',");
|
||
}
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
#endregion
|
||
break;
|
||
case 1: //单体对象
|
||
case 3: //子父级对象,返参要处理的格式
|
||
#region 获取单体数据对象
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "if (data.Result_Code !== 100) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "return data.Result_Desc");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return data.Result_Data;");
|
||
#endregion
|
||
break;
|
||
case 2: //列表形式的接口,返参要处理的格式
|
||
#region 获取列表数据
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "if (data.Result_Code !== 100) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "return {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "data: [],");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "current: 1,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "pageSize: 10,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "total: 0,");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(3) + "success: false");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return tableList(data.Result_Data);");
|
||
#endregion
|
||
break;
|
||
case 4: //子父级列表形式的接口,返参要处理的格式
|
||
#region 获取子父级列表数据
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "if (data.Result_Code !== 100) {");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(2) + "return []");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Service.AppendLine("");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "const treeTable = await wrapTreeNode(data.Result_Data.List);");
|
||
_Service.AppendLine(CommonHelper.GetTabChar(1) + "return [...treeTable];");
|
||
#endregion
|
||
break;
|
||
}
|
||
}
|
||
_Service.AppendLine("}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 前端页面相关代码
|
||
/// <summary>
|
||
/// 生成index页面代码
|
||
/// </summary>
|
||
/// <param name="webPageCodeModel">前端页面控件</param>
|
||
/// <param name="dtInterfaceParams">主接口入参字段列表数据源</param>
|
||
/// <returns></returns>
|
||
public static StringBuilder GetIndex(Model.WebPageCodeModel webPageCodeModel, DataTable dtInterfaceParams)
|
||
{
|
||
StringBuilder _Index = new StringBuilder();
|
||
|
||
Model.TreeViewModel treeViewModel = webPageCodeModel.treeViewModel;
|
||
Model.TableLayoutModel tableLayoutModel = webPageCodeModel.tableLayoutModel;
|
||
Model.WebChartModel webChartModel = webPageCodeModel.webChartModel;
|
||
|
||
#region 解析接口传入的列表字段数据源
|
||
//主接口返参字段列表数据源
|
||
DataTable dtGVEModel = null;
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.dtGVEModel))
|
||
{
|
||
dtGVEModel = JsonConvert.DeserializeObject<DataTable>(webPageCodeModel.dtGVEModel);
|
||
if (dtGVEModel.Columns.Contains("ENUM_FIELD") && dtGVEModel.Columns.Contains("FieldExplainField"))
|
||
{
|
||
foreach (DataRow dataRow in dtGVEModel.Rows)
|
||
{
|
||
if (dataRow["FieldExplainField"].ToString() == "")
|
||
{
|
||
dataRow["FieldExplainField"] = dataRow["ENUM_FIELD"];
|
||
}
|
||
}
|
||
}
|
||
//如果列表字段不包含索引【ColumnIndex】,则补充上去
|
||
if (!dtGVEModel.Columns.Contains("ColumnIndex"))
|
||
{
|
||
dtGVEModel.Columns.Add("ColumnIndex");
|
||
}
|
||
}
|
||
//主接口返参其他对象字段列表数据源
|
||
DataTable dtGVEOtherModel = null;
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.dtGVEOtherModel))
|
||
{
|
||
dtGVEOtherModel = JsonConvert.DeserializeObject<DataTable>(webPageCodeModel.dtGVEOtherModel);
|
||
if (dtGVEOtherModel.Columns.Contains("ENUM_FIELD") && dtGVEOtherModel.Columns.Contains("FieldExplainField"))
|
||
{
|
||
foreach (DataRow dataRow in dtGVEOtherModel.Rows)
|
||
{
|
||
if (dataRow["FieldExplainField"].ToString() == "")
|
||
{
|
||
dataRow["FieldExplainField"] = dataRow["ENUM_FIELD"];
|
||
}
|
||
}
|
||
}
|
||
//如果列表字段不包含索引【ColumnIndex】,则补充上去
|
||
if (!dtGVEOtherModel.Columns.Contains("ColumnIndex"))
|
||
{
|
||
dtGVEOtherModel.Columns.Add("ColumnIndex");
|
||
}
|
||
}
|
||
//主接口编辑页的字段数据源数据源
|
||
DataTable dtEditor = null;
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.dtEditor))
|
||
{
|
||
dtEditor = JsonConvert.DeserializeObject<DataTable>(webPageCodeModel.dtEditor);
|
||
if (dtEditor.Columns.Contains("ENUM_FIELD") && dtEditor.Columns.Contains("FieldExplainField"))
|
||
{
|
||
foreach (DataRow dataRow in dtEditor.Rows)
|
||
{
|
||
if (dataRow["FieldExplainField"].ToString() == "")
|
||
{
|
||
dataRow["FieldExplainField"] = dataRow["ENUM_FIELD"];
|
||
}
|
||
}
|
||
}
|
||
//如果列表字段不包含索引【ColumnIndex】,则补充上去
|
||
if (!dtEditor.Columns.Contains("ColumnIndex"))
|
||
{
|
||
dtEditor.Columns.Add("ColumnIndex");
|
||
}
|
||
}
|
||
//关联接口返参字段数据源
|
||
DataTable dtGridViewExRelate = null;
|
||
//关联表编辑页的字段数据源数据源
|
||
DataTable dtRelateEditorTable = null;
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.relateInterfaceModel.dtGridViewExRelate))
|
||
{
|
||
dtGridViewExRelate = JsonConvert.DeserializeObject<DataTable>(
|
||
webPageCodeModel.relateInterfaceModel.dtGridViewExRelate);
|
||
if (dtGridViewExRelate.Columns.Contains("ENUM_FIELD") &&
|
||
dtGridViewExRelate.Columns.Contains("FieldExplainField"))
|
||
{
|
||
foreach (DataRow dataRow in dtGridViewExRelate.Rows)
|
||
{
|
||
if (dataRow["FieldExplainField"].ToString() == "")
|
||
{
|
||
dataRow["FieldExplainField"] = dataRow["ENUM_FIELD"];
|
||
}
|
||
}
|
||
}
|
||
//如果列表字段不包含索引【ColumnIndex】,则补充上去
|
||
if (!dtGridViewExRelate.Columns.Contains("ColumnIndex"))
|
||
{
|
||
dtGridViewExRelate.Columns.Add("ColumnIndex");
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.relateInterfaceModel.dtRelateEditorTable))
|
||
{
|
||
dtRelateEditorTable = JsonConvert.DeserializeObject<DataTable>(
|
||
webPageCodeModel.relateInterfaceModel.dtRelateEditorTable);
|
||
if (dtRelateEditorTable.Columns.Contains("ENUM_FIELD") &&
|
||
dtRelateEditorTable.Columns.Contains("FieldExplainField"))
|
||
{
|
||
foreach (DataRow dataRow in dtRelateEditorTable.Rows)
|
||
{
|
||
if (dataRow["FieldExplainField"].ToString() == "")
|
||
{
|
||
dataRow["FieldExplainField"] = dataRow["ENUM_FIELD"];
|
||
}
|
||
}
|
||
}
|
||
//如果列表字段不包含索引【ColumnIndex】,则补充上去
|
||
if (!dtRelateEditorTable.Columns.Contains("ColumnIndex"))
|
||
{
|
||
dtRelateEditorTable.Columns.Add("ColumnIndex");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
bool ShowEdit = webPageCodeModel.tableLayoutModel != null && dtEditor != null && dtEditor.Rows.Count > 0 &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.BtnNameToolBar);
|
||
|
||
#region 引用相关代码
|
||
//添加通用引用
|
||
IndexPageImport(_Index, webPageCodeModel);
|
||
if (webChartModel != null)
|
||
{
|
||
//设置了第一个图表,则添加第一个图表的组件引用
|
||
if (!string.IsNullOrWhiteSpace(webChartModel.FChartValue))
|
||
{
|
||
_Index.AppendLine("import FChart from './components/FChart';");
|
||
}
|
||
//设置了第二个图表,则添加第二个图表的组件引用
|
||
if (!string.IsNullOrWhiteSpace(webChartModel.SChartValue))
|
||
{
|
||
_Index.AppendLine("import SChart from './components/SChart';");
|
||
}
|
||
//设置了第三个图表,则添加第三个图表的组件引用
|
||
if (!string.IsNullOrWhiteSpace(webChartModel.TChartValue))
|
||
{
|
||
_Index.AppendLine("import TChart from './components/TChart';");
|
||
}
|
||
}
|
||
_Index.AppendLine("");
|
||
|
||
//如果设置了合计栏的标题,需要引用text组件
|
||
if (!string.IsNullOrWhiteSpace(tableLayoutModel.SummaryTitle))
|
||
{
|
||
_Index.AppendLine("const { Text } = Typography;");
|
||
_Index.AppendLine("");
|
||
}
|
||
#endregion
|
||
|
||
if (webPageCodeModel.InterfaceType == 0)
|
||
{
|
||
//标准接口有增删改的功能,需要添加删除和同步数据的方法
|
||
|
||
#region 删除数据
|
||
_Index.AppendLine("const handelDelete = async (" + webPageCodeModel.HostClassName.ToLower() + "id: number) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const hide = message.loading('正在删除...');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "try {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const result = await del" +
|
||
webPageCodeModel.HostClassName.ToLower() + "(" + webPageCodeModel.HostClassName.ToLower() + "id);");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "hide();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "if (result.Result_Code !== 100) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "message.error(`${result.Result_Desc}` || `${result.Result_Code}:删除失败`);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "return false;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.success('删除成功!');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return true;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "} catch (error) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "hide();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error('删除失败');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return false;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine("};");
|
||
#endregion
|
||
|
||
_Index.AppendLine("");
|
||
|
||
#region 同步数据
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
//附表模式数据提交
|
||
_Index.AppendLine("const handleAddUpdate = async (fields: " + webPageCodeModel.HostModelName +
|
||
" & " + webPageCodeModel.relateInterfaceModel.RelateModelName + " & any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const hide = message.loading('正在提交...');");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const result = await update" +
|
||
webPageCodeModel.HostClassName.ToLower() + "(fields);");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (result.Result_Code !== 100) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error(`${result.Result_Desc}` || `${result.Result_Code}:提交失败`);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return false;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const subResult = await update" +
|
||
webPageCodeModel.relateInterfaceModel.RelateClassName.ToLower() + "({ ...fields, " +
|
||
webPageCodeModel.relateInterfaceModel.RelateField + ": result.Result_Data." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + " })");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "hide();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (subResult.Result_Code !== 100) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error(`${subResult.Result_Desc}` || `${subResult.Result_Code}:提交失败`);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return false;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "message.success(fields." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + " ? '更新成功!' : '新建成功!');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return result.Result_Data ? result.Result_Data : true;");
|
||
_Index.AppendLine("};");
|
||
}
|
||
else
|
||
{
|
||
//单表数据提交
|
||
_Index.AppendLine("const handleAddUpdate = async (fields: " + webPageCodeModel.HostModelName + ") => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const hide = message.loading('正在提交...');");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const result = await update" +
|
||
webPageCodeModel.HostClassName.ToLower() + "(fields);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "hide();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (result.Result_Code !== 100) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error(`${result.Result_Desc}` || `${result.Result_Code}:提交失败`);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return false;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
|
||
if (webPageCodeModel.attachmentLayoutModel != null &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.attachmentLayoutModel.ShowAttachmentValue))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "message.success(fields." +
|
||
webPageCodeModel.HostClassName + "_ID ? '更新成功!' : '新建成功!');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return result.Result_Data;");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return result.Result_Data ? result.Result_Data : true;");
|
||
}
|
||
_Index.AppendLine("};");
|
||
}
|
||
#endregion
|
||
|
||
_Index.AppendLine("");
|
||
}
|
||
//检查附件组件对象是否存在设置
|
||
if (webPageCodeModel.attachmentLayoutModel != null)
|
||
{
|
||
//页面附件上传的是图片,则需要增加校验图片的方法
|
||
if (webPageCodeModel.attachmentLayoutModel.Attachment_Type == "1" &&
|
||
(webPageCodeModel.attachmentLayoutModel.UploadAttachment ||
|
||
webPageCodeModel.attachmentLayoutModel.SearchAttachment ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.attachmentLayoutModel.ShowAttachmentValue)))
|
||
{
|
||
SetUploadCheckFunc(_Index);
|
||
}
|
||
//页面附件上传的是文件,增加上传附件的方法
|
||
if (webPageCodeModel.attachmentLayoutModel.Attachment_Type == "2" &&
|
||
webPageCodeModel.attachmentLayoutModel.UploadAttachment)
|
||
{
|
||
BuildUploadFunc(_Index, webPageCodeModel.attachmentLayoutModel);
|
||
}
|
||
}
|
||
|
||
#region 查询数据
|
||
_Index.AppendLine("const " + webPageCodeModel.HostModelName.Replace("Model", "") +
|
||
"Table: React.FC<{ currentUser: CurrentUser | undefined }> = (props) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const { currentUser } = props");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const actionRef = useRef<ActionType>();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const formRef = useRef<FormInstance>();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [currentRow, setCurrentRow] = useState<" +
|
||
webPageCodeModel.HostModelName + ">();");
|
||
//如果设置了关联表,且有编辑页面,需要申明两个表的集合对象
|
||
if (webPageCodeModel.relateInterfaceModel != null &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.BtnNameToolBar))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [fields, setFields] = useState<" + webPageCodeModel.HostModelName +
|
||
" & " + webPageCodeModel.relateInterfaceModel.RelateModelName + ">(); // 当前组件显示的主表和子表数据");
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [showDetail, setShowDetail] = useState<boolean>();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [modalVisible, handleModalVisible] = useState<boolean>();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [confirmLoading, handleConfirmLoading] = " +
|
||
"useState<boolean>(false) // 弹出框的内容表单是否在提交");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [searchParams, setSearchParams] = useState<any>();");
|
||
//列表接口要加载的类型:1【普通列表接口】,2【子父级接口】
|
||
if (webPageCodeModel.ListType == 2)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [" + webPageCodeModel.HostClassName.ToLower() +
|
||
"Tree, set" + webPageCodeModel.HostClassName + "Tree] = useState<any[]>(); " +
|
||
"// 树结构数据菜单 用于弹出编辑时选择上级角色");
|
||
}
|
||
//显示打印按钮时需要定义的参数
|
||
if (tableLayoutModel.ShowPrint)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [printOut, setPrintOut] = useState<any>(); // 定义打印的数据内容");
|
||
}
|
||
_Index.AppendLine("");
|
||
|
||
if (webPageCodeModel.InterfaceType == 0)
|
||
{
|
||
#region 弹出框拖动效果
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 弹出框拖动效果");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [bounds, setBounds] = useState<{ " +
|
||
"left: number, right: number, top: number, bottom: number }>() // 移动的位置");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [disabled, setDraggleDisabled] = useState<boolean>() // 是否拖动");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const draggleRef = React.createRef<any>()");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const onDraggaleStart = (event, uiData) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const { clientWidth, clientHeight } = window.document.documentElement;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const targetRect = draggleRef.current?.getBoundingClientRect();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "if (!targetRect) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "return;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "setBounds({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "left: -targetRect.left + uiData.x,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "right: clientWidth - (targetRect.right - uiData.x),");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "top: -targetRect.top + uiData.y,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "bottom: clientHeight - (targetRect.bottom - uiData.y),");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "});");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "};");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 拖动结束");
|
||
#endregion
|
||
|
||
_Index.AppendLine("");
|
||
}
|
||
|
||
//左侧有树时,定义树的加载事件
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.TreeViewWidth))
|
||
{
|
||
BuildTreeLoading(_Index, treeViewModel);
|
||
}
|
||
//检查附件组件对象是否存在设置
|
||
if (webPageCodeModel.attachmentLayoutModel != null)
|
||
{
|
||
//有附件组件时,定义预览图片的方法
|
||
if (webPageCodeModel.attachmentLayoutModel.UploadAttachment ||
|
||
webPageCodeModel.attachmentLayoutModel.SearchAttachment ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.attachmentLayoutModel.ShowAttachmentValue))
|
||
{
|
||
SetPreviewFunc(_Index, webPageCodeModel.attachmentLayoutModel,
|
||
webPageCodeModel.HostModelName, webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName);
|
||
}
|
||
}
|
||
//ctl 2023-11-01 兼容列表树状枚举解析,取消ShowColumn = 1过滤
|
||
if (dtEditor != null && dtEditor.Rows.Count > 0)
|
||
{
|
||
//定义枚举相关事件
|
||
dtEditor.DefaultView.RowFilter = " (FieldExplainField is not null and FieldExplainField <> '')";//ShowColumn = 1 and
|
||
DataTable dtFieldExplainField = dtEditor.DefaultView.ToTable();
|
||
//合并关联表中的枚举字段
|
||
if (dtRelateEditorTable != null && dtRelateEditorTable.Select(
|
||
"(FieldExplainField is not null and FieldExplainField <> '')").Length > 0)//ShowColumn = 1 and
|
||
{
|
||
DataTable dtRelateEnum = dtRelateEditorTable.Select(
|
||
"(FieldExplainField is not null and FieldExplainField <> '')").CopyToDataTable();//"ShowColumn = 1 and " +
|
||
|
||
foreach (DataRow drRelateEnum in dtRelateEnum.Rows)
|
||
{
|
||
DataRow drFieldExplainField = dtFieldExplainField.NewRow();
|
||
drFieldExplainField["INTERFACEMODEL_COMMENT"] = drRelateEnum["INTERFACEMODEL_COMMENT"];
|
||
drFieldExplainField["FieldExplainField"] = drRelateEnum["FieldExplainField"];
|
||
dtFieldExplainField.Rows.Add(drFieldExplainField);
|
||
}
|
||
}
|
||
//筛选出不重复的枚举字段,绑定到列表中
|
||
foreach (DataRow drEnum in dtFieldExplainField.DefaultView.ToTable(true, "INTERFACEMODEL_COMMENT", "FieldExplainField").Rows)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// " + drEnum["INTERFACEMODEL_COMMENT"] + "枚举解析");
|
||
BuildEnumLoading(_Index, drEnum["FieldExplainField"].ToString(), treeViewModel.DataAuthority == "2", treeViewModel.Province_Code);
|
||
}
|
||
}
|
||
#region 定义列表和抽屉字段
|
||
//生成列表字段
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 定义列表字段内容");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const columns: ProColumns<" +
|
||
webPageCodeModel.HostModelName + ">[] = [");
|
||
BuildListModel(_Index, webPageCodeModel, dtInterfaceParams, dtGVEModel, ShowEdit);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "];");
|
||
|
||
//如果关联了附表,则加载附表字段
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 定义附表字段内容");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const subColumns: ProColumns<" +
|
||
webPageCodeModel.relateInterfaceModel.RelateModelName + ">[] = [");
|
||
BuildDrawerSubModel(_Index, dtGridViewExRelate, tableLayoutModel.ShowPagination);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "];");
|
||
}
|
||
|
||
_Index.AppendLine("");
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "<PageContainer header={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "title: '',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "breadcrumb: { }");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}}>");
|
||
|
||
#region 树和ProTable列表代码
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.TreeViewWidth))
|
||
{
|
||
int tableStart = 2;
|
||
//有打印功能的时候要增加一层dome,所以代码要再缩进一格
|
||
if (tableLayoutModel.ShowPrint)
|
||
{
|
||
tableStart = 3;
|
||
}
|
||
//获取ProTable列表代码
|
||
StringBuilder sbProTable = new StringBuilder();
|
||
BuildProTable(sbProTable, webPageCodeModel, dtGVEModel, dtGVEOtherModel, dtGridViewExRelate, dtEditor, tableStart);
|
||
//如果左侧设置了树,则加载绑定树的代码
|
||
BuildTreeAndProTable(_Index, webPageCodeModel, sbProTable.ToString());
|
||
}
|
||
else
|
||
{
|
||
//有打印功能的时候要增加一层dome
|
||
if (tableLayoutModel.ShowPrint)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "<div");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "ref={(el) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "// 打印报表");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "setPrintOut(el);");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + ">");
|
||
BuildProTable(_Index, webPageCodeModel, dtGVEModel, dtGVEOtherModel, dtGridViewExRelate, dtEditor, 1);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "</div>");
|
||
}
|
||
else
|
||
{
|
||
//加载ProTable列表代码
|
||
BuildProTable(_Index, webPageCodeModel, dtGVEModel, dtGVEOtherModel, dtGridViewExRelate, dtEditor);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
if (!string.IsNullOrWhiteSpace(tableLayoutModel.DrawerWidth))
|
||
{
|
||
#region Drawer【抽屉代码】
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "<Drawer");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "width={" + tableLayoutModel.DrawerWidth + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "visible={showDetail}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "onClose={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "setCurrentRow(undefined);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "setShowDetail(false);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "closable={false}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{currentRow?." +
|
||
webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName.Replace(",", " && currentRow?.") + " && (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "<ProDescriptions<" + webPageCodeModel.HostModelName + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "column={" + tableLayoutModel.EveryLineCount + "}");
|
||
if (!string.IsNullOrWhiteSpace(tableLayoutModel.DrawerTitle))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "title={currentRow?." +
|
||
tableLayoutModel.DrawerTitle + "}");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "request={async () => ({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "data: currentRow || {},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "})}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "params={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "id: currentRow?." +
|
||
webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName.Replace(",", " + currentRow?.") + ",");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) +
|
||
"columns={columns as ProDescriptionsItemProps<" + webPageCodeModel.HostModelName + ">[]}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "/>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + ")}");
|
||
//显示附表内容
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{<ProDescriptions");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "column={" + tableLayoutModel.EveryLineCount + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "request={async () => ({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "data: await getSubDetail(currentRow?." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + "),");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "})}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "columns={subColumns as ProDescriptionsItemProps<" +
|
||
webPageCodeModel.relateInterfaceModel.RelateModelName + ">[]}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "/>}");
|
||
}
|
||
//显示图片附件组件
|
||
if (webPageCodeModel.attachmentLayoutModel != null &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.attachmentLayoutModel.ShowAttachmentValue))
|
||
{
|
||
if (webPageCodeModel.attachmentLayoutModel.Attachment_Type == "1")
|
||
{
|
||
//查看图片
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{/* 标题名称可以按需修改 */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{currentRow?." +
|
||
webPageCodeModel.attachmentLayoutModel.Attachment_Field +
|
||
" && <ProDescriptions.Item label=\"图片信息\" span={2}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "<Image width={100} height={100} src={currentRow?." +
|
||
webPageCodeModel.attachmentLayoutModel.Attachment_Field +
|
||
"} style={{ objectFit: \"contain\", border: '1px solid #eee' }} />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "</ProDescriptions.Item>}");
|
||
}
|
||
else
|
||
{
|
||
//查看文件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{/* 标题名称可以按需修改 */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "<div>附件信息</div>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "fileList ?");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "<Upload");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "defaultFileList={fileList || []}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "showUploadList={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "showDownloadIcon: false,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "showRemoveIcon: false,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "/> : '-'");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}");
|
||
}
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "</Drawer>");
|
||
#endregion
|
||
}
|
||
if (ShowEdit)
|
||
{
|
||
#region Modal【编辑弹出框代码】
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "<Modal");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "title={");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "<div");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "style={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "width: '100%',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "cursor: 'move',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onMouseOver={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "if (disabled) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "setDraggleDisabled(false)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onMouseOut={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "setDraggleDisabled(true)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onFocus={() => { }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onBlur={() => { }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "{currentRow ? '更新" + webPageCodeModel.tableLayoutModel.EditorTitle +
|
||
"' : '新建" + webPageCodeModel.tableLayoutModel.EditorTitle + "'}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "</div>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "destroyOnClose={true}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "width={" + webPageCodeModel.tableLayoutModel.EditorWidth + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "visible={modalVisible}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "confirmLoading={confirmLoading}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "afterClose={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "formRef.current?.resetFields();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "setCurrentRow(undefined);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "onCancel={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "handleConfirmLoading(false)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "handleModalVisible(false)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "onOk={async () => { // 提交框内的数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "formRef?.current?.validateFields().then(()=>{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "handleConfirmLoading(true)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "formRef?.current?.submit()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "})");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "modalRender={(modal) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "return <Draggable");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "disabled={disabled}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "bounds={bounds}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onStart={(event, uiData) => onDraggaleStart(event, uiData)}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "<div ref={draggleRef}>{modal}</div>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "</Draggable>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "<ProForm<" + webPageCodeModel.HostModelName + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "layout={'horizontal'}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "wrapperCol={{ span: 16 }} // 表单项 填写部分所占的栅格数");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "labelCol={{ span: 6 }} // 表单项 标题所占的栅格数");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "formRef={formRef}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "autoFocusFirstInput");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "submitter={false}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "preserve={false}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "initialValues={currentRow}");
|
||
//如果有附表,则组合两个表的数据加载到编辑框中
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "request={async () => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "// 初始化数据 ");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "const data: any = {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "STAFF_NAME: currentUser ? currentUser.Name : '',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "USER_ID: currentUser ? currentUser.ID : '',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "OPERATE_DATE: moment().format('YYYY-MM-DD hh:mm:ss'),");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "};");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "// 如果是编辑数据 则需要请求原数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "if (currentRow?." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + ") {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "const subData: any = await getSubDetail(currentRow?." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + "); // 附表详情");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "const newData = {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "...currentRow,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "...subData,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "setFields(newData);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "return newData;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "return { ...data };");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "}}");
|
||
}
|
||
|
||
#region 编辑页提交事件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "onFinish={async (values) => {");
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "let newValue: any = { ...values };");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "if (fields && fields." +
|
||
webPageCodeModel.relateInterfaceModel.HostField + ") {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "// 编辑数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "newValue = { ...fields, ...values };");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "// 如果有开关,要把开关的代码写进去");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "const success = await handleAddUpdate({ ...newValue });");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "let newValue: " + webPageCodeModel.HostModelName + " = { ...values };");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "if (currentRow) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "// 编辑数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "newValue = { ...values, " + webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName +
|
||
": currentRow." + webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName + " };");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "// 如果有开关,要把开关的代码写进去");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "const success = await handleAddUpdate(newValue as " + webPageCodeModel.HostModelName + ");");
|
||
}
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "handleConfirmLoading(false)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "if (success) {");
|
||
if (webPageCodeModel.attachmentLayoutModel != null &&
|
||
webPageCodeModel.attachmentLayoutModel.UploadAttachment &&
|
||
webPageCodeModel.attachmentLayoutModel.Attachment_Type == "2")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "const waitUpload = fileList.filter(n => n.status !== 'done')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "if (waitUpload.length > 0) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "setCurrentRow(success)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "const uploadSuccess = " +
|
||
"await customUploadRequest(waitUpload, success?." + webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName + ")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "if (uploadSuccess) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "if (actionRef.current) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10) + "actionRef.current.reload();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "handleModalVisible(false);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "if (actionRef.current) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "actionRef.current.reload();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "handleModalVisible(false);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "if (actionRef.current) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "actionRef.current.reload();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "handleModalVisible(false);");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + ">");
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "<Row>");
|
||
//添加编辑页字段
|
||
BuildEditModel(_Index, dtEditor, webPageCodeModel.tableLayoutModel.EveryLineCount,
|
||
webPageCodeModel.HostClassName, true, webPageCodeModel.ListType.TryParseToInt());
|
||
//获取编辑列表中不显示的字段
|
||
DataTable dtHideEditor;
|
||
//如果有附表,则添加附表中的字段
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
BuildEditModel(_Index, dtRelateEditorTable, webPageCodeModel.tableLayoutModel.EveryLineCount, "");
|
||
//获取主接口和关联接口编辑页面要隐藏的字段
|
||
dtHideEditor = CombineHideColumns(dtEditor, dtRelateEditorTable);
|
||
}
|
||
else
|
||
{
|
||
//获取主接口编辑页面要隐藏的字段
|
||
dtHideEditor = CombineHideColumns(dtEditor, null);
|
||
}
|
||
//绑定编辑页面上要隐藏的字段
|
||
if (dtHideEditor.Rows.Count > 0)
|
||
{
|
||
BuildEditModel(_Index, dtHideEditor, webPageCodeModel.tableLayoutModel.EveryLineCount, "", false);
|
||
}
|
||
|
||
#region 编辑页附件相关代码
|
||
if (webPageCodeModel.attachmentLayoutModel != null &&
|
||
(webPageCodeModel.attachmentLayoutModel.UploadAttachment ||
|
||
webPageCodeModel.attachmentLayoutModel.SearchAttachment))
|
||
{
|
||
BuildEditFileUpload(_Index, webPageCodeModel.attachmentLayoutModel);
|
||
}
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "</Row>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "</ProForm>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "</Modal>");
|
||
#endregion
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.TreeViewWidth) && !string.IsNullOrWhiteSpace(treeViewModel.UsedDefinedModeValue))
|
||
{
|
||
#region Modal【用户自定义类别弹出框代码】
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "{/* " + treeViewModel.UsedDefinedModeText + " */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "<Modal");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "title=\"" + treeViewModel.UsedDefinedModeText + "设置\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "bodyStyle={{ padding: 0, minHeight: 600 }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "visible={categoryVisible}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "width={1024}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "destroyOnClose={true}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "onOk={()=>{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "handleCategoryVisible(false)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "loadType()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "onCancel={() => handleCategoryVisible(false)}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "<CategoryTable typeName='" +
|
||
treeViewModel.UsedDefinedModeText + "' categoryType={" +
|
||
treeViewModel.UsedDefinedModeValue + "} />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "</Modal>");
|
||
#endregion
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "</PageContainer>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + ");");
|
||
_Index.AppendLine("};");
|
||
#endregion
|
||
|
||
_Index.AppendLine("export default connect(({ user }: ConnectState) => ({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "currentUser: user.currentUser");
|
||
_Index.AppendLine("}))(" + webPageCodeModel.HostModelName.Replace("Model", "") + "Table);");
|
||
|
||
return _Index;
|
||
}
|
||
|
||
#region 获取树对应的接口
|
||
/// <summary>
|
||
/// 获取树对应的接口
|
||
/// </summary>
|
||
/// <param name="treeViewModel">前端页面左侧树的布局设置内容</param>
|
||
/// <returns></returns>
|
||
public static string GetTreeInterfaceName(Model.TreeViewModel treeViewModel)
|
||
{
|
||
string TreeName = "";
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.UsedDefinedModeValue))
|
||
{
|
||
return "getCustomTypeTree";
|
||
}
|
||
else
|
||
{
|
||
switch (treeViewModel.DataMode)
|
||
{
|
||
case "1000":
|
||
case "1100":
|
||
TreeName = "getServerpartTree";
|
||
break;
|
||
case "1200":
|
||
TreeName = "getServerpartShopTree";
|
||
break;
|
||
case "1300":
|
||
TreeName = "getOwnerUnitTree";
|
||
break;
|
||
case "1400":
|
||
TreeName = "getUserShopTree";
|
||
break;
|
||
case "2000":
|
||
TreeName = "getBusinessTradeTree";
|
||
break;
|
||
case "3000":
|
||
TreeName = "getCommodityTypeTree";
|
||
break;
|
||
case "3100":
|
||
TreeName = "getUserDefinedTypeTree";
|
||
break;
|
||
}
|
||
}
|
||
|
||
return TreeName;
|
||
}
|
||
#endregion
|
||
|
||
#region 主页面引用相关代码
|
||
/// <summary>
|
||
/// 主页面引用相关代码
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="webPageCodeModel">前端页面控件相关类</param>
|
||
public static void IndexPageImport(StringBuilder stringBuilder, Model.WebPageCodeModel webPageCodeModel)
|
||
{
|
||
string TreeViewWidth = webPageCodeModel.treeViewModel.TreeViewWidth.Trim();
|
||
string TreeViewType = webPageCodeModel.treeViewModel.TreeViewType;
|
||
string UsedDefinedModeValue = webPageCodeModel.treeViewModel.UsedDefinedModeValue;
|
||
string TableToolBarName = webPageCodeModel.tableLayoutModel.TableToolBar.Trim();
|
||
string ParamsName = webPageCodeModel.interfaceNameSpaceModel == null ? "" :
|
||
webPageCodeModel.interfaceNameSpaceModel.txtParamsName;
|
||
string HostModelName = webPageCodeModel.HostModelName;
|
||
//string RelateClassName = webPageCodeModel.RelateClassName;
|
||
string InterfaceName = webPageCodeModel.interfaceNameSpaceModel.txtInterfaceName;
|
||
bool ShowExportExcel = webPageCodeModel.tableLayoutModel.ShowExportExcel;
|
||
|
||
stringBuilder.AppendLine("import React, { useRef, useState, Suspense } from 'react';");
|
||
stringBuilder.AppendLine("import moment from 'moment'; // 时间相关引用,没有使用可以删除");
|
||
stringBuilder.AppendLine("import numeral from \"numeral\"; // 数字相关引用,没有使用可以删除");
|
||
stringBuilder.AppendLine("import { connect } from 'umi';");
|
||
stringBuilder.AppendLine("");
|
||
stringBuilder.AppendLine("import useRequest from '@ahooksjs/use-request'; // 请求数据的引用");
|
||
stringBuilder.AppendLine("import Draggable from 'react-draggable';");
|
||
stringBuilder.AppendLine("import SubMenu from \"antd/lib/menu/SubMenu\";");
|
||
//页面左侧树相关引用
|
||
if (TreeViewWidth != "")
|
||
{
|
||
stringBuilder.AppendLine("import ProCard from '@ant-design/pro-card'; // 卡片组件");
|
||
}
|
||
stringBuilder.AppendLine("import ProTable from '@ant-design/pro-table';");
|
||
stringBuilder.AppendLine("import ProDescriptions from '@ant-design/pro-descriptions';");
|
||
stringBuilder.AppendLine("import ProForm, { ProFormDatePicker,ProFormDateTimePicker, ProFormMoney, ProFormSelect, " +
|
||
"ProFormText, ProFormTextArea, ProFormUploadButton } from '@ant-design/pro-form';");
|
||
stringBuilder.AppendLine("import { " + (TreeViewWidth != "" && UsedDefinedModeValue != "" ? "DiffTwoTone, " : "") +
|
||
"MenuFoldOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';");
|
||
stringBuilder.AppendLine("import { PageContainer } from '@ant-design/pro-layout';");
|
||
//相关组件引用
|
||
stringBuilder.AppendLine("import { Button, Col, Drawer, message, Row, Popconfirm, Space, Image" +
|
||
(TreeViewWidth != "" ? (TreeViewType == "2" ? ", Menu, Avatar" : ", Tree") +
|
||
(UsedDefinedModeValue != "" ? ", Alert" : "") : "") + (TableToolBarName != "" ? ", Typography" : "") +
|
||
", Modal, Form, Switch, Upload, Tooltip, Descriptions, TreeSelect } from 'antd';");
|
||
stringBuilder.AppendLine("");
|
||
stringBuilder.AppendLine("import type { CurrentUser } from \"umi\";");
|
||
stringBuilder.AppendLine("import type { ConnectState } from '@/models/connect';");
|
||
stringBuilder.AppendLine("import type { ActionType, ProColumns } from '@ant-design/pro-table';");
|
||
stringBuilder.AppendLine("import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';");
|
||
stringBuilder.AppendLine("import type { FormInstance } from 'antd';");
|
||
stringBuilder.AppendLine("import type { " + (!string.IsNullOrWhiteSpace(ParamsName) ? ParamsName + "," : "") +
|
||
HostModelName + (webPageCodeModel.relateInterfaceModel == null ? "" :
|
||
", " + webPageCodeModel.relateInterfaceModel.RelateModelName) + " } from './data';");
|
||
stringBuilder.AppendLine("");
|
||
if (TreeViewWidth != "")
|
||
{
|
||
//获取加载树模型的接口
|
||
string TreeName = GetTreeInterfaceName(webPageCodeModel.treeViewModel);
|
||
if (!string.IsNullOrWhiteSpace(UsedDefinedModeValue))
|
||
{
|
||
stringBuilder.AppendLine("import CategoryTable from '@/pages/merchantManagement/category/Base'; // 用户自定义树相关的页面");
|
||
stringBuilder.AppendLine("import type { ParamsModel } from '@/pages/merchantManagement/category/Base/data'; // 用户自定义树相关的数据对象");
|
||
stringBuilder.AppendLine("import { getFieldEnumTree, getFieldEnumName } from \"@/services/options\"; // 枚举的引用,没有使用可以删除");
|
||
stringBuilder.AppendLine("import { " + TreeName + " } from '@/pages/merchantManagement/category/Base/service'; // 用户自定义树相关的服务");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine("import { getFieldEnumTree, getFieldEnumName, " + TreeName + " } from \"@/services/options\"; // 枚举和树相关的引用,没有使用可以删除");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine("import { getFieldEnumTree, getFieldEnumName } from \"@/services/options\"; // 枚举的引用,没有使用可以删除");
|
||
}
|
||
//添加接口相关对象的引用
|
||
if (webPageCodeModel.InterfaceType == 0)
|
||
{
|
||
//如果是标准接口,则增加更新和删除接口
|
||
InterfaceName += ", del" + webPageCodeModel.HostClassName.ToLower() +
|
||
", update" + webPageCodeModel.HostClassName.ToLower();
|
||
if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
InterfaceName += ", getSubDetail, del" + webPageCodeModel.relateInterfaceModel.RelateClassName.ToLower() +
|
||
", update" + webPageCodeModel.relateInterfaceModel.RelateClassName.ToLower();
|
||
}
|
||
}
|
||
else if (webPageCodeModel.relateInterfaceModel != null)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.relateInterfaceModel.RelateClassName))
|
||
{
|
||
InterfaceName += ", getSubDetail";
|
||
}
|
||
}
|
||
stringBuilder.AppendLine("import { " + InterfaceName + " } from './service'; // 接口相关对象的引用");
|
||
//显示打印按钮时需要定义的引用
|
||
if (webPageCodeModel.tableLayoutModel != null && webPageCodeModel.tableLayoutModel.ShowPrint)
|
||
{
|
||
stringBuilder.AppendLine("import ReactToPrint from 'react-to-print'; // 打印功能的引用");
|
||
stringBuilder.AppendLine("import { printOutInternal } from '@/utils/utils'; // 打印功能的引用");
|
||
}
|
||
//导出excel的引用
|
||
if (ShowExportExcel)
|
||
{
|
||
stringBuilder.AppendLine("import { exportExcel } from '@/utils/utils'; // 导出excel的引用");
|
||
}
|
||
//附件图片相关引用
|
||
if (webPageCodeModel.attachmentLayoutModel != null)
|
||
{
|
||
if (webPageCodeModel.attachmentLayoutModel.UploadAttachment)
|
||
{
|
||
//编辑页面附件相关引用
|
||
if (webPageCodeModel.attachmentLayoutModel.Attachment_Type == "1")
|
||
{
|
||
//上传图片相关引用
|
||
stringBuilder.AppendLine("import { transferImg } from \"@/utils/format\";");
|
||
stringBuilder.AppendLine("import { uploadFile } from \"@/services/picture\";");
|
||
}
|
||
else
|
||
{
|
||
//上传附件相关引用
|
||
stringBuilder.AppendLine("import { getBase64 } from '@/utils/utils';");
|
||
stringBuilder.AppendLine("import { deletePicture, uploadPicture, getPictureList } from '@/services/picture';");
|
||
stringBuilder.AppendLine("import type { UploadFile } from 'antd/es/upload/interface';");
|
||
stringBuilder.AppendLine("import type { PictureModel } from '@/services/options/typings';");
|
||
}
|
||
stringBuilder.AppendLine("");
|
||
stringBuilder.AppendLine("const { confirm } = Modal;");
|
||
}
|
||
else if (webPageCodeModel.attachmentLayoutModel.SearchAttachment ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.attachmentLayoutModel.ShowAttachmentValue))
|
||
{
|
||
if (webPageCodeModel.attachmentLayoutModel.Attachment_Type == "1")
|
||
{
|
||
//查看图片相关引用
|
||
stringBuilder.AppendLine("import { transferImg } from \"@/utils/format\";");
|
||
}
|
||
else
|
||
{
|
||
//查看附件相关引用
|
||
stringBuilder.AppendLine("import { getPictureList } from '@/services/picture';");
|
||
stringBuilder.AppendLine("import type { UploadFile } from 'antd/es/upload/interface';");
|
||
stringBuilder.AppendLine("import type { PictureModel } from '@/services/options/typings';");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 增加校验图片大小方法
|
||
/// <summary>
|
||
/// 增加校验图片大小方法
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
public static void SetUploadCheckFunc(StringBuilder _Index)
|
||
{
|
||
_Index.AppendLine("// 校验图片大小");
|
||
_Index.AppendLine("const beforeUpload = (file: any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (!isJpgOrPng) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error('请上传JPEG、jpg、png格式的图片文件!');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const isLt2M = file.size / 1024 / 1024 < 2;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (!isLt2M) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error('图片大小不超过 2MB!');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return isJpgOrPng && isLt2M;");
|
||
_Index.AppendLine("}");
|
||
|
||
_Index.AppendLine("");
|
||
}
|
||
#endregion
|
||
|
||
#region 增加上传附件的方法
|
||
/// <summary>
|
||
/// 增加上传附件的方法
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
/// <param name="attachmentLayoutModel">附件相关组件</param>
|
||
public static void BuildUploadFunc(StringBuilder _Index, Model.AttachmentLayoutModel attachmentLayoutModel)
|
||
{
|
||
_Index.AppendLine("// 上传附件");
|
||
_Index.AppendLine("const customUploadRequest = async (fileList: UploadFile[], tableId: string) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (!fileList.length) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "message.error(\"您上传的附件不存在.\")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return false");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const formData = new FormData();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "fileList.forEach(file => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "formData.append('files[]', file);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "});");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "formData.append('TableType', '" +
|
||
attachmentLayoutModel.ShowAttachmentValue + "');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "formData.append('TableId', tableId);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const success = await uploadPicture(formData)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "if (success) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return true");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "return false");
|
||
_Index.AppendLine("}");
|
||
|
||
_Index.AppendLine("");
|
||
}
|
||
#endregion
|
||
|
||
#region 有附件组件时,定义预览图片的方法
|
||
/// <summary>
|
||
/// 有附件组件时,定义预览图片的方法
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
/// <param name="attachmentLayoutModel">附件相关组件</param>
|
||
/// <param name="ModelName">数据表对象名称</param>
|
||
/// <param name="UniqueId">数据表内码</param>
|
||
public static void SetPreviewFunc(StringBuilder _Index,
|
||
Model.AttachmentLayoutModel attachmentLayoutModel, string ModelName, string UniqueId)
|
||
{
|
||
//类型是图片是需要增加的预览图片的代码
|
||
if (attachmentLayoutModel.Attachment_Type == "1")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [fileList, setFileList] = useState<any[]>([]) // 需要上传的附件图片列表");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [imagePreviewVisible, setImagePreviewVisible] = useState<boolean>(false) // 预览图片");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 预览上传后的图片");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const handlePreview = async () => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "setFileList(fileList)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "setImagePreviewVisible(true)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "};");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [fileList, setFileList] = useState<UploadFile[]>([]) // 需要上传的附件图片列表");
|
||
//上传文件需要增加的定义
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [priviewImage, setPriviewImage] = useState<string>(); // 预览的文件地址");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 获取附件图片信息");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const getFileDetail = async (record: " + ModelName + ") => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const data = await getPictureList(record?." +
|
||
UniqueId + ", '" + attachmentLayoutModel.ShowAttachmentValue + "')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const files = data && data?.total > 0 ? data?.data.map((n: PictureModel) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "return {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "uid: n.ImageId,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "name: n.ImageName,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "status: 'done',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "url: n.ImageUrl,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "deletepath: n.ImagePath");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}) : []");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "setFileList(files)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return data");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
}
|
||
_Index.AppendLine("");
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定枚举加载事件
|
||
/// <summary>
|
||
/// 绑定枚举加载事件
|
||
/// </summary>
|
||
/// <param name="_Index">生成前端列表页面代码的字符串</param>
|
||
/// <param name="FieldExplainField">枚举字段</param>
|
||
/// <param name="ShowWholePower">是否根据省份编码查询枚举</param>
|
||
/// <param name="ProvinceCode">枚举省份编码</param>
|
||
public static void BuildEnumLoading(StringBuilder _Index, string FieldExplainField, bool ShowWholePower, string ProvinceCode)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const { data: " +
|
||
FieldExplainField.ToLower() + "Tree = [] } = useRequest(async () => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return await getFieldEnumTree({ FieldExplainField: '" +
|
||
FieldExplainField + "', sessionName: '" + FieldExplainField + "'" +
|
||
(ShowWholePower ? ", ShowWholePower: true, ProvinceCode:" + ProvinceCode : "") + " })");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "})");
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定树加载事件
|
||
/// <summary>
|
||
/// 绑定树加载事件
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
/// <param name="treeViewModel">前端页面左侧树的布局设置内容</param>
|
||
public static void BuildTreeLoading(StringBuilder _Index, Model.TreeViewModel treeViewModel)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 树相关的属性和方法");
|
||
//菜单树模式下,需要申明下方定义
|
||
if (treeViewModel.TreeViewType == "2")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [currenMenu, setCurrenMenu] = useState<any>(); // 当前选中的左侧菜单");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [selectedId, setSelectedId] = useState<" +
|
||
(!string.IsNullOrWhiteSpace(treeViewModel.UsedDefinedModeValue) ||
|
||
treeViewModel.TreeViewType == "2" ? "any" : "string") + ">()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [collapsible, setCollapsible] = useState<boolean>(false)");
|
||
//如果选择了用户自定义类的树,则加载自定义类的树
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.UsedDefinedModeValue))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const [categoryVisible, handleCategoryVisible] = " +
|
||
"useState<boolean>(false); // 定义用户自定义类别显示隐藏属性");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 加载用户自定义类别");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const { run: loadType, loading: treeLoading, data: treeView = [] } = useRequest(() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return getCustomTypeTree({ CustomType: " +
|
||
treeViewModel.UsedDefinedModeValue + ", BusinessManId: currentUser?.BusinessManID } as ParamsModel)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "})");
|
||
}
|
||
else
|
||
{
|
||
string TreeName = GetTreeInterfaceName(treeViewModel);
|
||
//设置全局权限情况下,树的接口入参
|
||
string Params = "";
|
||
if (treeViewModel.DataAuthority == "2")
|
||
{
|
||
switch (treeViewModel.DataMode)
|
||
{
|
||
case "1000"://区域服务区树
|
||
Params = treeViewModel.Province_Code + ", null, true";
|
||
break;
|
||
case "1100"://服务区树
|
||
Params = treeViewModel.Province_Code + ", null, true, false";
|
||
break;
|
||
case "1200"://服务区门店树
|
||
Params = treeViewModel.Province_Code + ", '', '', '', '', true";
|
||
break;
|
||
case "1300"://业主单位树
|
||
Params = "1";
|
||
break;
|
||
case "1400"://商家门店树
|
||
Params = treeViewModel.Province_Code + ", null, true, false";
|
||
break;
|
||
case "2000"://经营业态树
|
||
Params = treeViewModel.Province_Code + ", null, true";
|
||
break;
|
||
case "3000"://商品类别树
|
||
Params = treeViewModel.Province_Code + ", null, true";
|
||
break;
|
||
case "3100"://自定义商品类别树
|
||
Params = treeViewModel.Province_Code + ", null, true, false";
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch (treeViewModel.DataMode)
|
||
{
|
||
case "1300"://业主单位树
|
||
Params = "1";
|
||
break;
|
||
default:
|
||
Params = "currentUser?.ProvinceCode";
|
||
break;
|
||
}
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 加载服务区树");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const { loading: treeLoading, data: treeView = [] } = " +
|
||
"useRequest(() => { return " + TreeName + "(" + Params + ") })");
|
||
}
|
||
_Index.AppendLine("");
|
||
//菜单树模式的相关方法
|
||
if (treeViewModel.TreeViewType == "2")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 根据左侧选中的菜单加载右侧数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const loadSelectedId = (item?: any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "// 选中的子菜单key");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "const [type, value] = item.key.split('-')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "if (type === '1') {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setCurrenMenu(value)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setSelectedId('')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "else if (type === '2') {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setSelectedId(value)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setCurrenMenu('')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setSelectedId('0')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "setCurrenMenu('0')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "actionRef?.current?.reload()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
|
||
#region 生成左侧菜单
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "// 生成左侧菜单");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "const getMenuDom = (data: any[], callback: (item: any) => void) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "return (data.map((element: any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "if (element.node) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "// 绑定当前节点的子集");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "if (element.node.children && element.node.children.length > 0) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "return (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "<SubMenu title={element.node.label}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "icon={element.node.ico ? <Avatar src={element.node.ico} size={16} style={{ marginRight: 4 }} shape=\"square\" /> : null}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "key={`${element.node.key || element.node.value}`}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "onTitleClick={(item) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "// 选中一级菜单");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "if (!currenMenu || item.key !== `${currenMenu?.key}`) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "callback.call(callback, item)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "item.domEvent.stopPropagation();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "{element.node.children && element.node.children.length > 0 && getMenuDom(element.node.children, callback)}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "</SubMenu>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + ")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "// 绑定嵌套树的子节点");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "if (element.children && element.children.length > 0) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "return (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "<SubMenu title={element.node.label}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "icon={element.node.ico ? <Avatar src={element.node.ico} size={16} style={{ marginRight: 4 }} shape=\"square\" /> : null}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "key={`${element.node.key || element.node.value}`}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "onTitleClick={(item) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "// 选中一级菜单");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "if (!currenMenu || item.key !== `${currenMenu?.key}`) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9) + "callback.call(callback, item)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "item.domEvent.stopPropagation();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "{element.children && element.children.length > 0 && getMenuDom(element.children, callback)}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "</SubMenu>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + ")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "return (<Menu.Item icon={element.node.ico ? <Avatar src={element.node.ico} size={16} shape=\"square\" /> : null}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "key={`${element.node.key || element.node.value}`}>{element.node.label}</Menu.Item>)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "// 绑定嵌套树的子节点");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "if (element.children && element.children.length > 0) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "return (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "<SubMenu title={element.label}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "icon={element.ico ? <Avatar src={element.ico} size={16} style={{ marginRight: 4 }} shape=\"square\" /> : null}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "key={`${element.key || element.value}`}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "onTitleClick={(item) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "// 选中一级菜单");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "if (!currenMenu || item.key !== `${currenMenu?.key}`) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8) + "callback.call(callback, item)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7) + "item.domEvent.stopPropagation();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6) + "{element.children && element.children.length > 0 && getMenuDom(element.children, callback)}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5) + "</SubMenu>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + ")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3) + "return (<Menu.Item icon={element.ico ? <Avatar src={element.ico} size={16} shape=\"square\" /> : null}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4) + "key={`${element.key || element.value}`}>{element.label}</Menu.Item>)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(2) + "}))");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(1) + "}");
|
||
#endregion
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定树和ProTable列表代码
|
||
/// <summary>
|
||
/// 绑定树和ProTable列表代码
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="webPageCodeModel">前端页面控件相关类</param>
|
||
/// <param name="ProTableCode">ProTable列表代码</param>
|
||
/// <param name="StartIndex">代码内容缩进格数</param>
|
||
public static void BuildTreeAndProTable(StringBuilder stringBuilder,
|
||
Model.WebPageCodeModel webPageCodeModel, string ProTableCode, int StartIndex = 0)
|
||
{
|
||
string TreeViewTypeValue = webPageCodeModel.treeViewModel.TreeViewType;
|
||
string UsedDefinedModeValue = webPageCodeModel.treeViewModel.UsedDefinedModeValue;
|
||
string TreeViewFixedValue = webPageCodeModel.treeViewModel.DataMode;
|
||
string TreeViewWidth = webPageCodeModel.treeViewModel.TreeViewWidth.Trim();
|
||
bool IsSelectFresh = webPageCodeModel.treeViewModel.SelectFresh == "1";
|
||
|
||
//如果左侧设置了树,则加载绑定树的代码
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "<ProCard split=\"vertical\" style={{ height: 'calc(100vh - 127px)', overflowY:'scroll', backgroundColor: '#fff' }}>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "<ProCard");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "className=\"pageTable-leftnav\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "bodyStyle={{ padding: 0, paddingTop: 20, paddingLeft: 20 }}");
|
||
//如果是自定义类别的树,要增加“更新类别”的按钮
|
||
if (!string.IsNullOrWhiteSpace(UsedDefinedModeValue))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "headStyle={{ paddingRight: 10, paddingLeft: 20 }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "extra={<>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "{!collapsible && <Tooltip title=\"更新类别\">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Button type=\"text\" size='small'>" +
|
||
"<DiffTwoTone style={{fontSize:16}} onClick={() => { handleCategoryVisible(true) }} /></Button>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Tooltip>}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Button type=\"text\" size='small'><MenuFoldOutlined" +
|
||
" onClick={() => { setCollapsible(!collapsible) }} /></Button>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "</>}");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"extra={<MenuFoldOutlined onClick={() => { setCollapsible(!collapsible) }} />}");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "colSpan={!collapsible ? \"" + TreeViewWidth + "\" : \"60px\"}");
|
||
if (!string.IsNullOrWhiteSpace(UsedDefinedModeValue))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "title={!collapsible ? \"可筛选类别\" : \"\"}");
|
||
}
|
||
else
|
||
{
|
||
switch (TreeViewFixedValue)
|
||
{
|
||
case "1000"://区域服务区树
|
||
case "1100"://服务区树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择服务区\" : \"\"}");
|
||
break;
|
||
case "1200"://服务区门店树
|
||
case "1400"://商家门店树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择门店\" : \"\"}");
|
||
break;
|
||
case "2000"://经营业态树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择经营业态\" : \"\"}");
|
||
break;
|
||
case "1300"://业主单位树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择业主单位\" : \"\"}");
|
||
break;
|
||
case "3000"://商品类别树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择商品类别\" : \"\"}");
|
||
break;
|
||
case "3100"://商品自定义树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) +
|
||
"title={!collapsible ? \"请选择商品自定义类别\" : \"\"}");
|
||
break;
|
||
}
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "headerBordered");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "collapsed={collapsible}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + ">");
|
||
|
||
if (TreeViewTypeValue == "2")
|
||
{
|
||
//菜单形式呈现的树结构
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "{!treeLoading && <Menu");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "mode=\"inline\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "style={{ height:'calc(100vh - 230px)', overflowY: 'auto', overflowX: 'hidden' }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "selectedKeys={`2-${selectedId}` || `1-${currenMenu}`}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "onSelect={(item) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "loadSelectedId(item)");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "{getMenuDom(treeView, loadSelectedId)}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "</Menu>}");
|
||
}
|
||
else
|
||
{
|
||
//其他模式的树,以勾选树形结构展示
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "{treeView && treeView.length > 0 ? <Tree");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "checkable");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "treeData={!treeLoading ? [{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "label: '全部',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "value: 0,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "key: '0-0',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "children: treeView");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}] : []}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "fieldNames={{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "title: \"label\",");
|
||
if (!string.IsNullOrWhiteSpace(UsedDefinedModeValue))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "key: \"value\"");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "key: \"key\"");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "blockNode");
|
||
|
||
if (!string.IsNullOrWhiteSpace(UsedDefinedModeValue))
|
||
{
|
||
//自定义类别设置
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "defaultExpandedKeys={[0]}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "onCheck={(checkedKeys: React.Key[] | any) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "setSelectedId(checkedKeys)");
|
||
//勾选树节点后,自动刷新数据
|
||
if (IsSelectFresh)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "actionRef?.current?.reload()");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "return checkedKeys");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "/> :");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "(!treeLoading && <Alert message={<>没有类别,马上去<a onClick={() =>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "handleCategoryVisible(true)");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}>设置</a></>} banner />)}");
|
||
}
|
||
else
|
||
{
|
||
//常用目录树设置
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "defaultExpandedKeys={['0-0']}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "onCheck={(checkedKeys: React.Key[] | any, info) => {");
|
||
if (TreeViewFixedValue == "1200")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "const selectedIds = info.checkedNodes.filter(n => n?.type === 2)");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "const selectedIds = info.checkedNodes.filter(n => n?.type === 1)");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "setSelectedId(selectedIds.map(n => n?.value)?.toString() || '')");
|
||
//勾选树节点后,自动刷新数据
|
||
if (IsSelectFresh)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "actionRef?.current?.reload()");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// switcherIcon={<PlusOutlined />}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "/> : ''}");
|
||
}
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "</ProCard>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "<ProCard bodyStyle={{ paddingTop: 0, paddingBottom: 0, paddingRight: 0 }}>");
|
||
|
||
//有打印功能的时候要增加一层dome
|
||
if (webPageCodeModel.tableLayoutModel != null && webPageCodeModel.tableLayoutModel.ShowPrint)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "<div");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "ref={(el) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "// 打印报表");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "setPrintOut(el);");
|
||
stringBuilder.AppendLine("");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + ">");
|
||
stringBuilder.AppendLine(ProTableCode);
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "</div>");
|
||
}
|
||
else
|
||
{
|
||
//加载ProTable列表代码
|
||
stringBuilder.AppendLine(ProTableCode);
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "</ProCard>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "</ProCard>");
|
||
}
|
||
#endregion
|
||
|
||
#region 生成单个时间查询条件控件
|
||
/// <summary>
|
||
/// 生成单个时间查询条件控件
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="DateFormat">日期格式</param>
|
||
/// <param name="DefaultDateValue">时间默认值</param>
|
||
/// <param name="StartIndex">代码内容缩进格数</param>
|
||
public static void BuildDateSearchControl(StringBuilder stringBuilder,
|
||
string DateFormat, string DefaultDateValue = "", int StartIndex = 3)
|
||
{
|
||
switch (DateFormat)
|
||
{
|
||
case "0":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(StartIndex) + "valueType: 'dateTime',");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY-MM-DD", false);
|
||
break;
|
||
case "1":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(StartIndex) + "valueType: 'date',");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY-MM-DD", false);
|
||
break;
|
||
case "2":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(StartIndex) + "valueType: 'dateMonth',");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY-MM", false);
|
||
break;
|
||
case "3":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(StartIndex) + "valueType: 'dateYear',");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY", false);
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 生成时间段查询条件控件
|
||
/// <summary>
|
||
/// 生成时间段查询条件控件
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="DateFormat">日期格式</param>
|
||
/// <param name="StartDateValue">开始时间字段</param>
|
||
/// <param name="EndDateValue">结束时间字段</param>
|
||
/// <param name="DefaultDateValue">时间默认值</param>
|
||
/// <param name="StartIndex">代码内容缩进格数</param>
|
||
public static void BuildDateSearchControl(StringBuilder stringBuilder, string DateFormat,
|
||
string StartDateValue, string EndDateValue, string DefaultDateValue, int StartIndex = 0)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2 + StartIndex) + "{");
|
||
switch (DateFormat)
|
||
{
|
||
case "0": //按日期显示
|
||
case "1": //按时间显示
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "title: '查询时间',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "dataIndex: 'search_date',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "valueType: '" +
|
||
(DateFormat == "3" ? "dateTimeRange" : "dateRange") + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInTable: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInDescriptions: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "search: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "transform: (value) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + StartDateValue + ": value[0],");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + EndDateValue + ": value[1],");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "};");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "},");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY-MM-DD", true);
|
||
break;
|
||
case "2": //按月份显示
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "title: '查询月份',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "dataIndex: 'search_months',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "valueType: 'dateRange',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInTable: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInDescriptions: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "search: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "transform: (value) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// format中的格式决定入参内容");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + StartDateValue +
|
||
": moment(value[0]).startOf(\"month\").format('YYYY-MM-DD'),");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + EndDateValue +
|
||
": moment(value[1]).endOf(\"month\").format('YYYY-MM-DD'),");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "};");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "fieldProps: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "picker: \"month\",");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "format: 'YYYY-MM',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(StartIndex) + "},");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY-MM", true);
|
||
break;
|
||
case "3": //按年份显示
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "title: '查询年份',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "dataIndex: 'search_years',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "valueType: 'dateRange',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInTable: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "hideInDescriptions: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "search: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "transform: (value) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// format中的格式决定入参内容");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + StartDateValue +
|
||
": moment(value[0]).startOf(\"year\").format('YYYY-MM-DD'),");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + EndDateValue +
|
||
": moment(value[1]).endOf(\"year\").format('YYYY-MM-DD'),");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "};");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "fieldProps: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "picker: \"year\",");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "format: 'YYYY',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "},");
|
||
//添加时间默认值设置
|
||
CommonHelper.SetDateInitialValue(stringBuilder, DefaultDateValue, "YYYY", true);
|
||
break;
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2 + StartIndex) + "},");
|
||
}
|
||
#endregion
|
||
|
||
#region 生成列表字段【ProColumns】数据
|
||
/// <summary>
|
||
/// 生成列表字段【ProColumns】数据
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="webPageCodeModel">前端页面组件</param>
|
||
/// <param name="dtInterfaceParams">接口入参数据源</param>
|
||
/// <param name="dtGVEModel">接口反参数据源</param>
|
||
/// <param name="ShowEdit">是否显示编辑功能</param>
|
||
public static void BuildListModel(StringBuilder stringBuilder, Model.WebPageCodeModel webPageCodeModel,
|
||
DataTable dtInterfaceParams, DataTable dtGVEModel, bool ShowEdit)
|
||
{
|
||
Model.TableLayoutModel tableLayoutModel = webPageCodeModel.tableLayoutModel;
|
||
Model.AttachmentLayoutModel attachmentLayoutModel = webPageCodeModel.attachmentLayoutModel;
|
||
|
||
if (dtInterfaceParams != null && dtInterfaceParams.Rows.Count > 0)
|
||
{
|
||
//遍历数据对象的字段,添加到代码中,根据顺序和字段内码正序加入
|
||
foreach (DataRow _DataRow in dtInterfaceParams.Rows)
|
||
{
|
||
#region 添加入参字段的代码
|
||
//定义字段释义,不包含括号中的枚举解析
|
||
string _INTERFACEMODEL_COMMENT = _DataRow["INTERFACEPARAMS_COMMENT"].ToString().Split('(')[0].Split('(')[0];
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: '" + _DataRow["INTERFACEPARAMS_NAME"] + "', ");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '" + _INTERFACEMODEL_COMMENT + "',");
|
||
|
||
//如果时间筛选框只选择了一个参数,则在参数列表中显示查询框
|
||
if (webPageCodeModel.searchControlModel.DDLStartDate == _DataRow["INTERFACEPARAMS_NAME"].ToString() &&
|
||
string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLEndDate))
|
||
{
|
||
BuildDateSearchControl(stringBuilder, webPageCodeModel.searchControlModel.DateFormat,
|
||
webPageCodeModel.searchControlModel.DefaultDateValue);
|
||
}
|
||
else
|
||
{
|
||
//根据数据格式,判断显示形式
|
||
switch (_DataRow["INTERFACEPARAMS_FORMAT"].ToString())
|
||
{
|
||
case "1": //枚举或者下拉筛选框的字段,数据类型是treeSelect兼容树型选择
|
||
if (("," + webPageCodeModel.searchControlModel.DDLselect +
|
||
",").Contains("," + _DataRow["INTERFACEPARAMS_NAME"] + ","))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'treeSelect',");
|
||
}
|
||
break;
|
||
case "2":
|
||
if (_DataRow["INTERFACEPARAMS_NAME"].ToString().ToUpper() == "OPERATE_DATE")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'fromNow',");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'date',");
|
||
}
|
||
break;
|
||
}
|
||
//是否显示在筛选栏中
|
||
if ((string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLsearchKeyValue) || !("," +
|
||
webPageCodeModel.searchControlModel.DDLsearchKeyValue + ",").Contains("," + _DataRow["INTERFACEPARAMS_NAME"] + ",")) &&
|
||
(string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLselect) ||
|
||
!("," + webPageCodeModel.searchControlModel.DDLselect + ",").Contains("," + _DataRow["INTERFACEPARAMS_NAME"] + ",")))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInSearch: true,");
|
||
}
|
||
}
|
||
//不显示在列表上
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInTable: true,");
|
||
//不显示在抽屉中
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInDescriptions: true,");
|
||
//枚举解析
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ENUM_FIELD"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "request: async () => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) +
|
||
"return await getFieldEnumTree({ FieldExplainField: '" + _DataRow["ENUM_FIELD"] +
|
||
"', sessionName: '" + _DataRow["ENUM_FIELD"] + "' });");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
//chengtl 2023-10-27 兼容下拉多级树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "render: (_, record) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return <a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "{getFieldEnumName('" + _DataRow["ENUM_FIELD"] +
|
||
"',record?." + _DataRow["INTERFACEPARAMS_NAME"] + ")}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "</a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
#endregion
|
||
}
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLsearchKeyValue))
|
||
{
|
||
//添加查询条件框
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '查询条件',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: 'searchKey',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInTable: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInDescriptions: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "fieldProps: {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "placeholder: \"请输入" +
|
||
webPageCodeModel.searchControlModel.DDLsearchKeyText.Replace(",", "/") + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
}
|
||
if (webPageCodeModel.dtGVEModel != null)
|
||
{
|
||
//遍历数据对象的字段,添加到代码中,根据顺序和字段内码正序加入
|
||
foreach (DataRow _DataRow in dtGVEModel.Select("", "ColumnIndex,INTERFACEMODEL_ID"))
|
||
{
|
||
//获取字段名称
|
||
string _INTERFACEMODEL_NAME = _DataRow["INTERFACEMODEL_NAME"].ToString();
|
||
//如果字段既不显示在列表,也不显示在抽屉和筛选栏,则不添加代码
|
||
if (_DataRow["ShowList"].ToString() != "1" && _DataRow["ShowDrawer"].ToString() != "1" &&
|
||
!("," + webPageCodeModel.searchControlModel.DDLselect + ",").Contains("," + _INTERFACEMODEL_NAME + ","))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (_INTERFACEMODEL_NAME == "index")
|
||
{
|
||
#region 序号字段
|
||
//显示就添加到代码里面
|
||
if (_DataRow["ShowList"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: '" + _DataRow["INTERFACEMODEL_NAME"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "key: '" + _DataRow["INTERFACEMODEL_NAME"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'index',");
|
||
//设置列表宽度
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ColumnWidth"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "width: " + _DataRow["ColumnWidth"] + ",");
|
||
}
|
||
//设置单元格显示位置
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ContentAlign"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "align: '" + _DataRow["ContentAlign"] + "',");
|
||
}
|
||
|
||
string uniqueKey = webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName.Replace(",", " + record?.");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "if (record?." +
|
||
uniqueKey + " || record?." + uniqueKey + " === 0) {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "const page = actionRef.current?.pageInfo;");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "return index + (page.current - 1) * page.pageSize + 1;");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return ''");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 添加数据对象中字段的代码
|
||
//默认显示在查询栏,如果是非标准接口有对应的入参字段,则当前字段默认不显示在查询栏
|
||
bool hideInSearch = dtInterfaceParams != null && dtInterfaceParams.Rows.Count > 0;
|
||
//定义字段释义,不包含括号中的枚举解析
|
||
string _INTERFACEMODEL_COMMENT = _DataRow["INTERFACEMODEL_COMMENT"].ToString().Split('(')[0].Split('(')[0];
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: '" + _INTERFACEMODEL_NAME + "', ");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '" + _INTERFACEMODEL_COMMENT + "',");
|
||
|
||
if (_DataRow["DateFormat"].TryParseToInt() > 0)
|
||
{
|
||
BuildDateSearchControl(stringBuilder, _DataRow["DateFormat"].ToString());
|
||
}
|
||
else
|
||
{
|
||
if (("," + webPageCodeModel.searchControlModel.DDLselect + ",").Contains(
|
||
"," + _INTERFACEMODEL_NAME + ","))
|
||
{
|
||
//枚举或者下拉筛选框的字段,数据类型是treeSelect兼容树型选择
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'treeSelect',");
|
||
}
|
||
else if (_DataRow["FieldExplainField"].ToString() != "")
|
||
{
|
||
//枚举或者下拉筛选框的字段,数据类型是treeSelect兼容树型选择
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'treeSelect',");
|
||
hideInSearch = true;
|
||
}
|
||
else
|
||
{
|
||
//根据数据格式,判断显示形式
|
||
switch (_DataRow["INTERFACEMODEL_FORMAT"].ToString())
|
||
{
|
||
case "2": //字段的数据格式是时间
|
||
if (_INTERFACEMODEL_NAME.ToUpper() == "OPERATE_DATE" ||
|
||
_INTERFACEMODEL_NAME.ToUpper().EndsWith("_OPERATEDATE"))
|
||
{
|
||
//操作时间显示格式
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'fromNow',");
|
||
}
|
||
else
|
||
{
|
||
//其他时间显示格式
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'date',");
|
||
}
|
||
break;
|
||
case "7":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'dateMonth',");
|
||
break;
|
||
case "8":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'dateYear',");
|
||
break;
|
||
case "9":
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'dateTime',");
|
||
break;
|
||
default:
|
||
//标识为时间的字段,但字段格式不是时间
|
||
if (_DataRow["DATE_FIELD"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'date',");
|
||
}
|
||
else if (_DataRow["INTERFACEMODEL_COMMENT"].ToString().Contains("金额"))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'money',");
|
||
}
|
||
break;
|
||
}
|
||
hideInSearch = true;
|
||
}
|
||
}
|
||
//设置列表宽度
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ColumnWidth"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "width: " + _DataRow["ColumnWidth"] + ",");
|
||
}
|
||
//设置单元格显示位置
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ContentAlign"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "align: '" + _DataRow["ContentAlign"] + "',");
|
||
}
|
||
else if (_DataRow["INTERFACEMODEL_COMMENT"].ToString().Contains("金额") ||
|
||
_DataRow["INTERFACEMODEL_COMMENT"].ToString().Contains("数量"))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "align: 'right',");
|
||
}
|
||
//设置默认排序
|
||
if (webPageCodeModel.tableLayoutModel.ShowPagination)
|
||
{
|
||
CommonHelper.SetFieldSort(stringBuilder, _DataRow["OrderByType"].ToString());
|
||
}
|
||
else
|
||
{
|
||
CommonHelper.SetFieldSort(stringBuilder, _DataRow);
|
||
}
|
||
//是否显示在筛选栏中
|
||
if (hideInSearch)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInSearch: true,");
|
||
}
|
||
//是否显示在列表上
|
||
if (_DataRow["ShowList"].ToString() != "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInTable: true,");
|
||
}
|
||
//是否显示在抽屉中
|
||
if (_DataRow["ShowDrawer"].ToString() != "1" || _DataRow["INTERFACEMODEL_NAME"].ToString() ==
|
||
webPageCodeModel.tableLayoutModel.DrawerTitle)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInDescriptions: true,");
|
||
}
|
||
//是否有点击查看抽屉的效果
|
||
if (("," + webPageCodeModel.tableLayoutModel.DetailField + ",").Contains(
|
||
"," + _DataRow["INTERFACEMODEL_NAME"].ToString() + ","))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "render: (_, record) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return <a onClick={() => { // 点击" +
|
||
_INTERFACEMODEL_COMMENT + "时 打开抽屉 展示详情");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "setCurrentRow(record);");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "setShowDetail(true);");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "}}>{record." + _DataRow["INTERFACEMODEL_NAME"] + "}</a> ");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(_DataRow["FieldExplainField"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "request: async () => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return await getFieldEnumTree({ FieldExplainField: '" +
|
||
_DataRow["FieldExplainField"] + "', sessionName: '" + _DataRow["FieldExplainField"] + "' });");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
//chengtl 2023-10-27 兼容下拉多级树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "render: (_, record) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return <a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "{getFieldEnumName('" + _DataRow["ENUM_FIELD"] +
|
||
"',record?." + _INTERFACEMODEL_NAME + ")}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "</a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
#endregion
|
||
}
|
||
}
|
||
}
|
||
|
||
//设置了查询时间的字段,才加载时间筛选框
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLStartDate))
|
||
{
|
||
//添加时间段筛选框
|
||
BuildDateSearchControl(stringBuilder, webPageCodeModel.searchControlModel.DateFormat,
|
||
webPageCodeModel.searchControlModel.DDLStartDate,
|
||
webPageCodeModel.searchControlModel.DDLEndDate,
|
||
webPageCodeModel.searchControlModel.DefaultDateValue);
|
||
}
|
||
|
||
//列表要显示“操作”列:如果没有设置过抽屉字段或者有编辑功能才显示
|
||
if (tableLayoutModel != null && tableLayoutModel.ShowOption &&
|
||
((string.IsNullOrWhiteSpace(tableLayoutModel.DetailField) &&
|
||
!string.IsNullOrWhiteSpace(tableLayoutModel.DrawerWidth)) || ShowEdit))
|
||
{
|
||
#region 添加操作列
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: 'option', ");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '操作',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'option',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "hideInSearch: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "render: (_, record) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return (");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "<Space>");
|
||
|
||
#region 如果没有设置字段点击效果,则在操作栏中增加“查看”功能
|
||
if (string.IsNullOrWhiteSpace(tableLayoutModel.DetailField) &&
|
||
!string.IsNullOrWhiteSpace(tableLayoutModel.DrawerWidth))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "<a");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "onClick={() => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "setCurrentRow(record);");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "setShowDetail(true);");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "查看");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "</a>");
|
||
}
|
||
#endregion
|
||
|
||
//如果页面上有编辑的功能,需要增加编辑和删除效果
|
||
if (ShowEdit)
|
||
{
|
||
#region 编辑
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "<a");
|
||
//如果有附件上传功能,则存储当前行附件字段的值
|
||
if (attachmentLayoutModel != null &&
|
||
(attachmentLayoutModel.UploadAttachment || attachmentLayoutModel.SearchAttachment ||
|
||
!string.IsNullOrWhiteSpace(attachmentLayoutModel.ShowAttachmentValue)))
|
||
{
|
||
if (attachmentLayoutModel.Attachment_Type == "2")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "onClick={async () => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "// 获取附件字段的值");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "await getFileDetail(record);");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "onClick={() => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "// 获取附件字段的值");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "const imagesPath = record." + attachmentLayoutModel.Attachment_Field);
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "const images = transferImg(imagesPath ? imagesPath.split(',') : [])");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "setFileList(images)");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "onClick={() => {");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "setCurrentRow({ ...record });");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "handleModalVisible(true);");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "编辑");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "</a>");
|
||
#endregion
|
||
|
||
#region 删除
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "<Popconfirm");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "title=\"确认删除该" + tableLayoutModel.TableTitle + "信息吗?\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "onConfirm={async () => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "const sucesse = " +
|
||
"await handelDelete(record." + webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName + ");");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "if (sucesse && actionRef.current) {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9) + "actionRef.current.reload();");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7) + "<a>删除</a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6) + "</Popconfirm>");
|
||
#endregion
|
||
}
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "</Space>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + ");");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
#endregion
|
||
}
|
||
}
|
||
|
||
#region 添加附表数据对象
|
||
/// <summary>
|
||
/// 添加附表数据对象
|
||
/// </summary>
|
||
/// <param name="stringBuilder">生成列表页面代码字符串</param>
|
||
/// <param name="_DataTable">附表字段数据源</param>
|
||
/// <param name="ShowPagination">是否显示翻页组件</param>
|
||
public static void BuildDrawerSubModel(StringBuilder stringBuilder, DataTable _DataTable, bool ShowPagination)
|
||
{
|
||
//遍历附表数据对象的字段,添加到代码中,根据顺序和字段内码正序加入
|
||
foreach (DataRow _DataRow in _DataTable.Select("", "ColumnIndex,INTERFACEMODEL_ID"))
|
||
{
|
||
//如果字段不显示在抽屉,则不添加代码
|
||
if (_DataRow["ShowDrawer"].ToString() != "1")
|
||
{
|
||
continue;
|
||
}
|
||
//定义字段释义,不包含括号中的枚举解析
|
||
string _INTERFACEMODEL_COMMENT = _DataRow["INTERFACEMODEL_COMMENT"].ToString().Split('(')[0].Split('(')[0];
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "dataIndex: '" + _DataRow["INTERFACEMODEL_NAME"] + "', ");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "title: '" + _INTERFACEMODEL_COMMENT + "',");
|
||
//根据数据格式,判断显示形式
|
||
switch (_DataRow["INTERFACEMODEL_FORMAT"].ToString())
|
||
{
|
||
case "1": //枚举字段,数据类型是treeSelect兼容树型选择
|
||
if (_DataRow["FieldExplainField"].ToString() != "")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'treeSelect',");
|
||
}
|
||
break;
|
||
case "2":
|
||
if (_DataRow["INTERFACEMODEL_NAME"].ToString().ToUpper() == "OPERATE_DATE")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'fromNow',");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "valueType: 'date',");
|
||
}
|
||
break;
|
||
}
|
||
//设置列表宽度
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ColumnWidth"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "width: " + _DataRow["ColumnWidth"] + ",");
|
||
}
|
||
//设置单元格显示位置
|
||
if (!string.IsNullOrWhiteSpace(_DataRow["ContentAlign"].ToString()))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "align: '" + _DataRow["ContentAlign"] + "',");
|
||
}
|
||
//设置默认排序
|
||
if (ShowPagination)
|
||
{
|
||
CommonHelper.SetFieldSort(stringBuilder, _DataRow["OrderByType"].ToString());
|
||
}
|
||
else
|
||
{
|
||
CommonHelper.SetFieldSort(stringBuilder, _DataRow);
|
||
}
|
||
//解析枚举字段
|
||
if (_DataRow["FieldExplainField"].ToString() != "")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "request: async () => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return await getFieldEnumTree({ FieldExplainField: '" +
|
||
_DataRow["FieldExplainField"] + "', sessionName: '" + _DataRow["FieldExplainField"] + "' });");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return options");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
//chengtl 2023-10-27 兼容下拉多级树
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "render: (_, record) => {");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "return <a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(5) + "{getFieldEnumName('" + _DataRow["ENUM_FIELD"] +
|
||
"',record?." + _DataRow["INTERFACEMODEL_NAME"] + ")}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(4) + "</a>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(3) + "},");
|
||
}
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(2) + "},");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 生成ProTable【列表代码】
|
||
/// <summary>
|
||
/// 生成ProTable【列表代码】
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
/// <param name="webPageCodeModel">前端页面组件</param>
|
||
/// <param name="dtGVEModel">主接口返参字段列表数据源</param>
|
||
/// <param name="dtGVEOtherModel">主接口其他返参字段列表数据源</param>
|
||
/// <param name="dtGridViewExRelate">关联接口返参字段列表数据源</param>
|
||
/// <param name="StartIndex">额外缩进格数</param>
|
||
public static void BuildProTable(StringBuilder _Index, Model.WebPageCodeModel webPageCodeModel,
|
||
DataTable dtGVEModel, DataTable dtGVEOtherModel, DataTable dtGridViewExRelate, DataTable dtEditor, int StartIndex = 0)
|
||
{
|
||
Model.TreeViewModel treeViewModel = webPageCodeModel.treeViewModel;
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "<ProTable<" + webPageCodeModel.HostModelName + ">");
|
||
|
||
//如果列表左侧没有树,则要增加列表的高度样式
|
||
if (string.IsNullOrWhiteSpace(treeViewModel.TreeViewWidth))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "style={{height:'calc(100vh - 135px)',background:'#fff'}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "scroll={{y:'calc(100vh - 410px)'}}");
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "rowKey={(record) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return `${record?." +
|
||
webPageCodeModel.interfaceNameSpaceModel.DDLUniqueName.Replace(",", "}-${record?.") + "}`");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "formRef={formRef}");
|
||
if (string.IsNullOrWhiteSpace(webPageCodeModel.CodeGuid))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "headerTitle=\"" +
|
||
webPageCodeModel.tableLayoutModel.TableTitle + "\" // 列表表头");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "headerTitle={");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "<Tooltip title=\"" + webPageCodeModel.CodeGuid + "\">" +
|
||
webPageCodeModel.tableLayoutModel.TableTitle + "</Tooltip> // 列表表头");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "actionRef={actionRef}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "search={{ span: 6, labelWidth: 'auto' }}");
|
||
//是否需要手动触发首次请求, 配置为 true 时不可隐藏搜索表单
|
||
if (webPageCodeModel.treeViewModel.InitialSearch == "2")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "manualRequest={true}" +
|
||
" // 是否需要手动触发首次请求, 配置为 true 时不可隐藏搜索表单");
|
||
}
|
||
|
||
#region 请求数据的代码
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "// 请求数据");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "request={async (params, sorter) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "// 排序字段");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "const sortstr = Object.keys(sorter).map(n => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "const value = sorter[n]");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "return value ? `${n} ${value.replace('end', '')}` : ''");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "})");
|
||
|
||
if (webPageCodeModel.InterfaceType < 2)
|
||
{
|
||
#region 标准接口代码
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "const searchWholeParams = {");
|
||
|
||
string defaultSQL = "";
|
||
foreach (DataRow drGVEModel in dtGVEModel.Select("DefaultValue is not null and DefaultValue <> ''"))
|
||
{
|
||
defaultSQL += (defaultSQL == "" ? " " : ", ") + drGVEModel["INTERFACEMODEL_NAME"] + ": " + drGVEModel["DefaultValue"];
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.TreeViewWidth) && !string.IsNullOrWhiteSpace(treeViewModel.SearchParams))
|
||
{
|
||
#region 如果有左侧树组件,请求的参数中加上传参字段
|
||
string TabCharStr;
|
||
if (webPageCodeModel.ListType == 2)
|
||
{
|
||
//嵌套列表查询条件
|
||
TabCharStr = CommonHelper.GetTabChar(6 + StartIndex);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "...params," + defaultSQL);
|
||
}
|
||
else
|
||
{
|
||
//普通列表查询条件
|
||
TabCharStr = CommonHelper.GetTabChar(7 + StartIndex);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "searchParameter: { ...params," + defaultSQL);
|
||
}
|
||
|
||
if (treeViewModel.TreeViewType == "2")
|
||
{
|
||
#region 设置菜单树的查询条件
|
||
//如果父级节点和子级节点的入参是一样的,则传参规则写在一个字段里面
|
||
if (string.IsNullOrWhiteSpace(treeViewModel.SearchParentParams) ||
|
||
treeViewModel.SearchParentParams == treeViewModel.SearchParams)
|
||
{
|
||
_Index.AppendLine(TabCharStr + treeViewModel.SearchParams +
|
||
": selectedId ? selectedId : currenMenu,");
|
||
}
|
||
else
|
||
{
|
||
//子级和父级节点属性不一样,则分开写入参条件
|
||
_Index.AppendLine(TabCharStr + treeViewModel.SearchParams + ": selectedId,");
|
||
_Index.AppendLine(TabCharStr + treeViewModel.SearchParentParams + ": currenMenu");
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 设置勾选树的查询条件
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.UsedDefinedModeValue))
|
||
{
|
||
//增加自定义类别的传参字段
|
||
_Index.AppendLine(TabCharStr + treeViewModel.SearchParams +
|
||
": selectedId && selectedId.length > 0 ? selectedId.toString() : null,");
|
||
}
|
||
else
|
||
{
|
||
//增加树的传参字段
|
||
_Index.AppendLine(TabCharStr + treeViewModel.SearchParams + ": selectedId || '0',");
|
||
}
|
||
#endregion
|
||
}
|
||
if (webPageCodeModel.ListType == 1)
|
||
{
|
||
//普通列表补充结束代码
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "},");
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
if (webPageCodeModel.ListType == 2)
|
||
{
|
||
//嵌套列表查询条件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "...params," + defaultSQL);
|
||
}
|
||
else
|
||
{
|
||
//普通列表查询条件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
"searchParameter: { ...params" + (defaultSQL == "" ? "" : "," + defaultSQL) + " },");
|
||
}
|
||
}
|
||
//如果是全局权限,则传入省份编码
|
||
if (!string.IsNullOrWhiteSpace(treeViewModel.Province_Code))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "PROVINCE_CODE: " +
|
||
treeViewModel.Province_Code + ", ShowWholePower: true,");
|
||
}
|
||
//增加模糊查询的筛选
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLsearchKeyValue))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "keyWord: params.searchKey ? { key: \"" +
|
||
webPageCodeModel.searchControlModel.DDLsearchKeyValue + "\", value: params.searchKey } : null, // 关键词查询");
|
||
}
|
||
//增加排序字段
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "sortstr: sortstr.length ? sortstr.toString() : \"\",");
|
||
//默认不配置翻页属性,则每页返回999999行数据
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "pagesize: 999999");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "}");
|
||
//存储查询结果,用于导出excel使用
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "setSearchParams(searchWholeParams)");
|
||
//显示翻页组件
|
||
if (webPageCodeModel.tableLayoutModel.ShowPagination)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "searchWholeParams.pagesize = params.pageSize");
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "const data = await " +
|
||
webPageCodeModel.interfaceNameSpaceModel.txtInterfaceName + "(searchWholeParams);");
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 非标准接口代码
|
||
//定义请求全部入参
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "const searchWholeParams = {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "...params,");
|
||
//如果有左侧树组件,请求的参数中加上传参字段
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.treeViewModel.TreeViewWidth) &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.treeViewModel.SearchParams))
|
||
{
|
||
//如果是全局权限,则传入省份编码
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.treeViewModel.Province_Code))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "PROVINCE_CODE: " +
|
||
webPageCodeModel.treeViewModel.Province_Code + ", ShowWholePower: true,");
|
||
}
|
||
//设置菜单树的查询条件
|
||
if (webPageCodeModel.treeViewModel.TreeViewType == "2")
|
||
{
|
||
//如果父级节点和子级节点的入参是一样的,则传参规则写在一个字段里面
|
||
if (webPageCodeModel.treeViewModel.SearchParentParams == webPageCodeModel.treeViewModel.SearchParams)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + webPageCodeModel.treeViewModel.SearchParams +
|
||
": selectedId ? selectedId : currenMenu,");
|
||
}
|
||
else
|
||
{
|
||
//子级和父级节点属性不一样,则分开写入参条件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + webPageCodeModel.treeViewModel.SearchParams +
|
||
": selectedId ? selectedId : '',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
webPageCodeModel.treeViewModel.SearchParentParams + ": currenMenu,");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.treeViewModel.UsedDefinedModeValue))
|
||
{
|
||
//增加自定义类别的传参字段
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
webPageCodeModel.treeViewModel.SearchParams +
|
||
": selectedId && selectedId.length > 0 ? selectedId.toString() : null,");
|
||
}
|
||
else
|
||
{
|
||
//增加树的传参字段
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
webPageCodeModel.treeViewModel.SearchParams + ": selectedId || '0',");
|
||
}
|
||
}
|
||
}
|
||
//设置关键词查询字段
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.searchControlModel.DDLsearchKeyValue))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "keyWord: params.searchKey ? { key: \"" +
|
||
webPageCodeModel.searchControlModel.DDLsearchKeyValue + "\", value: params.searchKey } : null, // 关键词查询");
|
||
}
|
||
//默认不配置翻页属性,则每页返回999999行数据
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "PageIndex: 1,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "PageSize: 999999,");
|
||
|
||
string txtParamsName = webPageCodeModel.interfaceNameSpaceModel.txtParamsName;
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "}" +
|
||
(string.IsNullOrWhiteSpace(txtParamsName) ? "" : " as " + txtParamsName) + ";");
|
||
//增加排序字段
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "if (sortstr.length) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "searchWholeParams.SortStr = sortstr.toString()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "}");
|
||
//保存查询条件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "setSearchParams(searchWholeParams);");
|
||
//显示翻页组件
|
||
if (webPageCodeModel.tableLayoutModel.ShowPagination)
|
||
{
|
||
//查询页码数
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "searchWholeParams.PageIndex = params.current");
|
||
//每页显示行数
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "searchWholeParams.PageSize = params.pageSize");
|
||
}
|
||
//请求数据
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "const data = await " +
|
||
webPageCodeModel.interfaceNameSpaceModel.txtInterfaceName + "(searchWholeParams)");
|
||
#endregion
|
||
}
|
||
//初始化打印内容
|
||
if (webPageCodeModel.tableLayoutModel.ShowPrint)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "setPrintOut(undefined);");
|
||
}
|
||
if (webPageCodeModel.ListType == 2)
|
||
{
|
||
//嵌套接口列表返回格式
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "set" + webPageCodeModel.HostClassName + "Tree(data);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return { data, success: true };");
|
||
}
|
||
else
|
||
{
|
||
//非嵌套接口列表返回格式
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return data;");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}}");
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "columns={columns}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "toolbar={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "actions: [");
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.TableToolBar))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Typography.Text type=\"secondary\">" +
|
||
webPageCodeModel.tableLayoutModel.TableToolBar + "</Typography.Text>,");
|
||
}
|
||
if (webPageCodeModel.tableLayoutModel.ShowPrint)
|
||
{
|
||
#region 打印按钮
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// 打印按钮");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<ReactToPrint");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "trigger={() => (");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<Button key=\"printout\" type=\"default\">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "打印");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "</Button>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ")}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "content={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "if (printOut) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const content: HTMLElement | Node | " +
|
||
"undefined = printOut?.getElementsByClassName('ant-card-body')[0]");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const [start, end] = formRef.current?.getFieldValue('search_date') || [];");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const innerText = start && end ? " +
|
||
"`统计时间:${moment(start).format('YYYY/MM/DD')}-${moment(end).format('YYYY/MM/DD')}` : '';");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const ele = printOutInternal(" +
|
||
"content ? content.cloneNode(true) : [], innerText);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "return ele");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "return ''");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "/>,");
|
||
#endregion
|
||
}
|
||
if (webPageCodeModel.tableLayoutModel.ShowExportExcel)
|
||
{
|
||
#region 导出excel按钮
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// 导出Excel按钮");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Button");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "key=\"new\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "type=\"primary\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "onClick={async () => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "if (searchParams) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "searchParams.pageSize = 999999;");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const data = await " +
|
||
webPageCodeModel.interfaceNameSpaceModel.txtInterfaceName + "(searchParams);");
|
||
//_Index.AppendLine(Business.CommonHelper.GetTabChar(8) + "if (data.data && data.data.length > 0) {");
|
||
//_Index.AppendLine(Business.CommonHelper.GetTabChar(9) + "data.data.forEach((c: any, i) => {");
|
||
//foreach (DataRow drEnum in dtGVEModel.Select("ShowColumn = 1 and (FieldExplainField is not null and FieldExplainField <> '')"))
|
||
//{
|
||
// _Index.AppendLine(Business.CommonHelper.GetTabChar(10) + "c." + drEnum["INTERFACEMODEL_NAME"] + " = c." + drEnum["INTERFACEMODEL_NAME"] + " ? " +
|
||
// drEnum["FieldExplainField"].ToString().ToLower() + "Tree[c." + drEnum["INTERFACEMODEL_NAME"] + "] : '-';");
|
||
// //_Index.AppendLine(Business.CommonHelper.GetTabChar(10) + "c.COMPACT_STARTDATE = c.COMPACT_STARTDATE ? moment(c.COMPACT_STARTDATE).format('YYYY/MM/DD') : '-';");
|
||
// //_Index.AppendLine(Business.CommonHelper.GetTabChar(10) + "c.COMPACT_ENDDATE = c.COMPACT_ENDDATE ? moment(c.COMPACT_ENDDATE).format('YYYY/MM/DD') : '-';");
|
||
//}
|
||
//_Index.AppendLine(Business.CommonHelper.GetTabChar(9) + "})");
|
||
//_Index.AppendLine(Business.CommonHelper.GetTabChar(8) + "}");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "const success = await exportExcel(");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "columns.filter(n => !n.hideInTable && n.dataIndex !== 'option'),");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "data.data || [],");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "`" +
|
||
(string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.ExcelTitle) ? webPageCodeModel.tableLayoutModel.TableTitle :
|
||
webPageCodeModel.tableLayoutModel.ExcelTitle) + "_${moment().format('YYYY/MM/DD')}`,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + ");");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "if (success.message !== 'ok') {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message.info({ content: success.message });");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "导出excel");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Button>,");
|
||
#endregion
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.BtnNameToolBar) &&
|
||
dtEditor != null && dtEditor.Rows.Count > 0)
|
||
{
|
||
#region 新增按钮
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "// 新增按钮");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Button");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "key=\"new\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "icon={<PlusOutlined />}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "type=\"primary\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "onClick={() => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "handleModalVisible(true);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + ">");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + webPageCodeModel.tableLayoutModel.BtnNameToolBar);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Button>,");
|
||
#endregion
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "],");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}}");
|
||
//隐藏刷新组件
|
||
if (!webPageCodeModel.tableLayoutModel.ShowOptions)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "options={false} // 隐藏刷新组件");
|
||
}
|
||
|
||
if ((webPageCodeModel.webChartModel != null &&
|
||
(!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.FChartValue) ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.SChartValue) ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.TChartValue))) ||
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.SummaryTitle))
|
||
{
|
||
int ChartCount = 0;
|
||
if (webPageCodeModel.webChartModel != null)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.FChartValue)) ChartCount++;
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.SChartValue)) ChartCount++;
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.TChartValue)) ChartCount++;
|
||
}
|
||
|
||
if (ChartCount > 0 && string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.SummaryTitle))
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "tableExtraRender={() =>");
|
||
|
||
//配置报表页面图表相关代码
|
||
BuildIndexChart(_Index, webPageCodeModel, ChartCount, StartIndex);
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}");
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(webPageCodeModel.tableLayoutModel.SummaryTitle))
|
||
{
|
||
#region 拼接合计项的代码
|
||
string SummaryParamsStr = "", SummaryStr = "", TotalValueStr = "", DescriptionsStr = "";
|
||
if (dtGVEModel != null && dtGVEModel.Rows.Count > 0)
|
||
{
|
||
GetSummaryData(dtGVEModel, ref SummaryParamsStr, ref SummaryStr, ref TotalValueStr, ref DescriptionsStr, StartIndex);
|
||
}
|
||
if (dtGVEOtherModel != null && dtGVEOtherModel.Rows.Count > 0)
|
||
{
|
||
GetSummaryData(dtGVEOtherModel, ref SummaryParamsStr, ref SummaryStr, ref TotalValueStr, ref DescriptionsStr, StartIndex);
|
||
}
|
||
if (dtGridViewExRelate != null && dtGridViewExRelate.Rows.Count > 0)
|
||
{
|
||
GetSummaryData(dtGridViewExRelate, ref SummaryParamsStr, ref SummaryStr, ref TotalValueStr, ref DescriptionsStr, StartIndex);
|
||
}
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "tableExtraRender={(_, data) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "if (data && data.length > 0) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "const reduceData = data.reduce((p: {");
|
||
_Index.AppendLine(SummaryParamsStr);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
"}, currentValue: " + webPageCodeModel.HostModelName + ") => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "const previousValue = { ...p }");
|
||
_Index.AppendLine(SummaryStr);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "return previousValue");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "}, {");
|
||
_Index.AppendLine(TotalValueStr);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "});");
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "return <div style={{ paddingLeft: 24 }}>");
|
||
|
||
if (ChartCount > 0)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) +
|
||
"<Descriptions column={1} className=\"commity-sale-description\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) +
|
||
"contentStyle={{ fontSize: 14, color: \"#00000073\" }} labelStyle={{ color: \"#00000073\" }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ">");
|
||
|
||
//配置报表页面图表相关代码
|
||
BuildIndexChart(_Index, webPageCodeModel, ChartCount, 3 + StartIndex);
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Descriptions>");
|
||
}
|
||
|
||
#region 配置合计项显示内容
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Descriptions");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) +
|
||
"title={<Text type=\"success\" style={{ color: \"#1890ff\", fontSize: 14 }}>" +
|
||
webPageCodeModel.tableLayoutModel.SummaryTitle + "</Text>} size=\"small\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "className=\"commity-sale-description\" " +
|
||
"column={5} contentStyle={{ fontWeight: \"bolder\" }} labelStyle={{ color: \"#00000073\" }}>");
|
||
_Index.AppendLine(DescriptionsStr);
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Descriptions>");
|
||
#endregion
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</div>");
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "return <></>");
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "}}");
|
||
}
|
||
}
|
||
|
||
//显示分页组件,默认值是每页10行数据
|
||
if (webPageCodeModel.tableLayoutModel.ShowPagination)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "pagination={{ defaultPageSize: 10 }}");
|
||
}
|
||
else
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(4 + StartIndex) + "pagination={false} // 隐藏分页组件");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(3 + StartIndex) + "/>");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拼接合计项的代码
|
||
/// </summary>
|
||
/// <param name="dtResponseModel">字段数据源</param>
|
||
/// <param name="SummaryParamsStr">合计项入参代码</param>
|
||
/// <param name="SummaryStr">合计项代码</param>
|
||
/// <param name="TotalValueStr">合计值内容</param>
|
||
/// <param name="DescriptionsStr">合计值描述</param>
|
||
/// <param name="StartIndex">代码内容缩进格数</param>
|
||
public static void GetSummaryData(DataTable dtResponseModel, ref string SummaryParamsStr,
|
||
ref string SummaryStr, ref string TotalValueStr, ref string DescriptionsStr, int StartIndex = 0)
|
||
{
|
||
foreach (DataRow drResponseModel in dtResponseModel.Select("DataSummary > 0", "ColumnIndex"))
|
||
{
|
||
//定义合计显示的字段
|
||
SummaryParamsStr += (SummaryParamsStr == "" ? CommonHelper.GetTabChar(7 + StartIndex) :
|
||
" ," + (SummaryParamsStr.Split(',').Length % 4 == 0 ? "\r\n" +
|
||
CommonHelper.GetTabChar(7 + StartIndex) : "")) +
|
||
drResponseModel["INTERFACEMODEL_NAME"] + "_Total: number";
|
||
|
||
//设置合计显示的字段值
|
||
TotalValueStr += (TotalValueStr == "" ? CommonHelper.GetTabChar(7 + StartIndex) :
|
||
" ," + (TotalValueStr.Split(',').Length % 4 == 0 ? "\r\n" +
|
||
CommonHelper.GetTabChar(7 + StartIndex) : "")) +
|
||
drResponseModel["INTERFACEMODEL_NAME"] + "_Total: 0";
|
||
|
||
//设置合计项的计算公式
|
||
SummaryStr += (SummaryStr == "" ? "" : "\r\n") + CommonHelper.GetTabChar(7 + StartIndex);
|
||
if (drResponseModel["DataSummary"].ToString() == "1")
|
||
{
|
||
SummaryStr += "previousValue." + drResponseModel["INTERFACEMODEL_NAME"] + "_Total = numeral(numeral(previousValue." +
|
||
drResponseModel["INTERFACEMODEL_NAME"] + "_Total +\r\n" + CommonHelper.GetTabChar(8 + StartIndex) +
|
||
"(currentValue." + drResponseModel["INTERFACEMODEL_NAME"] + " || 0)).format('0.00')).value() || 0";
|
||
}
|
||
else
|
||
{
|
||
SummaryStr += "previousValue." + drResponseModel["INTERFACEMODEL_NAME"] + "_Total += 1";
|
||
}
|
||
|
||
//绑定合计项值
|
||
DescriptionsStr += (DescriptionsStr == "" ? "" : "\r\n") + CommonHelper.GetTabChar(8 + StartIndex);
|
||
if (drResponseModel["DataSummary"].ToString() == "1")
|
||
{
|
||
DescriptionsStr += "<Descriptions.Item label=\"" + drResponseModel["INTERFACEMODEL_COMMENT"] + "\">" +
|
||
"¥{numeral(reduceData." + drResponseModel["INTERFACEMODEL_NAME"] + "_Total).value()}</Descriptions.Item>";
|
||
}
|
||
else
|
||
{
|
||
DescriptionsStr += "<Descriptions.Item label=\"数据总数\">{numeral(reduceData." +
|
||
drResponseModel["INTERFACEMODEL_NAME"] + "_Total).value()}</Descriptions.Item>";
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 生成编辑页面代码
|
||
/// <summary>
|
||
/// 生成编辑页面数据
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="_DataTable">字段列表数据源</param>
|
||
/// <param name="EveryLineCount">每行显示字段个数</param>
|
||
/// <param name="_ClassName">主接口类名称</param>
|
||
/// <param name="ShowColumn">是否只显示要编辑的字段</param>
|
||
/// <param name="ListType">主接口类型:1【普通列表】,2【子父级列表】;判断要不要解析父级内码</param>
|
||
/// <param name="StartIndex">每行代码内容缩进格数</param>
|
||
public static void BuildEditModel(StringBuilder stringBuilder, DataTable _DataTable,
|
||
int EveryLineCount, string _ClassName, bool ShowColumn = true, int ListType = 0, int StartIndex = 0)
|
||
{
|
||
//加载要显示的控件
|
||
if (ShowColumn)
|
||
{
|
||
foreach (DataRow _DataRow in _DataTable.Select("ShowColumn = 1", "ColumnIndex,INTERFACEMODEL_ID"))
|
||
{
|
||
string _INTERFACEMODEL_COMMENT = _DataRow["INTERFACEMODEL_COMMENT"].ToString().Split('(')[0].Split('(')[0];
|
||
|
||
if (_DataRow["INTERFACEMODEL_NAME"].ToString().ToLower().EndsWith("desc"))
|
||
{
|
||
#region 设置备注字段显示格式
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col span={24}>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormTextArea");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "labelCol={{ span: 3 }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "wrapperCol={{ span: 20 }}");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col span={" + (24 / EveryLineCount) + "}>");
|
||
//验证数据格式
|
||
switch (_DataRow["ControlType"].ToString())
|
||
{
|
||
case "0":
|
||
#region 设置输入框控件
|
||
if (_DataRow["INTERFACEMODEL_NAME"].ToString().ToLower().EndsWith("date"))
|
||
{
|
||
#region 设置日期字段显示格式
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormDatePicker");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
if (_DataRow["FieldExplainField"].ToString() != "")
|
||
{
|
||
//如果是枚举,则加载枚举信息
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Form.Item");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<TreeSelect");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "placeholder=\"请选择" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "dropdownStyle={{ maxHeight: 300, overflow: 'auto' }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "treeData={" +
|
||
_DataRow["FieldExplainField"].ToString().ToLower() + "Tree}");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "readonly");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "allowClear");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Form.Item>");
|
||
}
|
||
else
|
||
{
|
||
if (_DataRow["INTERFACEMODEL_FORMAT"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormMoney");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "fieldProps={{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9) + "moneySymbol: false,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8) + "}}");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormText");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
case "1":
|
||
#region 设置下拉框控件
|
||
if (_DataRow["FieldExplainField"].ToString() != "")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Form.Item");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<TreeSelect");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "placeholder=\"请选择" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "dropdownStyle={{ maxHeight: 300, overflow: 'auto' }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "treeData={" +
|
||
_DataRow["FieldExplainField"].ToString().ToLower() + "Tree}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "allowClear");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "readonly");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Form.Item>");
|
||
}
|
||
else
|
||
{
|
||
if (_DataRow["INTERFACEMODEL_NAME"].ToString().EndsWith("PID"))
|
||
{
|
||
//父级内码代码格式
|
||
if (ListType == 2)
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Form.Item");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<TreeSelect");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "placeholder=\"请选择" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "dropdownStyle={{ maxHeight: 300, overflow: 'auto' }}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "treeData={" + _ClassName.ToLower() + "Tree}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "fieldNames={{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "label: '" + _ClassName + "_NAME',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "value: '" + _ClassName + "_ID',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "children: 'children'");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "allowClear");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "readonly");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Form.Item>");
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormSelect");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormSelect");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
case "2":
|
||
#region 设置日期框控件
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormDatePicker");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
break;
|
||
case "3":
|
||
#region 设置开关控件
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "{/* 当前依赖包动画过渡有问题 临时采用 Form.Item 方式进行Switch交互 */}");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Form.Item");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + ">");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<Switch");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "checkedChildren=\"有\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "unCheckedChildren=\"无\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "defaultChecked={currentRow ? !!currentRow." +
|
||
_DataRow["INTERFACEMODEL_NAME"] + " : true}");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Form.Item>");
|
||
#endregion
|
||
break;
|
||
case "4":
|
||
#region 设置月份框控件
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormDatePicker.Month");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
break;
|
||
case "5":
|
||
#region 设置年份框控件
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormDatePicker.Year");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
break;
|
||
case "6":
|
||
#region 设置时间框控件
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormDateTimePicker");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "width=\"lg\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请选择" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
break;
|
||
default:
|
||
#region 其他格式默认是输入文本框
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormText");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
//如果控件不可编辑,要加readonly属性
|
||
if (_DataRow["CBEditable"].ToString() == "0")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "readonly");
|
||
}
|
||
//如果是必填项,则设置必填项控制
|
||
else if (_DataRow["Required"].ToString() == "1")
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "placeholder=\"请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请输入" + _DataRow["INTERFACEMODEL_COMMENT"] + "',");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
}
|
||
#endregion
|
||
break;
|
||
}
|
||
//开关控件已经加过这行代码了,不需要重复写
|
||
if (_DataRow["ControlType"].ToString() != "3" && _DataRow["FieldExplainField"].ToString() == "" &&
|
||
!_DataRow["INTERFACEMODEL_NAME"].ToString().EndsWith("PID"))
|
||
{
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
}
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (DataRow _DataRow in _DataTable.Select("MULTI_SEARCH = 0", "ColumnIndex,INTERFACEMODEL_ID"))
|
||
{
|
||
string _INTERFACEMODEL_COMMENT = _DataRow["INTERFACEMODEL_COMMENT"].ToString().Split('(')[0].Split('(')[0];
|
||
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col style={{ display: 'none' }}>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormText");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"" + _DataRow["INTERFACEMODEL_NAME"] + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + _INTERFACEMODEL_COMMENT + "\"");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
stringBuilder.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 合并编辑页中需要隐藏的字段
|
||
/// <summary>
|
||
/// 合并编辑页中需要隐藏的字段
|
||
/// </summary>
|
||
/// <param name="dtHostEdit">主接口编辑页面字段数据源</param>
|
||
/// <param name="dtRelateEdit">关联接口编辑页面字段数据源</param>
|
||
/// <returns></returns>
|
||
public static DataTable CombineHideColumns(DataTable dtHostEdit, DataTable dtRelateEdit)
|
||
{
|
||
//获取编辑列表中不显示的字段
|
||
DataTable dtHideEditor = dtHostEdit.Select("ShowColumn is null or ShowColumn <> 1").CopyToDataTable();
|
||
//查询关联接口的编辑页列表设置,将需要隐藏的字段合并到dtHideEditor中
|
||
if (dtRelateEdit != null && dtRelateEdit.Rows.Count > 0)
|
||
{
|
||
foreach (DataRow drRelateEdit in dtRelateEdit.Rows)
|
||
{
|
||
if (drRelateEdit["ShowColumn"].ToString() == "1")
|
||
{
|
||
//该字段在关联接口中显示,在主接口中存在且不显示,那么需要从隐藏列表中移除
|
||
if (dtHideEditor.Select("INTERFACEMODEL_NAME = '" + drRelateEdit["INTERFACEMODEL_NAME"] + "'").Length > 0)
|
||
{
|
||
DataRow drHideEditor = dtHideEditor.Select("INTERFACEMODEL_NAME = '" + drRelateEdit["INTERFACEMODEL_NAME"] + "'")[0];
|
||
dtHideEditor.Rows.Remove(drHideEditor);
|
||
}
|
||
}
|
||
else if (dtHostEdit.Select("INTERFACEMODEL_NAME = '" +
|
||
drRelateEdit["INTERFACEMODEL_NAME"] + "'").Length == 0)
|
||
{
|
||
//该字段不存在主接口中,则要添加到隐藏列表中
|
||
DataRow drHideEditor = dtHideEditor.NewRow();
|
||
drHideEditor["INTERFACEMODEL_ID"] = drRelateEdit["INTERFACEMODEL_ID"];
|
||
drHideEditor["INTERFACEMODEL_NAME"] = drRelateEdit["INTERFACEMODEL_NAME"];
|
||
drHideEditor["INTERFACEMODEL_COMMENT"] = drRelateEdit["INTERFACEMODEL_COMMENT"];
|
||
drHideEditor["MULTI_SEARCH"] = drRelateEdit["MULTI_SEARCH"];
|
||
drHideEditor["ColumnIndex"] = drRelateEdit["ColumnIndex"];
|
||
dtHideEditor.Rows.Add(drHideEditor);
|
||
}
|
||
}
|
||
}
|
||
return dtHideEditor;
|
||
}
|
||
#endregion
|
||
|
||
#region 编辑页附件相关代码
|
||
/// <summary>
|
||
/// 生成编辑页附件相关代码
|
||
/// </summary>
|
||
/// <param name="_Index">前端列表页面生成的字符串</param>
|
||
/// <param name="attachmentLayoutModel">页面上附件控件相关类</param>
|
||
/// <param name="StartIndex">字符串缩进格数</param>
|
||
public static void BuildEditFileUpload(StringBuilder _Index,
|
||
Model.AttachmentLayoutModel attachmentLayoutModel, int StartIndex = 0)
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col span={24}>");
|
||
//附件类型是图片
|
||
if (attachmentLayoutModel.Attachment_Type == "1")
|
||
{
|
||
if (attachmentLayoutModel.UploadAttachment)
|
||
{
|
||
#region 上传图片
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormUploadButton");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"files\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"" + attachmentLayoutModel.AttachmentTitle + "\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "fileList={fileList}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "listType=\"picture-card\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "fieldProps={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "beforeUpload,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "maxCount: 1,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "onPreview: handlePreview,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "customRequest: async (info) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "const formData = new FormData();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "formData.append('files', info.file);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "formData.append('TableType', '" +
|
||
attachmentLayoutModel.ShowAttachmentValue + "');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "formData.append(" +
|
||
"'ImageName', typeof info.file !== 'string' ? info.file?.name : '');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "if (info.filename) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "const success = await uploadFile(formData)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "if (success) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "const list = [{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "uid: `${success.ImageId}`, // 注意,这个uid一定不能少,否则上传失败");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "name: success.ImageName,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "status: 'done',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "url: success.ImageUrl, // url 是展示在页面上的绝对链接");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "imgUrl: success.ImagePath // + success.ImageUrl,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "}]");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setFileList(list)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "} else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "message.error(\"您上传的图片不存在.\")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "onChange: async (info: any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "if (info.file.status === 'removed') {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "confirm({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "title: '确认删除该图片吗?',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "icon: <ExclamationCircleOutlined />,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "// content: 'When clicked the OK button, this dialog will be closed after 1 second',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "async onOk() {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "const deleteLoading = message.loading('正在删除...')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "try {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "const deleteIndex = fileList?.findIndex((n: any) => n.uid === info.file.uid)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "if (deleteIndex !== -1) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(15 + StartIndex) + "const files = [...fileList]");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(15 + StartIndex) + "files.splice(deleteIndex, 1)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(15 + StartIndex) + "setFileList(files)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "}");
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "deleteLoading()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "return true");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "} catch (error) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "deleteLoading()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "message.error(\"删除失败\")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "return false");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "onCancel() { },");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "});");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "}");
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
|
||
_Index.AppendLine("");
|
||
#endregion
|
||
}
|
||
|
||
#region 预览图片
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "{/* 图片预览组件 */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "{fileList && fileList.length > 0 && <div style={{ display: 'none' }}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<Image.PreviewGroup");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "preview={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "visible: imagePreviewVisible,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "onVisibleChange: vis => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "setImagePreviewVisible(vis)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "fileList.map((n) => <Image src={n.url} key={n.url} />)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "</Image.PreviewGroup>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</div>}");
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 附件类型是文件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "{/* 上传文件组件 */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<ProFormUploadButton");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "name=\"ImgList\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "title=\"选择文件\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "label=\"上传文件\"");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "wrapperCol={{ span: 20 }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "labelCol={{ span: 3 }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "// max={0} // 设置每次上传文件的个数");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "// 附件默认要求必传,可以取消限制");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "rules={[");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "required: true,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "message: '请上传资质文件" +
|
||
(!string.IsNullOrWhiteSpace(attachmentLayoutModel.Accept_Type) ? ",文件类型为" +
|
||
attachmentLayoutModel.Accept_Type.Replace(".", "") : "") + "',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "]}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "fieldProps={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "name: 'files',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "// listType: 'picture-card',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "className: 'upload-list-inline',");
|
||
if (attachmentLayoutModel.Accept_Type != "")
|
||
{
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "accept: '" +
|
||
attachmentLayoutModel.Accept_Type + "', // 上传的文件格式");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "// defaultFileList: priviewFileList,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "fileList,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "multiple: true,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "onPreview: async (file) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) +
|
||
"if (file.type && file.type?.indexOf('image/') > -1) { // 未上传的文件 如果是图片类型的");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "if (!file.url && !file.preview) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setPriviewImage(await getBase64(file.lastModifiedDate))");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "} else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setPriviewImage(file?.url)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "} else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "const filenameSplitPointArr = file.fileName?.split('.') || []");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "if (['png', 'jpg', 'jpeg'].indexOf(" +
|
||
"filenameSplitPointArr[filenameSplitPointArr?.length - 1]) > -1) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setPriviewImage(file?.url)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "else if (file?.url) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "window.open(file?.url)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "beforeUpload: (file, files) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "setFileList([...fileList, ...files])");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "return false");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "onChange: async (info: any) => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "if (info.file.status === 'removed') {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "// 如果在待上传列表中找到,则说明当前图片没有上传服务器,可直接删除");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "const index = fileList.findIndex(n => n.uid === info.file.uid);");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "if (!info.file?.deletepath) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "const newFileList = fileList.slice();");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "newFileList.splice(index, 1);");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setFileList(newFileList)");
|
||
_Index.AppendLine("");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "return");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "confirm({");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "title: '确认删除该文件吗?',");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "icon: <ExclamationCircleOutlined />,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "async onOk() {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "const deleteLoading = message.loading('正在删除...')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "const success = await deletePicture(" +
|
||
"info.file?.deletepath, info.file?.uid, '', '" + attachmentLayoutModel.Storage_TableName + "')");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "deleteLoading()");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "if (success) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "const files = [...fileList]");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "files.splice(index, 1)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "setFileList(files)");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "else {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(14 + StartIndex) + "message.error(\"删除失败\")");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(13 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "onCancel() {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "});");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "}}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "/>");
|
||
|
||
//查看文件
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "{/* 查看文件组件 */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<div style={{ display: 'none' }}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<Image width={100} height={100} " +
|
||
"src={priviewImage} style={{ objectFit: \"contain\", display: 'none' }}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "preview={{");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "visible: !!priviewImage,");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "onVisibleChange: value => {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "if (!value) {");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(12 + StartIndex) + "setPriviewImage('');");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(11 + StartIndex) + "}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(10 + StartIndex) + "},");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(9 + StartIndex) + "}} />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</div>");
|
||
#endregion
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
#endregion
|
||
|
||
#region 生成主页面图表代码
|
||
/// <summary>
|
||
/// 生成主页面图表代码
|
||
/// </summary>
|
||
/// <param name="_Index">字符串</param>
|
||
/// <param name="webPageCodeModel">前端页面组件</param>
|
||
/// <param name="ChartCount">图表个数</param>
|
||
/// <param name="StartIndex">内容缩进格数</param>
|
||
public static void BuildIndexChart(StringBuilder _Index, Model.WebPageCodeModel webPageCodeModel, int ChartCount, int StartIndex)
|
||
{
|
||
int xl = 24 / ChartCount;
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "<Row gutter={24}>");
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.FChartValue) &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.FChartSession))
|
||
{
|
||
string requestParams = "";
|
||
Model.ChartSettingModel chartSettingModel = JsonConvert.DeserializeObject<
|
||
Model.ChartSettingModel>(webPageCodeModel.webChartModel.FChartSession);
|
||
if (chartSettingModel.ParamsDataList != null && chartSettingModel.ParamsDataList.Count > 0)
|
||
{
|
||
foreach (Model.ParamsDataModel paramsDataModel in chartSettingModel.ParamsDataList)
|
||
{
|
||
requestParams += (requestParams == "" ? " " : "\r\n" + CommonHelper.GetTabChar(9 + StartIndex)) +
|
||
paramsDataModel.ChartParams.ToLower() + "={searchParams?." + paramsDataModel.RequestParams + "}";
|
||
}
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) +
|
||
"<Col xl={" + xl + "} lg={24} md={24} sm={24} xs={24} style={{ paddingBottom: 10, }}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) +
|
||
"{/* " + webPageCodeModel.webChartModel.FChartText + " */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Suspense fallback={null}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<FChart" + requestParams + " />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Suspense>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.SChartValue) &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.SChartSession))
|
||
{
|
||
string requestParams = "";
|
||
Model.ChartSettingModel chartSettingModel = JsonConvert.DeserializeObject<
|
||
Model.ChartSettingModel>(webPageCodeModel.webChartModel.SChartSession);
|
||
if (chartSettingModel.ParamsDataList != null && chartSettingModel.ParamsDataList.Count > 0)
|
||
{
|
||
foreach (Model.ParamsDataModel paramsDataModel in chartSettingModel.ParamsDataList)
|
||
{
|
||
requestParams += (requestParams == "" ? " " : "\r\n" + CommonHelper.GetTabChar(9 + StartIndex)) +
|
||
paramsDataModel.ChartParams.ToLower() + "={searchParams?." + paramsDataModel.RequestParams + "}";
|
||
}
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col xl={" + xl + "} lg={24} md={24} sm={24} xs={24}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) +
|
||
"{/* " + webPageCodeModel.webChartModel.SChartText + " */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Suspense fallback={null}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<SChart" + requestParams + " />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Suspense>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.TChartValue) &&
|
||
!string.IsNullOrWhiteSpace(webPageCodeModel.webChartModel.TChartSession))
|
||
{
|
||
string requestParams = "";
|
||
Model.ChartSettingModel chartSettingModel = JsonConvert.DeserializeObject<
|
||
Model.ChartSettingModel>(webPageCodeModel.webChartModel.TChartSession);
|
||
if (chartSettingModel.ParamsDataList != null && chartSettingModel.ParamsDataList.Count > 0)
|
||
{
|
||
foreach (Model.ParamsDataModel paramsDataModel in chartSettingModel.ParamsDataList)
|
||
{
|
||
requestParams += (requestParams == "" ? " " : "\r\n" + CommonHelper.GetTabChar(9 + StartIndex)) +
|
||
paramsDataModel.ChartParams.ToLower() + "={searchParams?." + paramsDataModel.RequestParams + "}";
|
||
}
|
||
}
|
||
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "<Col xl={" + xl + "} lg={24} md={24} sm={24} xs={24}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) +
|
||
"{/* " + webPageCodeModel.webChartModel.TChartText + " */}");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "<Suspense fallback={null}>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(8 + StartIndex) + "<TChart" + requestParams + " />");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(7 + StartIndex) + "</Suspense>");
|
||
_Index.AppendLine(CommonHelper.GetTabChar(6 + StartIndex) + "</Col>");
|
||
}
|
||
_Index.AppendLine(CommonHelper.GetTabChar(5 + StartIndex) + "</Row>");
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 方法 -> 生成antd框架路由相关方法
|
||
/// <summary>
|
||
/// 生成antd框架路由
|
||
/// </summary>
|
||
/// <param name="sbRoute"></param>
|
||
/// <param name="UserId">系统用户内码</param>
|
||
/// <param name="UserPassport">用户登录账号</param>
|
||
/// <param name="SystemModuleName">系统模块名称</param>
|
||
/// <param name="SystemModuleURL">系统模块地址</param>
|
||
/// <param name="ModuleGuid">模块唯一标识</param>
|
||
/// <param name="SystemMenuId">系统菜单内码</param>
|
||
/// <param name="SystemRoleId">系统角色内码</param>
|
||
/// <param name="SaveModule">是否保存模块数据</param>
|
||
/// <param name="RouteType">路由类型</param>
|
||
/// <returns></returns>
|
||
public static bool GetRoute(ref StringBuilder sbRoute, int UserId, string UserPassport, string SystemModuleName,
|
||
string SystemModuleURL, string ModuleGuid, int SystemMenuId, int? SystemRoleId, bool SaveModule, int RouteType)
|
||
{
|
||
string result;
|
||
JObject keyValuePairs;
|
||
|
||
if (SaveModule)
|
||
{
|
||
#region 方法保存菜单和模块数据
|
||
//查询是否配置过当前模块,根据模块路径匹配数据
|
||
Model.SearchModel<Model.SYSTEMMODULEModel> searchModelModule = new Model.SearchModel<Model.SYSTEMMODULEModel>();
|
||
searchModelModule.SearchParameter = new Model.SYSTEMMODULEModel();
|
||
searchModelModule.SearchParameter.SYSTEMMODULE_URL = SystemModuleURL; //模块地址
|
||
//调用接口查询数据
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(searchModelModule),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/GetSYSTEMMODULEList", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() != "100")
|
||
{
|
||
//接口返回失败,则返回发布不成功
|
||
return false;
|
||
}
|
||
|
||
//判断有没有查询到模块地址,没有则添加模块地址到用户选择的菜单中;否则绑定模块对象
|
||
Model.SYSTEMMODULEModel _SYSTEMMODULEModel = new Model.SYSTEMMODULEModel();
|
||
if (keyValuePairs["Result_Data"]["TotalCount"].TryParseToInt() > 0)
|
||
{
|
||
List<Model.SYSTEMMODULEModel> SYSTEMMODULEList = JsonConvert.DeserializeObject<
|
||
List<Model.SYSTEMMODULEModel>>(keyValuePairs["Result_Data"]["List"].ToString());
|
||
_SYSTEMMODULEModel = SYSTEMMODULEList[0];
|
||
}
|
||
else
|
||
{
|
||
_SYSTEMMODULEModel.SYSTEMMENU_ID = SystemMenuId;
|
||
_SYSTEMMODULEModel.SYSTEMMODULE_TYPE = 1000;
|
||
_SYSTEMMODULEModel.SYSTEMMODULE_NAME = SystemModuleName;
|
||
_SYSTEMMODULEModel.SYSTEMMODULE_URL = SystemModuleURL;
|
||
_SYSTEMMODULEModel.SYSTEMMODULE_GUID = ModuleGuid;
|
||
_SYSTEMMODULEModel.SYSTEMMODULE_STATUS = 1;
|
||
_SYSTEMMODULEModel.OPERATE_DATE = DateTime.Now;
|
||
//同步到正式数据中
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(_SYSTEMMODULEModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/SynchroSYSTEMMODULE", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() == "100")
|
||
{
|
||
_SYSTEMMODULEModel = JsonConvert.DeserializeObject<Model.SYSTEMMODULEModel>(keyValuePairs["Result_Data"].ToString());
|
||
//如果用户设置了模块绑定的角色,则要授权给用户模块权限
|
||
if (SystemRoleId != null)
|
||
{
|
||
Model.SYSTEMROLEMODULEModel _SYSTEMROLEMODULEModel = new Model.SYSTEMROLEMODULEModel();
|
||
_SYSTEMROLEMODULEModel.SYSTEMROLE_ID = SystemRoleId;
|
||
_SYSTEMROLEMODULEModel.SYSTEMMODULE_ID = _SYSTEMMODULEModel.SYSTEMMODULE_ID;
|
||
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(_SYSTEMROLEMODULEModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/SynchroSYSTEMROLEMODULE", "application/json");
|
||
|
||
Model.SearchModel<Model.USERSYSTEMROLEModel> searchModel = new Model.SearchModel<Model.USERSYSTEMROLEModel>()
|
||
{
|
||
SearchParameter = new Model.USERSYSTEMROLEModel()
|
||
{
|
||
SYSTEMROLE_ID = SystemRoleId,
|
||
USER_ID = UserId
|
||
}
|
||
};
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(searchModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/GetUSERSYSTEMROLEList", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() == "100" &&
|
||
keyValuePairs["Result_Data"]["TotalCount"].TryParseToInt() == 0)
|
||
{
|
||
Model.USERSYSTEMROLEModel userRoleModel = new Model.USERSYSTEMROLEModel()
|
||
{
|
||
SYSTEMROLE_ID = SystemRoleId,
|
||
USER_ID = UserId,
|
||
OPERATE_DATE = DateTime.Now
|
||
};
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(userRoleModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/SynchroUSERSYSTEMROLE", "application/json");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//新增模块失败,则返回发布不成功
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
int AntdRoutePID = ConfigurationManager.AppSettings["RoutePID_" + RouteType].TryParseToInt();
|
||
sbRoute.AppendLine("// 路由配置文件");
|
||
sbRoute.AppendLine("export default [");
|
||
//获取前端代码路由配置数据
|
||
Model.SearchModel<Model.ANTDROUTEModel> searchModelantdRoute = new Model.SearchModel<Model.ANTDROUTEModel>
|
||
{
|
||
SearchParameter = new Model.ANTDROUTEModel
|
||
{
|
||
ANTDROUTE_TYPE = (short)RouteType
|
||
},
|
||
PageSize = 99999999,
|
||
SortStr = "ANTDROUTE_INDEX,ANTDROUTE_ID"
|
||
};
|
||
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(searchModelantdRoute),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/GetANTDROUTEList", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() == "100")
|
||
{
|
||
List<Model.ANTDROUTEModel> RouteList = JsonConvert.DeserializeObject<
|
||
List<Model.ANTDROUTEModel>>(keyValuePairs["Result_Data"]["List"].ToString());
|
||
|
||
Model.ANTDROUTEModel PROUTEModel = new Model.ANTDROUTEModel();
|
||
//查询测试模块的路由地址是否已经配置
|
||
if (!RouteList.Exists(o => o.ANTDROUTE_PID == AntdRoutePID && o.ANTDROUTE_PATH == "/" + UserPassport.ToLower()))
|
||
{
|
||
//没有配置,则添加到路由数据库表中
|
||
Model.ANTDROUTEModel antdROUTEModel = new Model.ANTDROUTEModel();
|
||
antdROUTEModel.ANTDROUTE_PID = AntdRoutePID;
|
||
antdROUTEModel.ANTDROUTE_PATH = "/" + UserPassport.ToLower();
|
||
antdROUTEModel.ANTDROUTE_NAME = UserPassport.ToLower();
|
||
antdROUTEModel.ANTDROUTE_INDEX = 9000;
|
||
antdROUTEModel.ANTDROUTE_VISIBLE = 0;
|
||
antdROUTEModel.ANTDROUTE_STATE = 1;
|
||
antdROUTEModel.ANTDROUTE_TYPE = (short)RouteType;
|
||
antdROUTEModel.OPERATE_DATE = DateTime.Now;
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(antdROUTEModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/SynchroANTDROUTE", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() == "100")
|
||
{
|
||
PROUTEModel = JsonConvert.DeserializeObject<Model.ANTDROUTEModel>(keyValuePairs["Result_Data"].ToString());
|
||
}
|
||
RouteList.Add(antdROUTEModel);
|
||
}
|
||
else
|
||
{
|
||
PROUTEModel = RouteList.Find(o => o.ANTDROUTE_PID == AntdRoutePID && o.ANTDROUTE_PATH == "/" + UserPassport.ToLower());
|
||
}
|
||
|
||
//查询测试模块的路由地址是否已经配置
|
||
if (!RouteList.Exists(o => o.ANTDROUTE_PID == PROUTEModel.ANTDROUTE_ID &&
|
||
o.ANTDROUTE_PATH == SystemModuleURL.Split('/')[SystemModuleURL.Split('/').Length - 1]))
|
||
{
|
||
//没有配置,则添加到路由数据库表中
|
||
Model.ANTDROUTEModel antdROUTEModel = new Model.ANTDROUTEModel();
|
||
antdROUTEModel.ANTDROUTE_PID = PROUTEModel.ANTDROUTE_ID;
|
||
antdROUTEModel.ANTDROUTE_PATH = SystemModuleURL.Split('/')[SystemModuleURL.Split('/').Length - 1];
|
||
antdROUTEModel.ANTDROUTE_COMPONENT = "." + SystemModuleURL;
|
||
antdROUTEModel.ANTDROUTE_VISIBLE = 1;
|
||
antdROUTEModel.ANTDROUTE_STATE = 1;
|
||
antdROUTEModel.ANTDROUTE_TYPE = (short)RouteType;
|
||
antdROUTEModel.OPERATE_DATE = DateTime.Now;
|
||
result = HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(antdROUTEModel),
|
||
Config.AppSettings.EShangApiMainUrls + "/Platform/SynchroANTDROUTE", "application/json");
|
||
keyValuePairs = JObject.Parse(result);
|
||
if (keyValuePairs["Result_Code"].ToString() == "100")
|
||
{
|
||
antdROUTEModel = JsonConvert.DeserializeObject<Model.ANTDROUTEModel>(keyValuePairs["Result_Data"].ToString());
|
||
}
|
||
RouteList.Add(antdROUTEModel);
|
||
}
|
||
//绑定路由代码
|
||
BindChildRoute(sbRoute, -1, RouteList, 1);
|
||
}
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(1) + "{");
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(2) + "component: './404',");
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(1) + "},");
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(1) + "{");
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(2) + "component: './500',");
|
||
sbRoute.AppendLine(CommonHelper.GetTabChar(1) + "},");
|
||
|
||
sbRoute.AppendLine("];");
|
||
|
||
return true;
|
||
}
|
||
|
||
#region 绑定ANTD框架子集路由配置
|
||
/// <summary>
|
||
/// 绑定ANTD框架子集路由配置
|
||
/// </summary>
|
||
/// <param name="_Route">路由字符串</param>
|
||
/// <param name="AntdRoutePID">父级路由内码</param>
|
||
/// <param name="RouteList">路由数据集</param>
|
||
/// <param name="StartTabChar">缩进格数</param>
|
||
public static void BindChildRoute(StringBuilder _Route, int AntdRoutePID, List<Model.ANTDROUTEModel> RouteList, int StartTabChar)
|
||
{
|
||
foreach (Model.ANTDROUTEModel antdRoute in RouteList.FindAll(o => o.ANTDROUTE_PID == AntdRoutePID && o.ANTDROUTE_STATE == 1))
|
||
{
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar) + "{");
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_PATH))
|
||
{
|
||
//路由相对路径
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "path: '" + antdRoute.ANTDROUTE_PATH + "',");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_NAME))
|
||
{
|
||
//路由名称
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "name: '" + antdRoute.ANTDROUTE_NAME + "',");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_COMPONENT))
|
||
{
|
||
//路由地址
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "component: '" + antdRoute.ANTDROUTE_COMPONENT + "',");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_AUTHORITY))
|
||
{
|
||
//路由权限配置
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "authority: " + antdRoute.ANTDROUTE_AUTHORITY + ",");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_ICON))
|
||
{
|
||
//路由图标
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "icon: '" + antdRoute.ANTDROUTE_ICON + "',");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(antdRoute.ANTDROUTE_REDIRECT))
|
||
{
|
||
//路由重定向地址
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "redirect: '" + antdRoute.ANTDROUTE_REDIRECT + "',");
|
||
}
|
||
if (antdRoute.ANTDROUTE_VISIBLE == 0)
|
||
{
|
||
//是否隐藏当前模块
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "hideInMenu: true,");
|
||
}
|
||
if (RouteList.Exists(o => o.ANTDROUTE_PID == antdRoute.ANTDROUTE_ID))
|
||
{
|
||
//绑定子集路由配置
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "routes: [");
|
||
|
||
BindChildRoute(_Route, antdRoute.ANTDROUTE_ID.Value, RouteList, StartTabChar + 2);
|
||
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar + 1) + "],");
|
||
}
|
||
|
||
_Route.AppendLine(CommonHelper.GetTabChar(StartTabChar) + "},");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
}
|
||
}
|