一最安 2022-03-05 18:08 采纳率: 84.4%
浏览 59

密码输入框输入一次后退出就无法再次输入,请问如何调整?

img


如图,进入密码输入框的组件后输入密码,退出后再次进入发现密码依然存在,而且还无法删除,请问该如何调整?
密码输入框组件:


<template>
    <view class="verification_code">
        <view class="verification_code_continor">
            <view
                class="verification_code_item"
                v-for="(item, index) in latticeNum"
                :key="index"
                :style="blurShowLocal && (inputValues.length === index || (inputValues.length === latticeNum && index === latticeNum - 1)) ? borderCheckStyle : borderStyle"
                @tap="latticeFoc(index)"
            >
                <block v-if="inputValues[index]">
                    <view v-if="ciphertextSty == 1" class="point"></view>
                    <block v-else>{{ ciphertextSty == 2 ? '*' : inputValues[index] }}</block>
                </block>
            </view>
        </view>
        
        <input :type="inputType" focus=true :maxlength="latticeNum" class="input_info" @input="inputVal" @blur="blur" @focus="focus" />
        
    </view>
</template>

<script>
export default {
    
    props: {
        // 输入框框框的个数
        latticeNum: {
            type: Number,
            default: 4
        },
        // 未选中样式
        borderStyle: {
            type: String,
            // default: 'border:1px solid gray;'
        },
        // 选中的样式
        borderCheckStyle: {
            type: String,
            // default: 'border-bottom:1px solid gray;'
        },
        // input类型
        inputType: {
            type: String,
            default: 'number'
        },
        // 失去焦点后是否继续显示,当前所对焦的输入框(样式)
        blurShow: {
            type: Boolean,
            default: false
        },
        // 密文样式  1 圆点样式    2 星号 *  样式   默认为0   无密文
        ciphertextSty: {
            type: Number,
            default: 1
        },
        // 是否允许修改/填写某一个框框的值
        updateOne: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            inputValues: [], //输入的值
            blurShowLocal: true,
            // focus:false
            // cursor:null
        };
    },
    mounted() {
        this.blurShowLocal = this.blurShow;
        // if (this.updateOne) {
        //     let arr = [];
        //     for (let i = 0; i < this.latticeNum; i++) {
        //         arr.push(' ');
        //     }
        //     this.inputValues = arr;
        // }
    },
    

    methods: {
        /**
         * 输入框的值
         */
        inputVal(e) {
            this.inputValues = e.detail.value;
            this.$emit('getInputVerification', this.inputValues);
        },
        // 设置验证码的值
        /**
         * verificationCodeValue  数组
         */
        setVerificationCode(verificationCodeValue = []) {
            this.inputValues = verificationCodeValue;
        },
        /**
         * 清空验证码的值
         */
        cleanVal() {
            this.inputValues = [];
        },
        latticeFoc(index) {
            
        },
        blur() {
            !this.blurShow ? (this.blurShowLocal = false) : '';
        },
        focus() {
            
            !this.blurShow ? (this.blurShowLocal = true) : '';
        }
    }
};
</script>

<style lang="less">
.verification_code {
    position: relative;
    overflow: hidden;

    .verification_code_continor {
        display: flex;
        text-align: center;
        margin-left:5px auto;
        .verification_code_item {
            width: 60px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            display: flex;
            border-radius: 3px;
            background-color:#E7EAEC;
        }

        .verification_code_item:not(:first-child) {
            margin-left: 20rpx;
        }
        .point {
            width: 10rpx;
            height: 10rpx;
            background-color: black;
            border-radius: 200px;
        }
    }

    .input_info {
        width: 1200rpx;
        height: 60rpx;
        border: 1px solid red;
        position: absolute;
        opacity: 0;
        top: 0;
        left: -800rpx;
    }
}
</style>


父组件:

<template>
    <view class="makeOrder">
        <view class="content">
            <view class="content_item" style="margin-top: 3vw;">
                <view class="title">存款产品</view>
                <view class="answer">{{deposit.name}}</view>
            </view>
            <view class="content_item">
                <view class="title">年利率</view>
                <view class="answer">{{deposit.annual_rate}}%</view>
            </view>
            <view class="content_item">
                <view class="title">身份证号</view>
                <view class="answer">{{IdcardNumber}}</view>
            </view>
            <view class="content_item">
                <view class="title">银行卡号</view>
                <view class="answer">{{bankNumber}}</view>
            </view>
            
            <view class="content_item">
                <view class="title">存款金额</view>
                <view class="answer">{{depositMoney}}</view>
            </view>
            <view class="content_item">
                <view class="title">存入日期</view>
                <view class="answer">{{depositDate}}</view>
            </view>
            <view class="content_item">
                <view class="title">起息日期</view>
                <view class="answer">{{interestStart}}</view>
            </view>
            <view class="content_item">
                <view class="title">到期日期</view>
                <view class="answer">{{endDay}}</view>
            </view>
            
            <view style="margin:10px auto;margin-top:20px;">
                <van-button block color="rgb(215,0,15)"  @click="toPurchaseResult">
                    结算
                </van-button>
            </view>
            
            <van-dialog
              use-title-slot
              use-slot
              :show-close="true"
              title="请输入支付密码"
              :show="showDialog"
              :showConfirmButton="false"
            >
                <view slot="title" style="margin-bottom: 15px;">
                    <view style="position:relative">
                        请输入支付密码
                        <van-icon name="cross" size="18px" custom-style="position:absolute;right:5%;top:5%" @click="close"/>
                    </view>
                </view>
                
                <view class="dialogContent" style="text-align: center;position: relative;min-height: 180px;">
                    <view style="font-size:16px;margin-bottom: 5px;">银行</view>
                    <view style="font-size:35px;font-weight:580">{{depositMoney}}</view>
                    
                    <van-viewider/>
                    
                    <view style="display:flex;margin:10px">
                        <view style="font-size:14px;color:#999999">银行卡号</view>
                        <view style="position:absolute;right:3%">{{bankNumber}}</view>
                    </view>
                    
                        
                    <view class="password">
                        <verification-code-style :latticeNum="6" @getInputVerification="getInputVerification">
                            
                            <!-- <input :type="inputType" focus :maxlength="latticeNum" class="input_info" @input="inputVal" @blur="blur" @focus="focus" /> -->
                        
                        </verification-code-style>
                    </view>
                

                
                </view>
                
            </van-dialog>
            
        </view>
            
    </view>
</template>

<script>
    import { showProductById } from '../../../api/product.js'
    import * as atomServiceList from '../../../api/atomService.js'
    import verificationCodeStyle from '../../../components/verification-code-style2/verification-code-style2.vue'
    import { getNext } from '../../../api/graph.js'
    import md5 from 'js-md5'
    
    export default{
        components: {
            verificationCodeStyle
        },
        props: {
            // input类型
            inputType: {
                type: String,
                default: 'number'
            },
            latticeNum: {
                type: Number,
                default: 6
            },
        },
        data(){
            return{
                current:'',
                productId:'',
                deposit:[],
                IdcardNumber:'',
                bankNumber:'',
                depositMoney:'',
                depositDate:'',//存入日期
                interestStart:'',//起息日期
                endDay:'',    //到期日期
                showDialog:false,
                password:'',
                
                blurShowLocal: true,
                inputValues: [], //输入的值
            }
        },
        
        onLoad(option){
            this.current=option.id;
            this.productId=option.productId
            this.depositMoney=option.money;
            this.bankNumber=this.$store.getters.cardNumber.replace(/^(\d{4})\d+(\d{4})$/, "$1****$2")
            this.IdcardNumber=this.$store.getters.IdcardNumber.replace(/^(.{4})(?:\d+)(.{4})$/,"$1******$2");
            showProductById(this.productId).then(res=>{
                this.deposit = res.data;
            })
            atomServiceList.makeOrder(this.productId,this.depositMoney).then(res=>{
                this.interestStart=res.data.interestStart.substr(0,10);
                this.endDay=res.data.endDay.substr(0,10);
                this.depositDate=res.data.createdTime.substr(0,10);
                console.log("生成订单完")
            })
            getNext(this.productId,this.current,'#').then(res=>{
                this.current=res.data.next.substr(1)
                if(res.data.name==='stockLock'){
                    atomServiceList.stockLock(this.productId,this.depositMoney).then(res=>{
                        console.log("库存锁定完")
                    
                    })
                    }
                })
            
                
            
                    
        },
        
        onBackPress(e) {
            console.log(e);
            if(e.from == 'backbutton'){
            this.$utils.showModal('提示','房型尚未保存,确认退出吗?',true,'继续编辑','确定').then(()=>{
                console.log('确定')
                uni.navigateBack({
                    delta:1
                })
            }).catch(()=>{
                console.log('继续编辑')
            })
            return true;//阻止默认返回行为
            }
        },
        mounted() {
            this.blurShowLocal = this.blurShow;
            // if (this.updateOne) {
            //     let arr = [];
            //     for (let i = 0; i < this.latticeNum; i++) {
            //         arr.push(' ');
            //     }
            //     this.inputValues = arr;
            // }
        },
    
        methods:{
            inputVal(e) {
                this.inputValues = e.detail.value;
                this.$emit('getInputVerification', this.inputValues);
            },
            
            
            getInputVerification(e) {
                this.password=e
                if(this.password.length===6){
                    atomServiceList.payMoney(md5(this.password),this.depositMoney).then(res=>{
                        console.log('付款接口完')
                        this.toPurchaseResult()
                    })
                    this.showDialog=false
                    
                }
            },
            close(){
                this.showDialog=false
            },
            toPurchaseResult(){
                this.showDialog=true
                // getNext(this.productId,this.current,'#').then(res=>{
                //     if(this.password.length===6){
                //         this.current=res.data.next.substr(1)
                //     }
                //     if(res.data.name==='payMoney'){
                //         this.showDialog=true
                //     }
                // })
                
                // this.$refs.sonCode.focus()
                // console.log('this.password:',this.password.length)
                
                // getNext(this.productId,this.current,'#').then(res=>{
                //     if(res.data.name==='payMoney'){
                //         this.current=res.data.current
                        
                        
                        
                //         atomServiceList.payMoney(bankNumber,password).then(res=>{
                //             console.log("payMoney.res:",res)
                //         })
                //         getNext(this.productId,this.current,'#').then(res=>{
                //             if(res.data.name==='stockUpdate'){
                //             }
                //         })
                        
                //         // uni.redirectTo({
                //         //     url: `purchase_result?item=${encodeURIComponent(JSON.stringify(this.deposit))}&money=${this.depositMoney}&id=${rea.data.current}`,
                //         // })
                //     }
                // })
                
                
            }
        }
    }
</script>

<style>
    
    .password{
        width: 500rpx;
        margin: 50rpx auto;
    }

    .content{
        padding: 0 4vw;
    }
    .content_item{
        margin-top:3vw;
        padding-bottom:3vw;
        display: flex;
        position: relative;
        border-bottom: 1px solid #e7eaec !important;
        
    }
    
    .answer{
            color: #B0B0B0;
            position: absolute;
            right: 1vw;
            max-width:65%;
            text-align: right;
        }
    
</style>



请赐教,不胜感激。

  • 写回答

4条回答 默认 最新

  • 波 吉 2022-03-05 21:12
    关注

    出现这种情况,一般的问题在于子组件被关闭后,并没有被销毁;当下次打开时,便会残留之前所输入的数据。要验证这一点的话,可以在子组件中的 beforeDestroyed 打log看下是否属于这种情况。
    如果是上述所说的情况,我这边有个思路可以供题主参考下:假设子组件中的数据是 let password = '...',那么监听每次关闭弹窗后(或打开弹窗前),先将弹窗中的数据重置 password = ' ',应该就可以解决该问题。如果还有问题的话,可以再一起探讨下

    评论

报告相同问题?

问题事件

  • 创建了问题 3月5日

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 易优eyoucms关于二级栏目调用的问题
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题