当前位置: 首页 > news >正文

Vue2移动端(H5项目)项目封装车牌选择组件

一、最终效果

在这里插入图片描述

二、参数配置

1、代码示例:

<t-keyword:isShow="isShow"@ok="isShow=false"@cancel="isShow=false"@inputchange="inputchange":finalValue="trailerNo"/>

2、配置参数(TKeyword Attributes)的属性

参数说明类型默认值
isShow是否弹起键盘Booleanfalse
cancelColor取消字体颜色String#2072ED
confirmColor确认背景颜色String#2072ED
isShowMask是否显示遮罩Booleantrue
isClickMask是否点击遮罩关闭键盘Booleantrue
maxLength最大输入长度Number8
finalValue最终显示的值 (下拉框顶部)String-

3、events 事件

事件名说明返回值
inputchange选中车牌键盘选中的值和最大输入长度
cancel点击取消按钮时触发-
ok点击确定按钮时触发-
delete点击键盘清除键,-

三、具体页面使用

<template><div class="start_judging_scrap_steel"><van-fieldv-model="trailerNo"centerclearablelabel="车牌号"@focus="isShow=true"placeholder="请输入车牌号"/><t-keyword:isShow="isShow"@ok="isShow=false"@cancel="isShow=false"@inputchange="inputchange":finalValue="trailerNo"/></div>
</template>
<script>
export default {name: 'startJudgingScrapSteel',data() {return {isShow: false,trailerNo: '', // 车牌号}},methods: {// 输入车牌号inputchange(val, maxLength) {if (this.trailerNo.length >= maxLength && val !== 'delete') {return false}if (val === 'delete') {this.trailerNo = this.trailerNo.slice(0, this.trailerNo.length - 1)} else {this.trailerNo += val.toUpperCase()}},},
};
</script>

三、源码

<template><div class="panel-wrap" v-if="isShow" data-value="exit" @click="colse_da"><div class="mask_layer" v-if="isShowMask"></div><div class="vehicle-panel" :style="{background:backgroundColor}" @click.stop><div class="topItem"><div class="check" @click.stop="check">中/英切换</div><div class="contentShow" v-if="finalValue">最终值:{{finalValue}}</div><div class="exit" :style="{color:cancelColor}" @click.stop="vehicleTap('cancel')">取消</div></div><!--省份简写键盘--><div v-if="keyBoardType === 1"><div class="vehicle-panel-row_province"><divclass="vehicle-panel-row-button":style="{border:buttonBorder}"v-for="(item,idx) in keyVehicle1"@click.stop="vehicleTap(item)":key="idx+item">{{item}}</div></div><div class="vehicle-panel-row_province"><divclass="vehicle-panel-row-button":style="{border:buttonBorder}"v-for="(item,idx) in keyVehicle2"@click.stop="vehicleTap(item)":key="idx+item">{{item}}</div></div><div class="vehicle-panel-row_province"><divclass="vehicle-panel-row-button":style="{border:buttonBorder}"v-for="(item,idx) in keyVehicle3"@click.stop="vehicleTap(item)":key="idx+item">{{item}}</div></div><div class="vehicle-panel-row_province"><divclass="vehicle-panel-row-button vehicle-panel-row-button-last"@click.stop="vehicleTap(item)"v-for="(item,idx) in keyVehicle4":style="{border:buttonBorder}":key="idx+item">{{item}}</div><div:style="{border:buttonBorder}"class="vehicle-panel-row-button vehicle-panel-row-button-img"><van-iconclass="vehicle-en-button-delete"name="close"@click.stop="vehicleTap('delete')"/></div></div></div><!--英文键盘  --><div v-else><div class="vehicle-panel-row"><divclass="vehicle-panel-row-button vehicle-panel-row-button-number"@click.stop="vehicleTap(item)"v-for="(item,idx) in keyNumber":style="{border:buttonBorder}":key="item+idx">{{item}}</div></div><div class="vehicle-panel-row"><divclass="vehicle-panel-row-button":style="{border:buttonBorder}"v-for="(item,idx) in keyEnInput1"@click.stop="vehicleTap(item)":key="idx+item">{{item}}</div></div><div class="vehicle-panel-row"><divclass="vehicle-panel-row-button":style="{border:buttonBorder}"v-for="(item,idx) in keyEnInput2"@click.stop="vehicleTap(item)":key="idx+item">{{item}}</div><div:style="{border:buttonBorder}"class="vehicle-panel-row-button vehicle-panel-row-button-img"><van-iconclass="vehicle-en-button-delete"name="close"@click.stop="vehicleTap('delete')"/></div></div><div class="vehicle-panel-row-last"><divclass="vehicle-panel-row-button vehicle-panel-row-button-last"@click.stop="vehicleTap(item)":style="{border:buttonBorder}"v-for="(item,idx) in keyEnInput3":key="idx+item">{{item}}</div><div:style="{border:buttonBorder,backgroundColor:confirmColor}"class="vehicle-panel-row-button vehicle-panel-ok"@click.stop="vehicleTap('ok')">确定</div></div></div></div></div>
</template>
<script>
import variables from '@/assets/css/variables.scss'
export default {name: 'TKeyword',props: {// 是否弹起键盘isShow: {type: Boolean,default: false},// 取消字体颜色cancelColor: {type: String,default: `#2072ED`},// 是否显示遮罩isShowMask: {type: Boolean,default: true},// 是否点击遮罩关闭键盘isClickMask: {type: Boolean,default: true},// 最大输入长度maxLength: {type: Number,default: 8},// 确认背景颜色confirmColor: {type: String,default: `#2072ED`},// 最终显示的值finalValue: {type: String}},data() {return {keyVehicle1: ['京', '津', '晋', '冀', '蒙', '辽', '吉', '黑', '沪'],keyVehicle2: ['苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘'],keyVehicle3: ['粤', '桂', '琼', '渝', '川', '贵', '云', '藏'],keyVehicle4: ['陕', '甘', '青', '宁', '新', 'W'],keyNumber: '1234567890',keyEnInput1: 'QWERTYUP', // 没有IOkeyEnInput2: 'ASDFGHJKL',keyEnInput3: 'ZXCVBNM',backgroundColor: '#fff',keyBoardType: 1,buttonBorder: '1px solid #ccc'}},methods: {vehicleTap(event) {console.log(event)if (/^[\u4e00-\u9fa5]/.test(event)) {this.keyBoardType = 2}switch (event) {case 'delete':this.$emit('delete')this.$emit('inputchange', event, this.maxLength)breakcase 'ok':this.$emit('ok')breakcase 'cancel':this.$emit('cancel')breakdefault:this.$emit('inputchange', event, this.maxLength)}},// 点击遮罩关闭键盘mask-layercolse_da() {if (!this.isClickMask) {return}this.$emit('cancel')},check() {if (this.keyBoardType === 1) {this.keyBoardType = 2} else if (this.keyBoardType === 2) {this.keyBoardType = 1}}}
}
</script><style lang="scss" scoped>
:host {width: 100%;
}.panel-wrap {position: fixed;top: 0;left: 0;right: 0;bottom: 0;z-index: 9999;.mask_layer {position: absolute;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0, 0, 0, 0.5);}.vehicle-panel {width: 100%;position: fixed;bottom: 0;display: flex;flex-direction: column;justify-content: center;z-index: 1000;background: #fff;padding-bottom: 10px;}.vehicle-panel-row_province {display: flex;justify-content: center;align-items: center;}.vehicle-panel-row {display: flex;justify-content: space-between;align-items: center;}.vehicle-panel-row-last {display: flex;justify-content: space-between;align-items: center;}.vehicle-panel-row-button {background-color: #fff;margin: 0 1vw;margin-top: 8px;width: 8.8vw;height: 40px;border-radius: 5px;display: flex;justify-content: center;align-items: center;}.vehicle-panel-row-button-number {background-color: #eee;}.vehicle-panel-row-button-last {width: 8.8vw;height: 40px;display: flex;justify-content: center;align-items: center;}.vehicle-hover {background-color: #ccc;}.vehicle-panel-row-button-img {display: flex;justify-content: center;align-items: center;}.vehicle-en-button-delete {width: 8.8vw;height: 40px;display: flex;justify-content: center;align-items: center;}.vehicle-panel-ok {background-color: #355db4;color: #fff;width: 50px;height: 40px;font-size: 16px;display: flex;justify-content: center;align-items: center;}.topItem {display: flex;justify-content: space-between;align-items: center;height: 40px;font-size: 16px;border: 1px solid #ebedf0;.check {margin-left: 10px;color: #355db4;flex: 0.5;}.exit {margin-left: 0;margin-right: 10px;flex: 0.5;text-align: right;}.contentShow {text-align: center;flex: 1;}}
}
</style>

相关文章

基于ElementUi再次封装基础组件文档


基于ant-design-vue再次封装基础组件文档


vue3+ts基于Element-plus再次封装基础组件文档

http://www.lryc.cn/news/429531.html

相关文章:

  • 四川财谷通信息技术有限公司抖音小店的优势
  • 2025届八股文:计算机网络高频重点面试题
  • 嵌入式和单片机有什么区别?
  • JSON.stringify 和 JSON.parse
  • APP架构设计_2.用MVVM架构实现一个具体业务
  • 安恒信息总裁宋端智,辞职了!活捉一枚新鲜出炉的餐饮人!
  • 《javaEE篇》--定时器
  • OpenLayers3, 缩放、平移、复位操作
  • 进程与线程(7)
  • 传知代码-自动化细胞核分割与特征分析(论文复现)
  • Vue UI - 可视化的Vue项目管理器
  • 团队管理之敏捷开发
  • Hive3:表的常用修改语句
  • MidJourney付费失败的原因以及失败后如何取消或续订(文末附MidJourney,GPT-4o教程)
  • PHP安全开发
  • 【大模型从入门到精通32】开源库框架LangChain RAG 系统中的问答技术2
  • MySQL 数据库管理
  • 屏幕录制了一个视频,发现有些部分是不需要的,那么我们就用到视频剪辑的工具,利用必剪去删除中间的一部分视频,并且导出,然后利用格式工厂去压缩mp4文件的过程。
  • 代码随想录跟练第六天——LeetCode
  • 【Qt】常用控件QCalendarWidget的使用
  • Nginx: 配置项之main段核心参数用法梳理
  • 密码学之RSA算法
  • 教你学习企业高性能web服务器-nginx
  • 封装通用第三方平台用户表(微信开放平台)
  • 【C++】_string类字符串详细解析(1)
  • 【Linux】——进程概念(万字解读)
  • 03 serv00搭建WordPress
  • 伪共享问题如何解决?
  • 基于web框架的协同过滤的美食推荐系统【数据爬虫、管理系统、数据可更新、样式可调整】
  • Eureka中的多实例配置:如何处理微服务实例动态扩展与缩减