|
|
|
@ -21,108 +21,110 @@ import { NPopover, NButton, NIcon, NPopconfirm, NSpace } from 'naive-ui'
|
|
|
|
|
import { EditOutlined, DeleteOutlined } from '@vicons/antd' |
|
|
|
|
import JsonHighlight from './json-highlight' |
|
|
|
|
import ButtonLink from '@/components/button-link' |
|
|
|
|
import { TableColumns } from './types' |
|
|
|
|
import type { TableColumns } from './types' |
|
|
|
|
|
|
|
|
|
export function useColumns(onCallback: Function) { |
|
|
|
|
const { t } = useI18n() |
|
|
|
|
|
|
|
|
|
const columnsRef: TableColumns = [ |
|
|
|
|
{ |
|
|
|
|
title: '#', |
|
|
|
|
key: 'index', |
|
|
|
|
render: (rowData, rowIndex) => rowIndex + 1 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_name'), |
|
|
|
|
key: 'name' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_user_name'), |
|
|
|
|
key: 'userName' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_type'), |
|
|
|
|
key: 'type' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_parameter'), |
|
|
|
|
key: 'parameter', |
|
|
|
|
render: (rowData) => { |
|
|
|
|
return h( |
|
|
|
|
NPopover, |
|
|
|
|
{ trigger: 'click' }, |
|
|
|
|
{ |
|
|
|
|
trigger: () => |
|
|
|
|
h(ButtonLink, null, { |
|
|
|
|
default: () => t('datasource.click_to_view') |
|
|
|
|
}), |
|
|
|
|
default: () => h(JsonHighlight, { rowData }) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
const getColumns = (): TableColumns => { |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
title: '#', |
|
|
|
|
key: 'index', |
|
|
|
|
render: (rowData, rowIndex) => rowIndex + 1 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_name'), |
|
|
|
|
key: 'name' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_user_name'), |
|
|
|
|
key: 'userName' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_type'), |
|
|
|
|
key: 'type' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.datasource_parameter'), |
|
|
|
|
key: 'parameter', |
|
|
|
|
render: (rowData) => { |
|
|
|
|
return h( |
|
|
|
|
NPopover, |
|
|
|
|
{ trigger: 'click' }, |
|
|
|
|
{ |
|
|
|
|
trigger: () => |
|
|
|
|
h(ButtonLink, null, { |
|
|
|
|
default: () => t('datasource.click_to_view') |
|
|
|
|
}), |
|
|
|
|
default: () => h(JsonHighlight, { rowData }) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.description'), |
|
|
|
|
key: 'note' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.create_time'), |
|
|
|
|
key: 'createTime' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.update_time'), |
|
|
|
|
key: 'updateTime' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.operation'), |
|
|
|
|
key: 'operation', |
|
|
|
|
width: 150, |
|
|
|
|
render: (rowData, unused) => { |
|
|
|
|
return h(NSpace, null, { |
|
|
|
|
default: () => [ |
|
|
|
|
h( |
|
|
|
|
NButton, |
|
|
|
|
{ |
|
|
|
|
circle: true, |
|
|
|
|
type: 'info', |
|
|
|
|
onClick: () => void onCallback(rowData.id, 'edit') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
default: () => |
|
|
|
|
h(NIcon, null, { default: () => h(EditOutlined) }) |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
h( |
|
|
|
|
NPopconfirm, |
|
|
|
|
{ |
|
|
|
|
onPositiveClick: () => void onCallback(rowData.id, 'delete'), |
|
|
|
|
negativeText: t('datasource.cancel'), |
|
|
|
|
positiveText: t('datasource.confirm') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
trigger: () => |
|
|
|
|
h( |
|
|
|
|
NButton, |
|
|
|
|
{ |
|
|
|
|
circle: true, |
|
|
|
|
type: 'error', |
|
|
|
|
class: 'btn-delete' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
default: () => |
|
|
|
|
h(NIcon, null, { default: () => h(DeleteOutlined) }) |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
default: () => t('datasource.delete') |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.description'), |
|
|
|
|
key: 'note' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.create_time'), |
|
|
|
|
key: 'createTime' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.update_time'), |
|
|
|
|
key: 'updateTime' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: t('datasource.operation'), |
|
|
|
|
key: 'operation', |
|
|
|
|
width: 150, |
|
|
|
|
render: (rowData, unused) => { |
|
|
|
|
return h(NSpace, null, { |
|
|
|
|
default: () => [ |
|
|
|
|
h( |
|
|
|
|
NButton, |
|
|
|
|
{ |
|
|
|
|
circle: true, |
|
|
|
|
type: 'info', |
|
|
|
|
onClick: () => void onCallback(rowData.id, 'edit') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
default: () => |
|
|
|
|
h(NIcon, null, { default: () => h(EditOutlined) }) |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
h( |
|
|
|
|
NPopconfirm, |
|
|
|
|
{ |
|
|
|
|
onPositiveClick: () => void onCallback(rowData.id, 'delete'), |
|
|
|
|
negativeText: t('datasource.cancel'), |
|
|
|
|
positiveText: t('datasource.confirm') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
trigger: () => |
|
|
|
|
h( |
|
|
|
|
NButton, |
|
|
|
|
{ |
|
|
|
|
circle: true, |
|
|
|
|
type: 'error', |
|
|
|
|
class: 'btn-delete' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
default: () => |
|
|
|
|
h(NIcon, null, { default: () => h(DeleteOutlined) }) |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
default: () => t('datasource.delete') |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
columnsRef |
|
|
|
|
getColumns |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|