v3计划内容上传

This commit is contained in:
2026-07-04 20:36:26 +08:00
parent def3ed5175
commit 743d242d52
23 changed files with 291 additions and 53 deletions
+1
View File
@@ -22,6 +22,7 @@ function WechatOAuthHandler() {
useEffect(() => {
if (!isWechatEnv() || !location.search.includes('code=')) return;
if (location.pathname === '/login') return;
void handlePartnerWechatCallback()
.then((result) => {
if (!result || !savePartnerWechatAuth(result)) return;
+45 -3
View File
@@ -1,6 +1,12 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import { request, saveAuth } from '../lib/api';
import {
authorizePartnerWechat,
handlePartnerWechatCallback,
savePartnerWechatAuth,
} from '../lib/wechat-auth';
import { isWechatEnv } from '../lib/weixin';
export default function LoginPage() {
const navigate = useNavigate();
@@ -9,7 +15,21 @@ export default function LoginPage() {
const [phone, setPhone] = useState('13700000001');
const [code, setCode] = useState('123456');
const [loading, setLoading] = useState(false);
const [wechatLoading, setWechatLoading] = useState(false);
const [codeCooldown, setCodeCooldown] = useState(0);
const [msg, setMsg] = useState('');
useEffect(() => {
if (!isWechatEnv()) return;
void handlePartnerWechatCallback()
.then((result) => {
if (!result) return;
if (savePartnerWechatAuth(result)) {
navigate('/');
}
})
.catch((e) => setMsg(e instanceof Error ? e.message : '微信登录失败'));
}, [navigate]);
async function login() {
setLoading(true);
@@ -29,6 +49,21 @@ export default function LoginPage() {
}
}
async function wechatLogin() {
setMsg('');
if (!isWechatEnv()) {
setMsg('请在微信内打开以使用微信一键登录');
return;
}
setWechatLoading(true);
try {
await authorizePartnerWechat();
} catch (e) {
setMsg(e instanceof Error ? e.message : '微信登录失败');
setWechatLoading(false);
}
}
function sendCode() {
if (codeCooldown > 0) return;
request('PARTNER_H5', '/partner/auth/sms/send', {
@@ -122,10 +157,17 @@ export default function LoginPage() {
{!loading && <span className="material-symbols-outlined">arrow_forward</span>}
</button>
<div className="partner-auth-divider"><span></span></div>
<button type="button" className="partner-btn-outline" style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8 }}>
<button
type="button"
className="partner-btn-outline"
style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8 }}
disabled={wechatLoading || loading}
onClick={() => void wechatLogin()}
>
<svg width="24" height="24" viewBox="0 0 24 24" fill="#07C160"><path d="M8.25 4.5C4.52 4.5 1.5 7.04 1.5 10.17c0 1.78.98 3.37 2.5 4.48l-.63 1.88 2.19-1.09c.84.24 1.74.38 2.69.38.25 0 .5 0 .75-.03-.16-.53-.25-1.09-.25-1.66 0-3.13 3.02-5.67 6.75-5.67.57 0 1.13.06 1.66.17C15.17 6.13 12 4.5 8.25 4.5zm10.5 6.33c-3.11 0-5.62 2.12-5.62 4.73 0 2.61 2.51 4.73 5.62 4.73.79 0 1.54-.14 2.24-.38l1.83.91-.53-1.57c1.27-.92 2.08-2.25 2.08-3.73 0-2.61-2.51-4.73-5.62-4.73z" /></svg>
{wechatLoading ? '跳转授权中…' : '微信一键登录'}
</button>
{msg && <p className="partner-form-error" role="alert">{msg}</p>}
<label className="partner-checkbox-row">
<input type="checkbox" />
<span>