WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2020-12-01 b29ed998189c3de5e408f37d61802dfa30e4f9a8
forms/input/CInputPhoneCode.vue
@@ -6,14 +6,14 @@
<template>
    <view class="c-input-phone-code">
        <AtInput
            :name="itemData.name"
            :title="itemData.label"
            :name="itemRes.name"
            :title="itemRes.label"
            type="text"
            :placeholder="placeholder"
            :required="itemData.required"
            :error="itemData.error"
            :value="itemData.formData[itemData.name]"
            :onChange="evt=>itemData.onChange(evt)"
            :required="itemRes.required"
            :error="itemRes.error"
            :value="itemRes.formData[itemRes.name]"
            :onChange="evt=>itemRes.onChange(evt)"
        >
            <AtButton
                class="c-input-phone-btn"
@@ -38,7 +38,8 @@
    },
    props: {
        placeholder: String,
        itemData: Object,
        itemRes: Object,
        autoStart: { type: Boolean, default: true },
        onCallPhoneCode: Function,
    },
    data() {
@@ -61,16 +62,25 @@
            if (this.holding) {
                return;
            }
            this.holding = true;
            this.cd = 60;
            this.onCallPhoneCode();
            const timer = setInterval(() => {
                this.cd -= 1;
                if (this.cd === 0) {
                    this.holding = false;
                    this.cd = 60;
                }
            }, 1000);
            const startCD = () => {
                this.holding = true;
                this.cd = 60;
                setInterval(() => {
                    this.cd -= 1;
                    if (this.cd === 0) {
                        this.holding = false;
                        this.cd = 60;
                    }
                }, 1000);
            };
            if (this.autoStart) {
                startCD();
                this.onCallPhoneCode(() => null);
            } else {
                this.onCallPhoneCode(() => {
                    startCD();
                });
            }
        },
    },
};