fix:完善门店和总部管理端
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { WechatLoginResult } from '@dukang/shared-types';
|
||||
import { WECHAT_INAPP_REQUIRED_MSG } from '@dukang/weixin-sdk';
|
||||
import { isWechatEnv, weixinSdk } from './weixin';
|
||||
import { request, saveAuth } from './api';
|
||||
|
||||
@@ -31,37 +32,16 @@ export async function handlePartnerWechatCallback(): Promise<WechatLoginResult |
|
||||
return weixinSdk.handleOAuthCallback();
|
||||
}
|
||||
|
||||
let clientConfigCache: { mockWechat?: boolean } | null = null;
|
||||
|
||||
async function fetchClientConfig(): Promise<{ mockWechat?: boolean }> {
|
||||
if (clientConfigCache) return clientConfigCache;
|
||||
try {
|
||||
clientConfigCache = await request<{ mockWechat?: boolean }>('PARTNER_H5', '/common/client-config');
|
||||
} catch {
|
||||
clientConfigCache = {};
|
||||
}
|
||||
return clientConfigCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信授权登录(与 C 端一致:微信内走公众号 OAuth)。
|
||||
* 微信授权登录(对齐 C 端:仅微信内置浏览器走 OAuth)。
|
||||
* 返回 true = 已登录;void = 已跳转授权页等待回调。
|
||||
*/
|
||||
export async function loginPartnerWithWechat(): Promise<boolean | void> {
|
||||
if (isWechatEnv()) {
|
||||
const result = await weixinSdk.login();
|
||||
if (result) return handlePartnerWechatLoginResult(result);
|
||||
return;
|
||||
if (!isWechatEnv()) {
|
||||
throw new Error(WECHAT_INAPP_REQUIRED_MSG);
|
||||
}
|
||||
const cfg = await fetchClientConfig();
|
||||
if (!cfg.mockWechat) {
|
||||
throw new Error('请在微信内打开以使用微信一键授权');
|
||||
}
|
||||
const result = await request<WechatLoginResult>('PARTNER_H5', '/partner/auth/login/wechat', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ code: `mockcode_${Date.now()}`, platform: 'h5' }),
|
||||
});
|
||||
return handlePartnerWechatLoginResult(result);
|
||||
const result = await weixinSdk.login();
|
||||
if (result) return handlePartnerWechatLoginResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +54,7 @@ export async function bindPartnerWechatAfterSmsLogin(): Promise<void> {
|
||||
|
||||
export async function authorizePartnerWechat(): Promise<WechatLoginResult | void> {
|
||||
if (!isWechatEnv()) {
|
||||
throw new Error('请在微信内打开以完成授权');
|
||||
throw new Error(WECHAT_INAPP_REQUIRED_MSG);
|
||||
}
|
||||
return weixinSdk.login();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user