【操盘手】 流量分发 - 对接添加接口及页面优化
This commit is contained in:
@@ -15,12 +15,12 @@ interface BasicInfoStepProps {
|
||||
|
||||
export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoStepProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
name: initialData.name || `流量分发 ${format(new Date(), "yyyyMMdd HHmm")}`,
|
||||
distributionMethod: initialData.distributionMethod || "equal",
|
||||
dailyLimit: initialData.dailyLimit || 50,
|
||||
timeRestriction: initialData.timeRestriction || "custom",
|
||||
startTime: initialData.startTime || "09:00",
|
||||
endTime: initialData.endTime || "18:00",
|
||||
name: initialData.name ?? `流量分发 ${format(new Date(), "yyyyMMdd HHmm")}`,
|
||||
distributeType: initialData.distributeType ?? "1",
|
||||
maxPerDay: initialData.maxPerDay ?? 50,
|
||||
timeType: initialData.timeType ?? "2",
|
||||
startTime: initialData.startTime ?? "09:00",
|
||||
endTime: initialData.endTime ?? "18:00",
|
||||
})
|
||||
|
||||
const handleChange = (field: string, value: any) => {
|
||||
@@ -28,7 +28,14 @@ export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoSte
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
onNext(formData)
|
||||
onNext({
|
||||
name: formData.name,
|
||||
distributeType: Number(formData.distributeType),
|
||||
maxPerDay: formData.maxPerDay,
|
||||
timeType: Number(formData.timeType),
|
||||
startTime: formData.timeType == "2" ? formData.startTime : "09:00",
|
||||
endTime: formData.timeType == "2" ? formData.endTime : "21:00",
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -52,24 +59,24 @@ export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoSte
|
||||
<div className="space-y-2">
|
||||
<Label>分配方式</Label>
|
||||
<RadioGroup
|
||||
value={formData.distributionMethod}
|
||||
onValueChange={(value) => handleChange("distributionMethod", value)}
|
||||
value={String(formData.distributeType)}
|
||||
onValueChange={(value) => handleChange("distributeType", value)}
|
||||
className="space-y-2"
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="equal" id="equal" />
|
||||
<RadioGroupItem value="1" id="equal" />
|
||||
<Label htmlFor="equal" className="cursor-pointer">
|
||||
均分配 <span className="text-gray-500 text-sm">(流量将均分配给所有客服)</span>
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="priority" id="priority" />
|
||||
<RadioGroupItem value="2" id="priority" />
|
||||
<Label htmlFor="priority" className="cursor-pointer">
|
||||
优先级分配 <span className="text-gray-500 text-sm">(按客服优先级顺序分配)</span>
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="ratio" id="ratio" />
|
||||
<RadioGroupItem value="3" id="ratio" />
|
||||
<Label htmlFor="ratio" className="cursor-pointer">
|
||||
比例分配 <span className="text-gray-500 text-sm">(按设定比例分配流量)</span>
|
||||
</Label>
|
||||
@@ -83,14 +90,14 @@ export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoSte
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between items-center">
|
||||
<span>每日最大分配量</span>
|
||||
<span className="font-medium">{formData.dailyLimit} 人/天</span>
|
||||
<span className="font-medium">{formData.maxPerDay} 人/天</span>
|
||||
</div>
|
||||
<Slider
|
||||
value={[formData.dailyLimit]}
|
||||
value={[formData.maxPerDay]}
|
||||
min={1}
|
||||
max={200}
|
||||
step={1}
|
||||
onValueChange={(value) => handleChange("dailyLimit", value[0])}
|
||||
onValueChange={(value) => handleChange("maxPerDay", value[0])}
|
||||
className="py-4"
|
||||
/>
|
||||
<p className="text-sm text-gray-500">限制每天最多分配的流量数量</p>
|
||||
@@ -99,25 +106,25 @@ export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoSte
|
||||
<div className="space-y-4 pt-4">
|
||||
<Label>时间限制</Label>
|
||||
<RadioGroup
|
||||
value={formData.timeRestriction}
|
||||
onValueChange={(value) => handleChange("timeRestriction", value)}
|
||||
value={String(formData.timeType)}
|
||||
onValueChange={(value) => handleChange("timeType", value)}
|
||||
className="space-y-4"
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="allDay" id="allDay" />
|
||||
<RadioGroupItem value="1" id="allDay" />
|
||||
<Label htmlFor="allDay" className="cursor-pointer">
|
||||
全天分配
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="custom" id="custom" />
|
||||
<RadioGroupItem value="2" id="custom" />
|
||||
<Label htmlFor="custom" className="cursor-pointer">
|
||||
自定义时间段
|
||||
</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
|
||||
{formData.timeRestriction === "custom" && (
|
||||
{formData.timeType == "2" && (
|
||||
<div className="grid grid-cols-2 gap-4 pt-2">
|
||||
<div>
|
||||
<Label htmlFor="startTime" className="mb-2 block">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useState, useEffect } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
@@ -8,6 +8,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { Avatar } from "@/components/ui/avatar"
|
||||
import { Search } from "lucide-react"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { api } from "@/lib/api"
|
||||
|
||||
interface Device {
|
||||
id: string
|
||||
@@ -30,150 +31,64 @@ interface TargetSettingsStepProps {
|
||||
}
|
||||
|
||||
export default function TargetSettingsStep({ onNext, onBack, initialData = {} }: TargetSettingsStepProps) {
|
||||
const [selectedDevices, setSelectedDevices] = useState<string[]>(initialData.selectedDevices || [])
|
||||
const [selectedCustomerServices, setSelectedCustomerServices] = useState<string[]>(
|
||||
initialData.selectedCustomerServices || [],
|
||||
)
|
||||
const [searchTerm, setSearchTerm] = useState("")
|
||||
const [deviceList, setDeviceList] = useState<any[]>([])
|
||||
const [selectedDeviceIds, setSelectedDeviceIds] = useState<string[]>(initialData.devices || [])
|
||||
const [search, setSearch] = useState("")
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
// 模拟设备数据
|
||||
const devices: Device[] = [
|
||||
{ id: "1", name: "设备 1", status: "online" },
|
||||
{ id: "2", name: "设备 2", status: "online" },
|
||||
{ id: "3", name: "设备 3", status: "offline" },
|
||||
{ id: "4", name: "设备 4", status: "online" },
|
||||
{ id: "5", name: "设备 5", status: "offline" },
|
||||
]
|
||||
useEffect(() => {
|
||||
setLoading(true)
|
||||
api.get('/v1/devices?page=1&limit=100').then(res => {
|
||||
setDeviceList(res.data?.list || [])
|
||||
}).finally(() => setLoading(false))
|
||||
}, [])
|
||||
|
||||
// 模拟客服数据
|
||||
const customerServices: CustomerService[] = [
|
||||
{ id: "1", name: "客服 A", status: "online" },
|
||||
{ id: "2", name: "客服 B", status: "online" },
|
||||
{ id: "3", name: "客服 C", status: "offline" },
|
||||
{ id: "4", name: "客服 D", status: "online" },
|
||||
]
|
||||
|
||||
const filteredDevices = devices.filter((device) => device.name.toLowerCase().includes(searchTerm.toLowerCase()))
|
||||
|
||||
const filteredCustomerServices = customerServices.filter((cs) =>
|
||||
cs.name.toLowerCase().includes(searchTerm.toLowerCase()),
|
||||
const filteredDevices = deviceList.filter(device =>
|
||||
(device.memo || device.nickname || "").toLowerCase().includes(search.toLowerCase())
|
||||
)
|
||||
|
||||
const toggleDevice = (id: string) => {
|
||||
setSelectedDevices((prev) => (prev.includes(id) ? prev.filter((deviceId) => deviceId !== id) : [...prev, id]))
|
||||
}
|
||||
|
||||
const toggleCustomerService = (id: string) => {
|
||||
setSelectedCustomerServices((prev) => (prev.includes(id) ? prev.filter((csId) => csId !== id) : [...prev, id]))
|
||||
setSelectedDeviceIds(prev =>
|
||||
prev.includes(id) ? prev.filter(did => did !== id) : [...prev, id]
|
||||
)
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
onNext({
|
||||
selectedDevices,
|
||||
selectedCustomerServices,
|
||||
targets: selectedDeviceIds,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg p-6 shadow-sm">
|
||||
<h2 className="text-xl font-bold mb-6">目标设置</h2>
|
||||
|
||||
<div className="mb-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400" size={18} />
|
||||
<Input
|
||||
placeholder="搜索设备或客服"
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
<Input placeholder="搜索设备" value={search} onChange={e => setSearch(e.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-3 mt-4 max-h-80 overflow-y-auto">
|
||||
{loading ? <div className="text-center text-gray-400 py-8">加载中...</div> :
|
||||
filteredDevices.map(device => (
|
||||
<div key={device.id} className="flex items-center border rounded-lg px-4 py-2 mb-2 justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className={`w-8 h-8 flex items-center justify-center rounded-full ${device.alive === 1 ? "bg-green-100 text-green-600" : "bg-gray-100 text-gray-400"}`}>设</span>
|
||||
<div>
|
||||
<div className="font-medium">{device.memo }</div>
|
||||
<div className="text-xs text-gray-400">IMEI:{device.imei}</div>
|
||||
<div className="text-xs text-gray-400">微信号:{device.wechatId || "--"}({device.nickname || "--"})</div>
|
||||
<div className={`text-xs ${device.alive === 1 ? "text-green-600" : "text-gray-400"}`}>{device.alive === 1 ? "在线" : "离线"}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={selectedDeviceIds.includes(device.id)}
|
||||
onCheckedChange={() => toggleDevice(device.id)}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
<Tabs defaultValue="devices" className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2 mb-4">
|
||||
<TabsTrigger value="devices">设备选择</TabsTrigger>
|
||||
<TabsTrigger value="customerService">客服选择</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="devices" className="space-y-4">
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
{filteredDevices.map((device) => (
|
||||
<Card
|
||||
key={device.id}
|
||||
className={`cursor-pointer border ${selectedDevices.includes(device.id) ? "border-blue-500" : "border-gray-200"}`}
|
||||
>
|
||||
<CardContent className="p-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Avatar>
|
||||
<div
|
||||
className={`w-full h-full flex items-center justify-center ${device.status === "online" ? "bg-green-100" : "bg-gray-100"}`}
|
||||
>
|
||||
<span className={`text-sm ${device.status === "online" ? "text-green-600" : "text-gray-600"}`}>
|
||||
{device.name.substring(0, 1)}
|
||||
</span>
|
||||
</div>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="font-medium">{device.name}</p>
|
||||
<p className={`text-xs ${device.status === "online" ? "text-green-600" : "text-gray-500"}`}>
|
||||
{device.status === "online" ? "在线" : "离线"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={selectedDevices.includes(device.id)}
|
||||
onCheckedChange={() => toggleDevice(device.id)}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="customerService" className="space-y-4">
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
{filteredCustomerServices.map((cs) => (
|
||||
<Card
|
||||
key={cs.id}
|
||||
className={`cursor-pointer border ${selectedCustomerServices.includes(cs.id) ? "border-blue-500" : "border-gray-200"}`}
|
||||
>
|
||||
<CardContent className="p-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Avatar>
|
||||
<div
|
||||
className={`w-full h-full flex items-center justify-center ${cs.status === "online" ? "bg-green-100" : "bg-gray-100"}`}
|
||||
>
|
||||
<span className={`text-sm ${cs.status === "online" ? "text-green-600" : "text-gray-600"}`}>
|
||||
{cs.name.substring(0, 1)}
|
||||
</span>
|
||||
</div>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="font-medium">{cs.name}</p>
|
||||
<p className={`text-xs ${cs.status === "online" ? "text-green-600" : "text-gray-500"}`}>
|
||||
{cs.status === "online" ? "在线" : "离线"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={selectedCustomerServices.includes(cs.id)}
|
||||
onCheckedChange={() => toggleCustomerService(cs.id)}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
<div className="mt-8 flex justify-between">
|
||||
<Button variant="outline" onClick={onBack}>
|
||||
← 上一步
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={selectedDevices.length === 0 && selectedCustomerServices.length === 0}>
|
||||
下一步 →
|
||||
</Button>
|
||||
<Button variant="outline" onClick={onBack}>← 上一步</Button>
|
||||
<Button onClick={handleSubmit} disabled={selectedDeviceIds.length === 0}>下一步 →</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ export default function TrafficPoolStep({ onSubmit, onBack, initialData = {} }:
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000)) // 模拟API请求
|
||||
|
||||
onSubmit({
|
||||
selectedPools,
|
||||
poolIds: selectedPools,
|
||||
// 可以添加其他需要提交的数据
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user