Skip to content

Commit 0fcbe9f

Browse files
jevin98sleeprite
authored andcommitted
!484 fix(treeSelect): 设置replaceFields.children 输入框未反填二级内容
* chore: type * fix(treeSelect): 设置replaceFields.children 输入框未反填二级内容
1 parent e558159 commit 0fcbe9f

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

packages/component/component/treeSelect/__tests__/treeSelect.test.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { VueWrapper } from "@vue/test-utils";
77
import LayTreeSelect from "../index.vue";
88
import LayInput from "../../input/index.vue";
99
import LayTagInput from "@layui/component/component/tagInput/index.vue";
10+
import LayTag from "@layui/component/component/tag/index.vue";
1011
import { sleep } from "@layui/component/test-utils";
1112

1213
const teleportProps = { to: "body", disabled: true };
@@ -218,4 +219,91 @@ describe("LayTreeSelect", () => {
218219

219220
expect(tagInput.props('modelValue')?.length).toBe(2)
220221
});
222+
223+
test("replaceFields + 输入反填多级数据", async () => {
224+
225+
const wrapper = mount({
226+
setup() {
227+
const value1 = ref(11)
228+
229+
const data = ref([{
230+
name: "一级1",
231+
key: 1,
232+
spread: true,
233+
child: [
234+
{
235+
name: "一级1-1",
236+
key: 11,
237+
},
238+
],
239+
}]);
240+
241+
const replaceFields = {
242+
id: "key",
243+
title: "name",
244+
children: "child",
245+
};
246+
247+
248+
return () => (
249+
<LayTreeSelect
250+
v-model={value1.value}
251+
data={data.value}
252+
replaceFields={replaceFields}
253+
></LayTreeSelect>
254+
);
255+
},
256+
});
257+
258+
await nextTick();
259+
260+
const InputVm = wrapper.findComponent(LayInput);
261+
262+
expect(InputVm.props("modelValue")).toBe("一级1-1");
263+
});
264+
265+
test("replaceFields + 输入反填多级数据 + 多选", async () => {
266+
267+
const wrapper = mount({
268+
setup() {
269+
const value1 = ref([11])
270+
271+
const data = ref([{
272+
name: "一级1",
273+
key: 1,
274+
spread: true,
275+
child: [
276+
{
277+
name: "一级1-1",
278+
key: 11,
279+
},
280+
],
281+
}]);
282+
283+
const replaceFields = {
284+
id: "key",
285+
title: "name",
286+
children: "child",
287+
};
288+
289+
290+
return () => (
291+
<LayTreeSelect
292+
v-model={value1.value}
293+
multiple
294+
data={data.value}
295+
replaceFields={replaceFields}
296+
></LayTreeSelect>
297+
);
298+
},
299+
});
300+
301+
await nextTick();
302+
303+
const tagInput = wrapper.findComponent(LayTagInput);
304+
expect(tagInput.props('modelValue')?.length).toBe(1)
305+
306+
const tagComponent = tagInput.findComponent(LayTag);
307+
expect(tagComponent.text()).toBe('一级1-1')
308+
});
221309
});

packages/component/component/treeSelect/index.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import LayInput from "@layui/component/component/input/index.vue";
1818
import LayTagInput from "@layui/component/component/tagInput/index.vue";
1919
import { treeReplaceFields } from "@layui/component/component/tree/constant";
2020
import LayTree from "@layui/component/component/tree/index.vue";
21-
import { isArray } from "@layui/component/utils";
21+
import { isArray, isValueArray } from "@layui/component/utils";
2222
import { LayIcon } from "@layui/icons-vue";
2323
import { useDebounceFn } from "@vueuse/core";
2424
import { computed, provide, ref, useSlots, watch } from "vue";
@@ -80,8 +80,10 @@ const flatData = computed(() => {
8080
const flatter = <K extends OriginalTreeData>(target: Array<K>) => {
8181
target.forEach((item) => {
8282
ret.push(item);
83-
if (item.children?.length) {
84-
flatter(item.children);
83+
84+
const children: K[] = item[_replaceFields.value.children];
85+
if (isValueArray(children)) {
86+
flatter(children);
8587
}
8688
});
8789
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy