mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-08 11:27:30 -08:00
46 lines
940 B
TypeScript
46 lines
940 B
TypeScript
|
import { ref } from 'vue';
|
||
|
import { useI18n } from '@/composables/useI18n';
|
||
|
import { Loading } from 'element-ui';
|
||
|
|
||
|
interface LoadingService {
|
||
|
text: string;
|
||
|
close: () => void;
|
||
|
}
|
||
|
|
||
|
export function useLoadingService() {
|
||
|
const { i18n } = useI18n();
|
||
|
const loadingService = ref<LoadingService | null>(null);
|
||
|
|
||
|
function startLoading(text?: string) {
|
||
|
if (loadingService.value !== null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
loadingService.value = Loading.service({
|
||
|
lock: true,
|
||
|
text: text || i18n.baseText('genericHelpers.loading'),
|
||
|
spinner: 'el-icon-loading',
|
||
|
background: 'rgba(255, 255, 255, 0.8)',
|
||
|
}) as unknown as LoadingService;
|
||
|
}
|
||
|
|
||
|
function setLoadingText(text: string) {
|
||
|
if (loadingService.value) {
|
||
|
loadingService.value.text = text;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function stopLoading() {
|
||
|
if (loadingService.value) {
|
||
|
loadingService.value.close();
|
||
|
loadingService.value = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
startLoading,
|
||
|
setLoadingText,
|
||
|
stopLoading,
|
||
|
};
|
||
|
}
|