Skip to content

Commit

Permalink
fix: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyihui committed Apr 12, 2022
1 parent 72e2ef5 commit 327522f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/components/ContextMenu/index.ts
@@ -1,8 +1,10 @@
import ContextMenu from './src/ContextMenu.vue'
import { ElDropdown } from 'element-plus'
import type { RouteLocationNormalizedLoaded } from 'vue-router'

export interface ContextMenuExpose {
elDropdownMenuRef: ComponentRef<typeof ElDropdown>
tagItem: RouteLocationNormalizedLoaded
}

export { ContextMenu }
14 changes: 10 additions & 4 deletions src/components/ContextMenu/src/ContextMenu.vue
@@ -1,8 +1,9 @@
<script setup lang="ts">
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 { useDesign } from '@/hooks/web/useDesign'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
const { getPrefixCls } = useDesign()
Expand All @@ -12,14 +13,18 @@ const { t } = useI18n()
const emit = defineEmits(['visibleChange'])
defineProps({
const props = defineProps({
schema: {
type: Array as PropType<contextMenuSchema[]>,
default: () => []
},
trigger: {
type: String as PropType<'click' | 'hover' | 'focus' | 'contextmenu'>,
default: 'contextmenu'
},
tagItem: {
type: Object as PropType<RouteLocationNormalizedLoaded>,
default: () => ({})
}
})
Expand All @@ -28,13 +33,14 @@ const command = (item: contextMenuSchema) => {
}
const visibleChange = (visible: boolean) => {
emit('visibleChange', visible, unref(elDropdownMenuRef))
emit('visibleChange', visible, props.tagItem)
}
const elDropdownMenuRef = ref<ComponentRef<typeof ElDropdown>>()
defineExpose({
elDropdownMenuRef
elDropdownMenuRef,
tagItem: props.tagItem
})
</script>

Expand Down
9 changes: 3 additions & 6 deletions src/components/TagsView/src/TagsView.vue
Expand Up @@ -205,15 +205,11 @@ const isActive = (route: RouteLocationNormalizedLoaded): boolean => {
const itemRefs = useTemplateRefsList<ComponentRef<typeof ContextMenu & ContextMenuExpose>>()
// 右键菜单装填改变的时候
const visibleChange = (
visible: boolean,
ref: ComponentRef<typeof ContextMenu & ContextMenuExpose>
) => {
const uid = ref.$el['__vueParentComponent'].uid
const visibleChange = (visible: boolean, tagItem: RouteLocationNormalizedLoaded) => {
if (visible) {
for (const v of unref(itemRefs)) {
const elDropdownMenuRef = v.elDropdownMenuRef
if (uid !== elDropdownMenuRef?.$el['__vueParentComponent'].uid) {
if (tagItem.fullPath !== v.tagItem.fullPath) {
elDropdownMenuRef?.handleClose()
}
}
Expand Down Expand Up @@ -330,6 +326,7 @@ watch(
]"
v-for="item in visitedViews"
:key="item.fullPath"
:tag-item="item"
:class="[
`${prefixCls}__item`,
item?.meta?.affix ? `${prefixCls}__item--affix` : '',
Expand Down

0 comments on commit 327522f

Please sign in to comment.