index.vue 4.6 KB

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