提交 b45b1774 编写于 作者: Skyeye云's avatar Skyeye云

上传修改

上级 afd4748c
......@@ -17,6 +17,7 @@ import com.skyeye.common.dao.CommonDao;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.common.service.CommonService;
import com.skyeye.common.util.ToolUtil;
@Service
......@@ -38,34 +39,56 @@ public class CommonServiceImpl implements CommonService{
@SuppressWarnings({ "static-access", "rawtypes" })
@Override
public void uploadFile(InputObject inputObject, OutputObject outputObject) throws Exception {
Map<String, Object> map = inputObject.getParams();
// 将当前上下文初始化给 CommonsMutipartResolver (多部分解析器)
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(inputObject.getRequest().getSession().getServletContext());
// 检查form中是否有enctype="multipart/form-data"
System.out.println(inputObject.getRequest().getContentType());
if (multipartResolver.isMultipart(inputObject.getRequest())) {
// 将request变成多部分request
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) inputObject.getRequest();
// 获取multiRequest 中所有的文件名
Iterator iter = multiRequest.getFileNames();
int type = Integer.parseInt(map.get("type").toString());
String tPath = inputObject.getRequest().getSession().getServletContext().getRealPath("/");
String basePath = "";
//决定存储路径
switch (type) {
case 1://小程序上传
basePath = tPath + "\\assets\\smpropic" ;
break;
default:
basePath = tPath.substring(0, inputObject.getRequest().getSession().getServletContext().getRealPath("/").indexOf(Constants.PROJECT_WEB));
break;
}
Map<String, Object> bean = new HashMap<>();
String trueFileName = "";
while (iter.hasNext()) {
// 一次遍历所有文件
MultipartFile file = multiRequest.getFile(iter.next().toString());
String fileName = file.getOriginalFilename();// 文件名称
//得到文件扩展名
String fileExtName = fileName.substring(fileName.lastIndexOf(".") + 1);
if (file != null) {
String tPath = inputObject.getRequest().getSession().getServletContext().getRealPath("/");
String basePath = tPath.substring(0, inputObject.getRequest().getSession().getServletContext().getRealPath("/").indexOf(Constants.PROJECT_WEB));
File pack = new File(basePath);
if(!pack.isDirectory()){//目录不存在
pack.mkdir();//创建目录
}
String path = basePath + file.getOriginalFilename();
// 自定义的文件名称
String newFileName = String.valueOf(System.currentTimeMillis()) + "." + fileExtName;
String path = basePath + "\\" + newFileName;
// 上传
file.transferTo(new File(path));
if(ToolUtil.isBlank(trueFileName)){
trueFileName = newFileName;
}else{
trueFileName = trueFileName + "," + newFileName;
}
}
}
bean.put("picUrl", trueFileName);
bean.put("type", type);
outputObject.setBean(bean);
}
}
......
......@@ -182,9 +182,17 @@ public class RmGroupMemberServiceImpl implements RmGroupMemberService{
* @return void 返回类型
* @throws
*/
@SuppressWarnings("static-access")
@Override
public void editRmGroupMemberMationById(InputObject inputObject, OutputObject outputObject) throws Exception {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> item = rmGroupMemberDao.queryRmGroupMemberMationById(map);
if(!item.get("printsPicUrl").toString().equals(map.get("img").toString())){//保存的图片和原来的图片不符
//删除原来的图片
String tPath = inputObject.getRequest().getSession().getServletContext().getRealPath("/");
String basePath = tPath + "\\assets\\smpropic\\" + item.get("printsPicUrl").toString();
ToolUtil.deleteFile(basePath);
}
rmGroupMemberDao.editRmGroupMemberMationById(map);
}
......
......@@ -98,7 +98,8 @@
<select id="queryRmGroupMemberMationToEditById" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
CONCAT(#{basePath}, a.prints_pic_url) printsPicUrl,
a.prints_pic_url printsPicUrl,
a.prints_pic_url printsPicUrlOld,
(SELECT COUNT(*) FROM sm_project_page_mode b WHERE b.rm_group_member_id = a.id) memberUseNum,
CONVERT(a.create_time, char) createTime,
(SELECT c.name FROM rm_type c WHERE c.id = a.sm_type_id) typeName,
......@@ -121,6 +122,9 @@
<if test="wxmlJsContent != '' and wxmlJsContent != null">
wxml_js_content = #{wxmlJsContent},
</if>
<if test="img != '' and img != null">
prints_pic_url = #{img},
</if>
</set>
WHERE id = #{id}
</update>
......
......@@ -230,7 +230,7 @@
<property id="htmlJsContent" name="htmlJsContent" ref="" var="html对应的js内容"/>
<property id="wxmlContent" name="wxmlContent" ref="required" var="wxml内容"/>
<property id="wxmlJsContent" name="wxmlJsContent" ref="" var="wxml对应的js内容"/>
<property id="img" name="img" ref="required" var="小程序分组id"/>
<property id="img" name="img" ref="required" var="小程序组件图片"/>
</url>
<url id="rmxcx017" path="/post/RmGroupMemberController/editRmGroupMemberSortTopById" val="小程序组件展示顺序上移" allUse="1">
<property id="rowId" name="id" ref="required" var="小程序组件id"/>
......@@ -248,6 +248,7 @@
<property id="wxmlContent" name="wxmlContent" ref="required" var="wxml内容"/>
<property id="wxmlJsContent" name="wxmlJsContent" ref="" var="wxml对应的js内容"/>
<property id="rowId" name="id" ref="required" var="小程序组件id"/>
<property id="img" name="img" ref="required" var="小程序组件图片"/>
</url>
<!-- 小程序系列结束 -->
......
......@@ -105,6 +105,7 @@ function isNull(str){
mobile: 'modules/mobile', // 移动大模块 | 若当前为开发目录,则为移动模块入口,否则为移动模块集合
'layui.all': '../layui.all', // PC模块合并版
cookie: 'modules/cookie',//cookie
fileUpload: 'modules/jQuery.upload.min'//上传
};
// 记录基础数据
......
......@@ -2093,6 +2093,333 @@ body .layer-ext-winconfirm {
/***showmode end***/
/*** 上传 start ***/
.upload,.upload li {
margin: 0;
padding: 0;
list-style-type: none
}
.upload {
border: 1px solid #d7d7d7;
padding: 2px 2px 2px 2px;
zoom: 1;
position: relative;
width: 100%;
background-color: #fff
}
.upload:after {
display: block;
clear: both;
content: "";
visibility: hidden;
height: 0
}
.upload .item {
width: 60px;
height: 60px;
float: left;
margin: 0 5px 0px 0;
background: #f8f8f8;
position: relative;
border-radius: 4px;
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
border: 1px solid #d7d7d7;
overflow: hidden
}
.upload .item .filename {
font-size: 12px;
width: 90%;
left: 5%;
position: absolute;
top: 70%;
line-height: 1.3em;
height: 2.6em;
overflow: hidden;
text-align: center
}
.upload .item.error {
border-color: #f20
}
.upload .item.error::after {
content: "";
background: rgba(255,255,255,.8);
position: absolute;
width: 100%;
height: 100%;
z-index: 9;
display: block;
line-height: 100%;
text-align: center
}
.upload .item.error::before {
content: attr(data-error);
position: absolute;
padding: 10px;
z-index: 10;
display: block;
font-size: 12px;
color: #f20;
top: 0
}
.upload .item svg.icon {
position: absolute;
height: 40%;
top: 20%;
left: 0;
width: 100%
}
.upload .item svg.progress {
position: absolute;
bottom: 0;
width: 100%;
height: 50%
}
.upload .item .progressnum {
width: 40px;
height: 40px;
border-radius: 40px;
text-align: center;
line-height: 40px;
font-size: 12px;
color: #fff;
position: absolute;
left: 50%;
margin-left: -20px;
top: 50%;
margin-top: -20px;
background: rgba(17,89,164,.5)
}
.upload .item.add svg {
top: 30%
}
.upload .item.success::after {
position: absolute;
background: rgba(0,0,0,.6);
content: "";
left: 0;
right: 0;
top: 0;
bottom: 0;
opacity: 0;
transition: all .3s
}
.upload .item.success:hover::after {
opacity: 1
}
.upload .item.success svg.delete,.upload .item.success svg.look {
position: absolute;
height: 30px;
top: 50%;
margin-top: -15px;
left: 50%;
color: #fff;
z-index: 10;
transition: all .3s;
cursor: pointer
}
.upload .item.success svg.delete {
margin-left: -35px;
height: 26px;
margin-top: -14px;
left: -30px
}
.upload .item.success svg.look {
margin-left: 10px;
left: 105%
}
.upload .item.success:hover svg.delete {
margin-left: -35px;
left: 50%;
height: 26px;
margin-top: -14px;
transition: all .3s
}
.upload .item.success:hover svg.look {
margin-left: 10px;
left: 50%;
transition: all .3s
}
.upload .item.delete {
opacity: .2;
transition: all .3s
}
.upload input[type=file] {
display: none
}
.upload.multiple.empty {
height: 60px;
width: 100%
}
.upload.multiple.empty .add {
width: 100%;
position: absolute;
top: 50%;
margin-top: -30px;
height: 36px;
background: 0;
border: 0;
left: 0;
overflow: inherit
}
.upload.multiple.empty .add::after {
content: "选择";
width: 20%;
top: 10px;
position: absolute;
height: 36px;
background: #0e90d2;
left: 40%;
/*margin-left: -90px;*/
display: block;
z-index: 9;
visibility: visible;
text-align: center;
color: #fff;
line-height: 36px;
font-size: 14px;
border: 0;
border-radius: 0
}
.upload.multiple.empty .add:hover::after {
background-color: #0a70c2
}
.upload.multiple.empty .add svg {
display: none
}
/*.upload.multiple.empty .add::before {
!*content: "点击此处选择文件,最多可以上传 "attr(data-num) " 个" attr(data-type) "格式文件";*!
content: "点击此处选择文件";
width: 100%;
text-align: center;
position: absolute;
bottom: -30px;
font-size: 12px;
margin-top: 14px;
left: 0;
color: #999;
white-space: nowrap
}*/
.upload.one {
width: 70px;
height: 70px;
padding: 0
}
.upload.one li {
height: 100%;
width: 100%;
margin: 0;
padding: 0
}
.upload.one li.add svg {
opacity: 0;
transition: all .3s;
margin-top: -30px
}
.upload.one li.add:hover svg {
opacity: 1;
transition: all .3s
}
.upload.one.empty li.add svg {
opacity: 1;
transition: all .3s
}
.upload.one .item {
border: 0;
border-radius: 0
}
.upload.one .add {
position: absolute;
top: 30px;
right: 0;
left: 0;
background: 0
}
.upload.one .item.success svg.delete,.upload.one .item.success svg.look {
top: 0;
margin-top: 5px
}
.upload.one .item.success svg.look {
margin-top: 3px
}
.upload.dragenter {
border: 2px dashed #d7d7d7;
box-shadow: 0 1px 5px rgba(0,0,0,.7);
display: table
}
.upload.dragenter::after {
content: "";
background: rgba(255,255,255,.9);
z-index: 998;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
vertical-align: middle;
display: table-cell;
visibility: visible
}
.upload.dragenter::before {
content: "将文件拖到这里上传";
position: absolute;
width: 100%;
top: 50%;
z-index: 999;
width: 100%;
text-align: center;
margin-top: -12px;
color: #999
}
.upload.one li.add svg{
margin-top: unset;
}
.upload.one .add{
top: unset;
}
/*** 上传 end ***/
.cursor{
cursor: pointer;
}
......
......@@ -2,7 +2,7 @@
layui.config({
base: basePath,
version: skyeyeVersion
}).define(['table', 'jquery', 'winui'], function (exports) {
}).define(['table', 'jquery', 'winui', 'fileUpload'], function (exports) {
winui.renderColor();
layui.use(['form'], function (form) {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
......@@ -16,23 +16,36 @@ layui.config({
pagination: false,
template: getFileContent('tpl/rmgroupmember/rmgroupmembereditTemplate.tpl'),
ajaxSendLoadBefore: function(hdb){
hdb.registerHelper("compare1", function(v1, options){
return '<img src="' + fileBasePath + v1 + '" style="width:100%;height:auto" class="cursor">';
});
},
ajaxSendAfter:function(json){
//初始化上传
$("#printsPicUrl").upload({
"action": reqBasePath + "common003",
"data-num": "1",
"data-type": "PNG,JPG,jpeg,gif",
"uploadType": 1,
"data-value": json.bean.printsPicUrl,
//该函数为点击放大镜的回调函数,如没有该函数,则不显示放大镜
"function": function (_this, data) {
show("#printsPicUrl", data);
}
});
//搜索表单
form.render();
form.on('submit(formEditBean)', function (data) {
//表单验证
if (winui.verifyForm(data.elem)) {
var params = {
wxmlContent: encodeURI($("#wxmlContent").val()),
wxmlJsContent: encodeURI($("#wxmlJsContent").val()),
rowId: parent.rowId
rowId: parent.rowId,
};
params.img = $("#printsPicUrl").find("input[type='hidden'][name='upload']").attr("oldurl");
AjaxPostUtil.request({url:reqBasePath + "rmxcx021", params:params, type:'json', callback:function(json){
if(json.returnCode == 0){
parent.layer.close(index);
......@@ -52,19 +65,6 @@ layui.config({
parent.layer.close(index);
});
//图片点击
$("body").on("click", ".cursor", function(){
layer.open({
type:1,
title:false,
closeBtn:0,
skin: 'demo-class',
shadeClose:true,
content:'<img src="' + $(this).attr("src") + '" style="max-height:600px;max-width:100%;">',
scrollbar:false
});
});
});
});
\ No newline at end of file
......@@ -29,7 +29,7 @@ layui.config({
//初始化上传
$("#showForm").find('.fileUploadContent').each(function(i, dom) {
if($.inArray($(dom).attr("id"), picArray) < 0){
picArray.push($(dom).attr("id"));
picArray.push($(dom).attr("id"));
var fileType = "*";
if($(dom).attr("id") == "userPhoto")//图片上传
fileType = filePicType;
......
......@@ -26,9 +26,8 @@
<div class="layui-form-item">
<label class="layui-form-label">预览图<i class="red">*</i></label>
<div class="layui-col-xs6">
<div class="layui-col-xs10" id="images">
{{#compare1 printsPicUrl}}{{/compare1}}
</div>
<div class="upload" id="printsPicUrl"></div>
<span class="help-block m-b-none">格式:png,jpg,jpeg,gif</span>
</div>
</div>
<div class="layui-form-item">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册