import { useState } from "react"; import { Button, Input, Space, Tooltip, Typography } from "antd"; import { FolderOpenOutlined, CheckCircleTwoTone, LoadingOutlined, WarningTwoTone, } from "@ant-design/icons"; import type { TChannelType } from "../../api/Channel"; import { post } from "../../request"; import ChannelTableModal from "./ChannelTableModal"; import type { IChannel } from "./Channel"; import type { IPayload, ITokenCreate, ITokenCreateResponse, TPower, } from "../../api/token"; const { Text } = Typography; interface IData { value: string; label: string; } interface IWidget { channelsId?: string[]; type?: TChannelType; book?: number; para?: number; power?: TPower; onChange?: (channel?: string | null) => void; } const ChannelSelectWithToken = ({ type, book, para, power, onChange, }: IWidget) => { const [curr, setCurr] = useState(); const [access, setAccess] = useState(); const [loading, setLoading] = useState(false); return ( { if (event.target.value.trim().length === 0) { setCurr(undefined); setAccess(undefined); if (onChange) { onChange(undefined); } } }} /> } type="text" />} onSelect={(channel: IChannel) => { setCurr({ value: channel.id, label: channel.name }); //验证权限 if (power) { setLoading(true); const payload: IPayload[] = []; payload.push({ res_id: channel.id, res_type: "channel", power: power, }); const url = "/v2/access-token"; const values = { payload: payload }; console.info("token api request", url, values); post(url, values) .then((json) => { console.info("token api response", json); if (json.ok) { if (json.data.count > 0) { setAccess(true); } } }) .finally(() => setLoading(false)); } if (onChange) { onChange(channel.id + (power ? "@" + power : "")); } }} /> {power} {loading ? ( ) : typeof access !== "undefined" ? ( access ? ( ) : ( ) ) : ( <> )} ); }; export default ChannelSelectWithToken;