service.portal_wev8.js
8.19 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
define("mService/portal", ["mUtil", "mService"], function(mUtil, mService) {
return {
mounted: function($page, cfg){
var loadBadge = function(){
var actionUrl = mUtil.getActionUrl("NavPanel", {action:"getBadge", "mec_id": defCfg.id, "lite": false}, defCfg.pageid);
var $badges = $(".wev-badge", $(".wev-page-portal", $page));
require(["remindHelper"], function(helper){
helper.renderBadge(actionUrl, $badges, defCfg.remindApis);
});
};
var modifyCfg = function(){
var showItems = [];
$(".sort-handle", $(".portal-items-big ul")).each(function(){
var itemid = $(this).find("a").attr("id").substring(2);
showItems.push(itemid);
});
var actionUrl = mUtil.getActionUrl("service.MobileCommon", {action: "setUserMecConfig"});
var paramData = {"config":JSON.stringify(showItems), "mecid": defCfg.id};
mUtil.ajax(actionUrl, paramData, function(result){
if(result.status == 1){
Mobile_NS.triggerRefresh(defCfg.id);
Mobile_NS.msg(mUtil.getLabel(384445,"保存设置成功"));
}
}, {type: "POST", dataType: "json"});
};
var defCfg = {
id: "",
pageid: "",
categories : [],
items : [],
col : "4",
title: ""
};
$.extend(defCfg, cfg);
$(".wev-header", $page).html(defCfg.title);
var tmpl_items = [
'<div class="portal-items">',
'<div>',
//应用编辑小图标
'<div class="portal-items-small"><span>#390289#</span>',
'<span>',
'{@each datas as d}',
'{@each d as item}',
'{@if !item.fillIn}',
'<img id="s_${item.id}" class="${item.iconClass}" src="${item.icon}"/>',
'{@/if}',
'{@/each}',
'{@/each}',
'</span>',
'<span class="portal-edit-btn"></span>',
'</div>',
//应用编辑拖拽内容
'<div class="portal-items-big">',
'<div class="portal-category">',
'<div>',
'<div class="portal-title"><span>#390289#<span class="portal-item-dragtips">#390461#</span></span><span class="portal-done-btn"></span></div>',
'<div class="portal-square">',
'<ul class="portal-square-inner portal-flex">',
'{@each datas as d}',
'{@each d as item}',
'{@if item.fillIn}',
'<li class="sort-hidden" style="width: calc(${perCol}% / ${col});"></li>',
'{@else}',
'<li class="sort-handle" style="width: calc(${perCol}% / ${col});">',
'<a id="b_${item.id}">',
'<img class="wev-big-icon ${item.iconClass}" src="${item.icon}"/>',
'<div class="portal-text">',
'$${item.text}',
'</div>',
'<div class="portal-item-edit portal-item-del"></div>',
'</a>',
'</li>',
'{@/if}',
'{@/each}',
'{@/each}',
'</ul>',
'</div>',
'</div>',
'</div>',
'</div>',
'</div>',
].join('');
var tmpl_categories = [
//全部应用
'{@each datas as d}',
'<div class="portal-category portal-items-select">',
'<div>',
'<div class="portal-title"><span>${d.category}</span></div>',
'<div class="portal-square">',
'<ul class="portal-square-inner portal-flex">',
'{@each d.items as item}',
'{@if item.fillIn}',
'<li style="width: calc(${perCol}% / ${col});"></li>',
'{@else}',
'<li style="width: calc(${perCol}% / ${col});">',
'<a id="c_${item.id}" href="${item.url}" data-ajax="${item.dataAjax}" data-reload="true" data-formdata="${item.queryString}">',
'<img class="wev-big-icon ${item.iconClass}" src="${item.icon}"/>',
'<div class="portal-text">',
'$${item.text}',
'</div>',
'{@if item.remind}',
'<span class="wev-badge" data-index="${index}" {@if item.apiid}data-api="${item.uuid}_${item.apiid}"{@/if}></span>',
'{@/if}',
'<div class="portal-item-edit {@if item.del}portal-item-del{@else}portal-item-add{@/if}"></div>',
'</a>',
'</li>',
'{@/if}',
'{@/each}',
'</ul>',
'</div>',
'</div>',
'</div>',
'{@/each}'
].join('');
var labelCahe = {
'131654':'更多',
'384116':'编辑',
'386812':'完成',
'390289':'我的应用',
'383193':'全部应用',
'390461':'(按住拖动调整排序)'
};
var replaceTempi18nLabel = function(tmpl,labels){
for(var labelIndex in labels){
tmpl = tmpl.replace(eval("/#"+labelIndex+"#/g"),labels[labelIndex]);
}
return tmpl;
};
var hrefMap = {};
mUtil.getMultiLabel(labelCahe,function(resultlabels){
!defCfg.title && $(".wev-header", $page).html(resultlabels['383193']);
$(".wev-loading", $page).hide();
var calWidth = 100-defCfg.col;
var html = mUtil.parseTemplate(replaceTempi18nLabel(tmpl_items,resultlabels), {"datas" : defCfg.items, "perCol" : calWidth, "col": defCfg.col});
html += mUtil.parseTemplate(replaceTempi18nLabel(tmpl_categories,resultlabels), {"datas" : defCfg.categories, "perCol" : calWidth, "col": defCfg.col});
$(".wev-page-portal", $page).html(html);
loadBadge();
$(".portal-edit-btn", $page).html(resultlabels['384116']).click(function(){
$(".portal-items-small").hide();
$(".portal-items-big").show();
$(".wev-page-portal", $page).addClass("portal-editing");
$(".portal-items-select").find("a").each(function(){
var a = $(this);
hrefMap[a.attr("id")] = a.attr("href");
a.attr("href", "javascript:void(0);");
});
});
$(".portal-done-btn", $page).html(resultlabels['386812']).click(function(){
$(".portal-items-big").hide();
$(".portal-items-small").show();
$(".wev-page-portal", $page).removeClass("portal-editing");
$(".portal-items-select").find("a").each(function(){
var a = $(this);
a.attr("href", hrefMap[a.attr("id")]);
});
modifyCfg();
});
var fillinNum = $(".sort-hidden", $(".portal-items-big")).size();
while(fillinNum < defCfg.col){
$(".portal-square-inner", $(".portal-items-big")).append("<li class=\"sort-hidden\" style=\"width: calc("+calWidth+"% / "+defCfg.col+");\"></li>");
fillinNum++;
}
//拖拽排序、删除
require(["sortable"], function (sortable) {
sortable.create($(".portal-square-inner", $(".portal-items-big", $page))[0], {
//handle: ".sort-handle",
draggable: ".sort-handle",
animation: 50,
filter: ".portal-item-del",
onFilter: function (evt) {
var item = evt.item,
ctrl = evt.target;
if (sortable.utils.is(ctrl, ".portal-item-del")) {
var itemid = $(item).find("a").attr("id").substring(2);
$(".portal-item-edit", $("#c_"+itemid)).removeClass("portal-item-del").addClass("portal-item-add");
item.parentNode.removeChild(item);
$("#s_"+itemid).remove();
}
}
});
});
$(".portal-item-edit", $(".portal-items-select")).on("click",function(){
var that = $(this);
if(that.hasClass("portal-item-del")) return;
that.removeClass("portal-item-add").addClass("portal-item-del");
var $item = that.parent();
var itemid = $item.attr("id").substring(2);
$item.attr("id", "b_"+itemid);
var $lastLi = $(".sort-handle", $(".portal-items-big")).last();
if($lastLi.length > 0){
$lastLi.after($item.parent().clone(true).addClass("sort-handle"));
}else{
$(".portal-square-inner", $(".portal-items-big")).prepend($item.parent().clone(true).addClass("sort-handle"));
}
$item.attr("id", "c_"+itemid);
var imgsrc = $item.find("img").attr("src");
var imgClass = $item.find("img").attr("class");
$(".portal-items-small>span:nth-child(2)").append("<img id=\"s_"+itemid+"\" class=\""+imgClass+"\" src=\""+imgsrc+"\">");
});
});
}
};
});