index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="数据源" prop="dataName">
  5. <el-input
  6. v-model="queryParams.dataName"
  7. placeholder="请输入数据源名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="表名称" prop="tableName">
  13. <el-input
  14. v-model="queryParams.tableName"
  15. placeholder="请输入表名称"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="表描述" prop="tableComment">
  21. <el-input
  22. v-model="queryParams.tableComment"
  23. placeholder="请输入表描述"
  24. clearable
  25. @keyup.enter.native="handleQuery"
  26. />
  27. </el-form-item>
  28. <el-form-item label="创建时间">
  29. <el-date-picker
  30. v-model="dateRange"
  31. style="width: 240px"
  32. value-format="yyyy-MM-dd"
  33. type="daterange"
  34. range-separator="-"
  35. start-placeholder="开始日期"
  36. end-placeholder="结束日期"
  37. ></el-date-picker>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  41. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  42. </el-form-item>
  43. </el-form>
  44. <el-row :gutter="10" class="mb8">
  45. <el-col :span="1.5">
  46. <el-button
  47. type="primary"
  48. plain
  49. icon="el-icon-download"
  50. size="mini"
  51. @click="handleGenTable"
  52. v-hasPermi="['tool:gen:code']"
  53. >生成</el-button>
  54. </el-col>
  55. <el-col :span="1.5">
  56. <el-button
  57. type="info"
  58. plain
  59. icon="el-icon-upload"
  60. size="mini"
  61. @click="openImportTable"
  62. v-hasPermi="['tool:gen:import']"
  63. >导入</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="success"
  68. plain
  69. icon="el-icon-edit"
  70. size="mini"
  71. :disabled="single"
  72. @click="handleEditTable"
  73. v-hasPermi="['tool:gen:edit']"
  74. >修改</el-button>
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-button
  78. type="danger"
  79. plain
  80. icon="el-icon-delete"
  81. size="mini"
  82. :disabled="multiple"
  83. @click="handleDelete"
  84. v-hasPermi="['tool:gen:remove']"
  85. >删除</el-button>
  86. </el-col>
  87. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  88. </el-row>
  89. <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
  90. <el-table-column type="selection" align="center" width="55"></el-table-column>
  91. <el-table-column label="序号" type="index" width="50" align="center">
  92. <template slot-scope="scope">
  93. <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column
  97. label="表名称"
  98. align="center"
  99. prop="tableName"
  100. :show-overflow-tooltip="true"
  101. width="120"
  102. />
  103. <el-table-column
  104. label="表描述"
  105. align="center"
  106. prop="tableComment"
  107. :show-overflow-tooltip="true"
  108. width="120"
  109. />
  110. <el-table-column
  111. label="实体"
  112. align="center"
  113. prop="className"
  114. :show-overflow-tooltip="true"
  115. width="120"
  116. />
  117. <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
  118. <el-table-column label="更新时间" align="center" prop="updateTime" width="160" />
  119. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  120. <template slot-scope="scope">
  121. <el-button
  122. type="text"
  123. size="small"
  124. icon="el-icon-view"
  125. @click="handlePreview(scope.row)"
  126. v-hasPermi="['tool:gen:preview']"
  127. >预览</el-button>
  128. <el-button
  129. type="text"
  130. size="small"
  131. icon="el-icon-edit"
  132. @click="handleEditTable(scope.row)"
  133. v-hasPermi="['tool:gen:edit']"
  134. >编辑</el-button>
  135. <el-button
  136. type="text"
  137. size="small"
  138. icon="el-icon-delete"
  139. @click="handleDelete(scope.row)"
  140. v-hasPermi="['tool:gen:remove']"
  141. >删除</el-button>
  142. <el-button
  143. type="text"
  144. size="small"
  145. icon="el-icon-refresh"
  146. @click="handleSynchDb(scope.row)"
  147. v-hasPermi="['tool:gen:edit']"
  148. >同步</el-button>
  149. <el-button
  150. type="text"
  151. size="small"
  152. icon="el-icon-download"
  153. @click="handleGenTable(scope.row)"
  154. v-hasPermi="['tool:gen:code']"
  155. >生成代码</el-button>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <pagination
  160. v-show="total>0"
  161. :total="total"
  162. :page.sync="queryParams.pageNum"
  163. :limit.sync="queryParams.pageSize"
  164. @pagination="getList"
  165. />
  166. <!-- 预览界面 -->
  167. <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body class="scrollbar">
  168. <el-tabs v-model="preview.activeName">
  169. <el-tab-pane
  170. v-for="(value, key) in preview.data"
  171. :label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
  172. :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
  173. :key="key"
  174. >
  175. <el-link :underline="false" icon="el-icon-document-copy" v-clipboard:copy="value" v-clipboard:success="clipboardSuccess" style="float:right">复制</el-link>
  176. <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
  177. </el-tab-pane>
  178. </el-tabs>
  179. </el-dialog>
  180. <import-table ref="import" @ok="handleQuery" />
  181. </div>
  182. </template>
  183. <script>
  184. import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
  185. import importTable from "./importTable";
  186. import hljs from "highlight.js/lib/highlight";
  187. import "highlight.js/styles/github-gist.css";
  188. hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
  189. hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
  190. hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
  191. hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml"));
  192. hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript"));
  193. hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"));
  194. export default {
  195. name: "Gen",
  196. components: { importTable },
  197. data() {
  198. return {
  199. // 遮罩层
  200. loading: true,
  201. // 唯一标识符
  202. uniqueId: "",
  203. // 选中数组
  204. ids: [],
  205. // 选中表数组
  206. tableNames: [],
  207. // 非单个禁用
  208. single: true,
  209. // 非多个禁用
  210. multiple: true,
  211. // 显示搜索条件
  212. showSearch: true,
  213. // 总条数
  214. total: 0,
  215. // 表数据
  216. tableList: [],
  217. // 日期范围
  218. dateRange: "",
  219. // 查询参数
  220. queryParams: {
  221. pageNum: 1,
  222. pageSize: 10,
  223. tableName: undefined,
  224. tableComment: undefined,
  225. dataName: "master"
  226. },
  227. // 预览参数
  228. preview: {
  229. open: false,
  230. title: "代码预览",
  231. data: {},
  232. activeName: "domain.java"
  233. }
  234. };
  235. },
  236. created() {
  237. localStorage.setItem("dataName", this.queryParams.dataName);
  238. this.getList();
  239. },
  240. activated() {
  241. const time = this.$route.query.t;
  242. if (time != null && time != this.uniqueId) {
  243. this.uniqueId = time;
  244. this.queryParams.pageNum = Number(this.$route.query.pageNum);
  245. this.getList();
  246. }
  247. },
  248. methods: {
  249. /** 查询表集合 */
  250. getList() {
  251. this.loading = true;
  252. listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  253. this.tableList = response.rows;
  254. this.total = response.total;
  255. this.loading = false;
  256. }
  257. );
  258. },
  259. /** 搜索按钮操作 */
  260. handleQuery() {
  261. localStorage.setItem("dataName", this.queryParams.dataName);
  262. this.queryParams.pageNum = 1;
  263. this.getList();
  264. },
  265. /** 生成代码操作 */
  266. handleGenTable(row) {
  267. const tableNames = row.tableName || this.tableNames;
  268. if (tableNames == "") {
  269. this.$modal.msgError("请选择要生成的数据");
  270. return;
  271. }
  272. if(row.genType === "1") {
  273. genCode(row.tableName).then(response => {
  274. this.$modal.msgSuccess("成功生成到自定义路径:" + row.genPath);
  275. });
  276. } else {
  277. this.$download.zip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi");
  278. }
  279. },
  280. /** 同步数据库操作 */
  281. handleSynchDb(row) {
  282. const tableName = row.tableName;
  283. this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
  284. return synchDb(tableName);
  285. }).then(() => {
  286. this.$modal.msgSuccess("同步成功");
  287. }).catch(() => {});
  288. },
  289. /** 打开导入表弹窗 */
  290. openImportTable() {
  291. this.$refs.import.show();
  292. },
  293. /** 重置按钮操作 */
  294. resetQuery() {
  295. this.dateRange = [];
  296. this.resetForm("queryForm");
  297. this.handleQuery();
  298. },
  299. /** 预览按钮 */
  300. handlePreview(row) {
  301. previewTable(row.tableId).then(response => {
  302. this.preview.data = response.data;
  303. this.preview.open = true;
  304. this.preview.activeName = "domain.java";
  305. });
  306. },
  307. /** 高亮显示 */
  308. highlightedCode(code, key) {
  309. const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
  310. var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
  311. const result = hljs.highlight(language, code || "", true);
  312. return result.value || '&nbsp;';
  313. },
  314. /** 复制代码成功 */
  315. clipboardSuccess() {
  316. this.$modal.msgSuccess("复制成功");
  317. },
  318. // 多选框选中数据
  319. handleSelectionChange(selection) {
  320. this.ids = selection.map(item => item.tableId);
  321. this.tableNames = selection.map(item => item.tableName);
  322. this.single = selection.length != 1;
  323. this.multiple = !selection.length;
  324. },
  325. /** 修改按钮操作 */
  326. handleEditTable(row) {
  327. const tableId = row.tableId || this.ids[0];
  328. const tableName = row.tableName || this.tableNames[0];
  329. const params = { pageNum: this.queryParams.pageNum };
  330. this.$tab.openPage("修改[" + tableName + "]生成配置", '/tool/gen-edit/index/' + tableId, params);
  331. },
  332. /** 删除按钮操作 */
  333. handleDelete(row) {
  334. const tableIds = row.tableId || this.ids;
  335. this.$modal.confirm('是否确认删除表编号为"' + tableIds + '"的数据项?').then(function() {
  336. return delTable(tableIds);
  337. }).then(() => {
  338. this.getList();
  339. this.$modal.msgSuccess("删除成功");
  340. }).catch(() => {});
  341. }
  342. }
  343. };
  344. </script>