gen.html 8.4 KB

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