index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form class="-mb-15px" :inline="true">
  5. <el-form-item>
  6. <el-button
  7. type="primary"
  8. @click="openModal('create')"
  9. v-hasPermi="['infra:data-source-config:create']"
  10. >
  11. <Icon icon="ep:plus" class="mr-5px" /> 新增
  12. </el-button>
  13. </el-form-item>
  14. </el-form>
  15. </content-wrap>
  16. <!-- 列表 -->
  17. <content-wrap>
  18. <el-table v-loading="loading" :data="list" align="center">
  19. <el-table-column label="主键编号" align="center" prop="id" />
  20. <el-table-column label="数据源名称" align="center" prop="name" />
  21. <el-table-column label="数据源连接" align="center" prop="url" :show-overflow-tooltip="true" />
  22. <el-table-column label="用户名" align="center" prop="username" />
  23. <el-table-column
  24. label="创建时间"
  25. align="center"
  26. prop="createTime"
  27. width="180"
  28. :formatter="dateFormatter"
  29. />
  30. <el-table-column label="操作" align="center">
  31. <template #default="scope">
  32. <el-button
  33. link
  34. type="primary"
  35. @click="openModal('update', scope.row.id)"
  36. v-hasPermi="['infra:data-source-config:update']"
  37. :disabled="scope.row.id === 0"
  38. >
  39. 编辑
  40. </el-button>
  41. <el-button
  42. link
  43. type="danger"
  44. @click="handleDelete(scope.row.id)"
  45. v-hasPermi="['infra:data-source-config:delete']"
  46. :disabled="scope.row.id === 0"
  47. >
  48. 删除
  49. </el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </content-wrap>
  54. <!-- 表单弹窗:添加/修改 -->
  55. <data-source-config-form ref="modalRef" @success="getList" />
  56. </template>
  57. <script setup lang="ts" name="DataSourceConfig">
  58. import { dateFormatter } from '@/utils/formatTime'
  59. import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
  60. import DataSourceConfigForm from './form.vue'
  61. const message = useMessage() // 消息弹窗
  62. const { t } = useI18n() // 国际化
  63. const loading = ref(true) // 列表的加载中
  64. const list = ref([]) // 列表的数据
  65. /** 查询列表 */
  66. const getList = async () => {
  67. loading.value = true
  68. try {
  69. list.value = await DataSourceConfigApi.getDataSourceConfigList()
  70. } finally {
  71. loading.value = false
  72. }
  73. }
  74. /** 添加/修改操作 */
  75. const modalRef = ref()
  76. const openModal = (type: string, id?: number) => {
  77. modalRef.value.openModal(type, id)
  78. }
  79. /** 删除按钮操作 */
  80. const handleDelete = async (id: number) => {
  81. try {
  82. // 删除的二次确认
  83. await message.delConfirm()
  84. // 发起删除
  85. await DataSourceConfigApi.deleteDataSourceConfig(id)
  86. message.success(t('common.delSuccess'))
  87. // 刷新列表
  88. await getList()
  89. } catch {}
  90. }
  91. /** 初始化 **/
  92. onMounted(() => {
  93. getList()
  94. })
  95. </script>