当前位置: 首页 > 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.lryc.cn/news/621344.html

相关文章:

  • 【力扣322】零钱兑换
  • C++ 排序指南
  • Kafka下载和安装
  • Ubuntu 22.04 远程桌面设置固定密码的方法
  • HQA-Attack: Toward High Quality Black-Box Hard-Label Adversarial Attack on Text
  • CoreShop商城框架开启多租户(3)
  • PyTorch 2025全解析:从基础到前沿,深度学习框架的技术演进与实战指南
  • ESP32入门开发·通用硬件定时器 (GPTimer)
  • C# 高并发处理方式
  • 算法题Day1
  • torchvision中数据集的使用与DataLoader 小土堆pytorch记录
  • # Vue 列表渲染详解
  • VLMs开发——基于Qwen2.5-VL 实现视觉语言模型在目标检测中的层级结构与实现方法
  • RxJava Android 创建操作符实战:从数据源到Observable
  • 中久数创——笔试题
  • PiscTrace基于YOLO追踪算法的物体速度检测系统详解
  • 2025.8.24复习总结
  • React.memo、useMemo 和 React.PureComponent的区别
  • 基于场景的无人驾驶叉车分类研究:应用场景与技术选型分析
  • springboot myabtis返回list对象集合,对象的一个属性为List对象
  • 飞算 JavaAI 真是 yyds
  • 一周学会Matplotlib3 Python 数据可视化-绘制面积图(Area)
  • [C++] Git 使用教程(从入门到常用操作)
  • TDengine IDMP 基本功能(6. 无问智推)
  • TDengine IDMP 基本功能(7. 智能问数)
  • C++11新特性深度解析
  • 【CF】Day127——杂题 (数论 gcd | 数论 gcd | 博弈论 | 二分图判断 | 贪心 + 暴力 / 二分答案 | 数论 gcd + 动态规划)
  • OSG+Qt —— 笔记1 - Qt窗口加载模型(附源码)
  • Mybatis 源码解读-SqlSession 会话源码和Executor SQL操作执行器源码
  • 《Python函数:从入门到精通,一文掌握函数编程精髓》