提交 | 用户 | 时间
|
71e81e
|
1 |
layui.use(['layer', 'ax', 'form', 'laydate', 'element', 'table'], function () { |
懒 |
2 |
var $ = layui.$; |
|
3 |
var $ax = layui.ax; |
|
4 |
var layer = layui.layer; |
|
5 |
var form = layui.form; |
|
6 |
var laydate = layui.laydate; |
|
7 |
var element = layui.element; |
|
8 |
var table = layui.table; |
|
9 |
var fieldConfigList = []; |
|
10 |
|
|
11 |
table.render({ |
|
12 |
elem: '#fieldTable', |
|
13 |
url: Feng.ctxPath + '/getTableFieldConfigs?tableName=' + $("#tableName").val() + "&dbId=" + $("#dbId").val(), |
|
14 |
parseData: function (res) { |
|
15 |
//获取返回的数据缓存起来 |
|
16 |
fieldConfigList = res.data; |
|
17 |
return res; |
|
18 |
}, |
|
19 |
page: false, |
|
20 |
cellMinWidth: 100, |
|
21 |
cols: [[ |
|
22 |
{field: 'columnName', title: '字段名'}, |
|
23 |
{field: 'columnComment', title: '字段注释'}, |
|
24 |
{field: 'queryConditionFlag', title: '是否为查询条件', templet: '#conditionTpl'}, |
|
25 |
{field: 'inputType', title: '字段属性样式', templet: '#inputTypeTpl'} |
|
26 |
]] |
|
27 |
}); |
|
28 |
form.render('select'); |
|
29 |
|
|
30 |
//监听下拉选项操作 |
|
31 |
form.on('select(columnStyleFilter)', function (data) { |
|
32 |
var columnName = data.elem.id; |
|
33 |
var inputType = data.elem.value; |
|
34 |
|
|
35 |
for (let i = 0, len = fieldConfigList.length; i < len; i++) { |
|
36 |
if (fieldConfigList[i].columnName === columnName) { |
|
37 |
fieldConfigList[i].inputType = inputType; |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
console.log(fieldConfigList); |
|
42 |
}); |
|
43 |
|
|
44 |
//监听单选事件 |
|
45 |
form.on('checkbox(queryConditionFlagFilter)', function (data) { |
|
46 |
var columnName = data.elem.id; |
|
47 |
var checked = data.elem.checked; |
|
48 |
|
|
49 |
//fieldConfigList配置过字段则直接设置为checked |
|
50 |
for (let i = 0, len = fieldConfigList.length; i < len; i++) { |
|
51 |
if (fieldConfigList[i].columnName === columnName) { |
|
52 |
fieldConfigList[i].queryConditionFlag = checked; |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
console.log(fieldConfigList); |
|
57 |
}); |
|
58 |
|
|
59 |
//点击提交时 |
|
60 |
$('#submit').click(function () { |
|
61 |
var requestBody = new Map(); |
|
62 |
requestBody.set("tableName", $("#tableName").val()); |
|
63 |
requestBody.set("fieldConfigList", fieldConfigList); |
|
64 |
|
|
65 |
layui.jquery.ajax({ |
|
66 |
url: Feng.ctxPath + "/saveFieldsConfig", |
|
67 |
type: 'post', |
|
68 |
contentType: "application/json; charset=utf-8", |
|
69 |
dataType: 'json', |
|
70 |
data: _mapToJson(requestBody), |
|
71 |
success: function (data) { |
|
72 |
fieldConfigList = []; |
|
73 |
Feng.success("保存成功"); |
|
74 |
parent.layer.close(parent.layer.getFrameIndex(window.name)); |
|
75 |
}, |
|
76 |
error: function (data) { |
|
77 |
Feng.error("保存失败"); |
|
78 |
} |
|
79 |
}); |
|
80 |
|
|
81 |
}); |
|
82 |
|
|
83 |
function _strMapToObj(strMap) { |
|
84 |
let obj = Object.create(null); |
|
85 |
for (let [k, v] of strMap) { |
|
86 |
obj[k] = v; |
|
87 |
} |
|
88 |
return obj; |
|
89 |
} |
|
90 |
|
|
91 |
function _mapToJson(map) { |
|
92 |
return JSON.stringify(_strMapToObj(map)); |
|
93 |
} |
|
94 |
|
|
95 |
}); |