主頁 > 企業開發 > 前端Vue自定義發送短信驗證碼彈框popup 實作剩余秒數計數 重發短信驗證碼

前端Vue自定義發送短信驗證碼彈框popup 實作剩余秒數計數 重發短信驗證碼

2023-06-27 10:04:45 企業開發

前端Vue自定義發送短信驗證碼彈框popup 實作剩余秒數計數 重發短信驗證碼, 請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=13207

效果圖如下:

實作代碼如下:

cc-codeDialog

使用方法


<!-- show:是否顯示彈框 phone:手機號  autoCountdown:自動時間秒數 len:短信驗證碼長度 @closeClick:關閉彈框 @confirmClick:確認事件 -->

<cc-codeDialog :show="show" phone="1900000000" :autoCountdown="true" :len="6" @closeClick="closeCodeDialog" @confirmClick="confirmClick"></cc-codeDialog>

HTML代碼實作部分


<template>

<view >

<button @click="showCodeDialog" style="margin-top: 39px;">發送短信驗證碼 </button>

<!-- show:是否顯示彈框 phone:手機號  autoCountdown:自動時間秒數 len:短信驗證碼長度 @closeClick:關閉彈框 @confirmClick:確認彈框 -->

<cc-codeDialog :show="show" phone="1900000000" :autoCountdown="true" :len="6" @closeClick="closeCodeDialog"

@confirmClick="confirmClick"></cc-codeDialog>

</view>

</template>

<script>

export default {

data() {

return {

show: false

}

},

methods: {

showCodeDialog(item) {

this.show = true;

},

closeCodeDialog(item) {

this.show = false;

},

confirmClick(result) {

console.log("result = " + JSON.stringify(result));

this.show = false;

}

}

}

</script>

<style>

.content {

display: flex;

flex-direction: column;

background-color: aliceblue;

height: 100vh;

}

</style>

組件實作代碼


<template>
	<view v-if="show" >
		<view ></view>
		<view >
			<text  @click="closeDialog()"></text>
			<view >
				<view >
					<text>發送驗證碼</text>
				</view>
				<view v-if="phone!='' && phone !=null " >
					<text>已發送到手機號:{{phoneStr}}</text>
				</view>
			</view>
			<view >
				<view >
					<view v-for="(code,index) of codeAry" :key="index" >{{code.val}}</view>
				</view>
			</view>
			<view >
				<view v-if="countdown==60" @click="resend" >重新發送</view>
				<view v-if="countdown<60" >{{countdown}}s</view>
			</view>

			<button style="margin-top: 20px; width: 88%;background-color: royalblue;color: white;"
				@click="confirmClick">確定</button>
		</view>

		<view >
			<view >
				<view data-val="1" @click="bindKeyEvent" >1</view>
				<view data-val="2" @click="bindKeyEvent" >2</view>
				<view data-val="3" @click="bindKeyEvent" >3</view>
			</view>
			<view >
				<view data-val="4" @click="bindKeyEvent" >4</view>
				<view data-val="5" @click="bindKeyEvent" >5</view>
				<view data-val="6" @click="bindKeyEvent" >6</view>
			</view>
			<view >
				<view data-val="7" @click="bindKeyEvent" >7</view>
				<view data-val="8" @click="bindKeyEvent" >8</view>
				<view data-val="9" @click="bindKeyEvent" >9</view>
			</view>
			<view >
				<view data-val="clear" @click="bindKeyEvent" >清空</view>
				<view data-val="0" @click="bindKeyEvent" >0</view>
				<view data-val="delete" @click="bindKeyEvent" >x</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
			autoCountdown: {
				type: Boolean,
				default: true
			},
			phone: {
				type: String,
				default: ""
			},
			len: {
				type: Number,
				default: 6
			}
		},
		data() {
			return {
				codeAry: [{
						"val": ""
					}, {
						"val": ""
					}, {
						"val": ""
					}, {
						"val": ""
					},
					{
						"val": ""
					},
					{
						"val": ""
					}
				],
				currItem: 0,
				countdown: 60,
				cTimer: null,
				callResult: {
					type: 0,
					code: ''
				},
				suspend: false
			};
		},
		computed: {
			phoneStr() {
				return this.phone.substr(0, 3) + "****" + this.phone.substr(7);
			}
		},
		watch: {
			show: function() {
				console.log(this.show)
				if (this.show) {
					if (!this.suspend) {
						this.init();
					}
				} else {
					if (!this.suspend) {
						this.clearTimer();
					}
					this.clearCode();
				}
			}
		},
		methods: {
			init: function() {
				var codeAry = [];
				for (var i = 0; i < this.len; i++) {
					codeAry.push({
						val: ""
					})
				}
				this.codeAry = codeAry;
				this.currItem = 0;
				if (this.autoCountdown) {
					this.startTimer();
				}
			},
			bindKeyEvent: function(e) {
				var _this = this;
				var val = e.currentTarget.dataset.val;
				switch (val) {
					case "clear":
						_this.clearCode();
						break;
					case "delete":
						_this.deleteCode();
						break;
					default:
						_this.inputVal(val);
						break;
				}
			},
			inputVal: function(val) {
				if (this.currItem < this.len) {
					this.codeAry[this.currItem].val = val;
					this.currItem++;
				}
				if (this.currItem == this.len) {
					this.execuCall(1);
				}
			},
			clearCode: function() {

				this.init();
			},
			deleteCode: function() {
				if (this.currItem > 0) {
					this.codeAry[this.currItem - 1].val = "";
					this.currItem--;
				}
			},
			closeDialog: function() {
				this.execuCall(-1);
				this.$emit("closeClick");
			},
			startTimer: function() {
				var _this = this;
				if (_this.cTimer == null) {
					_this.cTimer = setInterval(function() {
						_this.countdown--;
						if (_this.countdown == 0) {
							_this.clearTimer();
						}
					}, 1000)
				}
			},
			clearTimer: function() {
				var _this = this;
				clearInterval(_this.cTimer);
				_this.cTimer = null;
				_this.countdown = 60;
			},
			getCodeValue: function() {
				var codeStr = "";
				this.codeAry.forEach(function(code) {
					codeStr += code.val;
				})
				return codeStr;
			},
			execuCall: function(type) {
				this.callResult.type = type;
				if (type == 1) {
					this.callResult.code = this.getCodeValue();
					this.clearTimer();

				} else {
					this.suspend = true;
					this.callResult.code = '';
				}
				this.$emit("change", this.callResult);
			},
			resend: function() {
				var _this = this;
				_this.callResult.code = '';
				_this.callResult.type = 0;
				// _this.callResult.resendCall = function() {

				// }
				_this.init();
				_this.$emit("change", _this.callResult);

			},

			confirmClick() {


				console.log("result = " + JSON.stringify(this.callResult));

				if (this.callResult.code.length < 6) {

					uni.showModal({
						title: '溫馨提示',
						content: '輸入短信驗證碼長度有誤'
					})
				} else {
					this.$emit("confirmClick", this.callResult);

				}

			}


		}
	}
</script>

<style scoped>
	.button-item:active {
		background: #d4d4d4;
	}

	.button-item+.button-item {
		border-left: 0.1px solid #d4d4d4;
	}

	.button-item {
		flex: 1;
		padding: 14px 0px;
	}

	.keyboard-line+.keyboard-line {
		border-top: 0.1px solid #d4d4d4;
	}

	.keyboard-line {
		display: flex;
	}

	.keyboard {
		background: #fff;
		position: absolute;
		z-index: 999;
		width: 100%;
		left: 0;
		bottom: 0;
		font-size: 17px;
	}

	.dialog-close {
		color: #999;
		height: 28px;
		width: 28px;
		font-size: 19px;
		top: 5px;
		left: 5px;
		position: absolute;
	}


	.dialog-close:before {
		content: "\2716";
	}

	.countdown {
		color: #666;
		font-size: 16px;
	}

	.resend {
		color: #007aff;
		font-size: 16px;
	}

	.dialog-ft {
		margin-top: 10px;
	}

	.code-view {
		display: flex;
		text-align: center;
		margin: 0 auto;
		border-collapse: separate;
		border-spacing: 10px 5px;
	}

	.code-item+.code-item {
		margin-left: 5px;
	}

	.code-item {
		flex: 1;
		border-bottom: 1px solid #999;
		padding-bottom: 2px;
		height: 60upx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30upx;
	}

	.dialog-bd {
		margin-top: 5px;
	}

	.codedialog-subtitle {
		margin-top: 5px;
		padding: 5px 0px;
		font-size: 15px;
		line-height: 1.4;
		word-wrap: break-word;
		word-break: break-all;
		color: #999;
	}

	.dialog-view {
		position: fixed;
		z-index: 999;
		width: 70%;
		max-width: 300px;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -120%);
		background-color: #fff;
		text-align: center;
		border-radius: 3px;
		overflow: hidden;
		padding: 20px 10px;
	}

	.mask {
		position: fixed;
		z-index: 999;
		top: 0;
		right: 0;
		left: 0;
		bottom: 0;
		background: rgba(0, 0, 0, .6);
	}

	.codedialog {
		z-index: 999;
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		box-sizing: border-box;
		text-align: center;
	}
</style>



轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/556095.html

標籤:其他

上一篇:前端Vue自定義驗證碼密碼登錄切換tabs選項卡標簽欄標題欄 驗證碼登錄模版 密碼登錄模版

下一篇:返回列表

標籤雲
其他(161699) Python(38254) JavaScript(25515) Java(18266) C(15238) 區塊鏈(8273) C#(7972) AI(7469) 爪哇(7425) MySQL(7270) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5875) 数组(5741) R(5409) Linux(5347) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4607) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2437) ASP.NET(2404) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) .NET技术(1985) HtmlCss(1974) 功能(1967) Web開發(1951) C++(1942) python-3.x(1918) 弹簧靴(1913) xml(1889) PostgreSQL(1881) .NETCore(1863) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • IEEE1588PTP在數字化變電站時鐘同步方面的應用

    IEEE1588ptp在數字化變電站時鐘同步方面的應用 京準電子科技官微——ahjzsz 一、電力系統時間同步基本概況 隨著對IEC 61850標準研究的不斷深入,國內外學者提出基于IEC61850通信標準體系建設數字化變電站的發展思路。數字化變電站與常規變電站的顯著區別在于程序層傳統的電流/電壓互 ......

    uj5u.com 2020-09-10 03:51:52 more
  • HTTP request smuggling CL.TE

    CL.TE 簡介 前端通過Content-Length處理請求,通過反向代理或者負載均衡將請求轉發到后端,后端Transfer-Encoding優先級較高,以TE處理請求造成安全問題。 檢測 發送如下資料包 POST / HTTP/1.1 Host: ac391f7e1e9af821806e890 ......

    uj5u.com 2020-09-10 03:52:11 more
  • 網路滲透資料大全單——漏洞庫篇

    網路滲透資料大全單——漏洞庫篇漏洞庫 NVD ——美國國家漏洞庫 →http://nvd.nist.gov/。 CERT ——美國國家應急回應中心 →https://www.us-cert.gov/ OSVDB ——開源漏洞庫 →http://osvdb.org Bugtraq ——賽門鐵克 →ht ......

    uj5u.com 2020-09-10 03:52:15 more
  • 京準講述NTP時鐘服務器應用及原理

    京準講述NTP時鐘服務器應用及原理京準講述NTP時鐘服務器應用及原理 安徽京準電子科技官微——ahjzsz 北斗授時原理 授時是指接識訓通過某種方式獲得本地時間與北斗標準時間的鐘差,然后調整本地時鐘使時差控制在一定的精度范圍內。 衛星導航系統通常由三部分組成:導航授時衛星、地面檢測校正維護系統和用戶 ......

    uj5u.com 2020-09-10 03:52:25 more
  • 利用北斗衛星系統設計NTP網路時間服務器

    利用北斗衛星系統設計NTP網路時間服務器 利用北斗衛星系統設計NTP網路時間服務器 安徽京準電子科技官微——ahjzsz 概述 NTP網路時間服務器是一款支持NTP和SNTP網路時間同步協議,高精度、大容量、高品質的高科技時鐘產品。 NTP網路時間服務器設備采用冗余架構設計,高精度時鐘直接來源于北斗 ......

    uj5u.com 2020-09-10 03:52:35 more
  • 詳細解讀電力系統各種對時方式

    詳細解讀電力系統各種對時方式 詳細解讀電力系統各種對時方式 安徽京準電子科技官微——ahjzsz,更多資料請添加VX 衛星同步時鐘是我京準公司開發研制的應用衛星授時時技術的標準時間顯示和發送的裝置,該裝置以M國全球定位系統(GLOBAL POSITIONING SYSTEM,縮寫為GPS)或者我國北 ......

    uj5u.com 2020-09-10 03:52:45 more
  • 如何保證外包團隊接入企業內網安全

    不管企業規模的大小,只要企業想省錢,那么企業的某些服務就一定會采用外包的形式,然而看似美好又經濟的策略,其實也有不好的一面。下面我通過安全的角度來聊聊使用外包團的安全隱患問題。 先看看什么服務會使用外包的,最常見的就是話務/客服這種需要大量重復性、無技術性的服務,或者是一些銷售外包、特殊的職能外包等 ......

    uj5u.com 2020-09-10 03:52:57 more
  • PHP漏洞之【整型數字型SQL注入】

    0x01 什么是SQL注入 SQL是一種注入攻擊,通過前端帶入后端資料庫進行惡意的SQL陳述句查詢。 0x02 SQL整型注入原理 SQL注入一般發生在動態網站URL地址里,當然也會發生在其它地發,如登錄框等等也會存在注入,只要是和資料庫打交道的地方都有可能存在。 如這里http://192.168. ......

    uj5u.com 2020-09-10 03:55:40 more
  • [GXYCTF2019]禁止套娃

    git泄露獲取原始碼 使用GET傳參,引數為exp 經過三層過濾執行 第一層過濾偽協議,第二層過濾帶引數的函式,第三層過濾一些函式 preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'] (?R)參考當前正則運算式,相當于匹配函式里的引數 因此傳遞 ......

    uj5u.com 2020-09-10 03:56:07 more
  • 等保2.0實施流程

    流程 結論 ......

    uj5u.com 2020-09-10 03:56:16 more
最新发布
  • 前端Vue自定義發送短信驗證碼彈框popup 實作剩余秒數計數 重發短

    前端Vue自定義發送短信驗證碼彈框popup 實作剩余秒數計數 重發短信驗證碼, 請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=13207 效果圖如下: ![](https://p3-juejin.byteimg.com/tos-cn-i- ......

    uj5u.com 2023-06-27 10:04:45 more
  • 前端Vue自定義驗證碼密碼登錄切換tabs選項卡標簽欄標題欄 驗證碼

    #### 前端Vue自定義驗證碼密碼登錄切換tabs選項卡標簽欄標題欄 驗證碼登錄模版 密碼登錄模版, 請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=13221 #### 效果圖如下: #### ![](https://p3-juejin. ......

    uj5u.com 2023-06-27 10:04:15 more
  • 驅動開發:內核讀寫記憶體多級偏移

    讓我們繼續在`《內核讀寫記憶體浮點數》`的基礎之上做一個簡單的延申,如何實作多級偏移讀寫,其實很簡單,讀寫函式無需改變,只是在讀寫之前提前做好計算作業,以此來得到一個記憶體偏移值,并通過呼叫記憶體寫入原函式實作寫出資料的目的。以讀取偏移記憶體為例,如下代碼同樣來源于本人的`LyMemory`讀寫驅動專案,其... ......

    uj5u.com 2023-06-27 09:58:39 more
  • 驅動開發:內核讀寫記憶體多級偏移

    讓我們繼續在`《內核讀寫記憶體浮點數》`的基礎之上做一個簡單的延申,如何實作多級偏移讀寫,其實很簡單,讀寫函式無需改變,只是在讀寫之前提前做好計算作業,以此來得到一個記憶體偏移值,并通過呼叫記憶體寫入原函式實作寫出資料的目的。以讀取偏移記憶體為例,如下代碼同樣來源于本人的`LyMemory`讀寫驅動專案,其... ......

    uj5u.com 2023-06-27 09:56:17 more
  • uniapp-chatgpt跨端仿ChatGPT實體|uniapp+vue3+pinia多端聊天模

    基于uniapp+vite4+pinia跨多端實作chatgpt會話模板Uniapp-ChatGPT。 uni-chatgpt 使用uni-app+vite4+vue3+pinia+uview-plus等技術構建多端仿制ChatGPT手機端APP會話應用模板。支持編譯到h5+小程式+APP端,支持渲 ......

    uj5u.com 2023-06-27 08:32:33 more
  • ModifyAjaxResponse,修改ajax請求回傳值,前后端除錯之利器

    一、概要 先看圖 京豆多的離譜,你的第一想法肯定是:按F12修改了網頁元素 沒那么簡單,你看支持重繪的 肯定還是假的,通過 Fiddler 或 Wireshark 等抓包工具修改了回應包;或者干脆改了本地host檔案,指向了一個自己寫的頁面...... 這些都太麻煩了,如果能在當前網頁上攔截這個請求 ......

    uj5u.com 2023-06-27 08:31:48 more
  • 記錄--巧用 overflow-scroll 實作絲滑輪播圖

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 前言: 近期我在專案中就接到了一個完成輪播圖組件的需求。最開始我也像大家一樣,直接選擇使用了知名的開源專案 "Swiper",但是后來發現它在移動端專案中某些測驗環境下會白屏一段時間。無論如何除錯都不能修復這個問題,于是就自己上手寫了個輪 ......

    uj5u.com 2023-06-27 08:30:57 more
  • 教你學會使用Angular 應用里的 export declare const X Y

    摘要:export declare const X: Y語法用于在Angular應用程式中宣告一個具有指定型別的常量變數,并將其匯出,以便在其他檔案中使用。 本文分享自華為云社區《關于 Angular 應用里的 export declare const X Y 的用法》,作者:Jerry Wang。 ......

    uj5u.com 2023-06-27 08:30:47 more
  • ModifyAjaxResponse,修改ajax請求回傳值,前后端除錯之利器

    一、概要 先看圖 京豆多的離譜,你的第一想法肯定是:按F12修改了網頁元素 沒那么簡單,你看支持重繪的 肯定還是假的,通過 Fiddler 或 Wireshark 等抓包工具修改了回應包;或者干脆改了本地host檔案,指向了一個自己寫的頁面...... 這些都太麻煩了,如果能在當前網頁上攔截這個請求 ......

    uj5u.com 2023-06-27 08:30:19 more
  • 記錄--巧用 overflow-scroll 實作絲滑輪播圖

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 前言: 近期我在專案中就接到了一個完成輪播圖組件的需求。最開始我也像大家一樣,直接選擇使用了知名的開源專案 "Swiper",但是后來發現它在移動端專案中某些測驗環境下會白屏一段時間。無論如何除錯都不能修復這個問題,于是就自己上手寫了個輪 ......

    uj5u.com 2023-06-27 08:24:39 more