From 67e16872e49878d6819ad588537709aa55734efd Mon Sep 17 00:00:00 2001 From: Hooray Hu <304327508@qq.com> Date: Sat, 6 Jan 2024 11:24:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20HDropdown=20/?= =?UTF-8?q?=20HDropdownMenu=20/=20HTooltip=20=E7=BB=84=E4=BB=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/AppSetting/index.vue | 14 +++++++------- src/layouts/ui-kit/HDropdown.vue | 2 +- src/layouts/ui-kit/HDropdownMenu.vue | 2 +- src/layouts/ui-kit/HTooltip.vue | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/layouts/components/AppSetting/index.vue b/src/layouts/components/AppSetting/index.vue index ef19dc92..89db01ae 100755 --- a/src/layouts/components/AppSetting/index.vue +++ b/src/layouts/components/AppSetting/index.vue @@ -51,20 +51,20 @@ watch(copied, (val) => { } }) -interface AnyObject { - [key: string]: any +function isObject(value: any) { + return typeof value === 'object' && !Array.isArray(value) } // 比较两个对象,并提取出不同的部分 -function getObjectDiff(originalObj: AnyObject, diffObj: AnyObject): AnyObject { - if (typeof originalObj !== 'object' || typeof diffObj !== 'object') { +function getObjectDiff(originalObj: Record, diffObj: Record) { + if (!isObject(originalObj) || !isObject(diffObj)) { return diffObj } - const diff: AnyObject = {} + const diff: Record = {} for (const key in diffObj) { const originalValue = originalObj[key] const diffValue = diffObj[key] - if (originalValue !== diffValue) { - if (typeof originalValue === 'object' && typeof diffValue === 'object') { + if (JSON.stringify(originalValue) !== JSON.stringify(diffValue)) { + if (isObject(originalValue) && isObject(diffValue)) { const nestedDiff = getObjectDiff(originalValue, diffValue) if (Object.keys(nestedDiff).length > 0) { diff[key] = nestedDiff diff --git a/src/layouts/ui-kit/HDropdown.vue b/src/layouts/ui-kit/HDropdown.vue index 9f00c176..3fb4160c 100644 --- a/src/layouts/ui-kit/HDropdown.vue +++ b/src/layouts/ui-kit/HDropdown.vue @@ -1,5 +1,5 @@