ip-list.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <script setup>
  2. import { ref, shallowRef, computed } from 'vue'
  3. import { useRoute } from 'vue-router'
  4. import { PlusOutlined } from '@ant-design/icons-vue'
  5. import CrudTableModal from './components/ip-list-modal.vue'
  6. import { getListApi, deleteApi } from '~@/api/list/gateway-group-ip-list.js'
  7. import { useTableQuery } from '~@/composables/table-query'
  8. const route = useRoute()
  9. const message = useMessage()
  10. const gatewayGroupId = computed(() => Number(route.query.id || 0))
  11. const columns = shallowRef([
  12. { title: 'ID', dataIndex: 'id', key: 'id' },
  13. { title: '网关组ID', dataIndex: 'gatewayGroupId', key: 'gatewayGroupId' },
  14. { title: 'IP地址', dataIndex: 'ip', key: 'ip' },
  15. { title: '标签', dataIndex: 'tag', key: 'tag' },
  16. { title: '归属地', dataIndex: 'originPlace', key: 'originPlace' },
  17. { title: '备注', dataIndex: 'comment', key: 'comment' },
  18. { title: '创建时间', dataIndex: 'createdAt', key: 'createdAt' },
  19. { title: '更新时间', dataIndex: 'updatedAt', key: 'updatedAt' },
  20. { title: '操作', dataIndex: 'action', key: 'action' },
  21. ])
  22. const { state, initQuery, resetQuery, query } = useTableQuery({
  23. queryApi: getListApi,
  24. queryParams: {
  25. gatewayGroupId: gatewayGroupId.value,
  26. ip: undefined,
  27. },
  28. afterQuery: (res) => {
  29. console.log('afterQuery', res)
  30. if (!res || !Array.isArray(res.records)) {
  31. // 如果数据格式不正确,返回一个空状态,防止程序崩溃
  32. return { list: [], total: 0 }
  33. }
  34. return res
  35. },
  36. })
  37. const crudTableModal = ref()
  38. async function handleDelete(record) {
  39. if (!record.id) return message.error('id 不能为空')
  40. try {
  41. const res = await deleteApi(record.id)
  42. if (res.code === 0) {
  43. await query()
  44. message.success('删除成功')
  45. }
  46. } catch (e) {
  47. console.log(e)
  48. }
  49. }
  50. function handleAdd() {
  51. crudTableModal.value?.open({ gatewayGroupId: gatewayGroupId.value })
  52. }
  53. function handleEdit(record) {
  54. crudTableModal.value?.open(record)
  55. }
  56. </script>
  57. <template>
  58. <page-container>
  59. <a-card mb-4>
  60. <a-form class="system-crud-wrapper" :label-col="{ span: 7 }" :model="state.queryParams">
  61. <a-row :gutter="[15, 0]">
  62. <a-col :span="6">
  63. <a-form-item name="ip" label="IP地址">
  64. <a-input v-model:value="state.queryParams.ip" placeholder="请输入IP地址" />
  65. </a-form-item>
  66. </a-col>
  67. <a-col :span="6">
  68. <a-space flex justify-end w-full>
  69. <a-button :loading="state.loading" type="primary" @click="initQuery">
  70. 查询
  71. </a-button>
  72. <a-button :loading="state.loading" @click="resetQuery">
  73. 重置
  74. </a-button>
  75. </a-space>
  76. </a-col>
  77. </a-row>
  78. </a-form>
  79. </a-card>
  80. <a-card title="IP列表">
  81. <template #extra>
  82. <a-space size="middle">
  83. <a-button type="primary" @click="handleAdd">
  84. <template #icon>
  85. <PlusOutlined />
  86. </template>
  87. 新增
  88. </a-button>
  89. </a-space>
  90. </template>
  91. <a-table
  92. row-key="id"
  93. :loading="state.loading"
  94. :columns="columns"
  95. :data-source="state.dataSource"
  96. :pagination="state.pagination"
  97. >
  98. <template #bodyCell="scope">
  99. <template v-if="scope?.column?.dataIndex === 'action'">
  100. <div flex gap-2>
  101. <a-button type="link" @click="handleEdit(scope?.record)">
  102. 编辑
  103. </a-button>
  104. <a-popconfirm
  105. title="确定删除该条数据?"
  106. ok-text="确定"
  107. cancel-text="取消"
  108. @confirm="handleDelete(scope?.record)"
  109. >
  110. <a-button type="link">
  111. 删除
  112. </a-button>
  113. </a-popconfirm>
  114. </div>
  115. </template>
  116. </template>
  117. </a-table>
  118. </a-card>
  119. <CrudTableModal ref="crudTableModal" @ok="query" />
  120. </page-container>
  121. </template>