From df639309af5d9dfca647f836d344d68ed3de6225 Mon Sep 17 00:00:00 2001 From: cuckooent Date: Wed, 17 Sep 2025 17:46:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E7=BB=84=E6=93=8D=E4=BD=9C=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E2=80=9C=E5=AD=97=E6=AE=B5=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E2=80=9D=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CollectionOperationKit/ClientSideArrayOp.cs | 8 +- .../CollectionOperationKit.csproj | 136 +++++++++--------- CollectionOperationKit/PluginConfig.json | 4 +- .../Resources/CollectionOperationKit.js | 41 +++++- CollectionOperationKit/ServerSideArrayOp.cs | 60 +++++++- 5 files changed, 176 insertions(+), 73 deletions(-) diff --git a/CollectionOperationKit/ClientSideArrayOp.cs b/CollectionOperationKit/ClientSideArrayOp.cs index 89d4042..83499d5 100644 --- a/CollectionOperationKit/ClientSideArrayOp.cs +++ b/CollectionOperationKit/ClientSideArrayOp.cs @@ -191,6 +191,10 @@ namespace CollectionOperationKit { return setPropertyVisiblity(propertyName, true, true, false); } + case SupportedOperations.RenameProperty: + { + return setPropertyVisiblity(propertyName, true, true, true); + } default: { return base.GetDesignerPropertyVisible(propertyName, commandScope); @@ -240,7 +244,9 @@ namespace CollectionOperationKit [Description("Select:提取【输入参数】中每个元素里名为【操作参数A】的属性,将其作为一个新的数组返回")] Select, [Description("Distinct:以名为【操作参数A】的属性为基准(留空则直接比较数组元素),将【输入参数】去除空值和重复值后,作为新数组返回")] - Distinct + Distinct, + [Description("RenameProperty:将【输入参数】中每个对象的【操作参数A】属性重命名为【操作参数B】")] + RenameProperty } } } diff --git a/CollectionOperationKit/CollectionOperationKit.csproj b/CollectionOperationKit/CollectionOperationKit.csproj index 4ebef76..101e604 100644 --- a/CollectionOperationKit/CollectionOperationKit.csproj +++ b/CollectionOperationKit/CollectionOperationKit.csproj @@ -1,69 +1,69 @@ - - - net472 - false - 8 - bin\ - true - - - - - - - - - - runtime - - - runtime - - - - - C:\Program Files\Forguncy 8\Website\bin\Forguncy.Commands.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\Forguncy.Commands.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.CellTypes.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\GrapeCity.Forguncy.CellTypes.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.Plugin.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\GrapeCity.Forguncy.Plugin.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.ServerApi.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\Newtonsoft.Json.dll - False - - - False - - - - - - - - - - - + + + net472 + false + 8 + bin\ + true + + + + + + + + + + runtime + + + runtime + + + + + D:\Program Files\Forguncy 8.105\Website\bin\Forguncy.Commands.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\Forguncy.Commands.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.CellTypes.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\GrapeCity.Forguncy.CellTypes.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.Plugin.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\GrapeCity.Forguncy.Plugin.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.ServerApi.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\Newtonsoft.Json.dll + False + + + False + + + + + + + + + + + diff --git a/CollectionOperationKit/PluginConfig.json b/CollectionOperationKit/PluginConfig.json index 1a02cd5..073c4dd 100644 --- a/CollectionOperationKit/PluginConfig.json +++ b/CollectionOperationKit/PluginConfig.json @@ -1,4 +1,4 @@ -{ +{ "assembly": [ "CollectionOperationKit.dll" ], @@ -11,7 +11,7 @@ "name": "对象与集合操作工具", "pluginType": "command", "guid": "CDD2FBD5-794F-4C7F-A483-030352D73C3C", - "version": "2.10.0.2", + "version": "2.10.0.3", "dependenceVersion": "8.0.0.0", "bundleJavaScript": true, "bundleCSS": true diff --git a/CollectionOperationKit/Resources/CollectionOperationKit.js b/CollectionOperationKit/Resources/CollectionOperationKit.js index 97733e2..9d2df4c 100644 --- a/CollectionOperationKit/Resources/CollectionOperationKit.js +++ b/CollectionOperationKit/Resources/CollectionOperationKit.js @@ -440,6 +440,44 @@ var ClientSideArrayOp = (function (_super) { break; } + case SupportedOperations.RenameProperty: { + if (!Array.isArray(inP)) { + this.log("Paramater [" + params.InParamaterName + "] should be an Array."); + return; + } + + if (!paramA || paramA === "") { + this.log("Paramater [" + params.OperationParamaterAName + "] (original property name) should not be empty."); + return; + } + + if (!paramB || paramB === "") { + this.log("Paramater [" + params.OperationParamaterBName + "] (new property name) should not be empty."); + return; + } + + var result = []; + inP.forEach(function (obj) { + if (obj && typeof obj === 'object' && !Array.isArray(obj)) { + var newObj = {}; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + if (key === paramA) { + newObj[paramB] = obj[key]; + } else { + newObj[key] = obj[key]; + } + } + } + result.push(newObj); + } else { + result.push(obj); + } + }); + + COK.returnToParam(OutParamaterName, result); + break; + } } }; @@ -464,7 +502,8 @@ var ClientSideArrayOp = (function (_super) { Join: 16, Split: 17, Select: 18, - Distinct: 19 + Distinct: 19, + RenameProperty: 20 } diff --git a/CollectionOperationKit/ServerSideArrayOp.cs b/CollectionOperationKit/ServerSideArrayOp.cs index f1c0dd5..8a6434c 100644 --- a/CollectionOperationKit/ServerSideArrayOp.cs +++ b/CollectionOperationKit/ServerSideArrayOp.cs @@ -289,6 +289,58 @@ namespace CollectionOperationKit returnToParam(dataContext, string.Join(seprator, values)); break; } + case SupportedOperations.RenameProperty: + { + // 获取输入数组 + ArrayList data = getArrayListParam(dataContext, this.InParamater); + // 获取要替换的原字段名 + string oldPropertyName = getParamValue(dataContext, this.OperationParamaterAName).ToString(); + // 获取新的字段名 + string newPropertyName = getParamValue(dataContext, this.OperationParamaterBName).ToString(); + + // 创建新的数组来存储修改后的对象 + ArrayList result = new ArrayList(); + + // 遍历数组中的每个对象 + for (int i = 0; i < data.Count; i++) + { + var item = data[i]; + + // 如果是Dictionary类型的对象 + if (item is Dictionary dictItem) + { + // 创建新的Dictionary + var newDict = new Dictionary(); + + // 复制所有属性,如果遇到要替换的字段名则使用新字段名 + foreach (var kvp in dictItem) + { + if (kvp.Key == oldPropertyName) + { + // 使用新字段名 + newDict[newPropertyName] = kvp.Value; + } + else + { + // 保持原字段名 + newDict[kvp.Key] = kvp.Value; + } + } + + result.Add(newDict); + } + else + { + // 对于其他类型的对象,直接添加到结果中(不做修改) + // 因为非Dictionary类型的对象属性名无法动态修改 + result.Add(item); + } + } + + // 返回修改后的数组到OutParamaterName2 + returnToParam2(dataContext, result); + break; + } default: { break; @@ -421,6 +473,10 @@ namespace CollectionOperationKit { return setPropertyVisiblity(propertyName, true, true, false); } + case SupportedOperations.RenameProperty: + { + return setPropertyVisiblity(propertyName, true, true, true); + } default: { return base.GetDesignerPropertyVisible(propertyName, commandScope); @@ -495,7 +551,9 @@ namespace CollectionOperationKit [Description("Select:提取【输入参数】中每个元素里名为【操作参数A】的属性,将其作为一个新的数组返回")] Select, [Description("Distinct:以名为【操作参数A】的属性为基准(留空则直接比较数组元素),将【输入参数】去除空值和重复值后,作为新数组返回")] - Distinct + Distinct, + [Description("RenameProperty:将【输入参数】中所有对象的【操作参数A】字段名修改为【操作参数B】字段名,返回修改后的新数组")] + RenameProperty } public class ObjectComparer : IEqualityComparer -- Gitee