|
@@ -2,22 +2,49 @@ import { useIntl } from "react-intl";
|
|
|
import {
|
|
import {
|
|
|
ProForm,
|
|
ProForm,
|
|
|
ProFormInstance,
|
|
ProFormInstance,
|
|
|
|
|
+ ProFormSelect,
|
|
|
ProFormText,
|
|
ProFormText,
|
|
|
} from "@ant-design/pro-components";
|
|
} from "@ant-design/pro-components";
|
|
|
-import { message } from "antd";
|
|
|
|
|
|
|
+import { Tag, message } from "antd";
|
|
|
|
|
|
|
|
-import { post } from "../../request";
|
|
|
|
|
|
|
+import { get, post, put } from "../../request";
|
|
|
import { useRef } from "react";
|
|
import { useRef } from "react";
|
|
|
import { ITagRequest, ITagResponse } from "../api/Tag";
|
|
import { ITagRequest, ITagResponse } from "../api/Tag";
|
|
|
|
|
|
|
|
interface IWidgetCourseCreate {
|
|
interface IWidgetCourseCreate {
|
|
|
studio?: string;
|
|
studio?: string;
|
|
|
|
|
+ tagId?: string;
|
|
|
onCreate?: Function;
|
|
onCreate?: Function;
|
|
|
}
|
|
}
|
|
|
-const TagCreateWidget = ({ studio = "", onCreate }: IWidgetCourseCreate) => {
|
|
|
|
|
|
|
+const TagCreateWidget = ({ studio, tagId, onCreate }: IWidgetCourseCreate) => {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
|
|
|
|
|
|
|
+ const _color = [
|
|
|
|
|
+ "b60205",
|
|
|
|
|
+ "d93f0b",
|
|
|
|
|
+ "fbca04",
|
|
|
|
|
+ "0e8a16",
|
|
|
|
|
+ "006b75",
|
|
|
|
|
+ "1d76db",
|
|
|
|
|
+ "0052cc",
|
|
|
|
|
+ "5319e7",
|
|
|
|
|
+ "e99695",
|
|
|
|
|
+ "f9d0c4",
|
|
|
|
|
+ "fef2c0",
|
|
|
|
|
+ "c2e0c6",
|
|
|
|
|
+ "bfdadc",
|
|
|
|
|
+ "c5def5",
|
|
|
|
|
+ "bfd4f2",
|
|
|
|
|
+ "d4c5f9",
|
|
|
|
|
+ ];
|
|
|
|
|
+ const colorOptions = _color.map((item) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ value: parseInt(item, 16),
|
|
|
|
|
+ label: <Tag color={`#${item}`}>{item}</Tag>,
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<ProForm<ITagRequest>
|
|
<ProForm<ITagRequest>
|
|
|
formRef={formRef}
|
|
formRef={formRef}
|
|
@@ -25,9 +52,18 @@ const TagCreateWidget = ({ studio = "", onCreate }: IWidgetCourseCreate) => {
|
|
|
console.log(values);
|
|
console.log(values);
|
|
|
if (studio) {
|
|
if (studio) {
|
|
|
values.studio = studio;
|
|
values.studio = studio;
|
|
|
- const url = `/v2/tag`;
|
|
|
|
|
|
|
+ let url = `/v2/tag`;
|
|
|
|
|
+ if (tagId) {
|
|
|
|
|
+ url += `/${tagId}`;
|
|
|
|
|
+ }
|
|
|
console.info("CourseCreateWidget api request", url, values);
|
|
console.info("CourseCreateWidget api request", url, values);
|
|
|
- const res = await post<ITagRequest, ITagResponse>(url, values);
|
|
|
|
|
|
|
+ let res: any;
|
|
|
|
|
+ if (tagId) {
|
|
|
|
|
+ res = await put<ITagRequest, ITagResponse>(url, values);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ res = await post<ITagRequest, ITagResponse>(url, values);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
console.info("CourseCreateWidget api response", res);
|
|
console.info("CourseCreateWidget api response", res);
|
|
|
if (res.ok) {
|
|
if (res.ok) {
|
|
|
message.success(intl.formatMessage({ id: "flashes.success" }));
|
|
message.success(intl.formatMessage({ id: "flashes.success" }));
|
|
@@ -42,6 +78,17 @@ const TagCreateWidget = ({ studio = "", onCreate }: IWidgetCourseCreate) => {
|
|
|
console.error("no studio");
|
|
console.error("no studio");
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
|
|
|
+ request={
|
|
|
|
|
+ tagId
|
|
|
|
|
+ ? async () => {
|
|
|
|
|
+ const url = `/v2/tag/${tagId}`;
|
|
|
|
|
+ console.info("api request", url);
|
|
|
|
|
+ const res = await get<ITagResponse>(url);
|
|
|
|
|
+ console.info("api response", res);
|
|
|
|
|
+ return res.data;
|
|
|
|
|
+ }
|
|
|
|
|
+ : undefined
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
<ProForm.Group>
|
|
<ProForm.Group>
|
|
|
<ProFormText
|
|
<ProFormText
|
|
@@ -69,6 +116,14 @@ const TagCreateWidget = ({ studio = "", onCreate }: IWidgetCourseCreate) => {
|
|
|
]}
|
|
]}
|
|
|
/>
|
|
/>
|
|
|
</ProForm.Group>
|
|
</ProForm.Group>
|
|
|
|
|
+ <ProForm.Group>
|
|
|
|
|
+ <ProFormSelect
|
|
|
|
|
+ width="md"
|
|
|
|
|
+ name="color"
|
|
|
|
|
+ label={intl.formatMessage({ id: "forms.fields.color.label" })}
|
|
|
|
|
+ options={colorOptions}
|
|
|
|
|
+ />
|
|
|
|
|
+ </ProForm.Group>
|
|
|
</ProForm>
|
|
</ProForm>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|