index.js 874 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Loading from './Loading'
  2. import { mount } from '../../utils/componentHelper'
  3. const seat = 1
  4. const closeStack = []
  5. Loading.use = function use(app) {
  6. Loading.show = function (config) {
  7. if (closeStack.length) {
  8. closeStack.push(seat)
  9. } else {
  10. const { destroy } = mount(Loading, {
  11. app,
  12. props: { ...config },
  13. })
  14. closeStack.push(destroy)
  15. }
  16. }
  17. Loading.hide = function () {
  18. if (closeStack.length) {
  19. const close = closeStack.pop()
  20. if (close !== seat) {
  21. close()
  22. }
  23. }
  24. }
  25. Loading.hideAll = function () {
  26. for (const close of closeStack) {
  27. if (close !== seat) {
  28. close()
  29. }
  30. }
  31. closeStack.length = 0
  32. }
  33. }
  34. export default Loading