feat: 简化小程序上传入口
This commit is contained in:
1 parent
d5a84b51a7
commit
ad949ab370
4 files changed
+29
-66
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
@@ -41,10 +41,6 @@ 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 [activeTab, setActiveTab] = useState("content");
|
||||
const brand = useQuery({
|
||||
queryKey: ["publication-brand"],
|
||||
@@ -148,19 +144,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const createMiniAppRelease = useMutation({
|
||||
mutationFn: () => client.createAdminMiniAppRelease(),
|
||||
onSuccess: () => {
|
||||
message.success("小程序发布任务已创建");
|
||||
void miniAppReleases.refetch();
|
||||
const uploadLatestMiniAppRelease = useMutation({
|
||||
mutationFn: async () => {
|
||||
const latest = await client.getLatestAdminMiniAppRelease();
|
||||
if (!latest) throw new Error("还没有可发布的内容版本");
|
||||
return client.uploadAdminMiniAppRelease(latest.id);
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
mutationFn: (values: { appId?: string; artifactPath?: string; privateKey?: string }) =>
|
||||
client.updateAdminMiniAppSettings(values),
|
||||
onSuccess: () => {
|
||||
message.success("小程序上传配置已保存");
|
||||
void miniAppSettings.refetch();
|
||||
message.success("小程序代码已上传");
|
||||
void miniAppReleases.refetch();
|
||||
},
|
||||
});
|
||||
const uploadMiniAppRelease = useMutation({
|
||||
@@ -219,13 +211,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
? brand.data.config.visualTemplateKey
|
||||
: (visuals[0]?.key ?? null);
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const settings = miniAppSettings.data;
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
setSettingsAppId(miniAppSettings.data.appId);
|
||||
setSettingsArtifactPath(miniAppSettings.data.artifactPath);
|
||||
setSettingsPrivateKey("");
|
||||
}, [settings]);
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
);
|
||||
@@ -438,13 +423,13 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
</Typography.Paragraph>
|
||||
<Space wrap style={{ marginBottom: 12 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={createMiniAppRelease.isPending}
|
||||
onClick={() => createMiniAppRelease.mutate()}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
基于当前品牌版本创建任务
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
<Button onClick={() => setSettingsOpen(true)}>上传配置</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<Tag color="green">已配置上传凭据</Tag>
|
||||
) : (
|
||||
@@ -590,44 +575,6 @@ 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>
|
||||
);
|
||||
}
|
||||
@@ -47,6 +47,16 @@ export class AdminMiniAppReleaseController {
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
@Get("latest")
|
||||
async latest(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const identity = await this.identity(request);
|
||||
const task = await this.prisma.miniAppReleaseTask.findFirst({
|
||||
where: { brandId: identity.brandId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return task ?? null;
|
||||
}
|
||||
|
||||
@Get("settings")
|
||||
async settings(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const identity = await this.identity(request);
|
||||
@@ -129,7 +139,8 @@ export class AdminMiniAppReleaseController {
|
||||
where: { id: taskId, brandId: identity.brandId },
|
||||
});
|
||||
if (!task) throw new BadRequestException("小程序发布任务不存在");
|
||||
if (task.status !== "built") throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||
if (task.status !== "built" && task.status !== "failed")
|
||||
throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
||||
where: { id: identity.brandId },
|
||||
select: { miniAppSettings: true },
|
||||
|
||||
Reference in new issue
Block a user