小程序支付密碼,驗(yàn)證碼6位demo

  • 效果圖


    image.png
  • . vue文件

<template>
  <div class="securitycode">
    <div class="code_title" v-show="staus === 0">請?jiān)O(shè)置賬戶余額支付密碼</div>
    <div class="code_title" v-show="staus === 1">請?jiān)俅翁顚懸源_認(rèn)</div>
    <div class="code_title" v-show="staus === 2">
      請輸入支付密碼,以驗(yàn)證身份
    </div>

    <view class='content' @click='Tap'>
      <block v-for="6" :key="item">
        <input class='code-input-main-item' value="{{code.length>=index+1?code[index]:''}}" disabled ></input>
      </block>
    </view>
    <input name="password"  class='ipt' maxlength="6" focus="{{isFocus}}"  type="number" @input="inputFunc"></input>

    <div class="code_forget" v-show="staus === 2" @click="staus = 0">
      忘記密碼?
    </div>
    <div class="code_comfirm" v-show="staus === 1">確認(rèn)</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      code: "",
      staus: 0,
      relCode: "",
      focus:true,
  isFocus:true,  //聚焦 
    };
  },
  onShow() {
    this.code = '';
    if (this.relCode) {
      this.staus = 2;
    }
  },
  methods: {
    inputFunc() {
      if (this.code.length === 6) {
        //輸入框的值
        console.log(this.code);
        switch (this.staus) {
          case 0: //設(shè)置
            this.staus = 1;
            this.relCode = this.code;
            this.code = "";
            break;
          case 1: //確認(rèn)
            if (this.relCode === this.code) {
              wx.showToast({
                title: "設(shè)置成功",
              });
              setTimeout(()=>{
              wx.navigateBack({
                delta: 1, //返回的頁面數(shù),如果 delta 大于現(xiàn)有頁面數(shù),則返回到首頁,
              });
              })

            } else {
              wx.showToast({
                title: "倆次支付密碼不一致", //提示的內(nèi)容,
                icon: "none", //圖標(biāo),
                duration: 2000, //延遲時(shí)間,
                mask: true, //顯示透明蒙層,防止觸摸穿透,
                success: (res) => {},
              });
              this.code = "";
            }

            break;
          case 2: //忘記
            if (this.relCode === this.code) {
              this.staus=0;
            } else {
              wx.showToast({
                title: "支付密碼錯(cuò)誤", //提示的內(nèi)容,
                icon: "none", //圖標(biāo),
                duration: 2000, //延遲時(shí)間,
                mask: true, //顯示透明蒙層,防止觸摸穿透,
                success: (res) => {},
              });
             
            }
             this.code = "";
            break;
          default:
            break;
        }
        
      }
    },
  },
};
</script>
<style lang="less" scoped>
@red: #ee3c4c;
.securitycode {
  box-sizing: border-box;
  height: 100%;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 200rpx;
}
.code-input-main {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin: 40rpx 0;
  width: 550rpx;
}

.code_forget {
  width: 550rpx;
  text-align: right;
  color: @red;
}
.code_comfirm {
  width: 550rpx;
  height: 80rpx;
  text-align: center;
  line-height: 80rpx;
  background-color: @red;
  color: #fff;
  border-radius: 10rpx;
}
.code-input-main-item {
  /* font-family: time-font-myself; */
  font-family: PingFang-SC-Medium;
  /* width: .34rem;
    height: .44rem; */
  opacity: 0.85;
  /* border-bottom: solid #ffffff 1rpx; */
  border: solid #d9d9d9 1rpx;
  margin: 0 5rpx;
  text-align: center;
  padding-bottom: 0;
  color: #333333;
  line-height: 102rpx;
  width: 90rpx;
  height: 90rpx;
  font-size: 50rpx;
  line-height: 90rpx;
  background: rgba(255, 255, 255, 1);
  border-radius: 10rpx;
}
.code-input-input {
  height: 102rpx;
  position: absolute;
  width: 300%; //隱藏光標(biāo)位置
  outline: none;
  color: transparent;
  text-shadow: 0 0 0 transparent;
}
</style>

  • 用 mpvue 寫的, 有需要自行轉(zhuǎn)小程序原生哈
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容