index.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import {message, Modal} from 'antd';
  2. import React, {useRef, useState} from 'react';
  3. import {PageHeaderWrapper} from '@ant-design/pro-layout';
  4. import ProTable, {ActionType, ProColumns, TableDropdown} from '@ant-design/pro-table';
  5. import {SorterResult} from 'antd/es/table/interface';
  6. import {TableListItem} from './data.d';
  7. import service from './service';
  8. import UpdateForm from "@/pages/Memory/components/UpdateForm";
  9. import {ExclamationCircleOutlined} from "@ant-design/icons/lib";
  10. import MyQuill from "@/pages/Memory/components/MyQuill";
  11. import styles from './index.less';
  12. /**
  13. * 删除节点
  14. * @param fields
  15. */
  16. const handleRemove = async (fields: TableListItem) => {
  17. const hide = message.loading('正在删除');
  18. try {
  19. await service.delete(fields);
  20. hide();
  21. message.success('删除成功,即将刷新');
  22. return true;
  23. } catch (error) {
  24. hide();
  25. message.error('删除失败,请重试');
  26. return false;
  27. }
  28. };
  29. const TableList: React.FC<{}> = () => {
  30. const [sorter, setSorter] = useState<string>('');
  31. const [modelVisible, setModalVisible] = useState<boolean>(false);
  32. const [formValues, setFormValues] = useState<TableListItem>({
  33. back: "",
  34. front: "",
  35. id: 0,
  36. period: 0,
  37. remindTime: new Date(),
  38. tag: "",
  39. updateTime: "",
  40. userId: 0
  41. });
  42. const [showVisible, setShowVisible] = useState(false); // 是否查看
  43. const actionRef = useRef<ActionType>();
  44. const {confirm} = Modal;
  45. const deleteMemory = async (record: any) => {
  46. await handleRemove(record);
  47. if (actionRef.current) {
  48. actionRef.current.reload();
  49. }
  50. };
  51. const changeForm = async (record: any) => {
  52. setFormValues(record);
  53. setModalVisible(true);
  54. }
  55. const columns: ProColumns<TableListItem>[] = [
  56. {
  57. title: '正面',
  58. dataIndex: 'front',
  59. width: 250,
  60. // hideInSearch: true,
  61. render: (text, row) => {
  62. return (<div className={styles.listHeight}>
  63. <MyQuill theme="bubble" readonly onChange={() => {
  64. }} value={text}/>
  65. </div>);
  66. }
  67. },
  68. {
  69. title: '背面',
  70. dataIndex: 'back',
  71. width: 250,
  72. hideInSearch: true,
  73. render: (text, row) => {
  74. return (<div className={styles.listHeight}>
  75. <MyQuill theme="bubble" readonly onChange={() => {
  76. }} value={text}/>
  77. </div>);
  78. }
  79. },
  80. // {
  81. // title: '间隔时间',
  82. // dataIndex: 'period',
  83. // width: 110,
  84. // hideInSearch: true,
  85. // hideInForm: true,
  86. // render: (text, row) => {
  87. // return (<>
  88. // <span>{minuteToDay(row.period)}</span>
  89. // </>);
  90. // }
  91. // },
  92. {
  93. title: '提醒时间',
  94. dataIndex: 'remindTime',
  95. valueType: 'dateTime',
  96. // width: 150,
  97. hideInSearch: true,
  98. hideInForm: true,
  99. sorter: true
  100. },
  101. // {
  102. // title: '更新时间',
  103. // dataIndex: 'updateTime',
  104. // valueType: 'dateTime',
  105. // width: 150,
  106. // hideInSearch: true,
  107. // hideInForm: true,
  108. // sorter: true
  109. // },
  110. {
  111. title: '操作',
  112. dataIndex: 'option',
  113. width: 200,
  114. valueType: 'option',
  115. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  116. render: (_, record, index, action) => (
  117. <>
  118. <a
  119. onClick={(e) => {
  120. e.stopPropagation();
  121. setFormValues(record);
  122. setShowVisible(true);
  123. }}
  124. >
  125. 查看
  126. </a>
  127. <a
  128. onClick={(e) => {
  129. e.stopPropagation();
  130. changeForm(record);
  131. }}
  132. >
  133. 修改
  134. </a>
  135. <TableDropdown
  136. key="actionGroup"
  137. menus={[
  138. { key: 'restart', name: '重新复习' },
  139. { key: 'delete', name: '删除' },
  140. ]}
  141. onSelect={async (key)=>{
  142. if (key === 'restart') {
  143. await service.restart(record);
  144. }else if (key === 'delete') {
  145. confirm({
  146. title: '确定删除吗?',
  147. icon: <ExclamationCircleOutlined/>,
  148. content: '删除后无法恢复',
  149. okText: '确定',
  150. okType: 'danger',
  151. cancelText: '取消',
  152. onOk() {
  153. deleteMemory(record);
  154. },
  155. onCancel() {
  156. console.log('Cancel');
  157. },
  158. });
  159. }
  160. }}
  161. />
  162. </>
  163. ),
  164. },
  165. ];
  166. return (
  167. <PageHeaderWrapper title={false}>
  168. <ProTable<TableListItem>
  169. search
  170. headerTitle="查询表格"
  171. actionRef={actionRef}
  172. rowKey="id"
  173. onChange={(_, _filter, _sorter) => {
  174. const sorterResult = _sorter as SorterResult<TableListItem>;
  175. if (sorterResult.field) {
  176. setSorter(`${sorterResult.field}_${sorterResult.order}`);
  177. }
  178. }}
  179. pagination={{
  180. defaultPageSize: 10,
  181. }}
  182. params={{
  183. sorter,
  184. }}
  185. request={async (params = {}) => {
  186. const res = await service.queryList(params);
  187. return {
  188. data: res.data.list,
  189. page: params.current,
  190. success: true,
  191. total: res.data.total,
  192. };
  193. }}
  194. columns={columns}
  195. // rowSelection={{}}
  196. scroll={{x: 1000}}
  197. onRow={record => {
  198. return {
  199. onClick: event => {
  200. // changeForm(record);
  201. }, // 点击行
  202. onDoubleClick: event => {
  203. event.stopPropagation();
  204. setFormValues(record);
  205. setShowVisible(true);
  206. },
  207. onContextMenu: event => {
  208. },
  209. onMouseEnter: event => {
  210. }, // 鼠标移入行
  211. onMouseLeave: event => {
  212. },
  213. };
  214. }}
  215. />
  216. {modelVisible ? (
  217. <UpdateForm
  218. onCancel={(refresh) => {
  219. setModalVisible(false);
  220. if (refresh && actionRef.current) {
  221. actionRef.current.reload();
  222. }
  223. }}
  224. modalVisible={modelVisible}
  225. values={formValues}/>
  226. ) : null}
  227. {showVisible ? (
  228. <Modal
  229. destroyOnClose
  230. width={640}
  231. bodyStyle={{padding: '15px 15px 15px'}}
  232. title="配置模型"
  233. visible={showVisible}
  234. onCancel={() => setShowVisible(false)}
  235. footer={null}
  236. >
  237. 正面:
  238. <p/>
  239. <MyQuill theme="bubble" readonly onChange={() => {
  240. }} value={formValues.front}/>
  241. <p/>
  242. 反面:
  243. <p/>
  244. <MyQuill theme="bubble" readonly onChange={() => {
  245. }} value={formValues.back}/>
  246. </Modal>
  247. ) : null}
  248. </PageHeaderWrapper>
  249. );
  250. };
  251. export default TableList;