index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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="请选择数据源" @change="search">
  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. <el-button
  61. type="text"
  62. icon="icon-sheji"
  63. @click="handleDesign(scope.row,scope.index)">设计
  64. </el-button>
  65. </template>
  66. </avue-crud>
  67. <el-dialog
  68. :visible.sync="box"
  69. title="生成配置"
  70. width="50%"
  71. lock-scroll>
  72. <div class="pull-auto">
  73. <avue-form
  74. ref="formData"
  75. :option="formOption"
  76. v-model="formData"
  77. @submit="gen"/>
  78. </div>
  79. </el-dialog>
  80. <el-dialog
  81. :visible.sync="boxBatch"
  82. title="批量生成"
  83. width="50%"
  84. lock-scroll>
  85. <div class="pull-auto">
  86. <avue-form
  87. ref="formBatchData"
  88. :option="formBatchOption"
  89. v-model="formBatchData"
  90. @submit="batchGen"/>
  91. </div>
  92. </el-dialog>
  93. </basic-container>
  94. </div>
  95. </template>
  96. <script>
  97. import {fetchList, fetchSelectDsList, handleDown} from '@/api/gen/gen'
  98. import {formBatchOption, formOption, tableOption} from '@/const/crud/gen/gen'
  99. export default {
  100. name: 'CodeGenerator',
  101. data() {
  102. return {
  103. q: {},
  104. dataSourceList: [],
  105. tableData: [],
  106. formData: {},
  107. formBatchData: {},
  108. box: false,
  109. boxBatch: false,
  110. page: {
  111. total: 0, // 总页数
  112. currentPage: 1, // 当前页数
  113. pageSize: 20 // 每页显示多少条
  114. },
  115. tableLoading: false,
  116. tableOption: tableOption,
  117. formOption: formOption,
  118. formBatchOption: formBatchOption
  119. }
  120. },
  121. created() {
  122. this.getdataSourceList()
  123. },
  124. methods: {
  125. getList(page) {
  126. this.tableLoading = true
  127. fetchList(Object.assign({
  128. current: page.currentPage,
  129. size: page.pageSize
  130. }, this.q)).then(response => {
  131. this.tableData = response.data.data.records
  132. this.page.total = response.data.data.total
  133. this.tableLoading = false
  134. })
  135. },
  136. handleDesign: function (row) {
  137. this.$router.push({path: '/gen/design', query: {tableName: row.tableName, dsId: this.q.id}})
  138. },
  139. handleDown: function (row) {
  140. this.formData.tableName = row.tableName
  141. this.box = true
  142. },
  143. refreshChange() {
  144. this.getList(this.page)
  145. },
  146. gen(form,done) {
  147. this.formData.id = this.q.id
  148. handleDown(this.formData).then(() => {
  149. done()
  150. this.box = false
  151. }).catch(()=>{
  152. done()
  153. })
  154. },
  155. getdataSourceList() {
  156. fetchSelectDsList().then(response => {
  157. this.dataSourceList = response.data.data
  158. })
  159. },
  160. search() {
  161. this.getList(this.page)
  162. },
  163. openBatch() {
  164. if (this.$refs.crud.tableSelect.length <= 1 || this.$refs.crud.tableSelect.length > 10) {
  165. this.$message.error('选中表数量不合法,数量最少2个或最多为10个')
  166. return false
  167. }
  168. let tableName = []
  169. for (const table of this.$refs.crud.tableSelect) {
  170. tableName.push(table.tableName)
  171. }
  172. this.formBatchData.tableName = tableName.join('-')
  173. this.boxBatch = true
  174. },
  175. batchGen(form,done) {
  176. this.formBatchData.id = this.q.id
  177. handleDown(this.formBatchData).then(() => {
  178. done()
  179. this.boxBatch = false
  180. }).catch(()=>{
  181. done()
  182. })
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. </style>