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 { useNavigate } from "react-router-dom";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
@@ -41,10 +41,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
||||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||||
const [note, setNote] = useState("");
|
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 [activeTab, setActiveTab] = useState("content");
|
||||||
const brand = useQuery({
|
const brand = useQuery({
|
||||||
queryKey: ["publication-brand"],
|
queryKey: ["publication-brand"],
|
||||||
@@ -148,19 +144,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
refresh();
|
refresh();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const createMiniAppRelease = useMutation({
|
const uploadLatestMiniAppRelease = useMutation({
|
||||||
mutationFn: () => client.createAdminMiniAppRelease(),
|
mutationFn: async () => {
|
||||||
onSuccess: () => {
|
const latest = await client.getLatestAdminMiniAppRelease();
|
||||||
message.success("小程序发布任务已创建");
|
if (!latest) throw new Error("还没有可发布的内容版本");
|
||||||
void miniAppReleases.refetch();
|
return client.uploadAdminMiniAppRelease(latest.id);
|
||||||
},
|
},
|
||||||
});
|
|
||||||
const saveMiniAppSettings = useMutation({
|
|
||||||
mutationFn: (values: { appId?: string; artifactPath?: string; privateKey?: string }) =>
|
|
||||||
client.updateAdminMiniAppSettings(values),
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("小程序上传配置已保存");
|
message.success("小程序代码已上传");
|
||||||
void miniAppSettings.refetch();
|
void miniAppReleases.refetch();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const uploadMiniAppRelease = useMutation({
|
const uploadMiniAppRelease = useMutation({
|
||||||
@@ -219,13 +211,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
? brand.data.config.visualTemplateKey
|
? brand.data.config.visualTemplateKey
|
||||||
: (visuals[0]?.key ?? null);
|
: (visuals[0]?.key ?? null);
|
||||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
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(
|
const publishedHistory = (releases.data ?? []).filter(
|
||||||
(item) => item.status === "published" || item.status === "superseded",
|
(item) => item.status === "published" || item.status === "superseded",
|
||||||
);
|
);
|
||||||
@@ -438,13 +423,13 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<Space wrap style={{ marginBottom: 12 }}>
|
<Space wrap style={{ marginBottom: 12 }}>
|
||||||
<Button
|
<Button
|
||||||
|
type="primary"
|
||||||
disabled={!currentRelease}
|
disabled={!currentRelease}
|
||||||
loading={createMiniAppRelease.isPending}
|
loading={uploadLatestMiniAppRelease.isPending}
|
||||||
onClick={() => createMiniAppRelease.mutate()}
|
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||||
>
|
>
|
||||||
基于当前品牌版本创建任务
|
上传当前版本到微信
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => setSettingsOpen(true)}>上传配置</Button>
|
|
||||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||||
<Tag color="green">已配置上传凭据</Tag>
|
<Tag color="green">已配置上传凭据</Tag>
|
||||||
) : (
|
) : (
|
||||||
@@ -590,44 +575,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
>
|
>
|
||||||
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
||||||
</Modal>
|
</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>
|
</QueryState>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,16 @@ export class AdminMiniAppReleaseController {
|
|||||||
private readonly prisma: PrismaService,
|
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")
|
@Get("settings")
|
||||||
async settings(@Req() request: FastifyRequest): Promise<unknown> {
|
async settings(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
const identity = await this.identity(request);
|
const identity = await this.identity(request);
|
||||||
@@ -129,7 +139,8 @@ export class AdminMiniAppReleaseController {
|
|||||||
where: { id: taskId, brandId: identity.brandId },
|
where: { id: taskId, brandId: identity.brandId },
|
||||||
});
|
});
|
||||||
if (!task) throw new BadRequestException("小程序发布任务不存在");
|
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({
|
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
||||||
where: { id: identity.brandId },
|
where: { id: identity.brandId },
|
||||||
select: { miniAppSettings: true },
|
select: { miniAppSettings: true },
|
||||||
|
|||||||
@@ -212,6 +212,9 @@ export class ApiClient
|
|||||||
listAdminMiniAppReleases = (
|
listAdminMiniAppReleases = (
|
||||||
...arguments_: Parameters<BrandMethods["listAdminMiniAppReleases"]>
|
...arguments_: Parameters<BrandMethods["listAdminMiniAppReleases"]>
|
||||||
) => this.resources.brand.listAdminMiniAppReleases(...arguments_);
|
) => this.resources.brand.listAdminMiniAppReleases(...arguments_);
|
||||||
|
getLatestAdminMiniAppRelease = (
|
||||||
|
...arguments_: Parameters<BrandMethods["getLatestAdminMiniAppRelease"]>
|
||||||
|
) => this.resources.brand.getLatestAdminMiniAppRelease(...arguments_);
|
||||||
createAdminMiniAppRelease = (
|
createAdminMiniAppRelease = (
|
||||||
...arguments_: Parameters<BrandMethods["createAdminMiniAppRelease"]>
|
...arguments_: Parameters<BrandMethods["createAdminMiniAppRelease"]>
|
||||||
) => this.resources.brand.createAdminMiniAppRelease(...arguments_);
|
) => this.resources.brand.createAdminMiniAppRelease(...arguments_);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export interface BrandMethods {
|
|||||||
Pick<BrandReleaseSummary, "id" | "version" | "status" | "revokedAt">
|
Pick<BrandReleaseSummary, "id" | "version" | "status" | "revokedAt">
|
||||||
>;
|
>;
|
||||||
listAdminMiniAppReleases(): Promise<MiniAppReleaseTask[]>;
|
listAdminMiniAppReleases(): Promise<MiniAppReleaseTask[]>;
|
||||||
|
getLatestAdminMiniAppRelease(): Promise<MiniAppReleaseTask | null>;
|
||||||
createAdminMiniAppRelease(releaseId?: string): Promise<MiniAppReleaseTask>;
|
createAdminMiniAppRelease(releaseId?: string): Promise<MiniAppReleaseTask>;
|
||||||
uploadAdminMiniAppRelease(
|
uploadAdminMiniAppRelease(
|
||||||
id: string,
|
id: string,
|
||||||
@@ -117,6 +118,7 @@ export function brandMethods({ request }: { request: RequestFn }): BrandMethods
|
|||||||
}),
|
}),
|
||||||
revokeAdminRelease: () => request("/admin/releases/revoke", { method: "POST" }),
|
revokeAdminRelease: () => request("/admin/releases/revoke", { method: "POST" }),
|
||||||
listAdminMiniAppReleases: () => request("/admin/miniapp-releases"),
|
listAdminMiniAppReleases: () => request("/admin/miniapp-releases"),
|
||||||
|
getLatestAdminMiniAppRelease: () => request("/admin/miniapp-releases/latest"),
|
||||||
createAdminMiniAppRelease: (releaseId) =>
|
createAdminMiniAppRelease: (releaseId) =>
|
||||||
request("/admin/miniapp-releases", {
|
request("/admin/miniapp-releases", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in new issue
Block a user