<?php if (! function_exists('ossUrl')) { /* * 如果url 不是http或https开头,则加上oss的域名 * @param string $path 路径 */ function ossUrl($path) { if (empty($path)) { return ''; } if (strpos($path, 'http') === 0 || strpos($path, 'https') === 0) { return $path; } return env('OSS_HOST').'/'. $path; } } if (! function_exists('getBreadcrumb')) { function getBreadcrumb($id, $data, $path = []) { foreach ($data as $item) { // 如果当前项的 id 匹配,将其 title 加入路径 if ($item['id'] == $id) { $path[] = $item['title']; return $path; } // 如果有子节点,递归查找 if (!empty($item['children'])) { $result = getBreadcrumb($id, $item['children'], $path); if (!empty($result)) { // 如果找到匹配的子节点,将当前项的 title 加入路径 array_unshift($result, $item['title']); return $result; } } } // 如果没有找到匹配的 id,返回空数组 return []; } }