feat: 支持按品牌配置微信登录凭据
This commit is contained in:
1 parent
e75c524343
commit
d0a0eeea8c
23 files changed
+460
-62
No files matched your search
@@ -9,6 +9,7 @@ export type MiniAppSettingsValues = {
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
privateKey?: string;
|
||||
appSecret?: string;
|
||||
};
|
||||
|
||||
interface MiniAppSettingsTabProps {
|
||||
@@ -27,14 +28,15 @@ export function MiniAppSettingsTab({ settings, saving, error, onSave }: MiniAppS
|
||||
appId: settings.appId,
|
||||
apiBaseUrl: settings.apiBaseUrl,
|
||||
privateKey: "",
|
||||
appSecret: "",
|
||||
});
|
||||
}, [form, settings]);
|
||||
|
||||
return (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序上传配置"
|
||||
description="AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM 加密。"
|
||||
title="小程序配置"
|
||||
description="AppID 同时用于代码上传和小程序登录;AppSecret 只用于 wx.login 换取 OpenID;上传私钥和 AppSecret 均使用 AES-256-GCM 加密保存。"
|
||||
>
|
||||
{settings?.buildError ? (
|
||||
<Alert
|
||||
@@ -59,7 +61,32 @@ export function MiniAppSettingsTab({ settings, saving, error, onSave }: MiniAppS
|
||||
label="微信 AppID"
|
||||
rules={[{ required: true, message: "请输入微信 AppID" }]}
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
<Input maxLength={100} autoComplete="off" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="appSecret"
|
||||
label="微信登录 AppSecret"
|
||||
help={
|
||||
settings?.hasStoredAppSecret
|
||||
? "已加密保存。留空保持现有 AppSecret;修改 AppID 时必须同时填写新 AppID 对应的 AppSecret。"
|
||||
: "从微信公众平台“开发管理 → 开发设置”复制。保存后立即生效,不需要重新上传小程序代码。"
|
||||
}
|
||||
rules={[
|
||||
{
|
||||
validator: (_rule, value: string) =>
|
||||
!value || /^[A-Za-z0-9]{16,64}$/.test(value.trim())
|
||||
? Promise.resolve()
|
||||
: Promise.reject(new Error("AppSecret 应为 16-64 位字母或数字,请复制完整值")),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input.Password
|
||||
maxLength={64}
|
||||
autoComplete="new-password"
|
||||
placeholder={
|
||||
settings?.hasStoredAppSecret ? "留空保持现有 AppSecret" : "填写该小程序的 AppSecret"
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="apiBaseUrl"
|
||||
@@ -98,15 +125,29 @@ export function MiniAppSettingsTab({ settings, saving, error, onSave }: MiniAppS
|
||||
className="admin-code-input"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
{!settings?.loginConfigured ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
title="微信登录尚不可用"
|
||||
description="该品牌需要同时保存微信 AppID 和 AppSecret,体验版才能通过 wx.login 换取 OpenID。"
|
||||
/>
|
||||
) : null}
|
||||
<Space wrap>
|
||||
<Button type="primary" loading={saving} htmlType="submit">
|
||||
保存上传配置
|
||||
保存小程序配置
|
||||
</Button>
|
||||
{settings?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已加密保存上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传私钥" />
|
||||
)}
|
||||
{settings?.hasStoredAppSecret ? (
|
||||
<StatusTag tone="success" label="已加密保存登录凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置登录 AppSecret" />
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={error} />
|
||||
</Form>
|
||||
|
||||
@@ -56,14 +56,20 @@ export function usePublicationMutations({
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
mutationFn: (values: { appId: string; apiBaseUrl: string; privateKey?: string }) =>
|
||||
mutationFn: (values: {
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
privateKey?: string;
|
||||
appSecret?: string;
|
||||
}) =>
|
||||
client.updateAdminMiniAppSettings({
|
||||
appId: values.appId,
|
||||
apiBaseUrl: values.apiBaseUrl,
|
||||
...(values.privateKey ? { privateKey: values.privateKey } : {}),
|
||||
...(values.appSecret ? { appSecret: values.appSecret } : {}),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("小程序上传配置已保存");
|
||||
message.success("小程序配置已保存");
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-settings"] });
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user