支付时检测是否已经微信授权

This commit is contained in:
2026-07-02 17:34:58 +08:00
parent a0f4d8c18f
commit f7fe4597c6
9 changed files with 254 additions and 15 deletions
+6 -4
View File
@@ -1,13 +1,15 @@
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import AppImage from '@dukang/shared-ui/AppImage';
import type { WechatLoginResult } from '@dukang/shared-types';
import { request, saveSession } from '../lib/api';
import { request, saveSession, type UserProfile } from '../lib/api';
import { normalizePhoneInput, validateMobilePhone } from '../lib/phone';
import { isWechatEnv, weixinSdk } from '../lib/weixin';
export default function LoginPage() {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const returnTo = searchParams.get('return') || '/';
const [phone, setPhone] = useState('13800000001');
const [code, setCode] = useState('123456');
const [loading, setLoading] = useState(false);
@@ -43,7 +45,7 @@ export default function LoginPage() {
phoneVerified: !!result.phoneVerified,
user: result.user as never,
});
navigate('/');
navigate(returnTo.startsWith('/') ? returnTo : '/');
}
}
@@ -111,7 +113,7 @@ export default function LoginPage() {
body: JSON.stringify({ phone, code }),
});
saveSession(data);
navigate('/');
navigate(returnTo.startsWith('/') ? returnTo : '/');
} catch (e) {
setMsg(e instanceof Error ? e.message : '登录失败');
} finally {