<!--
 * @Author: changjun
 * @FilePath: /qingdao-safety-product/src/views/screen/components/ProgressBar.vue
 * @Date: 2022-07-08 08:52:06
 * @Description: 进度条组件
 * @LastEditTime: 2023-09-01 15:24:11
 * @LastEditors: 曹文丽
-->
<script setup lang="ts">
import { computed } from 'vue'
interface ProgressBarProps {
  percentage: number,
  color?: string
}
const { percentage = 0, color = 'rgba(1, 121, 234, 1)' } = defineProps<ProgressBarProps>()

const getCss = computed(() => {
  return {
    background: 'linear-gradient(270deg, #3067DB, #62CCF0)'
  }
})

const beforeEnter = (el) => {
  el.style.width = 0
}
const enter = (el) => {
  el.style.width = `${percentage}%`
  el.style.transition = `width 1s linear`
}

</script>

<template>
  <div class="progress-bar">
    <div class="background-bar"></div>
    <transition appear @before-appear="beforeEnter" @after-appear="enter">
      <div class="tracker-bar" :style="getCss"></div>
    </transition>
  </div>
</template>

<style scoped lang="scss">
.progress-bar {
  width: 100%;

  .background-bar {
    background: rgba(10, 51, 126, 0.3);
    width: 100%;
    height: 10px;
    border-radius: 4px;
  }

  .tracker-bar {
    background: transparent;
    height: 10px;
    width: 0;
    transition: width 0.5s linear;
    margin-top: -10px;
    border-radius: 4px;
  }
}
</style>
