|
@@ -34,7 +34,7 @@ interface AuthResultData {
|
|
|
ghId: string;
|
|
|
}
|
|
|
|
|
|
-const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel, authFailed = false, accountData }: AccountDialogProps) => {
|
|
|
+const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel, accountData }: AccountDialogProps) => {
|
|
|
const [qrCodeUrl, setQrCodeUrl] = useState<string>("");
|
|
|
const [accountName, setAccountName] = useState<string>("授权成功后展示");
|
|
|
const [accountId, setAccountId] = useState<string>("授权成功后展示");
|
|
@@ -42,6 +42,7 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
const [selectedContentType, setSelectedContentType] = useState<string>("");
|
|
|
const [authSuccess, setAuthSuccess] = useState<boolean>(false);
|
|
|
const [saving, setSaving] = useState<boolean>(false);
|
|
|
+ const [authFailed, setAuthFailed] = useState<boolean>(false);
|
|
|
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
|
|
|
|
|
// 生成随机code
|
|
@@ -53,7 +54,7 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
const getQrCode = async () => {
|
|
|
try {
|
|
|
const code = generateRandomCode();
|
|
|
- const res = await http.post<{ qrcodeStr: string }>(accountGetAuthQrCode, { params: { code } });
|
|
|
+ const res = await http.post<{ qrcodeStr: string }>(accountGetAuthQrCode, { code });
|
|
|
if (res.success && res.data && res.data.qrcodeStr) {
|
|
|
setQrCodeUrl(res.data.qrcodeStr);
|
|
|
// 开始轮询检查授权结果
|
|
@@ -75,7 +76,7 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
// 检查授权结果
|
|
|
const checkAuthResult = async (code: string) => {
|
|
|
try {
|
|
|
- const res = await http.post<AuthResultData>(accountGetAuthResult, { params: { code } });
|
|
|
+ const res = await http.post<AuthResultData>(accountGetAuthResult, { code });
|
|
|
if (res.success) {
|
|
|
if (res.data) {
|
|
|
// 授权成功
|
|
@@ -91,6 +92,8 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
timerRef.current = setTimeout(() => checkAuthResult(code), 3000);
|
|
|
}
|
|
|
} else {
|
|
|
+ // 接口返回失败,设置授权失败状态
|
|
|
+ setAuthFailed(true);
|
|
|
if (timerRef.current) {
|
|
|
clearTimeout(timerRef.current);
|
|
|
timerRef.current = null;
|
|
@@ -98,6 +101,8 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error("检查授权结果失败:", error);
|
|
|
+ // 接口调用异常,设置授权失败状态
|
|
|
+ setAuthFailed(true);
|
|
|
if (timerRef.current) {
|
|
|
clearTimeout(timerRef.current);
|
|
|
timerRef.current = null;
|
|
@@ -220,7 +225,7 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
cancelText="取消"
|
|
|
okText="确定"
|
|
|
onOk={handleSave}
|
|
|
- okButtonProps={{ loading: saving }}
|
|
|
+ okButtonProps={{ loading: saving, disabled: authFailed }}
|
|
|
onCancel={handleCancel}>
|
|
|
{authFailed ? (
|
|
|
<div className={"p-[20px] text-[#333] text-center"}>
|
|
@@ -232,6 +237,7 @@ const AccountDialog = ({ title, isOpen, handleOk: parentHandleOk, handleCancel,
|
|
|
</div>
|
|
|
<Button type="primary" onClick={() => {
|
|
|
setAuthSuccess(false);
|
|
|
+ setAuthFailed(false);
|
|
|
getQrCode();
|
|
|
}} className={"mb-[20px]"}>重新扫码</Button>
|
|
|
</div>
|
|
@@ -461,7 +467,6 @@ const Gzh: React.FC = () => {
|
|
|
isOpen={isOpen}
|
|
|
handleOk={handleOk}
|
|
|
handleCancel={handleCancel}
|
|
|
- authFailed={authFailed}
|
|
|
accountData={currentAccount}
|
|
|
/>
|
|
|
</>
|