fix: 恢复小程序上传配置并固定产物目录
This commit is contained in:
1 parent
ad949ab370
commit
26f1157083
5 files changed
+137
-21
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 {
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Empty,
|
||||
Input,
|
||||
Modal,
|
||||
Form,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
@@ -42,6 +43,11 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [note, setNote] = useState("");
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<{
|
||||
appId: string;
|
||||
artifactPath: string;
|
||||
privateKey?: string;
|
||||
}>();
|
||||
const brand = useQuery({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
@@ -75,6 +81,14 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
queryKey: ["publication-miniapp-settings"],
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
miniAppSettingsForm.setFieldsValue({
|
||||
appId: miniAppSettings.data.appId,
|
||||
artifactPath: miniAppSettings.data.artifactPath,
|
||||
privateKey: "",
|
||||
});
|
||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||
const refresh = () => {
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
@@ -155,6 +169,18 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
void miniAppReleases.refetch();
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
mutationFn: (values: { appId: string; artifactPath: string; privateKey?: string }) =>
|
||||
client.updateAdminMiniAppSettings({
|
||||
appId: values.appId,
|
||||
artifactPath: values.artifactPath,
|
||||
...(values.privateKey ? { privateKey: values.privateKey } : {}),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("小程序上传配置已保存");
|
||||
void miniAppSettings.refetch();
|
||||
},
|
||||
});
|
||||
const uploadMiniAppRelease = useMutation({
|
||||
mutationFn: (id: string) => client.uploadAdminMiniAppRelease(id),
|
||||
onSuccess: () => {
|
||||
@@ -175,9 +201,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
void miniAppReleases.refetch();
|
||||
},
|
||||
});
|
||||
const loading = [brand, workspace, catalog, readiness, releases, miniAppReleases].some(
|
||||
(query) => query.isLoading,
|
||||
);
|
||||
const loading = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].some((query) => query.isLoading);
|
||||
const error = [
|
||||
brand,
|
||||
workspace,
|
||||
@@ -221,8 +253,52 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
isEnabled: boolean;
|
||||
}>;
|
||||
|
||||
const contentTab = <Space direction="vertical" size={24} style={{ width: "100%" }}></Space>;
|
||||
const miniAppTab = <Space direction="vertical" size={24} style={{ width: "100%" }}></Space>;
|
||||
const contentTab = null;
|
||||
const miniAppSettingsTab = (
|
||||
<Space direction="vertical" size={24} style={{ width: "100%" }}>
|
||||
<Card title="小程序上传配置">
|
||||
<Typography.Paragraph type="secondary">
|
||||
AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM
|
||||
加密。小程序产物目录由系统构建流程决定,不需要手动修改。
|
||||
</Typography.Paragraph>
|
||||
<Form
|
||||
form={miniAppSettingsForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveMiniAppSettings.mutate(values)}
|
||||
>
|
||||
<Form.Item
|
||||
name="appId"
|
||||
label="微信 AppID"
|
||||
rules={[{ required: true, message: "请输入微信 AppID" }]}
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="privateKey"
|
||||
label="上传私钥"
|
||||
help={
|
||||
miniAppSettings.data?.hasStoredCredentials
|
||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||
: "粘贴以 -----BEGIN 开头的微信上传私钥。"
|
||||
}
|
||||
>
|
||||
<Input.Password autoComplete="new-password" />
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
||||
保存上传配置
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<Tag color="green">已加密保存上传凭据</Tag>
|
||||
) : (
|
||||
<Tag color="warning">未配置上传私钥</Tag>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={saveMiniAppSettings.error} />
|
||||
</Form>
|
||||
</Card>
|
||||
</Space>
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
@@ -234,8 +310,17 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
items={[
|
||||
{ key: "content", label: "内容发布", children: contentTab },
|
||||
{ key: "miniapp", label: "小程序发布", children: miniAppTab },
|
||||
{
|
||||
key: "content",
|
||||
label: "内容发布",
|
||||
children: contentTab,
|
||||
},
|
||||
{ key: "miniapp", label: "小程序发布", children: null },
|
||||
{
|
||||
key: "settings",
|
||||
label: "小程序配置",
|
||||
children: activeTab === "settings" ? miniAppSettingsTab : null,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{activeTab === "content" && (
|
||||
|
||||
Reference in new issue
Block a user