DataSet_wev8.js
15 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
if(typeof(MEC_NS) == 'undefined'){
MEC_NS = {};
}
MEC_NS.DataSet = function(type, id, mecJson){
this.type = type;
if(!id){
id = new UUID().toString();
}
this.id = id;
if(!mecJson){
mecJson = this.getDefaultMecJson();
}
this.mecJson = mecJson;
var that = this;
require(['mec'], function(mec){
that.remark = function(){
return mec.remark(that.mecJson.name);
};
});
}
/*获取id。 必需的方法*/
MEC_NS.DataSet.prototype.getID = function(){
return this.id;
};
/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.DataSet.prototype.getDesignHtml = function(){
return getDesignHtml(this);
};
/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.DataSet.prototype.getAttrDlgHtml = function(){
var styleL = "_style" + _userLanguage;
var theId = this.id;
var htm = "<div id=\"MADDS_"+theId+"\">";
htm += "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>";//基本信息
htm += "<div class=\"form-group\">"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4142)+"</span>" //名称:
+ "<div class=\"col-m-8 required\">"
+ "<input type=\"text\" data-autobind='name' id=\"name_"+theId+"\" class=\"form-control requireded\" placeholder=\""+SystemEnv.getHtmlNoteName(4375)+"\"/>" //一个英文的名称,如:shopData
+ "</div>"
+ "</div>"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4255)+"</span>" //来源:
+ "<span class=\"col-m-8 multi-checkbox\">"
+ "<span class=\"cbboxEntry\">"
+ "<input type=\"checkbox\" name=\"sourceType_"+theId+"\" value=\"0\" onclick=\"MADDS_ChangeSourceType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4376)+"</span>" //表单
+ "</span>"
+ "<span class=\"cbboxEntry\">"
+ "<input type=\"checkbox\" name=\"sourceType_"+theId+"\" value=\"1\" onclick=\"MADDS_ChangeSourceType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">SQL</span>"
+ "</span>"
+ "<span class=\"cbboxEntry\">"
+ "<input type=\"checkbox\" name=\"sourceType_"+theId+"\" value=\"2\" onclick=\"MADDS_ChangeSourceType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">Url</span>"
+ "</span>"
+ "<span class=\"cbboxEntry\">"
+ "<input type=\"checkbox\" name=\"sourceType_"+theId+"\" value=\"3\" onclick=\"MADDS_ChangeSourceType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(5268)+"</span>"//接口
+ "</span>"
+ "</span>"
+ "</div>"
+ "<div id=\"div_sourceType_"+theId+"_0\" class=\"div_sourceType\" style=\"display:none;\">"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4377)+"</span>" //表单:
+ "<div class=\"col-m-8\" style=\"position: relative;\">"
+ "<input id=\"tablename_"+theId+"\" class=\"form-control\" type=\"text\" readonly=\"readonly\" style=\"\"/>"
+ "<div class=\"search-before\" onclick=\"MADDS_openTableChoose('"+theId+"')\" style=\"position: absolute;top:2px;right:2px;\"></div>"
+"</div>"
+ "<input id=\"tableid_"+theId+"\" type=\"hidden\"/>"
+ "</div>"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\" style=\"vertical-align: top;\">"+SystemEnv.getHtmlNoteName(4378)+"</span>" //条件:
+ "<div class=\"col-m-8\">"
+ "<textarea id=\"tablecondition_"+theId+"\" class=\"area-control\" placeholder=\""+SystemEnv.getHtmlNoteName(4594)+"\"></textarea>" //查询条件,支持变量,如:id={id} and name={name}
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div id=\"div_sourceType_"+theId+"_1\" class=\"div_sourceType\" style=\"display:none;\">"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4201)+"</span>" //数据源:
+ "<div class=\"col-m-8\">"
+"<select class=\"form-control\" id=\"datasource_"+theId+"\">"
+" <option value=\"\">(local)</option>"
+"</select>"
+ "</div>"
+ "</div>"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\" style=\"vertical-align: top;\">SQL:</span>"
+ "<div class=\"col-m-8\">"
+ "<textarea id=\"sql_"+theId+"\" class=\"area-control\" placeholder=\""+SystemEnv.getHtmlNoteName(4380)+"\"></textarea>" //请在此处键入SQL
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div id=\"div_sourceType_"+theId+"_2\" class=\"div_sourceType\" style=\"display:none;position:relative\">"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADDS_BaseInfo_Entry_Label"+styleL+"\" style=\"vertical-align: top;\">Url:</span>"
+ "<div class=\"col-m-8\">"
+ "<textarea id=\"url_"+theId+"\" class=\"area-control\" placeholder=\""+SystemEnv.getHtmlNoteName(4381)+"\"></textarea>" //请在此处键入Url
+ "</div>"
+ "<div class=\"helper\" data-tipmsg=\""+ MADDS_URLDataTip() +"\" style=\"top:7px;right:10px\" for=\"default\">?</div>"
+ "</div>"
+ "</div>"
+ "<div id=\"div_sourceType_"+theId+"_3\" class=\"div_sourceType\" style=\"display:none;\">"
+ '<div class="row" style="position: relative;">'
+ '<span class="col-2 span-control">'+ SystemEnv.getHtmlNoteName(5239) + '</span>' //接口配置:
+ '<div class="api-browser col edit-before pd-72" style="width: 20px;text-align:left;"></div>'
+ '<div class="col ml-5 pd-7 link" id="apiName_'+theId+'"></div>'
+ '</div>'
+ '<div>'
+ '<div class="title" style="font-weight:normal;color:#666;">'
+ SystemEnv.getHtmlNoteName(4295) //输出格式
+ '</div>'
+ '<div class="form-group">'
+ '<div>'
+ '<ul class="normal-list outformat-list">'
+ '<li>'
+ '<div class="inline" style="width:50%;">'
+ '<input name="key" type="hidden" value="DATAS">'
+ '<input name="name" data-key="DATAS" type="text" class="form-control" value="">'
+ '</div>'
+ '<div class="inline" style="width:50%;">'
+ '<div class="outformat_key_desc" style="margin-left:10px;">'+SystemEnv.getHtmlNoteName(4302)+'</div>'//数据JSON对应KEY
+ '</div>'
+ '</li>'
+ '</ul>'
+ '</div>'
+ '</div>'
+ '</div>'
+ "</div>"
+"</div>";
htm += "<div class=\"bottom\"><div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>"; //确定
htm += "</div>";
htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>"; //已生成到布局
return htm;
};
/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.DataSet.prototype.afterAttrDlgBuild = function(){
var theId = this.id;
var $attrContainer = this.$attrContainer = $("#MAD_"+theId);
this.bindAttrDlgHtmlEvent();
$("#name_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["name"]));
$("#name_"+theId).blur(function(){
var nameV = $(this).val();
if(nameV != '' && !eval("/^[\\w]{1,}$/.test(\""+nameV+"\")")){
alert(SystemEnv.getHtmlNoteName(5269));//数据集名称不合法,此处仅可以使用英文字母,数字和下划线
$(this).val("");
}
});
var sourceTypeV = this.mecJson["sourceType"];
var $sourceType = $("input[type='checkbox'][name='sourceType_"+theId+"'][value='"+sourceTypeV+"']");
if($sourceType.length > 0){
$sourceType.checked();
}
//数据集支持接口
var apiConfig = this.mecJson.apiConfig;
var apiId = apiConfig && apiConfig.api.id || "";
var apiName = apiConfig && apiConfig.api.name || "";
$("#apiName_"+theId).data("last", apiId).text(apiName);
var outFormat = this.mecJson.outFormat;
var $outFormatLi = $("ul.outformat-list > li", $attrContainer);
outFormat && $outFormatLi.each(function(){
var $li = $(this);
var key = $("input[name='key']", $li).val();
outFormat[key] && $("input[name='name']", $li).val(outFormat[key]);
});
var datasource = Mec_FiexdUndefinedVal(this.mecJson["datasource"]);
$("#datasource_"+theId).val(datasource);
MADDS_setDataSourceHTML(theId, datasource);
$("#sql_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["sql"]));
$("#url_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["url"]));
$("#tablename_" + theId).val(Mec_FiexdUndefinedVal(this.mecJson["tablename"]));
$("#tableid_" + theId).val(Mec_FiexdUndefinedVal(this.mecJson["tableid"]));
$("#tablecondition_" + theId).val(Mec_FiexdUndefinedVal(this.mecJson["sqlwhere"]));
$("#MADDS_"+theId).checkbox();
require(["modal"], function(modal) {
var indexArr = [];
$($attrContainer).on("click",".helper", function(e) {
indexArr.push(modal.tips($(this).data('tipmsg'), $(this), {
area: ['250px', ''],
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);
});
});
});
};
/*获取JSON*/
MEC_NS.DataSet.prototype.getMecJson = function(){
var theId = this.id;
this.mecJson["id"] = theId;
this.mecJson["mectype"] = this.type;
var $attrContainer = $("#MAD_"+theId);
if($attrContainer.length > 0){
this.mecJson["name"] = $("#name_"+theId).val();
this.mecJson["sourceType"] = $("input[type='checkbox'][name='sourceType_"+theId+"']:checked").val();
this.mecJson["datasource"] = $("#datasource_"+theId).val();
this.mecJson["sql"] = $("#sql_"+theId).val();
this.mecJson["url"] = $("#url_"+theId).val();
this.mecJson["tablename"] = $("#tablename_" + theId).val();
this.mecJson["tableid"] = $("#tableid_" + theId).val();
this.mecJson["sqlwhere"] = $("#tablecondition_" + theId).val();
var formats = {};
var $outFormatLi = $("ul.outformat-list > li", $attrContainer);
$outFormatLi.each(function(){
var $li = $(this);
var key = $("input[name='key']", $li).val();
var name = $("input[name='name']", $li).val();
formats[key] = name;
});
this.mecJson["outFormat"] = formats;
}
return this.mecJson;
};
MEC_NS.DataSet.prototype.getDefaultMecJson = function(){
var theId = this.id;
var defMecJson = {};
defMecJson["id"] = theId;
defMecJson["mectype"] = this.type;
defMecJson["apiConfig"] = {
api: {},
params: {
query: [],
body: {}
}
};
defMecJson["name"] = ""; //标题
defMecJson["sourceType"] = "1"; //SQL
defMecJson["datasource"] = ""; //单击类型
defMecJson["sql"] = ""; //sql
defMecJson["url"] = ""; //url
return defMecJson;
};
MEC_NS.DataSet.prototype.validate = function () {
var name = this.mecJson.name;
var isValid = !!name;
if (isValid) {
return true;
} else {
var mec_id = this.id;
var $pluginAttr = $('#MAD_' + mec_id);
$pluginAttr.find('#name_' + mec_id).parents('.col-m-8').validate({
value: name,
rules: [{
msg: '"' + SystemEnv.getHtmlNoteName(4142).replace(/[\:\:]/g, '') + '" ' + SystemEnv.getHtmlNoteName(6041) //名称
}],
});
return {
isValid: isValid,
msg: SystemEnv.getHtmlNoteName(6075) //请设置名称!
};
}
};
function MADDS_ChangeSourceType(cbObj, mec_id){
var objV = cbObj.value;
$(".div_sourceType", "#MADDS_"+mec_id).hide();
$("#div_sourceType_"+mec_id+"_" + objV).show();
}
function MADDS_setDataSourceHTML(mec_id,val){
var $MADFS_DataSource = $("#datasource_" + mec_id);
var url = jionActionUrl("com.weaver.formmodel.mobile.servlet.MobileAppBaseAction", "action=getDataSource");
FormmodeUtil.doAjaxDataLoad(url, function(datas){
for(var i = 0; i < datas.length; i++){
var data = datas[i];
var pointid = data;
var selected = "";
if (pointid=="" || typeof(pointid)=="undefined") continue;
if (pointid == val) selected = "selected";
var dataSourceSelectHtml = "<option value=\""+pointid+"\" "+selected+">";
dataSourceSelectHtml += pointid;
dataSourceSelectHtml += "</option>";
$MADFS_DataSource.append(dataSourceSelectHtml);
}
});
}
function MADDS_openTableChoose(mec_id){
var mecHandler = MECHandlerPool.getHandler(mec_id);
require(['utils'],function(_u){
_u.openRcDialog("browser", {
title: SystemEnv.getHtmlNoteName(3418), //请选择
width: 700,
height: 500,
params:{
type: '1'
},
btn:[SystemEnv.getHtmlNoteName(3704),SystemEnv.getHtmlNoteName(3516)]
}, function(result) {
$("#tableid_" + mec_id).val(result.id);
$("#tablename_" + mec_id).val(result.name);
mecHandler.autobind.update();
});
});
}
$.extend(MEC_NS.DataSet.prototype, {
bindAttrDlgHtmlEvent: function(){
var that = this, theId = this.id,
$attrContainer = this.$attrContainer,
_u = require("utils");
//选择接口事件绑定
$(".api-browser, #apiName_" + theId, $attrContainer).click(function(){
var apiConfig = that.mecJson.apiConfig || {
api: {},
params: {
query: [],
body: {}
}
};
_u.openRcDialog("api-config", {
title: SystemEnv.getHtmlNoteName(5239).replace(/[::]/g, ""),//接口配置
params: {
id: apiConfig.api.id||"",
config: apiConfig,
height: 506
}
}, function(result) {
that.mecJson.apiConfig = result;
var selectApi = result.api || {};
var selectApiId = selectApi.id,
selectApiName = selectApi.name;
var lastSourceValue = $("#apiName_" + theId).data("last");
if(!selectApiId || selectApiId === lastSourceValue) return;
$("#apiName_" + theId).data("last", selectApiId).text(selectApiName);
_u.api('api', {
action: "info",
type: "get",
data: {
"id": selectApiId
}
}).then(function (apiResult) {
apiResult = apiResult.data;
var resultDefine = apiResult.resultDefine || [];
//结果定义(输出参数)
var keyMap = {};
resultDefine.forEach(function(ele) {
var resultKey = ele.name || "";
if(resultKey.indexOf(".") === -1){
if(ele.type === "JSON"){
!keyMap.DATAS && (keyMap.DATAS = resultKey);
}
}
});
var $outFormatLi = $("ul.outformat-list > li", $attrContainer);
$outFormatLi.each(function(){
var $li = $(this);
var _key = $("input[name='key']", $li).val();
keyMap[_key] && $("input[name='name']", $li).val(keyMap[_key]);
});
});
});
});
}
});
function MADDS_URLDataTip(){
var tip = SystemEnv.getHtmlNoteName(6218) ;//Url返回的数据格式如:
tip += "{\n" +
" 'name': 'Weaver',\n" +
" 'company': 'Weaver Software'\n"+
"}";
return tip;
}