提交 | 用户 | 时间
|
71e81e
|
1 |
layui.use(['table', 'admin', 'ax', 'func'], function () { |
懒 |
2 |
var $ = layui.$; |
|
3 |
var table = layui.table; |
|
4 |
var $ax = layui.ax; |
|
5 |
var admin = layui.admin; |
|
6 |
var func = layui.func; |
|
7 |
|
|
8 |
/** |
|
9 |
* ${tableComment}管理 |
|
10 |
*/ |
|
11 |
var ${entity} = { |
|
12 |
tableId: "${lowerEntity}Table" |
|
13 |
}; |
|
14 |
|
|
15 |
/** |
|
16 |
* 初始化表格的列 |
|
17 |
*/ |
|
18 |
${entity}.initColumn = function () { |
|
19 |
return [[ |
|
20 |
{type: 'checkbox'}, |
|
21 |
<% for(item in table.fields!){ %> |
|
22 |
<% if(item.keyFlag){ %> |
|
23 |
{field: '${item.propertyName}', hide: true, title: '${item.comment}'}, |
|
24 |
<% }else{ %> |
|
25 |
{field: '${item.propertyName}', sort: true, title: '${item.comment}'}, |
|
26 |
<% } %> |
|
27 |
<% } %> |
|
28 |
{align: 'center', toolbar: '#tableBar', title: '操作'} |
|
29 |
]]; |
|
30 |
}; |
|
31 |
|
|
32 |
/** |
|
33 |
* 点击查询按钮 |
|
34 |
*/ |
|
35 |
${entity}.search = function () { |
|
36 |
var queryData = {}; |
|
37 |
|
|
38 |
<% for(var i=0 ; i < conditionFields.~size ; i++){ %> |
|
39 |
queryData['${conditionFields[i].camelFieldName}'] = $('#${conditionFields[i].camelFieldName}').val(); |
|
40 |
<% } %> |
|
41 |
|
|
42 |
table.reload(${entity}.tableId, { |
|
43 |
where: queryData, page: {curr: 1} |
|
44 |
}); |
|
45 |
}; |
|
46 |
|
|
47 |
<% if(jumpType){ %> |
|
48 |
/** |
|
49 |
* 弹出添加对话框 |
|
50 |
*/ |
|
51 |
${entity}.openAddDlg = function () { |
|
52 |
func.open({ |
|
53 |
title: '添加${tableComment}', |
|
54 |
content: Feng.ctxPath + '/${lowerEntity}/add', |
|
55 |
tableId: ${entity}.tableId |
|
56 |
}); |
|
57 |
}; |
|
58 |
|
|
59 |
/** |
|
60 |
* 点击编辑 |
|
61 |
* |
|
62 |
* @param data 点击按钮时候的行数据 |
|
63 |
*/ |
|
64 |
${entity}.openEditDlg = function (data) { |
|
65 |
func.open({ |
|
66 |
title: '修改${tableComment}', |
|
67 |
content: Feng.ctxPath + '/${lowerEntity}/edit?${keyPropertyName}=' + data.${keyPropertyName}, |
|
68 |
tableId: ${entity}.tableId |
|
69 |
}); |
|
70 |
}; |
|
71 |
|
|
72 |
<% }else{ %> |
|
73 |
/** |
|
74 |
* 跳转到添加页面 |
|
75 |
*/ |
|
76 |
${entity}.jumpAddPage = function () { |
|
77 |
window.location.href = Feng.ctxPath + '/${lowerEntity}/add' |
|
78 |
}; |
|
79 |
|
|
80 |
/** |
|
81 |
* 跳转到编辑页面 |
|
82 |
* |
|
83 |
* @param data 点击按钮时候的行数据 |
|
84 |
*/ |
|
85 |
${entity}.jumpEditPage = function (data) { |
|
86 |
window.location.href = Feng.ctxPath + '/${lowerEntity}/edit?${keyPropertyName}=' + data.${keyPropertyName} |
|
87 |
}; |
|
88 |
<% } %> |
|
89 |
|
|
90 |
/** |
|
91 |
* 导出excel按钮 |
|
92 |
*/ |
|
93 |
${entity}.exportExcel = function () { |
|
94 |
var checkRows = table.checkStatus(${entity}.tableId); |
|
95 |
if (checkRows.data.length === 0) { |
|
96 |
Feng.error("请选择要导出的数据"); |
|
97 |
} else { |
|
98 |
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); |
|
99 |
} |
|
100 |
}; |
|
101 |
|
|
102 |
/** |
|
103 |
* 点击删除 |
|
104 |
* |
|
105 |
* @param data 点击按钮时候的行数据 |
|
106 |
*/ |
|
107 |
${entity}.onDeleteItem = function (data) { |
|
108 |
var operation = function () { |
|
109 |
var ajax = new $ax(Feng.ctxPath + "/${lowerEntity}/delete", function (data) { |
|
110 |
Feng.success("删除成功!"); |
|
111 |
table.reload(${entity}.tableId); |
|
112 |
}, function (data) { |
|
113 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
114 |
}); |
|
115 |
ajax.set("${keyPropertyName}", data.${keyPropertyName}); |
|
116 |
ajax.start(); |
|
117 |
}; |
|
118 |
Feng.confirm("是否删除?", operation); |
|
119 |
}; |
|
120 |
|
|
121 |
// 渲染表格 |
|
122 |
var tableResult = table.render({ |
|
123 |
elem: '#' + ${entity}.tableId, |
|
124 |
url: Feng.ctxPath + '/${lowerEntity}/list', |
|
125 |
page: true, |
|
126 |
height: "full-158", |
|
127 |
cellMinWidth: 100, |
|
128 |
cols: ${entity}.initColumn() |
|
129 |
}); |
|
130 |
|
|
131 |
// 搜索按钮点击事件 |
|
132 |
$('#btnSearch').click(function () { |
|
133 |
${entity}.search(); |
|
134 |
}); |
|
135 |
|
|
136 |
// 添加按钮点击事件 |
|
137 |
$('#btnAdd').click(function () { |
|
138 |
|
|
139 |
<% if(jumpType){ %> |
|
140 |
${entity}.openAddDlg(); |
|
141 |
<% }else{ %> |
|
142 |
${entity}.jumpAddPage(); |
|
143 |
<% } %> |
|
144 |
|
|
145 |
}); |
|
146 |
|
|
147 |
// 导出excel |
|
148 |
$('#btnExp').click(function () { |
|
149 |
${entity}.exportExcel(); |
|
150 |
}); |
|
151 |
|
|
152 |
// 工具条点击事件 |
|
153 |
table.on('tool(' + ${entity}.tableId + ')', function (obj) { |
|
154 |
var data = obj.data; |
|
155 |
var layEvent = obj.event; |
|
156 |
|
|
157 |
if (layEvent === 'edit') { |
|
158 |
<% if(jumpType){ %> |
|
159 |
${entity}.openEditDlg(data); |
|
160 |
<% }else{ %> |
|
161 |
${entity}.jumpEditPage(data); |
|
162 |
<% } %> |
|
163 |
} else if (layEvent === 'delete') { |
|
164 |
${entity}.onDeleteItem(data); |
|
165 |
} |
|
166 |
}); |
|
167 |
}); |