提交 6ec04ae4 编写于 作者: zhujiamin's avatar zhujiamin

新增loading组件

上级 0a491402
.cover{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0);
z-index: 9999;
.loading{
position: absolute;
top: 50%;
left: 43%;
transform:translateY(-50%);
width: 150px;
height: 15px;
}
.loading span{
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
border-radius: 50%;
background: #3be8b0;
-webkit-animation: load 1.04s ease infinite;
}
.loading span:nth-child(2){
background: #1aafd0;
}
.loading span:nth-child(3){
background: #6a67ce;
}
.loading span:nth-child(4){
background: #ffb900;
}
.loading span:last-child{
margin-right: 0px;
}
@-webkit-keyframes load{
0%{
opacity: 1;
transform: scale(1);
}
50%{
transform: scale(0);
}
75%{
transform: scale(0.5);
}
100%{
opacity: 0.5;
transform: scale(1);
}
}
.loading span:nth-child(1){
-webkit-animation-delay:0.13s;
}
.loading span:nth-child(2){
-webkit-animation-delay:0.26s;
}
.loading span:nth-child(3){
-webkit-animation-delay:0.39s;
}
.loading span:nth-child(4){
-webkit-animation-delay:0.52s;
}
}
\ No newline at end of file
<template>
<div class="cover">
<div class="loading">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</template>
<script lang="ts">
import {
Vue,
Component,
Prop,
Provide,
Emit,
Watch
} from "vue-property-decorator";
@Component({
components: {}
})
export default class AppLoading extends Vue{
}
</script>
<style lang="less">
@import "./app-loading.less";
</style>
import i18n from '@/locale'; import i18n from '@/locale';
import Vue from 'vue';
import AppLoading from "./app-loading.vue";
/** /**
* 全局加载动画工具类 * 全局加载动画工具类
* *
...@@ -17,47 +18,55 @@ export class Loading { ...@@ -17,47 +18,55 @@ export class Loading {
protected static loadingCount: number = 0; protected static loadingCount: number = 0;
/** /**
* 加载对象 * vue 实例
* *
* @private * @private
* @static * @type {Vue}
* @type {*}
* @memberof Loading * @memberof Loading
*/ */
private static loading: any = null; private static vueExample?: Vue;
/** /**
* 显示加载动画 * 显示加载动画
* *
* @static * @static
* @param {(any | string)} [message]
* @memberof Loading * @memberof Loading
*/ */
public static show(message?: any | string): void { public static show(): void {
if (this.loadingCount === 0) { if (this.loadingCount === 0) {
this.loading = document.createElement('ion-loading'); let component = AppLoading;
this.loading.message = message ? message : i18n.t('app.loadding');; let vm: any = new Vue({
document.body.appendChild(this.loading); i18n: i18n,
this.loading.present(); render(h) {
return h(component);
},
}).$mount();
this.vueExample = vm;
let app = document.getElementById("app");
if(app){
app.appendChild(vm.$el);
} }
this.loadingCount++; }
} this.loadingCount++;
}
/** /**
* 隐藏加载动画 * 隐藏加载动画
* *
* @memberof DragDesignBase * @memberof DragDesignBase
*/ */
public static hidden(): void { public static hidden(): void {
this.loadingCount--; this.loadingCount--;
if (this.loadingCount < 0) { if (this.loadingCount < 0) {
this.loadingCount = 0; this.loadingCount = 0;
} }
if (this.loadingCount === 0) { if (this.loadingCount === 0) {
if (this.loading) { let app = document.getElementById("app");
this.loading.dismiss(); if(app){
this.loading = null; if(this.vueExample){
} app.removeChild(this.vueExample.$el);
} }
} }
}
}
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册