use-columns.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import { h } from 'vue'
  18. import { useI18n } from 'vue-i18n'
  19. import { NPopover, NButton, NIcon, NPopconfirm, NSpace } from 'naive-ui'
  20. import { EditOutlined, DeleteOutlined } from '@vicons/antd'
  21. import JsonHighlight from './json-highlight'
  22. import styles from './index.module.scss'
  23. import { TableColumns } from './types'
  24. export function useColumns(onCallback: Function) {
  25. const { t } = useI18n()
  26. const columnsRef: TableColumns = [
  27. {
  28. title: t('datasource.serial_number'),
  29. key: 'index',
  30. render: (rowData, rowIndex) => rowIndex + 1
  31. },
  32. {
  33. title: t('datasource.datasource_name'),
  34. key: 'name'
  35. },
  36. {
  37. title: t('datasource.datasource_user_name'),
  38. key: 'userName'
  39. },
  40. {
  41. title: t('datasource.datasource_type'),
  42. key: 'type'
  43. },
  44. {
  45. title: t('datasource.datasource_parameter'),
  46. key: 'parameter',
  47. render: (rowData) => {
  48. return h(
  49. NPopover,
  50. { trigger: 'click' },
  51. {
  52. trigger: () =>
  53. h(
  54. NButton,
  55. {
  56. quaternary: true,
  57. type: 'primary'
  58. },
  59. {
  60. default: () => t('datasource.click_to_view')
  61. }
  62. ),
  63. default: () => h(JsonHighlight, { rowData })
  64. }
  65. )
  66. }
  67. },
  68. {
  69. title: t('datasource.description'),
  70. key: 'note'
  71. },
  72. {
  73. title: t('datasource.create_time'),
  74. key: 'createTime'
  75. },
  76. {
  77. title: t('datasource.update_time'),
  78. key: 'updateTime'
  79. },
  80. {
  81. title: t('datasource.operation'),
  82. key: 'operation',
  83. width: 150,
  84. render: (rowData, rowIndex) => {
  85. return h(NSpace, null, {
  86. default: () => [
  87. h(
  88. NButton,
  89. {
  90. circle: true,
  91. type: 'info',
  92. onClick: () => void onCallback(rowData.id, 'edit')
  93. },
  94. {
  95. default: () =>
  96. h(NIcon, null, { default: () => h(EditOutlined) })
  97. }
  98. ),
  99. h(
  100. NPopconfirm,
  101. {
  102. onPositiveClick: () => void onCallback(rowData.id, 'delete'),
  103. negativeText: t('datasource.cancel'),
  104. positiveText: t('datasource.confirm')
  105. },
  106. {
  107. trigger: () =>
  108. h(
  109. NButton,
  110. {
  111. circle: true,
  112. type: 'error'
  113. },
  114. {
  115. default: () =>
  116. h(NIcon, null, { default: () => h(DeleteOutlined) })
  117. }
  118. ),
  119. default: () => t('datasource.delete')
  120. }
  121. )
  122. ]
  123. })
  124. }
  125. }
  126. ]
  127. return {
  128. columnsRef
  129. }
  130. }