sourcePanel.js
27 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
define('sourcePanel', ['components/common', 'utils', 'jquery'], function(common, utils){
var _customSearchList = [];
var template = function(id){
var htm = '';
htm += '<div class="row">';
htm += '<span class="col-2 span-control">'+ SystemEnv.getHtmlNoteName(4144) +'</span>'; //内容来源:
htm += '<div class="col-m-8">';
htm += '<select class="form-control" name="sourceType">';
htm += '<option value="1">'+SystemEnv.getHtmlNoteName(6100)+'</option>'; //建模查询
htm += '<option value="2">'+SystemEnv.getHtmlNoteName(6001)+'</option>'; //模拟数据
htm += '<option value="3">SQL</option>'; //SQL
htm += '<option value="4">Url</option>'; //Url
htm += '<option value="5">'+SystemEnv.getHtmlNoteName(5268)+'</option>'; //接口
htm += '</select>';
htm += '</div>';
htm += '</div>';
htm += '<div data-sourceType="1">';//建模查询
htm += '<div class="row">';
htm += '<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(6101)+'</span>'; //建模查询:
htm += '<div class="col-m-8 required">';
htm += '<select class="form-control requireded" name="customSearch"></select>';
htm += '</div>';
htm += '</div>';
htm += '</div>';
htm += '<div data-sourceType="2" style="display:none;">';//模拟数据
htm += '<div class="row">';
htm += '<div class="col-2 span-control">' + SystemEnv.getHtmlNoteName(6002) + '</div>';//模拟数据:
htm += '<div class="col-m-8 required">';
htm += '<div class="col edit-before pd-72" style="width: 20px;text-align:left;"></div>';
htm += '<div class="col ml-5 pd-7 link mockData_tip" style="display:none;">'+SystemEnv.getHtmlNoteName(4162)+'</div>'; //已配置
htm += '<input name="mockData" type="hidden" value=""/>';
htm += '</div>';
htm += '</div>';
htm += '</div>';
htm += '<div data-sourceType="3" style="display:none;">';//sourceSql
htm += '<div class="row">';
htm += '<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4201)+'</span>'; //数据源:
htm += '<div class="col-m-8">';
htm +='<select class="form-control" name="datasource">';
htm +='<option value="$ECOLOGY_SYS_LOCAL_POOLNAME">(local)</option>';
htm +='</select>';
htm += '</div>';
htm += '</div>';
htm += '<div class="row">';
htm += '<span class="col-2 span-control" style="vertical-align: top;">SQL:</span>';
htm += '<div class="col-m-8 required" style="position:relative;">';
htm += '<textarea name="sourceSql" class="area-control requireded" placeholder="'+SystemEnv.getHtmlNoteName(4380)+'"></textarea>'; //请在此处键入SQL
htm += '<div class="helper" for="sql">?</div>';
htm += '</div>';
htm += '</div>';
htm += '</div>';
htm += '<div data-sourceType="4" style="display:none;">';//url
htm += '<div class="row" style="position: relative;margin-bottom:0;">';
htm += '<span class="col-2 span-control">Url:</span>'; //Url
htm += '<div class="col-m-8 inline-icons required">';
htm += '<input type="text" name="sourceUrl" class="form-control requireded" />';
htm += '<div class="helper" for="url" style="top:9px;">?</div>';
htm += '</div>';
htm += '</div>';
htm += '<div class="row" style="position: relative;">';
htm += '<span class="col span-control pd-0"> </span>';
htm += '<div class="col-m-8">';
htm += '<div style="text-align:right;">';
htm += '<a class="download-template help-link inline">'+SystemEnv.getHtmlNoteName(4288)+'</a>'; //下载模板
htm += '<a class="init-template help-link inline">'+SystemEnv.getHtmlNoteName(4289)+'</a>'; //使用模板
htm += '</div>';
htm += '</div>';
htm += "</div>"
htm += '</div>';
htm += '<div data-sourceType="5" style="display:none;">';//接口
htm += '<div class="row">';
htm += '<div class="col-2 span-control">' + SystemEnv.getHtmlNoteName(6102) + '</div>';//接口:
htm += '<div class="col-m-8 required">';
htm += '<div class="col edit-before pd-72" style="width: 20px;text-align:left;"></div>';
htm += '<div class="col ml-5 pd-7 link selectApi_tip"></div>';
htm += '<input name="api" type="hidden" value=""/>';
htm += '</div>';
htm += '</div>';
htm += '</div>';
htm += '<div class="urltype-container">';
htm += '<div class="row">';
htm += '<span class="col-2 span-control">' + SystemEnv.getHtmlNoteName(4145) + '</span>'; //数据链接:
htm += '<div class="col-m-8"><select class="form-control" name="urltype">';
htm += '<option value="0">'+SystemEnv.getHtmlNoteName(4146)+'</option>'; //自动解析
htm += '<option value="1">'+SystemEnv.getHtmlNoteName(4147)+'</option>'; //手动输入
htm += '</select>';
htm += '</div>';
htm += '</div>';
htm += '</div>';
htm += '<div class="dataurl-container">';
htm += '<div class= "row" style="position: relative;">';
htm += '<span class="col-2 span-control">' + SystemEnv.getHtmlNoteName(3977) + '</span>'; //链接地址:
htm += '<div class="dataurl-input sbHolder" >';
htm += '<a href="javascript:void(0);" class="sbToggle sbToggle-btc"></a>';
htm += '<input class="panel-input" type="text" readonly="readonly" unselectable="on" autocomplete="off"/>';
htm += '<input id="sourcePanel_dataurl_'+id+'" type="hidden" name="dataurl" />';
htm += '</div>';
htm += "</div>";
htm += "</div>";
return htm;
};
var defData = {
sourceType: "1",
urltype: "0",
mockData: "",
sourceSql: "",
sourceUrl: "",
apiConfig: {
api: {},
params: {
query: [],
body: {}
}
}
};
var hideError = function(val, $obj){
if(val){
$obj.removeClass('required has-error').children('.error-tip').hide();
}else {
$obj.addClass('required has-error').children('.error-tip').show();
}
};
var SP = function(options){
var t = this;
t.id = options.id = "sp_" + options.id;
t.type = options.type || 'list';
t.el = options.el;
t.data = $.extend({}, defData, options.data);
t.callback = options.callback || {};
t.target = null; // 源目标
t.initialize = false;
t.render();
return t;
};
SP.pt = SP.prototype;
SP.pt.create = function(){
var sp = this;
sp.el.empty().html(template(sp.id));
sp.el.find('select').niceSelect();
//utils.urlSelector('sourcePanel_dataurl_'+sp.id);
sp.$ = {};
sp.$.sourceType = sp.el.find("select[name='sourceType']")
sp.$.customSearch = sp.el.find("select[name='customSearch']");
sp.$.mockData = sp.el.find("input[name='mockData']");
sp.$.datasource = sp.el.find("select[name='datasource']");
sp.$.sourceSql = sp.el.find("textarea[name='sourceSql']");
sp.$.sourceUrl = sp.el.find("input[name='sourceUrl']");
sp.$.api = sp.el.find("input[name='api']");
sp.$.urltype = sp.el.find("select[name='urltype']");
sp.$.dataurl = sp.el.find("input[name='dataurl']");
sp.$urltypeWrp = sp.el.find(".urltype-container"),
sp.$dataurlWrp = sp.el.find(".dataurl-container"),
sp.$mockDataTip = sp.el.find(".mockData_tip"),
sp.$apiTip = sp.el.find(".selectApi_tip")
return sp;
};
SP.fn = {
sourceTypeChange: function(sourceType){
var sp = this;
sp.el.find('div[data-sourceType]').hide();
sp.el.find('div[data-sourceType="'+sourceType+'"]').show();
var isCustomSearch = sourceType == "1",
urltype = sp.$.urltype.val();
sp.$urltypeWrp[isCustomSearch ? "show" : "hide"]();
SP.fn.urltypeChange.call(sp, urltype, sourceType, true);
SP.fn.customSearchChange.call(sp, sourceType);
sp.callback && typeof(sp.callback.sourceTypeChange) == 'function' && sp.callback.sourceTypeChange(sourceType);
},
sourceValueChange: function(options){
var sp = this;
sp.callback && typeof(sp.callback.sourceValueChange) == 'function' && sp.callback.sourceValueChange(options);
},
customSearchChange: function(sourceType, searchid){
var sp = this;
if(!searchid) searchid = sp.$.customSearch.val();
var $option = sp.$.customSearch.find("option[value='"+searchid+"']");
if(!$option.length) return;
var modeid = $option.data("modeid"),
hasRelateMode = !!modeid && modeid != "0",
urltype = sp.$.urltype.val();
sp.$urltypeWrp[sourceType == "1" && hasRelateMode ? "show" : "hide"]();
SP.fn.urltypeChange.call(sp, urltype, sourceType, hasRelateMode);
},
getSearchOption: function(searchid){
for(var i = 0; i < _customSearchList.length; i++ ){
if(_customSearchList[i].id == searchid)return _customSearchList[i];
}
},
setSearchOption: function(sp, item){
item && sp.$.customSearch.empty().append('<option value="'+item.id+'" selected data-modeid="'+item.modeid+'" data-unreadbadge="'+item.unreadBadge+'">'+item.showname+'</option>');
!item && sp.$.customSearch.empty().append('<option value="" data-modeid="-1"></option>');
},
initDefaultUrlTemplate: function(){
var sp = this;
sp.callback && typeof(sp.callback.initDefaultUrlTemplate) == 'function' && sp.callback.initDefaultUrlTemplate();
},
urltypeChange: function(urltype, sourceType, hasRelateMode){
var sp = this;
sp.$dataurlWrp[urltype == "0" && sourceType == "1" && hasRelateMode ? "hide" : "show"]();
},
editMockData: function(){
var sp = this;
top.mockJsonData = sp.$.mockData.val();
var url = "/mobilemode/admin/dialog/jsonConfig.jsp";
var dlg = top.createTopDialog();//获取Dialog对象
var hgt = $(document.body).height(),
wdh = $(document.body).width();
dlg.Width = wdh*0.6;//定义长度
dlg.Height = hgt*0.8;
dlg.Model = true;
dlg.normalDialog = false;
dlg.URL = url;
dlg.Title = SystemEnv.getHtmlNoteName(6003); //模拟数据配置
dlg.show();
dlg.hookFn = function(result){
var mockData = result["scriptCode"] || "";
sp.$.mockData.val(mockData);
var trimVal = mockData.trim();
sp.$mockDataTip[trimVal ? "show" : "hide"]();
hideError(trimVal, sp.$.mockData.closest(".col-m-8"));
};
},
editApiConfig: function(){
var sp = this;
var apiConfig = sp.data.apiConfig;
utils.openRcDialog("api-config", {
title: SystemEnv.getHtmlNoteName(5239).replace(/[::]/g, ""),//接口配置
params: {
id: apiConfig.api.id||"",
config: apiConfig,
height: 506
}
}, function(result) {
sp.data.apiConfig = result;
var selectApi = result.api || {};
var selectApiId = selectApi.id,
selectApiName = selectApi.name;
hideError(selectApiId, sp.$.api.closest(".col-m-8"));
var lastSourceValue = sp.$apiTip.data("last");
if(!selectApiId || selectApiId === lastSourceValue) return;
sp.$apiTip.data("last", selectApiId).html(selectApiName);
utils.api('api', {
action: "info",
type: "get",
data: {
"id": selectApiId
}
}).then(function (apiResult) {
apiResult = apiResult.data;
var resultDefine = apiResult.resultDefine || [];
var getOutFormat = function(){
//结果定义(输出参数)
var keyMap = {};
resultDefine.forEach(function(ele) {
var resultKey = ele.name || "";
if(resultKey.indexOf(".") === -1){
if(ele.type === "ARRAY"){
!keyMap.DATAS && (keyMap.DATAS = resultKey);
}
if(ele.type === "NUMBER"){
!keyMap.TOTAL_SIZE && (keyMap.TOTAL_SIZE = resultKey);
}
}
});
return keyMap;
};
SP.fn.sourceValueChange.call(sp, getOutFormat());
});
});
}
}
SP.pt.events = function(){
var sp = this, data = sp.data;
//数据来源
sp.$.sourceType.on("change", function(){
SP.fn.sourceTypeChange.call(sp, $(this).val());
sp.loadFields();
});
sp.$.customSearch.on("change", function(){
var searchid = sp.$.customSearch.val() || "",
item = SP.fn.getSearchOption(searchid);
SP.fn.setSearchOption(sp, item);
SP.fn.customSearchChange.call(sp, sp.$.sourceType.val(), $(this).val());
sp.callback && typeof(sp.callback.customSearchChange) == 'function' && sp.callback.customSearchChange.call(sp, sp.$.sourceType.val(), $(this));
sp.loadFields();
});
//模拟数据点击事件
sp.el.find("div[data-sourceType='2']").on("click", ".edit-before, .mockData_tip", function(e){
SP.fn.editMockData.call(sp);
e.stopPropagation();
});
sp.$.datasource.on("change", function(){
SP.fn.sourceValueChange.call(sp, {sqlChange: true});
});
sp.$.sourceSql.on("change", function(){
SP.fn.sourceValueChange.call(sp, {sqlChange: true});
});
//url下载模板
sp.el.find("div[data-sourceType='4']").on("click", ".download-template", function(e){
var type = sp.type;
switch (type) {
case 'timeline':
location.href = '/api/mobilemode/admin/designer/plugin/downloadTemplate?template=timelineUrlTempletAction.jsp';
break;
case 'list':
default:
location.href = '/api/mobilemode/admin/designer/plugin/downloadTemplate?template=listUrlTempletAction.jsp';
break;
}
e.stopPropagation();
});
//url初始化模板
sp.el.find("div[data-sourceType='4']").on("click", ".init-template", function(e){
var type = sp.type;
switch (type) {
case 'timeline':
sp.$.sourceUrl.val("/mobilemode/actiontemplet/timelineUrlTempletAction.jsp").trigger('change');
break;
case 'list':
default:
sp.$.sourceUrl.val("/mobilemode/actiontemplet/listUrlTempletAction.jsp").trigger('change');
break;
}
SP.fn.initDefaultUrlTemplate.call(sp);
e.stopPropagation();
});
//选择接口绑定事件
sp.el.find("div[data-sourceType='5']").on("click", ".edit-before, .selectApi_tip", function(e){
SP.fn.editApiConfig.call(sp);
e.stopPropagation();
});
//数据链接
sp.$.urltype.on("change", function(){
SP.fn.urltypeChange.call(sp, $(this).val(), sp.$.sourceType.val(), true);
});
sp.el.find('.dataurl-container').on("click",".sbHolder",function (e) {
showUrlSelectPanel(this);
e.stopPropagation();
});
require(["modal"], function(modal) {
var indexArr = [], type = sp.type, sqlTip, urlTip, tipWidth;
switch (type) {
case 'timeline':
tipWidth = '250px';
sqlTip = SystemEnv.getHtmlNoteName(6340);//sql语句如未明确指定order by,则查询列必须包含id字段(默认按id降序排序)
urlTip = SystemEnv.getHtmlNoteName(6126).replace("#directory#", "/mobilemode/apps") + "<br/>"//1、存放位置:如果url为一个系统内部jsp必须放在/mobilemode/apps目录下
+ SystemEnv.getHtmlNoteName(6127) + "<br/>"//2、url可以接收参数:
+ "pageNo("+SystemEnv.getHtmlNoteName(4298)+", "+SystemEnv.getHtmlNoteName(6128)+"{page_no})" + "<br/>"// 4298 当前页 6128 对应变量名
+ "pageSize("+SystemEnv.getHtmlNoteName(4299)+", "+SystemEnv.getHtmlNoteName(6128)+"{page_size})" + "<br/>"// 4299 每页显示大小 6128 对应变量名
+ SystemEnv.getHtmlNoteName(6129);//可以在后台代码中使用以上名称去接收列表插件传递过来的参数,同时,如果你需要自定义参数名称,比如当前页 后台代码使用的是 pageNumber来接收的,那么你可以在url上传递参数pageNumber, 参数值使用当前页对应的变量名即可,如xxx?pageNumber={page_no},这样,后台就可以使用名称pageNumber而非pageNo来接收当前页参数了
break;
case 'list':
default:
tipWidth = '500px';
sqlTip = SystemEnv.getHtmlNoteName(6098) + "<br/>"//1、sql语句如未明确指定order by,则查询列必须包含id字段(默认按id降序排序)
+ SystemEnv.getHtmlNoteName(6099).replace("#exampleSql#", "select * from t where a=1 {searchCondition} and b=2");//2、搜索时系统会自动拼接快捷搜索查询条件到sql语句中,若查询出现异常,可在sql语句中使用{searchCondition}占位符手动拼接,以确保sql正确执行,示例:#exampleSql#(注意:占位符前面需加条件,若无条件,可用1=1代替)";
urlTip = SystemEnv.getHtmlNoteName(6126).replace("#directory#", "/mobilemode/apps") + "<br/>"//1、存放位置:如果url为一个系统内部jsp必须放在/mobilemode/apps目录下
+ SystemEnv.getHtmlNoteName(6127) + "<br/>"//2、url可以接收参数:
+ "pageNo("+SystemEnv.getHtmlNoteName(4298)+", "+SystemEnv.getHtmlNoteName(6128)+"{page_no})" + "<br/>"// 4298 当前页 6128 对应变量名
+ "pageSize("+SystemEnv.getHtmlNoteName(4299)+", "+SystemEnv.getHtmlNoteName(6128)+"{page_size})" + "<br/>"// 4299 每页显示大小 6128 对应变量名
+ "searchKey("+SystemEnv.getHtmlNoteName(4300)+", "+SystemEnv.getHtmlNoteName(6128)+"{search_key})" + "<br/>"// 4300 查询参数 6128 对应变量名
+ SystemEnv.getHtmlNoteName(6129);//可以在后台代码中使用以上名称去接收列表插件传递过来的参数,同时,如果你需要自定义参数名称,比如当前页 后台代码使用的是 pageNumber来接收的,那么你可以在url上传递参数pageNumber, 参数值使用当前页对应的变量名即可,如xxx?pageNumber={page_no},这样,后台就可以使用名称pageNumber而非pageNo来接收当前页参数了
break;
}
sp.el.find(".helper").on("click", function(e) {
indexArr.push(modal.tips($(this).attr("for") == 'sql' ? sqlTip : urlTip, $(this), {
area: [tipWidth, ''],
placement: "left"
}));
e.stopPropagation();
});
$("body").on("click", function(e) {
var $target = $(e.target);
var layero = $target.parents(".layui-layer-tips");
if(layero.length) return;
indexArr.map(function (v) {
modal.close(v);
});
});
});
return sp;
};
SP.pt.loadFields = function(hideNotification){
var sp = this,
sourceType = sp.$.sourceType.val() || "",
datasource = sourceType == "3" ? sp.$.datasource.val() || "" : "",
sourceSql = sourceType == "3" ? sp.$.sourceSql.val() || "" : "",
searchid = sourceType == "1" ? sp.$.customSearch.val() || "" : "";
if(!sp.initialize){
datasource = sp.data.datasource || "";
searchid = sp.data.searchid || "";
}
var callback = function(sourceFields){
sp.callback && typeof(sp.callback.sourceFieldsLoaded) == 'function' && sp.callback.sourceFieldsLoaded(sourceType, sourceFields);
};
if(sourceType == "1" && searchid){
if(sps.searchFieldsMap[searchid]){
callback(sps.searchFieldsMap[searchid]);
return;
}
utils.api("designer/plugin", {
action: "getSourceFields",
notification: !hideNotification,
type: 'POST',
data: {
source: sp.$.sourceType.val(),
searchid: searchid,
datasource: compressByLZ(datasource),
sql: compressByLZ(sourceSql)
}
}, function (result) {
var sourceFields = result.data || [];
if(sourceFields.length && sourceType == "1"){
sps.searchFieldsMap[searchid] = sourceFields;
}
callback(sourceFields);
}, function(){
callback([]);
});
}else{
callback([]);
}
},
SP.pt.initData = function(){
var sp = this, data = sp.data;
//sourceType
sp.$.sourceType.val(data.sourceType);
//mockData
sp.$.mockData.val(data.mockData);
sp.$mockDataTip[data.mockData ? "show" : "hide"]();
//sourceSql
sp.$.sourceSql.val(data.sourceSql);
//sourceUrl
sp.$.sourceUrl.val(data.sourceUrl);
//apiConfig
var api = data.apiConfig.api;
sp.$apiTip.data("last", api.id || "").html(api && api.name ? api.name : "");
//urltype
sp.$.urltype.val(data.urltype);
//dataurl
sp.$.dataurl.val(data.dataurl);
UrlSelectUtil.link.setUrlLink( sp.$.dataurl.parent(),data.dataurl);
var getSearchList = function(defSearchid){
//建模查询
return utils.api("designer/plugin", {
action: "getCustomSearchList",
notification: false,
data: {}
}, function (result) {
_customSearchList = result.data;
var items = result.data.reduce(function(prev, item){
if(item.id == defSearchid){
sp.$.customSearch.empty().append('<option value="'+item.id+'" selected data-modeid="'+item.modeid+'" data-unreadbadge="'+item.unreadBadge+'">'+item.showname+'</option>');
}
prev.push({
id: item.id,
text: item.showname
});
return prev;
}, []);
sp.$.customSearch.removeAttr('disabled').niceSelect({
pagination: true,
datas: items,
pageSize: 200
})
});
},
getDataSource = function(defDatasource){
//数据源
return utils.api("designer/plugin", {
action: "getDatasource",
notification: false,
data: {}
}, function (result) {
var html = result.data.reduce(function(prev, next){
return prev += '<option value="'+next+'" '+(defDatasource == next ? "selected" : "")+'>'+next+'</option>';
}, '<option value="$ECOLOGY_SYS_LOCAL_POOLNAME">(local)</option>');
sp.$.datasource.html(html);
});
};
$.when(getSearchList(sp.data.searchid), getDataSource(sp.data.datasource)).then(function(){
SP.fn.customSearchChange.call(sp, data.sourceType, sp.data.searchid);
sp.initialize = true;
});
return sp;
};
SP.pt.render = function(){
return this.create().events().initData();
};
SP.pt.mounted = function(){
var sp = this, data = sp.data;
SP.fn.sourceTypeChange.call(sp, data.sourceType);
sp.loadFields();
return sp;
};
SP.pt.getData = function(){
var sp = this,
data = sp.data;
if(sp.initialize){
data = {
sourceType: sp.$.sourceType.val() || "",
searchid: sp.$.customSearch.val() || "",
mockData: sp.$.mockData.val(),
datasource: sp.$.datasource.val() || "",
sourceSql: sp.$.sourceSql.val(),
sourceUrl: sp.$.sourceUrl.val(),
apiConfig: sp.data.apiConfig,
urltype: sp.$.urltype.val() || "",
dataurl: sp.$.dataurl.val()
}
var $option = sp.$.customSearch.find("option[value='"+data.searchid+"']");
data.modeid = $option.data("modeid");
}
return data;
};
var sps = {
searchFieldsMap: {},
setSP: function (sp) {
this[sp.id] = sp;
if(sp.data.sourceType == "1") !sp.data.searchid && SP.fn.setSearchOption(sp);
},
getSP: function (id) {
return this["sp_" + id];
}
};
return {
run: function(options){
var sp = new SP(options);
sps.setSP(sp);
sp.mounted();
},
getData: function(id){
var sp = sps.getSP(id);
return sp.getData();
},
getInstance: function(id){
return sps.getSP(id);
}
}
});