mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-06 18:24:07 +08:00
refactor: 优化 HDropdown / HDropdownMenu / HTooltip 组件触发隐藏逻辑
This commit is contained in:
@@ -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<string, any>, diffObj: Record<string, any>) {
|
||||
if (!isObject(originalObj) || !isObject(diffObj)) {
|
||||
return diffObj
|
||||
}
|
||||
const diff: AnyObject = {}
|
||||
const diff: Record<string, any> = {}
|
||||
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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VDropdown :triggers="['hover']" :popper-triggers="['hover']" :delay="200" v-bind="$attrs">
|
||||
<VDropdown :show-triggers="['hover']" :hide-triggers="['hover']" :auto-hide="false" :popper-triggers="['hover']" :delay="200" v-bind="$attrs">
|
||||
<slot />
|
||||
<template #popper>
|
||||
<slot name="dropdown" />
|
||||
|
||||
@@ -16,7 +16,7 @@ const myItems = computed(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VMenu :delay="200" v-bind="$attrs">
|
||||
<VMenu :show-triggers="['hover']" :auto-hide="false" :popper-triggers="['hover', 'click']" :delay="200" v-bind="$attrs">
|
||||
<slot />
|
||||
<template #popper>
|
||||
<div v-for="(item, index) in myItems" :key="index" class="p-1" border-b="~ solid stone-2 dark:stone-7 last:size-0">
|
||||
|
||||
@@ -10,7 +10,7 @@ withDefaults(
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VTooltip v-bind="$attrs">
|
||||
<VTooltip :popper-triggers="['hover']" v-bind="$attrs">
|
||||
<slot />
|
||||
<template #popper>
|
||||
<slot name="text">
|
||||
|
||||
Reference in New Issue
Block a user