ChannelSelect.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { ProFormCascader } from "@ant-design/pro-components";
  2. import { message } from "antd";
  3. import { get } from "../../request";
  4. import { IApiResponseChannelList } from "../api/Channel";
  5. interface IOption {
  6. value: string;
  7. label: string;
  8. }
  9. interface IWidget {
  10. width?: number | "md" | "sm" | "xl" | "xs" | "lg";
  11. channelId?: string;
  12. name?: string;
  13. tooltip?: string;
  14. label?: string;
  15. onSelect?: Function;
  16. }
  17. const Widget = ({
  18. width = "md",
  19. channelId,
  20. name = "channel",
  21. tooltip,
  22. label,
  23. onSelect,
  24. }: IWidget) => {
  25. return (
  26. <ProFormCascader
  27. width={width}
  28. name={name}
  29. tooltip={tooltip}
  30. label={label}
  31. request={async ({ keyWords }) => {
  32. console.log("keyWord", keyWords);
  33. const json = await get<IApiResponseChannelList>(
  34. `/v2/channel?view=user-edit&key=${keyWords}`
  35. );
  36. if (json.ok) {
  37. //获取studio list
  38. let studio = new Map<string, string>();
  39. for (const iterator of json.data.rows) {
  40. studio.set(iterator.studio.id, iterator.studio.nickName);
  41. }
  42. let channels: IOption[] = [];
  43. studio.forEach((value, key, map) => {
  44. const node = {
  45. value: key,
  46. label: value,
  47. children: json.data.rows
  48. .filter((value) => value.studio.id === key)
  49. .map((item) => {
  50. return { value: item.uid, label: item.name };
  51. }),
  52. };
  53. channels.push(node);
  54. });
  55. console.log("json", channels);
  56. return channels;
  57. } else {
  58. message.error(json.message);
  59. return [];
  60. }
  61. }}
  62. fieldProps={{}}
  63. />
  64. );
  65. };
  66. export default Widget;