供应商排序问题
This commit is contained in:
		
							parent
							
								
									5c612db1c7
								
							
						
					
					
						commit
						166a51958b
					
				| @ -216,11 +216,35 @@ const handleCurrentChange = (val) => { | |||||||
|   pagination.current = val; |   pagination.current = val; | ||||||
|   getList(); |   getList(); | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | const sortTreeByDescendingId = (nodes) => { | ||||||
|  |   if (!nodes || !nodes.length) return []; | ||||||
|  | 
 | ||||||
|  |   // 对当前层级节点排序(BigInt 安全比较) | ||||||
|  |   const sortedNodes = [...nodes].sort((a, b) => { | ||||||
|  |     const idA = BigInt(a.id); | ||||||
|  |     const idB = BigInt(b.id); | ||||||
|  |     return idA > idB ? -1 : idA < idB ? 1 : 0; // 降序 | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   // 递归排序每个节点的 children | ||||||
|  |   sortedNodes.forEach((node) => { | ||||||
|  |     if (node.children && node.children.length) { | ||||||
|  |       node.children = sortTreeByDescendingId(node.children); | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   return sortedNodes; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| const getTree = () => { | const getTree = () => { | ||||||
|   transaction().then((res) => { |   transaction().then((res) => { | ||||||
|     if (res.code === 200) { |     if (res.code === 200) { | ||||||
|       let a = res.data.sort((a, b) => Number(b.id) - Number(a.id)); |       // 2. 使用排序函数 | ||||||
|       treeList.splice(0, treeList.length, ...a); |       const sortedData = sortTreeByDescendingId(res.data); | ||||||
|  |       treeList.splice(0, treeList.length, ...sortedData); | ||||||
|  |       // let a = res.data.sort((a, b) => Number(b.id) - Number(a.id)); | ||||||
|  |       // treeList.splice(0, treeList.length, ...a); | ||||||
|       // console.log('treeList', treeList); |       // console.log('treeList', treeList); | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user