index.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, { useRef, useState } from 'react'
  2. import List from '@/components/Page/List'
  3. import { Button, Tag, Image } from 'antd'
  4. import { useNavigate } from 'react-router-dom'
  5. import { getTaPost, deleteTaPost } from "@/services/taPost";
  6. export default (props) => {
  7. const actionRef = useRef();
  8. const navigate = useNavigate();
  9. const columns = [
  10. {
  11. title: '标题',
  12. dataIndex: 'title',
  13. ellipsis: true,
  14. },
  15. {
  16. title: '描述',
  17. dataIndex: 'describe',
  18. ellipsis: true,
  19. search: false,
  20. },
  21. {
  22. title: '正文',
  23. dataIndex: 'content',
  24. render: (_, it) =>
  25. <div style={{ width: '9vw' }}>
  26. <div dangerouslySetInnerHTML={{ __html: it?.content }} style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap' }} />
  27. </div>,
  28. search: false,
  29. },
  30. {
  31. title: '图片',
  32. dataIndex: 'images',
  33. render: (_, it) => it?.images ? <Image src={`${prefix}` + JSON.parse(it?.images)[0]} width={80} /> : null,
  34. search: false,
  35. },
  36. // {
  37. // title: '横向封面',
  38. // dataIndex: 'coverHorizontal',
  39. // render: (_, it) => it?.coverHorizontal ? <Image src={`${prefix}` + it?.coverHorizontal} width={80} /> : null,
  40. // search: false,
  41. // },
  42. // {
  43. // title: '纵向封面',
  44. // dataIndex: 'coverVertical',
  45. // render: (_, it) => it?.coverVertical ? <Image src={`${prefix}` + it?.coverVertical} width={80} /> : null,
  46. // search: false,
  47. // },
  48. {
  49. title: '标签',
  50. dataIndex: 'tags',
  51. search: false,
  52. render: (_, it) => it?.tags ? JSON.parse(it?.tags).map(it => <Tag color="red">{it}</Tag>) : null
  53. },
  54. {
  55. title: '作者',
  56. dataIndex: 'author'
  57. },
  58. {
  59. title: '链接',
  60. dataIndex: 'link',
  61. ellipsis: true,
  62. render: (_, it) =>
  63. <div style={{ width: '8vw' }}>
  64. <div style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap' }}><a href="#">{it?.link}</a></div>
  65. </div>,
  66. search: false,
  67. },
  68. // {
  69. // title: '附件',
  70. // dataIndex: 'attachment',
  71. // search: false,
  72. // }
  73. ]
  74. const onEdit = (it) => {
  75. navigate(`/article/edit?id=${it.postId}`)
  76. }
  77. const onDelete = (it) => {
  78. deleteTaPost(it.postId).then(res => {
  79. actionRef.current.reload();
  80. })
  81. }
  82. const onDetail = (it) => {
  83. navigate(`/article/detail?id=${it.postId}`)
  84. }
  85. return (
  86. <List
  87. rowKey="postId"
  88. columns={columns}
  89. actionRef={actionRef}
  90. onEdit={onEdit}
  91. onDelete={onDelete}
  92. // onDetail={onDetail}
  93. request={getTaPost}
  94. toolBarRender={() => [
  95. <Button
  96. key="2"
  97. type="primary"
  98. onClick={() => {
  99. navigate('/article/edit')
  100. }}
  101. >
  102. 新增
  103. </Button>
  104. ]}
  105. />
  106. )
  107. }