提交 6b40267e 编写于 作者: F fancy

新增移动端应用页面图片替换

上级 1ce7cc36
package com.x.program.center.jaxrs.appstyle;
import com.x.base.core.project.config.AppStyle.Image;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Method;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
* 应用页面顶部图片替换
* 730 * 390
*/
class ActionImageApplicationTop extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, byte[] bytes, FormDataContentDisposition disposition)
throws Exception {
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ActionResult<Wo> result = new ActionResult<>();
if (!effectivePerson.isManager()) {
throw new ExceptionAccessDenied(effectivePerson.getName());
}
BufferedImage image = ImageIO.read(bais);
BufferedImage scalrImage = Scalr.resize(image, Method.QUALITY, 730, 390);
ImageIO.write(scalrImage, "png", baos);
String value = Base64.encodeBase64String(baos.toByteArray());
Image o = Image.application_top();
o.setValue(value);
// 由于getImages设置了检查,所以只能对images进行处理
Set<Image> images = Config.appStyle().getImages();
images = images.stream().filter(img -> (!StringUtils.equals(img.getName(), Image.name_application_top)))
.collect(Collectors.toSet());
images.add(o);
Config.appStyle().setImages(new TreeSet<>(images));
Config.appStyle().save();
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
Config.flush();
return result;
}
}
public static class Wo extends WrapBoolean {
}
}
\ No newline at end of file
package com.x.program.center.jaxrs.appstyle;
import com.x.base.core.project.config.AppStyle.Image;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import org.apache.commons.lang3.StringUtils;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
class ActionImageApplicationTopErase extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
if (!effectivePerson.isManager()) {
throw new ExceptionAccessDenied(effectivePerson.getName());
}
// 由于getImages设置了检查,所以只能对images进行处理
Set<Image> images = Config.appStyle().getImages();
images = images.stream().filter(img -> (!StringUtils.equals(img.getName(), Image.name_application_top)))
.collect(Collectors.toSet());
Config.appStyle().setImages(new TreeSet< >(images));
Config.appStyle().save();
Config.flush();
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
public static class Wo extends WrapBoolean {
}
}
\ No newline at end of file
......@@ -196,6 +196,25 @@ public class AppStyleAction extends BaseAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "设置图片:应用页面顶部图片,730x390.", action = ActionImageApplicationTop.class)
@PUT
@Path("image/application/top")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
public void imageApplicationTop(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@FormDataParam(FILE_FIELD) final byte[] bytes,
@JaxrsParameterDescribe("图片文件") @FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
ActionResult<ActionImageApplicationTop.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionImageApplicationTop().execute(effectivePerson, bytes, disposition);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "删除图片:首页底部菜单中间主页的按钮(不选中).", action = ActionImageMenuLogoBlurErase.class)
@GET
@Path("image/menu/logo/blur/erase")
......@@ -304,4 +323,22 @@ public class AppStyleAction extends BaseAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "设置图片:应用页面顶部图片,730x390", action = ActionImageApplicationTopErase.class)
@GET
@Path("image/application/top/erase")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void imageApplicationTopErase(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request) {
ActionResult<ActionImageApplicationTopErase.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionImageApplicationTopErase().execute(effectivePerson);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
......@@ -70,6 +70,9 @@
"imageSetupAboutLogo": {"uri": "/jaxrs/appstyle/image/setup/about/logo", "method": "PUT", "enctype": "formData"},
"imageSetupAboutLogoErase": {"uri": "/jaxrs/appstyle/image/setup/about/logo/erase"},
"imageApplicationTop": {"uri": "/jaxrs/appstyle/image/application/top", "method": "PUT", "enctype": "formData"},
"imageApplicationTopErase": {"uri": "/jaxrs/appstyle/image/application/top/erase"},
"setAppStyle": {"uri": "/jaxrs/appstyle", "method": "PUT"},
"listAgent": {"uri": "/jaxrs/agent"},
......
......@@ -444,6 +444,9 @@ MWF.xApplication.Setting.Document.Image = new Class({
case "setup_about_logo":
method = "imageSetupAboutLogo";
break;
case "application_top":
method = "imageApplicationTop";
break;
}
MWF.require("MWF.widget.Upload", function(){
......@@ -500,6 +503,9 @@ MWF.xApplication.Setting.Document.Image = new Class({
case "setup_about_logo":
method = "imageSetupAboutLogoErase";
break;
case "application_top":
method = "imageApplicationTopErase";
break;
}
this.actions[method](function(){
this.actions.mobile_currentStyle(function(json){
......
......@@ -189,6 +189,7 @@ MWF.xApplication.Setting.LP = {
"mobile_style_imgs": {
"launch_logo": "Start logo",
"login_avatar": "Default avatar for login page",
"application_top": "Image at the Application page",
"index_bottom_menu_logo_blur": "Home navigation icon (unchecked)",
"index_bottom_menu_logo_focus": "Home navigation icon (selected)",
"people_avatar_default": "User default avatar",
......
......@@ -188,6 +188,7 @@ MWF.xApplication.Setting.LP = {
"mobile_style_imgs": {
"launch_logo": "启动Logo",
"login_avatar": "登录界面默认头像",
"application_top": "应用页面顶部",
"index_bottom_menu_logo_blur": "主页导航图标(未选中)",
"index_bottom_menu_logo_focus": "主页导航图标(选中)",
"people_avatar_default": "用户默认头像",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册