spring
昨天 304f9efb86e72eb3ce239fd69b2f4516b4438c6a
1
2
3
4
5
6
7
8
9
10
11
12
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<template>
  <view class="el-progress">
    <view class="el-progress-bar">
      <view class="el-progress-bar__outer" :style="{ height: `${strokeWidth}px` }">
        <view class="el-progress-bar__inner" :style="innerStyle" />
      </view>
    </view>
    <view v-if="showText" class="el-progress__text">{{ text }}</view>
  </view>
</template>
 
<script setup>
import { computed } from "vue";
 
const props = defineProps({
  percentage: { type: Number, default: 0 },
  strokeWidth: { type: Number, default: 10 },
  showText: { type: Boolean, default: true },
  color: { type: String, default: "#409EFF" },
});
 
const safePercent = computed(() => {
  const n = Number(props.percentage);
  if (!Number.isFinite(n)) return 0;
  return Math.max(0, Math.min(100, Math.floor(n)));
});
 
const innerStyle = computed(() => ({
  width: `${safePercent.value}%`,
  backgroundColor: props.color,
}));
 
const text = computed(() => `${safePercent.value}%`);
</script>
 
<style scoped>
.el-progress {
  width: 100%;
}
.el-progress-bar__outer {
  background-color: rgba(0, 0, 0, 0.08);
  border-radius: 100px;
  overflow: hidden;
}
.el-progress-bar__inner {
  height: 100%;
  border-radius: 100px;
  transition: width 0.15s ease;
}
.el-progress__text {
  margin-top: 10rpx;
  text-align: center;
  font-size: 26rpx;
  color: rgba(0, 0, 0, 0.55);
}
</style>