<!--
 * @Description: 
 * @Autor: Heloise
 * @Date: 2022-05-23 16:02:49
 * @LastEditors: Heloise
 * @LastEditTime: 2022-11-09 16:14:21
-->
<template>
  <transition name="el-loading-fade" @after-leave="handleAfterLeave">
    <div
      v-show="visible"
      class="el-loading-mask"
      :style="{ backgroundColor: background || '' }"
      :class="[customClass, { 'is-fullscreen': fullscreen }]"
    >
      <div class="el-loading-spinner">
        <svg v-if="!spinner" class="circular" viewBox="25 25 50 50">
          <defs>
            <linearGradient :id="`greenGradient${id}`">
              <stop offset="0%" stop-color="rgba(83, 114, 236, 0.1)" />
              <stop offset="25%" stop-color="rgba(83, 114, 236, 0.25)" />
              <stop offset="50%" stop-color="rgba(83, 114, 236, 0.4)" />
              <stop offset="75%" stop-color="rgba(83, 114, 236, 0.55)" />
              <stop offset="100%" stop-color="rgba(83, 114, 236, 0.7)" />
            </linearGradient>
          </defs>
          <circle class="path" cx="50" cy="50" r="20" fill="none" :stroke="`url(#greenGradient${id})`" />
        </svg>
        <i v-else :class="spinner"></i>
        <p v-if="text" class="el-loading-text">{{ text }}</p>
      </div>
    </div>
  </transition>
</template>

<script>
const uuid = require('uuid');
export default {
  data() {
    return {
      id: uuid.v1(),
      text: null,
      spinner: null,
      background: null,
      fullscreen: true,
      visible: false,
      customClass: ''
    };
  },

  methods: {
    handleAfterLeave() {
      this.$emit('after-leave');
    },
    setText(text) {
      this.text = text;
    }
  }
};
</script>
