Detail.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div>
  3. <com-detail :data="form" :schema="fromSchema" :collapsed="false" title="文章详情">
  4. <template #contentContent="scope">
  5. <div v-html="scope.row.content"></div>
  6. </template>
  7. </com-detail>
  8. <div class="dialong__button--wrap">
  9. <el-button @click="close">取消</el-button>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup lang="ts" name="Detail">
  14. import { PropType, reactive } from 'vue'
  15. import { getExampDetApi } from '../api'
  16. import { SchemaConfig } from '_c/ComDetail/types'
  17. const fromSchema: SchemaConfig[] = [
  18. {
  19. field: 'title',
  20. label: '标题',
  21. span: 24
  22. },
  23. {
  24. field: 'author',
  25. label: '作者'
  26. },
  27. {
  28. field: 'display_time',
  29. label: '创建时间'
  30. },
  31. {
  32. field: 'importance',
  33. label: '重要性'
  34. },
  35. {
  36. field: 'pageviews',
  37. label: '阅读数'
  38. },
  39. {
  40. field: 'content',
  41. label: '内容',
  42. span: 24
  43. }
  44. ]
  45. const props = defineProps({
  46. info: {
  47. type: Object as PropType<Nullable<IObj>>,
  48. default: () => null
  49. }
  50. })
  51. const emit = defineEmits(['close'])
  52. const form = reactive<IObj>({
  53. id: '', // id
  54. author: '', // 作者
  55. title: '', // 标题
  56. content: '', // 内容
  57. importance: '', // 重要性
  58. display_time: '', // 创建时间
  59. pageviews: 0 // 阅读数
  60. })
  61. async function getDet() {
  62. if (props.info) {
  63. const id = props.info.id
  64. try {
  65. const res: any = await getExampDetApi({
  66. params: {
  67. id: id
  68. }
  69. })
  70. if (res) {
  71. for (const key in form) {
  72. if (key === 'importance') {
  73. form[key] = (res.data[key] as number).toString()
  74. } else {
  75. form[key] = res.data[key]
  76. }
  77. }
  78. }
  79. } catch (e) {
  80. console.log(e)
  81. }
  82. }
  83. }
  84. function close() {
  85. emit('close')
  86. }
  87. getDet()
  88. </script>