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-code
								ref="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+)?$/g
				if(!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.isLogin
				this.$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 = true
						this.$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>

uni-easyinput 设置,uniapp,Hbuilder,uni-app,javascript,前端文章来源地址https://www.toymoban.com/news/detail-717722.html

到了这里,关于uniapp-uni-easyinput使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • uniapp使用uni.createInnerAudioContext()播放指定音频并且切换

    uniapp API 中 uni.createInnerAudioContext()是无法多音频播放的 如果我们想同时播放 加上ambient(不中止其他声音播放,不能后台播放,静音后无声音)这个属性,我做的这个是用uniapp开发的一个安卓端的壳包,正常h5用MP3,WMA或者MPEG等格式的音频都是可以的,但在安卓端手机测试需

    2024年02月11日
    浏览(47)
  • uniApp使用uni.chooseAddress()获取微信收货地址

    使用uniapp或者原生微信小程序获取微信的收货地址 在【开发】-【开发管理】-【接口设置】-【获取用户收货地址】–申请该权限,审核通过后方可使用。 2.1 在uniapp上开发配置 打开manifest.json点击源码视图,搜索找到“mp-weixin”在这个对象下添加 “requiredPrivateInfos”:[“choos

    2024年02月02日
    浏览(31)
  • uniapp 使用 uni-data-picker级联选择器,自定义展示,uni小程序

    先看效果是不是你要的效果 页面组件 接口数据 接口数据以及处理方式 选中后的数据处理,拿到选中的值

    2024年02月05日
    浏览(36)
  • uniapp 使用组件 uni-list 实现聊天列表功能

    如何使用 uniapp 的组件实现聊天列表的功能呢,翻阅了半天文档,终于找到一个实用的方法,下面是具体的步骤  1、首先需要下载对应的插件 去uniapp的官方文档进行下载(uni-ui - DCloud 插件市场),这里直接下载插件并导入到HBuilderx 中就可以了。  2、接下来就可以直接进行使

    2024年02月09日
    浏览(36)
  • uniapp中使用uni-file-picker上传文件

    效果图:

    2024年01月25日
    浏览(33)
  • [uniapp] 跨页面传值 uni.$emit 和 uni.$on 的使用方法 以及遇到的坑

    uni.$emit 和 uni.$on 是uniapp自带的跨页面传值    vue 父子通讯可以用 props  this.$emit   这种简单的父子通讯紧适用于 页面和组件 或者 组件之间的传值,他并不适用于页面和页面的互相传值 那要实现页面通讯呢,我们一起来看看uni.$emit 和 uni.$on的使用方法 示例:         A页面

    2024年02月02日
    浏览(32)
  • uniapp小程序因使用 uni.switchTab传不了值使用vuex(简单明了)

    里面写如以下代码

    2024年02月20日
    浏览(28)
  • uniapp如何配置后使用uni.chooseLocation等地图位置api

    在uniapp中想要使用uni.getLocation、uni.chooseLocation ……api的时候我们需要在小程序就开启配置,不然无法使用。 第一步:首先找到manifest.json 第二步:点击源码视图 第三步:在 mp-weixin 加入下面代码 \\\"permission\\\" : {             \\\"scope.userLocation\\\" : {                 \\\"desc\\\" : \\\"你的位

    2024年04月09日
    浏览(35)
  • uniapp 下拉框效果使用 uni-data-select标签

    uni-data-select v-model=\\\"formData.femMerchantsClassificationId\\\" :localdata=\\\"range\\\" @change=\\\"change\\\" /uni-data-select :localdata 绑定下拉框内容 当下拉框内容调用后端接口时候,写法:

    2024年02月11日
    浏览(34)
  • uniapp刷新页面后使用uni.navigateBack()无法返回上个页面

    最近写uniapp项目的时候发现有时候需要更新页面数据,我是用h5强制刷新页面后就无法返回上一个页面,查了文档后发现是页面栈丢失问题。百度看了很多大佬们的方法,方法基本一致,使用原生JS的history对象,封装一个兼容uniapp api和原生js的返回的方法。在此记录一下 方法

    2024年02月15日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包