edit.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import { useState } from "react";
  2. import { useParams } from "react-router-dom";
  3. import { useIntl, FormattedMessage } from "react-intl";
  4. import {
  5. ProForm,
  6. ProFormText,
  7. ProFormTextArea,
  8. ProFormDateRangePicker,
  9. } from "@ant-design/pro-components";
  10. import { Card, message, Col, Row, Divider, Tabs } from "antd";
  11. import { get, put } from "../../../request";
  12. import { marked } from "marked";
  13. import {
  14. ICourseDataRequest,
  15. ICourseResponse,
  16. } from "../../../components/api/Course";
  17. import PublicitySelect from "../../../components/studio/PublicitySelect";
  18. import GoBack from "../../../components/studio/GoBack";
  19. import UploadTexture from "../../../components/library/course/UploadTexture";
  20. import TeacherSelect from "../../../components/library/course/TeacherSelect";
  21. import StudentsSelect from "../../../components/library/course/StudentsSelect";
  22. import LessonSelect from "../../../components/library/course/LessonSelect";
  23. import LessonTreeShow from "../../../components/library/course/LessonTreeShow";
  24. interface IFormData {
  25. uid: string;
  26. title: string;
  27. t_type: string;
  28. status: number;
  29. lang: string;
  30. }
  31. const onChange = (key: string) => {
  32. console.log(key);
  33. };
  34. let groupid = "1";
  35. const Widget = () => {
  36. const intl = useIntl();
  37. const { studioname, courseid } = useParams(); //url 参数
  38. const [title, setTitle] = useState("loading");
  39. return (
  40. <Tabs
  41. onChange={onChange}
  42. type="card"
  43. items={[
  44. {
  45. label: `基本信息`,
  46. key: "1",
  47. children: (
  48. <Card
  49. title={
  50. <GoBack
  51. to={`/studio/${studioname}/course/list`}
  52. title={title}
  53. />
  54. }
  55. >
  56. <ProForm<IFormData>
  57. onFinish={async (values: IFormData) => {
  58. // TODO
  59. let request = {
  60. uid: courseid?.toString,
  61. title: "课程" + courseid,
  62. subtitle: "课程副标题" + courseid,
  63. teacher: 1,
  64. course_count: 2,
  65. type: 30,
  66. created_at: "",
  67. updated_at: "",
  68. article_id: 1, //"1e642dac-dcb2-468a-8cc7-0228e5ca6ac4",
  69. course_start_at: "", //课程开始时间
  70. course_end_at: "", //课程结束时间
  71. intro_markdown: "", //简介
  72. cover_img_name: "", //封面图片文件名
  73. };
  74. }}
  75. /* const request = {
  76. uid: courseid ? courseid : "",
  77. title: values.title,
  78. subtitle: values.subtitle,
  79. teacher: values.teacher,//UserID
  80. course_count: values.course_count,//课程数
  81. type: values.type,//类型-公开/内部
  82. created_at: values.created_at,//创建时间
  83. updated_at: values.updated_at,//修改时间
  84. article_id: values.article_id,//文集ID
  85. course_start_at: values.course_start_at,//课程开始时间
  86. course_end_at: values.course_end_at,//课程结束时间
  87. intro_markdown: values.intro_markdown,//简介
  88. cover_img_name: values.cover_img_name,//封面图片文件名
  89. };
  90. console.log(request);
  91. const res = await put<ICourseDataRequest, ICourseResponse>(
  92. `/v2/course/${courseid}`,
  93. request
  94. );
  95. console.log(res);
  96. if (res.ok) {
  97. message.success(intl.formatMessage({ id: "flashes.success" }));
  98. } else {
  99. message.error(res.message);
  100. }
  101. }}
  102. request={async () => {
  103. const res = await get<ICourseResponse>(`/v2/course/${courseid}`);
  104. setTitle(res.data.title);
  105. return {
  106. uid: res.data.uid,
  107. title: res.data.title,
  108. subtitle: res.data.subtitle,
  109. summary: res.data.summary,
  110. content: res.data.content,
  111. content_type: res.data.content_type,
  112. lang: res.data.lang,
  113. status: res.data.status,
  114. };
  115. }}*/
  116. >
  117. <ProForm.Group>
  118. <ProFormText
  119. width="md"
  120. name="title"
  121. required
  122. label={intl.formatMessage({
  123. id: "forms.fields.title.label",
  124. })}
  125. rules={[
  126. {
  127. required: true,
  128. message: intl.formatMessage({
  129. id: "forms.message.title.required",
  130. }),
  131. },
  132. ]}
  133. />
  134. </ProForm.Group>
  135. <ProForm.Group>
  136. <ProFormText
  137. width="md"
  138. name="subtitle"
  139. label={intl.formatMessage({
  140. id: "forms.fields.subtitle.label",
  141. })}
  142. />
  143. </ProForm.Group>
  144. <ProForm.Group>
  145. <p style={{ fontWeight: "bold", fontSize: 15 }}>
  146. <FormattedMessage id="forms.fields.upload.texture" />{" "}
  147. </p>
  148. <UploadTexture />
  149. </ProForm.Group>
  150. <ProForm.Group>
  151. <ProFormDateRangePicker
  152. width="md"
  153. name={["contract", "createTime"]}
  154. label="课程区间"
  155. />
  156. </ProForm.Group>
  157. <ProForm.Group>
  158. <PublicitySelect />
  159. </ProForm.Group>
  160. <Divider />
  161. <Row>
  162. <Col flex="400px">
  163. <TeacherSelect groupId={groupid} />
  164. </Col>
  165. </Row>
  166. <Divider />
  167. <Row>
  168. <Col flex="400px">
  169. <LessonSelect groupId={groupid} />
  170. </Col>
  171. </Row>
  172. <Divider />
  173. <ProForm.Group>
  174. <ProFormTextArea
  175. name="summary"
  176. width="md"
  177. label={intl.formatMessage({
  178. id: "forms.fields.summary.label",
  179. })}
  180. />
  181. <p style={{ fontWeight: "bold", fontSize: 15 }}>
  182. <FormattedMessage id="forms.fields.markdown.label" />{" "}
  183. </p>
  184. <Row>
  185. <div
  186. dangerouslySetInnerHTML={{
  187. __html: marked.parse(
  188. "# 这是标题\n" +
  189. "[ **M** ] arkdown + E [ **ditor** ] = **Mditor** \n" +
  190. "**这是加粗的文字**\n\n" +
  191. "*这是倾斜的文字*`\n\n" +
  192. "***这是斜体加粗的文字***\n\n" +
  193. "~~这是加删除线的文字~~ \n\n"
  194. ),
  195. }}
  196. ></div>
  197. </Row>
  198. </ProForm.Group>
  199. </ProForm>
  200. </Card>
  201. ),
  202. },
  203. {
  204. label: `学生与助教选择 `,
  205. key: "2",
  206. children: (
  207. <Card
  208. title={
  209. <GoBack
  210. to={`/studio/${studioname}/course/list`}
  211. title={title}
  212. />
  213. }
  214. >
  215. <ProForm<IFormData> onFinish={async (values: IFormData) => {}}>
  216. <ProForm.Group>
  217. <LessonTreeShow />
  218. </ProForm.Group>
  219. <ProForm.Group></ProForm.Group>
  220. <Row>
  221. <Col flex="400px">
  222. <StudentsSelect groupId={groupid} />
  223. </Col>
  224. </Row>
  225. </ProForm>
  226. </Card>
  227. ),
  228. },
  229. ]}
  230. />
  231. );
  232. };
  233. export default Widget;