edit.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { useParams } from "react-router-dom";
  2. import {
  3. ProForm,
  4. ProFormText,
  5. ProFormSelect,
  6. ProFormTextArea,
  7. } from "@ant-design/pro-components";
  8. import { useIntl } from "react-intl";
  9. import { message, Card } from "antd";
  10. import { IGroupResponse } from "../../../components/api/Group";
  11. import { useEffect, useState } from "react";
  12. import { get } from "../../../request";
  13. import GoBack from "../../../components/studio/GoBack";
  14. interface IFormData {
  15. name: string;
  16. type: string;
  17. lang: string;
  18. summary: string;
  19. studio: string;
  20. }
  21. const Widget = () => {
  22. const intl = useIntl();
  23. const { studioname, groupid } = useParams(); //url 参数
  24. const [title, setTitle] = useState("Loading");
  25. useEffect(() => {
  26. get<IGroupResponse>(`/v2/group/${groupid}`).then((json) => {
  27. setTitle(json.data.name);
  28. });
  29. }, [groupid]);
  30. return (
  31. <Card
  32. title={
  33. <GoBack to={`/studio/${studioname}/group/list`} title={title} />
  34. }
  35. >
  36. <ProForm<IFormData>
  37. onFinish={async (values: IFormData) => {
  38. // TODO
  39. values.studio = "aaaa";
  40. console.log(values);
  41. message.success(
  42. intl.formatMessage({ id: "flashes.success" })
  43. );
  44. }}
  45. >
  46. <ProForm.Group>
  47. <ProFormText
  48. width="md"
  49. name="name"
  50. required
  51. label={intl.formatMessage({ id: "channel.name" })}
  52. rules={[
  53. {
  54. required: true,
  55. message: intl.formatMessage({
  56. id: "channel.create.message.noname",
  57. }),
  58. },
  59. ]}
  60. />
  61. </ProForm.Group>
  62. <ProForm.Group>
  63. <ProFormSelect
  64. options={[
  65. {
  66. value: "translation",
  67. label: intl.formatMessage({
  68. id: "channel.type.translation.title",
  69. }),
  70. },
  71. {
  72. value: "nissaya",
  73. label: intl.formatMessage({
  74. id: "channel.type.nissaya.title",
  75. }),
  76. },
  77. ]}
  78. width="md"
  79. name="type"
  80. rules={[
  81. {
  82. required: true,
  83. message: intl.formatMessage({
  84. id: "channel.create.message.noname",
  85. }),
  86. },
  87. ]}
  88. label={intl.formatMessage({ id: "channel.type" })}
  89. />
  90. </ProForm.Group>
  91. <ProForm.Group>
  92. <ProFormSelect
  93. options={[
  94. { value: "zh-Hans", label: "简体中文" },
  95. { value: "zh-Hant", label: "繁体中文" },
  96. { value: "en-US", label: "English" },
  97. ]}
  98. width="md"
  99. name="lang"
  100. rules={[
  101. {
  102. required: true,
  103. message: intl.formatMessage({
  104. id: "channel.create.message.noname",
  105. }),
  106. },
  107. ]}
  108. label={intl.formatMessage({ id: "channel.lang" })}
  109. />
  110. </ProForm.Group>
  111. <ProForm.Group>
  112. <ProFormTextArea name="summary" label="简介" />
  113. </ProForm.Group>
  114. </ProForm>
  115. </Card>
  116. );
  117. };
  118. export default Widget;