Skip to content

Commit

Permalink
fix: 修复表单form.value默认值无法赋值的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Oct 26, 2023
1 parent 4109872 commit d40def3
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/fast-crud/src/components/crud/fs-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,28 +256,20 @@ export default defineComponent({
});
function createInitialForm() {
// eslint-disable-next-line vue/no-setup-props-destructure
const initialForm = _.cloneDeep(props.initialForm);
const form = _.cloneDeep(props.initialForm);
// 初始数据赋值
// eslint-disable-next-line vue/no-setup-props-destructure
_.each(props.columns, (item, key) => {
_.set(form, key, undefined);
const defValue = unref(item.value);
if (defValue !== undefined) {
_.set(form, key, defValue);
}
if (initialForm) {
const value = _.get(initialForm, key);
if (value != null) {
_.set(form, key, value);
}
}
});
return initialForm;
return form;
}
const initialForm = createInitialForm();
setFormData(initialForm);
const scope: Ref<FormScopeContext> = computed(() => {
return {
Expand All @@ -298,11 +290,12 @@ export default defineComponent({
return props.columns;
}, getContextFn);
//form.valueBuilder
function doValueBuilder(form: any) {
if (form == null) {
return;
}
_.each(computedColumns.value, (item, key) => {
_.each(props.columns, (item, key) => {
let value = _.get(form, key);
if (item.valueBuilder) {
item.valueBuilder({
Expand Down Expand Up @@ -380,11 +373,13 @@ export default defineComponent({
const groupActiveKey = ref([]);
// eslint-disable-next-line vue/no-setup-props-destructure
_.forEach(props.group?.groups, (groupItem, key) => {
if (groupItem.collapsed !== true) {
groupActiveKey.value.push(key);
}
});
// eslint-disable-next-line vue/no-setup-props-destructure
if (props.group?.groupType === "tabs") {
groupActiveKey.value = groupActiveKey.value.length > 0 ? groupActiveKey.value[0] : null;
}
Expand Down Expand Up @@ -460,6 +455,7 @@ export default defineComponent({
async function reset() {
// ui.form.resetWrap(formRef.value, { form, initialForm: createInitialForm() });
const initialForm = createInitialForm();
debugger;
const entries = _.entries(form);
for (const entry of entries) {
const initialValue = _.get(initialForm, entry[0]);
Expand Down

0 comments on commit d40def3

Please sign in to comment.