fix: fix bug
This commit is contained in:
parent
72e2ef5f55
commit
327522f2b7
|
@ -1,8 +1,10 @@
|
||||||
import ContextMenu from './src/ContextMenu.vue'
|
import ContextMenu from './src/ContextMenu.vue'
|
||||||
import { ElDropdown } from 'element-plus'
|
import { ElDropdown } from 'element-plus'
|
||||||
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||||
|
|
||||||
export interface ContextMenuExpose {
|
export interface ContextMenuExpose {
|
||||||
elDropdownMenuRef: ComponentRef<typeof ElDropdown>
|
elDropdownMenuRef: ComponentRef<typeof ElDropdown>
|
||||||
|
tagItem: RouteLocationNormalizedLoaded
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ContextMenu }
|
export { ContextMenu }
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus'
|
import { ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus'
|
||||||
import { PropType, ref, unref } from 'vue'
|
import { PropType, ref } from 'vue'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ const { t } = useI18n()
|
||||||
|
|
||||||
const emit = defineEmits(['visibleChange'])
|
const emit = defineEmits(['visibleChange'])
|
||||||
|
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
schema: {
|
schema: {
|
||||||
type: Array as PropType<contextMenuSchema[]>,
|
type: Array as PropType<contextMenuSchema[]>,
|
||||||
default: () => []
|
default: () => []
|
||||||
|
@ -20,6 +21,10 @@ defineProps({
|
||||||
trigger: {
|
trigger: {
|
||||||
type: String as PropType<'click' | 'hover' | 'focus' | 'contextmenu'>,
|
type: String as PropType<'click' | 'hover' | 'focus' | 'contextmenu'>,
|
||||||
default: 'contextmenu'
|
default: 'contextmenu'
|
||||||
|
},
|
||||||
|
tagItem: {
|
||||||
|
type: Object as PropType<RouteLocationNormalizedLoaded>,
|
||||||
|
default: () => ({})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -28,13 +33,14 @@ const command = (item: contextMenuSchema) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const visibleChange = (visible: boolean) => {
|
const visibleChange = (visible: boolean) => {
|
||||||
emit('visibleChange', visible, unref(elDropdownMenuRef))
|
emit('visibleChange', visible, props.tagItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
const elDropdownMenuRef = ref<ComponentRef<typeof ElDropdown>>()
|
const elDropdownMenuRef = ref<ComponentRef<typeof ElDropdown>>()
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
elDropdownMenuRef
|
elDropdownMenuRef,
|
||||||
|
tagItem: props.tagItem
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -205,15 +205,11 @@ const isActive = (route: RouteLocationNormalizedLoaded): boolean => {
|
||||||
const itemRefs = useTemplateRefsList<ComponentRef<typeof ContextMenu & ContextMenuExpose>>()
|
const itemRefs = useTemplateRefsList<ComponentRef<typeof ContextMenu & ContextMenuExpose>>()
|
||||||
|
|
||||||
// 右键菜单装填改变的时候
|
// 右键菜单装填改变的时候
|
||||||
const visibleChange = (
|
const visibleChange = (visible: boolean, tagItem: RouteLocationNormalizedLoaded) => {
|
||||||
visible: boolean,
|
|
||||||
ref: ComponentRef<typeof ContextMenu & ContextMenuExpose>
|
|
||||||
) => {
|
|
||||||
const uid = ref.$el['__vueParentComponent'].uid
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
for (const v of unref(itemRefs)) {
|
for (const v of unref(itemRefs)) {
|
||||||
const elDropdownMenuRef = v.elDropdownMenuRef
|
const elDropdownMenuRef = v.elDropdownMenuRef
|
||||||
if (uid !== elDropdownMenuRef?.$el['__vueParentComponent'].uid) {
|
if (tagItem.fullPath !== v.tagItem.fullPath) {
|
||||||
elDropdownMenuRef?.handleClose()
|
elDropdownMenuRef?.handleClose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,6 +326,7 @@ watch(
|
||||||
]"
|
]"
|
||||||
v-for="item in visitedViews"
|
v-for="item in visitedViews"
|
||||||
:key="item.fullPath"
|
:key="item.fullPath"
|
||||||
|
:tag-item="item"
|
||||||
:class="[
|
:class="[
|
||||||
`${prefixCls}__item`,
|
`${prefixCls}__item`,
|
||||||
item?.meta?.affix ? `${prefixCls}__item--affix` : '',
|
item?.meta?.affix ? `${prefixCls}__item--affix` : '',
|
||||||
|
|
Loading…
Reference in New Issue