index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <a-card :bordered="false" v-if="indexShow">
  3. <s-table
  4. ref="table"
  5. :columns="columns"
  6. :data="loadDate"
  7. :expand-row-by-click="true"
  8. :alert="options.alert.show"
  9. bordered
  10. :row-key="(record) => record.id"
  11. :row-selection="options.rowSelection"
  12. :toolConfig="{ refresh: true, height: true, columnSetting: true, striped: false }"
  13. >
  14. <template #operator class="table-operator">
  15. <a-space>
  16. <a-button type="primary" @click="openConfig()"> 新建 </a-button>
  17. <xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteBatchCodeGen" />
  18. </a-space>
  19. </template>
  20. <template #bodyCell="{ column, record }">
  21. <template v-if="column.dataIndex === 'tablePrefix'">
  22. {{ tablePrefixFilter(record.tablePrefix) }}
  23. </template>
  24. <template v-if="column.dataIndex === 'generateType'">
  25. {{ generateTypeFilter(record.generateType) }}
  26. </template>
  27. <template v-if="column.dataIndex === 'action'">
  28. <a @click="genPreviewRef.onOpen(record)">预览</a>
  29. <a-divider type="vertical" />
  30. <a-popconfirm title="确定生成代码?" @confirm="execGen(record)">
  31. <a-button type="link" size="small">生成</a-button>
  32. </a-popconfirm>
  33. <a-divider type="vertical" />
  34. <a @click="openConfig(record)">配置</a>
  35. <a-divider type="vertical" />
  36. <a-popconfirm title="删除此信息?" @confirm="deleteCodeGen(record)">
  37. <a-button type="link" danger size="small">删除</a-button>
  38. </a-popconfirm>
  39. </template>
  40. </template>
  41. </s-table>
  42. </a-card>
  43. <steps v-else ref="stepsRef" @successful="table.refresh(true)" @closed="closeConfig()" />
  44. <genPreview ref="genPreviewRef" />
  45. </template>
  46. <script setup name="genIndex">
  47. import { message } from 'ant-design-vue'
  48. import downloadUtil from '@/utils/downloadUtil'
  49. import steps from './steps.vue'
  50. import genPreview from './preview.vue'
  51. import genBasicApi from '@/api/gen/genBasicApi'
  52. const table = ref()
  53. const indexShow = ref(true)
  54. const stepsRef = ref()
  55. const genPreviewRef = ref()
  56. const columns = [
  57. {
  58. title: '业务名',
  59. dataIndex: 'busName',
  60. ellipsis: true
  61. },
  62. {
  63. title: '功能名',
  64. dataIndex: 'functionName',
  65. ellipsis: true
  66. },
  67. {
  68. title: '类名',
  69. dataIndex: 'className',
  70. ellipsis: true
  71. },
  72. {
  73. title: '包名',
  74. dataIndex: 'packageName',
  75. ellipsis: true
  76. },
  77. {
  78. title: '作者',
  79. dataIndex: 'authorName',
  80. ellipsis: true
  81. },
  82. {
  83. title: '移除表前缀',
  84. dataIndex: 'tablePrefix',
  85. ellipsis: true
  86. },
  87. {
  88. title: '生成方式',
  89. dataIndex: 'generateType',
  90. ellipsis: true
  91. },
  92. {
  93. title: '操作',
  94. dataIndex: 'action',
  95. align: 'center',
  96. width: '220px'
  97. }
  98. ]
  99. // 表格查询 返回 Promise 对象
  100. const loadDate = (parameter) => {
  101. return genBasicApi.basicPage(parameter).then((data) => {
  102. return data
  103. })
  104. }
  105. // 列表选择配置
  106. let selectedRowKeys = ref([])
  107. const options = {
  108. alert: {
  109. show: false,
  110. clear: () => {
  111. selectedRowKeys = ref([])
  112. }
  113. },
  114. rowSelection: {
  115. onChange: (selectedRowKey, selectedRows) => {
  116. selectedRowKeys.value = selectedRowKey
  117. }
  118. }
  119. }
  120. const generateTypeFilter = (text) => {
  121. const array = [
  122. {
  123. label: '压缩包',
  124. value: 'ZIP'
  125. },
  126. {
  127. label: '项目内',
  128. value: 'PRO'
  129. }
  130. ]
  131. return array.find((f) => f.value === text).label
  132. }
  133. const tablePrefixFilter = (text) => {
  134. const array = [
  135. {
  136. label: '移除',
  137. value: 'Y'
  138. },
  139. {
  140. label: '不移除',
  141. value: 'N'
  142. }
  143. ]
  144. return array.find((f) => f.value === text).label
  145. }
  146. // 生成代码
  147. const execGen = (record) => {
  148. const param = {
  149. id: record.id
  150. }
  151. if (record.generateType === 'PRO') {
  152. genBasicApi.basicExecGenPro(param).then(() => {
  153. message.success('操作成功')
  154. table.value.refresh()
  155. })
  156. } else {
  157. // 下载压缩包
  158. genBasicApi.basicExecGenBiz(param).then((res) => {
  159. downloadUtil.resultDownload(res)
  160. })
  161. }
  162. }
  163. // 删除
  164. const deleteCodeGen = (record) => {
  165. let params = [
  166. {
  167. id: record.id
  168. }
  169. ]
  170. genBasicApi.basicDelete(params).then(() => {
  171. table.value.refresh()
  172. })
  173. }
  174. // 批量删除
  175. const deleteBatchCodeGen = (params) => {
  176. genBasicApi.basicDelete(params).then(() => {
  177. table.value.refresh()
  178. })
  179. }
  180. // 打开配置界面
  181. const openConfig = (record) => {
  182. indexShow.value = false
  183. nextTick(() => {
  184. stepsRef.value.configSteps(record)
  185. })
  186. }
  187. // 关闭配置界面
  188. const closeConfig = () => {
  189. indexShow.value = true
  190. }
  191. </script>