Commit f964533701389109d90144cbefff7042cdcedbf6

Authored by 1sm
Committed by GitHub
1 parent dd158a17

feat(BasicForm): add `submitOnChange` option (#1521)

src/components/Form/src/BasicForm.vue
@@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
58 import { createFormContext } from './hooks/useFormContext'; 58 import { createFormContext } from './hooks/useFormContext';
59 import { useAutoFocus } from './hooks/useAutoFocus'; 59 import { useAutoFocus } from './hooks/useAutoFocus';
60 import { useModalContext } from '/@/components/Modal'; 60 import { useModalContext } from '/@/components/Modal';
  61 + import { useDebounceFn } from '@vueuse/core';
61 62
62 import { basicProps } from './props'; 63 import { basicProps } from './props';
63 import { useDesign } from '/@/hooks/web/useDesign'; 64 import { useDesign } from '/@/hooks/web/useDesign';
@@ -225,6 +226,14 @@ @@ -225,6 +226,14 @@
225 }, 226 },
226 ); 227 );
227 228
  229 + watch(
  230 + () => formModel,
  231 + useDebounceFn(() => {
  232 + unref(getProps).submitOnChange && handleSubmit();
  233 + }, 300),
  234 + { deep: true },
  235 + );
  236 +
228 async function setProps(formProps: Partial<FormProps>): Promise<void> { 237 async function setProps(formProps: Partial<FormProps>): Promise<void> {
229 propsRef.value = deepMerge(unref(propsRef) || {}, formProps); 238 propsRef.value = deepMerge(unref(propsRef) || {}, formProps);
230 } 239 }
src/components/Form/src/props.ts
@@ -40,6 +40,7 @@ export const basicProps = { @@ -40,6 +40,7 @@ export const basicProps = {
40 // 在INPUT组件上单击回车时,是否自动提交 40 // 在INPUT组件上单击回车时,是否自动提交
41 autoSubmitOnEnter: propTypes.bool.def(false), 41 autoSubmitOnEnter: propTypes.bool.def(false),
42 submitOnReset: propTypes.bool, 42 submitOnReset: propTypes.bool,
  43 + submitOnChange: propTypes.bool,
43 size: propTypes.oneOf(['default', 'small', 'large']).def('default'), 44 size: propTypes.oneOf(['default', 'small', 'large']).def('default'),
44 // 禁用表单 45 // 禁用表单
45 disabled: propTypes.bool, 46 disabled: propTypes.bool,
src/components/Form/src/types/form.ts
@@ -60,6 +60,8 @@ export interface FormProps { @@ -60,6 +60,8 @@ export interface FormProps {
60 rowProps?: RowProps; 60 rowProps?: RowProps;
61 // Submit form on reset 61 // Submit form on reset
62 submitOnReset?: boolean; 62 submitOnReset?: boolean;
  63 + // Submit form on form changing
  64 + submitOnChange?: boolean;
63 // Col configuration for the entire form 65 // Col configuration for the entire form
64 labelCol?: Partial<ColEx>; 66 labelCol?: Partial<ColEx>;
65 // Col configuration for the entire form 67 // Col configuration for the entire form
src/layouts/default/feature/index.vue
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 const { getUseOpenBackTop, getShowSettingButton, getSettingButtonPosition, getFullContent } = 23 const { getUseOpenBackTop, getShowSettingButton, getSettingButtonPosition, getFullContent } =
24 useRootSetting(); 24 useRootSetting();
25 const userStore = useUserStoreWithOut(); 25 const userStore = useUserStoreWithOut();
26 - const { prefixCls } = useDesign('setting-drawer-fearure'); 26 + const { prefixCls } = useDesign('setting-drawer-feature');
27 const { getShowHeader } = useHeaderSetting(); 27 const { getShowHeader } = useHeaderSetting();
28 28
29 const getIsSessionTimeout = computed(() => userStore.getSessionTimeout); 29 const getIsSessionTimeout = computed(() => userStore.getSessionTimeout);
@@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
59 </template> 59 </template>
60 60
61 <style lang="less"> 61 <style lang="less">
62 - @prefix-cls: ~'@{namespace}-setting-drawer-fearure'; 62 + @prefix-cls: ~'@{namespace}-setting-drawer-feature';
63 63
64 .@{prefix-cls} { 64 .@{prefix-cls} {
65 position: absolute; 65 position: absolute;
src/settings/projectSetting.ts
@@ -134,7 +134,7 @@ const setting: ProjectConfig = { @@ -134,7 +134,7 @@ const setting: ProjectConfig = {
134 // Transition Setting 134 // Transition Setting
135 transitionSetting: { 135 transitionSetting: {
136 // Whether to open the page switching animation 136 // Whether to open the page switching animation
137 - // The disabled state will also disable pageLoadinng 137 + // The disabled state will also disable pageLoading
138 enable: true, 138 enable: true,
139 139
140 // Route basic switching animation 140 // Route basic switching animation