index.vue 9.1 KB

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