fixed #1063
This commit is contained in:
parent
300bd6623e
commit
297648f1e6
9 changed files with 180 additions and 33 deletions
|
@ -181,6 +181,8 @@
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
切换显示状态:<i-switch @on-change="spinShow = !spinShow"></i-switch>
|
切换显示状态:<i-switch @on-change="spinShow = !spinShow"></i-switch>
|
||||||
|
<Button @click="show">show</Button>
|
||||||
|
<Button @click="hide">hide</Button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
@ -189,6 +191,29 @@
|
||||||
return {
|
return {
|
||||||
spinShow: true
|
spinShow: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
show () {
|
||||||
|
this.$Spin.show({
|
||||||
|
render: (h) => {
|
||||||
|
return h('div', [
|
||||||
|
h('Icon', {
|
||||||
|
props: {
|
||||||
|
type: 'load-c',
|
||||||
|
size: 24
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
h('div', 'Loading')
|
||||||
|
])
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$Spin.hide();
|
||||||
|
}, 3000)
|
||||||
|
},
|
||||||
|
hide () {
|
||||||
|
this.$Spin.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
34
src/components/modal/mixins-scrollbar.js
Normal file
34
src/components/modal/mixins-scrollbar.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// used for Modal & $Spin
|
||||||
|
import { getScrollBarSize } from '../../utils/assist';
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
checkScrollBar () {
|
||||||
|
let fullWindowWidth = window.innerWidth;
|
||||||
|
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
|
||||||
|
const documentElementRect = document.documentElement.getBoundingClientRect();
|
||||||
|
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
|
||||||
|
}
|
||||||
|
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
|
||||||
|
if (this.bodyIsOverflowing) {
|
||||||
|
this.scrollBarWidth = getScrollBarSize();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setScrollBar () {
|
||||||
|
if (this.bodyIsOverflowing && this.scrollBarWidth !== undefined) {
|
||||||
|
document.body.style.paddingRight = `${this.scrollBarWidth}px`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetScrollBar () {
|
||||||
|
document.body.style.paddingRight = '';
|
||||||
|
},
|
||||||
|
addScrollEffect () {
|
||||||
|
this.checkScrollBar();
|
||||||
|
this.setScrollBar();
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
},
|
||||||
|
removeScrollEffect() {
|
||||||
|
document.body.style.overflow = '';
|
||||||
|
this.resetScrollBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -30,15 +30,15 @@
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import iButton from '../button/button.vue';
|
import iButton from '../button/button.vue';
|
||||||
import TransferDom from '../../directives/transfer-dom';
|
import TransferDom from '../../directives/transfer-dom';
|
||||||
import { getScrollBarSize } from '../../utils/assist';
|
|
||||||
import Locale from '../../mixins/locale';
|
import Locale from '../../mixins/locale';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
|
import ScrollbarMixins from './mixins-scrollbar';
|
||||||
|
|
||||||
const prefixCls = 'ivu-modal';
|
const prefixCls = 'ivu-modal';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Modal',
|
name: 'Modal',
|
||||||
mixins: [ Locale, Emitter ],
|
mixins: [ Locale, Emitter, ScrollbarMixins ],
|
||||||
components: { Icon, iButton },
|
components: { Icon, iButton },
|
||||||
directives: { TransferDom },
|
directives: { TransferDom },
|
||||||
props: {
|
props: {
|
||||||
|
@ -186,34 +186,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkScrollBar () {
|
|
||||||
let fullWindowWidth = window.innerWidth;
|
|
||||||
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
|
|
||||||
const documentElementRect = document.documentElement.getBoundingClientRect();
|
|
||||||
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
|
|
||||||
}
|
|
||||||
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
|
|
||||||
if (this.bodyIsOverflowing) {
|
|
||||||
this.scrollBarWidth = getScrollBarSize();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setScrollBar () {
|
|
||||||
if (this.bodyIsOverflowing && this.scrollBarWidth !== undefined) {
|
|
||||||
document.body.style.paddingRight = `${this.scrollBarWidth}px`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
resetScrollBar () {
|
|
||||||
document.body.style.paddingRight = '';
|
|
||||||
},
|
|
||||||
addScrollEffect () {
|
|
||||||
this.checkScrollBar();
|
|
||||||
this.setScrollBar();
|
|
||||||
document.body.style.overflow = 'hidden';
|
|
||||||
},
|
|
||||||
removeScrollEffect() {
|
|
||||||
document.body.style.overflow = '';
|
|
||||||
this.resetScrollBar();
|
|
||||||
},
|
|
||||||
animationFinish() {
|
animationFinish() {
|
||||||
this.$emit('on-hidden');
|
this.$emit('on-hidden');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,33 @@
|
||||||
import Spin from './spin.vue';
|
import Spin from './spin.js';
|
||||||
|
|
||||||
|
let spinInstance;
|
||||||
|
|
||||||
|
function getSpinInstance (render = undefined) {
|
||||||
|
spinInstance = spinInstance || Spin.newInstance({
|
||||||
|
render: render
|
||||||
|
});
|
||||||
|
|
||||||
|
return spinInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loading (options) {
|
||||||
|
const render = ('render' in options) ? options.render : undefined;
|
||||||
|
let instance = getSpinInstance(render);
|
||||||
|
|
||||||
|
instance.show(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
Spin.show = function (props = {}) {
|
||||||
|
return loading(props);
|
||||||
|
};
|
||||||
|
Spin.hide = function () {
|
||||||
|
if (!spinInstance) return false;
|
||||||
|
|
||||||
|
const instance = getSpinInstance();
|
||||||
|
|
||||||
|
instance.remove(() => {
|
||||||
|
spinInstance = null;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default Spin;
|
export default Spin;
|
55
src/components/spin/spin.js
Normal file
55
src/components/spin/spin.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import Vue from 'vue';
|
||||||
|
import Spin from './spin.vue';
|
||||||
|
|
||||||
|
Spin.newInstance = properties => {
|
||||||
|
const _props = properties || {};
|
||||||
|
|
||||||
|
const Instance = new Vue({
|
||||||
|
data: Object.assign({}, _props, {
|
||||||
|
|
||||||
|
}),
|
||||||
|
render (h) {
|
||||||
|
let vnode = '';
|
||||||
|
if (this.render) {
|
||||||
|
vnode = h(Spin, {
|
||||||
|
props: {
|
||||||
|
fix: true,
|
||||||
|
fullscreen: true
|
||||||
|
}
|
||||||
|
}, [this.render(h)]);
|
||||||
|
} else {
|
||||||
|
vnode = h(Spin, {
|
||||||
|
props: {
|
||||||
|
size: 'large',
|
||||||
|
fix: true,
|
||||||
|
fullscreen: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return h('div', {
|
||||||
|
'class': 'ivu-spin-fullscreen'
|
||||||
|
}, [vnode]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const component = Instance.$mount();
|
||||||
|
document.body.appendChild(component.$el);
|
||||||
|
const spin = Instance.$children[0];
|
||||||
|
|
||||||
|
return {
|
||||||
|
show () {
|
||||||
|
spin.visible = true;
|
||||||
|
},
|
||||||
|
remove (cb) {
|
||||||
|
spin.visible = false;
|
||||||
|
setTimeout(function() {
|
||||||
|
spin.$parent.$destroy();
|
||||||
|
document.body.removeChild(document.getElementsByClassName('ivu-spin-fullscreen')[0]);
|
||||||
|
cb();
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
component: spin
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Spin;
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<transition name="fade">
|
<transition name="fade">
|
||||||
<div :class="classes">
|
<div :class="classes" v-if="fullscreenVisible">
|
||||||
<div :class="mainClasses">
|
<div :class="mainClasses">
|
||||||
<span :class="dotClasses"></span>
|
<span :class="dotClasses"></span>
|
||||||
<div :class="textClasses"><slot></slot></div>
|
<div :class="textClasses"><slot></slot></div>
|
||||||
|
@ -10,11 +10,13 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { oneOf } from '../../utils/assist';
|
import { oneOf } from '../../utils/assist';
|
||||||
|
import ScrollbarMixins from '../modal/mixins-scrollbar';
|
||||||
|
|
||||||
const prefixCls = 'ivu-spin';
|
const prefixCls = 'ivu-spin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Spin',
|
name: 'Spin',
|
||||||
|
mixins: [ ScrollbarMixins ],
|
||||||
props: {
|
props: {
|
||||||
size: {
|
size: {
|
||||||
validator (value) {
|
validator (value) {
|
||||||
|
@ -24,11 +26,17 @@
|
||||||
fix: {
|
fix: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
fullscreen: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
showText: false
|
showText: false,
|
||||||
|
// used for $Spin
|
||||||
|
visible: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -39,6 +47,7 @@
|
||||||
[`${prefixCls}-${this.size}`]: !!this.size,
|
[`${prefixCls}-${this.size}`]: !!this.size,
|
||||||
[`${prefixCls}-fix`]: this.fix,
|
[`${prefixCls}-fix`]: this.fix,
|
||||||
[`${prefixCls}-show-text`]: this.showText,
|
[`${prefixCls}-show-text`]: this.showText,
|
||||||
|
[`${prefixCls}-fullscreen`]: this.fullscreen
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
@ -50,6 +59,22 @@
|
||||||
},
|
},
|
||||||
textClasses () {
|
textClasses () {
|
||||||
return `${prefixCls}-text`;
|
return `${prefixCls}-text`;
|
||||||
|
},
|
||||||
|
fullscreenVisible () {
|
||||||
|
if (this.fullscreen) {
|
||||||
|
return this.visible;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible (val) {
|
||||||
|
if (val) {
|
||||||
|
this.addScrollEffect();
|
||||||
|
} else {
|
||||||
|
this.removeScrollEffect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
|
|
@ -139,6 +139,7 @@ const install = function (Vue, opts = {}) {
|
||||||
Vue.prototype.$Message = Message;
|
Vue.prototype.$Message = Message;
|
||||||
Vue.prototype.$Modal = Modal;
|
Vue.prototype.$Modal = Modal;
|
||||||
Vue.prototype.$Notice = Notice;
|
Vue.prototype.$Notice = Notice;
|
||||||
|
Vue.prototype.$Spin = Spin;
|
||||||
};
|
};
|
||||||
|
|
||||||
// auto install
|
// auto install
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
.square(100%);
|
.square(100%);
|
||||||
background-color: rgba(255,255,255,.9);
|
background-color: rgba(255,255,255,.9);
|
||||||
}
|
}
|
||||||
|
&-fullscreen{
|
||||||
|
z-index: @zindex-spin-fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
&-fix &-main {
|
&-fix &-main {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
@ -149,6 +149,7 @@
|
||||||
@zindex-tooltip : 1060;
|
@zindex-tooltip : 1060;
|
||||||
@zindex-transfer : 1060;
|
@zindex-transfer : 1060;
|
||||||
@zindex-loading-bar : 2000;
|
@zindex-loading-bar : 2000;
|
||||||
|
@zindex-spin-fullscreen : 2010;
|
||||||
|
|
||||||
// Animation
|
// Animation
|
||||||
@animation-time : .3s;
|
@animation-time : .3s;
|
||||||
|
|
Loading…
Add table
Reference in a new issue