😎优化文件上传模块
This commit is contained in:
parent
d5f9a60f47
commit
073201d774
@ -32,6 +32,10 @@ public class PageFileInput : BasePageInput
|
|||||||
public DateTime? EndTime { get; set; }
|
public DateTime? EndTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class FileInput : BaseIdInput
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public class DeleteFileInput : BaseIdInput
|
public class DeleteFileInput : BaseIdInput
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,17 +57,6 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
.ToPagedListAsync(input.Page, input.PageSize);
|
.ToPagedListAsync(input.Page, input.PageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 上传文件 🔖
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[DisplayName("上传文件")]
|
|
||||||
public async Task<SysFile> UploadFile([FromForm] UploadFileInput input)
|
|
||||||
{
|
|
||||||
return await HandleUploadFile(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上传文件Base64 🔖
|
/// 上传文件Base64 🔖
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -122,7 +111,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("根据文件Id或Url下载")]
|
[DisplayName("根据文件Id或Url下载")]
|
||||||
public async Task<IActionResult> DownloadFile(SysFile input)
|
public async Task<IActionResult> DownloadFile(SysFile input)
|
||||||
{
|
{
|
||||||
var file = input.Id > 0 ? await GetFile(input) : await _sysFileRep.CopyNew().GetFirstAsync(u => u.Url == input.Url);
|
var file = input.Id > 0 ? await GetFile(input.Id) : await _sysFileRep.CopyNew().GetFirstAsync(u => u.Url == input.Url);
|
||||||
var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
||||||
var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
||||||
|
|
||||||
@ -149,12 +138,12 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件预览 🔖
|
/// 文件预览 🔖
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[DisplayName("文件预览")]
|
[DisplayName("文件预览")]
|
||||||
public async Task<IActionResult> GetPreview([FromRoute] long Id)
|
public async Task<IActionResult> GetPreview([FromRoute] long id)
|
||||||
{
|
{
|
||||||
var file = await GetFile(new SysFile { Id = Id });
|
var file = await GetFile(id);
|
||||||
//var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
//var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
||||||
var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
||||||
|
|
||||||
@ -276,27 +265,28 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
var isExist = await _sysFileRep.IsAnyAsync(u => u.Id == input.Id);
|
var isExist = await _sysFileRep.IsAnyAsync(u => u.Id == input.Id);
|
||||||
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D8000);
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D8000);
|
||||||
|
|
||||||
await _sysFileRep.UpdateAsync(u => new SysFile() { FileName = input.FileName, FileType = input.FileType, IsPublic = input.IsPublic }, u => u.Id == input.Id);
|
await _sysFileRep.UpdateAsync(u => input.Adapt<SysFile>(), u => u.Id == input.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取文件 🔖
|
/// 获取文件 🔖
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[DisplayName("获取文件")]
|
[DisplayName("获取文件")]
|
||||||
public async Task<SysFile> GetFile([FromQuery] SysFile input)
|
public async Task<SysFile> GetFile([FromQuery] long id)
|
||||||
{
|
{
|
||||||
var file = await _sysFileRep.CopyNew().GetByIdAsync(input.Id);
|
var file = await _sysFileRep.CopyNew().GetByIdAsync(id);
|
||||||
return file ?? throw Oops.Oh(ErrorCodeEnum.D8000);
|
return file ?? throw Oops.Oh(ErrorCodeEnum.D8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上传文件
|
/// 上传文件 🔖
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<SysFile> HandleUploadFile(UploadFileInput input)
|
[DisplayName("上传文件")]
|
||||||
|
public async Task<SysFile> UploadFile([FromForm] UploadFileInput input)
|
||||||
{
|
{
|
||||||
if (input.File == null) throw Oops.Oh(ErrorCodeEnum.D8000);
|
if (input.File == null) throw Oops.Oh(ErrorCodeEnum.D8000);
|
||||||
|
|
||||||
@ -422,7 +412,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("上传头像")]
|
[DisplayName("上传头像")]
|
||||||
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
||||||
{
|
{
|
||||||
var sysFile = await HandleUploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/avatar" });
|
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/avatar" });
|
||||||
|
|
||||||
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
||||||
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
||||||
@ -444,7 +434,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("上传电子签名")]
|
[DisplayName("上传电子签名")]
|
||||||
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
||||||
{
|
{
|
||||||
var sysFile = await HandleUploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/signature" });
|
var sysFile = await UploadFile(new UploadFileInput { File = file, AllowSuffix = _imageType, SavePath = "upload/signature" });
|
||||||
|
|
||||||
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
||||||
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
var user = await sysUserRep.GetByIdAsync(_userManager.UserId);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -82,30 +82,6 @@ export interface PageCodeGenInput {
|
|||||||
*/
|
*/
|
||||||
descStr?: string | null;
|
descStr?: string | null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库表名
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
tableName?: string | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务名(业务代码包名称)
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
busName?: string | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 命名空间
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
nameSpace?: string | null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作者姓名
|
* 作者姓名
|
||||||
*
|
*
|
||||||
@ -114,30 +90,6 @@ export interface PageCodeGenInput {
|
|||||||
*/
|
*/
|
||||||
authorName?: string | null;
|
authorName?: string | null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成方式
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
generateType?: string | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否生成菜单
|
|
||||||
*
|
|
||||||
* @type {boolean}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
generateMenu?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否使用 Api Service
|
|
||||||
*
|
|
||||||
* @type {boolean}
|
|
||||||
* @memberof PageCodeGenInput
|
|
||||||
*/
|
|
||||||
isApiService?: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类名
|
* 类名
|
||||||
*
|
*
|
||||||
@ -186,6 +138,38 @@ export interface PageCodeGenInput {
|
|||||||
*/
|
*/
|
||||||
connectionString?: string | null;
|
connectionString?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成方式
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
generateType?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库表名
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
tableName?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命名空间
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
nameSpace?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务名(业务代码包名称)
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
busName?: string | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能名(数据库表名称)
|
* 功能名(数据库表名称)
|
||||||
*
|
*
|
||||||
@ -202,6 +186,14 @@ export interface PageCodeGenInput {
|
|||||||
*/
|
*/
|
||||||
menuApplication?: string | null;
|
menuApplication?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否生成菜单
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
generateMenu?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单父级
|
* 菜单父级
|
||||||
*
|
*
|
||||||
@ -241,4 +233,12 @@ export interface PageCodeGenInput {
|
|||||||
* @memberof PageCodeGenInput
|
* @memberof PageCodeGenInput
|
||||||
*/
|
*/
|
||||||
printName?: string | null;
|
printName?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否使用 Api Service
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @memberof PageCodeGenInput
|
||||||
|
*/
|
||||||
|
isApiService?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,6 +85,14 @@ export interface SysOAuthUser {
|
|||||||
*/
|
*/
|
||||||
isDelete?: boolean;
|
isDelete?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof SysOAuthUser
|
||||||
|
*/
|
||||||
|
email?: string | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户Id
|
* 系统用户Id
|
||||||
*
|
*
|
||||||
@ -147,14 +155,6 @@ export interface SysOAuthUser {
|
|||||||
*/
|
*/
|
||||||
avatar?: string | null;
|
avatar?: string | null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮箱
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof SysOAuthUser
|
|
||||||
*/
|
|
||||||
email?: string | null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
*
|
*
|
||||||
|
|||||||
@ -29,14 +29,6 @@ export interface SysRegion {
|
|||||||
*/
|
*/
|
||||||
id?: number;
|
id?: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* 名称
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof SysRegion
|
|
||||||
*/
|
|
||||||
name: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父Id
|
* 父Id
|
||||||
*
|
*
|
||||||
@ -45,6 +37,14 @@ export interface SysRegion {
|
|||||||
*/
|
*/
|
||||||
pid?: number;
|
pid?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof SysRegion
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 简称
|
* 简称
|
||||||
*
|
*
|
||||||
|
|||||||
@ -93,14 +93,6 @@ export interface SysSchedule {
|
|||||||
*/
|
*/
|
||||||
tenantId?: number | null;
|
tenantId?: number | null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 日程内容
|
|
||||||
*
|
|
||||||
* @type {string}
|
|
||||||
* @memberof SysSchedule
|
|
||||||
*/
|
|
||||||
content: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户Id
|
* 用户Id
|
||||||
*
|
*
|
||||||
@ -133,6 +125,14 @@ export interface SysSchedule {
|
|||||||
*/
|
*/
|
||||||
endTime?: string | null;
|
endTime?: string | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日程内容
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof SysSchedule
|
||||||
|
*/
|
||||||
|
content: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {FinishStatusEnum}
|
* @type {FinishStatusEnum}
|
||||||
* @memberof SysSchedule
|
* @memberof SysSchedule
|
||||||
|
|||||||
@ -49,7 +49,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||||
<el-form-item label="所属ID" prop="fileName">
|
<el-form-item label="所属Id" prop="fileName">
|
||||||
<el-input v-model="state.ruleForm.belongId" placeholder="所属ID" clearable />
|
<el-input v-model="state.ruleForm.belongId" placeholder="所属ID" clearable />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -71,7 +71,7 @@ import { ElMessage } from 'element-plus';
|
|||||||
|
|
||||||
import { getAPI } from '/@/utils/axios-utils';
|
import { getAPI } from '/@/utils/axios-utils';
|
||||||
import { SysFileApi } from '/@/api-services/api';
|
import { SysFileApi } from '/@/api-services/api';
|
||||||
import { FileInput } from '/@/api-services/models';
|
import { SysFile } from '/@/api-services/models';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
title: String,
|
title: String,
|
||||||
@ -81,7 +81,7 @@ const emits = defineEmits(['handleQuery']);
|
|||||||
const ruleFormRef = ref();
|
const ruleFormRef = ref();
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
isShowDialog: false,
|
isShowDialog: false,
|
||||||
ruleForm: {} as FileInput,
|
ruleForm: {} as SysFile,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
|
|||||||
@ -92,7 +92,7 @@
|
|||||||
<el-option label="归档文件" value="归档文件" />
|
<el-option label="归档文件" value="归档文件" />
|
||||||
</el-select>
|
</el-select>
|
||||||
是否公开:
|
是否公开:
|
||||||
<el-radio-group v-model="state.isPublic">
|
<el-radio-group v-model="state.isPublic" style="margin-bottom: 10px">
|
||||||
<el-radio :value="false">否</el-radio>
|
<el-radio :value="false">否</el-radio>
|
||||||
<el-radio :value="true">是</el-radio>
|
<el-radio :value="true">是</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user