Detail.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script setup lang="ts">
  2. import { getTableDetApi } from '@/api/table'
  3. import { PropType, watch, ref, reactive } from 'vue'
  4. import type { TableData } from '@/api/table/types'
  5. import { Descriptions } from '@/components/Descriptions'
  6. import { useI18n } from '@/hooks/web/useI18n'
  7. import { ElTag } from 'element-plus'
  8. const { t } = useI18n()
  9. const props = defineProps({
  10. currentRow: {
  11. type: Object as PropType<Nullable<TableData>>,
  12. default: () => null
  13. }
  14. })
  15. const currentRow = ref<Nullable<TableData>>(null)
  16. const loading = ref(false)
  17. const getTableDet = async () => {
  18. loading.value = true
  19. const res = await getTableDetApi({
  20. params: {
  21. id: props.currentRow?.id as string
  22. }
  23. }).finally(() => {
  24. loading.value = false
  25. })
  26. if (res) {
  27. currentRow.value = res.data
  28. }
  29. }
  30. watch(
  31. () => props.currentRow,
  32. () => {
  33. getTableDet()
  34. },
  35. {
  36. deep: true,
  37. immediate: true
  38. }
  39. )
  40. const schema = reactive<DescriptionsSchema[]>([
  41. {
  42. field: 'title',
  43. label: t('exampleDemo.title'),
  44. span: 24
  45. },
  46. {
  47. field: 'author',
  48. label: t('exampleDemo.author')
  49. },
  50. {
  51. field: 'display_time',
  52. label: t('exampleDemo.displayTime')
  53. },
  54. {
  55. field: 'importance',
  56. label: t('exampleDemo.importance')
  57. },
  58. {
  59. field: 'pageviews',
  60. label: t('exampleDemo.pageviews')
  61. },
  62. {
  63. field: 'content',
  64. label: t('exampleDemo.content'),
  65. span: 24
  66. }
  67. ])
  68. </script>
  69. <template>
  70. <Descriptions v-loading="loading" :schema="schema" :data="currentRow || {}">
  71. <template #importance="{ row }: { row: TableData }">
  72. <ElTag :type="row.importance === 1 ? 'success' : row.importance === 2 ? 'warning' : 'danger'">
  73. {{
  74. row.importance === 1
  75. ? t('tableDemo.important')
  76. : row.importance === 2
  77. ? t('tableDemo.good')
  78. : t('tableDemo.commonly')
  79. }}
  80. </ElTag>
  81. </template>
  82. <template #content="{ row }: { row: TableData }">
  83. <div v-html="row.content"></div>
  84. </template>
  85. </Descriptions>
  86. </template>