Skip to content
Permalink
Browse files

调整文件自然排序

  • Loading branch information...
WangNingkai committed Jun 30, 2019
1 parent 1f44f14 commit f66cf886e8f6191defae816f40d820f9e3af5a44
Showing with 9 additions and 1 deletion.
  1. +9 −1 app/Http/Controllers/IndexController.php
@@ -178,21 +178,29 @@ public function list(Request $request)
@list($field, $sortBy) = explode(',', $order);
$itemsBase = collect($originItems);
// 文件夹/文件夹 排序
// 默认排序字段
if ($field === '' || $sortBy === null) {
$field = 'name';
$sortBy = 'asc';
}
// 筛选文件夹/文件夹
$folders = $itemsBase->filter(static function ($value) {
return Arr::has($value, 'folder');
});
$files = $itemsBase->filter(static function ($value) {
return !Arr::has($value, 'folder');
});
// 执行文件夹/文件夹 排序
if (strtolower($sortBy) !== 'desc') {
$folders = $folders->sortBy($field, $field === 'name' ? SORT_NATURAL : SORT_REGULAR)->toArray();
$files = $files->sortBy($field, $field === 'name' ? SORT_NATURAL : SORT_REGULAR)->toArray();
} else {
$folders = $folders->sortByDesc($field, $field === 'name' ? SORT_NATURAL : SORT_REGULAR)->toArray();
$files = $files->sortByDesc($field, $field === 'name' ? SORT_NATURAL : SORT_REGULAR)->toArray();
}
// 合并
$originItems = collect($folders)->merge($files)->toArray();
$limit = $request->get('limit', 20);

0 comments on commit f66cf88

Please sign in to comment.
You can’t perform that action at this time.