mirror of https://github.com/ElemeFE/element
Loading: remove unnecessary inline styles
parent
455850d70c
commit
940b189bbd
|
@ -1,4 +1,5 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
import { addClass, removeClass } from 'wind-dom/src/class';
|
||||||
let Spinner = Vue.extend(require('./spinner.vue'));
|
let Spinner = Vue.extend(require('./spinner.vue'));
|
||||||
|
|
||||||
exports.install = Vue => {
|
exports.install = Vue => {
|
||||||
|
@ -9,14 +10,14 @@ exports.install = Vue => {
|
||||||
el.originalPosition = document.body.style.position;
|
el.originalPosition = document.body.style.position;
|
||||||
el.originalOverflow = document.body.style.overflow;
|
el.originalOverflow = document.body.style.overflow;
|
||||||
|
|
||||||
['top', 'right', 'bottom', 'left'].forEach(property => {
|
addClass(el.mask, 'is-fullscreen');
|
||||||
el.maskStyle[property] = '0';
|
addClass(el.spinner, 'is-fullscreen');
|
||||||
});
|
|
||||||
el.maskStyle.position = 'fixed';
|
|
||||||
el.spinnerStyle.position = 'fixed';
|
|
||||||
|
|
||||||
insertDom(document.body, el, binding);
|
insertDom(document.body, el, binding);
|
||||||
} else {
|
} else {
|
||||||
|
removeClass(el.mask, 'is-fullscreen');
|
||||||
|
removeClass(el.spinner, 'is-fullscreen');
|
||||||
|
|
||||||
if (binding.modifiers.body) {
|
if (binding.modifiers.body) {
|
||||||
el.originalPosition = document.body.style.position;
|
el.originalPosition = document.body.style.position;
|
||||||
|
|
||||||
|
@ -31,11 +32,6 @@ exports.install = Vue => {
|
||||||
insertDom(document.body, el, binding);
|
insertDom(document.body, el, binding);
|
||||||
} else {
|
} else {
|
||||||
el.originalPosition = el.style.position;
|
el.originalPosition = el.style.position;
|
||||||
|
|
||||||
['top', 'right', 'bottom', 'left'].forEach(property => {
|
|
||||||
el.maskStyle[property] = '0';
|
|
||||||
});
|
|
||||||
|
|
||||||
insertDom(el, el, binding);
|
insertDom(el, el, binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,10 +59,6 @@ exports.install = Vue => {
|
||||||
directive.mask.style[property] = directive.maskStyle[property];
|
directive.mask.style[property] = directive.maskStyle[property];
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(directive.spinnerStyle).forEach(property => {
|
|
||||||
directive.spinner.style[property] = directive.spinnerStyle[property];
|
|
||||||
});
|
|
||||||
|
|
||||||
if (directive.originalPosition !== 'absolute') {
|
if (directive.originalPosition !== 'absolute') {
|
||||||
parent.style.position = 'relative';
|
parent.style.position = 'relative';
|
||||||
}
|
}
|
||||||
|
@ -87,12 +79,7 @@ exports.install = Vue => {
|
||||||
bind: function(el, binding) {
|
bind: function(el, binding) {
|
||||||
el.mask = document.createElement('div');
|
el.mask = document.createElement('div');
|
||||||
el.mask.className = 'el-loading-mask';
|
el.mask.className = 'el-loading-mask';
|
||||||
el.maskStyle = {
|
el.maskStyle = {};
|
||||||
position: 'absolute',
|
|
||||||
zIndex: '10000',
|
|
||||||
backgroundColor: 'rgba(255, 255, 255, .9)',
|
|
||||||
margin: '0'
|
|
||||||
};
|
|
||||||
|
|
||||||
let spinner = new Spinner({
|
let spinner = new Spinner({
|
||||||
data: {
|
data: {
|
||||||
|
@ -102,9 +89,6 @@ exports.install = Vue => {
|
||||||
});
|
});
|
||||||
spinner.$mount(el.mask);
|
spinner.$mount(el.mask);
|
||||||
el.spinner = spinner.$el;
|
el.spinner = spinner.$el;
|
||||||
el.spinnerStyle = {
|
|
||||||
position: 'absolute'
|
|
||||||
};
|
|
||||||
toggleLoading(el, binding);
|
toggleLoading(el, binding);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,32 @@
|
||||||
@charset "UTF-8";
|
@charset "UTF-8";
|
||||||
@import "./common/var.css";
|
@import "./common/var.css";
|
||||||
|
|
||||||
.el-loading-spinner {
|
@component-namespace el {
|
||||||
|
@b loading-mask {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10000;
|
||||||
|
background-color: rgba(255, 255, 255, .9);
|
||||||
|
margin: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
@when fullscreen {
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@b loading-spinner {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
margin-top: calc(- var(--loading-spinner-size) / 2);
|
margin-top: calc(- var(--loading-spinner-size) / 2);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
@when fullscreen {
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
|
||||||
.el-loading-text {
|
.el-loading-text {
|
||||||
color: var(--color-primary);
|
color: var(--color-primary);
|
||||||
|
@ -19,11 +40,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.path {
|
.path {
|
||||||
|
animation: dash 1.5s ease-in-out infinite;
|
||||||
stroke-dasharray: 1, 100;
|
stroke-dasharray: 1, 100;
|
||||||
stroke-dashoffset: 0;
|
stroke-dashoffset: 0;
|
||||||
stroke-width: 2;
|
stroke-width: 2;
|
||||||
stroke: var(--color-primary);
|
stroke: var(--color-primary);
|
||||||
animation: dash 1.5s ease-in-out infinite;
|
|
||||||
stroke-linecap: round;
|
stroke-linecap: round;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +55,7 @@
|
||||||
width: var(--loading-fullscreen-spinner-size);
|
width: var(--loading-fullscreen-spinner-size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes rotate {
|
@keyframes rotate {
|
||||||
|
|
|
@ -106,9 +106,7 @@ describe('Loading', () => {
|
||||||
Vue.nextTick(() => {
|
Vue.nextTick(() => {
|
||||||
const mask = document.querySelector('.el-loading-mask');
|
const mask = document.querySelector('.el-loading-mask');
|
||||||
expect(mask.parentNode === document.body).to.true;
|
expect(mask.parentNode === document.body).to.true;
|
||||||
expect(mask.style.left).to.equal('0px');
|
expect(mask.classList.contains('is-fullscreen')).to.true;
|
||||||
expect(mask.style.right).to.equal('0px');
|
|
||||||
expect(mask.style.position).to.equal('fixed');
|
|
||||||
vm.loading = false;
|
vm.loading = false;
|
||||||
document.body.removeChild(mask);
|
document.body.removeChild(mask);
|
||||||
document.body.removeChild(vm.$el);
|
document.body.removeChild(vm.$el);
|
||||||
|
|
Loading…
Reference in New Issue