Loading.vue 1.8 KB
Newer Older
V
vben 已提交
1
<template>
2 3 4 5 6 7
  <section
    class="full-loading"
    :class="{ absolute, [theme]: !!theme }"
    :style="[background ? `background-color: ${background}` : '']"
    v-show="loading"
  >
V
vben 已提交
8 9 10 11
    <Spin v-bind="$attrs" :tip="tip" :size="size" :spinning="loading" />
  </section>
</template>
<script lang="ts">
V
Vben 已提交
12
  import { PropType } from 'vue';
V
vben 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  import { defineComponent } from 'vue';
  import { Spin } from 'ant-design-vue';
  import { SizeEnum } from '/@/enums/sizeEnum';

  export default defineComponent({
    name: 'Loading',
    components: { Spin },
    props: {
      tip: {
        type: String as PropType<string>,
        default: '',
      },
      size: {
        type: String as PropType<SizeEnum>,
        default: SizeEnum.LARGE,
        validator: (v: SizeEnum): boolean => {
          return [SizeEnum.DEFAULT, SizeEnum.SMALL, SizeEnum.LARGE].includes(v);
        },
      },
      absolute: {
        type: Boolean as PropType<boolean>,
        default: false,
      },
      loading: {
        type: Boolean as PropType<boolean>,
        default: false,
      },
      background: {
        type: String as PropType<string>,
      },
43 44 45
      theme: {
        type: String as PropType<'dark' | 'light'>,
      },
V
vben 已提交
46 47 48 49 50
    },
  });
</script>
<style lang="less" scoped>
  .full-loading {
V
vben 已提交
51
    display: flex;
V
vben 已提交
52
    position: fixed;
V
vben 已提交
53
    z-index: 200;
V
vben 已提交
54 55
    top: 0;
    left: 0;
V
vben 已提交
56 57
    align-items: center;
    justify-content: center;
V
vben 已提交
58 59
    width: 100%;
    height: 100%;
V
vben 已提交
60
    background-color: rgb(240 242 245 / 40%);
V
vben 已提交
61 62 63

    &.absolute {
      position: absolute;
V
vben 已提交
64
      z-index: 300;
V
vben 已提交
65 66 67 68
      top: 0;
      left: 0;
    }
  }
V
Vben 已提交
69 70

  html[data-theme='dark'] {
71
    .full-loading:not(.light) {
V
Vben 已提交
72
      background-color: @modal-mask-bg;
V
Vben 已提交
73 74
    }
  }
75 76 77 78

  .full-loading.dark {
    background-color: @modal-mask-bg;
  }
V
vben 已提交
79
</style>