StudioSelect.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Select } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { get } from "../../request";
  4. import { IStudio } from "../auth/StudioName";
  5. interface IStudioListResponse {
  6. ok: boolean;
  7. message: string;
  8. data: {
  9. rows: IStudio[];
  10. count: number;
  11. };
  12. }
  13. interface IOptions {
  14. value: string;
  15. label: string;
  16. }
  17. interface IWidget {
  18. studioName?: string;
  19. onSelect?: Function;
  20. }
  21. const StudioSelectWidget = ({ studioName, onSelect }: IWidget) => {
  22. const [anthology, setAnthology] = useState<IOptions[]>([
  23. { value: "all", label: "全部" },
  24. ]);
  25. useEffect(() => {
  26. let url = `/v2/studio?view=collaboration-channel&studio_name=${studioName}`;
  27. get<IStudioListResponse>(url).then((json) => {
  28. if (json.ok) {
  29. const data = json.data.rows.map((item) => {
  30. return {
  31. value: item.id,
  32. label: item.nickName,
  33. };
  34. });
  35. setAnthology([{ value: "all", label: "全部" }, ...data]);
  36. }
  37. });
  38. }, [studioName]);
  39. return (
  40. <Select
  41. defaultValue="all"
  42. style={{ width: 180 }}
  43. onChange={(value: string) => {
  44. console.log(`selected ${value}`);
  45. if (typeof onSelect !== "undefined") {
  46. onSelect(value);
  47. }
  48. }}
  49. options={anthology}
  50. />
  51. );
  52. };
  53. export default StudioSelectWidget;