index.jsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React, { useEffect, useRef, useCallback, useState } from 'react';
  2. import { connect, history } from 'umi';
  3. import { PageContainer } from '@ant-design/pro-layout';
  4. import ProTable from '@ant-design/pro-table';
  5. import { PlusOutlined, MenuOutlined } from '@ant-design/icons';
  6. import { Button, Popconfirm, Image, Space, notification } from 'antd';
  7. import { sortableContainer, sortableElement, sortableHandle } from 'react-sortable-hoc';
  8. import request, { queryTable } from '@/utils/request';
  9. import arrayMove from 'array-move';
  10. const SortableItem = sortableElement((props) => <tr {...props} />);
  11. const SortableContainer = sortableContainer((props) => <tbody {...props} />);
  12. const typeList = { post: '科普' };
  13. // const stateList = { post: '科普' };
  14. const SchoolList = (props) => {
  15. const [loading, setLoading] = useState(false);
  16. const ref = useRef();
  17. const handleSchoolClick = useCallback((id) => {
  18. history.push(id ? `/student/school/edit?id=${id}` : '/student/school/edit');
  19. }, []);
  20. const actions = [
  21. <Button key="button" icon={<PlusOutlined />} type="primary" onClick={() => handleSchoolClick()}>
  22. 新建
  23. </Button>,
  24. ];
  25. const deleteSchoolClick = (id) => {
  26. setLoading(true);
  27. console.log(ref, 'ref');
  28. request(`/school/${id}`, { method: 'delete' })
  29. .then((res) => {
  30. notification.success({ message: '删除成功' });
  31. ref.current.submit();
  32. })
  33. .catch((e) => {
  34. setLoading(false);
  35. notification.error({ message: e.message });
  36. });
  37. };
  38. const columns = [
  39. {
  40. title: 'logo',
  41. dataIndex: 'logo',
  42. hideInSearch: true,
  43. align: 'center',
  44. render: (text) => <Image width={64} height={64} src={text} />,
  45. },
  46. {
  47. title: '学校名称',
  48. dataIndex: 'name',
  49. align: 'center',
  50. },
  51. {
  52. title: '简介',
  53. dataIndex: 'desc',
  54. align: 'center',
  55. hideInSearch: true,
  56. width: '25%',
  57. ellipsis: true,
  58. // render: (text) => <Image src={text} />,
  59. },
  60. {
  61. title: '上架状态',
  62. dataIndex: 'status',
  63. align: 'center',
  64. // hideInTable: true,
  65. valueType: 'select',
  66. valueEnum: {
  67. 0: { text: '未上架' },
  68. 1: { text: '已上架' },
  69. },
  70. },
  71. {
  72. title: '上传时间',
  73. dataIndex: 'createDate',
  74. align: 'center',
  75. hideInSearch: true,
  76. valueType: 'date',
  77. },
  78. {
  79. title: '操作',
  80. dataIndex: 'action',
  81. align: 'center',
  82. hideInSearch: true,
  83. render: (text, record) => (
  84. <Space size="middle">
  85. <a onClick={() => handleSchoolClick(record.schoolId)}>编辑</a>
  86. <Popconfirm
  87. key="popconfirm"
  88. title={`确认删除吗?`}
  89. onConfirm={() => deleteSchoolClick(record.schoolId)}
  90. okText="是"
  91. cancelText="否"
  92. >
  93. <a>删除</a>
  94. </Popconfirm>
  95. </Space>
  96. ),
  97. },
  98. ];
  99. return (
  100. <PageContainer>
  101. <ProTable
  102. columns={columns}
  103. request={queryTable('/school')}
  104. formRef={ref}
  105. rowKey="schoolId"
  106. headerTitle="学校列表"
  107. search={{
  108. labelWidth: '4em',
  109. }}
  110. toolBarRender={() => actions}
  111. />
  112. </PageContainer>
  113. );
  114. };
  115. export default connect((s) => ({
  116. typeList: s.post.typeList,
  117. }))(SchoolList);