import { ElLoading } from "element-plus";
import { notOpenUrls } from "./config";

let loading: ReturnType<typeof ElLoading.service> | null;

export const openLoading = (url?: string) => {
  if (loading || (url && ~notOpenUrls.indexOf(url))) return;

  loading = ElLoading.service({
    lock: true,
    text: "加载中",
    background: "rgba(255, 255, 255, 0.4)",
  });
};

export const closeLoading = () => {
  if (loading) {
    loading.close();
    loading = null;
  }
};
