Commit 3c4de9b0be06350f0d9ad97bfb5f7f773c38be38

Authored by Vben
1 parent e49072c3

fix(input-count): make sure the reset function works close #381

CHANGELOG.zh_CN.md
... ... @@ -4,6 +4,10 @@
4 4  
5 5 - 重构路由多层模式,解决嵌套 keepalive 执行多次问题
6 6  
  7 +### 🐛 Bug Fixes
  8 +
  9 +- 确保 CountDownInput 组件重置清空值
  10 +
7 11 ## 2.1.0 (2021-03-15)
8 12  
9 13 ### ✨ Features
... ...
src/components/CountDown/src/CountButton.vue
... ... @@ -8,22 +8,21 @@
8 8 </Button>
9 9 </template>
10 10 <script lang="ts">
11   - import { defineComponent, ref, PropType } from 'vue';
  11 + import { defineComponent, ref, PropType, watchEffect } from 'vue';
12 12  
13 13 import { Button } from 'ant-design-vue';
14 14  
15 15 import { useCountdown } from './useCountdown';
16 16 import { isFunction } from '/@/utils/is';
17 17 import { useI18n } from '/@/hooks/web/useI18n';
  18 + import { propTypes } from '/@/utils/propTypes';
18 19  
19 20 export default defineComponent({
20 21 name: 'CountButton',
21 22 components: { Button },
22 23 props: {
23   - count: {
24   - type: Number,
25   - default: 60,
26   - },
  24 + value: propTypes.string,
  25 + count: propTypes.number.def(60),
27 26 beforeStartFunc: {
28 27 type: Function as PropType<() => boolean>,
29 28 default: null,
... ... @@ -32,8 +31,12 @@
32 31 setup(props) {
33 32 const loading = ref(false);
34 33  
35   - const { currentCount, isStart, start } = useCountdown(props.count);
  34 + const { currentCount, isStart, start, reset } = useCountdown(props.count);
36 35 const { t } = useI18n();
  36 +
  37 + watchEffect(() => {
  38 + props.value === undefined && reset();
  39 + });
37 40 /**
38 41 * @description: Judge whether there is an external function before execution, and decide whether to start after execution
39 42 */
... ...
src/components/CountDown/src/CountdownInput.vue
1 1 <template>
2   - <AInput v-bind="$attrs" :class="prefixCls" :size="size">
  2 + <AInput v-bind="$attrs" :class="prefixCls" :size="size" :value="state">
3 3 <template #addonAfter>
4   - <CountButton :size="size" :count="count" :beforeStartFunc="sendCodeApi" />
  4 + <CountButton :size="size" :count="count" :value="state" :beforeStartFunc="sendCodeApi" />
5 5 </template>
6 6 </AInput>
7 7 </template>
... ... @@ -18,6 +18,7 @@
18 18  
19 19 export default defineComponent({
20 20 name: 'CountDownInput',
  21 + inheritAttrs: false,
21 22 components: { [Input.name]: Input, CountButton },
22 23 props: {
23 24 value: propTypes.string,
... ...
src/components/CountDown/src/useCountdown.ts
... ... @@ -14,8 +14,8 @@ export function useCountdown(count: number) {
14 14  
15 15 function stop() {
16 16 isStart.value = false;
17   - timerId = null;
18 17 clear();
  18 + timerId = null;
19 19 }
20 20  
21 21 function start() {
... ...
src/components/Form/src/componentMap.ts
... ... @@ -23,6 +23,7 @@ import ApiSelect from &#39;./components/ApiSelect.vue&#39;;
23 23 import { BasicUpload } from '/@/components/Upload';
24 24 import { StrengthMeter } from '/@/components/StrengthMeter';
25 25 import { IconPicker } from '/@/components/Icon';
  26 +import { CountdownInput } from '/@/components/CountDown';
26 27  
27 28 const componentMap = new Map<ComponentType, Component>();
28 29  
... ... @@ -51,6 +52,7 @@ componentMap.set(&#39;WeekPicker&#39;, DatePicker.WeekPicker);
51 52 componentMap.set('TimePicker', TimePicker);
52 53 componentMap.set('StrengthMeter', StrengthMeter);
53 54 componentMap.set('IconPicker', IconPicker);
  55 +componentMap.set('InputCountDown', CountdownInput);
54 56  
55 57 componentMap.set('Upload', BasicUpload);
56 58  
... ...
src/hooks/component/useFormItem.ts
... ... @@ -31,6 +31,7 @@ export function useRuleFormItem&lt;T extends Indexable&gt;(
31 31 },
32 32 set(value) {
33 33 if (isEqual(value, defaultState.value)) return;
  34 +
34 35 innerState.value = value as T[keyof T];
35 36 emit?.(changeEvent, value);
36 37 },
... ...
src/views/demo/form/RuleForm.vue
... ... @@ -5,6 +5,7 @@
5 5 <a-button @click="resetValidate" class="mr-2"> 清空校验信息 </a-button>
6 6 <a-button @click="getFormValues" class="mr-2"> 获取表单值 </a-button>
7 7 <a-button @click="setFormValues" class="mr-2"> 设置表单值 </a-button>
  8 + <a-button @click="resetFields" class="mr-2"> 重置 </a-button>
8 9 </div>
9 10 <CollapseContainer title="表单校验">
10 11 <BasicForm @register="register" @submit="handleSubmit" />
... ... @@ -47,6 +48,15 @@
47 48 required: true,
48 49 },
49 50 {
  51 + field: 'field44',
  52 + component: 'InputCountDown',
  53 + label: '验证码',
  54 + colProps: {
  55 + span: 8,
  56 + },
  57 + required: true,
  58 + },
  59 + {
50 60 field: 'field4',
51 61 component: 'Select',
52 62 label: '字段4',
... ... @@ -150,15 +160,16 @@
150 160 components: { BasicForm, CollapseContainer, PageWrapper },
151 161 setup() {
152 162 const { createMessage } = useMessage();
153   - const [register, { validateFields, clearValidate, getFieldsValue, setFieldsValue }] = useForm(
154   - {
155   - labelWidth: 120,
156   - schemas,
157   - actionColOptions: {
158   - span: 24,
159   - },
160   - }
161   - );
  163 + const [
  164 + register,
  165 + { validateFields, clearValidate, getFieldsValue, resetFields, setFieldsValue },
  166 + ] = useForm({
  167 + labelWidth: 120,
  168 + schemas,
  169 + actionColOptions: {
  170 + span: 24,
  171 + },
  172 + });
162 173 async function validateForm() {
163 174 try {
164 175 const res = await validateFields();
... ... @@ -191,6 +202,7 @@
191 202 setFormValues,
192 203 validateForm,
193 204 resetValidate,
  205 + resetFields,
194 206 };
195 207 },
196 208 });
... ...
src/views/demo/table/FetchTable.vue
... ... @@ -24,9 +24,6 @@
24 24 });
25 25 function handleReloadCurrent() {
26 26 reload();
27   - // reload({
28   - // searchInfo: 'xxx',
29   - // });
30 27 }
31 28  
32 29 function handleReload() {
... ...
src/views/sys/login/ForgetPasswordForm.vue
... ... @@ -40,7 +40,7 @@
40 40 import { CountdownInput } from '/@/components/CountDown';
41 41  
42 42 import { useI18n } from '/@/hooks/web/useI18n';
43   - import { useLoginState, useFormRules, useFormValid, LoginStateEnum } from './useLogin';
  43 + import { useLoginState, useFormRules, LoginStateEnum } from './useLogin';
44 44  
45 45 export default defineComponent({
46 46 name: 'ForgetPasswordForm',
... ... @@ -66,14 +66,12 @@
66 66 sms: '',
67 67 });
68 68  
69   - const { validForm } = useFormValid(formRef);
70   -
71 69 const getShow = computed(() => unref(getLoginState) === LoginStateEnum.RESET_PASSWORD);
72 70  
73 71 async function handleReset() {
74   - const data = await validForm();
75   - if (!data) return;
76   - console.log(data);
  72 + const form = unref(formRef);
  73 + if (!form) return;
  74 + await form.resetFields();
77 75 }
78 76  
79 77 return {
... ...