Sfoglia il codice sorgente

LoadingL optimize the close process (#6966)

* Remove useless parameters

* Remove useless parameters

* [Tree docs] Modify typos

* [Loading] Optimize the close process

* Optimize the close process

* Revert the yarn.lock

* Update yarn.lock
Hejx 心流 8 anni fa
parent
commit
8fc973c51a

+ 1 - 1
examples/docs/zh-CN/tree.md

@@ -855,7 +855,7 @@
 | --------------------- | ---------------------------------------- | --------------------------- | ---- | ----- |
 | data                  | 展示数据                                     | array                       | —    | —     |
 | empty-text            | 内容为空的时候展示的文本                             | String                      | —    | —     |
-| node-key              | 每个树节点用来作为唯一标识的属性,整树应该是唯一的               | String                      | —    | —     |
+| node-key              | 每个树节点用来作为唯一标识的属性,整树应该是唯一的               | String                      | —    | —     |
 | props                 | 配置选项,具体看下表                               | object                      | —    | —     |
 | load                  | 加载子树数据的方法                                | function(node, resolve)     | —    | —     |
 | render-content        | 树节点的内容区的渲染 Function                      | Function(h, { node }        | —    | —     |

+ 11 - 11
packages/loading/src/index.js

@@ -19,21 +19,21 @@ LoadingConstructor.prototype.originalPosition = '';
 LoadingConstructor.prototype.originalOverflow = '';
 
 LoadingConstructor.prototype.close = function() {
-  if (this.fullscreen && this.originalOverflow !== 'hidden') {
-    document.body.style.overflow = this.originalOverflow;
-  }
-  if (this.fullscreen || this.body) {
-    document.body.style.position = this.originalPosition;
-  } else {
-    this.target.style.position = this.originalPosition;
-  }
   if (this.fullscreen) {
     fullscreenLoading = undefined;
   }
   this.$on('after-leave', _ => {
-    this.$el &&
-    this.$el.parentNode &&
-    this.$el.parentNode.removeChild(this.$el);
+    if (this.fullscreen && this.originalOverflow !== 'hidden') {
+      document.body.style.overflow = this.originalOverflow;
+    }
+    if (this.fullscreen || this.body) {
+      document.body.style.position = this.originalPosition;
+    } else {
+      this.target.style.position = this.originalPosition;
+    }
+    if (this.$el && this.$el.parentNode) {
+      this.$el.parentNode.removeChild(this.$el);
+    }
     this.$destroy();
   });
   this.visible = false;

+ 8 - 2
test/unit/specs/loading.spec.js

@@ -184,7 +184,7 @@ describe('Loading', () => {
       expect(loadingInstance.visible).to.false;
     });
 
-    it('target', () => {
+    it('target', done => {
       vm = createVue({
         template: `
         <div class="loading-container"></div>
@@ -192,8 +192,14 @@ describe('Loading', () => {
       }, true);
       loadingInstance = Loading({ target: '.loading-container' });
       let mask = document.querySelector('.el-loading-mask');
+      let container = document.querySelector('.loading-container');
       expect(mask).to.exist;
-      expect(mask.parentNode).to.equal(document.querySelector('.loading-container'));
+      expect(mask.parentNode).to.equal(container);
+      loadingInstance.close();
+      setTimeout(() => {
+        expect(container.style.position).to.equal('relative');
+        done();
+      }, 200);
     });
 
     it('body', () => {