vue h5實現車牌號輸入框

哈嘍,大家好,最近鵬仔開發的項目是學校校內車輛超速方面的統計檢測方面的系統,在開發過程中發現有個小功能,就是用戶移動端添加車牌號,剛開始想著就一個輸入框,提交時正則效驗一下格式就行,最后感覺不是很方便,所以就簡單自己手寫了一個H5車牌號軟鍵盤,由于每天工作比較忙,就沒封裝成插件了,趁著晚上空閑,給大家整理一下demo,復制即可使用,或者自行封裝一個組件調用也可以(代碼中一些寫法可能過于粗糙,時間有限,任務多,就粗糙寫一下吧,反正功能是實現了)。

功能如上圖所示,支持 8位電車車牌和7位油車車牌。

第一位是 省份,用戶點擊就會彈出省份軟鍵盤;

第二位是 字母,用戶點擊只能輸入字母;

第三、四、五、六位是字母和數字,不包含O;

第七位是 數字、字母、或者學、警之類漢字;

第八位是 電車選項。

用戶點擊軟鍵盤對應的按鍵時會高亮,這個是后期加的,所以上圖中沒有展示出來。

鵬仔的移動端是rem布局,根元素是26.67vw,如果你使用,可自行根據自己的項目將css中所有的單位變化一下。

body,div,p,ul,ol,li,dl,dt,dd,table,tr,td,form,hr,h1,h2,h3,h4,h5,h6,fieldset,img,input {margin:0;padding:0}
body,html {width:100%;height:100%;font-size: 26.67vw;}

完整代碼如下

<template><div class="layer"><!-- content --><div class="content-layer"><div class="my-car-layer"><!-- 添加車輛 --><div class="my-car-layer-add" @click="addShow = true"><div class="add-text"><p>添加車輛</p></div></div></div></div><!-- 添加車輛彈窗 --><div class="shade-layer" v-if="addShow" @click="keyboardShow = false"><div class="add-content"><div class="add-header"><p>車輛信息</p><span @click="addShow = false">關閉</span></div><div class="form-list"><p>車牌號:</p><div class="car-num-input"><div v-for="(item,index) in carNumList" :key="index" @click.stop="selectCarNum(index)" :class="(carIndex == index ? 'active' : '') + ' ' + (item ? 'status-key' : '')">{{ index == 0 && !item ? '省' : index == carNumList.length-1 && !item ? '新能源' : item }}</div></div></div><button class="submit-btn" @click="carSubmitBtn()" v-points>提交</button></div><!-- 車牌鍵盤 --><div class="keyboard-layer" v-if="keyboardShow" @click.stop=""><div class="keyboard-header"><span @click="keyboardShow = false">完成</span></div><!-- 省份鍵盤 --><div class="province-layer" v-if="carIndex == '0'"><span v-for="(item,index) in provinceList" :key="index" @click="keyboardBtn(item)" :class="activeKey == item ? 'active-hover' : ''">{{ item == 'del' ? '刪除' : item }}</span></div><!-- 數字字母鍵盤 --><div class="keyboard-item" v-if="carIndex != '0'"><div v-if="carIndex != '1'"><span v-for="(item,index) in keyboardList[0]" :key="index" @click="keyboardBtn(item)" :class="activeKey == item ? 'active-hover' : ''">{{ item }}</span></div><div><span v-for="(item,index) in keyboardList[1]" :key="index" @click="keyboardBtn(item)" :class="((item == 'O' && carIndex != '1') ? 'no-btn' : '') + ' ' + (activeKey == item ? 'active-hover' : '')">{{ item }}</span></div><div><span v-for="(item,index) in keyboardList[2]" :key="index" @click="keyboardBtn(item)" :class="activeKey == item ? 'active-hover' : ''">{{ item }}</span></div><div><span v-for="(item,index) in keyboardList[3]" :key="index" @click="keyboardBtn(item)" :class="activeKey == item ? 'active-hover' : ''">{{ item == 'del' ? '刪除' : item }}</span></div><div v-if="carIndex == carNumList.length-2"><span v-for="(item,index) in keyboardList[4]" :key="index" @click="keyboardBtn(item)" :class="activeKey == item ? 'active-hover' : ''">{{ item }}</span></div></div></div></div></div>
</template>
<script>
export default {name: "car",mixins: [],components: {},data() {return {addShow: false, // 添加車輛彈窗顯示隱藏formData: {carNumber: ''},carNumList: ['','','','','','','',''], // 車牌號數組activeKey: '', // 鍵盤按鍵選中激活timeoutId: null, // 定時器IDcarIndex: null, // 車牌號輸入光標索引keyboardShow: false, // 鍵盤顯示/隱藏provinceList: ['京', '津', '滬', '渝', '冀', '豫', '云', '遼', '黑', '湘','皖', '魯', '新', '蘇', '浙', '贛', '鄂', '桂', '甘', '晉','蒙', '陜', '吉', '閩', '貴', '粵', '青', '藏', '川', '寧','瓊', '使', '領', '學', '警', '掛', 'del'],keyboardList: [['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P'],['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],['Z', 'X', 'C', 'V', 'B', 'N', 'M', 'del'],['學','警','港','澳']]};},mounted() {},methods: {// 添加車輛carSubmitBtn(){this.formData.carNumber = '';for(let i in this.carNumList){if(this.carNumList[i] == '' && i != this.carNumList.length-1){console.log('請輸入完整車牌號');return;}this.formData.carNumber += this.carNumList[i];}console.log(this.formData.carNumber)},// 點擊車牌號輸入selectCarNum(inx){this.carIndex = inx;if(!this.keyboardShow){this.keyboardShow = true;}},// 鍵盤輸入keyboardBtn(val){this.activeKey = val; // 鍵盤按鍵選中激活this.activeKeyBtn(); // 鍵盤按鍵激活定時器this.carNumList[this.carIndex] = val == 'del' ? '' : val;if(val == 'del' && this.carIndex > 0){this.carIndex--;}if(val != 'del' && this.carIndex < this.carNumList.length-1){this.carIndex++;}this.$forceUpdate();},// 鍵盤按鍵激活定時器activeKeyBtn() {// 清除之前的定時器if (this.timeoutId) clearTimeout(this.timeoutId)// 1秒后重置狀態this.timeoutId = setTimeout(() => {this.activeKey = '';}, 300)}},watch: {"addShow"(){// 關閉彈窗時重置if(!this.addShow){this.formData = {carNumber: ''}this.carIndex = ''; // 車牌號輸入光標索引this.carNumList = ['','','','','','','','']; // 車牌號數組this.keyboardShow = false; // 車牌鍵盤隱藏}}},
};
</script>
<style lang="scss" scoped>
.layer {padding: 0.22rem 0 0.64rem;box-sizing: border-box;.content-layer {width: 100%;position: relative;padding: 0 0.16rem;box-sizing: border-box;.my-car-layer{width: 100%;.my-car-layer-add{width: 100%;padding: 0.14rem 0.16rem;box-sizing: border-box;border-radius: 0.08rem;background: #FFF;display: flex;flex-direction: column;align-items: center;justify-content: center;.add-text{width: 100%;display: flex;align-items: center;justify-content: center;padding-top: 0.04rem;box-sizing: border-box;p{color: #2E59FD;font-family: "PingFang SC";font-size: 0.14rem;font-weight: 700;line-height: 0.2rem;}}}}}.shade-layer{position: fixed;top: 0;left: 0;z-index: 5;width: 100%;height: 100%;background: rgba(0,0,0,.4);padding: 0.16rem;box-sizing: border-box;display: flex;align-items: center;justify-content: center;.add-content{width: 100%;padding: 0.16rem 0.16rem 0.24rem;box-sizing: border-box;border-radius: 0.16rem;background: #FFF;.add-header{width: 100%;display: flex;align-items: center;justify-content: space-between;padding-bottom: 0.14rem;box-sizing: border-box;p{color: #000;font-family: "PingFang SC";font-size: 0.16rem;font-weight: 700;line-height: 0.22rem;}span{color: #0A61C5;font-family: "PingFang SC";font-size: 0.12rem;font-weight: 700;line-height: 0.24rem;cursor: pointer;}}.form-list{p{color: #6B7280;font-family: "PingFang SC";font-size: 0.14rem;font-weight: 500;line-height: 0.2rem;}input{display: block;font-size: 0.14rem;line-height: 0.2rem;width: 100%;border-radius: 0.08rem;border: none;background: #F5F7FA;padding: 0.12rem 0.16rem;box-sizing: border-box;}.car-num-input{width: 100%;display: flex;align-items: center;justify-content: space-between;padding: 0.04rem 0;box-sizing: border-box;div{width: 0.3rem;height: 0.36rem;background: rgba(0,0,0,.05);border-radius: 0.04rem;border: 0.01rem solid transparent;box-sizing: border-box;display: flex;align-items: center;justify-content: center;color: #000;font-size: 0.14rem;line-height: 0.18rem;&:first-child{color: rgba(0,0,0,.5);}&:last-child{border: 0.01rem dashed rgba(27, 171, 80, 0.8);color: rgba(0,0,0,.5);font-size: 0.08rem;}}.active{border: 0.01rem solid rgba(48, 112, 255, 0.8)!important;}.status-key{color: #000!important;font-size: 0.14rem!important;line-height: 0.18rem!important;}}}.submit-btn{display: block;width: 100%;border: none;padding: 0.06rem 0.1rem;box-sizing: border-box;border-radius: 0.52rem;background: linear-gradient(90deg, #0FA6F6 1.1%, #198CFE 99.99%);color: #FFF;text-align: center;font-family: "PingFang SC";font-size: 0.16rem;font-weight: 700;line-height: 0.24rem;margin-top: 0.24rem;}}.keyboard-layer{width: 100%;background: #D0D5DC;padding: 0.08rem 0.04rem 0.16rem;box-sizing: border-box;position: absolute;bottom: 0;left: 0;.keyboard-header{width: 100%;display: flex;align-items: center;justify-content: flex-end;padding: 0 0.08rem 0.08rem;box-sizing: border-box;span{color: #2E59FD;font-family: "PingFang SC";font-size: 0.14rem;font-weight: 700;line-height: 0.28rem;cursor: pointer;}}.province-layer{width: 100%;display: flex;align-items: center;justify-content: center;flex-wrap: wrap;span{color: #000;font-size: 0.14rem;line-height: 0.28rem;background: #fff;border-radius: 0.06rem;padding: 0.06rem 0.08rem;box-sizing: border-box;margin: 0.02rem;box-shadow: 0px 0.02rem 0.02rem 0px rgba(0, 0, 0, 0.1);}}.keyboard-item{width: 100%;div{display: flex;align-items: center;justify-content: center;span{color: #000;font-size: 0.14rem;line-height: 0.28rem;background: #fff;border-radius: 0.06rem;padding: 0.04rem 0.1rem;box-sizing: border-box;margin: 0.04rem;box-shadow: 0px 0.02rem 0.04rem 0px rgba(0, 0, 0, 0.3);}}}.no-btn{color: rgba(0,0,0,.4)!important;pointer-events: none;}.active-hover{background: #B3BAC7!important;}}}
}
</style>

原文:共享博客 sharedbk.comvue h5實現車牌號輸入框哈嘍,大家好,最近鵬仔開發的項目是學校校內車輛超速方面的統計檢測方面的系統,在開發過程中發現有個小功能,就是用戶移動端添加車牌號,剛開始想著就一個輸入框,提交時正則效驗一下格式就行,最后感覺不是很方便,所以就簡單自己手寫了一個H5車牌號軟鍵盤,由于每天工作比較忙,就沒封...,共享博客-(百變鵬仔)https://www.sharedbk.com/post/284.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/73398.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/73398.shtml
英文地址,請注明出處:http://en.pswp.cn/web/73398.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

硬件基礎(5):(3)二極管的應用

文章目錄 [toc]1. **整流電路****功能**&#xff1a;**工作原理**&#xff1a;**應用實例**&#xff1a;電路組成&#xff1a;整流過程&#xff1a;電路的應用&#xff1a; 2. **穩壓電路****功能**&#xff1a;**工作原理**&#xff1a;**應用實例**&#xff1a;電路組成及功能…

Wireshark網絡抓包分析使用詳解

序言 之前學計網還有前幾天備考華為 ICT 網絡賽道時都有了解認識 Wireshark&#xff0c;但一直沒怎么專門去用過&#xff0c;也沒去系統學習過&#xff0c;就想趁著備考的網絡相關知識還沒忘光&#xff0c;先來系統學下整理點筆記~ 什么是抓包&#xff1f;抓包就是將網絡傳輸…

安心聯車輛管理平臺源碼價值分析

安心聯車輛管理平臺源碼的價值可從技術特性、功能覆蓋、市場適配性、擴展潛力及商業化支持等多個維度進行分析。以下結合實際應用進行詳細解讀&#xff1a; 一、技術架構與開發優勢 主流技術棧與高性能架構 源碼采用成熟的前后端分離架構&#xff0c;后端基于Java技術&#xff…

【操作系統】Docker如何使用-續

文章目錄 1、概述2、鞏固知識2.1、基礎命令2.2、容器管理2.3、鏡像管理2.4、網絡管理2.5、Compose 3、常用命令 1、概述 在使用Docker的過程中&#xff0c;掌握常用的命令是至關重要的。然而&#xff0c;隨著時間的推移&#xff0c;我們可能會遺忘一些關鍵的命令或對其用法變得…

ElementUI el-menu導航開啟vue-router模式

有沒有小伙伴遇到這么一種情況&#xff1a;ElementUI el-menu導航中&#xff0c;開啟vue-router 的模式后&#xff0c;點擊觸發事件而不進行路由跳轉&#xff1f; 別慌&#xff01;下面直接說解決方案&#xff1a; 借助路由守衛進行判斷 給el-menu綁定切換事件&#xff0c;給…

【leetcode hot 100 17】電話號碼的字母組合

分析&#xff1a;當設計關鍵字“所有組合”時&#xff0c;要考慮深度優先遍歷、廣度優先遍歷&#xff08;層次遍歷&#xff09;&#xff0c;其中&#xff1a; 深度優先搜索&#xff1a; 自頂向下的遞歸實現深搜定義子問題在當前遞歸層結合子問題結果解決原問題 廣度優先搜索 利…

Vue 2 探秘:visible 和 append-to-body 是誰的小秘密?

&#x1f680; Vue 2 探秘&#xff1a;visible 和 append-to-body 是誰的小秘密&#xff1f;&#x1f914; 父組件&#xff1a;identify-list.vue子組件&#xff1a;fake-clue-list.vue 嘿&#xff0c;各位前端探險家&#xff01;&#x1f44b; 今天我們要在 Vue 2 的代碼叢林…

C++學習之路:從頭搞懂配置VScode開發環境的邏輯與步驟

目錄 編輯器與IDE基于vscode的C開發環境配置1. 下載vscode、淺嘗編譯。番外篇 2. 安裝插件&#xff0c;賦能編程。3. 各種json文件的作用。c_cpp_properties.jsontask.jsonlaunch.json 總結&&彩蛋 編輯器與IDE 上一篇博客已經介紹過了C程序的一個編譯流程&#xff0c;從…

PPT 轉高精度圖片 API 接口

PPT 轉高精度圖片 API 接口 文件處理 / 圖片處理&#xff0c;將 PPT 文件轉換為圖片序列。 1. 產品功能 支持將 PPT 文件轉換為高質量圖片序列&#xff1b;支持 .ppt 和 .pptx 格式&#xff1b;保持原始 PPT 的布局和樣式&#xff1b;轉換后的圖片支持永久訪問&#xff1b;全…

VSCode 抽風之 兩個conda環境同時在被激活

出現了神奇的(toolsZCH)(base) 提示符&#xff0c;如下圖所示&#xff1a; 原因大概是&#xff1a;conda 環境的雙重激活&#xff1a;可能是 conda 環境沒有被正確清理或初始化&#xff0c;導致 base 和 toolsZCH 同時被激活。 解決辦法就是 &#xff1a;conda deactivate 兩次…

git | 回退版本 并保存當前修改到stash,在進行整合。[git checkout | git stash 等方法 ]

目錄 一些常見命令&#xff1a; git 回退版本 一、臨時回退&#xff08;不會修改歷史&#xff0c;可隨時回到當前版本&#xff09; 方法1&#xff1a;git checkout HEAD~1 問題&#xff1a;處于 detached HEAD 狀態下提交的&#xff0c;無法直接 git push ? 選項 1&…

如何使用 Postman 進行接口測試?

使用 Postman 這一工具&#xff0c;可以輕松地進行接口測試。以下是一份簡單的使用教程&#xff0c;幫助你快速上手。 Postman 接口測試教程&#xff1a;詳細步驟及操作技巧

寫作軟件新體驗:讓文字創作更高效

一、開篇引入:寫作難題的破解之道 在當今信息爆炸的時代,寫作成為了我們生活和工作中不可或缺的一部分。然而,面對繁瑣的寫作任務,我們時常感到力不從心,甚至陷入創作的瓶頸。那么,有沒有一款軟件能夠幫助我們破解這一難題,讓文字創作變得更加高效和輕松呢?答案是肯定…

大模型思維鏈COT:Chain-of-Thought Prompting Elicits Reasoningin Large Language Models

一、TL&#xff1b;DR 探索了COT&#xff08;chain-of-thought prompting&#xff09;通過一系列的中間推理步驟來顯著的提升了LLM的復雜推理能力在三個大型語言模型上的實驗表明&#xff0c;思維鏈提示能夠提升模型在一系列算術、常識和符號推理任務上的表現解釋了一下為什么…

systemd-networkd的配置文件的優先級 筆記250325

systemd-networkd的配置文件的優先級 systemd-networkd的配置文件優先級規則如下&#xff1a; 1. 目錄優先級 配置文件按以下目錄順序加載&#xff08;優先級從高到低&#xff09;&#xff1a; /etc/systemd/network&#xff08;用戶自定義配置&#xff0c;最高優先級&#x…

詳細說明windows系統函數::SetUnhandledExceptionFilter(ExceptionFilter)

::SetUnhandledExceptionFilter(ExceptionFilter); 是 Windows 編程中用于設置頂層未處理異常過濾器的關鍵 API 調用。它屬于 Windows 結構化異常處理&#xff08;SEH, Structured Exception Handling&#xff09;機制的一部分&#xff0c;主要用于捕獲那些未被程序內部處理的異…

決策樹算法詳解:從西瓜分類到實戰應用

目錄 0. 引言 1. 決策樹是什么&#xff1f; 1.1 生活中的決策樹 1.2 專業版決策樹 2. 如何構建決策樹&#xff1f; 2.1 關鍵問題&#xff1a;選哪個特征先判斷&#xff1f; 2.1.1 信息熵&#xff08;數據混亂度&#xff09; 2.1.2 信息增益&#xff08;劃分后的整潔度提…

超融合服務器是什么

超融合服務器的定義與背景 超融合服務器&#xff08;Hyperconverged Infrastructure, HCI&#xff09;是一種通過軟件定義技術&#xff0c;將計算、存儲、網絡和虛擬化功能整合到單一硬件平臺中的IT基礎設施解決方案。其核心目標是通過資源的高度集成和統一管理&#xff0c;簡…

【網絡層協議】NAT技術內網穿透

IP地址數量限制 我們知道&#xff0c;IP地址&#xff08;IPv4&#xff09;是一個4字節32位的整數&#xff0c;那么一共只有2^32也就是接近43億個IP地址&#xff0c;而TCP/IP協議棧規定&#xff0c;每臺主機只能有一個IP地址&#xff0c;這就意味著&#xff0c;一共只有不到43億…

時隔多年,終于給它換了皮膚,并正式起了名字

時隔多年&#xff0c;終于更新了直播推流軟件UI&#xff0c;并正式命名為FlashEncoder。軟件仍使用MFC框架&#xff0c;重繪了所有用到的控件&#xff0c;可以有效保證軟件性能&#xff0c;也便于后續進一步優化。 下載地址&#xff1a;https://download.csdn.net/download/Xi…