From 297648f1e634900ce4e22498f9c061f670c7321f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Tue, 19 Sep 2017 14:26:46 +0800 Subject: [PATCH] fixed #1063 --- examples/routers/spin.vue | 25 +++++++++++ src/components/modal/mixins-scrollbar.js | 34 +++++++++++++++ src/components/modal/modal.vue | 32 +------------- src/components/spin/index.js | 33 +++++++++++++- src/components/spin/spin.js | 55 ++++++++++++++++++++++++ src/components/spin/spin.vue | 29 ++++++++++++- src/index.js | 1 + src/styles/components/spin.less | 3 ++ src/styles/custom.less | 1 + 9 files changed, 180 insertions(+), 33 deletions(-) create mode 100644 src/components/modal/mixins-scrollbar.js create mode 100644 src/components/spin/spin.js diff --git a/examples/routers/spin.vue b/examples/routers/spin.vue index cc878a46..5500eb3e 100644 --- a/examples/routers/spin.vue +++ b/examples/routers/spin.vue @@ -181,6 +181,8 @@
切换显示状态: + + diff --git a/src/components/modal/mixins-scrollbar.js b/src/components/modal/mixins-scrollbar.js new file mode 100644 index 00000000..1570fb77 --- /dev/null +++ b/src/components/modal/mixins-scrollbar.js @@ -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(); + } + } +}; \ No newline at end of file diff --git a/src/components/modal/modal.vue b/src/components/modal/modal.vue index db4ae39e..1eaa6fa1 100644 --- a/src/components/modal/modal.vue +++ b/src/components/modal/modal.vue @@ -30,15 +30,15 @@ import Icon from '../icon'; import iButton from '../button/button.vue'; import TransferDom from '../../directives/transfer-dom'; - import { getScrollBarSize } from '../../utils/assist'; import Locale from '../../mixins/locale'; import Emitter from '../../mixins/emitter'; + import ScrollbarMixins from './mixins-scrollbar'; const prefixCls = 'ivu-modal'; export default { name: 'Modal', - mixins: [ Locale, Emitter ], + mixins: [ Locale, Emitter, ScrollbarMixins ], components: { Icon, iButton }, directives: { TransferDom }, 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() { this.$emit('on-hidden'); } diff --git a/src/components/spin/index.js b/src/components/spin/index.js index 59e6d667..ffba3c7d 100644 --- a/src/components/spin/index.js +++ b/src/components/spin/index.js @@ -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; \ No newline at end of file diff --git a/src/components/spin/spin.js b/src/components/spin/spin.js new file mode 100644 index 00000000..619a3267 --- /dev/null +++ b/src/components/spin/spin.js @@ -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; \ No newline at end of file diff --git a/src/components/spin/spin.vue b/src/components/spin/spin.vue index 25a619d0..9cb683c2 100644 --- a/src/components/spin/spin.vue +++ b/src/components/spin/spin.vue @@ -1,6 +1,6 @@