Skip to content

Commit

Permalink
fix(form): tabs配置name后出错
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed Jul 5, 2022
1 parent 26c60c3 commit 9454bb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
13 changes: 11 additions & 2 deletions packages/form/src/containers/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
v-for="item in tabItems(tab)"
:key="item[mForm?.keyProp || '__key']"
:config="item"
:model="config.dynamic ? model[config.name || ''][tabIndex] : tab.name ? model[tab.name] : model"
:model="
config.dynamic
? (name ? model[name] : model)[tabIndex]
: tab.name
? (name ? model[name] : model)[tab.name]
: name
? model[name]
: model
"
:prop="config.dynamic ? `${prop}${prop ? '.' : ''}${String(tabIndex)}` : prop"
:size="size"
:label-width="tab.labelWidth || labelWidth"
Expand All @@ -34,7 +42,6 @@
</template>

<script lang="ts">
/* eslint-disable vue/no-mutating-props */
import { computed, defineComponent, inject, PropType, ref, watchEffect } from 'vue';
import { cloneDeep } from 'lodash-es';
Expand Down Expand Up @@ -87,6 +94,8 @@ const Tab = defineComponent({
prop: String,
name: String,
size: String,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/form/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ export interface TabPaneConfig {
lazy?: boolean;
labelWidth?: string;
items: FormConfig;
onTabClick?: (mForm: FormState | undefined, tab: any, data: any) => void;
[key: string]: any;
}
export interface TabConfig extends FormItem, ContainerCommonConfig {
Expand All @@ -527,6 +528,7 @@ export interface TabConfig extends FormItem, ContainerCommonConfig {
onChange?: (mForm: FormState | undefined, data: any) => void;
onTabAdd?: (mForm: FormState | undefined, data: any) => void;
onTabRemove?: (mForm: FormState | undefined, tabName: string, data: any) => void;
onTabClick?: (mForm: FormState | undefined, tab: any, data: any) => void;
activeChange?: (mForm: FormState | undefined, tabName: string, data: any) => void;
}

Expand Down
13 changes: 2 additions & 11 deletions packages/form/src/utils/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ const asyncLoadConfig = (value: FormValue, initValue: FormValue, { asyncLoad, na

const isMultipleValue = (type?: string | TypeFunction) =>
typeof type === 'string' &&
[
'checkbox-group',
'checkboxGroup',
'table',
'cascader',
'group-list',
'groupList',
'dynamic-tab',
'dynamicTab',
].includes(type);
['checkbox-group', 'checkboxGroup', 'table', 'cascader', 'group-list', 'groupList'].includes(type);

const initItemsValue = (
mForm: FormState | undefined,
Expand All @@ -83,7 +74,7 @@ const initItemsValue = (
const setValue = (mForm: FormState | undefined, value: FormValue, initValue: FormValue, item: any) => {
const { items, name, type, checkbox } = item;
// 值是数组, 有可能也有items配置,所以不能放到getDefaultValue里赋值
if (isMultipleValue(type)) {
if (isMultipleValue(type) || (type === 'tab' && item.dynamic)) {
value[name] = initValue[name] || [];
}

Expand Down

0 comments on commit 9454bb3

Please sign in to comment.