fix: reset back to default value after fixing form query
This commit is contained in:
parent
5cff73bcaf
commit
1c075a7a32
|
|
@ -3,6 +3,7 @@
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
- 修复抽屉组件自动高度及显示 footer 显示问题
|
- 修复抽屉组件自动高度及显示 footer 显示问题
|
||||||
|
- 修复表单查询后重置回默认值
|
||||||
|
|
||||||
# 2.0.0-rc.4 (2020-10-21)
|
# 2.0.0-rc.4 (2020-10-21)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module.exports = {
|
||||||
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
|
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
|
||||||
'{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': ['prettier --write--parser json'],
|
'{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': ['prettier --write--parser json'],
|
||||||
'package.json': ['prettier --write'],
|
'package.json': ['prettier --write'],
|
||||||
'*.vue': ['prettier --write', 'stylelint --fix', 'git add .'],
|
'*.vue': ['prettier --write', 'stylelint --fix'],
|
||||||
'*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write', 'git add .'],
|
'*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write'],
|
||||||
'*.md': ['prettier --write'],
|
'*.md': ['prettier --write'],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,6 @@
|
||||||
|
|
||||||
&__active {
|
&__active {
|
||||||
transform: rotate(90deg);
|
transform: rotate(90deg);
|
||||||
// > span {
|
|
||||||
// transform: rotate(90deg);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<FormItem
|
<FormItem
|
||||||
:schema="schema"
|
:schema="schema"
|
||||||
:formProps="getProps"
|
:formProps="getProps"
|
||||||
:allDefaultValues="getAllDefaultValues"
|
:allDefaultValues="defaultValueRef"
|
||||||
:formModel="formModel"
|
:formModel="formModel"
|
||||||
>
|
>
|
||||||
<template #[item]="data" v-for="item in Object.keys($slots)">
|
<template #[item]="data" v-for="item in Object.keys($slots)">
|
||||||
|
|
@ -56,8 +56,8 @@
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'BasicForm',
|
name: 'BasicForm',
|
||||||
inheritAttrs: false,
|
|
||||||
components: { FormItem, Form, Row, FormAction },
|
components: { FormItem, Form, Row, FormAction },
|
||||||
|
inheritAttrs: false,
|
||||||
props: basicProps,
|
props: basicProps,
|
||||||
emits: ['advanced-change', 'reset', 'submit', 'register'],
|
emits: ['advanced-change', 'reset', 'submit', 'register'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
|
|
@ -68,6 +68,7 @@
|
||||||
isLoad: false,
|
isLoad: false,
|
||||||
actionSpan: 6,
|
actionSpan: 6,
|
||||||
});
|
});
|
||||||
|
const defaultValueRef = ref<any>({});
|
||||||
const propsRef = ref<Partial<FormProps>>({});
|
const propsRef = ref<Partial<FormProps>>({});
|
||||||
const schemaRef = ref<FormSchema[] | null>(null);
|
const schemaRef = ref<FormSchema[] | null>(null);
|
||||||
const formElRef = ref<Nullable<FormType>>(null);
|
const formElRef = ref<Nullable<FormType>>(null);
|
||||||
|
|
@ -132,17 +133,6 @@
|
||||||
return schemas as FormSchema[];
|
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 => {
|
const getEmptySpanRef = computed((): number => {
|
||||||
if (!advanceState.isAdvanced) {
|
if (!advanceState.isAdvanced) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -174,6 +164,19 @@
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ 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() {
|
function updateAdvanced() {
|
||||||
let itemColSum = 0;
|
let itemColSum = 0;
|
||||||
let realItemColSum = 0;
|
let realItemColSum = 0;
|
||||||
|
|
@ -191,7 +194,7 @@
|
||||||
model: formModel,
|
model: formModel,
|
||||||
field: schema.field,
|
field: schema.field,
|
||||||
values: {
|
values: {
|
||||||
...getAllDefaultValues,
|
...unerf(defaultValueRef),
|
||||||
...formModel,
|
...formModel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -343,6 +346,7 @@
|
||||||
}
|
}
|
||||||
schemaRef.value = schemaList as any;
|
schemaRef.value = schemaList as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 根据字段名删除
|
* @description: 根据字段名删除
|
||||||
*/
|
*/
|
||||||
|
|
@ -354,6 +358,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 往某个字段后面插入,如果没有插入最后一个
|
* @description: 往某个字段后面插入,如果没有插入最后一个
|
||||||
*/
|
*/
|
||||||
|
|
@ -400,7 +405,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
schemaRef.value = unique(schema, 'field') as any;
|
schemaRef.value = unique(schema, 'field') as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,6 +416,7 @@
|
||||||
toRef(props, 'transformDateFunc'),
|
toRef(props, 'transformDateFunc'),
|
||||||
toRef(props, 'fieldMapToTime')
|
toRef(props, 'fieldMapToTime')
|
||||||
);
|
);
|
||||||
|
|
||||||
function getFieldsValue(): any {
|
function getFieldsValue(): any {
|
||||||
const formEl = unref(formElRef);
|
const formEl = unref(formElRef);
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
|
|
@ -426,6 +431,7 @@
|
||||||
return item.field === key ? dateItemType.includes(item.component!) : false;
|
return item.field === key ? dateItemType.includes(item.component!) : false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description:设置表单
|
* @description:设置表单
|
||||||
*/
|
*/
|
||||||
|
|
@ -438,6 +444,7 @@
|
||||||
if (!formElRef.value) return;
|
if (!formElRef.value) return;
|
||||||
return formElRef.value.validateFields(nameList);
|
return formElRef.value.validateFields(nameList);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate(nameList?: NamePath[] | undefined) {
|
function validate(nameList?: NamePath[] | undefined) {
|
||||||
if (!formElRef.value) return;
|
if (!formElRef.value) return;
|
||||||
return formElRef.value.validate(nameList);
|
return formElRef.value.validate(nameList);
|
||||||
|
|
@ -460,14 +467,17 @@
|
||||||
validateFields: validateFields as ValidateFields,
|
validateFields: validateFields as ValidateFields,
|
||||||
validate: validate as ValidateFields,
|
validate: validate as ValidateFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
initDefault();
|
||||||
emit('register', methods);
|
emit('register', methods);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleToggleAdvanced,
|
handleToggleAdvanced,
|
||||||
formModel,
|
formModel,
|
||||||
getActionPropsRef,
|
getActionPropsRef,
|
||||||
getAllDefaultValues,
|
defaultValueRef,
|
||||||
advanceState,
|
advanceState,
|
||||||
getProps,
|
getProps,
|
||||||
formElRef,
|
formElRef,
|
||||||
|
|
|
||||||
|
|
@ -216,34 +216,36 @@
|
||||||
fetch();
|
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(
|
watch(
|
||||||
() => unref(getDataSourceRef),
|
() => unref(getDataSourceRef),
|
||||||
() => {
|
() => {
|
||||||
if (unref(getMergeProps).showSummary) {
|
handleSummary();
|
||||||
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,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,33 @@ export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
|
||||||
export function getFormConfig(): Partial<FormProps> {
|
export function getFormConfig(): Partial<FormProps> {
|
||||||
return {
|
return {
|
||||||
labelWidth: 100,
|
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() {
|
export function getBasicData() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue