From d7bef8c4b6a087e1320ec281b6ca7d7332081cfd Mon Sep 17 00:00:00 2001 From: yupeng12 Date: Fri, 14 Jun 2024 09:53:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E6=8D=B7=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor-core/src/util.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 33e7f0737..ac5a3dabb 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -1457,6 +1457,20 @@ export function resolveQuickVariables( const filterVar = filter ? filter(finalVars) : finalVars; + function sortVars(arr: any[]) { + const arrs = [...arr]; + arrs.sort((obj1, obj2) => { + if ('children' in obj1 && !('children' in obj2)) { + return 1; + } else if (!('children' in obj1) && 'children' in obj2) { + return -1; + } else { + return 0; + } + }); + return arrs; + } + if (quickVars?.length) { const vars: VariableItem[] = []; @@ -1477,10 +1491,10 @@ export function resolveQuickVariables( }); } - return vars; + return sortVars(vars); } - return filterVar; + return sortVars(filterVar); } /**