index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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="6">
  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-option>
  30. </el-select>
  31. </div>
  32. </el-col>
  33. <el-col :span="6">
  34. <div class="grid-content bg-purple">
  35. <el-input v-model="q.tableName" placeholder="表名称"></el-input>
  36. </div>
  37. </el-col>
  38. <el-col :span="6">
  39. <div class="grid-content bg-purple">
  40. <el-button type="primary" size="small" icon="el-icon-search" @click="search">搜索</el-button>
  41. <el-button type="primary" size="small" icon="el-icon-setting" @click="setting" @close="dsBox=false">维护
  42. </el-button>
  43. </div>
  44. </el-col>
  45. </el-row>
  46. <avue-crud ref="crud"
  47. :page="page"
  48. :data="tableData"
  49. :table-loading="tableLoading"
  50. :option="tableOption"
  51. @on-load="getList"
  52. @refresh-change="refreshChange">
  53. <template slot-scope="scope"
  54. slot="menu">
  55. <el-button type="text"
  56. icon="el-icon-check"
  57. size="mini"
  58. plain
  59. @click="handleDown(scope.row,scope.index)">生成
  60. </el-button>
  61. </template>
  62. </avue-crud>
  63. <el-dialog title="生成配置"
  64. :visible.sync="box"
  65. width="50%"
  66. lock-scroll>
  67. <div class="pull-auto">
  68. <avue-form :option="formOption"
  69. ref="formData"
  70. v-model="formData"
  71. @submit="gen()">
  72. </avue-form>
  73. </div>
  74. </el-dialog>
  75. <el-dialog title="数据源管理" :visible.sync="dsBox" width="90%"
  76. :table-loading="tableLoading"
  77. @close="dsBox=false">
  78. <avue-crud ref="data-source-settings-crud"
  79. v-model="dsForm"
  80. :page="dsPage"
  81. :data="tableDsData"
  82. :option="tableDsOption"
  83. :before-open="handleOpenBefore"
  84. @row-update="handleUpdate"
  85. @row-save="handleSave"
  86. @row-del="rowDel"
  87. @refresh-change="refreshDsChange"
  88. @on-load="getDsList">
  89. </avue-crud>
  90. </el-dialog>
  91. </basic-container>
  92. </div>
  93. </template>
  94. <script>
  95. import {addObj, delObj, fetchDsList, fetchList, fetchSelectDsList, handleDown, putObj} from '@/api/gen/gen'
  96. import {formOption, tableDsOption, tableOption} from '@/const/crud/gen/gen'
  97. export default {
  98. name: 'code-generator',
  99. data() {
  100. return {
  101. dsBox: false,
  102. q: {},
  103. dataSourceList: [],
  104. tableData: [],
  105. tableDsData: [],
  106. formData: {},
  107. box: false,
  108. page: {
  109. total: 0, // 总页数
  110. currentPage: 1, // 当前页数
  111. pageSize: 20 // 每页显示多少条
  112. },
  113. dsPage: {
  114. total: 0, // 总页数
  115. currentPage: 1, // 当前页数
  116. pageSize: 20 // 每页显示多少条
  117. },
  118. dsForm: {},
  119. tableLoading: false,
  120. tableOption: tableOption,
  121. tableDsOption: tableDsOption,
  122. formOption: formOption
  123. }
  124. },
  125. created() {
  126. this.getdataSourceList();
  127. },
  128. methods: {
  129. getList(page, params) {
  130. this.tableLoading = true
  131. fetchList(Object.assign({
  132. current: page.currentPage,
  133. size: page.pageSize
  134. }, params)).then(response => {
  135. this.tableData = response.data.data.records
  136. this.page.total = response.data.data.total
  137. this.tableLoading = false
  138. })
  139. },
  140. rowDel: function (row, index) {
  141. this.$confirm('是否确认删除ID为' + row.id, '提示', {
  142. confirmButtonText: '确定',
  143. cancelButtonText: '取消',
  144. type: 'warning'
  145. }).then(function () {
  146. return delObj(row.id)
  147. }).then(data => {
  148. this.tableData.splice(index, 1)
  149. this.$message.success('删除成功')
  150. this.getDsList(this.page)
  151. }).catch(function (err) {
  152. })
  153. },
  154. handleOpenBefore: function (show,type) {
  155. this.dsForm.password = undefined
  156. show()
  157. },
  158. handleUpdate: function (row, index, done) {
  159. putObj(row).then(() => {
  160. this.tableData.splice(index, 1, Object.assign({}, row))
  161. this.$message.success('修改成功')
  162. done()
  163. this.getDsList(this.page)
  164. })
  165. },
  166. handleSave: function (row, done) {
  167. addObj(row).then(() => {
  168. this.tableData.push(Object.assign({}, row))
  169. this.$message.success('添加成功')
  170. done()
  171. this.getDsList(this.page)
  172. })
  173. },
  174. getDsList(page, params) {
  175. fetchDsList(Object.assign({
  176. current: page.currentPage,
  177. size: page.pageSize
  178. }, params)).then(response => {
  179. this.tableDsData = response.data.data.records
  180. this.dsPage.total = response.data.data.total
  181. })
  182. },
  183. handleDown: function (row, index) {
  184. this.formData.tableName = row.tableName
  185. this.box = true
  186. },
  187. refreshChange() {
  188. this.getList(this.page)
  189. },
  190. refreshDsChange() {
  191. this.getDsList(this.page)
  192. },
  193. gen() {
  194. this.formData.id = this.q.id
  195. handleDown(this.formData).then(() => {
  196. this.box = true
  197. })
  198. },
  199. setting() {
  200. this.dsBox = true
  201. },
  202. search() {
  203. this.getList(this.page, this.filterForm(this.q))
  204. },
  205. getdataSourceList() {
  206. fetchSelectDsList().then(response => {
  207. this.dataSourceList = response.data.data
  208. })
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. </style>