1
1
<script lang="ts" setup>
2
2
import { NProgress , NSkeleton , NSpin } from ' naive-ui' ;
3
3
4
- import { onDeactivated , onMounted , onUnmounted , ref , toRefs , watch } from ' vue' ;
4
+ import { computed , onMounted , onUnmounted , ref , toRefs , watch } from ' vue' ;
5
5
6
6
import AnimatedNumber from ' ./AnimatedNumber.vue' ;
7
7
8
+ import { Rating } from ' ~/models/rating.model' ;
8
9
import { wait } from ' ~/utils/promise.utils' ;
9
10
10
11
const props = defineProps ({
@@ -47,6 +48,13 @@ const { progress, delay } = toRefs(props);
47
48
48
49
const _progress = ref (0 );
49
50
51
+ const color = computed (() => {
52
+ if (_progress .value <= Rating .Bad * 10 ) return ' color-error' ;
53
+ if (_progress .value <= Rating .Mediocre * 10 ) return ' color-warning' ;
54
+ if (_progress .value <= Rating .Good * 10 ) return ' color-info' ;
55
+ return ' color-primary' ;
56
+ });
57
+
50
58
onMounted (async () => {
51
59
watch (
52
60
progress ,
@@ -74,7 +82,10 @@ onUnmounted(() => {
74
82
class =" progress custom-color"
75
83
type =" circle"
76
84
:percentage =" _progress"
77
- :style =" { '--duration': `${duration - delay}ms` }"
85
+ :style =" {
86
+ '--duration': `${ duration - delay }ms`,
87
+ '--custom-progress-color': `var(--${ color })`,
88
+ }"
78
89
>
79
90
<AnimatedNumber
80
91
:from =" from"
@@ -94,7 +105,7 @@ onUnmounted(() => {
94
105
}
95
106
96
107
.custom-color {
97
- --custom- color : var (--info-color ) --n-fill- color: var (--custom- color ) !important ;
108
+ --n-fill- color : var (--custom-progress- color , var (--color-info ) ) !important ;
98
109
}
99
110
100
111
.spin {
0 commit comments