Commit b06a7ab77b99abee63dd55770ffd55b594ee42f9

Authored by 无木
1 parent 1b3058f8

fix(basic-tree): `checkedKeys` not worked with `search`

修复搜索功能可能导致`checkedKeys`丢失的问题

fixed: #915
CHANGELOG.zh_CN.md
... ... @@ -8,15 +8,15 @@
8 8  
9 9 ### 🐛 Bug Fixes
10 10  
11   -- **Table**
12   - - 修复滚动条样式问题
  11 +- **BasicTable**
  12 + - 修复滚动条样式问题(移除了滚动样式补丁)
13 13 - 修复树形表格的带有展开图标的单元格的内容对齐问题
14 14 - 新增`headerTop`插槽
15 15 - 修复操作列的按钮在 disabled 状态下的颜色显示
16   -- **AppSearch** 修复可能会搜索隐藏菜单的问题
17 16 - **TableAction**
18   - - 仅在 action.tooltip 存在的情况下 才包裹 Tooltip 组件
  17 + - 仅在 `action.tooltip`存在的情况下 才创建 Tooltip 组件
19 18 - 修复组件内的圆形按钮内容没有居中的问题
  19 +- **AppSearch** 修复可能会搜索隐藏菜单的问题
20 20 - **BasicUpload** 修复处理非`array`值时报错的问题
21 21 - **Form** 修复`FormItem`的`suffix`插槽样式问题
22 22 - **Menu**
... ... @@ -27,6 +27,7 @@
27 27 - **Markdown** 修复初始化异常以及不能正确地动态设置 value 的问题
28 28 - **Modal** 确保 props 正确被传递
29 29 - **MultipleTab** 修复可能会意外创建登录路由标签的问题
  30 +- **BasicTree** 修复搜索功能可能导致`checkedKeys`丢失的问题
30 31 - **其它**
31 32 - 修复菜单默认折叠的配置不起作用的问题
32 33 - 修复`safari`浏览器报错导致网站打不开
... ...
src/components/Tree/src/Tree.vue
... ... @@ -18,7 +18,7 @@
18 18 import TreeHeader from './TreeHeader.vue';
19 19 import { ScrollContainer } from '/@/components/Container';
20 20  
21   - import { omit, get } from 'lodash-es';
  21 + import { omit, get, cloneDeep, concat, uniq } from 'lodash-es';
22 22 import { isBoolean, isFunction } from '/@/utils/is';
23 23 import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper';
24 24 import { filter } from '/@/utils/helper/treeHelper';
... ... @@ -56,6 +56,25 @@
56 56 searchData: [] as TreeItem[],
57 57 });
58 58  
  59 + const copyState = {
  60 + checkedKeys: [],
  61 + };
  62 +
  63 + watch(
  64 + () => searchState.startSearch,
  65 + (newVal, oldVal) => {
  66 + if (newVal && !oldVal) {
  67 + // before search, save current checkedKeys
  68 + copyState.checkedKeys = cloneDeep(state.checkedKeys);
  69 + } else if (!newVal && oldVal) {
  70 + // after search, restore checkedKeys
  71 + state.checkedKeys = uniq(concat(state.checkedKeys, copyState.checkedKeys));
  72 + copyState.checkedKeys = [];
  73 + }
  74 + },
  75 + { immediate: true }
  76 + );
  77 +
59 78 const treeDataRef = ref<TreeItem[]>([]);
60 79  
61 80 const [createContextMenu] = useContextMenu();
... ...