😎完善系统配置轮播图处理

This commit is contained in:
zuohuaijun 2025-01-23 15:51:32 +08:00
parent ffafd9d7ff
commit 9a199b2263
6 changed files with 184 additions and 18 deletions

View File

@ -20,10 +20,12 @@ public class SysTenantService : IDynamicApiController, ITransient
private readonly SqlSugarRepository<SysUserExtOrg> _sysUserExtOrgRep; private readonly SqlSugarRepository<SysUserExtOrg> _sysUserExtOrgRep;
private readonly SqlSugarRepository<SysRoleMenu> _sysRoleMenuRep; private readonly SqlSugarRepository<SysRoleMenu> _sysRoleMenuRep;
private readonly SqlSugarRepository<SysUserRole> _userRoleRep; private readonly SqlSugarRepository<SysUserRole> _userRoleRep;
private readonly SqlSugarRepository<SysFile> _fileRep;
private readonly SysUserRoleService _sysUserRoleService; private readonly SysUserRoleService _sysUserRoleService;
private readonly SysRoleMenuService _sysRoleMenuService; private readonly SysRoleMenuService _sysRoleMenuService;
private readonly SysConfigService _sysConfigService; private readonly SysConfigService _sysConfigService;
private readonly SysCacheService _sysCacheService; private readonly SysCacheService _sysCacheService;
private readonly SysFileService _sysFileService;
private readonly IEventPublisher _eventPublisher; private readonly IEventPublisher _eventPublisher;
public SysTenantService(SqlSugarRepository<SysTenant> sysTenantRep, public SysTenantService(SqlSugarRepository<SysTenant> sysTenantRep,
@ -34,10 +36,12 @@ public class SysTenantService : IDynamicApiController, ITransient
SqlSugarRepository<SysUserExtOrg> sysUserExtOrgRep, SqlSugarRepository<SysUserExtOrg> sysUserExtOrgRep,
SqlSugarRepository<SysRoleMenu> sysRoleMenuRep, SqlSugarRepository<SysRoleMenu> sysRoleMenuRep,
SqlSugarRepository<SysUserRole> userRoleRep, SqlSugarRepository<SysUserRole> userRoleRep,
SqlSugarRepository<SysFile> fileRep,
SysUserRoleService sysUserRoleService, SysUserRoleService sysUserRoleService,
SysRoleMenuService sysRoleMenuService, SysRoleMenuService sysRoleMenuService,
SysConfigService sysConfigService, SysConfigService sysConfigService,
SysCacheService sysCacheService, SysCacheService sysCacheService,
SysFileService sysFileService,
IEventPublisher eventPublisher) IEventPublisher eventPublisher)
{ {
_sysTenantRep = sysTenantRep; _sysTenantRep = sysTenantRep;
@ -48,10 +52,12 @@ public class SysTenantService : IDynamicApiController, ITransient
_sysUserExtOrgRep = sysUserExtOrgRep; _sysUserExtOrgRep = sysUserExtOrgRep;
_sysRoleMenuRep = sysRoleMenuRep; _sysRoleMenuRep = sysRoleMenuRep;
_userRoleRep = userRoleRep; _userRoleRep = userRoleRep;
_fileRep = fileRep;
_sysUserRoleService = sysUserRoleService; _sysUserRoleService = sysUserRoleService;
_sysRoleMenuService = sysRoleMenuService; _sysRoleMenuService = sysRoleMenuService;
_sysConfigService = sysConfigService; _sysConfigService = sysConfigService;
_sysCacheService = sysCacheService; _sysCacheService = sysCacheService;
_sysFileService = sysFileService;
_eventPublisher = eventPublisher; _eventPublisher = eventPublisher;
} }
@ -572,6 +578,7 @@ public class SysTenantService : IDynamicApiController, ITransient
tenant = await _sysTenantRep.GetFirstAsync(u => u.Id == SqlSugarConst.DefaultTenantId); tenant = await _sysTenantRep.GetFirstAsync(u => u.Id == SqlSugarConst.DefaultTenantId);
// 获取首页轮播图列表 // 获取首页轮播图列表
var carouselFiles = await _fileRep.GetListAsync(u => u.BelongId == tenant.Id && u.RelationId == tenant.Id && u.FileType == "Carousel");
var forceChangePassword = await _sysConfigService.GetConfigValueByCode<bool>(ConfigConst.SysForceChangePassword); // 强制修改密码 var forceChangePassword = await _sysConfigService.GetConfigValueByCode<bool>(ConfigConst.SysForceChangePassword); // 强制修改密码
var passwordExpirationTime = await _sysConfigService.GetConfigValueByCode<int>(ConfigConst.SysPasswordExpirationTime); // 密码有效期 var passwordExpirationTime = await _sysConfigService.GetConfigValueByCode<int>(ConfigConst.SysPasswordExpirationTime); // 密码有效期
@ -596,7 +603,8 @@ public class SysTenantService : IDynamicApiController, ITransient
tenant.SecondVer, tenant.SecondVer,
ForceChangePassword = forceChangePassword, ForceChangePassword = forceChangePassword,
PasswordExpirationTime = passwordExpirationTime, PasswordExpirationTime = passwordExpirationTime,
PublicKey = publicKey PublicKey = publicKey,
CarouselFiles = carouselFiles
}; };
} }
@ -616,8 +624,6 @@ public class SysTenantService : IDynamicApiController, ITransient
tenant = input.Adapt<SysTenant>(); tenant = input.Adapt<SysTenant>();
tenant.Id = input.TenantId; tenant.Id = input.TenantId;
// 保存轮播图
// logo 不为空才保存 // logo 不为空才保存
if (!string.IsNullOrEmpty(input.LogoBase64)) if (!string.IsNullOrEmpty(input.LogoBase64))
{ {
@ -672,4 +678,40 @@ public class SysTenantService : IDynamicApiController, ITransient
}) })
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }
/// <summary>
/// 上传轮播图单文件 🔖
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[DisplayName("上传轮播图单文件")]
public async Task<SysFile> UploadCarouselFile([Required] IFormFile file)
{
var tenantId = long.Parse(App.User?.FindFirst(ClaimConst.TenantId)?.Value ?? "0");
if (tenantId < 1) tenantId = SqlSugarConst.DefaultTenantId;
var tenant = await _sysTenantRep.GetFirstAsync(u => u.Id == tenantId);
if (tenant == null) return null;
if (file == null)
throw Oops.Oh(ErrorCodeEnum.D8000);
// 本地轮播图保存路径
var path = $"upload/{tenantId}/carousel";
var absoluteDirPath = Path.Combine(App.WebHostEnvironment.WebRootPath, path);
// 创建文件夹
if (!Directory.Exists(absoluteDirPath))
Directory.CreateDirectory(absoluteDirPath);
// 保存轮播图文件
var sysFile = await _sysFileService.UploadFile(new UploadFileInput { File = file, FileType = "Carousel", SavePath = path });
// 保存轮播图配置
sysFile.BelongId = tenant.Id;
sysFile.RelationId = tenant.Id;
await _sysFileService.UpdateFile(sysFile);
return sysFile;
}
} }

View File

@ -24,6 +24,7 @@ import { AdminNETResultListSysUser } from '../models';
import { AdminNETResultObject } from '../models'; import { AdminNETResultObject } from '../models';
import { AdminNETResultSqlSugarPagedListTenantOutput } from '../models'; import { AdminNETResultSqlSugarPagedListTenantOutput } from '../models';
import { AdminNETResultString } from '../models'; import { AdminNETResultString } from '../models';
import { AdminNETResultSysFile } from '../models';
import { DeleteTenantInput } from '../models'; import { DeleteTenantInput } from '../models';
import { PageTenantInput } from '../models'; import { PageTenantInput } from '../models';
import { RoleMenuInput } from '../models'; import { RoleMenuInput } from '../models';
@ -658,6 +659,58 @@ export const SysTenantApiAxiosParamCreator = function (configuration?: Configura
options: localVarRequestOptions, options: localVarRequestOptions,
}; };
}, },
/**
*
* @summary 🔖
* @param {Blob} [file]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiSysTenantUploadCarouselFilePostForm: async (file?: Blob, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/sysTenant/uploadCarouselFile`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
const localVarFormParams = new FormData();
// authentication Bearer required
// http bearer authentication required
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
}
if (file !== undefined) {
localVarFormParams.append('file', file as any);
}
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.params) {
query.set(key, options.params[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = localVarFormParams;
return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
/** /**
* *
* @summary 🔖 * @summary 🔖
@ -896,6 +949,20 @@ export const SysTenantApiFp = function(configuration?: Configuration) {
return axios.request(axiosRequestArgs); return axios.request(axiosRequestArgs);
}; };
}, },
/**
*
* @summary 🔖
* @param {Blob} [file]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantUploadCarouselFilePostForm(file?: Blob, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminNETResultSysFile>>> {
const localVarAxiosArgs = await SysTenantApiAxiosParamCreator(configuration).apiSysTenantUploadCarouselFilePostForm(file, options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
/** /**
* *
* @summary 🔖 * @summary 🔖
@ -1048,6 +1115,16 @@ export const SysTenantApiFactory = function (configuration?: Configuration, base
async apiSysTenantUpdatePost(body?: UpdateTenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> { async apiSysTenantUpdatePost(body?: UpdateTenantInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
return SysTenantApiFp(configuration).apiSysTenantUpdatePost(body, options).then((request) => request(axios, basePath)); return SysTenantApiFp(configuration).apiSysTenantUpdatePost(body, options).then((request) => request(axios, basePath));
}, },
/**
*
* @summary 🔖
* @param {Blob} [file]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiSysTenantUploadCarouselFilePostForm(file?: Blob, options?: AxiosRequestConfig): Promise<AxiosResponse<AdminNETResultSysFile>> {
return SysTenantApiFp(configuration).apiSysTenantUploadCarouselFilePostForm(file, options).then((request) => request(axios, basePath));
},
/** /**
* *
* @summary 🔖 * @summary 🔖
@ -1210,6 +1287,17 @@ export class SysTenantApi extends BaseAPI {
public async apiSysTenantUpdatePost(body?: UpdateTenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> { public async apiSysTenantUpdatePost(body?: UpdateTenantInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
return SysTenantApiFp(this.configuration).apiSysTenantUpdatePost(body, options).then((request) => request(this.axios, this.basePath)); return SysTenantApiFp(this.configuration).apiSysTenantUpdatePost(body, options).then((request) => request(this.axios, this.basePath));
} }
/**
*
* @summary 🔖
* @param {Blob} [file]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SysTenantApi
*/
public async apiSysTenantUploadCarouselFilePostForm(file?: Blob, options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminNETResultSysFile>> {
return SysTenantApiFp(this.configuration).apiSysTenantUploadCarouselFilePostForm(file, options).then((request) => request(this.axios, this.basePath));
}
/** /**
* *
* @summary 🔖 * @summary 🔖

View File

@ -409,6 +409,7 @@ export * from './sys-plugin';
export * from './sys-print'; export * from './sys-print';
export * from './sys-region'; export * from './sys-region';
export * from './sys-schedule'; export * from './sys-schedule';
export * from './sys-tenant-upload-carousel-file-body';
export * from './sys-upgrade'; export * from './sys-upgrade';
export * from './sys-user'; export * from './sys-user';
export * from './sys-user-ext-org'; export * from './sys-user-ext-org';

View File

@ -0,0 +1,28 @@
/* tslint:disable */
/* eslint-disable */
/**
* Admin.NET
* .NET <br/><u><b><font color='FF0000'> 👮</font></b></u>
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/**
*
*
* @export
* @interface SysTenantUploadCarouselFileBody
*/
export interface SysTenantUploadCarouselFileBody {
/**
* @type {Blob}
* @memberof SysTenantUploadCarouselFileBody
*/
file: Blob;
}

View File

@ -105,9 +105,7 @@ router.beforeEach(async (to, from, next) => {
var routeLocation = `/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`; var routeLocation = `/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`;
// 附加租户Id标识 // 附加租户Id标识
var tenantid = Number(Local.get('tid')); var tenantid = Number(Local.get('tid'));
if (!isNaN(tenantid) && tenantid > 99999) { if (!isNaN(tenantid) && tenantid > 99999) routeLocation += `&tid=${tenantid}`;
routeLocation += `&tid=${tenantid}`;
}
next(routeLocation); next(routeLocation);
Session.clear(); Session.clear();
NProgress.done(); NProgress.done();

View File

@ -20,7 +20,7 @@
</template> </template>
{{ state.sysInfo.tenantId }} {{ state.sysInfo.tenantId }}
<p> <p>
<el-tag style="border: 1 solid var(--el-border-color)">访问地址{{ host }}/#/login?tid={{ state.sysInfo.tenantId }}</el-tag> <el-tag style="border: 1 solid var(--el-border-color)">访问地址{{ host }}/#/login?tenantid={{ state.sysInfo.tenantId }}</el-tag>
</p> </p>
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="系统主标题"> <el-descriptions-item label="系统主标题">
@ -152,7 +152,7 @@
<template #label> <template #label>
<el-icon><ele-Picture /></el-icon> <el-icon><ele-Picture /></el-icon>
</template> </template>
<el-upload v-model:file-list="state.carouselFileList" list-type="picture-card" :http-request="uploadCarouselFile" :on-preview="previewCarouselFile" :before-remove="beforeRemoveCarouselFile"> <el-upload :file-list="state.carouselFileList" list-type="picture-card" :http-request="uploadCarouselFile" :on-preview="previewCarouselFile" :before-remove="beforeRemoveCarouselFile">
<el-icon><ele-Plus /></el-icon> <el-icon><ele-Plus /></el-icon>
</el-upload> </el-upload>
</el-descriptions-item> </el-descriptions-item>
@ -208,9 +208,7 @@ const state = reactive({
colorName: '飞燕草蓝', // colorName: '飞燕草蓝', //
dialogImagePreviewVisible: false, // dialogImagePreviewVisible: false, //
dialogImagePreviewUrl: '', // dialogImagePreviewUrl: '', //
isDelete: false, // isDelete: false, //
fileList: [] as any, //
fileDeleteList: [] as any, //
carouselFileList: [] as any, // carouselFileList: [] as any, //
}); });
@ -234,11 +232,6 @@ const saveSysInfo = async () => {
state.sysInfo.logoFileName = state.logoFile.raw.name; state.sysInfo.logoFileName = state.logoFile.raw.name;
} }
//
// state.sysInfo.carouselFiles = [];
// state.carouselFileList.forEach((e: any) => {
// state.sysInfo.carouselFiles.push(e.raw);
// });
try { try {
state.isLoading = true; state.isLoading = true;
await getAPI(SysTenantApi).apiSysTenantSaveSysInfoPost(state.sysInfo); await getAPI(SysTenantApi).apiSysTenantSaveSysInfoPost(state.sysInfo);
@ -257,7 +250,9 @@ const loadSysInfoData = async () => {
state.isLoading = true; state.isLoading = true;
const res = await getAPI(SysTenantApi).apiSysTenantSysInfoTenantIdGet(0); const res = await getAPI(SysTenantApi).apiSysTenantSysInfoTenantIdGet(0);
if (res.data!.type !== 'success') return; if (res.data!.type !== 'success') return;
state.sysInfo = res.data.result; state.sysInfo = res.data.result;
if (state.sysInfo.carouselFiles) state.carouselFileList = state.sysInfo.carouselFiles;
} finally { } finally {
nextTick(() => { nextTick(() => {
state.isLoading = false; state.isLoading = false;
@ -265,9 +260,21 @@ const loadSysInfoData = async () => {
} }
}; };
// file
// const onlineImageToFile = async (imageUrl: string | URL | Request, fileName: string) => {
// try {
// const response = await fetch(imageUrl);
// const blob = await response.blob();
// const file = new File([blob], fileName, { type: blob.type });
// return file;
// } catch (error) {
// return null;
// }
// };
// //
const uploadCarouselFile = async (e: any) => { const uploadCarouselFile = async (e: any) => {
await getAPI(SysFileApi).apiSysFileUploadFilePostForm(e.file); await getAPI(SysTenantApi).apiSysTenantUploadCarouselFilePostForm(e.file);
}; };
// //
@ -279,9 +286,11 @@ const beforeRemoveCarouselFile = (file: any, fileList: any) => {
type: 'warning', type: 'warning',
}) })
.then(async () => { .then(async () => {
await getAPI(SysFileApi).apiSysFileDeletePost({ id: 0 }); state.isDelete = true;
let index = fileList.indexOf(file); let index = fileList.indexOf(file);
await getAPI(SysFileApi).apiSysFileDeletePost(fileList[index]);
fileList.splice(index, 1); fileList.splice(index, 1);
state.carouselFileList.splice(index, 1);
}) })
.catch(() => { .catch(() => {
reject(false); reject(false);