|
@@ -270,12 +270,13 @@ class FolderController extends Controller
|
|
|
|
|
|
$objectWhere = ['object_type' => $objectType, 'object_id' => $objectId,];
|
|
|
$folders = Folder::query()
|
|
|
+ ->select(['id', 'name'])
|
|
|
->where($objectWhere)
|
|
|
->when($folderId, fn($query) => $query->where("parent_id", $folderId))
|
|
|
->when(! $folderId, fn($query) => $query->where("parent_id", 0))
|
|
|
->orderBy('updated_at', $orderBy)
|
|
|
- ->get(['id', 'name']);
|
|
|
-
|
|
|
+ ->paginate($pageSize);
|
|
|
+ $folders_total = $folders->total();
|
|
|
$sonFolderCount=Folder::query()
|
|
|
->where($objectWhere)
|
|
|
->whereIn('parent_id',$folders->pluck('id'))
|
|
@@ -291,6 +292,7 @@ class FolderController extends Controller
|
|
|
->groupBy("folder_id")
|
|
|
->pluck("cut", "folder_id");
|
|
|
|
|
|
+
|
|
|
$index=1;
|
|
|
$folders = $folders->map(function (Folder $folder) use ($sonFolderCount,$sonFileCount,&$index) {
|
|
|
$folder->itemCount =$sonFolderCount->get($folder->id, 0)+$sonFileCount->get($folder->id, 0);
|
|
@@ -300,19 +302,41 @@ class FolderController extends Controller
|
|
|
return $folder;
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$files = File::query()->where($objectWhere)
|
|
|
->with('bimFile')
|
|
|
->where("folder_id", $folderId)
|
|
|
->where("is_latest_version", 1)
|
|
|
->orderBy('updated_at', $orderBy)
|
|
|
->get();
|
|
|
+
|
|
|
+ $files_total = $files->count();
|
|
|
+
|
|
|
+ $total = $files_total + $folders_total;
|
|
|
+ //分页
|
|
|
+ if ($folders_total < $pageSize * $page){
|
|
|
+ $offset = $pageSize * $page - $folders_total < $pageSize ? 0 : $pageSize * $page - $total - $folders_total; // 查看当前页面是否有包含文件夹
|
|
|
+ $limit = $pageSize * $page - $folders_total > $pageSize ? $pageSize : $pageSize * $page - $folders_total;
|
|
|
+
|
|
|
+ $files = File::query()->where($objectWhere)
|
|
|
+ ->with('bimFile')
|
|
|
+ ->where("folder_id", $folderId)
|
|
|
+ ->where("is_latest_version", 1)
|
|
|
+ ->orderBy('updated_at', $orderBy)
|
|
|
+ ->offset($offset)
|
|
|
+ ->limit($limit)
|
|
|
+ ->get();
|
|
|
+ //因为要接着文件夹进行文件id递增
|
|
|
+ $folderCount=$folders->count()+1;
|
|
|
+ $files->map(function (File $file) use (&$folderCount) {
|
|
|
+ $file->display_id=$folderCount++;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ //目录的总数 大于 显示数 时,不显示文件列表
|
|
|
+ $files = [];
|
|
|
+ }
|
|
|
+
|
|
|
//因为要接着文件夹进行文件id递增
|
|
|
- $folderCount=$folders->count()+1;
|
|
|
- $files->map(function (File $file) use (&$folderCount) {
|
|
|
- $file->display_id=$folderCount++;
|
|
|
- });
|
|
|
+
|
|
|
|
|
|
$container=[
|
|
|
'id'=>$object->id,
|
|
@@ -329,6 +353,7 @@ class FolderController extends Controller
|
|
|
'object'=>$container,
|
|
|
'data' => [
|
|
|
'folders' => $folders,
|
|
|
+ 'total' => $folders_total + $files_total,
|
|
|
'files' => FileByObjectResource::collection($files),
|
|
|
'folder_parent_id'=>$folderId>0?$folder->parent_id:$folderId,
|
|
|
]
|