Edit.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { useIntl } from "react-intl";
  2. import {
  3. ProForm,
  4. ProFormText,
  5. ProFormTextArea,
  6. } from "@ant-design/pro-components";
  7. import { Alert, message } from "antd";
  8. import { IApiResponseChannel } from "../../components/api/Channel";
  9. import { get, put } from "../../request";
  10. import ChannelTypeSelect from "../../components/channel/ChannelTypeSelect";
  11. import LangSelect from "../../components/general/LangSelect";
  12. import PublicitySelect from "../../components/studio/PublicitySelect";
  13. import { useState } from "react";
  14. interface IFormData {
  15. name: string;
  16. type: string;
  17. lang: string;
  18. summary: string;
  19. status: number;
  20. studio: string;
  21. isSystem: boolean;
  22. }
  23. interface IWidget {
  24. studioName?: string;
  25. channelId?: string;
  26. onLoad?: Function;
  27. }
  28. const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => {
  29. const intl = useIntl();
  30. const [isSystem, setIsSystem] = useState<Boolean>();
  31. return (
  32. <>
  33. {isSystem ? (
  34. <Alert type="warning" message={"此版本为系统建立。不能修改,删除。"} />
  35. ) : (
  36. <></>
  37. )}
  38. <ProForm<IFormData>
  39. submitter={{
  40. resetButtonProps: { disabled: isSystem ? true : false },
  41. submitButtonProps: { disabled: isSystem ? true : false },
  42. }}
  43. onFinish={async (values: IFormData) => {
  44. console.log(values);
  45. const res = await put(`/v2/channel/${channelId}`, values);
  46. console.log(res);
  47. message.success(intl.formatMessage({ id: "flashes.success" }));
  48. }}
  49. formKey="channel_edit"
  50. request={async () => {
  51. const res = await get<IApiResponseChannel>(
  52. `/v2/channel/${channelId}`
  53. );
  54. if (typeof onLoad !== "undefined") {
  55. onLoad(res.data);
  56. }
  57. setIsSystem(res.data.is_system);
  58. return {
  59. name: res.data.name,
  60. type: res.data.type,
  61. lang: res.data.lang,
  62. summary: res.data.summary,
  63. status: res.data.status,
  64. studio: studioName ? studioName : "",
  65. isSystem: res.data.is_system,
  66. };
  67. }}
  68. >
  69. <ProForm.Group>
  70. <ProFormText
  71. width="md"
  72. name="name"
  73. readonly={isSystem ? true : false}
  74. required
  75. label={intl.formatMessage({ id: "channel.name" })}
  76. rules={[
  77. {
  78. required: true,
  79. },
  80. ]}
  81. />
  82. </ProForm.Group>
  83. <ProForm.Group>
  84. <ChannelTypeSelect readonly={isSystem ? true : false} />
  85. <LangSelect readonly={isSystem ? true : false} />
  86. </ProForm.Group>
  87. <ProForm.Group>
  88. <PublicitySelect readonly={isSystem ? true : false} />
  89. </ProForm.Group>
  90. <ProForm.Group>
  91. <ProFormTextArea
  92. readonly={isSystem ? true : false}
  93. width="md"
  94. name="summary"
  95. label="简介"
  96. />
  97. </ProForm.Group>
  98. </ProForm>
  99. </>
  100. );
  101. };
  102. export default EditWidget;