$item->title ?? $item->name ?? $item->id, 'value' => (string)$item->id, 'id' => $item->id, 'pid' => $item->pid, ]; } $tree = new Tree($format_items); return Json::success('ok', $tree->getTree()); } /** * 格式化表格树 * * @param $data * @param $total * * @return \support\Response */ protected function formatTableTree($data, $total): \support\Response { $tree = new Tree($data->toArray()); $items = $tree->getTree(); return Json::success('ok', $items); } /** * 格式化下拉列表 * * @param $items * * @return \support\Response */ protected function formatSelect($items): \support\Response { $formatted_items = []; foreach ($items as $item) { $formatted_items[] = [ 'label' => $item->title ?? $item->name ?? $item->real_name ?? $item->id, 'value' => $item->id, ]; } return Json::success('ok', $formatted_items); } /** * 通用格式化 * * @param $items * @param $total * * @return \support\Response */ protected function formatNormal($items, $total): \support\Response { return Json::success('ok', compact('items', 'total')); } }