ScriptCenter.jsp
32.7 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/mobilemode/admin/init.jsp"%>
<%
String appid = Util.null2String(request.getParameter("appid"));
String inputid = Util.null2String(request.getParameter("inputid"));
String appHomepageId = Util.null2String(request.getParameter("appHomepageId"));
String noTitle = Util.null2String(request.getParameter("noTitle"));
String topMenu = Util.null2String(request.getParameter("topMenu"));
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>脚本库</title>
<link rel="stylesheet" type="text/css" href="./scriptLib.css" />
</head>
<body class="lang<%=user.getLanguage()%>">
<div class="wrapper">
<div class="function">
<div class="search">
<input id="fn-input" placeholder="<%=SystemEnv.getHtmlLabelName(383545, user.getLanguage())%>" /> <!-- 请输入函数名称或描述 -->
<label for="fn-input" class="input-del hide"></label>
</div>
<ul class="fn-tabs">
<li data-tab="all" class="selected"><%=SystemEnv.getHtmlLabelName(82857, user.getLanguage())%></li> <!-- 全部 -->
<li data-tab="recent"><%=SystemEnv.getHtmlLabelName(383546, user.getLanguage())%></li><!-- 最近使用 -->
</ul>
<div class="panel-wrapper">
<div data-rel="all" class="funcs tab-panel active">
</div>
<div data-rel="recent" class="recently tab-panel">
</div>
</div>
<div class="arrow"></div>
</div>
<div class='main <%=noTitle.equals("false") ? "no-title" : ""%>'>
<h4 class="default-title"><%=SystemEnv.getHtmlLabelName(383547, user.getLanguage())%></h4> <!-- 脚本编辑器 -->
<div class="fn-config">
<div class="vardesc-container" style="display: none; padding-left: 15px;">
<h4> <%=SystemEnv.getHtmlLabelName(506213, user.getLanguage())%> <span><%=SystemEnv.getHtmlLabelName(506215, user.getLanguage())%></span></h4><!--系统变量 点击生成代码-->
</div>
<div class="function-wrapper" style="display: none;">
<div class="temp-container">
<h4><span id="fn-title"></span> <%=SystemEnv.getHtmlLabelName(383548, user.getLanguage())%></h4> <!-- 函数配置 -->
<div class="config-btn">
<label></label>
<button><%=SystemEnv.getHtmlLabelName(127600, user.getLanguage())%></button> <!-- 生成代码 -->
</div>
</div>
<div class="fn-example">
<h4><%=SystemEnv.getHtmlLabelName(383551, user.getLanguage())%></h4> <!-- 函数示例 -->
<div id="example">
<div class="wrapper">
<pre></pre>
</div>
</div>
</div>
</div>
<div class="config-shrink"></div>
</div>
<div class="scriptCode">
<div id="scriptCode" name="scriptCode"></div>
</div>
</div>
</div>
<script type="text/template" id="fn-desc">
<li fnid="{{id}}">
<span class="sign">{{sign}}</span>
<span class="desc">{{desc}}</span>
</li>
</script>
<script type="text/template" id="fn-temp">
<div class="fn-category">
<input id="f-{{categoryName}}-input" type="checkbox">
<label for="f-{{categoryName}}-input"><span>{{categoryText}}</span><i class="iconfont icon-arrow-right fa-small"></i></label>
<ul class="fn-list">
{{
items.reduce(function(prev, item) {
var temp = "<li fnid='"+ item.id + "'>"
+ "<span class='sign'>" + item.sign + "</span>"
+ "<span class='desc'>" + item.desc + "</span></li>";
return prev + temp;
}, "");
}}
</ul>
</div>
</script>
<script type="text/template" id="fn-params">
<div>
<input class="f-params-key" type="text" placeholder="<%=SystemEnv.getHtmlLabelName(23481, user.getLanguage())%>"/> <!--参数名称-->
<span>=</span>
<input class="f-params-value" type="text" placeholder="<%=SystemEnv.getHtmlLabelName(126482, user.getLanguage())%>"/> <!--参数值-->
<span class="f-add" data-operation="addParams"></span>
<span class="f-delete" data-operation="delParams"></span>
</div>
</script>
<script type="text/template" id="menu-params">
<div>
<span class="icon-add unset-icon" data-operation="addIcon"><span><%=SystemEnv.getHtmlNoteName(4111, user.getLanguage())%></span><img></span><!--图标-->
<input type="text" placeholder="<%=SystemEnv.getHtmlLabelName(383593, user.getLanguage())%>"/> <!--菜单名称,多个菜单请点击+号添加-->
<span class="f-add" data-operation="addMenus"></span>
<span class="f-delete" data-operation="delParams"></span>
</div>
</script>
<script type="text/javascript">
// 传参 作为全局变量使用
var appid = "<%=appid%>";
var inputid = "<%=inputid%>";
var appHomepageId = "<%=appHomepageId%>";
var isTopMenu = "<%=topMenu%>" === "true";
var mec = top.require('mec');
var mecHandlers = {data:mec.getSortedMecHandlers()};
(function(){
// 常量
var MOBILE_FN = "Mobile_fn", // 最近使用 存放在localStorage中的关键字
NO_PARAMS = "noParams"; // 没有参数配置的函数所使用的公共模板html
var Common = null; // 供dataModel与template调用 dataModel,template仅能在common模块加载后调用
var Lang = null;
// 滚动条插件
var scroll = {
init: function(el) {
var $el = $(el);
if($el.hasClass("ps-container")) return this.update(el);
require(["perfect-scrollbar", 'css!ps_css'], function() {
$(el).perfectScrollbar({
wheelSpeed: 1,
wheelPropagation: true,
minScrollbarLength: 10,
theme: "lighter"
});
});
},
update: function(el) {
$(el).perfectScrollbar("update");
}
};
// 数据管理
var dataModel = {
cache: {},
functions: null,
get: function(modName) {
var cache = dataModel.cache,
mod = cache[modName];
if(mod) return $.Deferred().resolve(mod);
return false;
},
getAPIList: function() {
var APIList = dataModel.get("APIList");
if(APIList) return APIList;
return Common.api('api', {
action: "list",
type: "get",
}).then(function(res) {
var data = res.data;
data.map(function(val){
val.basic.name = Lang.parse(val.basic.name);
})
dataModel.cache.APIList = data;
return data;
});
},
getFunctions: function() { // 只调用一次
var that = this,
functions = {};
return Common.api("function", {
action: "list",
type: "get"
}, function(result) {
var data = result.data || [];
result.data.every(function(item){
if(item.categoryName == 'basic'){
var vardesc = {
id: 'vardesc',
desc: SystemEnv.getHtmlNoteName(6096),//系统内置了一些系统变量快捷获取方式,点击即可在编辑器中生成代码。
sign: SystemEnv.getHtmlNoteName(3641)//系统变量
};
item.items && item.items.splice(0, 0, vardesc);
return false;
}
return true;
});
data.forEach(function(category) {
category.items.forEach(function(item) {
functions[item.id] = item;
});
});
that.functions = functions;
});
},
getNavItems: function() {
var navItems = dataModel.get("navItems");
if(navItems) return navItems;
return Common.api('designer', {
action: "getNavPanelData",
type: "get",
data: { appid: appid }
}).then(function(res) {
var data = res.data;
dataModel.cache.navItems = data;
return data;
});
},
getMobileNSSnippet: function() {
return Common.api("function", {
action: "snippet",
type: "get"
});
},
getDataSources: function(fnid) {
var datasources = dataModel.get("datasources");
if(datasources) return datasources;
return Common.ajax({
url: Common.jionActionUrl("com.weaver.formmodel.mobile.servlet.MobileAppBaseAction", "action=getDataSource")
}, function(data) {
data = (data || []).map(function(datasource) {
return {
value: datasource,
text: datasource
};
});
// 添加local选项 并添加默认为空的选项 用来显示select的placeholder
data.unshift({value: "", text: ""}, {value: " ", text: "(local)"});
dataModel.cache.datasources = data;
});
},
getFormmodeModels: function() {
var formmodeModels = dataModel.get("formmodeModels");
if(formmodeModels) return formmodeModels;
return Common.api("formmode", {
action: "allmodelist",
type: "get"
}, function(result) {
var data = result.data || [];
data = data.map(function(item) {
return {
id: item.id,
text: item.name
};
});
data.unshift({id: "", text: ""});
dataModel.cache.formmodeModels = data;
});
},
getMsgTypeList: function () {
var navItems = dataModel.get("msgTypeList");
if(navItems) return navItems;
var messageGroupid = "15,18";
return Common.ajax({
url: Common.jionActionUrl("com.api.mobilemode.web.mobile.service.MsgAction", "action=getMsgTypeList"),
type: "get",
data: { "message_groupid": messageGroupid }
}).then(function (result) {
var list = result.data.list || [];
dataModel.cache.msgTypeList = list;
});
}
};
// 模板管理
window.template = {
cache: {},
sqls: ["sql"], // 需要选择数据源的插件
snippets: null,
currFnid: {},
defConfig: {// 存放元素.fn-config的高度和padding高度
height: 0,
padHeight: 0
},
mappings: {
"vardesc": "vardesc",
"$f": "$f",
"$p": "$p",
"$u_l_replace": "$u_l_replace",
"$u_r_replace": "$u_l_replace",
"$u": "$u",
"ajax": "ajax",
"alert": "alert",
"callMobile": "callMobile",
"confirm": "confirm",
"prompt": "prompt",
"createTopfloorPage": "createTopfloorPage",
"formSubmit": "formSubmit",
"formDelete": "formDelete",
"addDetailTableRow": "addDetailTableRow",
"openLBSPage": "openLBSPage",
"refresh": "refresh",
"refreshList": "refreshList",
"refreshCalendar": "refreshCalendar",
"refreshPrevPageList": "refreshPrevPageList",
"refreshRemind": "refreshRemind",
"refreshSpecifiedList": "refreshSpecifiedList",
"sendMessage": "sendMessage",
"sendEmobileMsg": "sendEmobileMsg",
"sendWechatMsg": "sendWechatMsg",
"sql": "sql",
"triggerRefresh": "triggerRefresh",
"triggerLazyLoad": "triggerLazyLoad",
"initWeather": "initWeather",
"callWebService": "callWebService",
"openMap": "openMap",
//"encrypt": "encrypt",
"getLayoutUrl": "getLayoutUrl",
"addFormmodeDataShare": "addFormmodeDataShare",
"msg": "msg",
"footerMenu": "footerMenu",
"dropDownMenu": "footerMenu",
"showLoader": "showLoader",
"toggleListData": "toggleListData",
"getListCheckedData": "getListCheckedData",
"switchListSelectable": "switchListSelectable",
"callApi": "callApi",
"$pluginLoad": "$pluginLoad",
"$d": "$d",
"openWebView": "openWebView",
"addEventListener" : "addEventListener"
},
plugins: { // 表单相关的插件
select: function($sels) {
var refs = ["select2", "css!select2_css"];
var language = (function getLanguage() {
switch (_userLanguage) {
case 7:
return "zh-CN";
case 8:
return "en";
case 9:
return "zh-TW";
default:
return "zh-CN";
}
}());
if (~language.indexOf("zh")) {
refs.push("select2-" + language);
}
require(refs, function() {
$sels.each(function(index, sel) {
var $sel = $(sel);
$sel.select2({
placeholder: $sel.data("placeholder") || " ", // 使用allowClear需要确保placeholder有值
language: language,
theme: "default select2-e9",
allowClear: true
});
});
});
},
urlSelector: function($container){
var eleid = $container.find("input")[0].id;
require(["utils"], function(_u) {
dataModel.getNavItems()
.then(function(data) {
_u.urlSelector(eleid, data);
});
});
}
},
get: function(fnid) {
var cache = this.cache,
mapping = this.mappings[fnid] || NO_PARAMS,
temp = this.cache[mapping];
if(temp) return $.Deferred().resolve(temp);
return $.get("./template/" + mapping + ".html", function(temp) {
cache[mapping] = temp;
});
},
getSnippets: function() {
if(template.snippets) return $.Deferred().resolve(template.snippets);
return dataModel.getMobileNSSnippet()
.then(function(result) {
template.snippets = {};
data = result.data || [];
data.forEach(function(item) {
template.snippets[item.id] = item;
});
return template.snippets;
});
},
calcHeight: function() { // 重新计算fn-config, scriptCode的高度
var $form = $(".temp-container").find("form"),
$pre = $("#example").find("pre"),
maxHeight = Math.max($pre.outerHeight(), $form.outerHeight() + $(".config-btn").outerHeight() );
if($('.function-wrapper').is(':hidden')){
maxHeight = $('.vardesc-container').find("form").outerHeight();
}
confHeight = maxHeight + template.defConfig.height;
$(".fn-config").height(confHeight);
$(".scriptCode").css("padding-top", confHeight + template.defConfig.padHeight);
// 重置编辑器的高度
setTimeout(function() {
editor.resize();
}, 300); // 动画时间
},
getDataSource: function() {
if(!~this.sqls.indexOf(this.currFnid)) return;
return dataModel.getDataSources;
},
initFormmode: function(el) {
dataModel.getFormmodeModels()
.then(function() {
require(["utils"], function(_u) {
_u.updateSelectSource(el, dataModel.cache.formmodeModels);
});
});
},
initMsgType: function(el) {
dataModel.getMsgTypeList()
.then(function() {
var html = dataModel.cache.msgTypeList.reduce(function(prev, item){
var optionName = item.sourcename + "(" + item.id + ")";
return prev += "<option value='" + item.id + "'>" + optionName + "</option>";
}, "<option value=''></option>");
el.html(html);
});
},
render: function(fnid) {
if(this.currFnid == fnid) return;
var that = this,
cache = this.cache,
mappings = this.mappings;
this.currFnid = fnid;
if(fnid == 'vardesc'){
this.get(fnid).then(function(data){
var mapping = mappings[fnid],
temp = cache[mapping];
var $temp = $(temp);
$temp.find('div.content-bar[language-id="'+_userLanguage+'"]').siblings('div.content-bar').remove();
//显示变量dom,隐藏函数dom
$(".function-wrapper").hide();
$(".vardesc-container").show().find('form').remove();
$(".vardesc-container").append($temp);
// 显示模板
$(".main").addClass("active");
$('.fn-config').css('margin-top','0px');
$(".config-shrink").addClass("config-down");
//重新计算高度
template.calcHeight();
});
} else {
this.get(fnid)
.then(this.getDataSource())
.then(dataModel.getAPIList)
.then(dataModel.getNavItems)
.then(function(data) {
var mapping = mappings[fnid] || NO_PARAMS,
temp = cache[mapping];
//显示函数dom,隐藏变量dom
$(".function-wrapper").show();
$(".vardesc-container").hide();
// 移除上一个函数的form
$(".temp-container").find("form").remove();
// 初始化函数模板
temp = Common.tempEngine(temp, {
items: data.nav_items || [],
mecHandlers: mecHandlers.data,
datasources: dataModel.cache.datasources,
APIList: dataModel.cache.APIList
});
// 将函数模板插入到dom中
$(temp).insertBefore($(".config-btn"));
// 显示模板
$(".main").addClass("active");
$('.fn-config').css('margin-top','0px');
$(".config-shrink").addClass("config-down");
// 初始化模板内的表单控件插件
var $form = $(".temp-container").find("form"),
$sels = $form.find("select"),
$urlSelector = $form.find(".url-selector");
$sels.length && template.plugins.select($sels);
$urlSelector.length && template.plugins.urlSelector($urlSelector);
// 当Form表单只有一个input框时,回车将会导致表单自动提交
$form.on("submit", function() { return false; });
})
.then(this.getSnippets)
.then(function(data) {
var snippet = data[fnid];
// 更新函数示例
$("#example").find("pre")[0].innerText = snippet.example;
// 计算高度
template.calcHeight();
// 更新函数title
$("#fn-title").text(snippet.id);
})
.then(function() { // 针对数据量较大的请求,在初始化dom之后采用data-xxx的形式render,
var $form = $(".temp-container").find("form");
if($form.find("[data-formmode]").length) { // getLayoutUrl与 addFormmodeDataShare函数
that.initFormmode($form.find("[data-formmode]"));
}
if($form.find("[data-msgtype]").length) { // sendMessage函数
that.initMsgType($form.find("[data-msgtype]"));
}
});
}
}
};
// 初始化编辑器
var defer = top.$ && top.$.Deferred();
require(['htmlEditor'], function(htmlEditor) {
var scriptCode = document.querySelector('#scriptCode');
var val = top.scriptCodeFun && top.scriptCodeFun() || "";
window.editor = htmlEditor.editor('scriptCode', 'javascript', ['Mobile_NS']);
editor.setValue(val, true);
scriptCode.style.visibility = "visible";
defer && defer.resolve(window.editor);
});
window.getEditor = function(cb) {
defer && defer.then(function(editor) {
cb && cb(editor, window);
});
};
// 初始化快捷键
var appdesigner = top.appdesigner;
var canInitMenu = appdesigner && isTopMenu;
require(["shortcut"], function(shortcut) {
var handler = onOK;
if(canInitMenu) {
handler = appdesigner.save;
}
shortcut.init({
container: document,
shortcuts: {
"ctrl+s": {
preventDefault: true,
handler: handler
}
}
});
})
// 供外部调用 重新刷新当前菜单
window.renderRightMenu = function() {
if(canInitMenu) {
require(['contextMenu'], function (contextMenu) {
appdesigner.rightMenu(document.body, contextMenu, true);
});
}
}
require(['components/common','i18n/lang'], function(common,lang) {
var $funcs = $(".funcs"),
funcs = [],
store = common.store;
Common = common; // 供外部调用
Lang = lang;
//初始化config默认高度值
var $fnConfig = $(".fn-config");
template.defConfig = {
height: 38,
padHeight: $fnConfig.outerHeight() - $fnConfig.height()
};
// 为fn-config绑定calcHeight,可供外部或模板内调用
$fnConfig.on("calcHeight", template.calcHeight);
// 初始化函数滚动条
scroll.init(".tab-panel");
// 初始化函数列表
dataModel.getFunctions()
.then(function(result) {
var temp = $("#fn-temp").html();
funcs = result.data || funcs;
temp = common.tempEngine(temp, funcs);
$funcs = $funcs.html(temp);
});
// 初始化函数关键字模板
template.getSnippets();
// 初始化最近使用列表
var renderRecently = function() {
var mobile_fn = store.get(MOBILE_FN);
var temp = $("#fn-desc").html();
if(!mobile_fn) return;
mobile_fn = JSON.parse(mobile_fn)
temp = common.tempEngine(temp, mobile_fn.recently.data);
$(".recently").html("<ul class='fn-list'>" + temp + "</ul>");
};
renderRecently();
// 函数tab事件
$('.fn-tabs').on("click", "li", function() {
var $tab = $(this),
tab = $tab.data("tab");
if($tab.hasClass("selected")) return;
$tab.addClass("selected").siblings('.selected').removeClass("selected");
$(".tab-panel[data-rel=" + tab + "]").addClass("active").siblings(".tab-panel").removeClass("active");
!$tab.hasClass(".funcs") && renderRecently(); // 切换至最近使用时, 更新该列表
});
// 函数搜索
$("#fn-input").on("input", function() {
var val = $(this).val().toLowerCase(),
$funcs = $(".funcs");
// 显示del按钮
$(this).siblings(".input-del").toggleClass("hide", !val);
// 过滤函数列表
$funcs.find("li[fnid]").each(function() {
var $li = $(this),
ismatch = !!~$li.text().toLowerCase().indexOf(val),
$category = $li.parents(".fn-category");
$li.toggleClass("hide", !ismatch); // 当切换tab时 使用toggle会导致fn-category出现问题
ismatch && $category.removeClass("hide");
});
// 隐藏不匹配的函数类型
$funcs.find(".fn-category").each(function() {
var $category = $(this),
isAllHidden = $category.find(".hide").length == $category.find("li").length;
$category.toggleClass("hide", isAllHidden);
isAllHidden && $category.find(".fixed").removeClass("fixed");
});
// 为第一个显示分类的标题添加fixed, 防止样式错乱
$funcs.find(".fn-category:not(.hide)").eq(0).find("label").addClass("fixed");
// 更新滚动条
scroll.update(".tab-panel");
})
// 清空搜索框事件
.siblings(".input-del")
.on("click", function() {
$(this).addClass("hide") // 隐藏del按钮
.siblings("input").val("") // 重置search框的值
.trigger("input"); // 触发input事件
});
// 函数选择
$(".panel-wrapper").on("click", "li", function() {
var $li = $(this),
fnid = $li.attr("fnid"),
mobile_fn = store.get(MOBILE_FN), recently;
if($li.hasClass("selected")) {
return template.render(fnid);
}
if(mobile_fn) {
mobile_fn = JSON.parse(mobile_fn);
} else {
mobile_fn = {
recently: { data: [], ids: [] }
};
}
$(".panel-wrapper").find("li.selected").removeClass("selected");
$li.addClass("selected");
recently = mobile_fn.recently;
template.render(fnid);
var index = recently.ids.indexOf(fnid);
if(~index) { // 将已存在的函数移除
recently.data.remove(index);
recently.ids.remove(index);
}
// 将函数添加至最近使用中的第一个
recently.data.unshift(dataModel.functions[fnid]);
recently.ids.unshift(fnid);
// 只保持最近10条记录
recently.ids.remove(10);
recently.data.remove(10);
store.set(MOBILE_FN, JSON.stringify(mobile_fn));
});
// 函数类型滚动切换
$funcs.scroll(function() {
var $funcs = $(this),
top = parseInt($funcs.offset().top);
$funcs.find(".fn-category").each(function(index, category) {
var $category = $(category),
$label = $category.find('label'),
sTop = parseInt($category.offset().top);
$label.toggleClass("fixed", sTop <= top);
});
});
// 生成代码
$(".config-btn").find("button").on("click", function() {
var data = {},
fnid = template.currFnid;
$(".temp-container").find(".fgroup").each(function(){
var $fgroup = $(this),
prop = $fgroup.attr("data-prop"), val;
$control = $fgroup.find("input[type=radio], input[type=checkbox]");
if ($control.length > 1) {
$control = $fgroup.find(":checked");
} else {
$control = $fgroup.find("input, select, textarea");
}
if (!$control.length) return;
var params = $fgroup.data("params");
if (params) {
var keys = [], values = [];
params = String(params).toLowerCase();
var isString = params == "string"; // 默认为json格式
var isArray = params == "array";
val = isString ? "" : isArray ? [] : {};
$control = $fgroup.find(".f-params:visible").find("input");
var $icons = $fgroup.find(".f-params .icon-add").find("img");
var hasIcon = !!$icons.length;
$control.each(function (index) {
var value = $(this).val();
if (isArray){
var obj = value;
if(hasIcon){
obj = {
icon:$($icons[index]).attr('src')||'',
text:value||''
}
}
return val.push(obj);
}
if (index % 2) return values.push(value);
keys.push(value);
});
keys.forEach(function (key, index) {
if (!key || !values[index]) return;
if (!isString) return (val[key] = values[index]);
val += key + "=" + values[index] + ";";
});
val = isString ? val.replace(/;$/, "") : isArray ? val : JSON.stringify(val);
val = val == "{}" ? "" : val;
} else {
val = $control.val();
val = (val === null ? "" : val).replace(/\n/g, " "); // 将多行文本的回车替换为空格
}
data[prop] = val;
});
template.getSnippets()
.then(function(snippets){
var snippet = snippets[fnid];
insertScriptCode(common.tempEngine(snippet.template, data));
});
});
// 收缩函数列表
$(".arrow").on("click", function() {
$(".wrapper").toggleClass("toggle");
$(this).toggleClass("right");
setTimeout(function() { // 动画
window.editor && window.editor.resize();
}, 250);
});
// 收缩函数配置和函数示例
$(".config-shrink").on("click", function() {
var $this = $(this),
$config = $(".fn-config"),
height = $config.outerHeight();
if($this.hasClass('config-down')){
$this.removeClass('config-down');
template.calcHeight();
$config.css('margin-top','-'+height+'px');
$(".scriptCode").css("padding-top", '10px');
}else{
$this.addClass('config-down');
$config.css('margin-top','0px');
template.calcHeight();
}
});
// 模板内公共操作的回调
var operations = {
add: function(tmplId){
var $opEl = $(this),
$parent = $opEl.parent(),
temp = $("#"+tmplId).html();
$(temp).insertAfter($parent);
},
addParams: function() {
operations.add.call(this, "fn-params");
},
delParams: function() {
$(this).parent().remove();
},
addMenus: function(){
operations.add.call(this, "menu-params");
},
addIcon: function(){
var $img = $(this).find('img');
top.showPicsetModal($img.attr('src')?"pic_path="+$img.attr('src'):'',function(res){
var imgpath = res["pic_path"];
$img.attr('src',imgpath).parent()[imgpath ? 'removeClass':'addClass']('unset-icon');
});
}
};
// 为模板绑定公共的操作事件
$(".main").on("click.operation", "[data-operation]", function() {
var operation = $(this).data("operation"),
cb = operations[operation];
cb && cb.call(this);
template.calcHeight();
});
});
})();
// 用于判断模板内mec插件类型
var mecHelper = {
cache: {
lists: {} // 页面插件列表
},
isForm: function(mecType) {
return "Form" == mecType;
},
isWeather: function(mecType) {
return "Weather" == mecType;
},
isRemind: function(mecType) {
return ~["Navigation", "Toolbar", "NavPanel", "Tab", "TabBar", "SegControl", "FloatButton"].indexOf(mecType);
},
isList: function(mecType) {
return ~["List", "UrlList", "APIList", "Timelinr", "NTimeline", "GridTable", "UrlGridTable", "HoriList", "NHoriList", "RSSList", "LargeList", "NLargeList", "NList", "NGridTable"].indexOf(mecType);
},
isParamsOnly: function(mecType) {
return ~["List","Timelinr", "GridTable"].indexOf(mecType);
},
formatName: function(mecHandler) {
var name = mecHandler.name,
typeName = mecHandler.typeName;
return name ? name + " [" + typeName + "]" : typeName;
},
getMecsByPageid: function(pageid, isType) {
var that = this,
common = require("components/common"),
currFnid = $(".panel-wrapper").find("li.selected").attr("fnid"),
lists = this.cache.lists, mecs;
lists[currFnid] = lists[currFnid] || {};
var mecs = lists[currFnid];
var formatData = function(data) {
return data.map(function(mecHandler) {
var mecparam = mecHandler.mecparam || mecHandler;
if(!isType || !isType(mecHandler.type)) return;
mecHandler.name = mecparam.formname || mecparam.name;
return {
id: mecHandler.id,
type: mecHandler.type,
text: that.formatName(mecHandler)
};
}).filter(function(mecHandler){
if(mecHandler) return mecHandler;
});
};
if(mecs[pageid]) return $.Deferred().resolve(mecs[pageid]);
if(pageid == appHomepageId) {
mecs[pageid] = formatData(mecHandlers.data);
return $.Deferred().resolve(mecs[pageid]);
}
return common.api("designer", {
action: "getPageComponents",
data: {id: pageid},
type: "get"
}).then(function(result) {
var data = result.data || [];
mecs[pageid] = formatData(data);
return mecs[pageid];
});
},
resetSelectSource: function(select, data) {
require(["utils"], function(_u) {
_u.updateSelectSource(select, data);
});
},
getFormFields: function(params) {
var common = require("components/common");
return common.ajax({
url: "/api/mobilemode/admin/designer/plugin/getFieldsByTable",
data: {
datasource: params.datasource,
tablename: params.tablename,
formType: params.formtype,
workflowId: params.workflowid
},
type: "get"
}).then(function(result) {
var data = (result.data || []).map(function(item) {
return {
id: item.column_name,
text: item.column_name
};
});
data.unshift({id: "", text: ""});
return data;
});
}
};
function getScriptCode(){
return editor.getValue();
}
function insertScriptCode(val) {
editor.insertSnippet(val);
}
function returnResult(inputid){
if(top && top.callTopDlgHookFn){
var result = {
"scriptCode" : getScriptCode()
};
top.callTopDlgHookFn(result,inputid);
}
// onCancel();
}
function onOK(){
returnResult(inputid);
}
function onCancel(){
top.closeTopDialog(inputid);
}
function onFunctionCancel () {
var codeObj = judgeCode();
var newCode = codeObj.newCode;
var oldCode = codeObj.oldCode;
var onOK = codeObj.onOK;
var onCancel = codeObj.onCancel;
var modal = top.require('modal');
var btnSave = SystemEnv.getHtmlNoteName(3515); //保存
var btnCancel = SystemEnv.getHtmlNoteName(3516); //取消
if (newCode !== oldCode) {
return modal.confirm(SystemEnv.getHtmlNoteName(6338), {
btn: [btnSave, btnCancel]
}, function(index) {
onOK();
modal.close(index);
}, onCancel);
}
onCancel();
}
function judgeCode () {
var oldValue = top.scriptCodeFun && top.scriptCodeFun() || "";
var newValue = getScriptCode();
return {
newCode: newValue,
oldCode: oldValue,
onOK: onOK,
onCancel: onCancel
}
}
window.onOK = onOK;
window.onFunctionCancel = onFunctionCancel;
</script>
</body>
</html>