当前位置: 首页 > news >正文

uniapp开发动态添加密码验证

在密码框里面添加验证当输入框输入时分别验证要满足至少8个字符,至少1个数字,至少1个字母,三种条件,不满足就亮起相应的图标 图标也有三种状态(默认状态,成功状态失败状态)

代码如下

<template><view class="cuotent"><!-- 顶部区域 --><view class="top"></view><!-- 中间部分 --><view><!-- 名称 --><view class="name"><view class="title">设置登录密码</view><view class="txt">安全从这里开始,请输入密码</view></view><!-- 表单区域 --><view class="form"><view class="item"><view class="title">密码</view><input class="uni-input" v-model="pasword" :type="showPassword ? 'text' : 'password'"  placeholder-class="iput_text" placeholder="请输入密码" /><uni-icons class="yesicon" :type="showPassword ? 'eye' : 'eye-slash'" size="36rpx" color="#737373" @click="changePassword(1)"></uni-icons><uni-icons class="closeicon" v-if="pasword && pasword.length > 0" type="close" size="36rpx" color="#737373" @click="clearPassword(1)"></uni-icons></view><view class="item"><view class="title">确认密码</view><input class="uni-input" v-model="isPasword" :type="showIsPassword ? 'text' : 'password'"  placeholder-class="iput_text" placeholder="请输入密码" /><uni-icons class="yesicon" :type="showIsPassword ? 'eye' : 'eye-slash'" size="36rpx" color="#737373" @click="changePassword(2)"></uni-icons><uni-icons class="closeicon" v-if="isPasword && isPasword.length > 0" type="close" size="36rpx" color="#737373" @click="clearPassword(2)"></uni-icons></view><view class="xieyi"><view class="requirement"><uni-icons :type="getIconType('length')" :color="getIconColor('length')" size="32rpx"></uni-icons><text class="label">至少8个字符</text></view><view class="requirement"><uni-icons :type="getIconType('number')" :color="getIconColor('number')" size="32rpx"></uni-icons><text class="label">至少1个数字</text></view><view class="requirement"><uni-icons :type="getIconType('letter')" :color="getIconColor('letter')" size="32rpx"></uni-icons><text class="label">至少1个字母</text></view></view></view><view class="bottom_are"><view class="btn" @click="sure">确定</view></view></view></view>
</template><script setup>
import { reactive, ref, computed  } from 'vue';
let showPassword = ref(false)
let showIsPassword = ref(false)
let pasword = ref('')
let isPasword = ref('')// 密码验证条件
const hasMinLength = computed(() => pasword.value.length >= 8)
const hasNumber = computed(() => /\d/.test(pasword.value))
const hasLetter = computed(() => /[a-zA-Z]/.test(pasword.value))
// 获取图标类型
const getIconType = (type) => {if (!pasword.value || pasword.value.length === 0) {// 默认状态return 'checkbox-filled'}switch (type) {case 'length':return hasMinLength.value ? 'checkbox-filled' : 'info-filled'case 'number':return hasNumber.value ? 'checkbox-filled' : 'info-filled'case 'letter':return hasLetter.value ? 'checkbox-filled' : 'info-filled'default:return 'info-filled'}
}// 获取图标颜色
const getIconColor = (type) => {if (!pasword.value || pasword.value.length === 0) {// 默认状态 - 灰色return '#d4d4d4'}switch (type) {case 'length':return hasMinLength.value ? '#12a58c' : '#d83d17'case 'number':return hasNumber.value ? '#12a58c' : '#d83d17'case 'letter':return hasLetter.value ? '#12a58c' : '#d83d17'default:return '#d4d4d4'}
}
const changePassword = (val)=> {if(val == 1) {showPassword.value = !showPassword.value;} else {showIsPassword.value = !showIsPassword.value;}console.log('rrr',showPassword.value);
}
// 清除密码的方法
const clearPassword = (val) => {if(val == 1) {pasword.value = "";} else {isPasword.value = "";}
}
const sure = ()=> {console.log('跳转注册成功页面');uni.navigateTo({url: '/pages/registeredsuccess/registeredsuccess'})
}</script><style lang="scss" scoped>.cuotent {width: 100%;height: 1100rpx;overflow: hidden;position: relative;.name {display: flex;flex-direction: column;align-items: center;width: 100%;margin-top: 112rpx;margin-bottom: 80rpx;.title {width: 384rpx;height: 64rpx;font-family: Inter, Inter;font-weight: 600;font-size: 64rpx;color: #171717;line-height: 64rpx;text-align: left;font-style: normal;text-transform: none;}.txt {height: 40rpx;font-family: Inter, Inter;font-weight: 400;font-size: 26rpx;color: #898989;line-height: 39rpx;font-style: normal;text-transform: none;margin-top: 16rpx;}}.form {width: 100%;box-sizing: border-box;padding: 0 40rpx;margin-bottom: 164rpx;.item {margin-bottom: 32rpx;position: relative;.title {height: 56rpx;font-family: PingFang SC, PingFang SC;font-size: 24rpx;color: #737373;line-height: 24rpx;font-style: normal;text-transform: none;display: flex;align-items: center;margin-bottom: 8rpx;}.iput_text {font-family: Inter, Inter;font-weight: 400;font-size: 28rpx;color: #A3A3A3;}.uni-input {height: 96rpx;background: #FAFAFA;border-radius: 24rpx 24rpx 24rpx 24rpx;border: 1rpx solid #898989;padding-left: 32rpx;padding-right: 64rpx;}.yesicon {position: absolute;right: 32rpx;top: 100rpx;}.closeicon {position: absolute;right: 90rpx;top: 100rpx; }}.xieyi {display: flex;flex-direction: column;.requirement {margin-bottom: 20rpx;height: 24rpx;font-family: Inter, Inter;font-weight: 400;font-size: 24rpx;color: #898989;text-align: left;font-style: normal;text-transform: none;position: relative;display: flex;align-items: center;.uni-icons {margin-right: 6rpx;}}}}.bottom_are {width: 100%;display: flex;justify-content: center;.btn {width: 670rpx;height: 104rpx;background: #FF4001;border-radius: 24rpx 24rpx 24rpx 24rpx;font-family: Inter, Inter;font-weight: normal;font-size: 32rpx;color: #FFFFFF;display: flex;align-items: center;justify-content: center;}}}    
</style>

效果图

在这里插入图片描述

http://www.dtcms.com/a/331366.html

相关文章:

  • Go语言全面解析:从入门到精通
  • C/C++ 指针与内存操作详解——从一级指针到字符串转换函数的完整解析
  • 拒绝“孤岛式”作战,全方位构筑隧道应急通信解决方案
  • Java 学习笔记(基础篇2)
  • 13、C 语言结构体尺寸知识点总结
  • LeetCode 刷题【41. 缺失的第一个正数】
  • 【力扣322】零钱兑换
  • 非容器方式安装Prometheus和Grafana,以及nginx配置访问Grafana
  • GraphRAG查询(Query)流程实现原理分析
  • NetLimiter:精准掌控网络流量,优化网络体验
  • 《中国人工智能安全承诺框架》发布
  • arthas火焰图怎么看
  • 搭建 Docker 私有仓库
  • 前端css学习笔记5:列表表格背景样式设置
  • 【Golang】Golang内存泄漏问题排查(二)
  • 服务器路由相关配置Linux和Windows
  • Android POS应用在android运行常见问题及解决方案
  • 当消息队列遇上AI:飞算JavaAI实现智能流量调度与故障自愈实践
  • 在 Windows 系统中解决 Git 推送时出现的 Permission denied (publickey) 错误,请按照以下详细步骤操作:
  • LE AUDIO---Common Audio Service
  • C#WPF实战出真汁02--登录界面设计
  • STM32学习笔记11-通信协议-串口基本发送与接收
  • 从轨道根数计算惯性系到轨道系旋转矩阵
  • 2020/12 JLPT听力原文 问题二 1番
  • [激光原理与应用-268]:理论 - 几何光学 - 人眼结构与颜色感知
  • Nacos 配置热更新:Spring Boot Bean 自动获取最新配置
  • 【21-倾斜数据集的误差指标】
  • 金融风控实战:从数据到模型的信用评分系统构建全解析
  • 使用马尔可夫链如何解码、预测股市模式
  • 西门子PLC通过稳联技术EtherCAT转Profinet网关连接baumuller伺服器的配置案例