feat(client): 添加品牌logo功能支持
- 在客户端账户实体中新增brandLogo字段用于存储品牌logo URL - 实现品牌logo的上传、获取和删除接口 - 在Vue前端中集成品牌logo的展示和管理功能- 添加品牌logo的缓存机制提升访问性能 - 在设置对话框中增加品牌logo配置界面 - 实现品牌logo的预览、上传和删除操作 - 添加VIP权限控制确保只有VIP用户可使用该功能 - 增加品牌logo变更事件监听以实时更新界面显示- 更新数据库映射文件以支持brand_logo字段的读写- 在登录成功后异步加载品牌logo配置信息- 调整UI布局以适配品牌logo展示区域- 添加品牌logo相关的样式定义和响应式处理 - 实现品牌logo上传的文件类型和大小校验- 增加品牌logo删除确认提示增强用户体验 - 在App.vue中添加品牌logo的全局状态管理和展示逻辑- 优化品牌logo加载失败时的容错处理 - 完善品牌logo功能的相关错误处理和日志记录
This commit is contained in:
@@ -76,6 +76,7 @@ public class ClientAccountController extends BaseController {
|
||||
private Auth auth;
|
||||
|
||||
private static final String SPLASH_IMAGE_CACHE_KEY = "splash_image:";
|
||||
private static final String BRAND_LOGO_CACHE_KEY = "brand_logo:";
|
||||
|
||||
private AjaxResult checkDeviceLimit(Long accountId, String deviceId, int deviceLimit) {
|
||||
int activeDeviceCount = accountDeviceMapper.countActiveDevicesByAccountId(accountId);
|
||||
@@ -180,6 +181,11 @@ public class ClientAccountController extends BaseController {
|
||||
if (StringUtils.isNotEmpty(account.getSplashImage())) {
|
||||
redisCache.setCacheObject(SPLASH_IMAGE_CACHE_KEY + username, account.getSplashImage());
|
||||
}
|
||||
|
||||
// 更新品牌logo缓存到 Redis
|
||||
if (StringUtils.isNotEmpty(account.getBrandLogo())) {
|
||||
redisCache.setCacheObject(BRAND_LOGO_CACHE_KEY + username, account.getBrandLogo());
|
||||
}
|
||||
|
||||
String token = Jwts.builder()
|
||||
.setHeaderParam("kid", jwtRsaKeyService.getKeyId())
|
||||
@@ -402,7 +408,7 @@ public class ClientAccountController extends BaseController {
|
||||
try {
|
||||
ClientAccount account = clientAccountService.selectClientAccountByUsername(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
|
||||
|
||||
account.setSplashImage(null);
|
||||
clientAccountService.updateClientAccount(account);
|
||||
redisCache.deleteObject(SPLASH_IMAGE_CACHE_KEY + username);
|
||||
@@ -413,4 +419,66 @@ public class ClientAccountController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传品牌logo
|
||||
*/
|
||||
@PostMapping("/brand-logo/upload")
|
||||
public AjaxResult uploadBrandLogo(@RequestParam("file") MultipartFile file, @RequestParam("username") String username) {
|
||||
try {
|
||||
ClientAccount account = clientAccountService.selectClientAccountByUsername(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
if (!file.getContentType().startsWith("image/")) return AjaxResult.error("只支持图片文件");
|
||||
if (file.getSize() > 5 * 1024 * 1024) return AjaxResult.error("图片大小不能超过5MB");
|
||||
|
||||
String fileName = "brand-logo/" + DateUtil.format(new Date(), "yyyy/MM/") + IdUtil.simpleUUID() + "." + FileUtil.extName(file.getOriginalFilename());
|
||||
try (InputStream is = file.getInputStream()) {
|
||||
Response res = uploadManager.put(is, fileName, auth.uploadToken(qiniu.getBucket()), null, "");
|
||||
if (!res.isOK()) return AjaxResult.error("上传失败");
|
||||
}
|
||||
|
||||
String url = qiniu.getResourcesUrl() + fileName;
|
||||
account.setBrandLogo(url);
|
||||
clientAccountService.updateClientAccount(account);
|
||||
redisCache.setCacheObject(BRAND_LOGO_CACHE_KEY + username, url);
|
||||
return AjaxResult.success().put("url", url).put("fileName", fileName);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取品牌logo
|
||||
*/
|
||||
@GetMapping("/brand-logo")
|
||||
public AjaxResult getBrandLogo(@RequestParam("username") String username) {
|
||||
String url = redisCache.getCacheObject(BRAND_LOGO_CACHE_KEY + username);
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
ClientAccount account = clientAccountService.selectClientAccountByUsername(username);
|
||||
if (account != null && StringUtils.isNotEmpty(account.getBrandLogo())) {
|
||||
url = account.getBrandLogo();
|
||||
redisCache.setCacheObject(BRAND_LOGO_CACHE_KEY + username, url);
|
||||
}
|
||||
}
|
||||
return AjaxResult.success(Map.of("url", url != null ? url : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除品牌logo
|
||||
*/
|
||||
@PostMapping("/brand-logo/delete")
|
||||
public AjaxResult deleteBrandLogo(@RequestParam("username") String username) {
|
||||
try {
|
||||
ClientAccount account = clientAccountService.selectClientAccountByUsername(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
|
||||
account.setBrandLogo(null);
|
||||
clientAccountService.updateClientAccount(account);
|
||||
redisCache.deleteObject(BRAND_LOGO_CACHE_KEY + username);
|
||||
return AjaxResult.success("品牌logo已删除");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("删除失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user