fix(h5-shop): tip unbound WeChat login to use phone first
This commit is contained in:
@@ -15,6 +15,40 @@ export type ShopAccountProfile = {
|
||||
store?: { name: string };
|
||||
};
|
||||
|
||||
/** 微信未绑定门店账号时的登录提示 */
|
||||
export const SHOP_WX_NEED_PHONE_LOGIN_MSG = '请先用手机号登录';
|
||||
|
||||
const SHOP_WX_LOGIN_HINT_KEY = 'shop_wx_login_hint';
|
||||
|
||||
export function isShopWechatUnboundError(message: string): boolean {
|
||||
return message.includes('首次登录') || message.includes('手机验证码') || message.includes('请先用手机号');
|
||||
}
|
||||
|
||||
export function formatShopWechatError(e: unknown): string {
|
||||
const text = e instanceof Error ? e.message : '微信登录失败';
|
||||
if (isShopWechatUnboundError(text)) return SHOP_WX_NEED_PHONE_LOGIN_MSG;
|
||||
return text;
|
||||
}
|
||||
|
||||
/** OAuth 在启动层失败时暂存提示,供登录页展示 */
|
||||
export function stashShopWechatLoginHint(message: string): void {
|
||||
try {
|
||||
sessionStorage.setItem(SHOP_WX_LOGIN_HINT_KEY, message);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function consumeShopWechatLoginHint(): string | null {
|
||||
try {
|
||||
const hint = sessionStorage.getItem(SHOP_WX_LOGIN_HINT_KEY);
|
||||
if (hint) sessionStorage.removeItem(SHOP_WX_LOGIN_HINT_KEY);
|
||||
return hint;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchClientConfig(): Promise<ClientRuntimeConfig> {
|
||||
return request<ClientRuntimeConfig>('SHOP_H5', '/common/client-config');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user