directive.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var service = require('./service.js');
  5. var shared = require('@vue/shared');
  6. const INSTANCE_KEY = Symbol("ElLoading");
  7. const createInstance = (el, binding) => {
  8. var _a, _b, _c, _d;
  9. const vm = binding.instance;
  10. const getBindingProp = (key) => shared.isObject(binding.value) ? binding.value[key] : void 0;
  11. const resolveExpression = (key) => {
  12. const data = shared.isString(key) && (vm == null ? void 0 : vm[key]) || key;
  13. if (data)
  14. return vue.ref(data);
  15. else
  16. return data;
  17. };
  18. const getProp = (name) => resolveExpression(getBindingProp(name) || el.getAttribute(`element-loading-${shared.hyphenate(name)}`));
  19. const fullscreen = (_a = getBindingProp("fullscreen")) != null ? _a : binding.modifiers.fullscreen;
  20. const options = {
  21. text: getProp("text"),
  22. svg: getProp("svg"),
  23. svgViewBox: getProp("svgViewBox"),
  24. spinner: getProp("spinner"),
  25. background: getProp("background"),
  26. customClass: getProp("customClass"),
  27. fullscreen,
  28. target: (_b = getBindingProp("target")) != null ? _b : fullscreen ? void 0 : el,
  29. body: (_c = getBindingProp("body")) != null ? _c : binding.modifiers.body,
  30. lock: (_d = getBindingProp("lock")) != null ? _d : binding.modifiers.lock
  31. };
  32. const instance = service["default"](options);
  33. instance._context = vLoading._context;
  34. el[INSTANCE_KEY] = {
  35. options,
  36. instance
  37. };
  38. };
  39. const updateOptions = (newOptions, originalOptions) => {
  40. for (const key of Object.keys(originalOptions)) {
  41. if (vue.isRef(originalOptions[key]))
  42. originalOptions[key].value = newOptions[key];
  43. }
  44. };
  45. const vLoading = {
  46. mounted(el, binding) {
  47. if (binding.value) {
  48. createInstance(el, binding);
  49. }
  50. },
  51. updated(el, binding) {
  52. const instance = el[INSTANCE_KEY];
  53. if (binding.oldValue !== binding.value) {
  54. if (binding.value && !binding.oldValue) {
  55. createInstance(el, binding);
  56. } else if (binding.value && binding.oldValue) {
  57. if (shared.isObject(binding.value))
  58. updateOptions(binding.value, instance.options);
  59. } else {
  60. instance == null ? void 0 : instance.instance.close();
  61. }
  62. }
  63. },
  64. unmounted(el) {
  65. var _a;
  66. (_a = el[INSTANCE_KEY]) == null ? void 0 : _a.instance.close();
  67. el[INSTANCE_KEY] = null;
  68. }
  69. };
  70. vLoading._context = null;
  71. exports["default"] = vLoading;
  72. //# sourceMappingURL=directive.js.map