Detail.vue 2.1 KB

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