vue-vben-admin/src/layouts/default/tabs/components/TabContent.vue

71 lines
2.0 KiB
Vue
Raw Normal View History

2020-12-13 22:05:34 +08:00
<template>
<Dropdown :dropMenuList="getDropMenuList" :trigger="getTrigger" @menuEvent="handleMenuEvent">
2021-04-10 19:25:49 +08:00
<div :class="`${prefixCls}__info`" @contextmenu="handleContext" v-if="getIsTabs">
2020-12-13 22:05:34 +08:00
<span class="ml-1">{{ getTitle }}</span>
</div>
2020-12-15 00:13:23 +08:00
<span :class="`${prefixCls}__extra-quick`" v-else @click="handleContext">
2021-02-19 22:15:02 +08:00
<Icon icon="ion:chevron-down" />
2020-12-13 22:05:34 +08:00
</span>
</Dropdown>
</template>
<script lang="ts">
import type { PropType } from 'vue';
2021-04-10 19:25:49 +08:00
import type { RouteLocationNormalized } from 'vue-router';
2020-12-13 22:05:34 +08:00
2021-04-10 19:25:49 +08:00
import { defineComponent, computed, unref } from 'vue';
2020-12-13 22:05:34 +08:00
import { Dropdown } from '/@/components/Dropdown/index';
2021-04-10 19:25:49 +08:00
import { Icon } from '/@/components/Icon';
2020-12-13 22:05:34 +08:00
2021-04-10 19:25:49 +08:00
import { TabContentProps } from '../types';
2020-12-13 22:05:34 +08:00
import { useDesign } from '/@/hooks/web/useDesign';
import { useI18n } from '/@/hooks/web/useI18n';
2021-04-10 19:25:49 +08:00
import { useTabDropdown } from '../useTabDropdown';
2020-12-13 22:05:34 +08:00
export default defineComponent({
name: 'TabContent',
2021-02-19 22:15:02 +08:00
components: { Dropdown, Icon },
2020-12-13 22:05:34 +08:00
props: {
tabItem: {
type: Object as PropType<RouteLocationNormalized>,
default: null,
},
2021-04-10 19:25:49 +08:00
isExtra: Boolean,
2020-12-13 22:05:34 +08:00
},
setup(props) {
const { prefixCls } = useDesign('multiple-tabs-content');
const { t } = useI18n();
const getTitle = computed(() => {
const { tabItem: { meta } = {} } = props;
2021-04-10 19:25:49 +08:00
return meta && t(meta.title as string);
2020-12-13 22:05:34 +08:00
});
2021-04-10 19:25:49 +08:00
const getIsTabs = computed(() => !props.isExtra);
2021-06-17 21:43:53 +08:00
const getTrigger = computed((): ('contextmenu' | 'click' | 'hover')[] =>
2021-08-24 22:41:48 +08:00
unref(getIsTabs) ? ['contextmenu'] : ['click'],
2021-06-17 21:43:53 +08:00
);
2020-12-13 22:05:34 +08:00
2021-04-10 19:25:49 +08:00
const { getDropMenuList, handleMenuEvent, handleContextMenu } = useTabDropdown(
props as TabContentProps,
2021-08-24 22:41:48 +08:00
getIsTabs,
2021-04-10 19:25:49 +08:00
);
function handleContext(e) {
2020-12-13 22:05:34 +08:00
props.tabItem && handleContextMenu(props.tabItem)(e);
}
2021-04-10 19:25:49 +08:00
2020-12-13 22:05:34 +08:00
return {
prefixCls,
getDropMenuList,
handleMenuEvent,
handleContext,
getTrigger,
2021-04-10 19:25:49 +08:00
getIsTabs,
2020-12-13 22:05:34 +08:00
getTitle,
};
},
});
</script>