| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import {storeToRefs, useTabStore} from '@stores';
- import {useSortable} from '@vueuse/integrations/useSortable';
- import {ref} from 'vue';
- import {type Options} from 'sortablejs';
- import ContextMenu from '@imengyu/vue3-context-menu';
- import {useI18n} from 'vue-i18n';
- export function useTabSrotable() {
- const state = useTabStore();
- const {tabList} = storeToRefs(state);
- const tabRef = ref<HTMLUListElement>();
- useSortable(
- tabRef,
- tabList,
- {animation: 150} as Options,
- );
- return {tabRef};
- }
- export function useContextMenu() {
- const tabStore = useTabStore();
- function remove(key: string) {
- tabStore.dispatch({type: 'REMOVE', payload: key});
- }
- const {t} = useI18n();
- function onContextMenu(e: MouseEvent) {
- e.preventDefault();
- const target = e.target as HTMLLIElement;
- const key = target.getAttribute('data-key');
- if (!key || key === '-1') return;
- ContextMenu.showContextMenu({
- x: e.x,
- y: e.y,
- items: [
- {
- label: t('home.contextMenu.close'),
- onClick: remove.bind(null, key),
- },
- {
- label: t('home.contextMenu.closeRight'),
- onClick() {
- tabStore.dispatch({type: 'REMOVE_RIGHT', payload: key});
- },
- },
- {
- label: t('home.contextMenu.closeOther'),
- onClick() {
- tabStore.dispatch({type: 'REMOVE_OTHER', payload: key});
- },
- },
- {
- label: t('home.contextMenu.clear'),
- onClick() {
- tabStore.dispatch({type: 'CLEAR'});
- },
- },
- ],
- });
- }
- return {onContextMenu, remove};
- }
|