index.vue
2.28 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<template>
<div class="prefixCls relative" style="width: 100%">
<el-input v-model="innerValueRef" v-bind="$attrs" type="password" show-password @change="handleChange" style="width: 100%">
<template #[item]="data" v-for="item in Object.keys($slots)">
<slot :name="item" v-bind="data || {}"></slot>
</template>
</el-input>
<div class="prefixCls-bar">
<div class="prefixCls-bar--fill" :data-score="getPasswordStrength"></div>
</div>
</div>
</template>
<script setup lang="ts" name="StrengthMeter">
import { verifyPasswordStrength } from '/@/utils/toolsValidate';
const props = defineProps({
value: {
type: String,
},
showInput: {
type: Boolean,
default: () => {
return true;
},
},
disabled: {
type: Boolean,
},
});
const emit = defineEmits(['score', 'change', 'update:value']);
// 计算密码强度
const getPasswordStrength = computed(() => {
const { disabled } = props;
if (disabled) return -1;
const innerValue = unref(innerValueRef);
const score = innerValue ? verifyPasswordStrength(innerValue) : -1;
emit('score', score);
return score;
});
const innerValueRef = ref();
const handleChange = (e: any) => {
innerValueRef.value = e;
};
watchEffect(() => {
innerValueRef.value = props.value || '';
});
watch(
() => unref(innerValueRef),
(val) => {
emit('update:value', val);
emit('change', val);
}
);
</script>
<style scoped lang="scss">
.prefixCls {
&-bar {
position: relative;
height: 6px;
margin: 10px auto 6px;
background-color: grey;
border-radius: 6px;
&::before,
&::after {
position: absolute;
z-index: 10;
display: block;
width: 33%;
height: inherit;
background-color: transparent;
border-color: white;
border-style: solid;
border-width: 0 5px;
content: '';
}
&::before {
left: 33%;
}
//
//&::after {
// right: 33%;
//}
&--fill {
position: absolute;
width: 0;
height: inherit;
background-color: transparent;
border-radius: inherit;
transition: width 0.5s ease-in-out, background 0.25s;
&[data-score='1'] {
width: 33%;
background-color: var(--el-color-danger);
}
&[data-score='2'] {
width: 67%;
background-color: var(--el-color-warning);
}
&[data-score='3'] {
width: 100%;
background-color: var(--el-color-success);
}
}
}
}
</style>