index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="execution">
  19. <basic-container>
  20. <el-row :gutter="20">
  21. <el-col :span="4">
  22. <div class="grid-content bg-purple">
  23. <el-select v-model="q.id" placeholder="请选择数据源">
  24. <el-option
  25. v-for="item in dataSourceList"
  26. :key="item.id"
  27. :label="item.name"
  28. :value="item.id"/>
  29. </el-select>
  30. </div>
  31. </el-col>
  32. <el-col :span="4">
  33. <div class="grid-content bg-purple">
  34. <el-input v-model="q.tableName" placeholder="表名称"/>
  35. </div>
  36. </el-col>
  37. <el-col :span="12">
  38. <div class="grid-content bg-purple">
  39. <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
  40. <el-button type="primary" icon="el-icon-download" @click="openBatch">批量生成</el-button>
  41. </div>
  42. </el-col>
  43. </el-row>
  44. <avue-crud
  45. ref="crud"
  46. :page="page"
  47. :data="tableData"
  48. :table-loading="tableLoading"
  49. :option="tableOption"
  50. @on-load="getList"
  51. @refresh-change="refreshChange">
  52. <template
  53. slot-scope="scope"
  54. slot="menu">
  55. <el-button
  56. type="text"
  57. icon="el-icon-check"
  58. @click="handleDown(scope.row,scope.index)">生成
  59. </el-button>
  60. </template>
  61. </avue-crud>
  62. <el-dialog
  63. :visible.sync="box"
  64. title="生成配置"
  65. width="50%"
  66. lock-scroll>
  67. <div class="pull-auto">
  68. <avue-form
  69. ref="formData"
  70. :option="formOption"
  71. v-model="formData"
  72. @submit="gen()"/>
  73. </div>
  74. </el-dialog>
  75. <el-dialog
  76. :visible.sync="boxBatch"
  77. title="批量生成"
  78. width="50%"
  79. lock-scroll>
  80. <div class="pull-auto">
  81. <avue-form
  82. ref="formBatchData"
  83. :option="formBatchOption"
  84. v-model="formBatchData"
  85. @submit="batchGen()"/>
  86. </div>
  87. </el-dialog>
  88. </basic-container>
  89. </div>
  90. </template>
  91. <script>
  92. import {fetchList, fetchSelectDsList, handleDown} from '@/api/gen/gen'
  93. import {formBatchOption, formOption, tableOption} from '@/const/crud/gen/gen'
  94. export default {
  95. name: 'CodeGenerator',
  96. data() {
  97. return {
  98. q: {},
  99. dataSourceList: [],
  100. tableData: [],
  101. formData: {},
  102. formBatchData: {},
  103. box: false,
  104. boxBatch: false,
  105. page: {
  106. total: 0, // 总页数
  107. currentPage: 1, // 当前页数
  108. pageSize: 20 // 每页显示多少条
  109. },
  110. tableLoading: false,
  111. tableOption: tableOption,
  112. formOption: formOption,
  113. formBatchOption: formBatchOption
  114. }
  115. },
  116. created() {
  117. this.getdataSourceList()
  118. },
  119. methods: {
  120. getList(page) {
  121. this.tableLoading = true
  122. fetchList(Object.assign({
  123. current: page.currentPage,
  124. size: page.pageSize
  125. }, this.q)).then(response => {
  126. this.tableData = response.data.data.records
  127. this.page.total = response.data.data.total
  128. this.tableLoading = false
  129. })
  130. },
  131. handleDown: function (row) {
  132. this.formData.tableName = row.tableName
  133. this.box = true
  134. },
  135. refreshChange() {
  136. this.getList(this.page)
  137. },
  138. gen() {
  139. this.formData.id = this.q.id
  140. handleDown(this.formData).then(() => {
  141. this.box = false
  142. })
  143. },
  144. getdataSourceList() {
  145. fetchSelectDsList().then(response => {
  146. this.dataSourceList = response.data.data
  147. })
  148. },
  149. search() {
  150. this.getList(this.page)
  151. },
  152. openBatch() {
  153. if (this.$refs.crud.tableSelect.length <= 1 || this.$refs.crud.tableSelect.length > 10) {
  154. this.$message.error('选中表数量不合法,数量最多10个')
  155. return false
  156. }
  157. let tableName = []
  158. for (const table of this.$refs.crud.tableSelect) {
  159. tableName.push(table.tableName)
  160. }
  161. this.formBatchData.tableName = tableName.join('-')
  162. this.boxBatch = true
  163. },
  164. batchGen() {
  165. this.formBatchData.id = this.q.id
  166. handleDown(this.formBatchData).then(() => {
  167. this.boxBatch = false
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. </style>