@@ -53,31 +53,18 @@ const strengthText = computed(() => {
5353})
5454
5555// 密码强度颜色
56- const strengthColor = computed <' error' | ' warning' | ' success ' >(() => {
57- const colors: Array <' error' | ' warning' | ' success ' > = [
56+ const strengthColor = computed <' error' | ' warning' | ' primary ' >(() => {
57+ const colors: Array <' error' | ' warning' | ' primary ' > = [
5858 ' error' ,
5959 ' error' ,
6060 ' warning' ,
61- ' success ' ,
62- ' success ' ,
63- ' success '
61+ ' primary ' ,
62+ ' primary ' ,
63+ ' primary '
6464 ]
6565 return colors [passwordStrength .value ] || ' error'
6666})
6767
68- // 密码强度颜色(用于Badge)
69- const strengthColorHex = computed (() => {
70- const colors = [
71- ' #ed3f14' ,
72- ' #ed3f14' ,
73- ' #ff9900' ,
74- ' #19be6b' ,
75- ' #19be6b' ,
76- ' #19be6b'
77- ]
78- return colors [passwordStrength .value ]
79- })
80-
8168function generatePassword() {
8269 if (data .value .types .length === 0 ) {
8370 toast .add ({ title: ' 请至少选择一种字符类型' , color: ' error' })
@@ -108,7 +95,7 @@ function generatePassword() {
10895
10996function copy() {
11097 navigator .clipboard .writeText (data .value .password )
111- toast .add ({ title: ' 密码已复制' , color: ' success ' })
98+ toast .add ({ title: ' 密码已复制' })
11299}
113100
114101generatePassword ()
@@ -141,12 +128,13 @@ generatePassword()
141128 <div class =" flex items-center gap-2" >
142129 <div class =" flex-1" >
143130 <UProgress
144- :value =" passwordStrength * 20 "
145- :color = " strengthColor "
131+ v-model =" passwordStrength"
132+ :max = " 5 "
146133 size =" sm"
134+ :color =" strengthColor"
147135 />
148136 </div >
149- <UBadge :style = " { backgroundColor: strengthColorHex, color: '#FFF' } " >
137+ <UBadge :color = " strengthColor " >
150138 {{ strengthText }}
151139 </UBadge >
152140 </div >
@@ -187,27 +175,12 @@ generatePassword()
187175 <div class =" flex flex-col gap-2" >
188176 <span class =" text-sm text-gray-500" >字符类型</span >
189177 <div class =" flex flex-wrap gap-4" >
190- <UCheckbox
191- v-for =" option in typeOptions"
192- :key =" option.value"
193- :model-value =" data.types.includes(option.value)"
194- @update:model-value ="
195- (checked) => {
196- if (checked) {
197- data.types.push(option.value)
198- }
199- else {
200- data.types = data.types.filter((t) => t !== option.value)
201- }
202- generatePassword()
203- }
204- "
205- >
206- <div class =" flex items-center gap-1" >
207- <div :class =" option.icon" />
208- {{ option.label }}
209- </div >
210- </UCheckbox >
178+ <UCheckboxGroup
179+ v-model =" data.types"
180+ :items =" typeOptions"
181+ orientation =" horizontal"
182+ @change =" generatePassword()"
183+ />
211184 </div >
212185 </div >
213186
0 commit comments