index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import {Divider, message, Modal} from 'antd';
  2. import React, {useRef, useState} from 'react';
  3. import {PageHeaderWrapper} from '@ant-design/pro-layout';
  4. import ProTable, {ActionType, ProColumns} 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 Quill from "@/pages/Memory/components/Quill";
  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. <Quill theme="bubble" readonly onChange={() => {}} value={text} />
  64. </div>);
  65. }
  66. },
  67. {
  68. title: '背面',
  69. dataIndex: 'back',
  70. width: 250,
  71. hideInSearch: true,
  72. render: (text, row) => {
  73. return (<div className={styles.listHeight}>
  74. <Quill theme="bubble" readonly onChange={() => {}} value={text} />
  75. </div>);
  76. }
  77. },
  78. // {
  79. // title: '间隔时间',
  80. // dataIndex: 'period',
  81. // width: 110,
  82. // hideInSearch: true,
  83. // hideInForm: true,
  84. // render: (text, row) => {
  85. // return (<>
  86. // <span>{minuteToDay(row.period)}</span>
  87. // </>);
  88. // }
  89. // },
  90. {
  91. title: '提醒时间',
  92. dataIndex: 'remindTime',
  93. valueType: 'dateTime',
  94. // width: 150,
  95. hideInSearch: true,
  96. hideInForm: true,
  97. sorter: true
  98. },
  99. // {
  100. // title: '更新时间',
  101. // dataIndex: 'updateTime',
  102. // valueType: 'dateTime',
  103. // width: 150,
  104. // hideInSearch: true,
  105. // hideInForm: true,
  106. // sorter: true
  107. // },
  108. {
  109. title: '操作',
  110. dataIndex: 'option',
  111. width: 200,
  112. valueType: 'option',
  113. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  114. render: (_, record, index, action) => (
  115. <>
  116. <a
  117. onClick={(e) => {
  118. e.stopPropagation();
  119. setFormValues(record);
  120. setShowVisible(true);
  121. }}
  122. >
  123. 查看
  124. </a>
  125. <Divider type="vertical"/>
  126. <a
  127. onClick={(e) => {
  128. e.stopPropagation();
  129. changeForm(record);
  130. }}
  131. >
  132. 修改
  133. </a>
  134. <Divider type="vertical"/>
  135. <a
  136. onClick={async () => {
  137. confirm({
  138. title: '确定删除吗?',
  139. icon: <ExclamationCircleOutlined/>,
  140. content: '删除后无法恢复',
  141. okText: '确定',
  142. okType: 'danger',
  143. cancelText: '取消',
  144. onOk() {
  145. deleteMemory(record);
  146. },
  147. onCancel() {
  148. console.log('Cancel');
  149. },
  150. });
  151. }}
  152. >
  153. 删除
  154. </a>
  155. </>
  156. ),
  157. },
  158. ];
  159. return (
  160. <PageHeaderWrapper title={false}>
  161. <ProTable<TableListItem>
  162. search
  163. headerTitle="查询表格"
  164. actionRef={actionRef}
  165. rowKey="id"
  166. onChange={(_, _filter, _sorter) => {
  167. const sorterResult = _sorter as SorterResult<TableListItem>;
  168. if (sorterResult.field) {
  169. setSorter(`${sorterResult.field}_${sorterResult.order}`);
  170. }
  171. }}
  172. pagination={{
  173. defaultPageSize: 10,
  174. }}
  175. params={{
  176. sorter,
  177. }}
  178. request={async (params = {}) => {
  179. const res = await service.queryList(params);
  180. return {
  181. data: res.data.list,
  182. page: params.current,
  183. success: true,
  184. total: res.data.total,
  185. };
  186. }}
  187. columns={columns}
  188. // rowSelection={{}}
  189. scroll={{x:1000}}
  190. />
  191. {modelVisible ? (
  192. <UpdateForm
  193. onCancel={(refresh) => {
  194. setModalVisible(false);
  195. if (refresh && actionRef.current) {
  196. actionRef.current.reload();
  197. }
  198. }}
  199. modalVisible={modelVisible}
  200. values={formValues} />
  201. ) : null}
  202. {showVisible ? (
  203. <Modal
  204. destroyOnClose
  205. width={640}
  206. bodyStyle={{padding: '15px 15px 15px'}}
  207. title="配置模型"
  208. visible={showVisible}
  209. onCancel={() => setShowVisible(false)}
  210. footer={null}
  211. >
  212. 正面:
  213. <p/>
  214. <Quill theme="bubble" readonly onChange={() => {
  215. }} value={formValues.front}/>
  216. <p/>
  217. 反面:
  218. <p/>
  219. <Quill theme="bubble" readonly onChange={() => {
  220. }} value={formValues.back}/>
  221. </Modal>
  222. ) : null}
  223. </PageHeaderWrapper>
  224. );
  225. };
  226. export default TableList;