Commit 9435b480abaec54151496b6f3afdaa5d1d654408
Committed by
GitHub
1 parent
8c2ba755
解决deleteTableRecord删除树形表格的行记录时,无法删除,无法找到子节点的问题 (#2461)
* feat(axiosSuccess): 操作成功后根据传入提示模式进行相应 * fix(axiosRetry): 解决get重试请求返回的headers造成无法成功请求的问题 * fix(axiosRetry): 参数首字母小写 * fix(useDataSource): 解决deleteTableRecord删除树形表格的行记录时,无法删除,无法找到子节点的问题
Showing
1 changed file
with
34 additions
and
22 deletions
src/components/Table/src/hooks/useDataSource.ts
@@ -165,30 +165,42 @@ export function useDataSource( | @@ -165,30 +165,42 @@ export function useDataSource( | ||
165 | const rowKeyName = unref(getRowKey); | 165 | const rowKeyName = unref(getRowKey); |
166 | if (!rowKeyName) return; | 166 | if (!rowKeyName) return; |
167 | const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey; | 167 | const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey; |
168 | - for (const key of rowKeys) { | ||
169 | - let index: number | undefined = dataSourceRef.value.findIndex((row) => { | ||
170 | - let targetKeyName: string; | ||
171 | - if (typeof rowKeyName === 'function') { | ||
172 | - targetKeyName = rowKeyName(row); | ||
173 | - } else { | ||
174 | - targetKeyName = rowKeyName as string; | ||
175 | - } | ||
176 | - return row[targetKeyName] === key; | ||
177 | - }); | ||
178 | - if (index >= 0) { | ||
179 | - dataSourceRef.value.splice(index, 1); | 168 | + |
169 | + function deleteRow(data, key) { | ||
170 | + const row: { index: number; data: [] } = findRow(data, key); | ||
171 | + if (row === null || row.index === -1) { | ||
172 | + return; | ||
180 | } | 173 | } |
181 | - index = unref(propsRef).dataSource?.findIndex((row) => { | ||
182 | - let targetKeyName: string; | ||
183 | - if (typeof rowKeyName === 'function') { | ||
184 | - targetKeyName = rowKeyName(row); | ||
185 | - } else { | ||
186 | - targetKeyName = rowKeyName as string; | 174 | + row.data.splice(row.index, 1); |
175 | + | ||
176 | + function findRow(data, key) { | ||
177 | + if (data === null || data === undefined) { | ||
178 | + return null; | ||
187 | } | 179 | } |
188 | - return row[targetKeyName] === key; | ||
189 | - }); | ||
190 | - if (typeof index !== 'undefined' && index !== -1) | ||
191 | - unref(propsRef).dataSource?.splice(index, 1); | 180 | + for (let i = 0; i < data.length; i++) { |
181 | + const row = data[i]; | ||
182 | + let targetKeyName: string = rowKeyName as string; | ||
183 | + if (isFunction(rowKeyName)) { | ||
184 | + targetKeyName = rowKeyName(row); | ||
185 | + } | ||
186 | + if (row[targetKeyName] === key) { | ||
187 | + return { index: i, data }; | ||
188 | + } | ||
189 | + if (row.children?.length > 0) { | ||
190 | + console.log(row.children, i); | ||
191 | + const result = findRow(row.children, key); | ||
192 | + if (result != null) { | ||
193 | + return result; | ||
194 | + } | ||
195 | + } | ||
196 | + } | ||
197 | + return null; | ||
198 | + } | ||
199 | + } | ||
200 | + | ||
201 | + for (const key of rowKeys) { | ||
202 | + deleteRow(dataSourceRef.value, key); | ||
203 | + deleteRow(unref(propsRef).dataSource, key); | ||
192 | } | 204 | } |
193 | setPagination({ | 205 | setPagination({ |
194 | total: unref(propsRef).dataSource?.length, | 206 | total: unref(propsRef).dataSource?.length, |