request-loading.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import load from "@/utils/loading";
  2. // isLoading
  3. // let times = store.getters.loadCount;
  4. let timer = null;
  5. export async function showFullScreenLoading(store) {
  6. if (store.getters.loadCount === 0 && !store.getters.isLoading) {
  7. await store.dispatch("app/setLoadCount", 1);
  8. await store.dispatch("app/setLoadStatus", true);
  9. load.startLoading();
  10. } else {
  11. if (store.getters.loadCount < 0) {
  12. await store.dispatch("app/resetLoadCount");
  13. await store.dispatch("app/setLoadCount", 1);
  14. clearTimeout(timer);
  15. timer = null;
  16. } else {
  17. await store.dispatch("app/setLoadCount", 1);
  18. clearTimeout(timer);
  19. timer = null;
  20. }
  21. }
  22. }
  23. export async function tryHideFullScreenLoading(store) {
  24. // console.log(store.getters.loadCount)
  25. await store.dispatch("app/setLoadCount", -1);
  26. if (store.getters.loadCount <= 0 && store.getters.isLoading) {
  27. if (timer) return;
  28. timer = setTimeout(async () => {
  29. await store.dispatch("app/resetLoadCount");
  30. await store.dispatch("app/setLoadStatus", false);
  31. load.endLoading();
  32. clearTimeout(timer);
  33. timer = null;
  34. }, 100);
  35. }
  36. }