gen.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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()" shiro:hasRole="admin">
  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 codeName = templateName.replace(".", "");
  148. var language = templateName.substring(templateName.lastIndexOf(".") + 1);
  149. var highCode = hljs.highlight(language, value).value;
  150. items.push({
  151. title: templateName , content: "<pre class=\"layui-code\"><a style=\"float:right\" href=\"javascript:copyText('" + codeName + "')\"><i class=\"fa fa-copy\"></i> 复制</a><code id=\"" + codeName + "\">" + highCode + "</code></pre><textarea id=\"t_" + codeName + "\" style='position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;'></textarea><script>function copyText(codeName){var text = document.getElementById(codeName).innerText;var input = document.getElementById(\"t_\"+codeName);input.value = text;input.select();document.execCommand(\"copy\");$.modal.msgSuccess(\"复制成功\");}<\/script>"
  152. })
  153. }
  154. });
  155. top.layer.tab({
  156. area: ['90%', '90%'],
  157. shadeClose: true,
  158. success: function(layero, index){
  159. parent.loadCss(ctx + "ajax/libs/highlight/default.min.css");
  160. },
  161. tab: items
  162. });
  163. } else {
  164. $.modal.alertError(result.msg);
  165. }
  166. $.modal.closeLoading();
  167. });
  168. }
  169. // 生成代码
  170. function genCode(tableName, genType) {
  171. $.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
  172. if(genType === "0") {
  173. location.href = prefix + "/download/" + tableName;
  174. layer.msg('执行成功,正在生成代码请稍候…', { icon: 1 });
  175. } else if(genType === "1") {
  176. $.operate.get(prefix + "/genCode/" + tableName);
  177. }
  178. })
  179. }
  180. // 同步数据库
  181. function synchDb(tableName){
  182. $.modal.confirm("确认要强制同步" + tableName + "表结构吗?", function() {
  183. $.operate.get(prefix + "/synchDb/" + tableName);
  184. })
  185. }
  186. // 批量生成代码
  187. function batchGenCode() {
  188. var rows = $.table.selectColumns("tableName");
  189. if (rows.length == 0) {
  190. $.modal.alertWarning("请选择要生成的数据");
  191. return;
  192. }
  193. $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
  194. location.href = prefix + "/batchGenCode?tables=" + rows;
  195. layer.msg('执行成功,正在生成代码请稍候…', { icon: 1 });
  196. });
  197. }
  198. // 导入表结构
  199. function importTable() {
  200. var importTableUrl = prefix + "/importTable";
  201. $.modal.open("导入表结构", importTableUrl);
  202. }
  203. // 创建表结构
  204. function createTable() {
  205. var creatTableUrl = prefix + "/createTable";
  206. $.modal.open("创建表结构", creatTableUrl);
  207. }
  208. </script>
  209. </body>
  210. </html>