displayPicOnMobile.jsp
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.Util"%>
<%@page import="com.weaver.formmodel.util.NumberHelper"%>
<%@page import="com.weaver.formmodel.util.StringHelper"%>
<%@page import="java.util.zip.ZipEntry"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.zip.ZipInputStream"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.file.AESCoder"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="com.sun.image.codec.jpeg.JPEGCodec"%>
<%@page import="com.sun.image.codec.jpeg.JPEGImageDecoder"%>
<%@page import="java.io.ByteArrayInputStream"%>
<%@page import="java.io.ByteArrayOutputStream"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.hrm.User"%>
<%@ page import="weaver.hrm.HrmUserVarify"%>
<%
User user = HrmUserVarify.checkUser(request, response);
if(user == null){
out.println("无用户,请登录");
return;
}
int language = user.getLanguage();
String imgSrc = Util.null2String(request.getParameter("imgSrc")).trim();
String imgSrcActive = Util.null2String(request.getParameter("imgSrcActive")).trim();
if("".equals(imgSrc)){
return;
}
int imgIndexActive = 0;
JSONArray items = new JSONArray();
String[] imgArr = imgSrc.split(",");
for(int imgIdx = 0; imgIdx < imgArr.length; imgIdx++){
String imgPath = imgArr[imgIdx];
if(imgPath.equals(imgSrcActive)){
imgIndexActive = imgIdx;
}
String fileid = "";
boolean isID = false;
int sIndex;
if((sIndex = imgPath.indexOf("/weaver/weaver.file.FileDownload?fileid=")) != -1){
int eIndex = imgPath.indexOf("&", sIndex);
if(eIndex == -1){
eIndex = imgPath.length();
}
fileid = imgPath.substring(sIndex + "/weaver/weaver.file.FileDownload?fileid=".length(), eIndex);
isID = true;
}else if(imgPath.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")){
fileid = imgPath;
imgPath = "/weaver/weaver.file.FileDownload?fileid=" + fileid;
isID = true;
}
boolean isUrl = !isID && !imgPath.equals("");
InputStream inStream = null;
String imagefiletype = "";
if(isID){
String sql = "select t1.imagefilename,t1.filerealpath,t1.iszip,t1.isencrypt,t1.imagefiletype , t1.imagefileid, t1.imagefile,t1.isaesencrypt,t1.aescode,t2.imagefilename as realname,t1.TokenKey,t1.StorageStatus,t1.comefrom,t1.fileSize as filesize from ImageFile t1 left join DocImageFile t2 on t1.imagefileid = t2.imagefileid where t1.imagefileid = "+fileid;
RecordSet rs = new RecordSet();
rs.execute(sql);
if(rs.next()){
String filerealpath = Util.null2String(rs.getString("filerealpath"));
String iszip = Util.null2String(rs.getString("iszip"));
String isaesencrypt = Util.null2o(rs.getString("isaesencrypt"));
String aescode = Util.null2String(rs.getString("aescode"));
imagefiletype = Util.null2String(rs.getString("imagefiletype"));
ZipInputStream zin = null;
File thefile = new File(filerealpath);
if (iszip.equals("1")) {
zin = new ZipInputStream(new FileInputStream(thefile));
if (zin.getNextEntry() != null) inStream = new BufferedInputStream(zin);
} else{
inStream = new BufferedInputStream(new FileInputStream(thefile));
}
if(isaesencrypt.equals("1")){
inStream = AESCoder.decrypt(inStream, aescode);
}
}
}else if(isUrl){
String realPath = request.getSession().getServletContext().getRealPath(imgPath);
File file = new File(realPath);
if(!file.exists() || !file.isFile()){
return;
}
inStream = new BufferedInputStream(new FileInputStream(file));
}
/*使用ByteArrayOutputStream读取inStream,相当于缓存复制一份inStream。下面用的时候不能因为try中的代码干扰catch中的代码*/
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = inStream.read(buffer)) > -1 ) {
byteArrayOutputStream.write(buffer, 0, len);
}
byteArrayOutputStream.flush();
BufferedImage inputBufImage = null;
try{
inputBufImage = ImageIO.read(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
}catch(Exception ex){
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
inputBufImage = decoder.decodeAsBufferedImage();
}
int width = inputBufImage.getWidth();
int height = inputBufImage.getHeight();
JSONObject item = new JSONObject();
item.put("src", imgPath);
item.put("w", width);
item.put("h", height);
items.add(item);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="/mobilemode/js/photoSwipe/css/photoswipe_wev8.css">
<link rel="stylesheet" href="/mobilemode/js/photoSwipe/css/default-skin/default-skin_wev8.css">
<script src="/mobilemode/js/photoSwipe/js/photoswipe.min_wev8.js"></script>
<script src="/mobilemode/js/photoSwipe/js/photoswipe-ui-default.min_wev8.js"></script>
<script src="/mobilemode/js/zepto/zepto.min_wev8.js"></script>
<script src="/mobilemode/js/hammer/hammer.min_wev8.js"></script>
<style type="text/css">
html,body{
margin: 0px;
padding: 0px;
background-color: #000;
}
.my-gallery {
width: 100%;
float: left;
}
.my-gallery img {
width: 100%;
height: auto;
}
.my-gallery figure {
display: block;
float: left;
margin: 0 5px 5px 0;
width: 150px;
}
.my-gallery figcaption {
display: none;
}
.pswp__button--close{
background: url(/mobilemode/js/photoSwipe/css/default-skin/default-skin_wev8.png) no-repeat;
background-size: 20px 20px;
width: 44px;
height: 44px;
background-position: 10px center;
position: relative;
cursor: pointer;
float: left;
-webkit-appearance: none;
display: block;
border: 0;
padding: 0;
margin: 0;
-webkit-transition: opacity 0.2s;
transition: opacity 0.2s;
-webkit-box-shadow: none;
box-shadow: none;
}
</style>
</head>
<body>
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="pswp__bg"></div>
<div class="pswp__scroll-wrap">
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var cWidth = document.body.clientWidth;
var cHeight= document.body.clientHeight;
var openPhotoSwipe = function() {
var pswpElement = document.querySelectorAll('.pswp')[0];
var items = <%=items.toString()%>;
var imgIndexActive = <%=imgIndexActive%>;
var options = {
history : false,
focus : false,
showAnimationDuration : 0,
hideAnimationDuration : 0,
captionAndToolbarOpacity : 0.1,
maxSpreadZoom: 4,
index : imgIndexActive, //显示图片位置
loop : false //相册是否自动循环
};
var pSwp = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
pSwp.init();
//图片加载完成时添加事件
pSwp.listen('imageLoadComplete', function(index, item) {
pressImgForSave();
});
};
document.addEventListener('DOMContentLoaded', openPhotoSwipe, false);
function pressImgForSave(){
if(!(typeof(top.isRunInEmobile) == "function" && top.isRunInEmobile())){
return;
}
$("img").each(function(){
var $imgEle = $(this);
var flag = $imgEle.attr("data-press-save-event");
if(flag == "1"){
return;
}
$imgEle.attr("data-press-save-event", "1");
var mc = new Hammer($imgEle[0], {
recognizers: [
[Hammer.Press,{ time : 500 }]
]
});
mc.on('press', function(ev) {
var imgSrc = $(ev.target).attr("src");
if(imgSrc == null || imgSrc == ""){
return;
}
top.addDialogCover([
{id : "a", menuText : "<div style='text-align: center;margin-left: -18px;font-size: 18px;color: #017afd;'><%=SystemEnv.getHtmlLabelName(383806,language)%></div>", callback : function(){
location = "emobile:saveImage:"+imgSrc+":111";
}}
]);
});
});
}
function doClose(){
if(top && typeof(top.doHistoryBack) == "function"){
top.doHistoryBack();
}
}
</script>
</body>
</html>