index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 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. <Divider type="vertical"/>
  128. <a
  129. onClick={(e) => {
  130. e.stopPropagation();
  131. changeForm(record);
  132. }}
  133. >
  134. 修改
  135. </a>
  136. <Divider type="vertical"/>
  137. <a
  138. onClick={async () => {
  139. confirm({
  140. title: '确定删除吗?',
  141. icon: <ExclamationCircleOutlined/>,
  142. content: '删除后无法恢复',
  143. okText: '确定',
  144. okType: 'danger',
  145. cancelText: '取消',
  146. onOk() {
  147. deleteMemory(record);
  148. },
  149. onCancel() {
  150. console.log('Cancel');
  151. },
  152. });
  153. }}
  154. >
  155. 删除
  156. </a>
  157. </>
  158. ),
  159. },
  160. ];
  161. return (
  162. <PageHeaderWrapper title={false}>
  163. <ProTable<TableListItem>
  164. search
  165. headerTitle="查询表格"
  166. actionRef={actionRef}
  167. rowKey="id"
  168. onChange={(_, _filter, _sorter) => {
  169. const sorterResult = _sorter as SorterResult<TableListItem>;
  170. if (sorterResult.field) {
  171. setSorter(`${sorterResult.field}_${sorterResult.order}`);
  172. }
  173. }}
  174. pagination={{
  175. defaultPageSize: 10,
  176. }}
  177. params={{
  178. sorter,
  179. }}
  180. request={async (params = {}) => {
  181. const res = await service.queryList(params);
  182. return {
  183. data: res.data.list,
  184. page: params.current,
  185. success: true,
  186. total: res.data.total,
  187. };
  188. }}
  189. columns={columns}
  190. // rowSelection={{}}
  191. scroll={{x: 1000}}
  192. />
  193. {modelVisible ? (
  194. <UpdateForm
  195. onCancel={(refresh) => {
  196. setModalVisible(false);
  197. if (refresh && actionRef.current) {
  198. actionRef.current.reload();
  199. }
  200. }}
  201. modalVisible={modelVisible}
  202. values={formValues}/>
  203. ) : null}
  204. {showVisible ? (
  205. <Modal
  206. destroyOnClose
  207. width={640}
  208. bodyStyle={{padding: '15px 15px 15px'}}
  209. title="配置模型"
  210. visible={showVisible}
  211. onCancel={() => setShowVisible(false)}
  212. footer={null}
  213. >
  214. 正面:
  215. <p/>
  216. <MyQuill theme="bubble" readonly onChange={() => {
  217. }} value={formValues.front}/>
  218. <p/>
  219. 反面:
  220. <p/>
  221. <MyQuill theme="bubble" readonly onChange={() => {
  222. }} value={formValues.back}/>
  223. </Modal>
  224. ) : null}
  225. </PageHeaderWrapper>
  226. );
  227. };
  228. export default TableList;