From 2ca2897cd0abb3e3d30091cfc3e92cf3f07f5cdd Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 7 Aug 2020 22:09:53 +0800 Subject: [PATCH] add file-management view --- .../Abp/FileManagement/FileSystemDto.cs | 1 + .../FileManagement/FileSystemAppService.cs | 60 ++++- .../FileManagement/FileSystemController.cs | 10 +- .../PlatformPermissionDefinitionProvider.cs | 26 +-- .../BackendAdminHostModule.cs | 2 + .../LINGYUN.BackendAdminApp.Host.csproj | 1 + vueJs/src/api/clients.ts | 1 - vueJs/src/api/filemanagement.ts | 103 ++++++++ vueJs/src/lang/zh.ts | 14 +- vueJs/src/router/index.ts | 3 +- vueJs/src/router/modules/file-management.ts | 27 +++ vueJs/src/views/file-management/index.vue | 220 ++++++++++++++++++ 12 files changed, 436 insertions(+), 32 deletions(-) create mode 100644 vueJs/src/api/filemanagement.ts create mode 100644 vueJs/src/router/modules/file-management.ts create mode 100644 vueJs/src/views/file-management/index.vue diff --git a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application.Contracts/LINGYUN/Abp/FileManagement/FileSystemDto.cs b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application.Contracts/LINGYUN/Abp/FileManagement/FileSystemDto.cs index 5efdebc45..aecbd0be0 100644 --- a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application.Contracts/LINGYUN/Abp/FileManagement/FileSystemDto.cs +++ b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application.Contracts/LINGYUN/Abp/FileManagement/FileSystemDto.cs @@ -7,6 +7,7 @@ namespace LINGYUN.Abp.FileManagement public FileSystemType Type { get; set; } public string Name { get; set; } public string Parent { get; set; } + public string Extension { get; set; } public long? Size { get; set; } public DateTime CreationTime { get; set; } public DateTime? LastModificationTime { get; set; } diff --git a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application/LINGYUN/Abp/FileManagement/FileSystemAppService.cs b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application/LINGYUN/Abp/FileManagement/FileSystemAppService.cs index 1d2c82838..68e3b603c 100644 --- a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application/LINGYUN/Abp/FileManagement/FileSystemAppService.cs +++ b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.Application/LINGYUN/Abp/FileManagement/FileSystemAppService.cs @@ -142,12 +142,13 @@ namespace LINGYUN.Abp.FileManagement Type = FileSystemType.File, Name = fileInfo.Name, Size = fileInfo.Length, + Extension = fileInfo.Extension, CreationTime = fileInfo.CreationTime, LastModificationTime = fileInfo.LastWriteTime }; - if (fileInfo.Directory?.Parent != null && !fileInfo.Directory.Parent.Name.IsNullOrWhiteSpace()) + if (fileInfo.Directory != null && !fileInfo.Directory.FullName.IsNullOrWhiteSpace()) { - fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.Parent.FullName); + fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.FullName); } return Task.FromResult(fileSystem); } @@ -161,7 +162,7 @@ namespace LINGYUN.Abp.FileManagement CreationTime = directoryInfo.CreationTime, LastModificationTime = directoryInfo.LastWriteTime }; - if (directoryInfo.Parent != null && !directoryInfo.Parent.Name.IsNullOrWhiteSpace()) + if (directoryInfo.Parent != null && !directoryInfo.Parent.FullName.IsNullOrWhiteSpace()) { fileSystem.Parent = GetFileSystemRelativePath(directoryInfo.Parent.FullName); } @@ -207,19 +208,21 @@ namespace LINGYUN.Abp.FileManagement CreationTime = fileSystemInfo.CreationTime, LastModificationTime = fileSystemInfo.LastWriteTime, }; + if (fileSystemInfo is FileInfo fileInfo) { fileSystem.Type = FileSystemType.File; fileSystem.Size = fileInfo.Length; - if (fileInfo.Directory?.Parent != null && !fileInfo.Directory.Parent.Name.IsNullOrWhiteSpace()) + fileSystem.Extension = fileInfo.Extension; + if (fileInfo.Directory != null && !fileInfo.Directory.FullName.IsNullOrWhiteSpace()) { - fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.Parent.FullName); + fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.FullName); } } else if (fileSystemInfo is DirectoryInfo directory) { fileSystem.Type = FileSystemType.Folder; - if (directory.Parent != null && !directory.Parent.Name.IsNullOrWhiteSpace()) + if (directory.Parent != null && !directory.Parent.FullName.IsNullOrWhiteSpace()) { fileSystem.Parent = GetFileSystemRelativePath(directory.Parent.FullName); } @@ -227,6 +230,11 @@ namespace LINGYUN.Abp.FileManagement fileSystems.Add(fileSystem); } + fileSystems = fileSystems + .OrderBy(f => f.Type) + .ThenBy(f => f.Name) + .ToList(); + return Task.FromResult(new PagedResultDto( fileSystemInfos.Length, fileSystems )); @@ -288,12 +296,13 @@ namespace LINGYUN.Abp.FileManagement Type = FileSystemType.File, Name = fileInfo.Name, Size = fileInfo.Length, + Extension = fileInfo.Extension, CreationTime = fileInfo.CreationTime, LastModificationTime = fileInfo.LastWriteTime }; - if (fileInfo.Directory?.Parent != null && !fileInfo.Directory.Parent.Name.IsNullOrWhiteSpace()) + if (fileInfo.Directory != null && !fileInfo.Directory.FullName.IsNullOrWhiteSpace()) { - fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.Parent.FullName); + fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.FullName); } return Task.FromResult(fileSystem); } @@ -314,7 +323,7 @@ namespace LINGYUN.Abp.FileManagement CreationTime = directoryInfo.CreationTime, LastModificationTime = directoryInfo.LastWriteTime }; - if (directoryInfo.Parent != null && !directoryInfo.Parent.Name.IsNullOrWhiteSpace()) + if (directoryInfo.Parent != null && !directoryInfo.Parent.FullName.IsNullOrWhiteSpace()) { fileSystem.Parent = GetFileSystemRelativePath(directoryInfo.Parent.FullName); } @@ -322,10 +331,31 @@ namespace LINGYUN.Abp.FileManagement } throw new UserFriendlyException("文件或目录不存在!"); } - + /// + /// 获取文件系统相对路径 + /// + /// + /// protected virtual string GetFileSystemRelativePath(string path) { - return path.Replace(Directory.GetCurrentDirectory(), ""); + // 去除完整路径中的文件系统根目录 + var fileSystemConfiguration = GetFileSystemBlobProviderConfiguration(); + var blobPath = fileSystemConfiguration.BasePath; + path = path.Replace(blobPath, ""); + // 去除租户或宿主目录 + if (CurrentTenant.Id == null) + { + path = path.Replace("\\host", ""); + } + else + { + path = path.Replace($"\\tenants\\{CurrentTenant.Id.Value.ToString("D")}", ""); + } + // 去除完整路径中的容器根目录 + var containerName = BlobContainerNameAttribute.GetContainerName(); + path = path.Replace($"\\{containerName}", ""); + + return path; } protected virtual string GetFileSystemPath(string path) @@ -354,6 +384,14 @@ namespace LINGYUN.Abp.FileManagement { blobPath = Path.Combine(blobPath, "tenants", CurrentTenant.Id.Value.ToString("D")); } + var containerName = BlobContainerNameAttribute.GetContainerName(); + + blobPath = Path.Combine(blobPath, containerName); + + if (!Directory.Exists(blobPath)) + { + Directory.CreateDirectory(blobPath); + } return blobPath; } diff --git a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.HttpApi/LINGYUN/Abp/FileManagement/FileSystemController.cs b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.HttpApi/LINGYUN/Abp/FileManagement/FileSystemController.cs index 52f242ca3..de8205cf7 100644 --- a/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.HttpApi/LINGYUN/Abp/FileManagement/FileSystemController.cs +++ b/aspnet-core/modules/file-management/LINGYUN.Abp.FileManagement.HttpApi/LINGYUN/Abp/FileManagement/FileSystemController.cs @@ -46,7 +46,7 @@ namespace LINGYUN.Abp.FileManagement } [HttpPost] - [Route("files/upload")] + [Route("files")] public virtual async Task CreateFileAsync(FileCreateDto input) { // 检查文件大小 @@ -138,28 +138,28 @@ namespace LINGYUN.Abp.FileManagement } [HttpPost] - [Route("folders/add")] + [Route("folders")] public virtual async Task CreateFolderAsync(FolderCreateDto input) { await FileSystemAppService.CreateFolderAsync(input); } [HttpDelete] - [Route("files/delete")] + [Route("files")] public virtual async Task DeleteFileAsync(FileDeleteDto input) { await FileSystemAppService.DeleteFileAsync(input); } [HttpDelete] - [Route("folders/delete")] + [Route("folders")] public virtual async Task DeleteFolderAsync([Required, StringLength(255)] string path) { await FileSystemAppService.DeleteFolderAsync(path); } [HttpGet] - [Route("files/download")] + [Route("files")] public virtual async Task DownloadFileAsync(FileSystemGetDto input) { var fileStream = await FileSystemAppService.DownloadFileAsync(input); diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Permissions/PlatformPermissionDefinitionProvider.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Permissions/PlatformPermissionDefinitionProvider.cs index 7a06e6b78..5a8448fa3 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Permissions/PlatformPermissionDefinitionProvider.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Permissions/PlatformPermissionDefinitionProvider.cs @@ -21,20 +21,20 @@ namespace LINGYUN.Platform.Permissions // TODO: 2020-07-27 目前abp不支持对象存储管理(或者属于企业版?)需要创建一个 LINGYUN.Abp.BlobStoring 项目自行实现 - var fileSystem = platform.AddPermission(PlatformPermissions.FileSystem.Default, L("Permission:FileSystem")); - fileSystem.AddChild(PlatformPermissions.FileSystem.Create, L("Permission:CreateFolder")); - fileSystem.AddChild(PlatformPermissions.FileSystem.Delete, L("Permission:DeleteFolder")); - fileSystem.AddChild(PlatformPermissions.FileSystem.Rename, L("Permission:RenameFolder")); - fileSystem.AddChild(PlatformPermissions.FileSystem.Copy, L("Permission:CopyFolder")); - fileSystem.AddChild(PlatformPermissions.FileSystem.Move, L("Permission:MoveFolder")); + //var fileSystem = platform.AddPermission(PlatformPermissions.FileSystem.Default, L("Permission:FileSystem")); + //fileSystem.AddChild(PlatformPermissions.FileSystem.Create, L("Permission:CreateFolder")); + //fileSystem.AddChild(PlatformPermissions.FileSystem.Delete, L("Permission:DeleteFolder")); + //fileSystem.AddChild(PlatformPermissions.FileSystem.Rename, L("Permission:RenameFolder")); + //fileSystem.AddChild(PlatformPermissions.FileSystem.Copy, L("Permission:CopyFolder")); + //fileSystem.AddChild(PlatformPermissions.FileSystem.Move, L("Permission:MoveFolder")); - var fileManager = fileSystem.AddChild(PlatformPermissions.FileSystem.FileManager.Default, L("Permission:FileManager")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Create, L("Permission:AppendFile")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Update, L("Permission:UpdateFile")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Delete, L("Permission:DeleteFile")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Copy, L("Permission:CopyFile")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Move, L("Permission:MoveFile")); - fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Download, L("Permission:DownloadFile")); + //var fileManager = fileSystem.AddChild(PlatformPermissions.FileSystem.FileManager.Default, L("Permission:FileManager")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Create, L("Permission:AppendFile")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Update, L("Permission:UpdateFile")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Delete, L("Permission:DeleteFile")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Copy, L("Permission:CopyFile")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Move, L("Permission:MoveFile")); + //fileManager.AddChild(PlatformPermissions.FileSystem.FileManager.Download, L("Permission:DownloadFile")); } private static LocalizableString L(string name) diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs index 58cde89b4..931a5b941 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs @@ -3,6 +3,7 @@ using IdentityModel; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; +using LINGYUN.Abp.FileManagement; using LINGYUN.Abp.Location.Tencent; using LINGYUN.Abp.MessageService; using LINGYUN.Abp.SettingManagement; @@ -59,6 +60,7 @@ namespace LINGYUN.BackendAdmin typeof(AbpPermissionManagementDomainIdentityServerModule), typeof(AppPlatformApplicationContractModule), typeof(ApiGatewayApplicationContractsModule), + typeof(AbpFileManagementApplicationContractsModule), typeof(AbpMessageServiceApplicationContractsModule), typeof(LINGYUN.Abp.Identity.AbpIdentityHttpApiModule), typeof(LINGYUN.Abp.Identity.AbpIdentityApplicationModule), diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj index b04ea5122..cc8830e45 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj @@ -62,6 +62,7 @@ + diff --git a/vueJs/src/api/clients.ts b/vueJs/src/api/clients.ts index bd29d5e40..ba27d5dc8 100644 --- a/vueJs/src/api/clients.ts +++ b/vueJs/src/api/clients.ts @@ -1,4 +1,3 @@ - import ApiService from './serviceBase' import { pagerFormat } from '@/utils/index' import { FullAuditedEntityDto, PagedAndSortedResultRequestDto, PagedResultDto } from './types' diff --git a/vueJs/src/api/filemanagement.ts b/vueJs/src/api/filemanagement.ts new file mode 100644 index 000000000..83a38a4a3 --- /dev/null +++ b/vueJs/src/api/filemanagement.ts @@ -0,0 +1,103 @@ +import ApiService from './serviceBase' +import { PagedAndSortedResultRequestDto, PagedResultDto } from './types' + +const serviceUrl = process.env.VUE_APP_BASE_API +const baseUrl = '/api/file-management/file-system' +export const FileManagementUrl = serviceUrl + baseUrl + +export default class FileManagementService { + public static getFileSystem(name: string, path: string | undefined) { + let _url = baseUrl + '?name=' + name + if (path) { + _url += '&path=' + path + } + return ApiService.Get(_url, serviceUrl) + } + + public static getFileSystemList(payload: FileSystemGetByPaged) { + let _url = baseUrl + '?skipCount=' + payload.skipCount + _url += '&maxResultCount=' + payload.maxResultCount + _url += '&sorting=' + payload.sorting + if (payload.filter) { + _url += '&filter=' + payload.filter + } + if (payload.parent) { + _url += '&parent=' + payload.parent + } + return ApiService.Get>(_url, serviceUrl) + } + + public static editFileSystem(name: string, newName: string) { + const _payload = { newName } + return ApiService.Put(baseUrl, _payload, serviceUrl) + } + + public static createFolder(path: string, parent: string | undefined) { + const _url = baseUrl + '/folders' + const _payload = { + path, + parent + } + return ApiService.Post(_url, _payload, serviceUrl) + } + + public static deleteFolder(path: string) { + const _url = baseUrl + '/folders?path=' + path + return ApiService.Delete(_url, serviceUrl) + } + + public static moveFolder(path: string, toPath: string) { + const _url = baseUrl + '/folders/move?path=' + path + const _payload = { toPath } + return ApiService.Put(_url, _payload, serviceUrl) + } + + public static copyFolder(path: string, toPath: string) { + const _url = baseUrl + '/folders/copy?path=' + path + const _payload = { toPath } + return ApiService.Put(_url, _payload, serviceUrl) + } + + public static deleteFile(path: string, name: string) { + let _url = baseUrl + '/files?path=' + path + _url += '&name=' + name + return ApiService.Delete(_url, serviceUrl) + } + + public static moveFile(payload: FileCopyOrMove) { + const _url = baseUrl + '/files/move' + return ApiService.Put(_url, payload, serviceUrl) + } + + public static copyFile(payload: FileCopyOrMove) { + const _url = baseUrl + '/files/copy' + return ApiService.Put(_url, payload, serviceUrl) + } +} + +export enum FileSystemType { + Folder = 0, + File = 1 +} + +export class FileSystem { + type!: FileSystemType + name!: string + parent?: string + size?: number + extension?: string + creationTime!: Date + lastModificationTime?: Date +} + +export class FileSystemGetByPaged extends PagedAndSortedResultRequestDto { + parent?: string + filter?: string +} + +export class FileCopyOrMove { + path!: string + name!: string + toPath!: string + toName?: string +} diff --git a/vueJs/src/lang/zh.ts b/vueJs/src/lang/zh.ts index 7ecdd356d..864e80807 100644 --- a/vueJs/src/lang/zh.ts +++ b/vueJs/src/lang/zh.ts @@ -78,7 +78,9 @@ export default { clients: '客户端管理', apiresources: 'Api资源管理', identityresources: '身份资源管理', - organizationUnit: '组织机构管理' + organizationUnit: '组织机构管理', + filemanagement: '文件管理', + filesystem: '文件系统' }, navbar: { logOut: '退出登录', @@ -617,5 +619,15 @@ export default { messages: { noNotifications: '没有通知', noMessages: '没有消息' + }, + fileSystem: { + name: '名称', + creationTime: '创建时间', + lastModificationTime: '修改时间', + type: '类型', + folder: '文件夹', + fileType: '{exten}文件', + size: '大小', + root: '根目录' } } diff --git a/vueJs/src/router/index.ts b/vueJs/src/router/index.ts index f7807af70..0022ac0e1 100644 --- a/vueJs/src/router/index.ts +++ b/vueJs/src/router/index.ts @@ -13,9 +13,9 @@ import taskRouter from './modules/task' import adminRouter from './modules/admin' import apigatewayRouter from './modules/apigateway' import identityServerRouter from './modules/identityServer' +import fileManagementRouter from './modules/file-management' Vue.use(Router) - /* Note: sub-menu only appear when children.length>=1 Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html @@ -128,6 +128,7 @@ export const asyncRoutes: RouteConfig[] = [ adminRouter, apigatewayRouter, identityServerRouter, + fileManagementRouter, { path: '*', component: () => import(/* webpackChunkName: "error-page-404" */ '@/views/error-page/404.vue'), diff --git a/vueJs/src/router/modules/file-management.ts b/vueJs/src/router/modules/file-management.ts new file mode 100644 index 000000000..1eab5151a --- /dev/null +++ b/vueJs/src/router/modules/file-management.ts @@ -0,0 +1,27 @@ +import { RouteConfig } from 'vue-router' +import Layout from '@/layout/index.vue' + +const fileManagementRouter: RouteConfig = { + path: '/file-management', + component: Layout, + meta: { + title: 'filemanagement', + icon: 'manager', + roles: ['Abp.FileManagement.FileSystem'], + alwaysShow: true + }, + children: [ + { + path: 'file-system', + component: () => import('@/views/file-management/index.vue'), + name: 'filesystem', + meta: { + title: 'filesystem', + icon: 'file-system', + roles: ['Abp.FileManagement.FileSystem'] + } + } + ] +} + +export default fileManagementRouter diff --git a/vueJs/src/views/file-management/index.vue b/vueJs/src/views/file-management/index.vue new file mode 100644 index 000000000..45fdfa78c --- /dev/null +++ b/vueJs/src/views/file-management/index.vue @@ -0,0 +1,220 @@ + + + + +