记录一次element 二次封装的密码输入安全等级显示

<template>
	<div>
		<el-input :type="type" v-model="localValue" @input="onInput" :placeholder="placeholder" autocomplete="off" 
		:maxlength="maxlength" show-password>
		</el-input>
		<div class="pasTips" v-if="pastips">
			<span :class="{'opcity':isopcity == 1}"></span> <span :class="{'opcity':isopcity == 2}"></span> <span :class="{'opcity':isopcity == 3}"></span>
		</div>
	</div>
	
</template>

<script>
	export default {
		name: "passwordInput",
		props: {
			//传进来的value值,只显示不修改
			value: {
				type: String,
				default: ''
			},
			placeholder: {
				type: String,
				default: ''
			},
			maxlength:{
				type: Number,
				default: 18
			},
			pastips:{
				type: Boolean,
				default: false
			}
		},
		data(){
			return{
				// 获取props中value的值,并与el-input绑定,过程中不修改props中value的值,保证了单向数据流原则
				localValue: this.value,
				isopcity: 0,
				type: 'password'
			}
		},
		methods: {
			onInput(e) {
				this.$emit('input', e)
				let $test = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,30}$/;
				let $test1 = /^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+){6,12}$/;   //  弱:纯数字,纯字母,纯特殊字符
				let $test2 = /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/;   //中:字母+数字,字母+特殊字符,数字+特殊字符
				let $test3 = /^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/;   //强:字母+数字+特殊字符
				if(e.length < 1){ this.isopcity = 0; return;}
				if($test1.test(e)){
					this.isopcity = 1
					if($test.test(e)){
						if($test2.test(e)){
							this.isopcity = 2
							if($test3.test(e)){
								this.isopcity = 3
							}
						}
					}
				}else{//没满足  弱  条件就依旧显示红色
					this.isopcity = 1
				}
			}
		},
	}
</script>

<style>
</style>

使用

<paddwordinput v-model="userForm.password" :pastips='true'></paddwordinput>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值