feat: 重做小程序发布任务卡片并支持配置请求地址
- 发布任务卡片拆为 MiniAppReleaseCard,状态用中文映射并附下一步说明,构建日志收进折叠面板,构建中自动滚动到底部 - 小程序配置增加“小程序请求地址”字段,展示当前生效域名,未配置时直接提示原因与修复位置 - 顶部上传按钮在无任务时自动创建发布任务,不再报“还没有可发布的内容版本” - 构建轮询在任务被判定为中断后停止,避免页面空转请求
This commit is contained in:
1 parent
44fe7a0142
commit
ac3f433ee6
2 files changed
+248
-111
No files matched your search
@@ -22,6 +22,7 @@ import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
@@ -45,6 +46,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<{
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
artifactPath: string;
|
||||
privateKey?: string;
|
||||
}>();
|
||||
@@ -85,12 +87,17 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
if (!miniAppSettings.data) return;
|
||||
miniAppSettingsForm.setFieldsValue({
|
||||
appId: miniAppSettings.data.appId,
|
||||
apiBaseUrl: miniAppSettings.data.apiBaseUrl,
|
||||
artifactPath: miniAppSettings.data.artifactPath,
|
||||
privateKey: "",
|
||||
});
|
||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||
useEffect(() => {
|
||||
const building = miniAppReleases.data?.find((task) => task.buildStatus === "building");
|
||||
const building = miniAppReleases.data?.find(
|
||||
(task) =>
|
||||
task.buildStatus === "building" &&
|
||||
Date.now() - new Date(task.updatedAt).getTime() < 15 * 60 * 1000,
|
||||
);
|
||||
if (!building) return;
|
||||
const timer = setInterval(() => void miniAppReleases.refetch(), 1500);
|
||||
return () => clearInterval(timer);
|
||||
@@ -167,8 +174,8 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const uploadLatestMiniAppRelease = useMutation({
|
||||
mutationFn: async () => {
|
||||
const latest = await client.getLatestAdminMiniAppRelease();
|
||||
if (!latest) throw new Error("还没有可发布的内容版本");
|
||||
return client.uploadAdminMiniAppRelease(latest.id);
|
||||
const task = latest ?? (await client.createAdminMiniAppRelease());
|
||||
return client.uploadAdminMiniAppRelease(task.id);
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("小程序代码已上传");
|
||||
@@ -267,6 +274,23 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM
|
||||
加密。小程序产物目录由系统构建流程决定,不需要手动修改。
|
||||
</Typography.Paragraph>
|
||||
{miniAppSettings.data?.buildError ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message="小程序构建参数未就绪"
|
||||
description={miniAppSettings.data.buildError}
|
||||
/>
|
||||
) : (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message={`请求域名 ${miniAppSettings.data?.requestDomain ?? "未确认"}`}
|
||||
description="该域名在构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致;不一致会导致小程序打开即加载失败。"
|
||||
/>
|
||||
)}
|
||||
<Form
|
||||
form={miniAppSettingsForm}
|
||||
layout="vertical"
|
||||
@@ -279,16 +303,42 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="apiBaseUrl"
|
||||
label="小程序请求地址"
|
||||
rules={[
|
||||
{ required: true, message: "请输入小程序请求地址" },
|
||||
{
|
||||
validator: (_rule, value: string) =>
|
||||
!value || /^https:\/\/[^/]+/.test(value)
|
||||
? Promise.resolve()
|
||||
: Promise.reject(
|
||||
new Error(
|
||||
"公网地址必须以 https:// 开头,例如 https://wechat.app.que01.top/api",
|
||||
),
|
||||
),
|
||||
},
|
||||
]}
|
||||
extra="构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致。修改后需重新构建并上传代码才生效。"
|
||||
>
|
||||
<Input maxLength={200} placeholder="https://wechat.app.que01.top/api" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="privateKey"
|
||||
label="上传私钥"
|
||||
help={
|
||||
miniAppSettings.data?.hasStoredCredentials
|
||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||
: "粘贴以 -----BEGIN 开头的微信上传私钥。"
|
||||
: "粘贴微信开发者工具导出的 private.<appid>.key 全文,必须保留换行。"
|
||||
}
|
||||
>
|
||||
<Input.Password autoComplete="new-password" />
|
||||
<Input.TextArea
|
||||
rows={5}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
|
||||
style={{ fontFamily: "monospace", fontSize: 12 }}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
||||
@@ -529,113 +579,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
</Space>
|
||||
<Divider />
|
||||
{miniAppReleases.data?.length ? (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<Space direction="vertical" size={12} style={{ width: "100%" }}>
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<Card key={task.id} size="small">
|
||||
<Space wrap>
|
||||
<Typography.Text>品牌 v{task.version}</Typography.Text>
|
||||
<Tag
|
||||
color={
|
||||
task.status === "published"
|
||||
? "green"
|
||||
: task.status === "failed" || task.buildStatus === "failed"
|
||||
? "red"
|
||||
: task.buildStatus === "building"
|
||||
? "orange"
|
||||
: "blue"
|
||||
}
|
||||
>
|
||||
{task.status}
|
||||
</Tag>
|
||||
{task.weappUploadId && (
|
||||
<Typography.Text type="secondary">
|
||||
微信版本 {task.weappUploadId}
|
||||
</Typography.Text>
|
||||
)}
|
||||
{task.error && <Typography.Text type="danger">{task.error}</Typography.Text>}
|
||||
{task.buildStatus === "building" && (
|
||||
<Typography.Text type="secondary">正在构建微信小程序...</Typography.Text>
|
||||
)}
|
||||
{task.buildStatus === "failed" && (
|
||||
<Typography.Text type="secondary">微信小程序构建失败</Typography.Text>
|
||||
)}
|
||||
{task.buildLogs?.length ? (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{task.buildLogs.slice(-8).map((log, index) => (
|
||||
<Typography.Paragraph
|
||||
key={`${log.at}-${index}`}
|
||||
type={log.stream === "stderr" ? "danger" : "secondary"}
|
||||
style={{ marginBottom: 0, whiteSpace: "pre-wrap", fontSize: 12 }}
|
||||
code
|
||||
>
|
||||
{log.message}
|
||||
</Typography.Paragraph>
|
||||
))}
|
||||
</Space>
|
||||
) : null}
|
||||
{(task.status === "built" || task.buildStatus === "failed") && (
|
||||
<Button
|
||||
size="small"
|
||||
loading={uploadMiniAppRelease.isPending}
|
||||
onClick={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
>
|
||||
上传微信
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "uploaded" && (
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status: "under_review" })
|
||||
}
|
||||
>
|
||||
标记提交审核
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "under_review" && (
|
||||
<>
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status: "approved" })
|
||||
}
|
||||
>
|
||||
审核通过
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
danger
|
||||
onClick={() =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status: "rejected" })
|
||||
}
|
||||
>
|
||||
审核驳回
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{task.status === "approved" && (
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
onClick={() =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status: "published" })
|
||||
}
|
||||
>
|
||||
标记已发布
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "failed" && (
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status: "built" })
|
||||
}
|
||||
>
|
||||
重置可上传
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
</Card>
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) => updateMiniAppStatus.mutate({ id: task.id, status })}
|
||||
/>
|
||||
))}
|
||||
</Space>
|
||||
) : (
|
||||
|
||||
Reference in new issue
Block a user