diff --git a/Cunkebao/src/api/scenarios.ts b/Cunkebao/src/api/scenarios.ts index 88e10dc1..74202095 100644 --- a/Cunkebao/src/api/scenarios.ts +++ b/Cunkebao/src/api/scenarios.ts @@ -308,4 +308,21 @@ export async function createScenarioPlan(data: any) { // 编辑计划 export async function updateScenarioPlan(planId: number | string, data: any) { return await put(`/v1/plan/update?planId=${planId}`, data); -} \ No newline at end of file +} + +/** + * 获取计划小程序二维码 + * @param taskid 任务ID + * @returns base64二维码 + */ +export const getWxMinAppCode = async (taskId: string): Promise<{ code: number; base64?: string; msg?: string }> => { + try { + return await get<{ code: number; base64?: string; msg?: string }>( + `/v1/plan/getWxMinAppCode?taskId=${ taskId }`, + + ); + } catch (error) { + console.error('获取小程序二维码失败:', error); + return { code: 500, msg: '获取小程序二维码失败' }; + } +}; \ No newline at end of file diff --git a/Cunkebao/src/pages/scenarios/ScenarioList.tsx b/Cunkebao/src/pages/scenarios/ScenarioList.tsx index 6c110961..aae47189 100644 --- a/Cunkebao/src/pages/scenarios/ScenarioList.tsx +++ b/Cunkebao/src/pages/scenarios/ScenarioList.tsx @@ -15,6 +15,7 @@ import { Code, Search, RefreshCw, + QrCode, } from "lucide-react"; import { fetchPlanList, @@ -22,6 +23,7 @@ import { copyPlan, deletePlan, type Task, + getWxMinAppCode, } from "@/api/scenarios"; import { useToast } from "@/components/ui/toast"; import "@/components/Layout.css"; @@ -65,6 +67,11 @@ export default function ScenarioDetail() { }); const [searchTerm, setSearchTerm] = useState(""); const [loadingTasks, setLoadingTasks] = useState(false); + // 二维码弹窗相关 + const [showQrDialog, setShowQrDialog] = useState(false); + const [qrLoading, setQrLoading] = useState(false); + const [qrImg, setQrImg] = useState(""); + const [qrTaskId, setQrTaskId] = useState(""); // 获取渠道中文名称 const getChannelName = (channel: string) => { @@ -310,6 +317,33 @@ export default function ScenarioDetail() { navigate(`/scenarios/new/${scenarioId}`); }; + const handleShowQrCode = async (taskId: string) => { + setQrTaskId(taskId); + setShowQrDialog(true); + setQrLoading(true); + setQrImg(""); + try { + const data = await getWxMinAppCode(taskId); + if (data && data.base64) { + setQrImg(`data:image/png;base64,${data.base64}`); + } else { + toast({ + title: "获取二维码失败", + description: data?.msg || "未知错误", + variant: "destructive", + }); + } + } catch (e) { + toast({ + title: "获取二维码失败", + description: "网络错误", + variant: "destructive", + }); + } finally { + setQrLoading(false); + } + }; + const getStatusColor = (status: number) => { switch (status) { case 1: @@ -463,70 +497,75 @@ export default function ScenarioDetail() { ) : ( -