index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <a-card :bordered="false" style="margin-bottom: 10px">
  3. <a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
  4. <a-row :gutter="24">
  5. <a-col :span="8">
  6. <a-form-item name="poolName" label="数据源名称">
  7. <a-input v-model:value="searchFormState.poolName" placeholder="请输入数据源名称" />
  8. </a-form-item>
  9. </a-col>
  10. <a-col :span="8">
  11. <a-button type="primary" @click="table.refresh(true)">
  12. <template #icon><SearchOutlined /></template>
  13. 查询
  14. </a-button>
  15. <a-button class="snowy-buttom-left" @click="reset">
  16. <template #icon><redo-outlined /></template>
  17. 重置
  18. </a-button>
  19. </a-col>
  20. </a-row>
  21. </a-form>
  22. </a-card>
  23. <a-card :bordered="false">
  24. <s-table
  25. ref="table"
  26. :columns="columns"
  27. :data="loadData"
  28. :expand-row-by-click="true"
  29. :alert="options.alert.show"
  30. bordered
  31. :row-key="(record) => record.id"
  32. :row-selection="options.rowSelection"
  33. >
  34. <template #operator class="table-operator">
  35. <a-space>
  36. <a-button type="primary" @click="form.onOpen()">
  37. <template #icon><plus-outlined /></template>
  38. 新增
  39. </a-button>
  40. <xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteBatchDbs" />
  41. </a-space>
  42. </template>
  43. <template #bodyCell="{ column, record }">
  44. <template v-if="column.dataIndex === 'category'">
  45. <a-tag v-if="record.category === 'MASTER'" color="pink">
  46. {{ $TOOL.dictTypeData('DBS_CATEGORY', record.category) }}
  47. </a-tag>
  48. <div v-else>
  49. {{ $TOOL.dictTypeData('DBS_CATEGORY', record.category) }}
  50. </div>
  51. </template>
  52. <template v-if="column.dataIndex === 'driverName'">
  53. <a-tag color="cyan">
  54. {{ $TOOL.dictTypeData('DATABASE_DRIVE_TYPE', record.driverName) }}
  55. </a-tag>
  56. </template>
  57. <template v-if="column.dataIndex === 'action'">
  58. <a @click="form.onOpen(record)">编辑</a>
  59. <a-divider type="vertical" />
  60. <a-popconfirm title="确定删除此数据源?" @confirm="remove(record)">
  61. <a-button type="link" danger size="small">删除</a-button>
  62. </a-popconfirm>
  63. </template>
  64. </template>
  65. </s-table>
  66. </a-card>
  67. <Form ref="form" @successful="table.refresh(true)" />
  68. </template>
  69. <script setup name="dbs">
  70. import dbsApi from '@/api/dbs/dbsApi'
  71. import Form from './form.vue'
  72. const columns = [
  73. {
  74. title: '数据源名称',
  75. dataIndex: 'poolName',
  76. ellipsis: true
  77. },
  78. {
  79. title: '驱动类型',
  80. dataIndex: 'driverName'
  81. },
  82. {
  83. title: '分类',
  84. dataIndex: 'category'
  85. },
  86. {
  87. title: '连接URL',
  88. dataIndex: 'url',
  89. ellipsis: true
  90. },
  91. {
  92. title: '排序',
  93. dataIndex: 'sortCode'
  94. },
  95. {
  96. title: '操作',
  97. dataIndex: 'action',
  98. align: 'center',
  99. width: '150px'
  100. }
  101. ]
  102. let selectedRowKeys = ref([])
  103. // 列表选择配置
  104. const options = {
  105. alert: {
  106. show: false,
  107. clear: () => {
  108. selectedRowKeys = ref([])
  109. }
  110. },
  111. rowSelection: {
  112. onChange: (selectedRowKey, selectedRows) => {
  113. selectedRowKeys.value = selectedRowKey
  114. }
  115. }
  116. }
  117. // 定义tableDOM
  118. const table = ref(null)
  119. const form = ref()
  120. const searchFormRef = ref()
  121. let searchFormState = reactive({})
  122. // 表格查询 返回 Promise 对象
  123. const loadData = (parameter) => {
  124. return dbsApi.dbsPage(Object.assign(parameter, searchFormState)).then((data) => {
  125. return data
  126. })
  127. }
  128. // 重置
  129. const reset = () => {
  130. searchFormRef.value.resetFields()
  131. table.value.refresh(true)
  132. }
  133. // 删除
  134. const remove = (record) => {
  135. let params = [
  136. {
  137. id: record.id
  138. }
  139. ]
  140. dbsApi.dbsDelete(params).then(() => {
  141. table.value.refresh()
  142. })
  143. }
  144. // 批量删除
  145. const deleteBatchDbs = (params) => {
  146. dbsApi.dbsDelete(params).then(() => {
  147. table.value.clearRefreshSelected()
  148. })
  149. }
  150. </script>
  151. <style scoped>
  152. .ant-form-item {
  153. margin-bottom: 0 !important;
  154. }
  155. .primaryAdd {
  156. margin-right: 10px;
  157. }
  158. .snowy-buttom-left {
  159. margin-left: 8px;
  160. }
  161. </style>