loading.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var useGlobalConfig = require('../../config-provider/src/hooks/use-global-config.js');
  5. var style = require('../../../utils/dom/style.js');
  6. function createLoadingComponent(options) {
  7. let afterLeaveTimer;
  8. const afterLeaveFlag = vue.ref(false);
  9. const data = vue.reactive({
  10. ...options,
  11. originalPosition: "",
  12. originalOverflow: "",
  13. visible: false
  14. });
  15. function setText(text) {
  16. data.text = text;
  17. }
  18. function destroySelf() {
  19. const target = data.parent;
  20. const ns = vm.ns;
  21. if (!target.vLoadingAddClassList) {
  22. let loadingNumber = target.getAttribute("loading-number");
  23. loadingNumber = Number.parseInt(loadingNumber) - 1;
  24. if (!loadingNumber) {
  25. style.removeClass(target, ns.bm("parent", "relative"));
  26. target.removeAttribute("loading-number");
  27. } else {
  28. target.setAttribute("loading-number", loadingNumber.toString());
  29. }
  30. style.removeClass(target, ns.bm("parent", "hidden"));
  31. }
  32. removeElLoadingChild();
  33. loadingInstance.unmount();
  34. }
  35. function removeElLoadingChild() {
  36. var _a, _b;
  37. (_b = (_a = vm.$el) == null ? void 0 : _a.parentNode) == null ? void 0 : _b.removeChild(vm.$el);
  38. }
  39. function close() {
  40. var _a;
  41. if (options.beforeClose && !options.beforeClose())
  42. return;
  43. afterLeaveFlag.value = true;
  44. clearTimeout(afterLeaveTimer);
  45. afterLeaveTimer = setTimeout(handleAfterLeave, 400);
  46. data.visible = false;
  47. (_a = options.closed) == null ? void 0 : _a.call(options);
  48. }
  49. function handleAfterLeave() {
  50. if (!afterLeaveFlag.value)
  51. return;
  52. const target = data.parent;
  53. afterLeaveFlag.value = false;
  54. target.vLoadingAddClassList = void 0;
  55. destroySelf();
  56. }
  57. const elLoadingComponent = vue.defineComponent({
  58. name: "ElLoading",
  59. setup(_, { expose }) {
  60. const { ns, zIndex } = useGlobalConfig.useGlobalComponentSettings("loading");
  61. expose({
  62. ns,
  63. zIndex
  64. });
  65. return () => {
  66. const svg = data.spinner || data.svg;
  67. const spinner = vue.h("svg", {
  68. class: "circular",
  69. viewBox: data.svgViewBox ? data.svgViewBox : "0 0 50 50",
  70. ...svg ? { innerHTML: svg } : {}
  71. }, [
  72. vue.h("circle", {
  73. class: "path",
  74. cx: "25",
  75. cy: "25",
  76. r: "20",
  77. fill: "none"
  78. })
  79. ]);
  80. const spinnerText = data.text ? vue.h("p", { class: ns.b("text") }, [data.text]) : void 0;
  81. return vue.h(vue.Transition, {
  82. name: ns.b("fade"),
  83. onAfterLeave: handleAfterLeave
  84. }, {
  85. default: vue.withCtx(() => [
  86. vue.withDirectives(vue.createVNode("div", {
  87. style: {
  88. backgroundColor: data.background || ""
  89. },
  90. class: [
  91. ns.b("mask"),
  92. data.customClass,
  93. data.fullscreen ? "is-fullscreen" : ""
  94. ]
  95. }, [
  96. vue.h("div", {
  97. class: ns.b("spinner")
  98. }, [spinner, spinnerText])
  99. ]), [[vue.vShow, data.visible]])
  100. ])
  101. });
  102. };
  103. }
  104. });
  105. const loadingInstance = vue.createApp(elLoadingComponent);
  106. const vm = loadingInstance.mount(document.createElement("div"));
  107. return {
  108. ...vue.toRefs(data),
  109. setText,
  110. removeElLoadingChild,
  111. close,
  112. handleAfterLeave,
  113. vm,
  114. get $el() {
  115. return vm.$el;
  116. }
  117. };
  118. }
  119. exports.createLoadingComponent = createLoadingComponent;
  120. //# sourceMappingURL=loading.js.map