gen.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
  3. <head>
  4. <th:block th:include="include :: header('代码生成列表')" />
  5. </head>
  6. <body class="gray-bg">
  7. <div class="container-div">
  8. <div class="row">
  9. <div class="col-sm-12 search-collapse">
  10. <form id="gen-form">
  11. <div class="select-list">
  12. <ul>
  13. <li>
  14. 表名称:<input type="text" name="tableName"/>
  15. </li>
  16. <li>
  17. 表描述:<input type="text" name="tableComment"/>
  18. </li>
  19. <li class="select-time">
  20. <label>表时间: </label>
  21. <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
  22. <span>-</span>
  23. <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
  24. </li>
  25. <li>
  26. <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
  27. <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
  28. </li>
  29. </ul>
  30. </div>
  31. </form>
  32. </div>
  33. <div class="btn-group-sm" id="toolbar" role="group">
  34. <a class="btn btn-success multiple disabled" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
  35. <i class="fa fa-download"></i> 生成
  36. </a>
  37. <a class="btn btn-info" onclick="importTable()">
  38. <i class="fa fa-upload"></i> 导入
  39. </a>
  40. <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="tool:gen:edit">
  41. <i class="fa fa-edit"></i> 修改
  42. </a>
  43. <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="tool:gen:remove">
  44. <i class="fa fa-remove"></i> 删除
  45. </a>
  46. </div>
  47. <div class="col-sm-12 select-table table-striped">
  48. <table id="bootstrap-table"></table>
  49. </div>
  50. </div>
  51. </div>
  52. <th:block th:include="include :: footer" />
  53. <th:block th:include="include :: bootstrap-table-export-js" />
  54. <script th:inline="javascript">
  55. var prefix = ctx + "tool/gen";
  56. var editFlag = [[${@permission.hasPermi('tool:gen:edit')}]];
  57. var removeFlag = [[${@permission.hasPermi('tool:gen:remove')}]];
  58. var previewFlag = [[${@permission.hasPermi('tool:gen:preview')}]];
  59. var codeFlag = [[${@permission.hasPermi('tool:gen:code')}]];
  60. $(function() {
  61. var options = {
  62. url: prefix + "/list",
  63. updateUrl: prefix + "/edit/{id}",
  64. removeUrl: prefix + "/remove",
  65. sortName: "createTime",
  66. sortOrder: "desc",
  67. showExport: true,
  68. modalName: "生成配置",
  69. rememberSelected: true,
  70. uniqueId: "tableId",
  71. columns: [{
  72. field: 'state',
  73. checkbox: true
  74. },
  75. {
  76. field: 'tableId',
  77. title: '编号',
  78. visible: false
  79. },
  80. {
  81. title: "序号",
  82. formatter: function (value, row, index) {
  83. return $.table.serialNumber(index);
  84. }
  85. },
  86. {
  87. field: 'tableName',
  88. title: '表名称',
  89. sortable: true,
  90. formatter: function(value, row, index) {
  91. return $.table.tooltip(value);
  92. }
  93. },
  94. {
  95. field: 'tableComment',
  96. title: '表描述',
  97. sortable: true,
  98. formatter: function(value, row, index) {
  99. return $.table.tooltip(value, 15);
  100. }
  101. },
  102. {
  103. field: 'className',
  104. title: '实体类名称',
  105. sortable: true
  106. },
  107. {
  108. field: 'createTime',
  109. title: '创建时间',
  110. sortable: true
  111. },
  112. {
  113. field: 'updateTime',
  114. title: '更新时间',
  115. sortable: true
  116. },
  117. {
  118. title: '操作',
  119. align: 'center',
  120. formatter: function(value, row, index) {
  121. var actions = [];
  122. actions.push('<a class="btn btn-info btn-xs ' + previewFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.tableId + '\')"><i class="fa fa-search"></i>预览</a> ');
  123. actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.tableId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
  124. actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a> ');
  125. actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCode(\'' + row.tableName + '\',\'' + row.genType + '\')"><i class="fa fa-bug"></i>生成代码</a> ');
  126. return actions.join('');
  127. }
  128. }
  129. ]
  130. };
  131. $.table.init(options);
  132. });
  133. // 预览代码
  134. function preview(tableId) {
  135. var preViewUrl = prefix + "/preview/" + tableId;
  136. $.modal.loading("正在加载数据,请稍后...");
  137. $.get(preViewUrl, function(result) {
  138. if (result.code == web_status.SUCCESS) {
  139. var items = [];
  140. $.each(result.data, function(index, value) {
  141. value = value.replace(/</g, "&lt;");
  142. value = value.replace(/>/g, "&gt;");
  143. var templateName = index.substring(index.lastIndexOf("/") + 1, index.length).replace(/\.vm/g, "");
  144. if(!$.common.equals("sql", templateName) && !$.common.equals("tree.html", templateName) && !$.common.equals("sub-domain.java", templateName)){
  145. items.push({
  146. title: templateName , content: "<pre class=\"layui-code\">" + value + "</pre>"
  147. })
  148. }
  149. });
  150. top.layer.tab({
  151. area: ['90%', '90%'],
  152. shadeClose: true,
  153. tab: items
  154. });
  155. } else {
  156. $.modal.alertError(result.msg);
  157. }
  158. $.modal.closeLoading();
  159. });
  160. }
  161. // 生成代码
  162. function genCode(tableName, genType) {
  163. $.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
  164. if(genType === "0") {
  165. location.href = prefix + "/download/" + tableName;
  166. layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
  167. } else if(genType === "1") {
  168. $.operate.get(prefix + "/genCode/" + tableName);
  169. }
  170. })
  171. }
  172. // 批量生成代码
  173. function batchGenCode() {
  174. var rows = $.table.selectColumns("tableName");
  175. if (rows.length == 0) {
  176. $.modal.alertWarning("请选择要生成的数据");
  177. return;
  178. }
  179. $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
  180. location.href = prefix + "/batchGenCode?tables=" + rows;
  181. layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
  182. });
  183. }
  184. // 导入表结构
  185. function importTable() {
  186. var importTableUrl = prefix + "/importTable";
  187. $.modal.open("导入表结构", importTableUrl);
  188. }
  189. </script>
  190. </body>
  191. </html>