首页 > 其他分享 >APICloud AVM 封装验证码输入框组件

APICloud AVM 封装验证码输入框组件

时间:2022-08-29 17:34:00浏览次数:89  
标签:code AVM 验证码 输入框 APICloud verification 组件 input data

AVM(Application-View-Model)前端组件化开发模式基于标准 Web Components 组件化思想,提供包含虚拟 DOM 和 Runtime 的编程框架 avm.js 以及多端统一编译工具,完全兼容 Web Components 标准,同时兼容 Vue 和 React 语法糖编写代码,编译工具将 Vue 和 React 相关语法糖编译转换为 avm.js 代码。

基于标准 Web Components 组件化思想,兼容 Vue / React 语法特性,通过一次编码,分别编译为 App、小程序代码,实现多端开发。
 

组件功能介绍

验证码输入框组件,可自定义下次点击等待时长,自定义验证码长度,可根据自定义的验证码长度进行输入内容的验证。

组件示例

组件开发

组件文件

verification-code-input.stml

<template>
	<view class="verification-code">
		<input class="code-input" placeholder="输入验证码" keyboard-type="number" oninput="getCode"/>
		<text v-show="show" class="code-btn" @click="sendCode">获取验证码</text>
		<text v-show="!show" class="code-btn">{count}s</text>
	</view>
</template>
<script>
	export default {
		name: 'verification-code-input',
		installed(){

		},
		props:{
			limitSecond:Number,
			limitCode:Number
		},
		data() {
			return{
				show:true,
				count: 0,
				timer:null
			}
		},
		methods: {
			sendCode(){
				//正则验证手机号码
				const TIME_COUNT = this.props.limitSecond;
				if (!this.data.timer) {
					this.data.count = TIME_COUNT;
					this.data.show = false;
					this.data.timer = setInterval(() => {
					if (this.data.count > 0 && this.data.count <= TIME_COUNT) {
							this.data.count--;
						} else {
							this.data.show = true;
							clearInterval(this.data.timer);
							this.data.timer = null;
						}
					}, 1000)
				}
				/**
				 * 进行发送短信验证码的操作
				 */
			},
			getCode(e){
				//对验证码进行校验 符合位置和规则进行输出
				if(e.detail.value.length == this.props.limitCode){
					let reg= /^[0-9]*$/;
					if(reg.test(e.detail.value)){
						this.fire('setCode',e.detail.value);
					}
					else{
						api.toast({
							msg:'请输入有效的验证码!'
						})
					}		
				}
				else if(e.detail.value.length > this.props.limitCode){
					api.toast({
						msg:'请输入'+this.props.limitCode+"位验证码!"
					})
				}
			}
		}
	}
</script>
<style>
	.verification-code{
		flex-flow: row nowrap;
		margin: 10px 20px;
		justify-content: space-between;
		border-bottom: 0.5px solid #f0f0f0;
		align-items: center;
	}
	.code-input{
		width: auto;
		border: none;
		font-size: 18px;
	}
	.code-btn{
		color: #1492ff;
		font-size: 18px;
	}
</style>

组件使用说明

本组件是基于 AVM.js 开发的多端组件,通常同时适配 Android、iOS、小程序、H5 , 具体支持情况还要看每个组件的说明文档。

首先需要登录开发平台,http://www.apicloud.com。 通过控制平台右上方的模块 Store 进入,然后选择 AVM 组件。

 

 找到对应模块进入

 也可通过搜索栏,通过组件名称关键字进行检索

进入模块详情,点击立即下载下载完整的组件安装包。  

 

 组件压缩包的文件目录如下

也可通过查看模块文档 来了解模块的具体参数,引用的原生模块,注意事项等。 

 

具体在项目中的使用步骤是,第一步将压缩文件中的 verification-code-input.stml 文件拷贝到项目的 components 目录,通过阅读 readme.md 文档和查看 demo 示例文件 demo-verification-code-input.stml 在需要开发的 stml 文件中,引入组件文件,完成页面的开发。

demo-verification-code-input.stml

<template>
	<view class="page">
		<safe-area></safe-area>
		<verification-code-input limitSecond={seconds} limitCode={codeLen} onsetCode="getCode"></verification-code-input>
	</view>
</template>
<script>
	import '../../components/verification-code-input.stml'
	export default {
		name: 'demo-verification-code-input',
		apiready(){

		},
		data() {
			return{
				code:'',
				seconds:60,
				codeLen:4
			}
		},
		methods: {		
			getCode(e){
				console.log(JSON.stringify(e.detail));
				this.data.code = e.detail;
			}
		}
	}
</script>
<style>
	.page {
		height: 100%;
		background-color: #ffffff;
		padding-top: 100px;
	}
	.verification-code{
		flex-flow: row nowrap;
		margin: 10px 20px;
		justify-content: space-between;
		border-bottom: 0.5px solid #f0f0f0;
		align-items: center;
	}
	.code-input{
		width: auto;
		border: none;
		font-size: 15px;
		flex: 1;
	}
	.code-btn{
		color: #1492ff;
		font-size: 15px;
	}
</style>

 

如果在 AVM 组件库中,没有找到实际项目中需要的组件,可以自己尝试封装组件。

这是组件化开发的在线文档地址

 

 

标签:code,AVM,验证码,输入框,APICloud,verification,组件,input,data
From: https://www.cnblogs.com/APICloud/p/16636683.html

相关文章

  • APICloud 可视化编程 - 拖拉拽实现专业级源码
    低代码开发平台是无需编码(0代码或⽆代码)或通过少量代码就可以快速生成应用程序的开发平台。它的强⼤之处在于,允许终端⽤户使⽤易于理解的可视化⼯具开发自己的应用程......
  • 使用 vue 开发 APICloud 应用的教程
    文档目录一、APICloud创建程序1、APICloud后台创建应用2、APICloud拉取代码,APICloud开发工具地址APICloud开发工具PC端,先下载APICloud开发工具,打开开发工具......
  • 原生js解决ios手机input输入框弹出覆盖问题
    背景:软键盘弹起挡住input框软键盘弹起页面布局乱掉安卓手机+界面父级组件使用了overflow:hidden导致键盘弹出(页面本质上变小了)仍然不可滚动解决思路:父级别不要使用ove......
  • <input> 实现输入框只能输入数字
    1.使用JS限制input输入框只能输入纯数字onkeyup="value=value.replace(/[^\d]/g,'')"使用onkeyup事件,有bug ,那就是在中文输入法状态下,输入汉字之后直接回车,......
  • 实例|APICloud可视化开发企业管理app
    利用 APICloudstudio3 可以帮助我们快速创建并运行一个简单的应用,内容涉及开发工具使用、代码管理、应用预览、调试等。现在我们来通过APICloudstudio3快速创建一个......
  • Flutter 循环创建输入框 TextField
    需求:根据接口返回的数据生成列表,列表内含有可编辑的字段 先初始化一个 TextEditingController集合Map<Object,TextEditingController>_numberControllers=......
  • vue 多行输入框显示行号
    一、概述因业务需求,多行文本需要显示行号,方便查看配置。由于默认的textarea输入框无法显示行号,因此需要使用第三方插件才行。 二、插件我找了一个插件,叫bin-code-edi......
  • 【快应用】input组件的输入框弹出后,如何点击其他地方后失去焦点,并收起键盘
    可以在input组件最外面的div上写一个收起键盘的事件。 代码如下(关注加粗的内容): <template>  <div class="item-container">    <div class="item-containe......