mirror of
https://gitee.com/jamen/slife.git
synced 2026-11-01 14:53:41 +00:00
改版界面
This commit is contained in:
@@ -34,7 +34,9 @@ public enum HttpCodeEnum {
|
||||
FAIL(501,"操作失败"),
|
||||
|
||||
|
||||
USERNAME_OR_PASSWORD_ERR(2000,"用户名或密码错误");
|
||||
USERNAME_OR_PASSWORD_ERR(2000,"用户名或密码错误"),
|
||||
DELETE_DEFAULT_PHOTO_ERR(2001,"默认头像不可删除");
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.slife.util;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@@ -19,6 +21,7 @@ import java.nio.file.Paths;
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(FileUtils.class);
|
||||
/**
|
||||
* 获取附件名称 13位时间戳+5位随机数
|
||||
*
|
||||
@@ -60,6 +63,45 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存文件到磁盘
|
||||
* @param file
|
||||
* @param filePath
|
||||
* @param fileName
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void saveFile(byte[] file, String filePath, String fileName) throws Exception {
|
||||
File targetFile = new File(filePath);
|
||||
if (!targetFile.exists()) {
|
||||
targetFile.mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(filePath + fileName);
|
||||
out.write(file);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static boolean deleteFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (file.delete()) {
|
||||
logger.error("删除单个文件-> {}成功!",fileName);
|
||||
return true;
|
||||
} else {
|
||||
logger.error("删除单个文件-> {}失败!",fileName);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger.info("删除单个文件失败-> {}不存在!",fileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成缩略图
|
||||
|
||||
@@ -18,14 +18,6 @@ public class ReturnDTOUtil {
|
||||
return new ReturnDTO(HttpCodeEnum.OK.getCode(),null, HttpCodeEnum.OK.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作失败
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO fail() {
|
||||
return new ReturnDTO(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功请求
|
||||
*
|
||||
@@ -36,7 +28,30 @@ public class ReturnDTOUtil {
|
||||
return new ReturnDTO(HttpCodeEnum.OK.getCode(), null,data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作失败
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO fail() {
|
||||
return new ReturnDTO(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMessage());
|
||||
}
|
||||
/**
|
||||
* 服务器错误
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO error() {
|
||||
return new ReturnDTO(HttpCodeEnum.INTERNAL_SERVER_ERROR.getCode(),HttpCodeEnum.INTERNAL_SERVER_ERROR.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务器错误
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO error(Object data) {
|
||||
return new ReturnDTO(HttpCodeEnum.INTERNAL_SERVER_ERROR.getCode(),HttpCodeEnum.INTERNAL_SERVER_ERROR.getMessage(), data);
|
||||
}
|
||||
/**
|
||||
* 参数错误
|
||||
* @return
|
||||
@@ -166,23 +181,6 @@ public class ReturnDTOUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务器错误
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO error() {
|
||||
return new ReturnDTO(HttpCodeEnum.INTERNAL_SERVER_ERROR.getCode(),HttpCodeEnum.INTERNAL_SERVER_ERROR.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务器错误
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO error(Object data) {
|
||||
return new ReturnDTO(HttpCodeEnum.INTERNAL_SERVER_ERROR.getCode(),HttpCodeEnum.INTERNAL_SERVER_ERROR.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 未知错误
|
||||
@@ -202,6 +200,14 @@ public class ReturnDTOUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义返回
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
public static ReturnDTO custom(HttpCodeEnum e) {
|
||||
return new ReturnDTO(e.getCode(),e.getMessage());
|
||||
}
|
||||
/**
|
||||
* 自定义返回
|
||||
* @param error
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.slife.controller;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -38,6 +39,7 @@ public class AttachmentController {
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "系统请求文件",notes = "系统请求文件 demo http://localhost:8081/sys/user/attach/head?filename=150641181924855150.png&s=s")
|
||||
@GetMapping("/{basefloder}/{type}")
|
||||
public String download(@PathVariable("basefloder") String baseFloder,
|
||||
@RequestParam("filename") String filename,
|
||||
|
||||
+27
-15
@@ -4,6 +4,7 @@ import com.slife.base.entity.ReturnDTO;
|
||||
import com.slife.constant.Setting;
|
||||
import com.slife.util.FileUtils;
|
||||
import com.slife.util.ReturnDTOUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -20,24 +21,35 @@ import java.util.Map;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/upload")
|
||||
public class UploadFileController {
|
||||
private static Logger logger = LoggerFactory.getLogger(UploadFileController.class);
|
||||
|
||||
@RequestMapping(value = "/file")
|
||||
public class FileController {
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "后台删除文件", notes = "后台删除文件")
|
||||
@PostMapping(value = "/delete")
|
||||
@ResponseBody
|
||||
public ReturnDTO delete(@RequestParam("name") String name) throws IOException {
|
||||
Boolean b = FileUtils.deleteFile(name);
|
||||
if (b) {
|
||||
return ReturnDTOUtil.success();
|
||||
} else {
|
||||
return ReturnDTOUtil.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台用户头像上传(图片)
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @param path 文件上传指定根目录下的目录
|
||||
* @param file 上传的文件
|
||||
* @param path 文件上传指定根目录下的目录
|
||||
* @param response
|
||||
* @param request
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping(value = "/{type}")
|
||||
@ApiOperation(value = "后台上传文件", notes = "后台上传文件")
|
||||
@PostMapping(value = "/upload/{type}")
|
||||
@ResponseBody
|
||||
public ReturnDTO uploadTransImg(@PathVariable("type") String type, @RequestParam("files") MultipartFile file,
|
||||
@RequestParam(value = "path", defaultValue = "") String path,
|
||||
@@ -55,14 +67,14 @@ public class UploadFileController {
|
||||
fileName = fileName + "/" + path;
|
||||
}
|
||||
|
||||
String savePath = fileName + "/"+type+"/"+ uuid + "." + fileExt;//附件路径+类型(头像、附件等)+名称+扩展名
|
||||
String savePath = fileName + "/" + type + "/" + uuid + "." + fileExt;//附件路径+类型(头像、附件等)+名称+扩展名
|
||||
File localFile = FileUtils.saveFileToDisk(file, savePath); //保存到磁盘
|
||||
|
||||
String thumbnailName="";
|
||||
String thumbnailName = "";
|
||||
if (FileUtils.getImageFormat(fileExt)) {
|
||||
//创建缩略图
|
||||
thumbnailName=fileName + "/"+type+"/s/"+ uuid + "." + fileExt;//附件路径+类型(头像、附件等)+s(文件夹)+名称+扩展名
|
||||
FileUtils.createThumbnail(localFile,thumbnailName);
|
||||
thumbnailName = fileName + "/" + type + "/s/" + uuid + "." + fileExt;//附件路径+类型(头像、附件等)+s(文件夹)+名称+扩展名
|
||||
FileUtils.createThumbnail(localFile, thumbnailName);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,11 +83,11 @@ public class UploadFileController {
|
||||
rt.put("uuid", uuid);
|
||||
rt.put("path", Setting.BASEFLODER);
|
||||
rt.put("ext", fileExt);
|
||||
rt.put("url", "/"+savePath);
|
||||
rt.put("s_url", "/"+thumbnailName);
|
||||
rt.put("url", "/" + savePath);
|
||||
rt.put("s_url", "/" + thumbnailName);
|
||||
|
||||
logger.info("上传的文件地址为 fileName={}",savePath);
|
||||
return ReturnDTOUtil.success(rt);
|
||||
logger.info("上传的文件地址为 fileName={}", savePath);
|
||||
return ReturnDTOUtil.success(rt);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,18 @@ import com.slife.base.controller.BaseController;
|
||||
import com.slife.base.entity.ReturnDTO;
|
||||
import com.slife.base.vo.DataTable;
|
||||
import com.slife.entity.SysUser;
|
||||
import com.slife.enums.HttpCodeEnum;
|
||||
import com.slife.service.impl.SysRoleService;
|
||||
import com.slife.service.impl.SysUserService;
|
||||
import com.slife.shiro.ShiroUser;
|
||||
import com.slife.shiro.SlifeSysUser;
|
||||
import com.slife.util.FileUtils;
|
||||
import com.slife.util.ReturnDTOUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@@ -49,7 +53,7 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@PostMapping(value = "/exportUserList")
|
||||
@ResponseBody
|
||||
public void exportCollectCustomerList(@RequestBody DataTable dt,HttpServletResponse response) throws Exception {
|
||||
public void exportCollectCustomerList(@RequestBody DataTable dt, HttpServletResponse response) throws Exception {
|
||||
List<SysUser> users = sysUserService.pageSearch(dt).getRows();
|
||||
|
||||
//导出数据
|
||||
@@ -57,7 +61,7 @@ public class SysUserController extends BaseController {
|
||||
String[] headerTitle = new String[]{"id", "登陆名", "姓名", "邮箱", "工号", "电话", "手机", "描述", "状态"};
|
||||
List<String[]> arrayList = new ArrayList<>();
|
||||
arrayList.add(headerTitle); //列头
|
||||
if (null!=users && users.size()>0) {
|
||||
if (null != users && users.size() > 0) {
|
||||
for (SysUser sysUser : users) {
|
||||
arrayList.add(
|
||||
new String[]{
|
||||
@@ -69,7 +73,7 @@ public class SysUserController extends BaseController {
|
||||
sysUser.getPhone(),
|
||||
sysUser.getMobile(),
|
||||
sysUser.getRemark(),
|
||||
sysUser.getLoginFlag().equals("Y")?"正常":"禁用"
|
||||
sysUser.getLoginFlag().equals("Y") ? "正常" : "禁用"
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -77,12 +81,27 @@ public class SysUserController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除头像", notes = "删除头像")
|
||||
@PostMapping(value = "/delete/photo")
|
||||
public ReturnDTO deletePhoto(@RequestParam("name") String name) {
|
||||
|
||||
String defaluePhoto = "/img/log9.png";
|
||||
if (defaluePhoto.equals(name)) {
|
||||
logger.info("默认头像不可删除!");
|
||||
return ReturnDTOUtil.custom(HttpCodeEnum.DELETE_DEFAULT_PHOTO_ERR);
|
||||
}
|
||||
Long userId = SlifeSysUser.id();
|
||||
SysUser sysUser = sysUserService.selectById(userId);
|
||||
if (ObjectUtils.isEmpty(sysUser)) {
|
||||
return ReturnDTOUtil.notFound();
|
||||
}
|
||||
sysUser.setPhoto(defaluePhoto);
|
||||
sysUserService.updateById(sysUser);
|
||||
|
||||
FileUtils.deleteFile(name);//删除文件
|
||||
return ReturnDTOUtil.success();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ApiOperation(value = "进入用户列表", notes = "进入用户列表")
|
||||
@GetMapping(value = "")
|
||||
public String list(Model model, HttpServletRequest request) {
|
||||
|
||||
@@ -39,25 +39,22 @@
|
||||
<div class="col-sm-2">
|
||||
<div id="localImag" style="margin-left:15px;">
|
||||
<div class="img_box" id="imgBox_${image.id}">
|
||||
<a class="fancybox" rel="img" <#if sysUser.photo?if_exists >
|
||||
href="${base}${sysUser.photo}"
|
||||
<a class="fancybox" rel="img" <#if sysUser.photo?if_exists > href="${base}${sysUser.photo}"
|
||||
<#else>href="${base}/img/log9.png" </#if>>
|
||||
<img style="width: 60px" src="${sysUser.photo}" onerror="this
|
||||
.src='${base}/img/log9.png'"
|
||||
class="img_file img-rounded"/></a>
|
||||
<img style="width: 60px" src="${sysUser.photo}" onerror="this.src='${base}/img/log9.png'" class="img_file img-rounded"/></a>
|
||||
<div class="img_edit_box">
|
||||
<!--<a class="img_desr" href="javascript:doDelete(${image.id})">删除</a>-->
|
||||
<a class="img_desr" href="javascript:doDeleteImg()">删除</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<span class="btn green btn-file fileinput-button input-group-btn" style="width: 180px;">
|
||||
<span>上传头像</span><input id="files" type="file" name="files"
|
||||
onchange="javascript:setImagePreview('files' ,'showIcon' ,'localImag' ,'74px' ,'74px' ,'74px' ,'74px')"/>
|
||||
<input id="photo" class="form-control" type="hidden" name="photo"
|
||||
value="${sysUser.photo}/type=image"/>
|
||||
<span>上传头像</span>
|
||||
<input id="files" type="file" name="files" onchange="javascript:setImagePreview('files' ,'showIcon' ,'localImag' ,'74px' ,'74px' ,'74px' ,'74px')"/>
|
||||
<input id="photo" class="form-control" type="hidden" name="photo" value="${sysUser.photo}"/>
|
||||
</span>
|
||||
<label class="col-sm-2 input-group" style="width:400px;" id="imgType"></label>
|
||||
</span>
|
||||
@@ -181,6 +178,33 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
function doDeleteImg() {
|
||||
|
||||
var name=$("#photo").val();
|
||||
layer.confirm('确定要删除头像吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.ajax({
|
||||
url: url + "delete/photo",
|
||||
type: "POST",
|
||||
data: {
|
||||
'name': name
|
||||
},
|
||||
success: function (r) {
|
||||
if (r.code == 200) {
|
||||
$("#photo").val("/img/log9.png");
|
||||
$("#imgId").attr('src',"/img/log9.png");
|
||||
$("#imgId").attr('src',"/img/log9.png");
|
||||
} else {
|
||||
layer.msg(r.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/!*上传头像*!/
|
||||
$('#files').fileupload({
|
||||
|
||||
@@ -62,9 +62,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Bootstrap table -->
|
||||
<script src="${base}/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
|
||||
<script src="${base}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 586 B |
@@ -15,4 +15,8 @@
|
||||
|
||||
.required {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.layui-layer-shade{
|
||||
opacity: -1!important;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* 请求 成功 返回的 操作
|
||||
* @param r
|
||||
*/
|
||||
function rep_message(r) {
|
||||
function dataTable_rep_message(r) {
|
||||
if (r.code == 200) {
|
||||
layer.msg(r.message);
|
||||
re_load();
|
||||
@@ -11,6 +11,8 @@ function rep_message(r) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@@ -36,7 +38,7 @@ function batch_remove() {
|
||||
data: {"ids": ids},
|
||||
url: url + "delete",
|
||||
success: function (r) {
|
||||
rep_message(r)
|
||||
dataTable_rep_message(r)
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
@@ -62,7 +64,7 @@ function remove(id) {
|
||||
'ids': id
|
||||
},
|
||||
success: function (r) {
|
||||
rep_message(r)
|
||||
dataTable_rep_message(r)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -16,3 +16,70 @@ function stop_request_load() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*docName file组件的name
|
||||
*viewId img的id
|
||||
*localId div的id
|
||||
* imgWidth img的宽度
|
||||
* imgHeight img的高度
|
||||
* divWidth div的宽度
|
||||
* divHeight div的高度
|
||||
*/
|
||||
function setImagePreview(docName,viewId,localId,imgWidth,imgHeight,divWidth,divHeight,tip){
|
||||
// return;
|
||||
$('#uploadFiletIcon').text('');
|
||||
var docObj=document.getElementById(docName); //"doc");
|
||||
var imgObjPreview=document.getElementById(viewId); //"preview");
|
||||
var fileObj=$('#'+docName).val();
|
||||
if(tip==1){
|
||||
$('#tip').val(1);
|
||||
$('#uploadFileIconx').val('');
|
||||
$('#uploadFileIcon').text('');
|
||||
}else{
|
||||
$('#iconTip').val(1);
|
||||
}
|
||||
if(fileObj){
|
||||
if(docObj.files&&docObj.files[0]){
|
||||
//火狐下,直接设img属性
|
||||
imgObjPreview.style.display='inline-block';
|
||||
imgObjPreview.style.width=imgWidth; //'60px';
|
||||
imgObjPreview.style.height=imgHeight; //'60px';
|
||||
//imgObjPreview.src = docObj.files[0].getAsDataURL();
|
||||
//火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式
|
||||
imgObjPreview.src=window.URL.createObjectURL(docObj.files[0]);
|
||||
}else{
|
||||
//IE下,使用滤镜
|
||||
docObj.select();
|
||||
var imgSrc=document.selection.createRange().text;
|
||||
var localImagId=document.getElementById(localId); //"localImag");
|
||||
//必须设置初始大小
|
||||
localImagId.style.width=divWidth; //"300px";
|
||||
localImagId.style.height=divHeight; //"120px";
|
||||
//图片异常的捕捉,防止用户修改后缀来伪造图片
|
||||
try{
|
||||
localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
|
||||
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=imgSrc;
|
||||
}catch(e){
|
||||
alert("您上传的图片格式不正确,请重新选择!");
|
||||
return false;
|
||||
}
|
||||
imgObjPreview.style.display='none';
|
||||
document.selection.empty();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* axaj 请求返回
|
||||
* @param r
|
||||
*/
|
||||
function rep_message(r) {
|
||||
if (r.code == 200) {
|
||||
layer.msg(r.message);
|
||||
} else {
|
||||
layer.msg(r.error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user