* [bug#64003,done,0.1h,0h] Optimize code.

This commit is contained in:
wangyuting
2025-07-14 17:17:56 +08:00
parent 604a47a7e5
commit 24f21ca529
+5 -5
View File
@@ -1785,12 +1785,12 @@ class testcase extends control
->fetchPairs();
$sortList = array_keys($sortList);
$sourceIndex = array_search($sourceID, $sortList);
$sourceData = array_splice($sortList, $sourceIndex, 1);
$targetIndex = array_search($targetID, $sortList);
array_splice($sortList, $type == 'before' ? $targetIndex : ($targetIndex + 1), 0, $sourceData);
$sourceIndex = array_search($sourceID, $sortList); // 获取拖动排序对象的索引。
$sourceData = array_splice($sortList, $sourceIndex, 1); // 将拖动排序的对象从数组移除。
$targetIndex = array_search($targetID, $sortList); // 获取拖动后排序对象的索引。
array_splice($sortList, $type == 'before' ? $targetIndex : ($targetIndex + 1), 0, $sourceData); // 将排序的对象放置在拖动后排序对象的前面或者后面。
foreach($sortList as $sort => $sortID) $this->dao->update($table)->set('sort')->eq($sort)->where('id')->eq($sortID)->exec();
foreach($sortList as $sort => $objectID) $this->dao->update($table)->set('sort')->eq($sort)->where('id')->eq($objectID)->exec();
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
}