欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp+vue3實(shí)現(xiàn)自定義封裝支付密碼組件

 更新時(shí)間:2025年08月18日 11:11:58   作者:Pinia_0819  
本文介紹使用Vue3語(yǔ)法在uniapp中自定義封裝支付密碼組件,通過(guò)父組件與子組件的交互實(shí)現(xiàn)密碼輸入功能,并附效果圖展示,感興趣的朋友跟隨小編一起看看吧

使用uniapp自定義封裝支付密碼組件(vue3語(yǔ)法)

父組件

<paypassword v-model="passwordValue" @complete="onPasswordComplete"></paypassword>
const passwordValue = ref('')
// 密碼輸入完成回調(diào)
const onPasswordComplete = (password) => {
  console.log('密碼輸入完成:', password)
  passwordValue.value = password;
  uni.showToast({
    title: '密碼輸入完成',
    icon: 'success'
  })
}

子組件

<template>
    <view class="password-container">
      <!-- 第一行:6個(gè)密碼輸入框 -->
      <view class="password-input-container">
        <view class="password-input-row">
          <view 
            v-for="index in 6" 
            :key="index"
            class="password-input-box"
            :class="{ 'active': currentIndex === index - 1 }"
          >
            <view v-if="password[index - 1]" class="password-dot"></view>
          </view>
        </view>
      </view>
      <!-- 第二行:狀態(tài)圖標(biāo)和文字 -->
      <view class="password-status">
        <uni-icons 
          :type="isCompleted ? 'checkbox-filled' : 'checkbox-filled'" 
          :color="isCompleted ? '#12a58c' : '#d4d4d4'"
          size="32rpx"
        ></uni-icons>
        <text 
          class="status-text" 
          :class="{ 'status-text-complete': isCompleted }"
        >
          {{ '6個(gè)數(shù)字' }}
        </text>
      </view>
      <!-- 第三模塊:12宮格數(shù)字鍵盤 -->
      <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>
            <!-- 移除按鈕可以使用icon,也可以使用自定義圖片我使用的是自定義圖片 -->
           <!-- <uni-icons 
              v-if="key.type === 'delete'" 
              type="closeempty" 
              size="56rpx" 
              color="#171717"
            ></uni-icons> -->
            <image class="delImg" v-if="key.type === 'delete'"  src="/static/image/home/Frame.png" mode=""></image>
          </view>
        </view>
      </view>
    </view>
  </template>
  <script setup>
  import { ref, computed, watch, defineProps, defineEmits } from 'vue'
  // 定義props
  const props = defineProps({
    // 提示文字
    tipText: {
      type: String,
      default: '請(qǐng)輸入6位數(shù)字密碼'
    },
    // 初始密碼值
    modelValue: {
      type: String,
      default: ''
    }
  })
  // 定義emits
  const emits = defineEmits(['update:modelValue', 'complete'])
  // 數(shù)據(jù)狀態(tài)
  const password = ref([])
  const currentIndex = ref(0)
  // 鍵盤布局
  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'}
    ]
  ]
  // 計(jì)算屬性:是否輸入完成
  const isCompleted = computed(() => password.value.length === 6)
  // 監(jiān)聽(tīng)密碼完成狀態(tài)
  watch(isCompleted, (newVal) => {
    if (newVal) {
      const passwordStr = password.value.join('')
      emits('update:modelValue', passwordStr)
      emits('complete', passwordStr)
    }
  })
  // 監(jiān)聽(tīng)modelValue變化
  watch(() => props.modelValue, (newVal) => {
    if (newVal && newVal.length <= 6) {
      password.value = newVal.split('')
      currentIndex.value = password.value.length
    }
  }, { immediate: true })
  // 處理按鍵點(diǎn)擊
  const handleKeyClick = (key) => {
    if (key.type === 'number') {
      // 輸入數(shù)字
      if (password.value.length < 6) {
        password.value.push(key.value)
        currentIndex.value = password.value.length
      }
    } else if (key.type === 'delete') {
      // 刪除
      if (password.value.length > 0) {
        password.value.pop()
        currentIndex.value = password.value.length
      }
    }
    // 更新modelValue
    const passwordStr = password.value.join('')
    emits('update:modelValue', passwordStr)
  }
  // 重置密碼
  const resetPassword = () => {
    password.value = []
    currentIndex.value = 0
  }
  // 暴露方法給父組件
  defineExpose({
    resetPassword
  })
  </script>
  <style lang="scss" scoped>
  .password-container {
    width: 100%;
    padding-top: 96rpx;
    box-sizing: border-box;
    .password-input-container {
      margin-bottom: 32rpx;
      .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;
          &.active {
            border-color: #FF4001;
          }
          .password-dot {
            width: 20rpx;
            height: 20rpx;
            border-radius: 50%;
            background: #333;
          }
        }
      }
    }
    .password-status {
      display: flex;
      align-items: center;
      margin-bottom: 40rpx;
      .status-text {
        font-family: PingFang SC, PingFang SC;
        font-size: 24rpx;
        color: #737373;
        margin-left: 8rpx;
      }
      .status-text-complete {
        color: #12a58c;
      }
    }
    .number-keyboard {
      .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;
          }
          &.key-delete {
            // background: #e0e0e0;
          }
          &.key-empty {
            // background: transparent;
            // visibility: hidden;
          }
        }
      }
    }
  }
  </style>

效果圖:

到此這篇關(guān)于uniapp+vue3實(shí)現(xiàn)自定義封裝支付密碼組件的文章就介紹到這了,更多相關(guān)vue自定義支付密碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue實(shí)現(xiàn)搜索功能

    vue實(shí)現(xiàn)搜索功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)搜索功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • 手拉手教你如何處理vue項(xiàng)目中的錯(cuò)誤

    手拉手教你如何處理vue項(xiàng)目中的錯(cuò)誤

    在項(xiàng)目開(kāi)發(fā)中經(jīng)常遇到各種報(bào)錯(cuò),每次總是通過(guò)這樣或那樣的辦法解決掉,這篇文章主要給大家介紹了關(guān)于如何處理vue項(xiàng)目中錯(cuò)誤的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • vue3.0父?jìng)鹘o子的值不隨父組件改變而改變問(wèn)題及解決

    vue3.0父?jìng)鹘o子的值不隨父組件改變而改變問(wèn)題及解決

    這篇文章主要介紹了vue3.0父?jìng)鹘o子的值不隨父組件改變而改變問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • 詳解vue 模版組件的三種用法

    詳解vue 模版組件的三種用法

    本篇文章主要介紹了詳解vue 模版組件的三種用法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • vue中兩種路由模式的實(shí)現(xiàn)詳解

    vue中兩種路由模式的實(shí)現(xiàn)詳解

    這篇文章主要為大家詳細(xì)介紹了vue中兩種路由模式的實(shí)現(xiàn),文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下
    2023-08-08
  • vue利用指令實(shí)現(xiàn)快速設(shè)置元素的高度

    vue利用指令實(shí)現(xiàn)快速設(shè)置元素的高度

    在項(xiàng)目中經(jīng)常有需要將列表的高度設(shè)置成剩余可視區(qū)域的高度,本文主要來(lái)和大家介紹一下如何通過(guò)指令和css變量的方式快速設(shè)置列表高度,希望對(duì)大家有所幫助
    2024-03-03
  • Vue頁(yè)面首次載入優(yōu)化的全過(guò)程

    Vue頁(yè)面首次載入優(yōu)化的全過(guò)程

    凡是做SPA的項(xiàng)目,特別是移動(dòng)端的SAP項(xiàng)目,首屏加載速度必定是一個(gè)繞不過(guò)去的話題,下面這篇文章主要給大家介紹了關(guān)于Vue頁(yè)面首次載入優(yōu)化的相關(guān)資料,需要的朋友可以參考下
    2021-12-12
  • vue+iview寫個(gè)彈框的示例代碼

    vue+iview寫個(gè)彈框的示例代碼

    本篇文章主要介紹了vue+iview寫個(gè)彈框的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • Vue2.0中集成UEditor富文本編輯器的方法

    Vue2.0中集成UEditor富文本編輯器的方法

    本文給大家詳細(xì)講述了Vue2.0中集成UEditor富文本編輯器的方法以及相關(guān)注意事項(xiàng)做了講述,有興趣的朋友學(xué)習(xí)下。
    2018-03-03
  • Vue3+Spring Framework框架開(kāi)發(fā)實(shí)戰(zhàn)

    Vue3+Spring Framework框架開(kāi)發(fā)實(shí)戰(zhàn)

    這篇文章主要為大家介紹了Vue3+Spring Framework框架開(kāi)發(fā)實(shí)戰(zhàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04

最新評(píng)論