From b29ed998189c3de5e408f37d61802dfa30e4f9a8 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Tue, 01 Dec 2020 22:01:50 +0800 Subject: [PATCH] 优化表单模块数据传递机制,不再污染数据源 --- forms/input/CInputPhoneCode.vue | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-) diff --git a/forms/input/CInputPhoneCode.vue b/forms/input/CInputPhoneCode.vue index 161473e..9f00532 100644 --- a/forms/input/CInputPhoneCode.vue +++ b/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(); + }); + } }, }, }; -- Gitblit v1.9.1