亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue實(shí)現(xiàn)數(shù)字+英文字母組合鍵盤功能

 更新時(shí)間:2023年12月07日 10:45:29   作者:明思齊  
這篇文章主要介紹了vue實(shí)現(xiàn)數(shù)字+英文字母組合鍵盤功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

  完整代碼

<template>
	<div class="login">
        <div @click="setFileClick">歡迎使用員工自助終端</div>
		<el-dialog title="初始化設(shè)置文件打印消耗品配置密碼" :visible.sync="dialogSetFile" width="600px">
			<el-form :model="fileForm" ref="fileForm" status-icon label-width="100px">
				<el-form-item label="密碼" prop="password">
					<el-input type="password" v-model="fileForm.password" show-password @focus="ifWritePopUp = true"></el-input>
				</el-form-item>
				<div class="screen-sign-mid" style="display: none;">
					<div class="screen-sign-mid-inner">
						<input class="self-el-input" type="text" v-model="password" ref="passwordInput" />
						<button class="self-el-button" type="button" @click.stop="checkIn()">確認(rèn)</button>
					</div>
				</div>
				<!-- 鍵盤組件開始 -->
				<div class="keyboard-wrap" v-show="ifWritePopUp">
				  <div class="key-group-item" v-for="(keyItem, index) in keyList" :key="index">
					<div class="key-item" :style="item.type == 'letter' ? '' : 'width:135px;'" v-for="(item, index) in keyItem" :key="index" :data-type="item.type" @click.stop="keyboardClick">
					  <span class="vertical-center">{{ item.text }}</span>
					</div>
				  </div>
				</div>
				<div style="text-align: center;">
				    <el-button type="primary" @click="submitForm" icon="el-icon-check">提交</el-button>
					<el-button @click="resetForm" icon="el-icon-delete">重置</el-button>
				</div>
			</el-form>
		</el-dialog>
	</div>
</template>
<script>
	import { queryInitializeFile, initPassword } from "@/api/setFile";
	export default {
		data() {
			return {
				clickCount: 0, //點(diǎn)擊次數(shù)
				dialogSetFile: false, //初始化文件配置
				ifInitialize: '', //是否初始化
				fileForm: {
					password: '',
				},
				ifWritePopUp: false,
				password: "", //鍵盤輸入內(nèi)容
				keyList: [
					// 鍵盤布局
					[{ text: "1",type: "digit"},{ text: "2",type: "digit"},
					 { text: "3",type: "digit"},{ text: "4",type: "digit"},
					 { text: "5",type: "digit"},{ text: "6",type: "digit"},
					 { text: "7",type: "digit"},{ text: "8",type: "digit"},
					 { text: "9",type: "digit"},{ text: "0",type: "digit"}],
					[{text: "Q",type: "digit"},{text: "W",type: "digit"},
					 {text: "E",type: "digit"},{text: "R",type: "digit"},
					 {text: "T",type: "digit"},{text: "Y",type: "digit"},
					 {text: "U",type: "digit"},{text: "I",type: "digit"},
					 {text: "O",type: "digit"},{text: "P",type: "digit"}],
					[{text: "A",type: "digit"},{text: "S",type: "digit"},
					 {text: "D",type: "digit"},{text: "F",type: "digit"},
					 {text: "G",type: "digit"},{text: "H",type: "digit"},
					 {text: "J",type: "digit"},{text: "K",type: "digit"},
					 {text: "L",type: "digit"}],
					[{text: "Z",type: "digit"},{text: "X",type: "digit"},
					 {text: "C",type: "digit"},{text: "V",type: "digit"},
					 {text: "B",type: "digit"},{text: "N",type: "digit"},
					 {text: "M",type: "digit"}],
					[{text: "回刪",type: "delete"},],
				],
			};
		},
		methods: {
			// 處理鍵盤事件
			keyboardClick(event) {
				let text = event.currentTarget.innerText;
				let type = event.currentTarget.getAttribute("data-type");
				switch (type) {
					case "digit":
						this.password += text;
						this.fileForm.password = this.password;
						break;
					case "delete":
						this.password = this.password.substr(0, this.password.length - 1);
						this.fileForm.password = this.password
						break;
				}
				this.$refs.passwordInput.focus();
			},
			checkIn() {
				if (this.password == "") {
					this.$refs["passwordInput"].focus();
					return;
				}
				this.password = "";
				this.ifWritePopUp = false
			},
			//點(diǎn)擊事件
			setFileClick() {
				this.clickCount += 1; // 每次點(diǎn)擊增加計(jì)數(shù)器的值
				this.fileForm = {}
				if (this.clickCount === 5) {
					//檢查是否要初始化設(shè)置文件打印消耗品配置的密碼
					queryInitializeFile().then((res) => {
						if (res && res.code === 200) {
							this.clickCount = 0
							this.ifInitialize = res.data
							//true初始化設(shè)置文件打印消耗品配置的密碼
							if (this.ifInitialize === true) {
								this.dialogSetFile = true
								this.password = ""
								this.ifWritePopUp = true
							}
						} else {
							this.$message.error(res.msg);
						}
					})
				}
			},
			//提交按鈕
			submitForm() {
				if (!this.fileForm.password) {
					this.$message.warning('請(qǐng)輸入密碼');
					return;
				}
				// 密碼正則表達(dá)式
				const passwordRegex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{6,8}$/;
				if (!passwordRegex.test(this.fileForm.password)) {
					this.$message.warning('密碼由數(shù)字和英文字母組成,且長(zhǎng)度為6~8位');
					return;
				}
				//初始化設(shè)置文件打印消耗品配置密碼
				initPassword(this.fileForm.password).then((res) => {
					if (res && res.code == 200) {
						this.clickCount = 0
						this.$message.success(res.msg);
						this.dialogSetFile = false
					} else {
						this.$message.error(res.msg);
					}
				});
			},
			//密碼清空重置
			resetForm() {
				this.password = ''
				this.fileForm = {}
			},
		},
	};
</script>
<style lang="less" scoped>
	.login {
		padding-top: 80px;
	}
	.screen-sign-mid {
	  position: relative;
	  width: 100%;
	  height: 80px;
	  padding: 3px;
	  box-sizing: border-box;
	  background-color: #eee;
	  color: #34592d;
	}
	.screen-sign-mid .screen-sign-mid-inner {
	  width: 100%;
	  height: 100%;
	  position: relative;
	  box-sizing: border-box;
	}
	.self-el-input {
	  display: inline-block;
	  width: 78%;
	  height: 80%;
	  padding: 0 100px 0 15px;
	  font-size: 26px;
	  color: #000;
	  border: 2px solid #35b9ff;
	  border-radius: 10px;
	  -webkit-appearance: none;
	  background-color: #eee;
	  background-image: none;
	  -webkit-box-sizing: border-box;
	  box-sizing: border-box;
	  -webkit-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
	  transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
	  outline: 0;
	}
	.self-el-button {
	  display: inline-block;
	  position: absolute;
	  top: 2px;
	  right: 2px;
	  width: 100px;
	  height: 56px;
	  margin: 0;
	  font-size: 22px;
	  border-radius: 10px;
	  border: 2px solid #35b9ff;
	  color: #fff;
	  background-color: #35b9ff;
	}
	.keyboard-wrap {
	  width: 100%;
	  box-sizing: border-box;
	}
	.keyboard-wrap .key-group-item {
	  width: 100%;
	  height: auto;
	  text-align: center;
	}
	.key-group-item .key-item {
	  display: inline-block;
	  position: relative;
	  width: 50px;
	  height: 50px;
	  line-height: 50px;
	  margin: 0 2px 8px 2px;
	  color: #000;
	  font-size: 20px;
	  box-sizing: border-box;
	  -webkit-border-radius: 3px;
	  -moz-border-radius: 3px;
	  border-radius: 15px;
	  background-color: #dedede;
	  -webkit-user-select: none;
	  -moz-user-select: none;
	  -ms-user-select: none;
	  user-select: none;
	  cursor: pointer;
	}
</style>

代碼詳解 

1.鍵盤界面是根據(jù)keyList數(shù)組中定義的內(nèi)容動(dòng)態(tài)生成的。

  • 我在外層使用了v-show="ifWritePopUp"來控制鍵盤界面的顯示與隱藏。
  • 通過v-for="(keyItem, index) in keyList" :key="index"遍歷keyList數(shù)組,生成多個(gè)key-group-item,每個(gè)key-group-item代表一行鍵位。
  • 在每個(gè)key-group-item內(nèi)部,再次通過v-for="(item, index) in keyItem" :key="index"遍歷keyItem數(shù)組,生成具體的按鍵元素。
  • 每個(gè)按鍵元素使用:style屬性來動(dòng)態(tài)設(shè)置樣式,根據(jù)item.type的值來確定是否為字母鍵位,從而動(dòng)態(tài)設(shè)置寬度。
  • 通過:data-type="item.type" @click.stop="keyboardClick"將按鍵的類型和點(diǎn)擊事件綁定到對(duì)應(yīng)的DOM元素上。

上圖所示方法,主要用于處理用戶在虛擬鍵盤上的點(diǎn)擊操作,動(dòng)態(tài)更新密碼輸入框中的內(nèi)容,并保持輸入焦點(diǎn)的流暢切換

  • 當(dāng)用戶點(diǎn)擊鍵盤上的按鍵時(shí),觸發(fā)keyboardClick方法,同時(shí)將事件對(duì)象event作為參數(shù)傳入
  • 通過event.currentTarget獲取被點(diǎn)擊的按鍵元素,然后分別獲取該按鍵的文本內(nèi)容和數(shù)據(jù)類型;
  • 根據(jù)被點(diǎn)擊的按鍵的數(shù)據(jù)類型,判斷是字母鍵還是刪除鍵,并進(jìn)行相應(yīng)的邏輯處理:
    • 若是字母鍵,則將該字母添加到密碼輸入框中,并更新fileForm.password的值;
    • 若是刪除鍵,則從密碼輸入框中刪除最后一個(gè)字符,并更新fileForm.password的值

  • 最后,調(diào)用this.$refs.passwordInput.focus()將焦點(diǎn)重新定位到密碼輸入框,以便繼續(xù)執(zhí)行輸入或刪除操作。

        我在這邊設(shè)置了CSS樣式屬性display: none;可以使元素不顯示在頁面上(即隱藏)。這意味著該元素將不會(huì)占據(jù)任何空間,并且無法通過直接的交互方式與用戶進(jìn)行互動(dòng)。

  @click.stop是Vue中阻止事件冒泡的指令(防止該事件繼續(xù)向上傳播,避免重復(fù)執(zhí)行相同的事件處理函數(shù))。它可以通過在事件處理函數(shù)中使用event.stopPropagation()方法來停止事件向父級(jí)元素傳播。

        簡(jiǎn)單來說,當(dāng)用戶在元素上點(diǎn)擊鼠標(biāo)時(shí),會(huì)觸發(fā)該元素的點(diǎn)擊事件,并向父級(jí)元素依次傳播。如果在某個(gè)父級(jí)元素上綁定了相同類型的事件處理函數(shù),則該函數(shù)也會(huì)被調(diào)用。

數(shù)字+英文字母鍵盤效果圖展示

        未設(shè)置style="display: none;",隱藏輸入框和確認(rèn)按鈕的效果圖     

OVER!!! 

到此這篇關(guān)于vue中實(shí)現(xiàn)數(shù)字+英文字母組合鍵盤的文章就介紹到這了,更多相關(guān)vue數(shù)字鍵盤內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue實(shí)現(xiàn)動(dòng)態(tài)樣式的多種方法匯總

    Vue實(shí)現(xiàn)動(dòng)態(tài)樣式的多種方法匯總

    本文要給大家介紹Vue實(shí)現(xiàn)動(dòng)態(tài)樣式的多種方法,下面給大家?guī)韼讉€(gè)案列,需要的朋友可以借鑒研究一下。
    2021-06-06
  • vue3中unplugin-auto-import自動(dòng)引入示例代碼

    vue3中unplugin-auto-import自動(dòng)引入示例代碼

    unplugin-auto-import 這個(gè)插件是為了解決在開發(fā)中的導(dǎo)入問題,下面這篇文章主要給大家介紹了關(guān)于vue3中unplugin-auto-import自動(dòng)引入的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • VUE使用localstorage和sessionstorage實(shí)現(xiàn)登錄示例詳解

    VUE使用localstorage和sessionstorage實(shí)現(xiàn)登錄示例詳解

    這篇文章主要為大家介紹了VUE使用localstorage和sessionstorage實(shí)現(xiàn)登錄示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • 通過vue刷新左側(cè)菜單欄操作

    通過vue刷新左側(cè)菜單欄操作

    這篇文章主要介紹了通過vue刷新左側(cè)菜單欄操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • 如何在vue3中使用滑塊檢驗(yàn)vue-puzzle-verification

    如何在vue3中使用滑塊檢驗(yàn)vue-puzzle-verification

    這篇文章主要介紹了在vue3中使用滑塊檢驗(yàn)vue-puzzle-verification的相關(guān)資料,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-11-11
  • vue create、vue webpack init創(chuàng)建vue項(xiàng)目產(chǎn)生的項(xiàng)目文件的區(qū)別

    vue create、vue webpack init創(chuàng)建vue項(xiàng)目產(chǎn)生的項(xiàng)目文件的區(qū)別

    這篇文章主要介紹了vue create、vue webpack init創(chuàng)建vue項(xiàng)目產(chǎn)生的項(xiàng)目文件的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue中tinymce富文本功能配置詳解

    Vue中tinymce富文本功能配置詳解

    TinyMCE是一款易用、且功能強(qiáng)大的所見即所得的富文本編輯器,跟其他富文本編輯器相比,有著豐富的插件,支持多種語言,能夠滿足日常的業(yè)務(wù)需求并且免費(fèi),本文小編給大家詳細(xì)介紹了Vue中tinymce富文本功能配置,需要的朋友可以參考下
    2023-11-11
  • 詳解Vue如何將多個(gè)空格被合并顯示成一個(gè)空格

    詳解Vue如何將多個(gè)空格被合并顯示成一個(gè)空格

    這篇文章主要為大家詳細(xì)介紹了在Vue中如何將多個(gè)空格被合并顯示成一個(gè)空格,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-04-04
  • 詳解如何在Vue3中捕獲和處理錯(cuò)誤

    詳解如何在Vue3中捕獲和處理錯(cuò)誤

    Vue 3 作為前端開發(fā)中一個(gè)非常流行的框架,在錯(cuò)誤處理方面提供了靈活和強(qiáng)大的能力,本文將深入介紹在 Vue 3 中如何捕獲和處理錯(cuò)誤,包括組件級(jí)的錯(cuò)誤處理、全局錯(cuò)誤處理以及如何與異常日志系統(tǒng)集成,需要的朋友可以參考下
    2024-07-07
  • 詳解webpack+vue-cli項(xiàng)目打包技巧

    詳解webpack+vue-cli項(xiàng)目打包技巧

    本篇文章主要介紹了詳解webpack+vue-cli項(xiàng)目打包技巧 ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06

最新評(píng)論