fix(h5-shop): remove redeem debug UI and enforce WeChat scan flow
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -65,7 +65,7 @@ export default function HomePage() {
|
|||||||
|
|
||||||
async function runScan() {
|
async function runScan() {
|
||||||
if (!isWechatEnv()) {
|
if (!isWechatEnv()) {
|
||||||
navigate('/redeem');
|
setScanMsg('请在微信内打开门店端进行扫码核销');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setScanning(true);
|
setScanning(true);
|
||||||
@@ -90,7 +90,7 @@ export default function HomePage() {
|
|||||||
async function handleScan() {
|
async function handleScan() {
|
||||||
setScanMsg('');
|
setScanMsg('');
|
||||||
if (!isWechatEnv()) {
|
if (!isWechatEnv()) {
|
||||||
navigate('/redeem');
|
setScanMsg('请在微信内打开门店端进行扫码核销');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ export default function RedeemConfirmPage() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const scanned = searchParams.get('token');
|
const scanned = searchParams.get('token')?.trim();
|
||||||
if (scanned) setToken(scanned);
|
if (!scanned) {
|
||||||
}, [searchParams]);
|
navigate('/', { replace: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setToken(scanned);
|
||||||
|
}, [searchParams, navigate]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!token.trim()) {
|
if (!token.trim()) {
|
||||||
@@ -71,7 +75,7 @@ export default function RedeemConfirmPage() {
|
|||||||
body: JSON.stringify({ token }),
|
body: JSON.stringify({ token }),
|
||||||
});
|
});
|
||||||
sessionStorage.setItem('lastRedeemResult', JSON.stringify(result));
|
sessionStorage.setItem('lastRedeemResult', JSON.stringify(result));
|
||||||
navigate('/redeem/success', { state: { result, storeName } });
|
navigate('/redeem/success', { state: { result, storeName, user: preview?.user } });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setMsg(e instanceof Error ? e.message : '核销失败');
|
setMsg(e instanceof Error ? e.message : '核销失败');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -80,7 +84,7 @@ export default function RedeemConfirmPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const previewAmount = preview?.amount ?? 0;
|
const previewAmount = preview?.amount ?? 0;
|
||||||
const userLabel = preview?.user?.nickname || preview?.user?.phone || preview?.user?.userNo || '待扫码确认';
|
const userLabel = preview?.user?.nickname || preview?.user?.phone || preview?.user?.userNo || '—';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="shop-redeem-page">
|
<div className="shop-redeem-page">
|
||||||
@@ -161,21 +165,10 @@ export default function RedeemConfirmPage() {
|
|||||||
<span className="material-symbols-outlined shop-fill-icon">
|
<span className="material-symbols-outlined shop-fill-icon">
|
||||||
{loading ? 'sync' : 'check_circle'}
|
{loading ? 'sync' : 'check_circle'}
|
||||||
</span>
|
</span>
|
||||||
<span>{loading ? '正在核销...' : preview ? `确认核销 ¥${formatAmount(previewAmount)}` : '等待扫码'}</span>
|
<span>{loading ? '正在核销...' : preview ? `确认核销 ¥${formatAmount(previewAmount)}` : '加载中…'}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p className="shop-redeem-hint">请核对金额后点击确认</p>
|
<p className="shop-redeem-hint">请核对金额后点击确认</p>
|
||||||
|
|
||||||
<details className="shop-redeem-dev">
|
|
||||||
<summary>开发者选项 · 手动输入核销码</summary>
|
|
||||||
<div className="shop-redeem-dev-body">
|
|
||||||
<input
|
|
||||||
value={token}
|
|
||||||
onChange={(e) => setToken(e.target.value)}
|
|
||||||
placeholder="粘贴用户核销码"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ export default function RedeemSuccessPage() {
|
|||||||
}, [location.state]);
|
}, [location.state]);
|
||||||
|
|
||||||
const storeName = (location.state as { storeName?: string })?.storeName || '当前门店';
|
const storeName = (location.state as { storeName?: string })?.storeName || '当前门店';
|
||||||
const amount = Number(result?.amount || 100);
|
const user = (location.state as { user?: { nickname?: string; phone?: string; userNo?: string } })?.user;
|
||||||
|
const userLabel = user?.nickname || user?.phone || user?.userNo || '—';
|
||||||
|
const amount = Number(result?.amount ?? 0);
|
||||||
const redeemNo = String(result?.redeemNo || '—');
|
const redeemNo = String(result?.redeemNo || '—');
|
||||||
const createdAt = result?.createdAt
|
const createdAt = result?.createdAt
|
||||||
? new Date(String(result.createdAt)).toLocaleString('zh-CN')
|
? new Date(String(result.createdAt)).toLocaleString('zh-CN')
|
||||||
@@ -58,8 +60,7 @@ export default function RedeemSuccessPage() {
|
|||||||
<span className="material-symbols-outlined">person</span>
|
<span className="material-symbols-outlined">person</span>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ textAlign: 'right' }}>
|
<div style={{ textAlign: 'right' }}>
|
||||||
<div className="shop-success-detail-value">杜康用户</div>
|
<div className="shop-success-detail-value">{userLabel}</div>
|
||||||
<div className="shop-success-detail-label">待完善</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,7 +79,7 @@ export default function RedeemSuccessPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="shop-success-actions">
|
<div className="shop-success-actions">
|
||||||
<button type="button" className="shop-success-primary-btn" onClick={() => navigate('/redeem')}>
|
<button type="button" className="shop-success-primary-btn" onClick={() => navigate('/')}>
|
||||||
<span>继续核销</span>
|
<span>继续核销</span>
|
||||||
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>qr_code_scanner</span>
|
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>qr_code_scanner</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1116,38 +1116,6 @@
|
|||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
.shop-redeem-dev {
|
|
||||||
margin-top: 8px;
|
|
||||||
border: 1px dashed var(--color-outline-variant);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-redeem-dev summary {
|
|
||||||
padding: 12px 16px;
|
|
||||||
font-family: var(--font-label);
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--color-subtle-gray);
|
|
||||||
cursor: pointer;
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-redeem-dev summary::-webkit-details-marker {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-redeem-dev-body {
|
|
||||||
padding: 0 16px 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-redeem-dev-body input {
|
|
||||||
width: 100%;
|
|
||||||
padding: 12px;
|
|
||||||
border: 1px solid var(--color-outline-variant);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-redeem-error {
|
.shop-redeem-error {
|
||||||
color: var(--color-error);
|
color: var(--color-error);
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
|||||||
@@ -47,6 +47,5 @@ export async function scanQrCode(config: WeixinSdkConfig): Promise<string | null
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const manual = typeof window !== 'undefined' ? window.prompt('当前环境无法调起微信扫码,请手动输入核销码') : null;
|
throw new Error('请在微信内打开以使用扫码核销');
|
||||||
return manual?.trim() || null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user