APICloud AVM框架封装车牌号输入键盘组件

简介: APICloud AVM框架 封装车牌号输入键盘组件实例分享。封装了车牌号输入键盘,支持燃油汽车、新能源车辆、教练车、挂车、警车5种模式。针对输入的车牌号进行了正则验证。

APICloudAVM框架 封装车牌号输入键盘组件实例分享。封装了车牌号输入键盘,支持燃油汽车、新能源车辆、教练车、挂车、警车5种模式。针对输入的车牌号进行了正则验证。

如有其他类型的车牌需要输入,可在此基础上进行添加即可,主要是控制号牌长度和一些固定的字。

组件引用

import '../../components/car-num-keyboard.stml'

组件使用

<car-num-keyboard v-bind:mode={mode} v-if="isSetCarNum" oncancal="claseKeyboard" ongetNum="getCarNum"></car-num-keyboard>

组件文件

car-num-keyboard.stml

<template>

<view class={"keyboard-box-bg" + (transition?' keyboard-box-bg-transition':'')}>

<view style="height:100%;"></view>

<view class={"keyboard-box" + (transition?' keyboard-box-transition':'')}>

<view class="header">

<text @click="cancelLicense">取消</text>

<text>{licenseType}</text>

<text @click="successLicense">完成</text>

</view>

<view class="license-number">

<view class="license-number-item" v-for="item in licenseNumber">

<text>{item}</text>

</view>

</view>

<view class="keyboard">

<view class="keyboard-item" v-for="item in provinces" data-value={item} @click="setNumber" v-show="!isProvince">

<text class="keyboard-item-title">{item}</text>

</view>

<view class="keyboard-item-key" v-for="item in licenseKey" data-value={item} @click="setNumberKey" v-show="isProvince">

<text class="keyboard-item-title">{item}</text>

</view>

<image class="keyboard-item-ico" src='../../image/key-back.png' mode="widthFix" @click="delLicenseNUmber"></image>

</view>

</view>

<safe-area></safe-area>

</view>

</template>

<script>

export default {

name: 'car-num-keyboard',

installed(){

if(this.props.mode=='new'){

this.data.licenseNumber=['','','','','','','',''];

this.data.licenseType='新能源汽车号牌';

this.data.numberLength = 8;

}

else if(this.props.mode=='trailer'){

this.data.licenseNumber=['','','','','','','挂'];

this.data.licenseType='挂车号牌';

this.data.numberLength = 6;

}

else if(this.props.mode=='instructional'){

this.data.licenseNumber=['','','','','','','学'];

this.data.licenseType='挂车号牌';

this.data.numberLength = 6;

}

else if(this.props.mode=='police'){

this.data.licenseNumber=['','','','','','','警'];

this.data.licenseType='警车号牌';

this.data.numberLength = 6;

}

else{

this.data.licenseNumber = ['', '', '', '', '', '', ''];

this.data.licenseType='燃油汽车号牌';

this.data.numberLength = 7;

}      

this.data.keyBoards = this.data.licenseKey;

setTimeout(()=>{

this.data.transition = true;

}, 50);

},

props:{

mode:String

},

data() {

return{

provinces: ['京', '津', '冀', '晋', '蒙', '辽', '吉', '黑', '沪', '苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤', '桂', '琼', '渝', '川', '贵', '云', '藏', '陕', '甘', '青', '宁', '新'],          

licenseNumber: [],

licenseKey: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],

keyBoards: [],

isProvince: false,

licenseNumberIndex: 0,

licenseType: '燃油汽车号牌',

mode:'',

numberLength:7,

transition: false

}

},

methods: {

setNumber(e) {

if (this.data.licenseNumberIndex == 0) {

this.data.licenseNumber[0] = e.dataset.value;

this.data.licenseNumberIndex += 1;

this.data.isProvince = true;

}

},

setNumberKey(e) {

if (this.data.licenseNumberIndex < this.data.numberLength) {

this.data.licenseNumber[this.data.licenseNumberIndex] = e.dataset.value;

this.data.licenseNumberIndex += 1;

}

},

delLicenseNUmber() {

this.data.licenseNumberIndex -= 1;

if (this.data.licenseNumberIndex == 0) {

this.data.isProvince = false;

}

this.data.licenseNumber[this.data.licenseNumberIndex] = '';

},

cancelLicense() {

this.fire('cancal','');

},

successLicense() {

let licenseNumber = this.data.licenseNumber.join('');

//校验车牌号

const carReg=/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;

if(!carReg.test(licenseNumber)){

api.confirm({

title: '提醒',

msg: '您输入的车牌号可能无效,是否继续使用?',

buttons: ['确定', '取消']

}, (ret, err) => {

// var index = ret.buttonIndex;

if(ret.buttonIndex==1){

this.fire('getNum',{carNum:licenseNumber,mode:this.props.mode});

}

});

}

else{

this.fire('getNum',{carNum:licenseNumber,mode:this.props.mode});

}    

}

}

}

</script>

<style>

.keyboard-box-bg{

position: absolute;

width: 100%;

height: 100%;

background-color: rgba(0,0,0,0.1);

transition-property: background-color;

transition-duration: 0.3s;

}

.keyboard-box-bg-transition{

background-color: rgba(0,0,0,0.4);

}

.keyboard-box{

align-items: center;

position: absolute;

bottom: 0;

width: 100%;

background-color: white;

box-sizing: border-box;

transform: translateY(100%);

transition-property: transform;

transition-duration: 0.3s;

}

.keyboard-box-transition{

transform: translateY(0);

}

.header {

background-color: #dddddd;

flex-flow: row nowrap;

justify-content: space-between;

align-items: center;

padding: 8px 15px;

width: 100%;

}

.license-number {

flex-flow: row nowrap;

justify-content: space-between;

align-items: center;

padding: 30px;

background-color: #ffffff;

width: 100%;

}

.license-number-item {

width: 10%;

justify-content: center;

align-items: center;

border: 0.5px solid #cccccc;

border-radius: 5px;

padding: 5px 0;

min-height: 35px;

}

.keyboard {

background-color: #ffffff;

width: 100%;

}

.keyboard {

flex-flow: row wrap;

align-items: center;

padding: 0 10px 10px 10px;

}

.keyboard-item {

width: 12.5%;

justify-content: center;

align-items: center;

}

.keyboard-item-key {

width: 10%;

justify-content: center;

align-items: center;

}

.keyboard-item-title {

border: 0.5px solid #ccc;

border-radius: 5px;

padding: 5px 10px;

margin: 10px 0;

}

.keyboard-item-ico {

width: 30px;

margin-left: 10px;

}

</style>

示例代码

<template>

<view class="page">

<safe-area></safe-area>

<view class="car-box" data-mode="oil" @click="openCarNumKeyboard">

<text class="car-label">燃油汽车号牌</text>

<text class="car-num">{carNumber}</text>

</view>

<view class="car-box" data-mode="new" @click="openCarNumKeyboard">

<text class="car-label">新能源汽车号牌</text>

<text class="car-num">{carNumber1}</text>

</view>

<view class="car-box" data-mode="trailer" @click="openCarNumKeyboard">

<text class="car-label">挂车号牌</text>

<text class="car-num">{carNumber2}</text>

</view>

<view class="car-box" data-mode="instructional" @click="openCarNumKeyboard">

<text class="car-label">教练车号牌</text>

<text class="car-num">{carNumber3}</text>

</view>

<view class="car-box" data-mode="police" @click="openCarNumKeyboard">

<text class="car-label">警车号牌</text>

<text class="car-num">{carNumber4}</text>

</view>

<car-num-keyboard v-bind:mode={mode} v-if="isSetCarNum" oncancal="claseKeyboard" ongetNum="getCarNum"></car-num-keyboard>

</view>

</template>

<script>

import '../../components/car-num-keyboard.stml'

export default {

name: 'license-number',

apiready(){

},

data() {

return{

carNumber:'',

carNumber1:'',

carNumber2:'',

carNumber3:'',

carNumber4:'',

isSetCarNum:false,

mode:''

}

},

methods: {

openCarNumKeyboard(e){

this.data.mode = e.dataset.mode;

this.data.isSetCarNum = true;//传递动态值 先传值初始化元素

},

claseKeyboard(e){

this.data.isSetCarNum = false;

this.data.mode = '';

},

getCarNum(e){

this.data.isSetCarNum = false;

if(e.detail.mode=='new'){

this.data.carNumber1=e.detail.carNum;

}

else if(e.detail.mode=='trailer'){

this.data.carNumber2=e.detail.carNum;

}

else if(e.detail.mode=='instructional'){

this.data.carNumber3=e.detail.carNum;

}

else if(e.detail.mode=='police'){

this.data.carNumber4=e.detail.carNum;

}

else{

this.data.carNumber = e.detail.carNum;

}

}

}

}

</script>

<style>

.page {

height: 100%;

background-color: #ffffff;

}

.car-box{

margin: 10px;

padding-bottom: 5px;

border-bottom: 0.5px solid #cccccc;

}

.car-label{

font-size: 15px;

color: #666666;

}

.car-num{

font-size: 20px;

min-height: 20px;

}

</style>

注意点:

在调用键盘的时候,是通过v-if 进行键盘的显示和隐藏,v-if  false的情况会销毁元素,所以需要传递的动态值,必须要在元素重新创建之前进行赋值操作。如下图所示,先后顺序很重要。

目录
相关文章
|
传感器 物联网 数据处理
认识IoT的基本概念和架构
物联网(Internet of Things, IoT)是现代信息技术的重要组成部分,通过将物理设备连接到互联网,实现设备之间的互联和数据交换。随着传感技术、通信技术和数据处理能力的不断提升,物联网在各个领域展现出巨大的潜力和应用前景。本文将介绍物联网的基本概念、架构、关键技术及其应用场景,并探讨其未来的发展趋势。
3695 3
|
开发框架 JavaScript 小程序
uni-app——如何阻止事件冒泡
uni-app——如何阻止事件冒泡
1107 0
|
小程序 Android开发 网络架构
uni-app中使用scroll-view滚到底部时多次触发scrolltolower
uni-app中使用scroll-view滚到底部时多次触发scrolltolower
2064 0
uni-app中使用scroll-view滚到底部时多次触发scrolltolower
|
小程序 API 索引
uniapp中uview组件库中丰富的Picker 选择器用法
uniapp中uview组件库中丰富的Picker 选择器用法
3194 0
|
移动开发 小程序
小程序-uniapp:URL Link / 适用于在移动端 从短信、邮件、微信外网页 等场景打开小程序任意页面
小程序-uniapp:URL Link / 适用于在移动端 从短信、邮件、微信外网页 等场景打开小程序任意页面
2097 0
|
10月前
|
人工智能 Linux API
OpenClaw(Clawdbot)一键部署接入 WhatsApp 保姆级教程
OpenClaw作为一款曾用名Clawdbot、Moltbot的开源本地优先AI代理平台,凭借本地运行保障数据隐私、多平台联动交互等优势,成为不少用户处理自动化任务的优选工具。它能接入WhatsApp等多种通信渠道,让用户通过聊天界面就能指挥其完成文件整理、信息查询等各类任务。而借助阿里云服务器的一键部署功能,能大幅降低部署门槛,即便无深厚技术基础的用户,也可快速完成部署并接入WhatsApp。以下是详细的操作步骤,涵盖前期准备、部署实施、WhatsApp接入及后续验证与问题排查,全程步骤清晰且易于操作。
3586 3
|
SQL 人工智能 数据管理
跨云数据管理平台DMS:构建Data+AI的企业智能Data Mesh
跨云数据管理平台DMS助力企业构建智能Data Mesh,实现Data+AI的统一管理。DMS提供开放式元数据服务OneMeta、一站式智能开发平台和云原生AI数据平台,支持多模数据管理和高效的数据处理。结合PolarDB、AnalyticDB等核心引擎,DMS在多个垂直场景中展现出显著优势,如智能营销和向量搜索,提升业务效率和准确性。通过DataOps和MLOps的融合,DMS为企业提供了从数据到AI模型的全生命周期管理,推动数据驱动的业务创新。
1544 0
|
开发工具 git
git怎么设置http代理服务器
git怎么设置http代理服务器
1617 12
|
SQL 安全 Java
安全测试之推荐工具
【2月更文挑战第2天】安全测试之推荐工具
1802 2
|
移动开发 小程序 API
uniapp中uview组件库中丰富的LineProgress 线形进度条 的使用方法
uniapp中uview组件库中丰富的LineProgress 线形进度条 的使用方法
1311 1