深入解析:分享一个完整的uniapp车牌号输入组件
2025-09-23 15:32 tlnshuju 阅读(0) 评论(0) 收藏 举报UniApp车牌号输入组件封装摘要: 该组件提供标准化的车牌号输入功能,支持普通车牌和新能源车牌两种类型切换。主要特性包括: 智能键盘:自动切换省份、字母和数字键盘 新能源车牌支持:自动适配9位车牌格式 交互体验:点击车牌位自动弹出对应键盘 双向绑定:支持v-model绑定车牌值 可配置性:可设置初始车牌类型和是否显示类型选择器 组件采用Vue单文件组件形式开发,包含完整的模板、脚本和样式,可直接在UniApp项目中引用。通过watch监听value变化实现双向绑定,提供plate-type-change事
车牌号输入功能标准的uniapp组件形式,方便在项目中调用:
普通车牌
新能源车牌
{{ item || '' }}
{{ getKeyboardTitle() }}
{{ key }}
删除
ABC
123
export default {
name: 'LicensePlateInput',
props: {
// 初始车牌类型
initPlateType: {
type: String,
default: 'normal' // normal 或 newEnergy
},
// 是否显示车牌类型选择器
showTypeSelector: {
type: Boolean,
default: true
},
// 初始车牌号码
value: {
type: String,
default: ''
}
},
data() {
return {
plateType: this.initPlateType,
plateArray: new Array(8).fill(''),
newEnergyPlateArray: new Array(9).fill(''),
activeIndex: 0,
showKeyboard: false,
keyboardType: 'province' // province, alphabet, number
}
},
computed: {
provinceKeys() {
return [
'京', '津', '冀', '晋', '蒙', '辽', '吉', '黑', '沪', '苏',
'浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤', '桂',
'琼', '渝', '川', '贵', '云', '藏', '陕', '甘', '青', '宁',
'新', '港', '澳', '台', '使', '领', '警', '学', '试'
]
},
alphabetKeys() {
return [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z'
]
},
numberKeys() {
return [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
]
},
newEnergyKeys() {
return [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
]
},
currentKeys() {
// 新能源车牌特殊处理
if (this.plateType === 'newEnergy') {
// 新能源车牌最后一位只能是数字或特定字母
if (this.activeIndex === 8) {
return this.newEnergyKeys;
}
}
switch(this.keyboardType) {
case 'province':
return this.provinceKeys;
case 'alphabet':
return this.alphabetKeys;
case 'number':
return this.numberKeys;
default:
return this.provinceKeys;
}
},
displayPlateArray() {
return this.plateType === 'newEnergy' ? this.newEnergyPlateArray : this.plateArray;
}
},
watch: {
value: {
handler(newVal) {
if (newVal) {
this.setPlateNumber(newVal);
}
},
immediate: true
}
},
methods: {
switchPlateType(type) {
this.plateType = type;
this.activeIndex = 0;
this.showKeyboard = false;
this.$emit('plate-type-change', type);
},
focusInput(index) {
this.activeIndex = index;
this.showKeyboard = true;
// 根据车牌类型和位置确定键盘类型
if (this.plateType === 'normal') {
if (index === 0) {
this.keyboardType = 'province';
} else if (index === 1) {
this.keyboardType = 'alphabet';
} else {
this.keyboardType = 'number';
}
} else {
// 新能源车牌
if (index === 0) {
this.keyboardType = 'province';
} else if (index === 1) {
this.keyboardType = 'alphabet';
} else if (index >= 2 && index = 2 && this.activeIndex 0) {
// 清空当前位
if (this.plateType === 'newEnergy') {
this.$set(this.newEnergyPlateArray, this.activeIndex, '');
} else {
this.$set(this.plateArray, this.activeIndex, '');
}
// 如果当前位已空,则跳转到上一位
if (this.getCurrentPlateArray()[this.activeIndex] === '') {
this.activeIndex--;
}
} else {
// 第一位时直接清空
if (this.plateType === 'newEnergy') {
this.$set(this.newEnergyPlateArray, this.activeIndex, '');
} else {
this.$set(this.plateArray, this.activeIndex, '');
}
}
// 触发输入事件
this.$emit('input', this.getPlateNumber());
},
switchKeyboard(type) {
this.keyboardType = type;
},
getKeyboardTitle() {
if (this.plateType === 'newEnergy' && this.activeIndex === 8) {
return '选择数字或字母(A-F)';
}
switch(this.keyboardType) {
case 'province':
return '选择省份';
case 'alphabet':
return '选择字母';
case 'number':
return '选择数字';
default:
return '选择字符';
}
},
getCurrentPlateArray() {
return this.plateType === 'newEnergy' ? this.newEnergyPlateArray : this.plateArray;
},
getPlateNumber() {
const plateArray = this.plateType === 'newEnergy' ? this.newEnergyPlateArray : this.plateArray;
return plateArray.join('');
},
// 设置车牌号码
setPlateNumber(plateNumber) {
if (!plateNumber) return;
const len = plateNumber.length;
if (len === 8) {
this.plateType = 'normal';
for (let i = 0; i
.license-plate-input {
padding: 20rpx;
}
.plate-type-selector {
display: flex;
justify-content: center;
margin-bottom: 30rpx;
}
.type-item {
padding: 15rpx 30rpx;
border: 2rpx solid #ddd;
border-radius: 50rpx;
margin: 0 20rpx;
font-size: 28rpx;
&.active {
background-color: #2979ff;
color: #fff;
border-color: #2979ff;
}
}
.plate-display {
display: flex;
justify-content: center;
margin-bottom: 40rpx;
&.normal .plate-item {
width: 60rpx;
}
&.newEnergy .plate-item {
width: 55rpx;
}
}
.plate-item {
height: 100rpx;
border: 2rpx solid #ddd;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: bold;
margin: 0 5rpx;
border-radius: 8rpx;
&.plate-item-active {
border-color: #2979ff;
box-shadow: 0 0 10rpx rgba(41, 121, 255, 0.3);
}
}
.keyboard-container {
background-color: #f5f5f5;
padding: 20rpx;
}
.keyboard-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 0;
border-bottom: 2rpx solid #eee;
}
.keyboard-title {
font-size: 32rpx;
font-weight: bold;
}
.keyboard-keys {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
padding: 20rpx 0;
max-height: 500rpx;
overflow-y: auto;
}
.key-item {
width: calc(10% - 10rpx);
height: 70rpx;
background-color: #fff;
border-radius: 10rpx;
display: flex;
align-items: center;
justify-content: center;
margin: 10rpx 5rpx;
font-size: 32rpx;
box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
&.key-delete {
background-color: #ff5a5f;
color: #fff;
width: 15%;
}
}
.keyboard-toggle {
display: flex;
justify-content: center;
padding: 20rpx 0;
}
.toggle-btn {
padding: 10rpx 30rpx;
background-color: #e0e0e0;
border-radius: 30rpx;
margin: 0 20rpx;
font-size: 28rpx;
&.active {
background-color: #2979ff;
color: #fff;
}
}
使用示例:
车牌号输入示例
基础用法
输入的车牌号: {{ plateNumber }}
新能源车牌
输入的车牌号: {{ newEnergyPlate }}
隐藏类型选择器
输入的车牌号: {{ fixedPlate }}
清空所有
设置车牌号
import LicensePlateInput from '@/components/LicensePlateInput.vue'
export default {
components: {
LicensePlateInput
},
data() {
return {
plateNumber: '',
newEnergyPlate: '',
fixedPlate: ''
}
},
methods: {
onPlateTypeChange(type) {
console.log('车牌类型切换为:', type)
},
clearAll() {
this.plateNumber = ''
this.newEnergyPlate = ''
this.fixedPlate = ''
},
setPlate() {
this.plateNumber = '京A12345'
this.newEnergyPlate = '京AD123456'
}
}
}
.container {
padding: 20rpx;
}
.title {
text-align: center;
font-size: 36rpx;
font-weight: bold;
margin-bottom: 40rpx;
}
.section {
margin-bottom: 40rpx;
padding: 20rpx;
background-color: #f8f8f8;
border-radius: 10rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 20rpx;
}
.result {
margin-top: 20rpx;
padding: 20rpx;
background-color: #fff;
border-radius: 10rpx;
}
.actions {
display: flex;
justify-content: space-around;
margin-top: 40rpx;
}
组件特性
Props
initPlateType
: 初始车牌类型 (‘normal’ | ‘newEnergy’),默认 ‘normal’showTypeSelector
: 是否显示车牌类型选择器 (Boolean),默认 truevalue
: 初始车牌号码 (String),默认 ‘’
Events
input
: 车牌号码变化时触发,返回完整车牌号plate-type-change
: 车牌类型切换时触发,返回类型值
Methods
getPlateNumber()
: 获取当前车牌号码setPlateNumber(plateNumber)
: 设置车牌号码clearPlate()
: 清空车牌号码
使用方式
- 将组件文件保存到
components/LicensePlateInput.vue
- 在页面中引入并注册组件
- 使用
v-model
进行双向绑定 - 可通过
init-plate-type
指定初始车牌类型 - 可通过
show-type-selector
控制是否显示类型选择器
这样就完成了一个功能完整的uniapp车牌号输入组件,可以直接在项目中使用。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/913010.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!相关文章
国产 CAD 新选择!NanoCAD 24.0:全功能 DWG 支持 + 3D 建模优化,多领域设计效率拉满
在建筑、机械、电气等设计领域,CAD 软件的兼容性、功能性与操作流畅度直接影响工作效率。今天给大家推荐一款国产专业级 CAD 工具 ——NanoCAD 24.0,不仅完美适配 64 位 Windows 全系列系统(Win7/8/10/11),更…
扣子Coze智能体实战:自动采集1000条小红书爆款笔记 ,自动写入飞书多维表格
大家好,我是汤师爷,专注AI智能体分享,致力于帮助100W人用智能体创富~
想要抓取小红书热门笔记,但一个个复制太耗时?
需要批量获取热门笔记数据,进行分析,却苦于没有高效的工具?
今天,我将为大家介绍一个超强的…
网站如何做成app建设二手商品网站总结
2016-2017-2 《Java程序设计》课程学生博客和代码托管链接 博客 1552 20155201 李卓雯20155202 张 旭20155203 杜可欣20155204 王 昊20155205 郝博雅20155206 赵 飞20155207 王雪纯20155208 徐子涵20155209 林虹宇20155210 潘滢昊20155211 解雪莹20155212 江振思20155213 陆忠民…
【CVCVCV】dataloader报错RuntimeError: Caught RuntimeError in DataLoader worker process 0
【CVCVCV】dataloader报错RuntimeError: Caught RuntimeError in DataLoader worker process 0Posted on
2025-09-23 15:34
SaTsuki26681534
阅读(0)
评论(0) 收藏
举报参考文献
https://blog.csdn.net/SHY0978/a…
成品网站1688入口网页版怎样攀枝花城市建设网站
文章目录 一、前言二、硬件1.引脚说明2.原理图 三、软件1.IIC读写函数1.1 读函数1.2 写函数 2.初始化2.1 检测设备是否存在2.2 读取LSM6DS3TRC器件ID2.3 LSM6DS3TRC重启,重置寄存器2.5 LSM6DS3TRC设置块数据更新2.6 LSM6DS3TRC设置加速度计的数据采样率2.7 LSM6DS3T…
道滘镇仿做网站怎样做化妆品网站
本系列文章描述了离线环境下以 UPI (User Provisioned Infrastructure) 模式安装 Openshift Container Platform (OCP) 4.4.5 的步骤,我的环境是 VMware ESXI 虚拟化,也适用于其他方式提供的虚拟机或物理主机。离线资源包括安装镜像、所有样例 Image Str…
响应式网站弊端企业建设高端网站的目的
基础配置:
1.配置主机名,静态IP地址
2.开启防火墙并配置
3.部分开启SElinux并配置
4.服务器之间使用同ntp.aliyun.com进行时间同步
5.服务器之间实现SSH免密登录
业务需求:
1.Server-NFS-DNS主机配置NFS服务器,将博客网…
discuz做资讯网站合适吗河南省台前县建设局网站
DBeaver Community(社区版)下载及安装自用版 数据库管理工具好用的都收费,收费的都好用。 DBeaver Community(社区版)免费,功能够用,性能可以,推荐。商业版的强大,收费&a…
网络广告图片揭阳百度推广优化
写在前面 最近花了一点时间阅读了《SRE Goolge运维解密》这本书,对于书的内容大家可以看看豆瓣上的介绍。总体而言,这本书是首次比较系统的披露Google内部SRE运作的一些指导思想、实践以及相关的问题,对于我们运维乃至开发人员都有一定的借鉴…
模板网站也需要服务器吗国内域名和国外域名区别
摘要:最近有客户反映使用阿里云虚拟云主机,wordpress常提示502 Bad Gateway错误,网关错误是网站上遇到的常... wordpress的502 Bad Gateway错误如何修复? 第1步:偶发错误可尝试重新加载网站 偶尔出现流量突发爆增或是服…
四川省住房与城乡建设厅网站管网做泵阀到哪个网站好
第一步 1、申请iOS证书 2、导入证书到钥匙串 第二步 1、xcode配置iOS证书 1.1用Xcode打开你的项目(我的Xcode版本是新版) 修改如下图 回到基本信息设置界面,Bundie 这项填写,最先创建的那个appid,跟创建iOS描述文件时选…
Fluent Bit采集k8s日志
Fluent Bit采集k8s日志2025-09-23 15:28
WilliamZheng
阅读(0)
评论(0) 收藏
举报Fluent Bit介绍
Fluentd 团队预测对于嵌入式 Linux 和 Gateways 等受约束的环境,需要更轻量级的日志处理器,于是便开发了Fluent …
公众号文章添加附件,公众号运营必学加分技巧-支持Word、Excel、PDF等文件
很多运营者都头疼公众号无法直接插附件的问题 —— 想分享资料还要让用户私信、加好友,流程繁琐又影响体验。其实只要用对工具,通过小程序中转,Word、Excel、PDF 等文件都能实现一键下载,新手也能快速上手很多运营…
微信管理系统在哪seo推广软件哪个好
在本文中,我们将回顾一些未能进入.NET Core 的历史性.NET 技术。有趣之处在于,这些技术的 API 被复制过来了,这暗示着微软当时在考虑将来在.NET Core 中对它们进行实现。全局程序集缓存全局程序集缓存(GAC)背后的理论是…
python脚本划分数据集
利用python脚本对文件夹中的大量文件划分训练集train、验证集val和测试集test。source_dir为源文件夹,source_dir目录中可以包含不同种类的文件夹。
import os
import shutil
import random
from pathlib import Path…
上海工程建设造价信息网站英雄联盟更新公告最新
ChatGPT 的工作原理
传统搜超搜引擎原理:蜘蛛抓取和数据收集,用户交互查找。 ChatGPT 的工作原理:数据收集称为预训练,用户响应阶段称为推理。
ChatGPT是一种基于自然语言处理技术的人工智能模型,它的工作原理建立在…
漳州微信网站建设电话怎么做网站卖东西
关键词:Web开发、Django、AJAX、前端交互、动态网页 今天和大家分享Django的AJAX支持。AJAX可实现在网页上动态加载内容、无刷新更新数据的需求。 1. AJAX简介
AJAX(Asynchronous JavaScript and XML)是一种在网页上实现异步通信的技术。通过…