feat: 支持小程序上传配置加密存储
This commit is contained in:
1 parent
526a9db789
commit
3d0252d187
10 files changed
+257
-12
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
@@ -40,6 +40,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [note, setNote] = useState("");
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [settingsAppId, setSettingsAppId] = useState("");
|
||||
const [settingsArtifactPath, setSettingsArtifactPath] = useState("");
|
||||
const [settingsPrivateKey, setSettingsPrivateKey] = useState("");
|
||||
const brand = useQuery({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
@@ -69,6 +73,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
queryKey: ["publication-miniapp-releases"],
|
||||
queryFn: () => client.listAdminMiniAppReleases(),
|
||||
});
|
||||
const miniAppSettings = useQuery({
|
||||
queryKey: ["publication-miniapp-settings"],
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
const refresh = () => {
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
@@ -145,6 +153,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
void miniAppReleases.refetch();
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
mutationFn: (values: { appId?: string; artifactPath?: string; privateKey?: string }) =>
|
||||
client.updateAdminMiniAppSettings(values),
|
||||
onSuccess: () => {
|
||||
setSettingsOpen(false);
|
||||
message.success("小程序上传配置已保存");
|
||||
void miniAppSettings.refetch();
|
||||
},
|
||||
});
|
||||
const uploadMiniAppRelease = useMutation({
|
||||
mutationFn: (id: string) => client.uploadAdminMiniAppRelease(id),
|
||||
onSuccess: () => {
|
||||
@@ -178,6 +195,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
void miniAppReleases.refetch();
|
||||
void miniAppSettings.refetch();
|
||||
};
|
||||
const industryKey =
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
@@ -194,6 +212,12 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
? brand.data.config.visualTemplateKey
|
||||
: (visuals[0]?.key ?? null);
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
setSettingsAppId(miniAppSettings.data.appId);
|
||||
setSettingsArtifactPath(miniAppSettings.data.artifactPath);
|
||||
setSettingsPrivateKey("");
|
||||
}, [miniAppSettings.data]);
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
);
|
||||
@@ -384,13 +408,21 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
<Typography.Paragraph type="secondary">
|
||||
使用微信官方 miniprogram-ci 上传代码;审核与发布状态需按微信平台结果人工确认。
|
||||
</Typography.Paragraph>
|
||||
<Button
|
||||
disabled={!currentRelease}
|
||||
loading={createMiniAppRelease.isPending}
|
||||
onClick={() => createMiniAppRelease.mutate()}
|
||||
>
|
||||
基于当前品牌版本创建任务
|
||||
</Button>
|
||||
<Space wrap style={{ marginBottom: 12 }}>
|
||||
<Button
|
||||
disabled={!currentRelease}
|
||||
loading={createMiniAppRelease.isPending}
|
||||
onClick={() => createMiniAppRelease.mutate()}
|
||||
>
|
||||
基于当前品牌版本创建任务
|
||||
</Button>
|
||||
<Button onClick={() => setSettingsOpen(true)}>上传配置</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<Tag color="green">已配置上传凭据</Tag>
|
||||
) : (
|
||||
<Tag color="warning">未配置上传凭据</Tag>
|
||||
)}
|
||||
</Space>
|
||||
<Divider />
|
||||
{miniAppReleases.data?.length ? (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
@@ -527,6 +559,44 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
>
|
||||
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
||||
</Modal>
|
||||
<Modal
|
||||
title="小程序上传配置"
|
||||
open={settingsOpen}
|
||||
onCancel={() => setSettingsOpen(false)}
|
||||
confirmLoading={saveMiniAppSettings.isPending}
|
||||
onOk={() =>
|
||||
saveMiniAppSettings.mutate({
|
||||
appId: settingsAppId,
|
||||
artifactPath: settingsArtifactPath,
|
||||
...(settingsPrivateKey ? { privateKey: settingsPrivateKey } : {}),
|
||||
})
|
||||
}
|
||||
>
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<Input
|
||||
value={settingsAppId}
|
||||
onChange={(event) => setSettingsAppId(event.target.value)}
|
||||
placeholder="微信 AppID"
|
||||
/>
|
||||
<Input
|
||||
value={settingsArtifactPath}
|
||||
onChange={(event) => setSettingsArtifactPath(event.target.value)}
|
||||
placeholder="服务端可访问的构建产物路径"
|
||||
/>
|
||||
<Input.Password
|
||||
value={settingsPrivateKey}
|
||||
onChange={(event) => setSettingsPrivateKey(event.target.value)}
|
||||
placeholder={
|
||||
miniAppSettings.data?.hasStoredCredentials
|
||||
? "已加密保存,输入新值可替换"
|
||||
: "微信上传私钥"
|
||||
}
|
||||
/>
|
||||
<Typography.Text type="secondary">
|
||||
私钥使用 AES-256-GCM 加密后保存;加密密钥只保留在服务端环境变量中。
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
</Modal>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user