admin-vben/packages/@vben-core/shared/toolkit/src/nprogress.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-05-19 13:20:42 +00:00
import type NProgress from 'nprogress';
// 创建一个NProgress实例的变量初始值为null
let nProgressInstance: null | typeof NProgress = null;
/**
* NProgress
* NProgressNProgress
* NProgressNProgress
*
* @returns NProgressPromise
*/
async function loadNprogress() {
if (nProgressInstance) {
return nProgressInstance;
}
nProgressInstance = await import('nprogress');
nProgressInstance.configure({
showSpinner: true,
speed: 300,
});
return nProgressInstance;
}
/**
*
* NProgressNProgressstart
*/
async function startProgress() {
const nprogress = await loadNprogress();
nprogress?.start();
}
/**
*
* NProgressNProgressdone
*/
async function stopProgress() {
const nprogress = await loadNprogress();
nprogress?.done();
}
export { startProgress, stopProgress };