预览接口字段报错不走js脚本
This commit is contained in:
@@ -354,6 +354,51 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController
|
||||
return JsEngineUtil.CallFunction(scriptStr, output.ToJsonString(CommonConst.options));//此处时间非时间戳
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不走js脚本
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> PreviewWithOutJs(string id, [FromBody] DataInterfacePreviewInput input)
|
||||
{
|
||||
_configId = _userManager.TenantId;
|
||||
_dbName = _userManager.TenantDbName;
|
||||
object output = null;
|
||||
var info = await GetInfo(id);
|
||||
var dicParameters = new Dictionary<string, string>();
|
||||
if (input.paramList.IsNotEmptyOrNull() && input.paramList.Count > 0)
|
||||
{
|
||||
dicParameters = input.paramList.ToDictionary(x => x.field, y => y.defaultValue);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(info.Path) && !info.Path.StartsWith("http"))
|
||||
{
|
||||
info.Path = $"{App.HttpContext.Request.Scheme}://{App.HttpContext.Request.Host}{info.Path}";
|
||||
}
|
||||
VerifyRequired(info, dicParameters);
|
||||
ReplaceParameterValue(info, dicParameters);
|
||||
if (info?.DataType == 1)
|
||||
{
|
||||
output = await GetData(info);
|
||||
}
|
||||
else if (info?.DataType == 2)
|
||||
{
|
||||
output = info.Query.ToObject<object>();
|
||||
}
|
||||
else
|
||||
{
|
||||
output = await GetApiDataByTypePreview(info);
|
||||
}
|
||||
if (info is null || info.DataProcessing.IsNullOrEmpty())
|
||||
{
|
||||
return output;
|
||||
}
|
||||
else
|
||||
{
|
||||
return output.ToJsonString(CommonConst.options);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 访问接口 选中 回写.
|
||||
@@ -578,7 +623,23 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.COM1020);
|
||||
if (e.Message == "TypeError: Method or property not found")
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await PreviewWithOutJs(id, input);
|
||||
List<Dictionary<string, Object>> list = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(result.ToString());
|
||||
return list.FirstOrDefault()?.Keys.ToList() ?? Enumerable.Empty<string>();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.COM1020);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.COM1020);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user