feat: 本次提交更新内容如下
场景计划构建完成
This commit is contained in:
@@ -6,7 +6,7 @@ export function getScenarioTypes() {
|
|||||||
|
|
||||||
// 创建计划
|
// 创建计划
|
||||||
export function createPlan(data: any) {
|
export function createPlan(data: any) {
|
||||||
return request("/v1/scenarios/plans", data, "POST");
|
return request("/v1/plan/create", data, "POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新计划
|
// 更新计划
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export default function NewPlan() {
|
|||||||
}
|
}
|
||||||
message.success(isEdit ? "计划已更新" : "获客计划已创建");
|
message.success(isEdit ? "计划已更新" : "获客计划已创建");
|
||||||
const sceneItem = sceneList.find((v) => formData.scenario === v.id);
|
const sceneItem = sceneList.find((v) => formData.scenario === v.id);
|
||||||
router(`/scenarios/list/${formData.sceneId}/${sceneItem.name}`);
|
router(`/scenarios/list/${formData.scenario}/${sceneItem.name}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(
|
message.error(
|
||||||
error instanceof Error
|
error instanceof Error
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useRef } from "react";
|
||||||
import { Input, Button, Tabs, Modal, Alert, message } from "antd";
|
import { Input, Button, Tabs, Modal, Alert, message } from "antd";
|
||||||
import {
|
import {
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
TeamOutlined,
|
TeamOutlined,
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import styles from "./messages.module.scss";
|
import styles from "./messages.module.scss";
|
||||||
|
import { uploadFile } from "@/api/common";
|
||||||
|
|
||||||
interface MessageContent {
|
interface MessageContent {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -87,6 +88,13 @@ const MessageSettings: React.FC<MessageSettingsProps> = ({
|
|||||||
const [isAddDayPlanOpen, setIsAddDayPlanOpen] = useState(false);
|
const [isAddDayPlanOpen, setIsAddDayPlanOpen] = useState(false);
|
||||||
const [isGroupSelectOpen, setIsGroupSelectOpen] = useState(false);
|
const [isGroupSelectOpen, setIsGroupSelectOpen] = useState(false);
|
||||||
const [selectedGroupId, setSelectedGroupId] = useState("");
|
const [selectedGroupId, setSelectedGroupId] = useState("");
|
||||||
|
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
const [uploadingIndex, setUploadingIndex] = useState<string | null>(null);
|
||||||
|
const [uploadingType, setUploadingType] = useState<
|
||||||
|
"miniprogram" | "link" | null
|
||||||
|
>(null);
|
||||||
|
const [uploadingDay, setUploadingDay] = useState<number | null>(null);
|
||||||
|
const [uploadingMsgIdx, setUploadingMsgIdx] = useState<number | null>(null);
|
||||||
|
|
||||||
// 添加新消息
|
// 添加新消息
|
||||||
const handleAddMessage = (dayIndex: number, type = "text") => {
|
const handleAddMessage = (dayIndex: number, type = "text") => {
|
||||||
@@ -177,17 +185,50 @@ const MessageSettings: React.FC<MessageSettingsProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理文件上传
|
// 触发文件选择
|
||||||
const handleFileUpload = (
|
const triggerUpload = (
|
||||||
dayIndex: number,
|
dayIdx: number,
|
||||||
messageIndex: number,
|
msgIdx: number,
|
||||||
type: "image" | "video" | "file"
|
type: "miniprogram" | "link"
|
||||||
) => {
|
) => {
|
||||||
message.success(
|
setUploadingDay(dayIdx);
|
||||||
`${
|
setUploadingMsgIdx(msgIdx);
|
||||||
type === "image" ? "图片" : type === "video" ? "视频" : "文件"
|
setUploadingType(type);
|
||||||
}上传成功`
|
setTimeout(() => {
|
||||||
);
|
fileInputRef.current?.click();
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理文件上传
|
||||||
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0];
|
||||||
|
if (
|
||||||
|
!file ||
|
||||||
|
uploadingDay === null ||
|
||||||
|
uploadingMsgIdx === null ||
|
||||||
|
!uploadingType
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
setUploadingIndex(`${uploadingDay}-${uploadingMsgIdx}`);
|
||||||
|
try {
|
||||||
|
const url = await uploadFile(file);
|
||||||
|
// 更新对应消息的coverImage
|
||||||
|
setDayPlans((prev) => {
|
||||||
|
const newPlans = [...prev];
|
||||||
|
const msg = newPlans[uploadingDay].messages[uploadingMsgIdx];
|
||||||
|
msg.coverImage = url;
|
||||||
|
return newPlans;
|
||||||
|
});
|
||||||
|
message.success("上传成功");
|
||||||
|
} catch (err) {
|
||||||
|
message.error("上传失败");
|
||||||
|
} finally {
|
||||||
|
setUploadingIndex(null);
|
||||||
|
setUploadingType(null);
|
||||||
|
setUploadingDay(null);
|
||||||
|
setUploadingMsgIdx(null);
|
||||||
|
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const items = dayPlans.map((plan, dayIndex) => ({
|
const items = dayPlans.map((plan, dayIndex) => ({
|
||||||
@@ -390,8 +431,11 @@ const MessageSettings: React.FC<MessageSettingsProps> = ({
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
icon={<UploadOutlined />}
|
icon={<UploadOutlined />}
|
||||||
|
loading={
|
||||||
|
uploadingIndex === `${dayIndex}-${messageIndex}`
|
||||||
|
}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handleFileUpload(dayIndex, messageIndex, "image")
|
triggerUpload(dayIndex, messageIndex, "miniprogram")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
上传封面
|
上传封面
|
||||||
@@ -461,8 +505,11 @@ const MessageSettings: React.FC<MessageSettingsProps> = ({
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
icon={<UploadOutlined />}
|
icon={<UploadOutlined />}
|
||||||
|
loading={
|
||||||
|
uploadingIndex === `${dayIndex}-${messageIndex}`
|
||||||
|
}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handleFileUpload(dayIndex, messageIndex, "image")
|
triggerUpload(dayIndex, messageIndex, "link")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
上传封面
|
上传封面
|
||||||
@@ -584,6 +631,13 @@ const MessageSettings: React.FC<MessageSettingsProps> = ({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<input
|
||||||
|
ref={fileInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
style={{ display: "none" }}
|
||||||
|
onChange={handleFileChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user