uniapp-uni-easyinput使用

2023-11-22 22:10
文章标签 uniapp 使用 uni easyinput

本文主要是介绍uniapp-uni-easyinput使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

代码如下

<template><view class="login" :style="{'paddingTop': menuContentTop}"><view class="title">{{passwordTel ? passwordTel : isLogin ? '登录' : '注册'}}</view><view class="helloTip" v-show="isLogin && !passwordTel">您好,欢迎来到顶医!</view><view class="content"><u--form:model="formData":rules="rules"ref="refFormData"><u-form-item prop="phone" borderBottom><u--input placeholder="请输入手机号" v-model="formData.phone" border="none"><template slot="suffix" v-if="!isLogin || passwordTel"><u-coderef="uCode"@change="codeChange"seconds="60"changeText="X秒重新获取"></u-code><u-button @tap="getCode" :text="tips" :plain="true" size="small" style="border: none;background: none;"></u-button></template></u--input></u-form-item><u-form-item prop="code" borderBottom v-if="!isLogin || passwordTel"><u--input v-model="formData.code" placeholder="请输入验证码" border="none"></u--input></u-form-item></u--form><uni-forms:modelValue="uniFormData":rules="uniRules"ref="uniFormData"validate-trigger="blur"><uni-forms-item name="password"><uni-easyinput type="password"v-model="uniFormData.password":placeholder="passwordTel ? '请输入新密码' : '请输入密码'"placeholderStyle="color: rgb(192, 196, 204); font-size: 15px;":inputBorder="false"></uni-easyinput></uni-forms-item><uni-forms-item name="confirmPassword" borderBottom v-if="!isLogin || passwordTel"><uni-easyinput type="password"v-model="uniFormData.confirmPassword":placeholder="passwordTel ? '请再次输入新密码' : '请再次输入密码'"placeholderStyle="color: rgb(192, 196, 204); font-size: 15px;":inputBorder="false"></uni-easyinput></uni-forms-item></uni-forms></view><view class="btn"><u-button type="primary" :text="passwordTel ? '提交' : isLogin ? '登录' : '注册'" @click="handelSubmit"></u-button><view class="text" v-if="!passwordTel"><text @click="changePassword">忘记密码</text><text class="setColor" @click="toggleStatus">{{isLogin ? '新用户注册' : '已有账号?去登录'}}</text></view><view class="text" v-if="passwordTel === '密码找回'"><text class="setColor" @click="backLogin">返回登录</text></view></view><u-toast ref="uToast" /></view>
</template>
<script>import { mapState } from 'vuex'import { sendSms, registerByApp, updatePassword } from "@/api/user.js"export default {name: "Login",options: {styleIsolation: 'shared', // 解除样式隔离},data() {const validateCode = (rule, value, callback) => {const reg = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/gif(!reg.test(value)){callback(new Error('请输入6位数字验证码'))}callback()}return {formData: {phone: '',code: '',},rules: {phone: [{ required: true, message: '请输入手机号', trigger: ['blur'],},{validator: (rule, value, callback) => {return uni.$u.test.mobile(value);},message: '请输入正确手机号',trigger: ['blur'],}],code: [{ required: true, len: 6, message: '请输入6位数字验证码', trigger: ['blur'],},{ validator: validateCode, trigger: ['blur'],},],},isLogin: true,tips: '',checkboxValue1: [],changeLoginStatus: null, // 挑战到登录页是否改变登录/注册状态uniFormData: {password: '',confirmPassword: '',},uniRules: {password: {rules: [{ required: true, errorMessage: '请输入密码'}],},confirmPassword: {rules: [{ required: true, errorMessage: '请再次输入密码'},{ validateFunction: (rule,value,data,callback) => {if (this.uniFormData.confirmPassword !== this.uniFormData.password) {callback('两次输入的密码不一致');}return}},],},}}},computed: {...mapState("user", ['passwordTel', 'menuContentTop', 'userOpenId'])},watch: {changeLoginStatus: {handler(newVal) {if (newVal) this.isLogin = false},immediate: true}},onReady() {// 兼容微信小程序this.$refs.refFormData.setRules(this.rules)this.$refs.uniFormData.setRules(this.uniRules)},onLoad(data) {this.changeLoginStatus = data.changeLoginStatus},onShow() {this.$common._removeStorage('token')},methods: {codeChange(text) {this.tips = text;},getCode() {if (!this.formData.phone) {this.$common._showToast('请输入手机号')return}if (this.$refs.uCode.canGetCode) {this.$refs.uCode.start();sendSms({ phone: this.formData.phone }).then(res => {// 这里此提示会被this.start()方法中的提示覆盖this.$refs.uToast.show({message: '验证码已发送',})})}},// 切换登录/注册及其他toggleStatus() {this.reset()this.isLogin = !this.isLoginthis.$store.commit('user/CHANGE_PASSWORD_TEL', '')},// 返回登录backLogin() {this.toggleStatus()this.isLogin = true},// 修改密码changePassword() {this.reset()this.$store.commit('user/CHANGE_PASSWORD_TEL', '密码找回')},// 登录/注册handelSubmit() {this.$refs.refFormData.validate().then(res => {this.$refs.uniFormData.validate().then(res=>{// 校验通过if (this.isLogin) {if (this.passwordTel) {// 忘记密码,修改密码this.updatePassword()} else {this.$store.dispatch('user/loginByAccount', { phone: this.formData.phone, password: this.uniFormData.password })}} else {this.registerByApp()}})}).catch(err => {this.$refs.uniFormData.validate().then()})},// 注册registerByApp() {registerByApp({userPhone: this.formData.phone,verifyCode: this.formData.code,userPwd: this.uniFormData.password,openId: this.userOpenId}).then(res => {this.$store.dispatch('user/loginByAccount', { phone: this.formData.phone, password: this.uniFormData.password })})},// 忘记密码updatePassword() {updatePassword({userPhone: this.formData.phone,verifyCode: this.formData.code,userPwd: this.uniFormData.password,}).then(res => {this.$common._showToast('密码修改成功')if (this.passwordTel === '修改密码') {// 个人中心-修改密码this.$store.commit('user/CHANGE_PASSWORD_TEL', '')this.$common._jumpToUrl('../personalCenter/personalCenter', 2)} else {// 登录-忘记密码this.isLogin = truethis.$store.commit('user/CHANGE_PASSWORD_TEL', '')this.reset()}}).catch(err => {this.reset()})},// 重置reset() {this.$refs.refFormData.resetFields()this.$refs.refFormData.clearValidate()this.$refs.uniFormData.clearValidate()this.uniFormData.password = ''this.uniFormData.confirmPassword = ''}}}
</script><style lang="scss" scoped>@import '@/static/css/form.scss';/deep/ {.content {.u-button:before {background: none;}}uni-label {font-size: 24rpx;color: #00000099;uni-text {color: #1683FB;}}.uni-easyinput__content-input {padding-left: 0 !important;}uni-radio-group {display: flex;align-items: center;}/* #ifdef MP-WEIXIN */radio-group {display: flex;align-items: center;}/* #endif */.uni-forms-item {border-bottom: 1px solid rgba(214, 215, 217, 0.8);margin-bottom: 0;padding: 10rpx 0;}.uni-forms-item__error.msg--active {position: initial;margin-left: 45px;}}.login {box-sizing: border-box;min-height: 100vh;.title {color: #3D3D3D;font-weight: 700;font-size: 40rpx;box-sizing: border-box;padding: 120rpx 76rpx 0;}.helloTip {opacity: 0.3;padding: 0 76rpx;margin-top: 26rpx;}.content {margin-top: 100rpx;box-sizing: border-box;padding: 0 76rpx;}.btn {margin-top: 128rpx;box-sizing: border-box;padding: 0 76rpx;.text {margin-top: 36rpx;color: #3D3D3D;display: flex;justify-content: space-between;.setColor {color: #1683FB;}}}}
</style>

在这里插入图片描述

这篇关于uniapp-uni-easyinput使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/413254

相关文章

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

Java Optional的使用技巧与最佳实践

《JavaOptional的使用技巧与最佳实践》在Java中,Optional是用于优雅处理null的容器类,其核心目标是显式提醒开发者处理空值场景,避免NullPointerExce... 目录一、Optional 的核心用途二、使用技巧与最佳实践三、常见误区与反模式四、替代方案与扩展五、总结在 Java

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Python虚拟环境终极(含PyCharm的使用教程)

《Python虚拟环境终极(含PyCharm的使用教程)》:本文主要介绍Python虚拟环境终极(含PyCharm的使用教程),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录一、为什么需要虚拟环境?二、虚拟环境创建方式对比三、命令行创建虚拟环境(venv)3.1 基础命令3

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi