fix: reset back to default value after fixing form query
| | |
| | | ### 🐛 Bug Fixes |
| | | |
| | | - 修复抽屉组件自动高度及显示 footer 显示问题 |
| | | - 修复表单查询后重置回默认值 |
| | | |
| | | # 2.0.0-rc.4 (2020-10-21) |
| | | |
| | |
| | | '*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'], |
| | | '{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': ['prettier --write--parser json'], |
| | | 'package.json': ['prettier --write'], |
| | | '*.vue': ['prettier --write', 'stylelint --fix', 'git add .'], |
| | | '*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write', 'git add .'], |
| | | '*.vue': ['prettier --write', 'stylelint --fix'], |
| | | '*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write'], |
| | | '*.md': ['prettier --write'], |
| | | }; |
| | |
| | | |
| | | &__active { |
| | | transform: rotate(90deg); |
| | | // > span { |
| | | // transform: rotate(90deg); |
| | | // } |
| | | } |
| | | } |
| | | </style> |
| | |
| | | <FormItem |
| | | :schema="schema" |
| | | :formProps="getProps" |
| | | :allDefaultValues="getAllDefaultValues" |
| | | :allDefaultValues="defaultValueRef" |
| | | :formModel="formModel" |
| | | > |
| | | <template #[item]="data" v-for="item in Object.keys($slots)"> |
| | |
| | | |
| | | export default defineComponent({ |
| | | name: 'BasicForm', |
| | | inheritAttrs: false, |
| | | components: { FormItem, Form, Row, FormAction }, |
| | | inheritAttrs: false, |
| | | props: basicProps, |
| | | emits: ['advanced-change', 'reset', 'submit', 'register'], |
| | | setup(props, { emit }) { |
| | |
| | | isLoad: false, |
| | | actionSpan: 6, |
| | | }); |
| | | const defaultValueRef = ref<any>({}); |
| | | const propsRef = ref<Partial<FormProps>>({}); |
| | | const schemaRef = ref<FormSchema[] | null>(null); |
| | | const formElRef = ref<Nullable<FormType>>(null); |
| | |
| | | return schemas as FormSchema[]; |
| | | }); |
| | | |
| | | const getAllDefaultValues = computed(() => { |
| | | const schemas = unref(getSchema); |
| | | const obj: any = {}; |
| | | schemas.forEach((item) => { |
| | | if (item.defaultValue) { |
| | | obj[item.field] = item.defaultValue; |
| | | (formModel as any)[item.field] = item.defaultValue; |
| | | } |
| | | }); |
| | | return obj; |
| | | }); |
| | | const getEmptySpanRef = computed((): number => { |
| | | if (!advanceState.isAdvanced) { |
| | | return 0; |
| | |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | | |
| | | function initDefault() { |
| | | const schemas = unref(getSchema); |
| | | const obj: any = {}; |
| | | schemas.forEach((item) => { |
| | | if (item.defaultValue) { |
| | | obj[item.field] = item.defaultValue; |
| | | (formModel as any)[item.field] = item.defaultValue; |
| | | } |
| | | }); |
| | | defaultValueRef.value = obj; |
| | | } |
| | | |
| | | function updateAdvanced() { |
| | | let itemColSum = 0; |
| | | let realItemColSum = 0; |
| | |
| | | model: formModel, |
| | | field: schema.field, |
| | | values: { |
| | | ...getAllDefaultValues, |
| | | ...unerf(defaultValueRef), |
| | | ...formModel, |
| | | }, |
| | | }); |
| | |
| | | } |
| | | schemaRef.value = schemaList as any; |
| | | } |
| | | |
| | | /** |
| | | * @description: 根据字段名删除 |
| | | */ |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description: 往某个字段后面插入,如果没有插入最后一个 |
| | | */ |
| | |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | schemaRef.value = unique(schema, 'field') as any; |
| | | } |
| | | |
| | |
| | | toRef(props, 'transformDateFunc'), |
| | | toRef(props, 'fieldMapToTime') |
| | | ); |
| | | |
| | | function getFieldsValue(): any { |
| | | const formEl = unref(formElRef); |
| | | if (!formEl) return; |
| | |
| | | return item.field === key ? dateItemType.includes(item.component!) : false; |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * @description:设置表单 |
| | | */ |
| | |
| | | if (!formElRef.value) return; |
| | | return formElRef.value.validateFields(nameList); |
| | | } |
| | | |
| | | function validate(nameList?: NamePath[] | undefined) { |
| | | if (!formElRef.value) return; |
| | | return formElRef.value.validate(nameList); |
| | |
| | | validateFields: validateFields as ValidateFields, |
| | | validate: validate as ValidateFields, |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | initDefault(); |
| | | emit('register', methods); |
| | | }); |
| | | |
| | | return { |
| | | handleToggleAdvanced, |
| | | formModel, |
| | | getActionPropsRef, |
| | | getAllDefaultValues, |
| | | defaultValueRef, |
| | | advanceState, |
| | | getProps, |
| | | formElRef, |
| | |
| | | fetch(); |
| | | } |
| | | |
| | | function handleSummary() { |
| | | if (unref(getMergeProps).showSummary) { |
| | | nextTick(() => { |
| | | const tableEl = unref(tableElRef); |
| | | if (!tableEl) { |
| | | return; |
| | | } |
| | | const bodyDomList = tableEl.$el.querySelectorAll('.ant-table-body') as HTMLDivElement[]; |
| | | const bodyDom = bodyDomList[0]; |
| | | useEvent({ |
| | | el: bodyDom, |
| | | name: 'scroll', |
| | | listener: () => { |
| | | const footerBodyDom = tableEl.$el.querySelector( |
| | | '.ant-table-footer .ant-table-body' |
| | | ) as HTMLDivElement; |
| | | if (!footerBodyDom || !bodyDom) return; |
| | | footerBodyDom.scrollLeft = bodyDom.scrollLeft; |
| | | }, |
| | | wait: 0, |
| | | options: true, |
| | | }); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | watch( |
| | | () => unref(getDataSourceRef), |
| | | () => { |
| | | if (unref(getMergeProps).showSummary) { |
| | | nextTick(() => { |
| | | const tableEl = unref(tableElRef); |
| | | if (!tableEl) { |
| | | return; |
| | | } |
| | | const bodyDomList = tableEl.$el.querySelectorAll( |
| | | '.ant-table-body' |
| | | ) as HTMLDivElement[]; |
| | | const bodyDom = bodyDomList[0]; |
| | | useEvent({ |
| | | el: bodyDom, |
| | | name: 'scroll', |
| | | listener: () => { |
| | | const footerBodyDom = tableEl.$el.querySelector( |
| | | '.ant-table-footer .ant-table-body' |
| | | ) as HTMLDivElement; |
| | | if (!footerBodyDom || !bodyDom) return; |
| | | footerBodyDom.scrollLeft = bodyDom.scrollLeft; |
| | | }, |
| | | wait: 0, |
| | | options: true, |
| | | }); |
| | | }); |
| | | } |
| | | handleSummary(); |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | |
| | | export function getFormConfig(): Partial<FormProps> { |
| | | return { |
| | | labelWidth: 100, |
| | | schemas: getAdvanceSchema(6), |
| | | schemas: [ |
| | | ...getAdvanceSchema(5), |
| | | { |
| | | field: `field11`, |
| | | label: `字段33`, |
| | | component: 'Select', |
| | | defaultValue: '1', |
| | | componentProps: { |
| | | options: [ |
| | | { |
| | | label: '选项1', |
| | | value: '1', |
| | | key: '1', |
| | | }, |
| | | { |
| | | label: '选项2', |
| | | value: '2', |
| | | key: '2', |
| | | }, |
| | | ], |
| | | }, |
| | | colProps: { |
| | | xl: 12, |
| | | xxl: 8, |
| | | }, |
| | | }, |
| | | ], |
| | | }; |
| | | } |
| | | export function getBasicData() { |