import { ref } from 'vue' /** * @param callback 组件关闭时的回调 * @returns */ export function useComponent(callback?: () => void) { // 组件名 const componentId = ref(); /** * 打开组件 * @param componentName */ const openComponent = (componentName: keyof T) => { if (componentName) { console.log('打开组件:' + componentName.toString()); componentId.value = componentName; } else { console.error('无效的组件名'); } } /** * 关闭组件 * @param isCallback */ const closeComponent = (isCallback?: boolean) => { console.log('关闭组件:' + componentId.value?.toString()); componentId.value = undefined; // 是否刷新数据 if (isCallback && callback) { callback(); } } return { componentId, openComponent, closeComponent, } }