index.vue 7.9 KB

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