gen.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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:src="@{/ajax/libs/highlight/highlight.min.js}"></script>
  55. <script th:inline="javascript">
  56. var prefix = ctx + "tool/gen";
  57. var editFlag = [[${@permission.hasPermi('tool:gen:edit')}]];
  58. var removeFlag = [[${@permission.hasPermi('tool:gen:remove')}]];
  59. var previewFlag = [[${@permission.hasPermi('tool:gen:preview')}]];
  60. var codeFlag = [[${@permission.hasPermi('tool:gen:code')}]];
  61. $(function() {
  62. var options = {
  63. url: prefix + "/list",
  64. updateUrl: prefix + "/edit/{id}",
  65. removeUrl: prefix + "/remove",
  66. sortName: "createTime",
  67. sortOrder: "desc",
  68. showExport: true,
  69. modalName: "生成配置",
  70. rememberSelected: true,
  71. uniqueId: "tableId",
  72. columns: [{
  73. field: 'state',
  74. checkbox: true
  75. },
  76. {
  77. field: 'tableId',
  78. title: '编号',
  79. visible: false
  80. },
  81. {
  82. title: "序号",
  83. formatter: function (value, row, index) {
  84. return $.table.serialNumber(index);
  85. }
  86. },
  87. {
  88. field: 'tableName',
  89. title: '表名称',
  90. sortable: true,
  91. formatter: function(value, row, index) {
  92. return $.table.tooltip(value);
  93. }
  94. },
  95. {
  96. field: 'tableComment',
  97. title: '表描述',
  98. sortable: true,
  99. formatter: function(value, row, index) {
  100. return $.table.tooltip(value, 15);
  101. }
  102. },
  103. {
  104. field: 'className',
  105. title: '实体类名称',
  106. sortable: true
  107. },
  108. {
  109. field: 'createTime',
  110. title: '创建时间',
  111. sortable: true
  112. },
  113. {
  114. field: 'updateTime',
  115. title: '更新时间',
  116. sortable: true
  117. },
  118. {
  119. title: '操作',
  120. align: 'center',
  121. formatter: function(value, row, index) {
  122. var actions = [];
  123. 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> ');
  124. 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> ');
  125. 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> ');
  126. actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="synchDb(\'' + row.tableName + '\')"><i class="fa fa-refresh"></i>同步</a> ');
  127. 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> ');
  128. return actions.join('');
  129. }
  130. }]
  131. };
  132. $.table.init(options);
  133. });
  134. // 预览代码
  135. function preview(tableId) {
  136. var preViewUrl = prefix + "/preview/" + tableId;
  137. $.modal.loading("正在加载数据,请稍后...");
  138. $.get(preViewUrl, function(result) {
  139. if (result.code == web_status.SUCCESS) {
  140. var items = [];
  141. $.each(result.data, function(index, value) {
  142. var templateName = index.substring(index.lastIndexOf("/") + 1, index.length).replace(/\.vm/g, "");
  143. if(!$.common.equals("sql", templateName) && !$.common.equals("tree.html", templateName) && !$.common.equals("sub-domain.java", templateName)){
  144. var language = templateName.substring(templateName.lastIndexOf(".") + 1);
  145. var highCode = hljs.highlight(language, value).value;
  146. items.push({
  147. title: templateName , content: "<pre class=\"layui-code\"><code>" + highCode + "</code></pre>"
  148. })
  149. }
  150. });
  151. top.layer.tab({
  152. area: ['90%', '90%'],
  153. shadeClose: true,
  154. success: function(layero, index){
  155. parent.loadCss(ctx + "ajax/libs/highlight/default.min.css");
  156. },
  157. tab: items
  158. });
  159. } else {
  160. $.modal.alertError(result.msg);
  161. }
  162. $.modal.closeLoading();
  163. });
  164. }
  165. // 生成代码
  166. function genCode(tableName, genType) {
  167. $.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
  168. if(genType === "0") {
  169. location.href = prefix + "/download/" + tableName;
  170. layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
  171. } else if(genType === "1") {
  172. $.operate.get(prefix + "/genCode/" + tableName);
  173. }
  174. })
  175. }
  176. // 同步数据库
  177. function synchDb(tableName){
  178. $.modal.confirm("确认要强制同步" + tableName + "表结构吗?", function() {
  179. $.operate.get(prefix + "/synchDb/" + tableName);
  180. })
  181. }
  182. // 批量生成代码
  183. function batchGenCode() {
  184. var rows = $.table.selectColumns("tableName");
  185. if (rows.length == 0) {
  186. $.modal.alertWarning("请选择要生成的数据");
  187. return;
  188. }
  189. $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
  190. location.href = prefix + "/batchGenCode?tables=" + rows;
  191. layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
  192. });
  193. }
  194. // 导入表结构
  195. function importTable() {
  196. var importTableUrl = prefix + "/importTable";
  197. $.modal.open("导入表结构", importTableUrl);
  198. }
  199. </script>
  200. </body>
  201. </html>