使用uniapp自定義組件雙重支付密碼

自定義組件雙重支付密碼

父組件

<template><view class="container"><view class="top"></view><navbar navTitle="修改支付密碼"></navbar><!-- 雙重支付密碼 --><view class="box">//核心代碼<paypassworddouble v-model="passwordValue" @complete="onPasswordComplete"></paypassworddouble></view></view>
</template><script setup>import { ref } from 'vue'import navbar from '@/pages/components/navbar.vue'import paypassworddouble from '../components/paypassworddouble.vue' //核心代碼const passwordValue = ref('')// 密碼輸入完成回調const onPasswordComplete = (password) => {console.log('密碼輸入完成獲取最新密碼:', password)passwordValue.value = password;// uni.showToast({//   title: '支付密碼修改完成',//   icon: 'success'// })}</script><style lang="scss" scoped>.container{width: 750rpx;height: 100%;background: #ffffff;.top{width: 100%;height: 88rpx;}.box{padding: 0 48rpx;}}       
</style>

子組件 全部復制過去直接用就完事了

<template><!-- 雙重驗證支付密碼組件 --><view class="password-container"><!-- 第一行:標題"請輸入支付密碼" --><view class="password-title">請輸入支付密碼</view><view class="password-tips">為了您的財產安全考慮,請輸入您的支付密碼進入!</view><!-- 第二行:6個密碼輸入框(第一組密碼) --><view class="password-input-container"><view class="password-input-row"><view v-for="index in 6" :key="index"class="password-input-box":class="{ 'active': currentInputGroup === 1 && currentFirstIndex === index - 1 }"><view v-if="firstPassword[index - 1]" class="password-text">{{ firstPassword[index - 1] }}</view><view v-else-if="firstPassword[index - 1] === ''" class="password-dot"></view></view></view></view><!-- 第三行:標題"請確認支付密碼" --><view class="password-title">請確認支付密碼</view><view class="password-tips">為了確認支付密碼是否正確,請再次輸入!</view><!-- 第四行:6個密碼輸入框(第二組密碼) --><view class="password-input-container password-input-container-two"><view class="password-input-row"><view v-for="index in 6" :key="index"class="password-input-box":class="{ 'active': currentInputGroup === 2 && currentSecondIndex === index - 1 }"><view v-if="secondPassword[index - 1]" class="password-text">{{ secondPassword[index - 1] }}</view><view v-else-if="secondPassword[index - 1] === ''" class="password-dot"></view></view></view></view><!-- 第五行:12宮格數字鍵盤 --><view class="number-keyboard"><view class="keyboard-row" v-for="(row, rowIndex) in keyboardLayout" :key="rowIndex"><view v-for="(key, keyIndex) in row" :key="keyIndex"class="keyboard-key"@click="handleKeyClick(key)"><text v-if="key.type === 'number'" class="key-text">{{ key.value }}</text><image class="delImg" v-if="key.type === 'delete'" src="/static/image/home/Frame.png" mode=""></image></view></view></view><!-- 密碼一致性提示 --><view class="password-match-tip" v-if="showMatchTip"><view v-if="isPasswordMatch && secondPassword.length === 6" class="tip-success"><uni-icons type="checkbox-filled" size="28rpx" color="#12a58c"></uni-icons><text class="tip-text success">兩次密碼輸入一致</text></view><view v-else-if="!isPasswordMatch && secondPassword.length === 6" class="tip-error"><uni-icons type="info-filled" size="28rpx" color="#ff0000"></uni-icons><text class="tip-text error">兩次密碼輸入不一致</text></view></view></view>
</template><script setup>
import { ref, computed, watch } from 'vue'// 定義props
const props = defineProps({modelValue: {type: String,default: ''}
})// 定義emits
const emits = defineEmits(['update:modelValue', 'complete', 'match'])// 數據狀態
const firstPassword = ref([])  // 第一組密碼
const secondPassword = ref([]) // 第二組密碼
const currentFirstIndex = ref(0)   // 第一組當前輸入位置
const currentSecondIndex = ref(0)  // 第二組當前輸入位置
const currentInputGroup = ref(1)   // 當前輸入組(1:第一組, 2:第二組)
const isCompleted = ref(false)     // 是否完成輸入// 鍵盤布局
const keyboardLayout = [[{ type: 'number', value: '1' },{ type: 'number', value: '2' },{ type: 'number', value: '3' }],[{ type: 'number', value: '4' },{ type: 'number', value: '5' },{ type: 'number', value: '6' }],[{ type: 'number', value: '7' },{ type: 'number', value: '8' },{ type: 'number', value: '9' }],[{ type: 'number', value: '*' },{ type: 'number', value: '0' },{ type: 'delete'}]
]// 計算屬性:密碼是否一致
const isPasswordMatch = computed(() => {return firstPassword.value.join('') === secondPassword.value.join('')
})// 計算屬性:第二行輸入完成開啟匹配是否顯示匹配提示
const showMatchTip = computed(() => {return secondPassword.value.length === 6
})// 監聽密碼完成狀態
watch([firstPassword, secondPassword], ([newFirst, newSecond]) => {// 當兩組密碼都輸入完成時if (newFirst.length === 6 && newSecond.length === 6) {isCompleted.value = trueconst firstPwd = newFirst.join('')const secondPwd = newSecond.join('')// 檢查密碼是否一致if (firstPwd === secondPwd) {emits('update:modelValue', firstPwd)emits('complete', firstPwd)emits('match', true)} else {emits('match', false)}} else {isCompleted.value = false}
},{ deep: true })
// 處理按鍵點擊
const handleKeyClick = (key) => {if (key.type === 'number') {// 輸入數字if (currentInputGroup.value === 1 && firstPassword.value.length < 6) {firstPassword.value.push(key.value)currentFirstIndex.value = firstPassword.value.length// 第一組輸入完成后自動切換到第二組if (firstPassword.value.length === 6) {currentInputGroup.value = 2}} else if (currentInputGroup.value === 2 && secondPassword.value.length < 6) {secondPassword.value.push(key.value)currentSecondIndex.value = secondPassword.value.length}} else if (key.type === 'delete') {// 刪除邏輯優化if (currentInputGroup.value === 1 && firstPassword.value.length > 0) {// 刪除第一組密碼firstPassword.value.pop()currentFirstIndex.value = firstPassword.value.length} else if (currentInputGroup.value === 2 && secondPassword.value.length > 0) {// 刪除第二組密碼secondPassword.value.pop()currentSecondIndex.value = secondPassword.value.length} else if (currentInputGroup.value === 2 && secondPassword.value.length === 0 && firstPassword.value.length === 6) {// 當第二組密碼為空時,切換回第一組currentInputGroup.value = 1currentFirstIndex.value = firstPassword.value.length}}
}// 重置密碼
const resetPassword = () => {firstPassword.value = []secondPassword.value = []currentFirstIndex.value = 0currentSecondIndex.value = 0currentInputGroup.value = 1isCompleted.value = false
}// 暴露方法給父組件
defineExpose({resetPassword
})
</script><style lang="scss" scoped>
.password-container {width: 100%;padding-top: 60rpx;box-sizing: border-box;.password-title {height: 56rpx;font-family: PingFang SC, PingFang SC;font-weight: 600;font-size: 56rpx;color: #171717;line-height: 56rpx;margin-bottom: 16rpx;}.password-tips {height: 42rpx;font-family: PingFang SC, PingFang SC;font-weight: 400;font-size: 28rpx;color: #737373;line-height: 42rpx;margin-bottom: 48rpx;}.password-input-container {margin-bottom: 48rpx;.password-input-row {display: flex;justify-content: space-between;.password-input-box {width: 96rpx;height: 112rpx;border-radius: 24rpx;border: 2rpx solid #171717;display: flex;align-items: center;justify-content: center;position: relative;&.active {border-color: #FF4001;}.password-text {font-family: PingFang SC, PingFang SC;font-weight: 500;font-size: 48rpx;color: #171717;}.password-dot {width: 20rpx;height: 20rpx;border-radius: 50%;background: #333;}}}}.password-input-container-two{margin-bottom: 156rpx;}.number-keyboard {margin-top: 40rpx;.keyboard-row {display: flex;justify-content: space-around;margin-bottom: 20rpx;.keyboard-key {width: 207rpx;height: 112rpx;background: #FAFAFA;border-radius: 24rpx;display: flex;align-items: center;justify-content: center;.key-text {font-family: PingFang SC, PingFang SC;font-weight: 500;font-size: 48rpx;color: #171717;}.delImg {width: 56rpx;height: 56rpx;}}}}.password-match-tip {margin-top: 30rpx;display: flex;justify-content: center;.tip-success, .tip-error {display: flex;align-items: center;.tip-text {font-size: 24rpx;margin-left: 10rpx;}.tip-text.success {color: #12a58c;}.tip-text.error {color: #ff0000;}}}
}
</style>

效果圖
在這里插入圖片描述

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

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

相關文章

C語言+安全函數+非安全函數

在C語言中&#xff0c;許多標準庫函數&#xff08;如 strcpy、scanf、gets 等&#xff09;由于缺乏邊界檢查&#xff0c;容易導致 ?緩沖區溢出&#xff08;Buffer Overflow&#xff09;?、內存越界訪問? 等安全問題。為了解決這些問題&#xff0c;C11標準引入了 ?安全函數&…

android build.gradle中的namespace和applicationId的區別

namespace 和 applicationId 確實容作用&#xff1a;1. namespace引入版本&#xff1a;Android Gradle Plugin (AGP) 7.0 開始引入&#xff0c;替代 AndroidManifest.xml 里的 package 屬性。作用&#xff1a; 用于 代碼中的 R 文件、BuildConfig 生成的 Java/Kotlin 包名。決定…

數據結構初階(15)排序算法—交換排序(快速排序)(動圖演示)

2.3 交換排序 2.3.0 基本思想交換排序的基本思想&#xff1a;基本思想根據序列中兩個記錄鍵值的比較結果來對換這兩個記錄在序列中的位置。&#xff08;比較結果→交換位置&#xff09;特點將鍵值較大的記錄向序列的尾部移動&#xff0c;鍵值較小的記錄向序列的前部移動。比 換…

Apache Hudi:數據湖的實時革命

Apache Hudi是一個開源的數據湖存儲格式和框架&#xff0c;它通過引入類似數據庫的事務機制&#xff0c;解決了傳統數據湖在實時更新、低延遲查詢和增量消費方面的痛點。Hudi最初由Uber于2016年開發并應用于生產環境&#xff0c;2017年開源&#xff0c;2019年成為Apache孵化項目…

深度解析和鯨社區熱門項目:電商雙 11 美妝數據分析的細節與價值

在數據驅動決策的時代&#xff0c;電商大促期間的行業數據分析總能為從業者和學習者提供寶貴參考。今天&#xff0c;我們來詳細拆解和鯨社區&#xff08;heywhale&#xff09;上一個備受關注的實戰項目 ——《電商雙 11 美妝數據分析》&#xff0c;看看它能給我們帶來哪些啟發。…

uniapp 開發微信小程序,獲取經緯度并且轉化詳細地址(單獨封裝版本)

目錄1、單獨抽離封裝2、使用示例3、前置條件和配置4、效果彈框1、單獨抽離封裝 // 騰訊地圖SDK引入&#xff08;需提前下載qqmap-wx-jssdk.min.js文件&#xff09; // 注意&#xff1a;使用前需在微信公眾平臺配置request合法域名https://apis.map.qq.com var QQMapWX requir…

深入理解 Python 元類中的 __prepare__ 方法:掌控類屬性定義順序的藝術

關鍵詞&#xff1a;元類、type、prepare、OrderedDict、屬性順序、數據建模在 Python 的高級編程中&#xff0c;元類&#xff08;metaclass&#xff09; 是一種強大而神秘的機制。它允許我們在類創建之前進行干預&#xff0c;從而實現諸如自動屬性驗證、字段序列化、ORM 映射等…

MATLAB基礎訓練實驗

MATLAB基礎訓練實驗 1. 標題 MATLAB 基礎訓練 2. 內容概括 本實驗旨在通過MATLAB基礎操作訓練,掌握數組創建與運算、矩陣操作、M文件編寫、流程控制、二維/三維繪圖等核心技能。實驗內容包括復數運算、矩陣變換、函數繪圖、結構體創建、電路方程求解、電流波形繪制、三維曲…

implement libwhich for Windows

因為windows沒有類似unix的which命令 現在實現盡量跨平臺&#xff0c;且stb 風格的libwhich // which.h #ifndef LIBWHICH_H #define LIBWHICH_H#ifdef __cplusplus extern "C" { #endif/** 查找可執行文件在系統中的路徑* 參數:* filename - 要查找的可執行文件名…

記與客戶端的一次“無謂之爭”

一、沖突今天&#xff0c;流程收尾時&#xff0c;客戶端為了統計時延&#xff0c;連發兩個接口&#xff1a;一個報開始時間&#xff0c;一個報結束時間。我因性能考慮&#xff0c;說&#xff1a;“明明一個接口能搞定&#xff01;”客戶端負責人說&#xff1a;“發送兩次更合理…

Java Condition 對象 wait 方法使用與修復方案

在 Java 中&#xff0c;java.util.concurrent.locks.Condition 接口提供了類似監視器的方法&#xff08;await(), signal(), signalAll()&#xff09;來實現線程間的協調。正確使用 Condition 對象需要遵循特定模式以避免常見問題。常見問題及修復方案1. 虛假喚醒問題問題&…

??金倉數據庫KingbaseES V9R1C10安裝教程 - Windows版詳細指南?

文章目錄一、前言二、軟件下載2.1 下載安裝包2.2 下載授權文件三. 安裝KingbaseES數據庫3.1 解壓安裝包3.2 運行安裝程序3.3 安裝步驟詳解步驟1&#xff1a;歡迎界面步驟2&#xff1a;許可協議步驟3&#xff1a;添加授權文件步驟4&#xff1a;選擇安裝路徑步驟5&#xff1a;選擇…

論文推薦|遷移學習+多模態特征融合

來gongzhonghao【圖靈學術計算機論文輔導】&#xff0c;快速拿捏更多計算機SCI/CCF發文資訊&#xff5e;在Cvpr、NeurIPS、AAAI等頂會中&#xff0c;遷移學習多模態特征融合正以“降成本、提性能、省標注”的絕對優勢成為最熱賽道。面對超大模型全量微調天價算力、異構模態對齊…

接口芯片斷電高阻態特性研究與應用分析

摘要&#xff1a; 本文以國科安芯推出的ASM1042 系列通訊接口芯片為例&#xff0c;深入探討接口芯片斷電高阻態特性&#xff0c;涵蓋其定義、原理、應用及設計注意事項。通過對相關技術資料的梳理與分析&#xff0c;結合具體芯片實例&#xff0c;闡述高阻態在電路穩定性、設備兼…

數據結構初階(17)排序算法——非比較排序(計數排序·動圖演示)、排序算法總結

2.0 十大排序算法2.5 非比較排序 之前學習的排序算法都是比較排序——借助比較大小&#xff0c;來實現排序。非比較就是不借助比較大小&#xff0c;來實現排序。——小眾的、局限的非比較排序大致有這些&#xff1a;計數排序、桶排序、基數排序。桶排序、基數排序在實踐中意義不…

VisualStudio2022調試Unity C#代碼步驟

一.VS安裝Unity開發組件按下圖所示安裝Unity開發組件二.附加Unity調試程序2.1 先將Unity進入Play模式2.2 VS選擇附加Unity調試程序菜單2.3 選擇附加的實例三.加入斷點測試Update方法中成功進入斷點

Zabbix【部署 01】Zabbix企業級分布式監控系統部署配置使用實例(在線安裝及問題處理)程序安裝+數據庫初始+前端配置+服務啟動+Web登錄

Zabbix使用 1.下載 2.安裝 2.1 程序安裝 2.2 數據庫初始化 2.3 前端配置 2.4 服務啟動 3.Web登錄 4.總結 安裝說明: 本次安裝為在線安裝,使用數據庫為PostgreSQL。 1.下載 由于是在線安裝,這次不涉及離線安裝包的下載,僅做參考用,點擊跳轉【下載頁面】,下載說明: 版本…

爬機 驗證服務器是否拒絕請求

當訪問XX網站時返回 418 狀態碼時&#xff0c;說明服務器識別到了爬蟲行為并拒絕了請求。這是網站的反爬機制在起作用&#xff0c;我們可以通過模擬瀏覽器行為來繞過基礎反爬。import requestsurl https://cn.bing.com/# 模擬瀏覽器的完整請求頭&#xff0c;包含更多瀏覽器標識…

GaussDB 數據庫架構師修煉(十三)安全管理(3)-數據庫審計

1 數據庫審計作用數據庫審計機制主要通過對SQL操作或其他操作記錄審計日志的方式 &#xff0c;增強數據庫系統對非法操作的追溯及舉證能力 。高斯數據庫提供兩種審計特性 &#xff1a;傳統審計 &#xff0c;統一審計。2 傳統審計傳統審計通過GUC參數配置需要對數據庫的哪些操作…

C語言(11)—— 數組(超絕詳細總結)

Hi&#xff01;冒險者&#x1f60e;&#xff0c;歡迎闖入 C 語言的奇幻異世界&#x1f30c;&#xff01; 我是 ankleless&#x1f9d1;?&#x1f4bb;&#xff0c;和你一樣的闖蕩者&#xff5e; 這是我的冒險筆記打怪升級之路——C語言之路&#x1f4d6;&#xff0c;里面有踩過…