index.vue 9.8 KB

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