This commit is contained in:
udf_admin@163.com
2020-05-05 13:49:48 +08:00
parent 07d9cfa878
commit ad184fccff
15 changed files with 117 additions and 40 deletions
+7 -2
View File
@@ -52,7 +52,8 @@
<div class="userPanel">
<el-row>
<el-col :span="24">
<el-avatar :src="userDto.avatarFilePath" fit="fill" shape="square" size="small" icon="el-icon-user-solid" style="vertical-align: middle;">
<el-avatar :src="avatarFilePath" fit="fill" shape="square" size="small" icon="el-icon-user-solid"
style="vertical-align: middle;">
</el-avatar>
<span>{{userDto.nickName}}</span>
<el-divider></el-divider>
@@ -68,7 +69,8 @@
</el-col>
</el-row>
</div>
<el-avatar :src="userDto.avatarFilePath" fit="fill" slot="reference" shape="square" size="large" icon="el-icon-user-solid">
<el-avatar :src="avatarFilePath" fit="fill" slot="reference" shape="square" size="large"
icon="el-icon-user-solid">
</el-avatar>
</el-popover>
</div>
@@ -147,6 +149,7 @@
import glob from "./assets/js/glob";
import leftMenu from "./components/leftMenu";
import userCenter from "./components/userCenter";
import api_file from "./api/file";
export default {
name: 'App',
@@ -203,6 +206,7 @@
showSearchInput: false,
searchInputText: null,
userDto: {},
avatarFilePath: null,
menu: [],
elAsideShow: true,
leftMenuDrawerShow: false,
@@ -233,6 +237,7 @@
//获得用户信息
const userDtoResponse = await api_rbac.infoByToken(glob.getToken());
this.userDto = userDtoResponse.data.result;
this.avatarFilePath = api_file.preview(this.userDto.avatarFileId, 40, 40);
//获得菜单
const menuResponse = await api_rbac.menu();
this.menu = menuResponse.data.result;
+10 -1
View File
@@ -1,4 +1,13 @@
import glob from "../assets/js/glob";
const api_file = {
upload: (formData = {}) => axios.post('/private/file/upload', formData, {'Content-Type': 'multipart/form-data'})
upload: (formData = {}) => axios.post('/private/file/upload', formData, {'Content-Type': 'multipart/form-data'}),
preview: (fileId = "", width, height) => {
let path = process.env.VUE_APP_BASE_URL + 'api/udf/web/private/file/preview/' + fileId + '?token=' + glob.getToken();
if (width && height) {
path += '&width=' + width + '&height=' + height;
}
return path;
}
};
export default api_file;
+6 -3
View File
@@ -14,7 +14,7 @@
:show-file-list="false"
:before-upload="beforeAvatarFileUpload"
:http-request="avatarFileUpload">
<img v-if="form.avatarFilePath" :src="form.avatarFilePath" class="avatar">
<img v-if="avatarFilePath" :src="avatarFilePath" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
@@ -35,7 +35,8 @@
data() {
return {
elUserCenter: {},
form: {}
form: {},
avatarFilePath: null
}
},
methods: {
@@ -50,12 +51,14 @@
const loading = this.$loading({target: this.elUserCenter, lock: true,});
api_rbac.infoByToken(glob.getToken()).then(response => {
this.form = response.data.result;
this.avatarFilePath = api_file.preview(this.form.avatarFileId);
}).finally(() => loading.close());
},
//重置
reset() {
this.elUserCenter = document.getElementsByClassName('userCenter')[0];
this.form = {};
this.avatarFilePath = null;
},
//保存按钮点击事件
saveBtnClick() {
@@ -89,7 +92,7 @@
api_file.upload(data).then(response => {
const fileInfo = response.data.result;
this.form.avatarFileId = fileInfo.id;
this.form.avatarFilePath = '/file/' + fileInfo.rootPathCode + '/' + fileInfo.physicalRelativePath + '/' + fileInfo.physicalFileName;
this.avatarFilePath = api_file.preview(this.form.avatarFileId);
}).finally(() => loading.close());
}
}
@@ -40,11 +40,6 @@ public class UserDto implements Serializable {
*/
private String avatarFileId;
/**
* 用户头像路径
*/
private String avatarFilePath;
/**
* 用户状态 (1:正常)
*/
@@ -2,6 +2,7 @@ package org.itkk.udf.api.page.auth;
import lombok.extern.slf4j.Slf4j;
import org.itkk.udf.api.common.CommonConstant;
import org.itkk.udf.api.common.CommonUtil;
import org.itkk.udf.api.common.dto.UserDto;
import org.itkk.udf.api.common.service.IUserService;
@@ -30,8 +31,10 @@ public class CommonHandlerInterceptor implements HandlerInterceptor {
UserDto userDto = iUserService.infoByToken(CommonUtil.getTokenByCookie(request));
//判断是否登陆
if (userDto != null) {
//放入token
modelAndView.addObject(CommonConstant.PARAMETER_NAME_TOKEN, CommonUtil.getTokenByCookie(request));
//放入用户信息
modelAndView.addObject("userDto", userDto);
modelAndView.addObject(CommonConstant.PARAMETER_NAME_TOKEN_INFO, userDto);
}
}
}
@@ -1,6 +1,8 @@
package org.itkk.udf.api.page.web;
import org.apache.commons.lang3.StringUtils;
import org.itkk.udf.starter.file.db.service.DbFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -8,6 +10,13 @@ import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HomeController {
/**
*
*/
@Autowired
private DbFileService dbFileService;
/**
* 首页
*
@@ -20,7 +20,6 @@ import org.itkk.udf.starter.cache.db.service.DbCacheService;
import org.itkk.udf.starter.core.CoreUtil;
import org.itkk.udf.starter.core.exception.ParameterValidException;
import org.itkk.udf.starter.core.id.IdWorker;
import org.itkk.udf.starter.file.db.dto.DbFileInfoDto;
import org.itkk.udf.starter.file.db.service.DbFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -259,13 +258,6 @@ public class UserService implements IUserService {
userDto = new UserDto();
//转换
CoreUtil.copyPropertiesIgnoreNull(userEntity, userDto);
//获得头像路径
if (StringUtils.isNotBlank(userDto.getAvatarFileId())) {
DbFileInfoDto dbFileInfoDto = dbFileService.get(userDto.getAvatarFileId());
if (dbFileInfoDto != null) {
userDto.setAvatarFilePath("/file/" + dbFileInfoDto.getRootPathCode() + "/" + dbFileInfoDto.getPhysicalRelativePath() + "/" + dbFileInfoDto.getPhysicalFileName());
}
}
}
//返回
return userDto;
@@ -14,6 +14,10 @@ org.itkk.udf.api.rbac.api.fileUpload.name=\u6587\u4EF6\u4E0A\u4F20
org.itkk.udf.api.rbac.api.fileUpload.uri=/api/udf/web/private/file/upload
org.itkk.udf.api.rbac.api.fileUpload.method=POST
#
org.itkk.udf.api.rbac.api.filePreview.name=\u6587\u4EF6\u9884\u89C8
org.itkk.udf.api.rbac.api.filePreview.uri=/api/udf/web/private/file/preview/{id}
org.itkk.udf.api.rbac.api.filePreview.method=GET
#
org.itkk.udf.api.rbac.api.updateUser.name=\u66F4\u65B0\u7528\u6237\u4FE1\u606F
org.itkk.udf.api.rbac.api.updateUser.uri=/api/udf/web/private/rbac/user/save
org.itkk.udf.api.rbac.api.updateUser.method=PUT
@@ -1,3 +1,3 @@
org.itkk.udf.api.rbac.rolePublic.publicRole.name=\u516C\u5171\u89D2\u8272
org.itkk.udf.api.rbac.rolePublic.publicRole.apis=infoByToken,logout,menu,fileUpload,updateUser
org.itkk.udf.api.rbac.rolePublic.publicRole.apis=infoByToken,logout,menu,fileUpload,filePreview,updateUser
@@ -328,7 +328,7 @@
<div class="item header-right-bar-search-input-div" style="display:none;">
<input type="text" class="form-control form-control-lg" placeholder="请输入要搜索的内容">
</div>
<div th:if="${userDto!=null}" class="item header-right-bar-bell-div">
<div th:if="${tokenInfo!=null}" class="item header-right-bar-bell-div">
<div class="el-badge">
<button type="button" class="btn btn-custom2">
<i class="fa fa-bell-o" aria-hidden="true"></i>
@@ -336,18 +336,19 @@
<sup class="el-badge__content el-badge__content--undefined is-fixed is-dot"></sup>
</div>
</div>
<div th:if="${userDto!=null}" class="item header-right-bar-user-div">
<button th:if="${userDto.avatarFilePath==null}" type="button"
<div th:if="${tokenInfo!=null}" class="item header-right-bar-user-div">
<button th:if="${tokenInfo.avatarFileId==null}" type="button"
class="btn btn-info btn-custom3 user-head-img-def">
<i class="fa fa-user" aria-hidden="true"></i>
</button>
<img th:if="${userDto.avatarFilePath!=null}" width="40px" height="40px"
th:src="${userDto.avatarFilePath}" class="img-rounded user-head-img" alt="头像">
<img th:if="${tokenInfo.avatarFileId!=null}" width="40px" height="40px"
th:src="@{/api/udf/web/private/file/preview/{fileId}?token={token}&width=40&height=40(fileId=${tokenInfo.avatarFileId},token=${token})}"
class="img-rounded user-head-img" alt="头像">
</div>
<div th:if="${userDto==null}" class="item header-right-bar-login-div">
<div th:if="${tokenInfo==null}" class="item header-right-bar-login-div">
<button type="button" class="btn btn-custom rounded-pill">登陆</button>
</div>
<div th:if="${userDto==null}" class="item header-right-bar-registered-div">
<div th:if="${tokenInfo==null}" class="item header-right-bar-registered-div">
<button type="button" class="btn btn-custom rounded-pill">注册</button>
</div>
</div>
+1
View File
@@ -25,6 +25,7 @@
<mybatis-plus-boot-starter.version>3.3.1.tmp</mybatis-plus-boot-starter.version>
<guava.version>28.2-jre</guava.version>
<poi.version>4.1.2</poi.version>
<thumbnailator.version>0.4.11</thumbnailator.version>
</properties>
<!--子模块 -->
<modules>
+6
View File
@@ -20,5 +20,11 @@
<groupId>org.itkk.udf</groupId>
<artifactId>udf-starter-core</artifactId>
</dependency>
<!-- thumbnailator -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>${thumbnailator.version}</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,25 @@
package org.itkk.udf.starter.file.db;
import lombok.extern.slf4j.Slf4j;
/**
* 常量
*/
@Slf4j
public class DbFileConstant {
/**
* JPEG上下文类型
*/
public static final String CONTENT_TYPE_JPEG = "image/jpeg";
/**
* PNG上下文类型
*/
public static final String CONTENT_TYPE_PNG = "image/png";
/**
* 私有化构造函数
*/
private DbFileConstant() {
}
}
@@ -1,19 +1,22 @@
package org.itkk.udf.starter.file.db.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.itkk.udf.starter.core.CoreConstant;
import org.itkk.udf.starter.core.CoreProperties;
import org.itkk.udf.starter.core.CoreUtil;
import org.itkk.udf.starter.core.exception.ParameterValidException;
import org.itkk.udf.starter.core.exception.SystemRuntimeException;
import org.itkk.udf.starter.file.db.DbFileConstant;
import org.itkk.udf.starter.file.db.DbFileProperties;
import org.itkk.udf.starter.file.db.IGenPreviewPdf;
import org.itkk.udf.starter.file.db.dto.DbFileInfoDto;
import org.itkk.udf.starter.file.db.entity.DbFileInfoEntity;
import org.itkk.udf.starter.file.db.repository.IDbFileInfoRepository;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -27,6 +30,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
@Service
@Slf4j
public class DbFileService {
/**
@@ -191,11 +195,13 @@ public class DbFileService {
/**
* 下载
*
* @param id 文件ID
* @param os 输出流
* @param id 文件ID
* @param width 宽度
* @param height 高度
* @param os 输出流
* @throws IOException IOException
*/
public void download(String id, OutputStream os) throws IOException {
public void download(String id, Integer width, Integer height, OutputStream os) throws IOException {
//获得文件信息
DbFileInfoEntity fileInfo = this.getEntity(id);
//判空
@@ -204,6 +210,22 @@ public class DbFileService {
}
//获得文件路径
Path path = Paths.get(dbFileProperties.getMapping().get(fileInfo.getRootPathCode()) + fileInfo.getPhysicalRelativePath() + fileInfo.getPhysicalFileName());
//缩略图处理
if (DbFileConstant.CONTENT_TYPE_JPEG.equals(fileInfo.getContentType()) || DbFileConstant.CONTENT_TYPE_PNG.equals(fileInfo.getContentType())) {
if (width != null && height != null) {
Path thumbnailsPath = Paths.get(path.getParent().toString() + "/" + width + "x" + height + "/" + fileInfo.getPhysicalFileName());
if (!Files.exists(thumbnailsPath)) {
try {
Files.createDirectories(thumbnailsPath.getParent());
} catch (Exception e) {
log.warn("{} --> {} 创建文件目录失败,错误类型为 : {}", CoreUtil.getTraceId(), thumbnailsPath.getParent(), e.getClass().getName());
}
Files.createFile(thumbnailsPath);
Thumbnails.of(path.toFile()).size(width, height).keepAspectRatio(false).toFile(thumbnailsPath.toFile());
}
path = thumbnailsPath;
}
}
//输出文件
try (
OutputStream osi = new BufferedOutputStream(os);
@@ -1,5 +1,7 @@
package org.itkk.udf.starter.file.db.web;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.itkk.udf.starter.core.CoreConstant;
import org.itkk.udf.starter.core.CoreProperties;
import org.itkk.udf.starter.core.RestResponse;
@@ -7,8 +9,6 @@ import org.itkk.udf.starter.core.exception.ParameterValidException;
import org.itkk.udf.starter.file.db.DbFileProperties;
import org.itkk.udf.starter.file.db.dto.DbFileInfoDto;
import org.itkk.udf.starter.file.db.service.DbFileService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -105,15 +105,17 @@ public abstract class DbFileBaseController {
/**
* 文件预览
*
* @param id id
* @param id id
* @param width width
* @param height height
* @throws IOException IOException
*/
@GetMapping("preview/{id}")
public void preview(@PathVariable String id) throws IOException {
public void preview(@PathVariable String id, @RequestParam(name = "width", required = false) Integer width, @RequestParam(name = "height", required = false) Integer height) throws IOException {
//设置头信息
this.setResponseHeader(id, true);
//下载
dbFileService.download(id, response.getOutputStream());
dbFileService.download(id, width, height, response.getOutputStream());
}
/**
@@ -127,7 +129,7 @@ public abstract class DbFileBaseController {
//设置头信息
this.setResponseHeader(id, false);
//下载
dbFileService.download(id, response.getOutputStream());
dbFileService.download(id, null, null, response.getOutputStream());
}
/**