FEAT => 本次更新项目为:

优化了代码
This commit is contained in:
超级老白兔
2025-08-06 17:36:15 +08:00
parent b53929cb22
commit f59ce8809d
2 changed files with 40 additions and 169 deletions

View File

@@ -1,6 +1,5 @@
import React, { useState, useEffect, useRef } from "react";
import { Form, Input, Button, Tag, Switch, Modal, Spin } from "antd";
import { Button as ButtonMobile } from "antd-mobile";
import { Input, Button, Tag, Switch, Modal, Spin } from "antd";
import {
PlusOutlined,
EyeOutlined,
@@ -11,6 +10,7 @@ import {
} from "@ant-design/icons";
import { uploadFile } from "@/api/common";
import styles from "./base.module.scss";
import { posterTemplates } from "./base.data";
interface BasicSettingsProps {
isEdit: boolean;
@@ -20,12 +20,6 @@ interface BasicSettingsProps {
sceneLoading: boolean;
}
interface Account {
id: string;
nickname: string;
avatar: string;
}
interface Material {
id: string;
name: string;
@@ -33,53 +27,6 @@ interface Material {
preview: string;
}
const posterTemplates = [
{
id: "poster-1",
name: "点击领取",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E9%A2%86%E5%8F%961-tipd1HI7da6qooY5NkhxQnXBnT5LGU.gif",
},
{
id: "poster-2",
name: "点击合作",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%90%88%E4%BD%9C-LPlMdgxtvhqCSr4IM1bZFEFDBF3ztI.gif",
},
{
id: "poster-3",
name: "点击咨询",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%92%A8%E8%AF%A2-FTiyAMAPop2g9LvjLOLDz0VwPg3KVu.gif",
},
{
id: "poster-4",
name: "点击签到",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E7%AD%BE%E5%88%B0-94TZIkjLldb4P2jTVlI6MkSDg0NbXi.gif",
},
{
id: "poster-5",
name: "点击了解",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E4%BA%86%E8%A7%A3-6GCl7mQVdO4WIiykJyweSubLsTwj71.gif",
},
{
id: "poster-6",
name: "点击报名",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E6%8A%A5%E5%90%8D-Mj0nnva0BiASeDAIhNNaRRAbjPgjEj.gif",
},
];
const generateRandomAccounts = (count: number): Account[] => {
return Array.from({ length: count }, (_, index) => ({
id: `account-${index + 1}`,
nickname: `账号-${Math.random().toString(36).substring(2, 7)}`,
avatar: `/placeholder.svg?height=40&width=40&text=${index + 1}`,
}));
};
const generatePosterMaterials = (): Material[] => {
return posterTemplates.map(template => ({
id: template.id,
@@ -96,30 +43,11 @@ const BasicSettings: React.FC<BasicSettingsProps> = ({
sceneList,
sceneLoading,
}) => {
const [isAccountDialogOpen, setIsAccountDialogOpen] = useState(false);
const [isMaterialDialogOpen, setIsMaterialDialogOpen] = useState(false);
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
const [isPhoneSettingsOpen, setIsPhoneSettingsOpen] = useState(false);
const [accounts] = useState<Account[]>(generateRandomAccounts(50));
const [materials] = useState<Material[]>(generatePosterMaterials());
const [selectedAccounts, setSelectedAccounts] = useState<Account[]>(
formData.accounts?.length > 0 ? formData.accounts : [],
);
const [selectedMaterials, setSelectedMaterials] = useState<Material[]>(
formData.materials?.length > 0 ? formData.materials : [],
);
// showAllScenarios 默认为 true
const [showAllScenarios, setShowAllScenarios] = useState(true);
const [isImportDialogOpen, setIsImportDialogOpen] = useState(false);
const [importedTags, setImportedTags] = useState<
Array<{
phone: string;
wechat: string;
source?: string;
orderAmount?: number;
orderDate?: string;
}>
>(formData.importedTags || []);
// 自定义标签相关状态
const [customTagInput, setCustomTagInput] = useState("");
@@ -152,28 +80,6 @@ const BasicSettings: React.FC<BasicSettingsProps> = ({
const uploadInputRef = useRef<HTMLInputElement>(null);
const uploadOrderInputRef = useRef<HTMLInputElement>(null);
// 更新电话获客设置
const handlePhoneSettingsUpdate = () => {
onChange({ ...formData, phoneSettings });
setIsPhoneSettingsOpen(false);
};
// 处理标签选择
const handleTagToggle = (tagId: string) => {
const newTags = selectedScenarioTags.includes(tagId)
? selectedScenarioTags.filter((id: string) => id !== tagId)
: [...selectedScenarioTags, tagId];
setSelectedScenarioTags(newTags);
onChange({ ...formData, scenarioTags: newTags });
};
// 处理通话类型选择
const handleCallTypeChange = (type: string) => {
// setPhoneCallType(type) // This line was removed as per the edit hint.
onChange({ ...formData, phoneCallType: type });
};
// 初始化时,如果没有选择场景,默认选择海报获客
useEffect(() => {
if (!formData.scenario) {
@@ -287,60 +193,6 @@ const BasicSettings: React.FC<BasicSettingsProps> = ({
setIsPreviewOpen(true);
};
// 账号多选切换
const handleAccountToggle = (account: Account) => {
const isSelected = selectedAccounts.some(
(a: Account) => a.id === account.id,
);
let newSelected;
if (isSelected) {
newSelected = selectedAccounts.filter(
(a: Account) => a.id !== account.id,
);
} else {
newSelected = [...selectedAccounts, account];
}
setSelectedAccounts(newSelected);
onChange({ ...formData, accounts: newSelected });
};
// 移除已选账号
const handleRemoveAccount = (id: string) => {
const newSelected = selectedAccounts.filter((a: Account) => a.id !== id);
setSelectedAccounts(newSelected);
onChange({ ...formData, accounts: newSelected });
};
// 处理文件导入
const handleFileImport = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = e => {
try {
const content = e.target?.result as string;
const rows = content.split("\n").filter(row => row.trim());
const tags = rows.slice(1).map(row => {
const [phone, wechat, source, orderAmount, orderDate] =
row.split(",");
return {
phone: phone?.trim(),
wechat: wechat?.trim(),
source: source?.trim(),
orderAmount: orderAmount ? Number(orderAmount) : undefined,
orderDate: orderDate?.trim(),
};
});
setImportedTags(tags);
onChange({ ...formData, importedTags: tags });
} catch (error) {
// 可用 toast 提示
}
};
reader.readAsText(file);
}
};
// 下载模板
const handleDownloadTemplate = () => {
const template =
@@ -378,25 +230,6 @@ const BasicSettings: React.FC<BasicSettingsProps> = ({
}
};
// 账号弹窗关闭时清理搜索等状态
const handleAccountDialogClose = () => {
setIsAccountDialogOpen(false);
// 可在此清理账号搜索等临时状态
};
// 素材弹窗关闭时清理搜索等状态
const handleMaterialDialogClose = () => {
setIsMaterialDialogOpen(false);
// 可在此清理素材搜索等临时状态
};
// 订单导入弹窗关闭时清理文件输入等状态
const handleImportDialogClose = () => {
setIsImportDialogOpen(false);
// 可在此清理文件输入等临时状态
};
// 电话获客弹窗关闭
const handlePhoneSettingsDialogClose = () => {
setIsPhoneSettingsOpen(false);
};
// 图片预览关闭
const handleImagePreviewClose = () => {
setIsPreviewOpen(false);

View File

@@ -0,0 +1,38 @@
export const posterTemplates = [
{
id: "poster-1",
name: "点击领取",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E9%A2%86%E5%8F%961-tipd1HI7da6qooY5NkhxQnXBnT5LGU.gif",
},
{
id: "poster-2",
name: "点击合作",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%90%88%E4%BD%9C-LPlMdgxtvhqCSr4IM1bZFEFDBF3ztI.gif",
},
{
id: "poster-3",
name: "点击咨询",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%92%A8%E8%AF%A2-FTiyAMAPop2g9LvjLOLDz0VwPg3KVu.gif",
},
{
id: "poster-4",
name: "点击签到",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E7%AD%BE%E5%88%B0-94TZIkjLldb4P2jTVlI6MkSDg0NbXi.gif",
},
{
id: "poster-5",
name: "点击了解",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E4%BA%86%E8%A7%A3-6GCl7mQVdO4WIiykJyweSubLsTwj71.gif",
},
{
id: "poster-6",
name: "点击报名",
preview:
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E6%8A%A5%E5%90%8D-Mj0nnva0BiASeDAIhNNaRRAbjPgjEj.gif",
},
];