service.viewimg_wev8.js
5.32 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
define("mService/viewimg", ["mUtil", "photoswipe", "photoswipe_ui", "i18n"], function(mUtil, PhotoSwipe, PhotoSwipeUI_Default, i18n) {
return {
mounted: function($page, cfg){
var defCfg = {
items : [],
active : 0
};
$.extend(defCfg, cfg);
var base64Items = [];
var webSrcs = [];
var defItems = defCfg.items;
defItems.forEach(function(theSrc, index){
if(theSrc.indexOf("data:image") == 0){
var img = new Image();
img.src = theSrc;
var itmCfg = {
"src": theSrc,
"w": img.naturalWidth,
"h": img.naturalHeight
};
base64Items.push(itmCfg);
}else{
webSrcs.push({src: theSrc, index: index});
}
});
if(webSrcs.length > 0){
var url = mUtil.jionActionUrl("com.api.mobilemode.web.mobile.service.MobileCommonAction", "action=getImgMeta&items="+encodeURIComponent(JSON.stringify(webSrcs)));
mUtil.getJSON(url, function(result){
var webItems = result.datas;
var allItems = webItems.concat(base64Items);
var pswpItems = [];
defItems.forEach(function(theSrc, defIndex){
allItems.every(function(theItem, index){
if(theItem.src == theSrc || theItem.index == defIndex){
pswpItems.push(theItem);
allItems.splice(index, 1);
return false;
}
return true;
});
});
initPswp(pswpItems);
});
}else{
initPswp(base64Items);
}
function initPswp(pswpItems){
if(pswpItems.length == 0 ){
Mobile_NS.alert(i18n.IMAGE_LOADING_ERROER);
}
$(".wev-loading", $page).hide();
var options = {
history : false,
focus : false,
showAnimationDuration : 0,
hideAnimationDuration : 0,
captionAndToolbarOpacity : 0.1,
maxSpreadZoom: 4,
errorMsg:"<div class='pswp__error-msg'>"+ i18n.IMAGE_LOADING_ERROER +"</div>",
escKey: false,
index : defCfg.active, //显示图片位置
loop : false,
closeOnVerticalDrag: false,
clickToCloseNonZoomable: false,
closeOnScroll:false,
closeElClasses: [],
pinchToClose:false,
onClose: function(){
mUtil.back();
}
};
var pswpElement = $(".pswp", $page)[0];
var pswp = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, pswpItems, options);
pswp.init();
var pressImgForSave = function(){
if(!mUtil.runtime.isEmobile() && !mUtil.runtime.isEmobile7()){
return;
}
require(["hammer"], function(Hammer){
$(".pswp__img", $page).each(function(){
var $img = $(this);
var mc = new Hammer($img[0], {
recognizers: [
[Hammer.Press,{ time : 500 }]
]
});
mc.on('press', function(ev) {
var imgSrc = $(ev.target).attr("src");
if(imgSrc == null || imgSrc == ""){
return;
}
Mobile_NS.footerMenu([
{
text : "<div style='text-align: center;margin-left: -18px;font-size: 20px;color: #017afd;'>"+i18n.SAVE_IMAGE+"</div>",
callback : function(){
if(mUtil.checkEmpJsApi("downloadImage")){
mUtil.invokeEmApi("downloadImage", {
url: imgSrc,
isShowProgressTips: 1,
success: function(){
Mobile_NS.msg(i18n.SAVE_SUCCESS);//保存成功
}
});
}else{
if(imgSrc.indexOf("data:image") == 0){
try {
var baseArr=imgSrc.split(",");
var basepic64=baseArr[1];
if(mUtil.checkEmpJsApi("saveBase64Image")) {
mUtil.invokeEmApi("saveBase64Image", {
base64Img: basepic64,
success: function(){
Mobile_NS.msg(i18n.SAVE_SUCCESS);//保存成功
}
});
}
} catch (e){
console.log(e.message);
}
} else {
location = "emobile:saveImage:"+imgSrc+":111";
}
}
}
}
]);
});
});
});
}
pswp.listen('imageLoadComplete', pressImgForSave);
}
}
};
});