index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { useParams, Link } from "react-router-dom";
  2. import { useIntl } from "react-intl";
  3. import { useState } from "react";
  4. import { ProList } from "@ant-design/pro-components";
  5. import { Space, Tag, Button, Layout, Breadcrumb } from "antd";
  6. import HeadBar from "../../../components/studio/HeadBar";
  7. import LeftSider from "../../../components/studio/LeftSider";
  8. import Footer from "../../../components/studio/Footer";
  9. const { Content } = Layout;
  10. const defaultData = [
  11. {
  12. id: "1",
  13. name: "IAPT巴利语学习营",
  14. tag: [
  15. { title: "巴利语", color: "blue" },
  16. { title: "大金塔", color: "yellow" },
  17. { title: "拥有者", color: "success" },
  18. ],
  19. image: "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
  20. description: "我是一条测试的描述",
  21. },
  22. {
  23. id: "2",
  24. name: "初级巴利语入门",
  25. tag: [
  26. { title: "巴利语", color: "blue" },
  27. { title: "管理员", color: "processing" },
  28. ],
  29. image: "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
  30. description: "我是一条测试的描述",
  31. },
  32. {
  33. id: "3",
  34. name: "大金塔寺学习小组",
  35. tag: [
  36. { title: "大金塔", color: "yellow" },
  37. { title: "成员", color: "default" },
  38. ],
  39. image: "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
  40. description: "我是一条测试的描述",
  41. },
  42. {
  43. id: "4",
  44. name: "趣向涅槃之道第一册翻译组",
  45. tag: [
  46. { title: "大金塔", color: "yellow" },
  47. { title: "成员", color: "default" },
  48. ],
  49. image: "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
  50. description: "我是一条测试的描述",
  51. },
  52. ];
  53. type DataItem = typeof defaultData[number];
  54. const Widget = () => {
  55. const intl = useIntl(); //i18n
  56. const { studioname } = useParams(); //url 参数
  57. const [dataSource, setDataSource] = useState<DataItem[]>(defaultData);
  58. const linkStudio = `/studio/${studioname}`;
  59. const linkGroup = `${linkStudio}/group`;
  60. return (
  61. <Layout>
  62. <HeadBar />
  63. <Layout>
  64. <LeftSider selectedKeys="group" />
  65. <Content>
  66. <Breadcrumb>
  67. <Breadcrumb.Item>
  68. <Link to={linkStudio}>{intl.formatMessage({ id: "columns.studio.title" })}</Link>
  69. </Breadcrumb.Item>
  70. <Breadcrumb.Item>
  71. {intl.formatMessage({ id: "columns.studio.collaboration.title" })}
  72. </Breadcrumb.Item>
  73. <Breadcrumb.Item>
  74. <Link to={linkGroup}>{intl.formatMessage({ id: "columns.studio.group.title" })}</Link>
  75. </Breadcrumb.Item>
  76. <Breadcrumb.Item>列表</Breadcrumb.Item>
  77. </Breadcrumb>
  78. <Layout>
  79. <ProList<DataItem>
  80. rowKey="id"
  81. headerTitle="群组列表"
  82. dataSource={dataSource}
  83. showActions="hover"
  84. editable={{
  85. onSave: async (key, record, originRow) => {
  86. console.log(key, record, originRow);
  87. return true;
  88. },
  89. }}
  90. onDataSourceChange={setDataSource}
  91. metas={{
  92. title: {
  93. dataIndex: "name",
  94. render: (text, row, index, action) => {
  95. return <Link to={row.id}>{row.name}</Link>;
  96. },
  97. },
  98. avatar: {
  99. dataIndex: "image",
  100. editable: false,
  101. },
  102. description: {
  103. dataIndex: "description",
  104. },
  105. content: {
  106. dataIndex: "content",
  107. editable: false,
  108. },
  109. subTitle: {
  110. render: (text, row, index, action) => {
  111. const showtag = row.tag.map((item, key) => {
  112. return <Tag color={item.color}>{item.title}</Tag>;
  113. });
  114. return <Space size={0}>{showtag}</Space>;
  115. },
  116. },
  117. actions: {
  118. render: (text, row, index, action) => [
  119. <Button
  120. onClick={() => {
  121. action?.startEditable(row.id);
  122. }}
  123. key="link"
  124. >
  125. 编辑
  126. </Button>,
  127. ],
  128. },
  129. }}
  130. />
  131. </Layout>
  132. </Content>
  133. </Layout>
  134. <Footer />
  135. </Layout>
  136. );
  137. };
  138. export default Widget;