From def9290c37bab726167414e1253ac166560c4964 Mon Sep 17 00:00:00 2001 From: zhou keda <1315948824@qq.com> Date: Thu, 20 Jun 2024 09:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=8E=A5=E5=8F=A3=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=8A=A5=E9=94=99=E4=B8=8D=E8=B5=B0js=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/DataInterfaceService.cs | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/system/Tnb.Systems/System/DataInterfaceService.cs b/system/Tnb.Systems/System/DataInterfaceService.cs index b1d66fc8..5b3829fa 100644 --- a/system/Tnb.Systems/System/DataInterfaceService.cs +++ b/system/Tnb.Systems/System/DataInterfaceService.cs @@ -354,6 +354,51 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController return JsEngineUtil.CallFunction(scriptStr, output.ToJsonString(CommonConst.options));//此处时间非时间戳 } } + + /// + /// 不走js脚本 + /// + /// + /// + /// + public async Task PreviewWithOutJs(string id, [FromBody] DataInterfacePreviewInput input) + { + _configId = _userManager.TenantId; + _dbName = _userManager.TenantDbName; + object output = null; + var info = await GetInfo(id); + var dicParameters = new Dictionary(); + 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(); + } + else + { + output = await GetApiDataByTypePreview(info); + } + if (info is null || info.DataProcessing.IsNullOrEmpty()) + { + return output; + } + else + { + return output.ToJsonString(CommonConst.options); + } + } /// /// 访问接口 选中 回写. @@ -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> list = JsonConvert.DeserializeObject>>(result.ToString()); + return list.FirstOrDefault()?.Keys.ToList() ?? Enumerable.Empty(); + } + catch (Exception exception) + { + throw Oops.Oh(ErrorCode.COM1020); + } + } + else + { + throw Oops.Oh(ErrorCode.COM1020); + } } } #endregion