index.tsx.bak 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import * as React from 'react';
  2. import { Table, TableColumnsType, TablePaginationConfig,Drawer } from 'antd';
  3. import { StepForwardOutlined } from '@ant-design/icons';
  4. import dayjs from 'dayjs';
  5. import store from './store';
  6. import { Record } from './types';
  7. import './style.less';
  8. import LocalStorage from '@/LocalStorage';
  9. import InfoModal from './components/InfoModal';
  10. import PreviewModal from './components/PreviewModal';
  11. import AuditHistory from './components/auditHistory';
  12. const KnowledgeLibList: React.FC = () => {
  13. const {
  14. state,
  15. onChangePagination,
  16. onClickCreate,
  17. onClickModify,
  18. onClickfetchTakaiApplicationDetail,
  19. infoModalOnClickConfirm,
  20. infoModalOnClickCancel,
  21. infoModalOnClickClose,
  22. init,
  23. reset
  24. } = store;
  25. const {
  26. listLoading,
  27. list,
  28. infoModalId,
  29. infoModalOpen,
  30. page
  31. } = state;
  32. const [drawerFlag, setDrawerFlag] = React.useState<boolean>(false);
  33. const [drawerData, setDrawerData] = React.useState<any>({});
  34. const [historyOpen, setHistoryOpen] = React.useState<boolean>(false);
  35. React.useEffect(() => {
  36. const userInfo = LocalStorage.getUserInfo();
  37. const userId = (userInfo?.id ?? '').toString();
  38. init(userId);
  39. // 监听面包屑创建知识库事件
  40. const handleKnowledgeLibCreate = (event: CustomEvent) => {
  41. if (event.detail.platform === 'auditHistory') {
  42. // onClickCreate();
  43. setHistoryOpen(true);
  44. }
  45. };
  46. window.addEventListener('auditHistory', handleKnowledgeLibCreate as EventListener);
  47. return () => {
  48. reset();
  49. window.removeEventListener('auditHistory', handleKnowledgeLibCreate as EventListener);
  50. };
  51. }, []);
  52. const columns: TableColumnsType<Record> = [
  53. {
  54. title: '序号',
  55. dataIndex: 'index',
  56. width: 80,
  57. render: (text, record, index) => {
  58. return index + 1;
  59. }
  60. },
  61. {
  62. title: '知识名称',
  63. dataIndex: 'name',
  64. render: (text, record) => {
  65. // const previewUrl = `/preview/${record.url}`; // 根据实际字段构造 URL
  66. return (
  67. <a
  68. href={record.url}
  69. target="_blank"
  70. rel="noopener noreferrer"
  71. onClick={(e) => {
  72. e.stopPropagation(); // 防止 Table 默认事件干扰
  73. }}
  74. >
  75. {text}
  76. </a>
  77. );
  78. }
  79. },
  80. {
  81. title: '状态',
  82. dataIndex: 'status',
  83. render: (text) => {
  84. if (text === '1') {
  85. return '待审核';
  86. }else if(text === '2'){
  87. return '审核中';
  88. }else if(text === '3'){
  89. return '审核通过';
  90. }else if(text === '4'||text === '5'){
  91. return '审核拒绝';
  92. }
  93. }
  94. },
  95. {
  96. title: '审核人',
  97. dataIndex: 'userName',
  98. render: (text) => {
  99. return `${text}`;
  100. }
  101. },
  102. {
  103. title: '审核意见',
  104. dataIndex: 'comment',
  105. render: (text) => {
  106. if(text){
  107. return `${text}`;
  108. }else{
  109. return '--';
  110. }
  111. }
  112. },
  113. {
  114. title: '创建时间',
  115. dataIndex: 'createTime',
  116. width: 200,
  117. render: (text) => {
  118. if (text) {
  119. return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
  120. } else {
  121. return '--';
  122. }
  123. }
  124. },
  125. {
  126. title: '操作',
  127. dataIndex: 'operation',
  128. width: 150,
  129. fixed: 'right',
  130. render: (text, record) => {
  131. return (
  132. <>
  133. <a
  134. style={{ marginRight: 16 }}
  135. onClick={() => {
  136. // onClickfetchTakaiApplicationDetail(record.appId);
  137. setDrawerFlag(true)
  138. setDrawerData(record)
  139. }}
  140. title='审核'
  141. >
  142. 查看
  143. </a >
  144. <a
  145. style={{ marginRight: 16 }}
  146. onClick={() => {
  147. onClickModify(record.appId);
  148. }}
  149. title='审核'
  150. >
  151. <StepForwardOutlined />审核
  152. </a >
  153. </>
  154. )
  155. }
  156. }
  157. ];
  158. const paginationConfig: TablePaginationConfig = {
  159. // 显示数据总量
  160. showTotal: (total: number) => {
  161. return `共 ${total} 条`;
  162. },
  163. // 展示分页条数切换
  164. showSizeChanger: true,
  165. // 指定每页显示条数
  166. pageSizeOptions: ['10', '20', '50', '100'],
  167. // 快速跳转至某页
  168. showQuickJumper: true,
  169. current: page.pageNum,
  170. pageSize: page.pageSize,
  171. total: page.total,
  172. onChange: async (page, pageSize) => {
  173. await onChangePagination(page, pageSize);
  174. },
  175. };
  176. return (
  177. <div className='knowledgeLibList'>
  178. <div className='knowledgeLibList-table'>
  179. <Table
  180. scroll={{ x: 'max-content' }}
  181. rowKey={(record) => record.createTime}
  182. loading={listLoading}
  183. columns={columns}
  184. dataSource={list}
  185. pagination={paginationConfig}
  186. />
  187. </div>
  188. {
  189. infoModalOpen &&
  190. <InfoModal
  191. id={infoModalId}
  192. open={infoModalOpen}
  193. onClickConfirm={infoModalOnClickConfirm}
  194. onClickCancel={infoModalOnClickCancel}
  195. onClickClose={infoModalOnClickClose}
  196. />
  197. }
  198. {
  199. <Drawer
  200. title={drawerData.name}
  201. closable={{ 'aria-label': 'Close Button' }}
  202. onClose={() => { setDrawerFlag(false) }}
  203. width="80%"
  204. open={drawerFlag}
  205. >
  206. {drawerFlag&&<PreviewModal isComponent={true} AuditAppId={drawerData.appId} />}
  207. </Drawer>
  208. }
  209. <AuditHistory open={historyOpen} onClose={() => setHistoryOpen(false)} />
  210. </div>
  211. );
  212. };
  213. export default observer(KnowledgeLibList);